java.lang.Object
org.klomp.snark.dht.DHTTracker
The tracker stores peers, i.e. Dest hashes (not nodes).
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classTimer event expiring the tracked entries.private static classBloom filters for a torrent, with the time they were built, so the per-query rebuild cost is amortized and the filters are rebuilt once they age out.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextThe app context.private longAge after which a tracked entry expires.private final Map<InfoHash, DHTTracker.FilterCache> Cached BEP 33 bloom filters per torrent, keyed by info hash.private final longHow long built bloom filters are reused before being rebuilt.private booleanTrue while the tracker runs.private final LogLogger for the DHT tracker.private intNot current; updated by the cleaner.private intNot current; updated by the cleaner.private final TorrentsThe torrents whose peers are tracked.private static final intMost peers stored for one torrent.private static final longStagger with other cleaners.private static final longStep adjusting the expire time by entry count.private static final longHow long built bloom filters are reused before being rebuilt.private static final intUpper bound on cached filter entries; the swarm map holds up toMAX_TORRENTS.(package private) static final intBase allowance for the global peer store.(package private) static final intHow many recent peers to retain per torrent; admission allows up to twice this between sweeps.private static final intMost torrents tracked at once.private static final longNo guidance in BEP 5; Vuze is 8h.Constructor Summary
ConstructorsConstructorDescriptionDHTTracker(I2PAppContext ctx) Create a tracker for the given context.DHTTracker(I2PAppContext ctx, long filterCacheTime) Construct a tracker that caches each built bloom filter for the default reuse interval.Method Summary
Modifier and TypeMethodDescription(package private) voidAnnounce a peer for a torrent.(package private) BloomFilter[]Build BEP 33 bloom filters for a torrent, one for the stored seeds and one for the stored peers, by inserting the 32-byte destination hash of each peer into the appropriate filter.(package private) static longgetMaxExpireTime(int peerCount) The maximum expiration period, scaled by how many peers are known: the fewer peers we know, the longer we keep them around.(package private) static intgetMaxPeers(int torrentCount) The dynamic ceiling for the global peer store: a fixed base allowance plus a per-torrent budget, so torrents loaded at runtime get their share rather than contending for one fixed cap.Fetch peers for a torrent.voidDebug info, HTML formatted.voidstart()Mark the tracker live and start the timer that expires stale torrents and peers.(package private) voidstop()Stop the tracker.(package private) voidunannounce(InfoHash ih, Hash hash) Remove a peer from a torrent's peer list.
Field Details
_context
The app context._torrents
The torrents whose peers are tracked.FILTER_CACHE_TIME
private static final long FILTER_CACHE_TIMEHow long built bloom filters are reused before being rebuilt.- See Also:
_filterCache
Cached BEP 33 bloom filters per torrent, keyed by info hash._filterCacheTime
private final long _filterCacheTimeHow long built bloom filters are reused before being rebuilt._expireTime
private long _expireTimeAge after which a tracked entry expires._log
Logger for the DHT tracker._isRunning
private volatile boolean _isRunningTrue while the tracker runs._peerCount
private int _peerCountNot current; updated by the cleaner._torrentCount
private int _torrentCountNot current; updated by the cleaner.CLEAN_TIME
MIN_EXPIRE_TIME
private static final long MIN_EXPIRE_TIMENo guidance in BEP 5; Vuze is 8h. Under sustained pressure the cleaner descends here.- See Also:
DELTA_EXPIRE_TIME
private static final long DELTA_EXPIRE_TIMEStep adjusting the expire time by entry count.- See Also:
MAX_PEERS
static final int MAX_PEERSBase allowance for the global peer store. The effective ceiling is this floor scaled up byMAX_PEERS_PER_TORRENTper torrent being tracked, seegetMaxPeers(int). Because each torrent is already LRU trimmed to MAX_PEERS_PER_TORRENT every sweep and admission is capped at ABSOLUTE_MAX_PER_TORRENT, this global bound is a backstop, not the primary limiter.- See Also:
MAX_PEERS_PER_TORRENT
static final int MAX_PEERS_PER_TORRENTHow many recent peers to retain per torrent; admission allows up to twice this between sweeps.- See Also:
ABSOLUTE_MAX_PER_TORRENT
private static final int ABSOLUTE_MAX_PER_TORRENTMost peers stored for one torrent.- See Also:
MAX_TORRENTS
MAX_FILTER_CACHE
private static final int MAX_FILTER_CACHEUpper bound on cached filter entries; the swarm map holds up toMAX_TORRENTS.- See Also:
Constructor Details
DHTTracker
DHTTracker(I2PAppContext ctx) Create a tracker for the given context.- Parameters:
ctx- the app context
DHTTracker
DHTTracker(I2PAppContext ctx, long filterCacheTime) Construct a tracker that caches each built bloom filter for the default reuse interval.- Parameters:
ctx- the app contextfilterCacheTime- how long built bloom filters are reused, milliseconds; for tests
Method Details
getMaxExpireTime
static long getMaxExpireTime(int peerCount) The maximum expiration period, scaled by how many peers are known: the fewer peers we know, the longer we keep them around. Tiers are aligned with the per-torrent retention capMAX_PEERS_PER_TORRENT; a single torrent approaching its cap keeps a 2-hour window, so a few healthy swarms do not churn peers that are merely quiet.- Parameters:
peerCount- the number of peers currently known- Returns:
- the maximum expiration period in milliseconds
getMaxPeers
static int getMaxPeers(int torrentCount) The dynamic ceiling for the global peer store: a fixed base allowance plus a per-torrent budget, so torrents loaded at runtime get their share rather than contending for one fixed cap. The per-torrent LRU trim and the ABSOLUTE_MAX_PER_TORRENT admission cap are the real limiters; this is a backstop for many simultaneously large swarms.- Parameters:
torrentCount- how many torrents have stored peers- Returns:
- the peer-count threshold above which expiration is tightened
start
public void start()Mark the tracker live and start the timer that expires stale torrents and peers.stop
void stop()Stop the tracker.announce
unannounce
getPeers
Fetch peers for a torrent. Caller's responsibility to remove himself from the list.- Parameters:
ih- the info hash of the torrentmax- maximum number of peers to returnnoSeeds- true if we do not want seeds in the result- Returns:
- list or empty list (never null)
getBloomFilters
Build BEP 33 bloom filters for a torrent, one for the stored seeds and one for the stored peers, by inserting the 32-byte destination hash of each peer into the appropriate filter.- Parameters:
ih- the info hash of the torrent- Returns:
- two-element array with the seeds filter first, or null if there are no entries for the torrent
renderStatusHTML
Debug info, HTML formatted.- Parameters:
buf- the buffer to append HTML to