public class TrackerClient extends Object implements Runnable
This class manages tracker announcements and peer discovery by:
Threading Model: The start() method creates a thread that runs one complete announcement cycle through all trackers, PEX, and DHT, then queues a new timed event and exits. This approach prevents thread accumulation while ensuring regular announcements.
The client can be restarted after halt() and handles various tracker responses including registration failures and error conditions.
| Modifier and Type | Field and Description |
|---|---|
static int | PORTDefault BitTorrent tracker port. |
| Constructor and Description |
|---|
TrackerClient(I2PSnarkUtil util,
MetaInfo meta,
String additionalTrackerURL,
PeerCoordinator coordinator,
Snark snark)Call start() to start it. |
| Modifier and Type | Method and Description |
|---|---|
void | awaitUnannounces(long ms)Wait, capped at ms, for the unannounces submitted by the last halt() to
dispatch. |
void | halt(boolean fast)Interrupts this Thread to stop it. |
boolean | halted()Check if this tracker client has been halted. |
static boolean | isValidAnnounce(String ann)Whether the announce URL is an I2P host. |
void | reinitialize()Call after editing torrent |
void | run()Run the tracker client thread. |
(package private) static String | scrapeURL(String announce)Build the BEP 48 scrape URL from the announce URL: drop any query string and replace the
last path segment with "scrape". |
void | start()Start the tracker client thread. |
boolean | started()Check if this tracker client has been started. |
(package private) static long | unannounceDispatchWait()How long a stop should keep its sessions open for unannounces to
dispatch: one wave per 32-tracker batch, so small swarms wait ~3s and
bigger swarms scale up to UNANNOUNCE_MAX_WAIT. |
static String | urlencode(byte[] bs)Very lazy byte[] to URL encoder. |
public static final int PORT
public TrackerClient(I2PSnarkUtil util, MetaInfo meta, String additionalTrackerURL, PeerCoordinator coordinator, Snark snark)
meta - null if in magnet modeadditionalTrackerURL - may be null, from the ?tr= param in magnet mode, otherwise
ignoredpublic void awaitUnannounces(long ms)
public void halt(boolean fast)
fast - if true, limit the life of the unannounce threadspublic boolean halted()
public static boolean isValidAnnounce(String ann)
ann - an announce URL, may be null, returns false if nullpublic void reinitialize()
static String scrapeURL(String announce)
announce - the announce URLpublic void start()
public boolean started()
static long unannounceDispatchWait()
public static String urlencode(byte[] bs)
RFC1738: 0-9a-zA-Z$-_.+!*'(), Us: 0-9a-zA-Z
bs - the bytes to encode