Search in sources :

Example 1 with UniqueId

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;
}
Also used : Destination(net.i2p.data.Destination) UniqueId(i2p.bote.UniqueId) DeletionQuery(i2p.bote.packet.dht.DeletionQuery) DeletionInfoPacket(i2p.bote.packet.dht.DeletionInfoPacket) DeletionRecord(i2p.bote.packet.dht.DeletionRecord) DhtStorageHandler(i2p.bote.network.DhtStorageHandler) PacketBatch(i2p.bote.network.PacketBatch) DataPacket(i2p.bote.packet.DataPacket) DeletionAwareDhtFolder(i2p.bote.folder.DeletionAwareDhtFolder)

Example 2 with UniqueId

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);
            }
    }
}
Also used : UniqueId(i2p.bote.UniqueId) PacketInfo(i2p.bote.email.EmailMetadata.PacketInfo) EmailMetadata(i2p.bote.email.EmailMetadata) PasswordException(i2p.bote.fileencryption.PasswordException)

Example 3 with UniqueId

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;
}
Also used : UniqueId(i2p.bote.UniqueId)

Example 4 with UniqueId

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());
        }
    }
}
Also used : UniqueId(i2p.bote.UniqueId) ResponsePacket(i2p.bote.packet.ResponsePacket) DataPacket(i2p.bote.packet.DataPacket) EmptyResponse(i2p.bote.packet.EmptyResponse)

Example 5 with UniqueId

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");
}
Also used : UniqueId(i2p.bote.UniqueId) EmailDestination(i2p.bote.email.EmailDestination) Destination(net.i2p.data.Destination) ByteArrayInputStream(java.io.ByteArrayInputStream) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) EmailDestination(i2p.bote.email.EmailDestination) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket) File(java.io.File) Before(org.junit.Before)

Aggregations

UniqueId (i2p.bote.UniqueId)25 ByteArrayInputStream (java.io.ByteArrayInputStream)9 Before (org.junit.Before)9 EncryptedEmailPacket (i2p.bote.packet.dht.EncryptedEmailPacket)7 EmailDestination (i2p.bote.email.EmailDestination)6 Hash (net.i2p.data.Hash)6 UnencryptedEmailPacket (i2p.bote.packet.dht.UnencryptedEmailPacket)5 File (java.io.File)5 DataPacket (i2p.bote.packet.DataPacket)3 DeletionInfoPacket (i2p.bote.packet.dht.DeletionInfoPacket)3 DhtStorablePacket (i2p.bote.packet.dht.DhtStorablePacket)3 EmailPacketDeleteRequest (i2p.bote.packet.dht.EmailPacketDeleteRequest)3 IOException (java.io.IOException)3 Destination (net.i2p.data.Destination)3 EmailIdentity (i2p.bote.email.EmailIdentity)2 DeletionAwareDhtFolder (i2p.bote.folder.DeletionAwareDhtFolder)2 DhtStorageHandler (i2p.bote.network.DhtStorageHandler)2 ResponsePacket (i2p.bote.packet.ResponsePacket)2 DeleteRequest (i2p.bote.packet.dht.DeleteRequest)2 DeletionQuery (i2p.bote.packet.dht.DeletionQuery)2