Package com.frostwire.jlibtorrent
Class AnnounceEntry
java.lang.Object
com.frostwire.jlibtorrent.AnnounceEntry
Metadata for a single tracker in a torrent's announce list.
AnnounceEntry represents one tracker used for peer discovery and seedstats.
A torrent typically lists multiple trackers organized in "tiers" - the client tries
trackers in order of tier (lowest first), and within each tier tries all trackers
before moving to the next tier. This provides redundancy and load balancing.
Tracker Tiers:
Tier 0 (Primary): [tracker1.com, tracker2.com] Tier 1 (Secondary): [tracker3.com, tracker4.com] Tier 2 (Fallback): [tracker5.com] The client tries all tier-0 trackers first. If they all fail or are slow, it tries tier-1, and so on.
Getting Trackers from a Torrent:
TorrentInfo ti = new TorrentInfo(torrentFile);
// Get all trackers sorted by tier
for (AnnounceEntry tracker : ti.trackers()) {
System.out.println("Tier " + tracker.tier() + ": " + tracker.url());
}
// Example output:
// Tier 0: http://tracker1.example.com:80/announce
// Tier 0: udp://tracker2.example.com:6969/announce
// Tier 1: http://tracker3.example.com:80/announce
Tracker URL Schemes:
// HTTP tracker "http://tracker.example.com:80/announce" // HTTPS tracker (secure) "https://secure-tracker.example.com:443/announce" // UDP tracker (lightweight) "udp://tracker.example.com:6969/announce" // UDP tracker with IPv6 "udp://[2001:db8::1]:6969/announce"
Modifying Tracker Lists:
TorrentInfo ti = new TorrentInfo(torrentFile);
// Add a tracker to tier 0 (primary)
ti.addTracker("http://new-tracker.example.com:80/announce", 0);
// Add a fallback tracker to tier 2
ti.addTracker("http://fallback.example.com:80/announce", 2);
// Remove a tracker (create new list without it)
// Note: JlibtorrentAPI doesn't provide direct removal, rebuild the list if needed
Tracker Statistics (Per Session):
AnnounceEntry tracker = ...;
// Get current state of this tracker
List<AnnounceEndpoint> endpoints = tracker.endpoints();
for (AnnounceEndpoint ep : endpoints) {
System.out.println("Endpoint: " + ep.toString());
}
// Optional tracker ID (for private trackers)
String trackerId = tracker.trackerId();
if (!trackerId.isEmpty()) {
System.out.println("This is a private tracker, trackerId: " + trackerId);
}
// Failure handling
int failLimit = tracker.failLimit();
System.out.println("Max failures before blacklisting: " + failLimit);
// Verification status
boolean verified = tracker.isVerified();
System.out.println("Has received valid response: " + verified);
Tracker Tier Strategy:
// Check and prioritize working trackers
List<AnnounceEntry> allTrackers = ti.trackers();
// Group by tier
Map<Integer, List<AnnounceEntry>> byTier = new TreeMap<>();
for (AnnounceEntry tracker : allTrackers) {
byTier.computeIfAbsent(tracker.tier(), k -> new ArrayList<>())
.add(tracker);
}
// Primary trackers (tier 0)
List<AnnounceEntry> primaryTrackers = byTier.get(0);
System.out.println("Primary trackers: " + primaryTrackers.size());
// Backup trackers (tier > 0)
List<AnnounceEntry> backupTrackers = allTrackers.stream()
.filter(t -> t.tier() > 0)
.collect(Collectors.toList());
System.out.println("Backup trackers: " + backupTrackers.size());
Private vs Public Torrents: - Public torrents: Use DHT (no private bit set), multiple public trackers - Private torrents: Require tracker (DHT disabled), use tracker-issued tracker IDs
// Check if likely private torrent
List<AnnounceEntry> trackers = ti.trackers();
boolean hasPrivateTracker = trackers.stream()
.anyMatch(t -> !t.trackerId().isEmpty());
System.out.println("Likely private torrent: " + hasPrivateTracker);
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAnnounceEntry(com.frostwire.jlibtorrent.swig.announce_entry e) AnnounceEntry(String url) Constructs a tracker announce entry withuas the URL. -
Method Summary
Modifier and TypeMethodDescriptionintThe max number of failures to announce to this tracker in a row, before this tracker is not used anymore.voidfailLimit(short value) booleanSet to true the first time we receive a valid response from this tracker.intsource()A bitmask specifying which sources we got this tracker from.com.frostwire.jlibtorrent.swig.announce_entryswig()inttier()The tier this tracker belongs to.voidtier(short value) The current&trackerid=argument passed to the tracker.voidurl()Tracker URL as it appeared in the torrent file.void
-
Constructor Details
-
AnnounceEntry
public AnnounceEntry(com.frostwire.jlibtorrent.swig.announce_entry e) - Parameters:
e- the native object
-
AnnounceEntry
Constructs a tracker announce entry withuas the URL.- Parameters:
url- the tracker url
-
-
Method Details
-
swig
public com.frostwire.jlibtorrent.swig.announce_entry swig()- Returns:
- the native object
-
endpoints
-
url
Tracker URL as it appeared in the torrent file.- Returns:
- the tracker url
-
url
-
trackerId
The current&trackerid=argument passed to the tracker. this is optional and is normally empty (in which case no trackerid is sent).- Returns:
- the trackerid url argument
-
trackerId
-
tier
public int tier()The tier this tracker belongs to.- Returns:
- the tier number
-
tier
public void tier(short value) -
failLimit
public int failLimit()The max number of failures to announce to this tracker in a row, before this tracker is not used anymore. 0 means unlimited.- Returns:
- the max number of failures allowed
-
failLimit
public void failLimit(short value) -
source
public int source()A bitmask specifying which sources we got this tracker from.- Returns:
- the source bitmask
-
isVerified
public boolean isVerified()Set to true the first time we receive a valid response from this tracker.- Returns:
- if the tracker has received a valid response
-