net.i2p.router.networkdb.kademlia

## Class FloodfillPeerSelector

- java.lang.Object
- - net.i2p.router.networkdb.kademlia.PeerSelector
  - - net.i2p.router.networkdb.kademlia.FloodfillPeerSelector

-     class FloodfillPeerSelector
      extends PeerSelector

  This is where we implement semi-Kademlia with the floodfills, by selecting floodfills closest to a given key for searches and stores. Warning - most methods taking a key as an argument require the routing key, not the original key.

- - ### Field Summary

    - ### Fields inherited from class net.i2p.router.networkdb.kademlia.PeerSelector

      `_context, _log`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FloodfillPeerSelector(RouterContext ctx)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) List<Hash>` | `selectFloodfillParticipants(Hash key, int maxNumRouters, KBucketSet<Hash> kbuckets)` Sort the floodfills.
    `(package private) List<Hash>` | `selectFloodfillParticipants(Hash key, int howMany, Set<Hash> toIgnore, KBucketSet<Hash> kbuckets)` See above for description List will not include our own hash Returns new list, may be modified.
    `(package private) List<Hash>` | `selectFloodfillParticipants(KBucketSet<Hash> kbuckets)` List will not include our own hash.
    `(package private) List<Hash>` | `selectMostReliablePeers(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets)` Pick out peers with the floodfill capacity set, returning them first, but then after they're complete, sort via kademlia.
    `(package private) List<Hash>` | `selectNearest(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets)` Floodfill peers only.
    `(package private) List<Hash>` | `selectNearestExplicit(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets)` Pick out peers with the floodfill capacity set, returning them first, but then after they're complete, sort via kademlia.
    `(package private) List<Hash>` | `selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets)`
    `(package private) List<Hash>` | `selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets, boolean preferConnected)` Pick out peers with the floodfill capacity set, returning them first, but then after they're complete, sort via kademlia.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### FloodfillPeerSelector

          public FloodfillPeerSelector(RouterContext ctx)

  - ### Method Detail

    - #### selectFloodfillParticipants

          List<Hash> selectFloodfillParticipants(Hash key,
                                                 int maxNumRouters,
                                                 KBucketSet<Hash> kbuckets)

      Sort the floodfills. The challenge here is to keep the good ones at the front and the bad ones at the back. If they are all good or bad, searches and stores won't work well. List will not include our own hash. Returns new list, may be modified.
      Parameters:
        `key` - the ROUTING key (NOT the original key)
        `maxNumRouters` - max to return
        `kbuckets` - now unused Sorted by closest to the key if > maxNumRouters, otherwise not The list is in 3 groups - sorted by routing key within each group. Group 1: No store or lookup failure in a long time, and lookup fail rate no more than 1.5 * average Group 2: No store or lookup failure in a little while or success newer than failure Group 3: All others
      Returns:
        floodfills closest to the key that are not banlisted forever

    - #### selectFloodfillParticipants

          List<Hash> selectFloodfillParticipants(Hash key,
                                                 int howMany,
                                                 Set<Hash> toIgnore,
                                                 KBucketSet<Hash> kbuckets)

      See above for description List will not include our own hash Returns new list, may be modified.
      Parameters:
        `key` - the ROUTING key (NOT the original key)
        `toIgnore` - can be null
        `kbuckets` - now unused

    - #### selectFloodfillParticipants

          List<Hash> selectFloodfillParticipants(KBucketSet<Hash> kbuckets)

      List will not include our own hash. List is not sorted and not shuffled. Returns new list, may be modified.
      Parameters:
        `kbuckets` - now unused
      Returns:
        all floodfills not banlisted forever.

    - #### selectMostReliablePeers

          List<Hash> selectMostReliablePeers(Hash key,
                                             int maxNumRouters,
                                             Set<Hash> peersToIgnore,
                                             KBucketSet<Hash> kbuckets)

      Pick out peers with the floodfill capacity set, returning them first, but then after they're complete, sort via kademlia. Puts the floodfill peers that are directly connected first in the list. List will not include our own hash. Returns new list, may be modified.
      Specified by:
        `selectMostReliablePeers` in class `PeerSelector`
      Parameters:
        `key` - the ROUTING key (NOT the original key)
        `peersToIgnore` - can be null
      Returns:
        List of Hash for the peers selected

    - #### selectNearest

          List<Hash> selectNearest(Hash key,
                                   int maxNumRouters,
                                   Set<Hash> peersToIgnore,
                                   KBucketSet<Hash> kbuckets)

      Floodfill peers only. Used only by HandleDatabaseLookupMessageJob to populate the DSRM. UNLESS peersToIgnore contains Hash.FAKE_HASH (all zeros), in which case this is an exploratory lookup, and the response should not include floodfills. List MAY INCLUDE our own router - add to peersToIgnore if you don't want
      Specified by:
        `selectNearest` in class `PeerSelector`
      Parameters:
        `key` - the original key (NOT the routing key)
        `peersToIgnore` - can be null
      Returns:
        List of Hash for the peers selected, ordered

    - #### selectNearestExplicit

          List<Hash> selectNearestExplicit(Hash key,
                                           int maxNumRouters,
                                           Set<Hash> peersToIgnore,
                                           KBucketSet<Hash> kbuckets)

      Pick out peers with the floodfill capacity set, returning them first, but then after they're complete, sort via kademlia. Does not prefer the floodfill peers that are directly connected. List will not include our own hash. Returns new list, may be modified.
      Specified by:
        `selectNearestExplicit` in class `PeerSelector`
      Parameters:
        `key` - the ROUTING key (NOT the original key)
        `peersToIgnore` - can be null
      Returns:
        List of Hash for the peers selected

    - #### selectNearestExplicitThin

          List<Hash> selectNearestExplicitThin(Hash key,
                                               int maxNumRouters,
                                               Set<Hash> peersToIgnore,
                                               KBucketSet<Hash> kbuckets)

      Specified by:
        `selectNearestExplicitThin` in class `PeerSelector`

    - #### selectNearestExplicitThin

          List<Hash> selectNearestExplicitThin(Hash key,
                                               int maxNumRouters,
                                               Set<Hash> peersToIgnore,
                                               KBucketSet<Hash> kbuckets,
                                               boolean preferConnected)

      Pick out peers with the floodfill capacity set, returning them first, but then after they're complete, sort via kademlia. List will not include our own hash. Returns new list, may be modified.
      Parameters:
        `key` - the ROUTING key (NOT the original key)
        `peersToIgnore` - can be null
      Returns:
        List of Hash for the peers selected