class KBTrimmer extends Object implements 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 older than 15 minutes
- Only trims if the bucket hasn't changed in the last 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.
| Constructor and Description |
|---|
KBTrimmer(I2PAppContext ctx,
int max)
Creates a new bucket trimmer with the specified maximum bucket size.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
trim(KBucket<NID> kbucket,
NID toAdd)
Attempts to trim a Kademlia bucket to make room for a new node.
|
public KBTrimmer(I2PAppContext ctx, int max)
ctx - the I2P application context for clock accessmax - the maximum number of entries allowed in a bucketpublic boolean trim(KBucket<NID> kbucket, NID toAdd)
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 in the last 5 minutes
2. Only nodes not seen in the last 15 minutes are candidates for removal
3. If no stale nodes are found, trimming only succeeds if bucket is under capacity
trim in interface KBucketTrimmer<NID>kbucket - the Kademlia bucket to trimtoAdd - the node ID that will be added if trimming succeeds