/** * Adds a DHT key to the list of deleted packets and sets the delete authorization key. * If the key is already on the list, nothing happens. * @param delFileName * @param dhtKey * @param delAuthorization */ protected void addToDeletedPackets(String delFileName, Hash dhtKey, UniqueId delAuthorization) { DeletionInfoPacket packet = createDelInfoPacket(delFileName); if (packet == null) { log.debug("Creating a new Deletion Info Packet file: <" + delFileName + ">"); packet = new DeletionInfoPacket(); } packet.put(dhtKey, delAuthorization); add(packet, delFileName); }
/** * Adds an entry to the <code>DeletionInfoPacket</code>. If an entry with the same DHT key * exists in the packet already, nothing happens. * @param dhtKey * @param delAuthorization */ public void put(Hash dhtKey, UniqueId delAuthorization) { if (contains(dhtKey)) return; DeletionRecord entry = new DeletionRecord(dhtKey, delAuthorization); entries.add(entry); }
/** * Tests if the <code>DeletionInfoPacket</code> contains a given DHT key. * @param dhtKey * @return <code>true</code> if the packet containes the DHT key, <code>false</code> otherwise. */ public boolean contains(Hash dhtKey) { return getEntry(dhtKey) != null; }
assertTrue(dataPacket instanceof DeletionInfoPacket); DeletionInfoPacket delInfoPacket = (DeletionInfoPacket)dataPacket; Iterator<DeletionRecord> delPacketIterator = delInfoPacket.iterator(); assertTrue("DeletionInfoPacket has no elements!", delPacketIterator.hasNext()); delPacketIterator.next();
@Override public byte[] toByteArray() { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); try { writeHeader(dataStream); dataStream.writeInt(entries.size()); for (DeletionRecord entry: entries) { dataStream.write(entry.dhtKey.toByteArray()); dataStream.write(entry.delAuthorization.toByteArray()); dataStream.writeInt((int)(entry.storeTime/1000L)); // store as seconds } } catch (IOException e) { log.error("Can't write to ByteArrayOutputStream/DataOutputStream.", e); } return byteStream.toByteArray(); }
public DeletionInfoPacket(byte[] data) { super(data); entries = new ArrayList<DeletionRecord>(); ByteBuffer buffer = ByteBuffer.wrap(data, HEADER_LENGTH, data.length-HEADER_LENGTH); try { int numEntries = buffer.getInt(); for (int i=0; i<numEntries; i++) { Hash dhtKey = readHash(buffer); UniqueId delAuthentication = new UniqueId(buffer); long storeTime = buffer.getInt() * 1000L; DeletionRecord entry = new DeletionRecord(dhtKey, delAuthentication, storeTime); entries.add(entry); } } catch (BufferUnderflowException e) { log.error("Not enough bytes in packet.", e); } if (buffer.hasRemaining()) log.debug("Extra bytes in Index Packet data."); }
assertTrue(dataPacket instanceof DeletionInfoPacket); DeletionInfoPacket delInfoPacket = (DeletionInfoPacket)dataPacket; Iterator<DeletionRecord> delPacketIterator = delInfoPacket.iterator(); assertTrue("DeletionInfoPacket has no elements!", delPacketIterator.hasNext()); delPacketIterator.next();
DeletionInfoPacket delInfo = new DeletionInfoPacket(); delInfo.put(dhtKey, delAuthorization); Collection<ResponsePacket> response = ResponsePacket.create(delInfo, StatusCode.OK, packet.getPacketId()); sendQueue.send(response, sender);
@Override public UniqueId getDeleteAuthorization(Hash dhtKey) { String delFileName = getDeletionFileName(dhtKey); DeletionInfoPacket delInfo = createDelInfoPacket(delFileName); if (delInfo != null) { DeletionRecord delRecord = delInfo.getEntry(dhtKey); if (delRecord != null) return delRecord.delAuthorization; } return null; }
@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; } }
if (response instanceof DeletionInfoPacket) { DeletionInfoPacket delInfo = (DeletionInfoPacket)response; DeletionRecord delRecord = delInfo.getEntry(dhtKey); if (delRecord != null) { boolean valid = Util.isDeleteAuthorizationValid(verificationHash, delRecord.delAuthorization);