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

class DHTNodesextends Object
All the nodes we know about, stored as a mapping from node ID to a Destination and Port.

And a real Kademlia routing table, which stores node IDs only.

  • Field Details

    • _context

      private final I2PAppContext _context
      The app context.
    • _expireTime

      private long _expireTime
      Age after which a cached node expires.
    • _log

      private final Log _log
      Logger for the DHT node cache.
    • _nodeMap

      private final ConcurrentHashMap<NID,NodeInfo> _nodeMap
      The known nodes, by node id.
    • _kad

      private final KBucketSet<NID> _kad
      The Kademlia buckets of the known nodes.
    • _isRunning

      private volatile boolean _isRunning
      True while the node cache runs.
    • CLEAN_TIME

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

      private static final long MAX_EXPIRE_TIME
      How long since last heard before deletion; BEP 5 says 15 minutes.
      See Also:
    • MIN_EXPIRE_TIME

      private static final long MIN_EXPIRE_TIME
      Shortest time before a node expires.
      See Also:
    • DELTA_EXPIRE_TIME

      private static final long DELTA_EXPIRE_TIME
      Step adjusting the expire time by node count.
      See Also:
    • MAX_PEERS

      private static final int MAX_PEERS
      Most nodes stored at once.
      See Also:
    • MAX_BUCKET_AGE

      private static final long MAX_BUCKET_AGE
      Buckets older than this are refreshed - BEP 5 says 15 minutes.
      See Also:
    • KAD_K

      private static final int KAD_K
      Nodes per Kademlia bucket.
      See Also:
    • KAD_B

      private static final int KAD_B
      Extra Kademlia buckets beyond the bucket size.
      See Also:
  • Constructor Details

    • DHTNodes

      public DHTNodes(I2PAppContext ctx, NID me)
      Create a new DHTNodes instance.
      Parameters:
      ctx - the I2P application context
      me - our own node ID
  • Method Details

    • start

      public void start()
      Start the DHT node manager.
    • stop

      public void stop()
      Stop the DHT node manager.
    • size

      public int size()
      Number of known nodes, not total net size.
      Returns:
      the size of the known-node map, not the Kademlia table
    • clear

      public void clear()
      Clear all known nodes and the routing table.
    • get

      public NodeInfo get(NID nid)
      The node with the given ID.
      Parameters:
      nid - the node ID to look up
      Returns:
      the node info, or null if not found
    • putIfAbsent

      public NodeInfo putIfAbsent(NodeInfo nInfo)
      Insert a node if absent.
      Parameters:
      nInfo - the node info to insert
      Returns:
      the old value if present, else null
    • remove

      public NodeInfo remove(NID nid)
      Remove a node by its ID.
      Parameters:
      nid - the node ID to remove
      Returns:
      the removed node info, or null if not found
    • values

      public Collection<NodeInfo> values()
      All known nodes.
      Returns:
      collection of all known node infos
    • findClosest

      public List<NodeInfo> findClosest(SHA1Hash h, int numWant)
      Find the closest nodes to a given hash or node ID.
      Parameters:
      h - either an InfoHash or a NID
      numWant - the maximum number of nodes to return
      Returns:
      list of closest node infos
    • getExploreKeys

      public List<NID> getExploreKeys()
      Random keys to explore for DHT maintenance.
      Returns:
      list of node IDs representing buckets that need refreshing
    • renderStatusHTML

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