- All Implemented Interfaces:
KBucketTrimmer<NID>
Implements a conservative bucket trimming strategy that removes stale nodes while preserving recently active routing information. This trimmer follows Kademlia best practices by only removing nodes that haven't been seen for an extended period, and only when the bucket has been stable.
Trimming strategy:
- Only removes nodes not seen for MAX_NODE_AGE (30 minutes)
- Only trims if the bucket hasn't changed for MIN_BUCKET_AGE (5 minutes)
- Prioritizes keeping recently active nodes in the routing table
- Helps maintain DHT health by preventing premature eviction of good nodes
This conservative approach helps maintain DHT stability and prevents thrashing where nodes are frequently added and removed from buckets.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextSupplies the clock and the log.private final intBuckets kept before the farthest are trimmed away.private static final longMaximum age (30 minutes) for nodes before they become candidates for removal.private static final longMinimum time (5 minutes) a bucket must be unchanged before trimming is allowed.Constructor Summary
ConstructorsConstructorDescriptionKBTrimmer(I2PAppContext ctx, int max) Creates a new bucket trimmer with the specified maximum bucket size.Method Summary
All Methods
Field Details
_ctx
Supplies the clock and the log._max
private final int _maxBuckets kept before the farthest are trimmed away.MIN_BUCKET_AGE
private static final long MIN_BUCKET_AGEMinimum time (5 minutes) a bucket must be unchanged before trimming is allowed.MAX_NODE_AGE
private static final long MAX_NODE_AGEMaximum age (30 minutes) for nodes before they become candidates for removal.
Constructor Details
KBTrimmer
Creates a new bucket trimmer with the specified maximum bucket size.- Parameters:
ctx- the I2P application context for clock accessmax- the maximum number of entries allowed in a bucket
Method Details
trim
Attempts to trim a Kademlia bucket to make room for a new node.This method implements a conservative trimming strategy that only removes stale nodes under specific conditions. The trimming logic is designed to maintain DHT health by preserving recently active nodes while allowing removal of nodes that are likely no longer reachable.
Trimming conditions:
1. The bucket must not have changed for MIN_BUCKET_AGE (5 minutes)
2. Only nodes not seen for MAX_NODE_AGE (30 minutes) are candidates for removal
3. If no stale nodes are found, trimming only succeeds if bucket is under capacity- Specified by:
trimin interfaceKBucketTrimmer<NID>- Parameters:
kbucket- the Kademlia bucket to trimtoAdd- the node ID that will be added if trimming succeeds- Returns:
- true if trimming was successful and space is available for the new node, false otherwise