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 Details

    • _ctx

      protected final I2PAppContext _ctx
      The app context, used for its random() source.
    • _max

      private final int _max
      Entries kept before the oldest are trimmed away.
  • Constructor Details

    • RandomTrimmer

      public RandomTrimmer(I2PAppContext ctx, int max)
      Retains the context and the bucket size limit.
      Parameters:
      ctx - the context, used for its random() source when picking an entry to drop
      max - the max entries
  • Method Details

    • trim

      public boolean trim(KBucket<T> kbucket, T toAdd)
      Description copied from interface: KBucketTrimmer
      Called 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:
      trim in interface KBucketTrimmer<T extends SimpleDataStructure>
      Parameters:
      kbucket - the kbucket that is now too big
      toAdd - the entry the bucket is about to accept
      Returns:
      true to actually add the entry.