public Hash getKey() { return packetToStore.getDhtKey(); }
/** * Informs the <code>ReplicationThread</code> that a packet has been stored in a local folder. * @param folder * @param packet */ public void packetStored(DhtStorageHandler folder, DhtStorablePacket packet) { keysToSkip.add(packet.getDhtKey()); }
@Override public void store(DhtStorablePacket packetToStore) { add(packetToStore, getFilename(packetToStore.getDhtKey())); }
@Override public DeleteRequest storeAndCreateDeleteRequest(DhtStorablePacket packetToStore) { if (!(packetToStore instanceof EncryptedEmailPacket)) throw new IllegalArgumentException("Invalid packet type: " + packetToStore.getClass().getSimpleName() + "; this folder only stores packets of type " + EncryptedEmailPacket.class.getSimpleName() + "."); DeleteRequest delRequest = null; // read the deletion info file for the email packet's DHT key Hash dhtKey = packetToStore.getDhtKey(); String delFileName = getDeletionFileName(dhtKey); DeletionInfoPacket delInfo = createDelInfoPacket(delFileName); if (delInfo != null) { DeletionRecord delRecord = delInfo.getEntry(dhtKey); if (delRecord != null) delRequest = new EmailPacketDeleteRequest(delRecord.dhtKey, delRecord.delAuthorization); } else // if the DHT key has not been recorded as deleted, store the email packet store(packetToStore); return delRequest; } }
@Override public void store(DhtStorablePacket packetToStore) { File packetFile = findPacketFile(packetToStore.getDhtKey()); if (packetFile != null) log.debug("Not storing directory packet with DHT key " + packetToStore.getDhtKey() + " because file exists."); else { if (!(packetToStore instanceof Contact)) log.error("Expected class Contact, got " + packetToStore.getClass()); else { Contact contact = (Contact)packetToStore; try { if (!contact.verify()) log.debug("Not storing Contact because verification failed."); else super.store(packetToStore); } catch (GeneralSecurityException e) { log.error("Can't verify Contact", e); } } } } }
@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); }
for (Iterator<? extends DhtStorablePacket> packetIterator=dhtStore.individualPackets(); packetIterator.hasNext(); ) { DhtStorablePacket packet = packetIterator.next(); Hash dhtKey = packet.getDhtKey(); if (!keysToSkip.contains(dhtKey)) { StoreRequest request = new StoreRequest(packet);
DhtStorablePacket existingPacket = super.retrieve(packetToStore.getDhtKey()); // use super.retrieve() because we don't want to delete time stamps here String delFileName = getDeletionFileName(packetToStore.getDhtKey()); DeletionInfoPacket delInfo = createDelInfoPacket(delFileName); IndexPacketDeleteRequest delRequest = null;