java.lang.Object
net.i2p.kademlia.RandomTrimmer<T>
- Type Parameters:
T- type of SimpleDataStructure objects in the bucket
- All Implemented Interfaces:
KBucketTrimmer<T>
- Direct Known Subclasses:
RandomIfOldTrimmer
public class RandomTrimmer<T extends SimpleDataStructure>extends Object implements KBucketTrimmer<T>
Removes a random element. Not resistant to flooding.
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final I2PAppContextThe app context, used for its random() source.private final intEntries kept before the oldest are trimmed away.Constructor Summary
ConstructorsConstructorDescriptionRandomTrimmer(I2PAppContext ctx, int max) Retains the context and the bucket size limit.Method Summary
All Methods
Field Details
_ctx
The app context, used for its random() source._max
private final int _maxEntries kept before the oldest are trimmed away.
Constructor Details
RandomTrimmer
Retains the context and the bucket size limit.- Parameters:
ctx- the context, used for itsrandom()source when picking an entry to dropmax- the max entries
Method Details
trim
Description copied from interface:KBucketTrimmerCalled from add() just before adding the entry. You may call getEntries() and/or remove() from here. Do NOT call add(). To always discard a newer entry, always return false.- Specified by:
trimin interfaceKBucketTrimmer<T extends SimpleDataStructure>- Parameters:
kbucket- the kbucket that is now too bigtoAdd- the entry the bucket is about to accept- Returns:
- true to actually add the entry.