/** * Queries the DHT for the <code>k</code> peers closest to a given key. * This method blocks. * @see ClosestNodesLookupTask */ private List<Destination> getClosestNodes(Hash key) throws InterruptedException { bucketManager.updateLastLookupTime(key); ClosestNodesLookupTask lookupTask = new ClosestNodesLookupTask(key, sendQueue, i2pReceiver, bucketManager); return lookupTask.call(); }
private boolean hasTimedOut(long startTime, long timeout) { return getTime() > startTime + timeout; }
private boolean hasTimedOut(CommunicationPacket request, long timeout) { long sentTime = request.getSentTime(); return sentTime>0 && hasTimedOut(sentTime, timeout); }
logStatus(); startTime = getTime(); do { addLocalResults(key); else { FindClosePeersPacket packet = new FindClosePeersPacket(key); sendQueue.send(packet, peer); logStatus(); if (hasTimedOut(request.getValue(), REQUEST_TIMEOUT)) { Destination peer = request.getKey(); log.debug("FindCloseNodes request to peer " + Util.toShortenedBase32(peer) + " timed out."); } while (!isDone()); log.debug("Node lookup for " + key + " found " + responses.size() + " nodes (may include local node)."); synchronized (responses) { return getResults();
/** * Updates <code>notQueriedYet</code> with the <code>k</code> closest locally known peers.<br/> * This has the the same effect as sending a <code>FindClosePeersPacket</code> to the local destination, * but without the network round-trip. * @param key * @see IncomingPacketHandler#packetReceived(CommunicationPacket, Destination, long) */ private void addLocalResults(Hash key) { log.debug("Adding local results for key " + key.toBase64()); responses.add(localDestination); Collection<Destination> closestPeers = bucketManager.getClosestPeers(key, KademliaConstants.K); addPeersToBeQueried(closestPeers); }
ClosestNodesLookupTask lookupTask = new ClosestNodesLookupTask(localDestination.calculateHash(), sendQueue, i2pReceiver, bucketManager); List<Destination> closestNodes = lookupTask.call(); closestNodes.remove(localDestination);
if (hasTimedOut(startTime, CLOSEST_NODES_LOOKUP_TIMEOUT)) { log.debug("Lookup for closest nodes timed out."); return true;