/** * @return a copy in a new set */ public Set<T> getAll(Set<T> toIgnore) { Set<T> all = getAll(); all.removeAll(toIgnore); return all; }
/** * 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. * * @param key the ROUTING key (NOT the original key) * @param peersToIgnore can be null * @return List of Hash for the peers selected */ List<Hash> selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets, boolean preferConnected) { if (peersToIgnore == null) peersToIgnore = Collections.singleton(_context.routerHash()); else peersToIgnore.add(_context.routerHash()); // TODO this is very slow FloodfillSelectionCollector matches = new FloodfillSelectionCollector(key, peersToIgnore, maxNumRouters); if (kbuckets == null) return new ArrayList<Hash>(); kbuckets.getAll(matches); List<Hash> rv = matches.get(maxNumRouters, preferConnected); if (_log.shouldLog(Log.DEBUG)) _log.debug("Searching for " + maxNumRouters + " peers close to " + key + ": " + rv + " (not including " + peersToIgnore + ") [allHashes.size = " + matches.size() + "]", new Exception("Search by")); return rv; }
/** * UNUSED - See FloodfillPeerSelector override * Ignore KBucket ordering and do the XOR explicitly per key. Runs in O(n*log(n)) * time (n=routing table size with c ~ 32 xor ops). This gets strict ordering * on closest * List will not include our own hash. * * @return List of Hash for the peers selected, ordered by bucket (but intra bucket order is not defined) */ List<Hash> selectNearestExplicitThin(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets) { if (peersToIgnore == null) peersToIgnore = new HashSet<Hash>(1); peersToIgnore.add(_context.routerHash()); MatchSelectionCollector matches = new MatchSelectionCollector(key, peersToIgnore); kbuckets.getAll(matches); List<Hash> rv = matches.get(maxNumRouters); if (_log.shouldLog(Log.DEBUG)) _log.debug("Searching for " + maxNumRouters + " peers close to " + key + ": " + rv + " (not including " + peersToIgnore + ") [allHashes.size = " + matches.size() + "]"); return rv; }
/** * 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 * * @param key the original key (NOT the routing key) * @param peersToIgnore can be null * @return List of Hash for the peers selected, ordered */ @Override List<Hash> selectNearest(Hash key, int maxNumRouters, Set<Hash> peersToIgnore, KBucketSet<Hash> kbuckets) { Hash rkey = _context.routingKeyGenerator().getRoutingKey(key); if (peersToIgnore != null && peersToIgnore.contains(Hash.FAKE_HASH)) { // return non-ff peersToIgnore.addAll(selectFloodfillParticipants(peersToIgnore, kbuckets)); // TODO this is very slow FloodfillSelectionCollector matches = new FloodfillSelectionCollector(rkey, peersToIgnore, maxNumRouters); kbuckets.getAll(matches); return matches.get(maxNumRouters); } else { // return ff return selectFloodfillParticipantsIncludingUs(rkey, maxNumRouters, peersToIgnore, kbuckets); } } }