java.lang.Object
org.klomp.snark.dht.DHTNodes
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.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classTimer event expiring the cached nodes.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextThe app context.private longAge after which a cached node expires.private booleanTrue while the node cache runs.private final KBucketSet<NID> The Kademlia buckets of the known nodes.private final LogLogger for the DHT node cache.private final ConcurrentHashMap<NID, NodeInfo> The known nodes, by node id.private static final longStagger with other cleaners.private static final longStep adjusting the expire time by node count.private static final intExtra Kademlia buckets beyond the bucket size.private static final intNodes per Kademlia bucket.private static final longBuckets older than this are refreshed - BEP 5 says 15 minutes.private static final longHow long since last heard before deletion; BEP 5 says 15 minutes.private static final intMost nodes stored at once.private static final longShortest time before a node expires.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionvoidclear()Clear all known nodes and the routing table.findClosest(SHA1Hash h, int numWant) Find the closest nodes to a given hash or node ID.The node with the given ID.Random keys to explore for DHT maintenance.putIfAbsent(NodeInfo nInfo) Insert a node if absent.Remove a node by its ID.voidDebug info, HTML formatted.intsize()Number of known nodes, not total net size.voidstart()Start the DHT node manager.voidstop()Stop the DHT node manager.values()All known nodes.
Field Details
_context
The app context._expireTime
private long _expireTimeAge after which a cached node expires._log
Logger for the DHT node cache._nodeMap
The known nodes, by node id._kad
The Kademlia buckets of the known nodes._isRunning
private volatile boolean _isRunningTrue while the node cache runs.CLEAN_TIME
MAX_EXPIRE_TIME
private static final long MAX_EXPIRE_TIMEHow long since last heard before deletion; BEP 5 says 15 minutes.- See Also:
MIN_EXPIRE_TIME
private static final long MIN_EXPIRE_TIMEShortest time before a node expires.- See Also:
DELTA_EXPIRE_TIME
private static final long DELTA_EXPIRE_TIMEStep adjusting the expire time by node count.- See Also:
MAX_PEERS
MAX_BUCKET_AGE
private static final long MAX_BUCKET_AGEBuckets older than this are refreshed - BEP 5 says 15 minutes.- See Also:
KAD_K
KAD_B
private static final int KAD_BExtra Kademlia buckets beyond the bucket size.- See Also:
Constructor Details
DHTNodes
Create a new DHTNodes instance.- Parameters:
ctx- the I2P application contextme- 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
putIfAbsent
remove
values
findClosest
getExploreKeys
renderStatusHTML
Debug info, HTML formatted.- Parameters:
buf- the buffer to append HTML to