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
FieldsModifier and TypeFieldDescriptionFloodfill hashes matching the search.private final Map<Hash, RouterInfo> Router infos cached during the search.private final HashThe hash being searched for.private intMatches counted so far.Candidate hashes, sorted by distance.Hashes to skip in the search.private final intMatches wanted from the search.private static final intExtra matches the collector keeps beyond the wanted count.Constructor Summary
ConstructorsConstructorDescriptionFloodfillSelectionCollector(Hash key, Set<Hash> toIgnore, int wanted) Warning - may return our router hash - add to toIgnore if necessary.Method Summary
Modifier and TypeMethodDescriptionvoidAdd an entry to the selection, skipping ignored, banlisted, or non-floodfill entries once enough matches have been collected.private RouterInfocachedInfo(Hash entry) 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.intsize()Number of entries collected so far.
Field Details
_sorted
_floodfillMatches
_key
The hash being searched for._toIgnore
_matches
private int _matchesMatches counted so far._wanted
private final int _wantedMatches wanted from the search._infoCache
Router infos cached during the search.EXTRA_MATCHES
private static final int EXTRA_MATCHESExtra matches the collector keeps beyond the wanted count.- See Also:
Constructor Details
FloodfillSelectionCollector
Warning - may return our router hash - add to toIgnore if necessary.- Parameters:
key- the ROUTING key (NOT the original key)toIgnore- can be nullwanted- target match count; non-floodfill candidates stop being collected once matches reach wanted plusEXTRA_MATCHES
Method Details
add
Add an entry to the selection, skipping ignored, banlisted, or non-floodfill entries once enough matches have been collected.- Specified by:
addin interfaceSelectionCollector<Hash>- Parameters:
entry- the candidate router hash
get
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
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