4.4 KiB
torrent-tracker Protocol Plan
Goal: build a tracker-side library that can serve the tracker protocols and extensions seen in real torrents, with protocol parsing separated from swarm storage and serving policy.
Implemented Foundation
- BEP-3 HTTP announce parameters:
info_hash,peer_id,port,uploaded,downloaded,left,compact,no_peer_id,event,numwant,key,ip, andtrackerid. - BEP-23 compact peer responses: IPv4
peersand BEP-7-style IPv6peers6. - BEP-48 HTTP scrape parsing and bencoded scrape responses.
- BEP-15 UDP connect, announce, scrape, and error packet handling.
- BEP-41 UDP announce extension parser, including concatenated URLData chunks.
- Client-side HTTP announce/scrape query builders and bencoded tracker response parsers.
- Client-side UDP connect/announce/scrape packet builders and response parsers with transaction-id validation.
- BEP-5 DHT/KRPC message builders and parser for
ping,find_node,get_peers,announce_peer, response, and error packets. - BEP-32 IPv6 DHT compact node support through
nodes6pluswantflags. - In-memory swarm table keyed by 20-byte tracker infohash.
- Announce handling for insert/update/stop, source-address-derived endpoints,
seed/leecher counts, completed-download scrape counts, no-self filtering,
randomized peer selection,
numwantclamping, and stale peer pruning.
Tracker-Side Roadmap
Client-Side Roadmap
-
DHT node/session manager: Add a UDP event loop, node ID generation, transaction table, timeout/retry logic, bootstrap nodes, and request dispatch for KRPC packets.
-
DHT routing table: Implement BEP-5 k-buckets, XOR distance sorting, good/questionable/bad node state, bucket refresh, and persistence of known nodes between runs.
-
DHT peer discovery: Implement iterative
get_peerslookup, token storage,announce_peer, and integration with the tracker client result format so callers can consume central tracker and DHT peers through one path. -
Tracker session manager: Add a small client state machine that stores UDP connection IDs until expiry, schedules announces at
interval, handles started/completed/stopped events, retries UDP with exponential backoff, and rotates across announce-list tiers. -
Transport adapters: Wrap the protocol helpers with optional HTTP(S) and UDP socket code. Keep TLS outside the core ABI, but provide a CLI/harness path that exercises real network announces through the C helpers.
-
Magnet and v2 metadata: Keep accepting 20-byte tracker hashes: v1 SHA-1 infohash and BEP-52 truncated SHA-256 for v2/hybrid torrents. Add metadata utilities or bindings so callers can compute the right tracker hash from metainfo without duplicating logic.
-
Client interop tests: Compare C helper output against libtorrent/tracker_probe behavior for HTTP, UDP, compact IPv4,
peers6, scrape, failure responses, BEP-41 URLData, and DHT KRPC packets observed from real nodes.
Tracker-Side Roadmap
-
Network daemons: Add HTTP/HTTPS and UDP listeners around the protocol core. HTTPS should live behind a TLS terminator initially; the library API should not require a TLS dependency.
-
IPv6 and multi-homed behavior: The store accepts IPv4 and IPv6 endpoints and prefers source addresses over user-supplied
ip. Add daemon-level tests for announcing the same peer over multiple listen interfaces and returning family-appropriate UDP responses. -
Tracker policy: Add hooks for private torrents, whitelist/auth tokens in HTTP query strings and BEP-41 UDP URLData, per-swarm limits, rate limits, and abuse controls.
-
Response selection: Add stronger selection policy controls: per-family caps, seed/leecher mix, deterministic test hooks for sampling, and configurable
tracker idgeneration/validation. -
Persistence and admin: Add optional durable storage or snapshot/restore for long-running trackers, metrics export, registered-torrent management, and scrape-cache policy.
-
Compatibility matrix: Build interop tests against libtorrent, Transmission, qBittorrent, aria2, rtorrent, and opentracker for HTTP, UDP, compact, IPv6, scrape, and private torrent behavior.
-
Optional adjacent discovery: DHT, PEX, and local peer discovery are peer-discovery mechanisms rather than central tracker protocols. Keep them as separate modules if this project grows into a full discovery stack.