public IndexPacket(byte[] data) { super(data); entries = new ArrayList<IndexPacketEntry>(); ByteBuffer buffer = ByteBuffer.wrap(data, HEADER_LENGTH, data.length-HEADER_LENGTH); try { destinationHash = readHash(buffer); int numEntries = buffer.getInt(); for (int i=0; i<numEntries; i++) { Hash emailPacketKey = readHash(buffer); Hash delVerificationHash = readHash(buffer); long storeTime = buffer.getInt() * 1000L; IndexPacketEntry entry = new IndexPacketEntry(emailPacketKey, delVerificationHash, 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."); }
public void put(Collection<EncryptedEmailPacket> emailPackets) { for (EncryptedEmailPacket emailPacket: emailPackets) { Hash emailPacketKey = emailPacket.getDhtKey(); Hash delVerificationHash = emailPacket.getDeleteVerificationHash(); IndexPacketEntry entry = new IndexPacketEntry(emailPacketKey, delVerificationHash); put(entry); } }
/** * Adds a new entry containing the DHT key and Delete Verification Hash of an Email Packet.<br/> * If an entry with the same DHT key exists already, nothing happens. * @param emailPacket */ public void put(EncryptedEmailPacket emailPacket) { Hash emailPacketKey = emailPacket.getDhtKey(); Hash delVerificationHash = emailPacket.getDeleteVerificationHash(); IndexPacketEntry newEntry = new IndexPacketEntry(emailPacketKey, delVerificationHash); put(newEntry); }