atlet99/dtorrent_tracker_v2

[FEATURE] - Add support for optional BEP parameters `ip` and `key`;

开放

#11 创建于 2025年11月3日

 (0 条评论) (0 个反应) (0 位负责人)Dart (0 个派生)auto 404
enhancementhelp wanted

仓库指标

星标
 (0 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Description

The HTTP tracker has commented-out support for optional BEP 0003 parameters ip and key. These parameters should be implemented to improve tracker compatibility and client identification capabilities.

Location

File: lib/src/tracker/http_tracker.dart
Lines: 90-92

Also needed in: lib/src/tracker/udp_tracker.dart (BEP 0015 also supports these)

Current Code

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

Expected Behavior

According to BEP 0003 and BEP 0015:

  1. ip parameter: Allows the client to specify an alternative IP address that should be sent to peers instead of the IP address from which the HTTP request came. Useful for:

    • Clients behind NAT/firewall
    • VPN scenarios
    • IPv4/IPv6 dual-stack scenarios
  2. key parameter: A 4-byte unique identifier for the client. Used to:

    • Uniquely identify clients with the same IP address
    • Help trackers distinguish between multiple clients behind the same NAT
    • Improve peer identification

Both parameters should be:

  • Optional (not required)
  • Supported in HTTP tracker (BEP 0003)
  • Supported in UDP tracker (BEP 0015)
  • Configurable through AnnounceOptionsProvider.getOptions()

Proposed Implementation

HTTP Tracker

@override
Map<String, String> generateQueryParameters(Map<String, dynamic> options) {
  // ... existing code ...
  
  if (currentTrackerId != null) params['trackerid'] = currentTrackerId!;
  
  // Add optional ip parameter
  if (options['ip'] != null) {
    var ip = options['ip'];
    if (ip is String || ip is InternetAddress) {
      params['ip'] = ip.toString();
    }
  }
  
  // Add optional key parameter (4-byte integer)
  if (options['key'] != null) {
    var key = options['key'];
    if (key is int) {
      params['key'] = key.toString();
    } else if (key is Uint8List && key.length == 4) {
      params['key'] = ByteData.view(key.buffer).getUint32(0).toString();
    }
  }
  
  return params;
}

UDP Tracker

In generateSecondTouchMessage:

// Replace the current hardcoded IP and key:
list.addAll(num2Uint32List(0)); // This is the IP address, default is 0
list.addAll(num2Uint32List(0)); // This is key, with the default value of 0

// With:
var ip = options['ip'] ?? 0; // Support IP parameter
var key = options['key'] ?? 0; // Support key parameter
list.addAll(num2Uint32List(ip));
list.addAll(num2Uint32List(key));

AnnounceOptionsProvider

Extend the provider interface to support these optional parameters:

Future<Map<String, dynamic>> getOptions(Uri uri, String infoHash) {
  return Future.value({
    'downloaded': 0,
    'uploaded': 0,
    'left': torrent.length,
    'compact': 1,
    'numwant': 50,
    'peerId': peerId,
    'port': port,
    'ip': alternativeIpAddress,  // Optional
    'key': uniqueClientKey,      // Optional
  });
}

Impact

  • Severity: Medium (Feature Enhancement)
  • Affected: HTTP and UDP tracker announce requests
  • Benefits:
    • Better compatibility with trackers that use these parameters
    • Improved client identification
    • Support for NAT/VPN scenarios
    • Full BEP 0003 and BEP 0015 compliance

Additional Context

These parameters are optional according to the BEP specifications, but many trackers use them for:

  • Better peer matching
  • Client identification behind NAT
  • Statistics tracking
  • Anti-cheating measures

Related Standards

贡献者指南