java.lang.Object
org.klomp.snark.dht.DHTTracker

class DHTTrackerextends Object
The tracker stores peers, i.e. Dest hashes (not nodes).
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private class 
    Timer event expiring the tracked entries.
    private static class 
    Bloom 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

    Fields
    Modifier and Type
    Field
    Description
    private final I2PAppContext
    The app context.
    private long
    Age after which a tracked entry expires.
    Cached BEP 33 bloom filters per torrent, keyed by info hash.
    private final long
    How long built bloom filters are reused before being rebuilt.
    private boolean
    True while the tracker runs.
    private final Log
    Logger for the DHT tracker.
    private int
    Not current; updated by the cleaner.
    private int
    Not current; updated by the cleaner.
    private final Torrents
    The torrents whose peers are tracked.
    private static final int
    Most peers stored for one torrent.
    private static final long
    Stagger with other cleaners.
    private static final long
    Step adjusting the expire time by entry count.
    private static final long
    How long built bloom filters are reused before being rebuilt.
    private static final int
    Upper bound on cached filter entries; the swarm map holds up to MAX_TORRENTS.
    (package private) static final int
    Base allowance for the global peer store.
    (package private) static final int
    How many recent peers to retain per torrent; admission allows up to twice this between sweeps.
    private static final int
    Most torrents tracked at once.
    private static final long
    No guidance in BEP 5; Vuze is 8h.
  • Constructor Summary

    Constructors
    Constructor
    Description
    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 Type
    Method
    Description
    (package private) void
    announce(InfoHash ih, Hash hash, boolean isSeed)
    Announce 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 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.
    (package private) 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.
    (package private) List<Hash>
    getPeers(InfoHash ih, int max, boolean noSeeds)
    Fetch peers for a torrent.
    void
    Debug info, HTML formatted.
    void
    Mark the tracker live and start the timer that expires stale torrents and peers.
    (package private) void
    Stop the tracker.
    (package private) void
    Remove a peer from a torrent's peer list.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _context

      private final I2PAppContext _context
      The app context.
    • _torrents

      private final Torrents _torrents
      The torrents whose peers are tracked.
    • FILTER_CACHE_TIME

      private static final long FILTER_CACHE_TIME
      How long built bloom filters are reused before being rebuilt.
      See Also:
    • _filterCache

      private final Map<InfoHash, DHTTracker.FilterCache> _filterCache
      Cached BEP 33 bloom filters per torrent, keyed by info hash.
    • _filterCacheTime

      private final long _filterCacheTime
      How long built bloom filters are reused before being rebuilt.
    • _expireTime

      private long _expireTime
      Age after which a tracked entry expires.
    • _log

      private final Log _log
      Logger for the DHT tracker.
    • _isRunning

      private volatile boolean _isRunning
      True while the tracker runs.
    • _peerCount

      private int _peerCount
      Not current; updated by the cleaner.
    • _torrentCount

      private int _torrentCount
      Not current; updated by the cleaner.
    • CLEAN_TIME

      private static final long CLEAN_TIME
      Stagger with other cleaners.
      See Also:
    • MIN_EXPIRE_TIME

      private static final long MIN_EXPIRE_TIME
      No 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_TIME
      Step adjusting the expire time by entry count.
      See Also:
    • MAX_PEERS

      static final int MAX_PEERS
      Base allowance for the global peer store. The effective ceiling is this floor scaled up by MAX_PEERS_PER_TORRENT per torrent being tracked, see getMaxPeers(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_TORRENT
      How 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_TORRENT
      Most peers stored for one torrent.
      See Also:
    • MAX_TORRENTS

      private static final int MAX_TORRENTS
      Most torrents tracked at once.
      See Also:
    • MAX_FILTER_CACHE

      private static final int MAX_FILTER_CACHE
      Upper bound on cached filter entries; the swarm map holds up to MAX_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 context
      filterCacheTime - 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 cap MAX_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

      void announce(InfoHash ih, Hash hash, boolean isSeed)
      Announce a peer for a torrent.
      Parameters:
      ih - the info hash of the torrent
      hash - the peer's destination hash
      isSeed - true if the peer is a seed
    • unannounce

      void unannounce(InfoHash ih, Hash hash)
      Remove a peer from a torrent's peer list.
      Parameters:
      ih - the info hash of the torrent
      hash - the peer's destination hash
    • getPeers

      List<Hash> getPeers(InfoHash ih, int max, boolean noSeeds)
      Fetch peers for a torrent. Caller's responsibility to remove himself from the list.
      Parameters:
      ih - the info hash of the torrent
      max - maximum number of peers to return
      noSeeds - true if we do not want seeds in the result
      Returns:
      list or empty list (never null)
    • getBloomFilters

      BloomFilter[] getBloomFilters(InfoHash ih)
      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

      public void renderStatusHTML(StringBuilder buf)
      Debug info, HTML formatted.
      Parameters:
      buf - the buffer to append HTML to