Search in sources :

Example 11 with DhtStorablePacket

use of i2p.bote.packet.dht.DhtStorablePacket in project i2p.i2p-bote by i2p.

the class IndexPacketFolder method process.

/**
 * Deletes index packet entries.
 * @param delRequest An instance of {@link IndexPacketDeleteRequest}
 */
@Override
public synchronized void process(DeleteRequest delRequest) {
    log.debug("Processing delete request: " + delRequest);
    if (!(delRequest instanceof IndexPacketDeleteRequest))
        log.error("Invalid type of delete request for IndexPacketFolder: " + delRequest.getClass());
    IndexPacketDeleteRequest indexPacketDelRequest = (IndexPacketDeleteRequest) delRequest;
    Hash destHash = indexPacketDelRequest.getEmailDestHash();
    DhtStorablePacket storedPacket = retrieve(destHash);
    if (storedPacket instanceof IndexPacket) {
        IndexPacket indexPacket = (IndexPacket) storedPacket;
        Collection<Hash> keysToDelete = indexPacketDelRequest.getDhtKeys();
        for (Hash keyToDelete : keysToDelete) {
            // verify
            Hash verificationHash = indexPacket.getDeleteVerificationHash(keyToDelete);
            if (verificationHash == null)
                log.debug("Email packet key " + keyToDelete + " from IndexPacketDeleteRequest not found in index packet for destination " + destHash);
            else {
                UniqueId delAuthorization = indexPacketDelRequest.getDeleteAuthorization(keyToDelete);
                boolean valid = Util.isDeleteAuthorizationValid(verificationHash, delAuthorization);
                if (valid)
                    remove(indexPacket, keyToDelete, delAuthorization);
                else
                    log.debug("Invalid delete verification hash in IndexPacketDeleteRequest. Should be: <" + verificationHash.toBase64() + ">");
            }
        }
    } else if (storedPacket != null)
        log.debug("IndexPacket expected for DHT key <" + destHash + ">, found " + storedPacket.getClass().getSimpleName());
}
Also used : DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) IndexPacketDeleteRequest(i2p.bote.packet.dht.IndexPacketDeleteRequest) UniqueId(i2p.bote.UniqueId) IndexPacket(i2p.bote.packet.dht.IndexPacket) Hash(net.i2p.data.Hash)

Example 12 with DhtStorablePacket

use of i2p.bote.packet.dht.DhtStorablePacket in project i2p.i2p-bote by i2p.

the class OutboxProcessorTest method testSendEmail.

@Test
public void testSendEmail() throws Exception {
    EmailIdentity identity = TestUtil.createTestIdentities().get(0).identity;
    String address = "tester <" + identity.getKey() + ">";
    when(identities.extractIdentity(address)).thenReturn(identity);
    testEmail = new Email(true);
    testEmail.setFrom(new InternetAddress(address));
    testEmail.addRecipient(RecipientType.TO, new InternetAddress("Erika Mustermann <m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY>"));
    testEmail.setSubject("Test", "UTF-8");
    testEmail.setText("foobar");
    op.sendEmail(testEmail);
    ArgumentCaptor<DhtStorablePacket> arg = ArgumentCaptor.forClass(DhtStorablePacket.class);
    verify(dht, times(2)).store(arg.capture());
    List<DhtStorablePacket> values = arg.getAllValues();
    assertTrue(values.get(0) instanceof EncryptedEmailPacket);
    assertTrue(values.get(1) instanceof IndexPacket);
    assertTrue(((IndexPacket) values.get(1)).contains(((EncryptedEmailPacket) values.get(0)).getDhtKey()));
}
Also used : DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) InternetAddress(javax.mail.internet.InternetAddress) Email(i2p.bote.email.Email) EmailIdentity(i2p.bote.email.EmailIdentity) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) IndexPacket(i2p.bote.packet.dht.IndexPacket) Test(org.junit.Test)

Example 13 with DhtStorablePacket

use of i2p.bote.packet.dht.DhtStorablePacket in project i2p.i2p-bote by i2p.

the class OutboxProcessorTest method testSendAnonymousEmail.

@Test
public void testSendAnonymousEmail() throws Exception {
    testEmail = new Email(true);
    testEmail.setFrom(new InternetAddress("anonymous"));
    testEmail.addRecipient(RecipientType.TO, new InternetAddress("Erika Mustermann <m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY>"));
    testEmail.setSubject("Test", "UTF-8");
    testEmail.setText("foobar");
    op.sendEmail(testEmail);
    ArgumentCaptor<DhtStorablePacket> arg = ArgumentCaptor.forClass(DhtStorablePacket.class);
    verify(dht, times(2)).store(arg.capture());
    List<DhtStorablePacket> values = arg.getAllValues();
    assertTrue(values.get(0) instanceof EncryptedEmailPacket);
    assertTrue(values.get(1) instanceof IndexPacket);
    assertTrue(((IndexPacket) values.get(1)).contains(((EncryptedEmailPacket) values.get(0)).getDhtKey()));
}
Also used : DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) InternetAddress(javax.mail.internet.InternetAddress) Email(i2p.bote.email.Email) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) IndexPacket(i2p.bote.packet.dht.IndexPacket) Test(org.junit.Test)

Aggregations

DhtStorablePacket (i2p.bote.packet.dht.DhtStorablePacket)13 IndexPacket (i2p.bote.packet.dht.IndexPacket)6 Hash (net.i2p.data.Hash)6 EncryptedEmailPacket (i2p.bote.packet.dht.EncryptedEmailPacket)4 UniqueId (i2p.bote.UniqueId)3 DhtResults (i2p.bote.network.DhtResults)3 DeleteRequest (i2p.bote.packet.dht.DeleteRequest)3 DeletionInfoPacket (i2p.bote.packet.dht.DeletionInfoPacket)3 IndexPacketDeleteRequest (i2p.bote.packet.dht.IndexPacketDeleteRequest)3 StoreRequest (i2p.bote.packet.dht.StoreRequest)3 Destination (net.i2p.data.Destination)3 Test (org.junit.Test)3 Email (i2p.bote.email.Email)2 DhtStorageHandler (i2p.bote.network.DhtStorageHandler)2 DataPacket (i2p.bote.packet.DataPacket)2 DeletionRecord (i2p.bote.packet.dht.DeletionRecord)2 RetrieveRequest (i2p.bote.packet.dht.RetrieveRequest)2 InternetAddress (javax.mail.internet.InternetAddress)2 EmailIdentity (i2p.bote.email.EmailIdentity)1 DeletionAwareDhtFolder (i2p.bote.folder.DeletionAwareDhtFolder)1