atlet99/dtorrent_tracker_v2

[FEATURE] - Implement `no_peer_id` parameter support;

Open

#10 opened on Nov 3, 2025

 (0 comments) (0 reactions) (0 assignees)Dart (0 forks)auto 404
enhancementhelp wanted

Repository metrics

Stars
 (0 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Description

The no_peer_id parameter is mentioned in comments but not implemented. According to BEP 0003, this parameter is used with non-compact peer format to omit peer IDs from the response, reducing response size.

Location

File: lib/src/tracker/http_tracker.dart
Line: 90

Current Code

if (currentTrackerId != null) params['trackerid'] = currentTrackerId!;
// params['no_peer_id']
// params['ip'] ; optional
// params['key'] ; optional
return params;

The parameter is commented out and not implemented.

Expected Behavior

According to BEP 0003:

  • no_peer_id: If compact=0, clients can set no_peer_id=1 to omit peer IDs from the response
  • When compact=1, this parameter is ignored (peer list is always compact format)
  • Used to reduce response size when peer IDs are not needed

Use Cases

  • Clients that don't need peer IDs for initial connection
  • Reducing bandwidth usage
  • Improving response parsing speed

Proposed Implementation

@override
Map<String, String> generateQueryParameters(Map<String, dynamic> options) {
  // ... existing code ...
  
  var compact = options['compact'] as int? ?? 1;
  params['compact'] = compact.toString();
  
  // no_peer_id only makes sense when compact=0
  if (compact == 0) {
    var noPeerId = options['no_peer_id'] as bool? ?? false;
    if (noPeerId) {
      params['no_peer_id'] = '1';
    }
  }
  // If compact=1, no_peer_id is ignored (per BEP 0003)
  
  // ... rest of parameters ...
  return params;
}

Update AnnounceOptionsProvider interface documentation:

abstract class AnnounceOptionsProvider {
  /// Get options for tracker announce request
  /// 
  /// Options map can include:
  /// - 'downloaded', 'uploaded', 'left': int (bytes)
  /// - 'compact': int (0 or 1, default 1)
  /// - 'numwant': int (0-50, default 50)
  /// - 'peerId': String or Uint8List (20 bytes)
  /// - 'port': int (1-65535)
  /// - 'no_peer_id': bool (only used when compact=0, default false)
  /// - 'ip': String or InternetAddress (optional)
  /// - 'key': int or Uint8List (4 bytes, optional)
  Future<Map<String, dynamic>> getOptions(Uri uri, String infoHash);
}

Example usage:

class MyProvider implements AnnounceOptionsProvider {
  @override
  Future<Map<String, dynamic>> getOptions(Uri uri, String infoHash) {
    return Future.value({
      'downloaded': 0,
      'uploaded': 0,
      'left': torrent.length,
      'compact': 0,  // Non-compact format
      'no_peer_id': true,  // ✅ Don't include peer IDs
      'numwant': 50,
      'peerId': peerId,
      'port': port,
    });
  }
}

Impact

  • Severity: Low (Feature Enhancement)
  • Affected: HTTP tracker requests with compact=0
  • Benefits:
    • Full BEP 0003 compliance
    • Reduced response size
    • Optional peer ID omission when not needed
    • Bandwidth optimization

Additional Context

  • no_peer_id only applies when compact=0
  • Many clients always use compact=1, making this less commonly used
  • Still important for full BEP 0003 compliance
  • Some trackers may require or prefer this parameter

Related Standards

Contributor guide