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());
}
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()));
}
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()));
}
Aggregations