java.lang.Object
net.i2p.router.networkdb.kademlia.FloodfillPeerSelector.FloodfillSelectionCollector
All Implemented Interfaces:
SelectionCollector<Hash>
Enclosing class:
FloodfillPeerSelector

private class FloodfillPeerSelector.FloodfillSelectionCollectorextends Object implements SelectionCollector<Hash>
Collector picking the closest floodfills.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final List<Hash>
    Floodfill hashes matching the search.
    private final Map<Hash, RouterInfo>
    Router infos cached during the search.
    private final Hash
    The hash being searched for.
    private int
    Matches counted so far.
    private final TreeSet<Hash>
    Candidate hashes, sorted by distance.
    private final Set<Hash>
    Hashes to skip in the search.
    private final int
    Matches wanted from the search.
    private static final int
    Extra matches the collector keeps beyond the wanted count.
  • Constructor Summary

    Constructors
    Constructor
    Description
    FloodfillSelectionCollector(Hash key, Set<Hash> toIgnore, int wanted)
    Warning - may return our router hash - add to toIgnore if necessary.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(Hash entry)
    Add an entry to the selection, skipping ignored, banlisted, or non-floodfill entries once enough matches have been collected.
    private RouterInfo
    Look up the RouterInfo for an entry, caching the result.
    get(int howMany)
    The first howMany matching entries, floodfills with the 'f' mark in their NetDb except for banlisted ones; non-floodfills only if there aren't enough floodfills.
    int
    Number of entries collected so far.

    Methods inherited from class Object

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

    • _sorted

      private final TreeSet<Hash> _sorted
      Candidate hashes, sorted by distance.
    • _floodfillMatches

      private final List<Hash> _floodfillMatches
      Floodfill hashes matching the search.
    • _key

      private final Hash _key
      The hash being searched for.
    • _toIgnore

      private final Set<Hash> _toIgnore
      Hashes to skip in the search.
    • _matches

      private int _matches
      Matches counted so far.
    • _wanted

      private final int _wanted
      Matches wanted from the search.
    • _infoCache

      private final Map<Hash, RouterInfo> _infoCache
      Router infos cached during the search.
    • EXTRA_MATCHES

      private static final int EXTRA_MATCHES
      Extra matches the collector keeps beyond the wanted count.
      See Also:
  • Constructor Details

    • FloodfillSelectionCollector

      public FloodfillSelectionCollector(Hash key, Set<Hash> toIgnore, int wanted)
      Warning - may return our router hash - add to toIgnore if necessary.
      Parameters:
      key - the ROUTING key (NOT the original key)
      toIgnore - can be null
      wanted - target match count; non-floodfill candidates stop being collected once matches reach wanted plus EXTRA_MATCHES
  • Method Details

    • add

      public void add(Hash entry)
      Add an entry to the selection, skipping ignored, banlisted, or non-floodfill entries once enough matches have been collected.
      Specified by:
      add in interface SelectionCollector<Hash>
      Parameters:
      entry - the candidate router hash
    • get

      public List<Hash> get(int howMany)
      The first howMany matching entries, floodfills with the 'f' mark in their NetDb except for banlisted ones; non-floodfills only if there aren't enough floodfills.

      The list is in 3 groups - unsorted (shuffled) within each group. Group 1: NetDb published less than 3h ago, no bad send in last 30m. Group 2: All others Group 3: Non-floodfills, sorted by closest-to-the-key.

      Parameters:
      howMany - the maximum number of entries to return
      Returns:
      the list of matching peer hashes
    • cachedInfo

      private RouterInfo cachedInfo(Hash entry)
      Look up the RouterInfo for an entry, caching the result. Null results are cached too, so unknown peers are not re-looked-up.
      Parameters:
      entry - the router hash
      Returns:
      the RouterInfo, or null if not found
    • size

      public int size()
      Number of entries collected so far.
      Returns:
      the match count