java.lang.Object
net.i2p.router.networkdb.kademlia.StaleContactTrimmer
All Implemented Interfaces:
KBucketTrimmer<Hash>

class StaleContactTrimmerextends Object implements KBucketTrimmer<Hash>
Evicts the least-recently-attested peer from a full routing bucket so the netdb routing table rotates toward live peers instead of filling with dead-but-unexpired routers. Liveness is the newest of the peer profile's heard-about / heard-from / successful-send times. A peer with no profile counts as never seen. The oldest entry is only evicted when it is older than the grace window, otherwise the newcomer is rejected. Peers with an established session are never eviction candidates — same protection ExpireRoutersJob gives them.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final long
    How long an entry is protected from eviction even when stale.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Evict stale entries using this context's clock and peer profiles.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static long
    lastSeen(RouterContext context, Hash peer)
    The newest contact evidence for a peer, 0 when there is none.
    boolean
    trim(KBucket<Hash> kbucket, Hash toAdd)
    Called from add() just before adding the entry.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • GRACE

      static final long GRACE
      How long an entry is protected from eviction even when stale.
      See Also:
  • Constructor Details

    • StaleContactTrimmer

      StaleContactTrimmer(RouterContext context)
      Evict stale entries using this context's clock and peer profiles.
      Parameters:
      context - the router context, for the clock and profile organizer
  • Method Details

    • trim

      public boolean trim(KBucket<Hash> kbucket, Hash 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<Hash>
      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.
    • lastSeen

      static long lastSeen(RouterContext context, Hash peer)
      The newest contact evidence for a peer, 0 when there is none. Static and package-visible so ExpireRoutersJob scores staleness the same way.
      Parameters:
      context - the router context
      peer - the peer hash
      Returns:
      context time of the newest evidence, or 0