private void refresh(KBucket bucket) throws InterruptedException { Hash key = createRandomHash(bucket.getStartId(), bucket.getEndId()); getClosestNodes(key); }
private void refresh(BucketSection section) throws InterruptedException { Hash key = createRandomHash(section.getStart(), section.getEnd()); getClosestNodes(key); }
@Override public void store(DhtStorablePacket packet) throws DhtException, InterruptedException { Hash key = packet.getDhtKey(); log.info("Looking up nodes to store a " + packet.getClass().getSimpleName() + " with key " + key); List<Destination> closeNodes = getClosestNodes(key); if (closeNodes.isEmpty()) throw new DhtException("Cannot store packet because no storage nodes found."); // store on local node if appropriate if (!closeNodes.contains(localDestination)) if (closeNodes.size()<KademliaConstants.K || isCloser(localDestination, closeNodes.get(0), key)) closeNodes.add(localDestination); log.info("Storing a " + packet.getClass().getSimpleName() + " with key " + key + " on " + closeNodes.size() + " nodes"); PacketBatch batch = new PacketBatch(); for (Destination node: closeNodes) if (localDestination.equals(node)) storeLocally(packet, null); else { StoreRequest storeRequest = new StoreRequest(packet); // use a separate packet id for each request batch.putPacket(storeRequest, node); } sendQueue.send(batch); batch.awaitSendCompletion(); // TODO awaitAllResponses, repeat if necessary sendQueue.remove(batch); }
private DhtResults find(Hash key, Class<? extends DhtStorablePacket> dataType, boolean exhaustive) throws InterruptedException { final Collection<Destination> closeNodes = getClosestNodes(key); log.info("Querying localhost + " + closeNodes.size() + " peers for data type " + dataType.getSimpleName() + ", Kademlia key " + key);
@Override public UniqueId findDeleteAuthorizationKey(Hash dhtKey, Hash verificationHash) throws InterruptedException { final Collection<Destination> closeNodes = getClosestNodes(dhtKey); log.info("Querying " + closeNodes.size() + " peers with DeletionQueries for Kademlia key " + dhtKey);