Search in sources :

Example 6 with EncryptedEmailPacket

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

the class IndexPacketFolderTest method setUp.

@Before
public void setUp() throws Exception {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    testDir = new File(tempDir, "IndexPacketFolderTest-" + System.currentTimeMillis());
    folderDir = new File(testDir, "dht_index_pkt");
    folder = new SettableStoreTimeIndexPacketFolder(folderDir);
    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;
    unencryptedPacket1 = new UnencryptedEmailPacket(new ByteArrayInputStream(content1), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    unencryptedPacket1.setNumFragments(1);
    unencryptedPacket2 = new UnencryptedEmailPacket(new ByteArrayInputStream(content2), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    unencryptedPacket2.setNumFragments(1);
    destination1 = new EmailDestination("2XP9Ep3WWLk3-FTlMgUjgw4h8GYVBCvR6YrPyKdhP4xyQMSh8Da0VjZCmQGbD3PCeaGXAShBKbKjhJjQ7laekI");
    destination2 = new EmailDestination("m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY");
    destination3 = new EmailDestination("0XuJjhgp58aOhvHHgpaxoQYsCUfDS6BECMEoVxFGEFPdk3y8lbzIsq9eUyeizFleMacYwoscCir8nQLlW34lxfRmirkNpD9vU1XnmjnZ5hGdnor1qIDqz3KJ040dVQ617MwyG97xxYLT0FsH907vBXgdc4RCHwKd1~9siagA5CSMaA~wM8ymKXLypiZGYexENLmim7nMzJTQYoOM~fVS99UaGJleDBN3pgZ2EvRYDQV2VqKH7Gee07R3y7b~c0tAKVHS0IbPQfTVJigrIHjTl~ZczxpaeTM04T8IgxKnO~lSmR1w7Ik8TpEkETwT9PDwUqQsjmlSY8E~WwwGMRJVyIRZUkHeRZ0aFq7us8W9EKzYtjjiU1z0QFpZrTfJE8oqCbnH5Lqv5Q86UdTPpriJC1N99E77TpCTnNzcBnpp6ko2JCy2IJUveaigKxS6EmS9KarkkkBRsckOKZZ6UNTOqPZsBCsx0Q9WvDF-Uc3dtouXWyenxRptaQsdkZyYlEQv");
    emailPacket1 = new EncryptedEmailPacket(unencryptedPacket1, destination1);
    emailPacket2 = new EncryptedEmailPacket(unencryptedPacket2, destination2);
}
Also used : UniqueId(i2p.bote.UniqueId) 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)

Example 7 with EncryptedEmailPacket

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

the class EmailPacketFolder method deleteExpired.

@Override
public synchronized void deleteExpired() {
    long currentTimeMillis = System.currentTimeMillis();
    for (Iterator<EncryptedEmailPacket> iterator = iterator(); iterator.hasNext(); ) {
        EncryptedEmailPacket emailPacket = iterator.next();
        if (currentTimeMillis > emailPacket.getStoreTime() + EXPIRATION_TIME_MILLISECONDS) {
            log.debug("Deleting expired email packet: <" + emailPacket + ">");
            iterator.remove();
        }
    }
}
Also used : EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket)

Example 8 with EncryptedEmailPacket

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

the class EmailPacketFolder method process.

/**
 * Deletes email packets.
 * @param delRequest An instance of {@link EmailPacketDeleteRequest}
 */
@Override
public synchronized void process(DeleteRequest delRequest) {
    log.debug("Processing delete request: " + delRequest);
    if (!(delRequest instanceof EmailPacketDeleteRequest))
        log.error("Invalid type of delete request for EmailPacketFolder: " + delRequest.getClass());
    EmailPacketDeleteRequest emailPacketDelRequest = (EmailPacketDeleteRequest) delRequest;
    // see if the packet exists
    Hash dhtKey = emailPacketDelRequest.getDhtKey();
    DhtStorablePacket storedPacket = retrieve(dhtKey);
    if (storedPacket instanceof EncryptedEmailPacket) {
        // verify
        Hash verificationHash = ((EncryptedEmailPacket) storedPacket).getDeleteVerificationHash();
        UniqueId delAuthorization = emailPacketDelRequest.getAuthorization();
        boolean valid = Util.isDeleteAuthorizationValid(verificationHash, delAuthorization);
        if (valid)
            delete(dhtKey, delAuthorization);
        else
            log.debug("Invalid Delete Authorization in EmailPacketDeleteRequest. Should be: <" + verificationHash.toBase64() + ">");
    } else if (storedPacket != null)
        log.debug("EncryptedEmailPacket expected for DHT key <" + dhtKey + ">, found " + storedPacket.getClass().getSimpleName());
}
Also used : EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest) DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) UniqueId(i2p.bote.UniqueId) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) Hash(net.i2p.data.Hash)

Example 9 with EncryptedEmailPacket

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

the class EmailPacketFolder method storeAndCreateDeleteRequest.

@Override
public DeleteRequest storeAndCreateDeleteRequest(DhtStorablePacket packetToStore) {
    if (!(packetToStore instanceof EncryptedEmailPacket))
        throw new IllegalArgumentException("Invalid packet type: " + packetToStore.getClass().getSimpleName() + "; this folder only stores packets of type " + EncryptedEmailPacket.class.getSimpleName() + ".");
    DeleteRequest delRequest = null;
    // read the deletion info file for the email packet's DHT key
    Hash dhtKey = packetToStore.getDhtKey();
    String delFileName = getDeletionFileName(dhtKey);
    DeletionInfoPacket delInfo = createDelInfoPacket(delFileName);
    if (delInfo != null) {
        DeletionRecord delRecord = delInfo.getEntry(dhtKey);
        if (delRecord != null)
            delRequest = new EmailPacketDeleteRequest(delRecord.dhtKey, delRecord.delAuthorization);
    } else
        // if the DHT key has not been recorded as deleted, store the email packet
        store(packetToStore);
    return delRequest;
}
Also used : EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest) DeletionInfoPacket(i2p.bote.packet.dht.DeletionInfoPacket) DeletionRecord(i2p.bote.packet.dht.DeletionRecord) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) Hash(net.i2p.data.Hash) DeleteRequest(i2p.bote.packet.dht.DeleteRequest) EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest)

Example 10 with EncryptedEmailPacket

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

the class EmailPacketFolder method store.

/**
 * Overridden to set a time stamp on the packet
 */
@Override
public void store(DhtStorablePacket packetToStore) {
    if (!(packetToStore instanceof EncryptedEmailPacket))
        throw new IllegalArgumentException("Invalid packet type: " + packetToStore.getClass().getSimpleName() + "; this folder only stores packets of type " + EncryptedEmailPacket.class.getSimpleName() + ".");
    EncryptedEmailPacket emailPacket = (EncryptedEmailPacket) packetToStore;
    // If the packet didn't come with a time stamp, set it to the current time
    if (emailPacket.getStoreTime() == 0)
        emailPacket.setStoreTime(System.currentTimeMillis());
    super.store(packetToStore);
}
Also used : EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket)

Aggregations

EncryptedEmailPacket (i2p.bote.packet.dht.EncryptedEmailPacket)16 UniqueId (i2p.bote.UniqueId)7 UnencryptedEmailPacket (i2p.bote.packet.dht.UnencryptedEmailPacket)6 Test (org.junit.Test)6 EmailDestination (i2p.bote.email.EmailDestination)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 DhtStorablePacket (i2p.bote.packet.dht.DhtStorablePacket)4 IndexPacket (i2p.bote.packet.dht.IndexPacket)4 DeleteRequest (i2p.bote.packet.dht.DeleteRequest)3 DeletionInfoPacket (i2p.bote.packet.dht.DeletionInfoPacket)3 DeletionRecord (i2p.bote.packet.dht.DeletionRecord)3 EmailPacketDeleteRequest (i2p.bote.packet.dht.EmailPacketDeleteRequest)3 Hash (net.i2p.data.Hash)3 Before (org.junit.Before)3 Email (i2p.bote.email.Email)2 EmailIdentity (i2p.bote.email.EmailIdentity)2 DataPacket (i2p.bote.packet.DataPacket)2 InternetAddress (javax.mail.internet.InternetAddress)2 Destination (net.i2p.data.Destination)2