use of i2p.bote.UniqueId in project i2p.i2p-bote by i2p.
the class KademliaDHT method findDeleteAuthorizationKey.
@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);
DhtStorageHandler storageHandler = storageHandlers.get(EncryptedEmailPacket.class);
if (storageHandler instanceof DeletionAwareDhtFolder) {
DeletionAwareDhtFolder<?> folder = (DeletionAwareDhtFolder<?>) storageHandler;
UniqueId delAuthorization = folder.getDeleteAuthorization(dhtKey);
if (delAuthorization != null)
return delAuthorization;
} else
log.error("StorageHandler for EncryptedEmailPackets is not a DeletionAwareDhtFolder!");
// Send the DeletionQueries
PacketBatch batch = new PacketBatch();
for (Destination node : closeNodes) if (// local has already been taken care of
!localDestination.equals(node))
batch.putPacket(new DeletionQuery(dhtKey), node);
sendQueue.send(batch);
batch.awaitSendCompletion();
// wait for replies
batch.awaitFirstReply(RESPONSE_TIMEOUT, TimeUnit.SECONDS);
log.info(batch.getResponses().size() + " response packets received for deletion query for hash " + dhtKey);
sendQueue.remove(batch);
Map<Destination, DataPacket> responses = batch.getResponses();
for (DataPacket response : responses.values()) if (response instanceof DeletionInfoPacket) {
DeletionInfoPacket delInfo = (DeletionInfoPacket) response;
DeletionRecord delRecord = delInfo.getEntry(dhtKey);
if (delRecord != null) {
boolean valid = Util.isDeleteAuthorizationValid(verificationHash, delRecord.delAuthorization);
if (valid)
return delRecord.delAuthorization;
}
}
return null;
}
use of i2p.bote.UniqueId in project i2p.i2p-bote by i2p.
the class DeliveryChecker method checkDelivery.
/**
* Checks the DHT for all undelivered packets belonging to a given email.
* @param email
* @throws InterruptedException
*/
private void checkDelivery(Email email) throws InterruptedException {
EmailMetadata metadata = email.getMetadata();
Collection<PacketInfo> packets = metadata.getUndeliveredPacketKeys();
synchronized (sentFolder) {
boolean updateMetadata = false;
for (PacketInfo packet : packets) {
UniqueId delAuth = dht.findDeleteAuthorizationKey(packet.dhtKey, packet.delVerificationHash);
if (delAuth != null) {
metadata.setPacketDelivered(packet.dhtKey, true);
updateMetadata = true;
log.debug("Delivery of email packet with DHT key " + packet.dhtKey + " confirmed.");
}
}
if (updateMetadata)
try {
sentFolder.saveMetadata(email);
} catch (Exception e) {
log.error("Can't save email metadata.", e);
}
}
}
use of i2p.bote.UniqueId in project i2p.i2p-bote by i2p.
the class IndexPacketDeleteRequest method getIndividualRequest.
@Override
public DeleteRequest getIndividualRequest(Hash dhtKey) {
UniqueId delAuthorization = entries.get(dhtKey);
if (delAuthorization == null)
return null;
IndexPacketDeleteRequest indivRequest = new IndexPacketDeleteRequest(emailDestHash);
indivRequest.put(dhtKey, delAuthorization);
return indivRequest;
}
use of i2p.bote.UniqueId in project i2p.i2p-bote by i2p.
the class I2PSendQueue method packetReceived.
// Implementation of PacketListener
@Override
public void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime) {
if (packet instanceof ResponsePacket) {
UniqueId packetId = packet.getPacketId();
for (PacketBatch batch : runningBatches) if (batch.contains(packetId)) {
DataPacket payload = ((ResponsePacket) packet).getPayload();
if (payload != null)
batch.addResponse(sender, payload);
else
batch.addResponse(sender, new EmptyResponse());
}
}
}
use of i2p.bote.UniqueId in project i2p.i2p-bote by i2p.
the class EmailPacketFolderTest method setUp.
@Before
public void setUp() throws Exception {
File tempDir = new File(System.getProperty("java.io.tmpdir"));
testDir = new File(tempDir, "EmailPacketFolderTest-" + System.currentTimeMillis());
folderDir = new File(testDir, "dht_email_pkt");
packetFolder = new EmailPacketFolder(folderDir);
// make two UnencryptedEmailPackets with different contents
byte[] content1 = "test TEST test ABCDEFGH asdfsadfsadf 3487562384".getBytes();
byte[] content2 = "fdlkhgjfljh test 123456".getBytes();
byte[] messageIdBytes = new byte[] { -69, -24, -109, 1, 69, -122, -69, 113, -68, -90, 55, -28, 105, 97, 125, 70, 51, 58, 14, 2, -13, -53, 90, -29, 36, 67, 36, -94, -108, -125, 11, 123 };
UniqueId messageId = new UniqueId(messageIdBytes, 0);
int fragmentIndex = 0;
unencryptedPacket = new UnencryptedEmailPacket(new ByteArrayInputStream(content1), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
unencryptedPacket.setNumFragments(1);
unencryptedPacket2 = new UnencryptedEmailPacket(new ByteArrayInputStream(content2), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
unencryptedPacket.setNumFragments(1);
String base64Dest = "m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY";
recipient = new EmailDestination(base64Dest);
emailPacket = new EncryptedEmailPacket(unencryptedPacket, recipient);
sender = new Destination("X3oKYQJ~1EAz7B1ZYGSrOTIMCW5Rnn2Svoc38dx5D9~zvz8vqiWcH-pCqQDwLgPWl9RTBzHtTmZcGRPXIv54i0XWeUfX6rTPDQGuZsnBMM0xrkH2FNLNFaJa0NgW3uKXWpNj9AI1AXUXzK-2MYTYoaZHx5SBoCaKfAGMcFJvTON1~kopxBxdBF9Q7T4~PJ3I2LeU-ycmUlehe9N9bIu7adUGyPGVl8Ka-UxwQromoJ~vSWHHl8HkwcDkW--v9Aj~wvFqxqriFkB1EeBiThi3V4XtVY~GUP4IkRj9YZGTsSBf3eS4xwXgnYWlB7IvxAGBfHY9MCg3lbAa1Dg~1IH6rhtXxsXUtGcXsz9yMZTxXHd~rGo~JrXeM1y~Vcenpr6tJcum6pxevkKzzT0qDegGPH3Zhqz7sSeeIaJEcPBUAkX89csqyFWFIjTMm6yZp2rW-QYUnVNLNTjf7vndYUAEICogAkq~btqpIzrGEpm3Pr9F23br3SpbOmdxQxg51AMmAAAA");
}
Aggregations