Search in sources :

Example 1 with RelayPeerManager

use of i2p.bote.service.RelayPeerManager in project i2p.i2p-bote by i2p.

the class I2PBote method initializeServices.

/**
 * Initializes daemon threads, doesn't start them yet.
 */
private void initializeServices() {
    I2PPacketDispatcher dispatcher = new I2PPacketDispatcher();
    i2pSession.addMuxedSessionListener(dispatcher, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY);
    backgroundThreads.add(passwordCache);
    I2PSendQueue sendQueue = new I2PSendQueue(i2pSession, dispatcher);
    backgroundThreads.add(sendQueue);
    // reads packets stored in the relayPacketFolder and sends them
    RelayPacketSender relayPacketSender = new RelayPacketSender(sendQueue, relayPacketFolder, configuration);
    backgroundThreads.add(relayPacketSender);
    I2PAppThread seedless = null;
    try {
        Class<? extends I2PAppThread> clazz = Class.forName("i2p.bote.service.seedless.SeedlessInitializer").asSubclass(I2PAppThread.class);
        Constructor<? extends I2PAppThread> ctor = clazz.getDeclaredConstructor(I2PSocketManager.class);
        seedless = ctor.newInstance(socketManager);
        backgroundThreads.add(seedless);
    } catch (ClassNotFoundException e) {
    } catch (NoSuchMethodException e) {
    } catch (InstantiationException e) {
    } catch (IllegalAccessException e) {
    } catch (InvocationTargetException e) {
    }
    dht = new KademliaDHT(sendQueue, dispatcher, configuration.getDhtPeerFile(), (DhtPeerSource) seedless);
    backgroundThreads.add(dht);
    dht.setStorageHandler(EncryptedEmailPacket.class, emailDhtStorageFolder);
    dht.setStorageHandler(IndexPacket.class, indexPacketDhtStorageFolder);
    dht.setStorageHandler(Contact.class, directoryDhtFolder);
    peerManager = new RelayPeerManager(sendQueue, getLocalDestination(), configuration.getRelayPeerFile());
    backgroundThreads.add(peerManager);
    dispatcher.addPacketListener(emailDhtStorageFolder);
    dispatcher.addPacketListener(indexPacketDhtStorageFolder);
    dispatcher.addPacketListener(new RelayPacketHandler(relayPacketFolder, dht, sendQueue, i2pSession));
    dispatcher.addPacketListener(peerManager);
    dispatcher.addPacketListener(relayPacketSender);
    ExpirationThread expirationThread = new ExpirationThread();
    expirationThread.addExpirationListener(emailDhtStorageFolder);
    expirationThread.addExpirationListener(indexPacketDhtStorageFolder);
    expirationThread.addExpirationListener(relayPacketSender);
    backgroundThreads.add(expirationThread);
    outboxProcessor = new OutboxProcessor(dht, outbox, peerManager, relayPacketFolder, identities, configuration, this);
    outboxProcessor.addOutboxListener(new OutboxListener() {

        /**
         * Moves sent emails to the "sent" folder
         */
        @Override
        public void emailSent(Email email) {
            try {
                outbox.setNew(email, false);
                log.debug("Moving email [" + email + "] to the \"sent\" folder.");
                outbox.move(email, sentFolder);
            } catch (Exception e) {
                log.error("Cannot move email from outbox to sent folder: " + email, e);
            }
        }
    });
    backgroundThreads.add(outboxProcessor);
    emailChecker = new EmailChecker(identities, configuration, incompleteEmailFolder, emailDhtStorageFolder, indexPacketDhtStorageFolder, this, sendQueue, dht, peerManager);
    backgroundThreads.add(emailChecker);
    deliveryChecker = new DeliveryChecker(dht, sentFolder, configuration, this);
    backgroundThreads.add(deliveryChecker);
}
Also used : RelayPacketHandler(i2p.bote.network.RelayPacketHandler) Email(i2p.bote.email.Email) EmailChecker(i2p.bote.service.EmailChecker) I2PSendQueue(i2p.bote.network.I2PSendQueue) RelayPeerManager(i2p.bote.service.RelayPeerManager) I2PAppThread(net.i2p.util.I2PAppThread) InvocationTargetException(java.lang.reflect.InvocationTargetException) OutboxProcessor(i2p.bote.service.OutboxProcessor) PasswordException(i2p.bote.fileencryption.PasswordException) GeneralSecurityException(java.security.GeneralSecurityException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoIdentityForSenderException(i2p.bote.email.NoIdentityForSenderException) IOException(java.io.IOException) I2PSessionException(net.i2p.client.I2PSessionException) I2PException(net.i2p.I2PException) ExecutionException(java.util.concurrent.ExecutionException) PasswordMismatchException(i2p.bote.fileencryption.PasswordMismatchException) URISyntaxException(java.net.URISyntaxException) MessagingException(javax.mail.MessagingException) DhtException(i2p.bote.network.DhtException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PasswordIncorrectException(i2p.bote.fileencryption.PasswordIncorrectException) DataFormatException(net.i2p.data.DataFormatException) DeliveryChecker(i2p.bote.service.DeliveryChecker) KademliaDHT(i2p.bote.network.kademlia.KademliaDHT) OutboxListener(i2p.bote.service.OutboxListener) DhtPeerSource(i2p.bote.network.DhtPeerSource) RelayPacketSender(i2p.bote.service.RelayPacketSender) I2PPacketDispatcher(i2p.bote.network.I2PPacketDispatcher) ExpirationThread(i2p.bote.service.ExpirationThread)

Example 2 with RelayPeerManager

use of i2p.bote.service.RelayPeerManager in project i2p.i2p-bote by i2p.

the class RelayRequestTest method setUp.

@Before
public void setUp() throws Exception {
    Destination nextDestination = new Destination("X3oKYQJ~1EAz7B1ZYGSrOTIMCW5Rnn2Svoc38dx5D9~zvz8vqiWcH-pCqQDwLgPWl9RTBzHtTmZcGRPXIv54i0XWeUfX6rTPDQGuZsnBMM0xrkH2FNLNFaJa0NgW3uKXWpNj9AI1AXUXzK-2MYTYoaZHx5SBoCaKfAGMcFJvTON1~kopxBxdBF9Q7T4~PJ3I2LeU-ycmUlehe9N9bIu7adUGyPGVl8Ka-UxwQromoJ~vSWHHl8HkwcDkW--v9Aj~wvFqxqriFkB1EeBiThi3V4XtVY~GUP4IkRj9YZGTsSBf3eS4xwXgnYWlB7IvxAGBfHY9MCg3lbAa1Dg~1IH6rhtXxsXUtGcXsz9yMZTxXHd~rGo~JrXeM1y~Vcenpr6tJcum6pxevkKzzT0qDegGPH3Zhqz7sSeeIaJEcPBUAkX89csqyFWFIjTMm6yZp2rW-QYUnVNLNTjf7vndYUAEICogAkq~btqpIzrGEpm3Pr9F23br3SpbOmdxQxg51AMmAAAA");
    EmailDestination destination = new EmailDestination("3LbBiN2nxtQVxPXYBQL3~PjBg-xOPalsFKZ0YqobHXP1u3MiBxqthF6TJxqdPS2LWWKb90FVzaPyIIEQOT0qSb");
    IndexPacket indexPacket = new IndexPacket(destination);
    storeRequest = new StoreRequest(indexPacket);
    long delayMilliseconds = TimeUnit.MILLISECONDS.convert(123, TimeUnit.MINUTES);
    relayRequestSingle = new RelayRequest(storeRequest, nextDestination, delayMilliseconds, 1000);
    // create a RelayPeerManager
    String localBase64DestKeys = "X3oKYQJ~1EAz7B1ZYGSrOTIMCW5Rnn2Svoc38dx5D9~zvz8vqiWcH-pCqQDwLgPWl9RTBzHtTmZcGRPXIv54i0XWeUfX6rTPDQGuZsnBMM0xrkH2FNLNFaJa0NgW3uKXWpNj9AI1AXUXzK-2MYTYoaZHx5SBoCaKfAGMcFJvTON1~kopxBxdBF9Q7T4~PJ3I2LeU-ycmUlehe9N9bIu7adUGyPGVl8Ka-UxwQromoJ~vSWHHl8HkwcDkW--v9Aj~wvFqxqriFkB1EeBiThi3V4XtVY~GUP4IkRj9YZGTsSBf3eS4xwXgnYWlB7IvxAGBfHY9MCg3lbAa1Dg~1IH6rhtXxsXUtGcXsz9yMZTxXHd~rGo~JrXeM1y~Vcenpr6tJcum6pxevkKzzT0qDegGPH3Zhqz7sSeeIaJEcPBUAkX89csqyFWFIjTMm6yZp2rW-QYUnVNLNTjf7vndYUAEICogAkq~btqpIzrGEpm3Pr9F23br3SpbOmdxQxg51AMmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADBrMolZp2gbXxrAef~UFJdSfiKSSSj~KcUOKndCndDipKboKQ5rcwHu0eKElE5NIS";
    i2pClient = I2PClientFactory.createClient();
    I2PSession i2pSession = i2pClient.createSession(new ByteArrayInputStream(Base64.decode(localBase64DestKeys)), null);
    final Synchroniser synchroniser = new Synchroniser();
    Mockery mockery = new Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
            // otherwise we get errors on threads
            setThreadingPolicy(synchroniser);
        }
    };
    I2PSendQueue sendQueue = mockery.mock(I2PSendQueue.class);
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    testDir = new File(tempDir, "RelayPacketTest-" + System.currentTimeMillis());
    if (!testDir.mkdirs())
        fail("Cannot create directory: <" + testDir + ">");
    destKeys = new String[3];
    destKeys[0] = "EN2qXoeZ-x3qCejofePmMfW~1gWo4~kKyRQg5NwzGW-gZ5rKD1pUN8eHFfEid6v7GLl6XRTOCPw4OELnqKhhtLSaQQz3U9qTcpbmS1Oc9U2cpqwiOwyGru-5RF8LU9s7VwhUTB1nh~NrSzEJlbCZ9eOZiJyw7t031aHRbWTIOniq3vUkEVpEkhYbO8TlNT~4KzvINoDGUsEr2b6vV6j8IpZN-J8Jd9mRBJCaY1dxyMJ~2rZ441m2q3ndHbu5~GUPBelf7nnTh2ggzdgtHJuy~j2MOJda65rPxBEZq8cOmN-YyA5-yagIPL34QH6yp10bERN8S3qz2LeyVRcvzDEhsJUOVYv2Bt67gJ-KhXyCB7qSpQjRaT~QKpYoKfdCH2eqYUA9Yj1QaZJZjWQTN6gGf0DUHNNz2VEBRyzkYNd7XHgt5vCIhSw0U2N6s~62iEzTQHF8QbgKYeUTmx8XVOgvSau0tdg-ZzG0-UKJ3Zzng93E75B3W7juUGA~Z59fXF-PAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AwIo0pboudvT9FrY~JcFTOVYxd3u2K9QW9IAvyeceQgXMKZVNmL6fdw8j3DDSS8faB043MMM2RB6md9ziRwBW60r7tt0b9-Jn-~98lBv4ilwH8H0ivd8S7xEsbFT0W7dvqyInJ0kkC8yfX5bUlQYedkozQxl8LikSZWL4hyfGkNcHmLGl11OkRdBf-QjIEEdUE614iVY5bRxc~XS9TedXuRFfSciwVB14M7RRz0-mY61uNeH-7tVJZ1ixsoHBCoXqY9TFZ33zZkjyUQaFJaJxWVA5069ureV0BpvO-wBfCdTqUe92v5-hZaCqzlr3PqWLMAhR82yUZlarlZdeeTvnU-4g1~2tsnyUZQlev2i9jmpCb2~N0goo6hPOWTfWADsgq8xABIfi7mUchlMz~tuzCZwOUx2WVjy66u-tccHEdGC737zyPEhvOmZqjo3tg54IeX72FVP7kHc2QYNbfO7HXzK1x6FQ0dTr-E-OUeAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADFD91On9qR24Vcrdp-QmybkllCrh6k~3FcBUcIETv1AG79DSell4tLImTenGkRKt1";
    peerFile = new File(testDir, "peers.txt");
    BufferedWriter writer = new BufferedWriter(new FileWriter(peerFile));
    for (String destKey : destKeys) {
        // make an entry in the peers file, set reachability to 100%
        writer.write(destKey);
        for (int i = 0; i < getMaxSamples(); i++) writer.write("\ttrue");
        writer.newLine();
    }
    writer.close();
    peerManager = new RelayPeerManager(sendQueue, i2pSession.getMyDestination(), peerFile);
    assertEquals(destKeys.length, peerManager.getAllPeers().size());
    minDelayMilliseconds = TimeUnit.MILLISECONDS.convert(120, TimeUnit.MINUTES);
    maxDelayMilliseconds = TimeUnit.MILLISECONDS.convert(600, TimeUnit.MINUTES);
    relayRequestMulti = RelayRequest.create(storeRequest, peerManager, destKeys.length, minDelayMilliseconds, maxDelayMilliseconds);
}
Also used : EmailDestination(i2p.bote.email.EmailDestination) Destination(net.i2p.data.Destination) StoreRequest(i2p.bote.packet.dht.StoreRequest) FileWriter(java.io.FileWriter) I2PSendQueue(i2p.bote.network.I2PSendQueue) RelayPeerManager(i2p.bote.service.RelayPeerManager) Mockery(org.jmock.Mockery) BufferedWriter(java.io.BufferedWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) IndexPacket(i2p.bote.packet.dht.IndexPacket) EmailDestination(i2p.bote.email.EmailDestination) I2PSession(net.i2p.client.I2PSession) Synchroniser(org.jmock.lib.concurrent.Synchroniser) File(java.io.File) Before(org.junit.Before)

Aggregations

I2PSendQueue (i2p.bote.network.I2PSendQueue)2 RelayPeerManager (i2p.bote.service.RelayPeerManager)2 Email (i2p.bote.email.Email)1 EmailDestination (i2p.bote.email.EmailDestination)1 NoIdentityForSenderException (i2p.bote.email.NoIdentityForSenderException)1 PasswordException (i2p.bote.fileencryption.PasswordException)1 PasswordIncorrectException (i2p.bote.fileencryption.PasswordIncorrectException)1 PasswordMismatchException (i2p.bote.fileencryption.PasswordMismatchException)1 DhtException (i2p.bote.network.DhtException)1 DhtPeerSource (i2p.bote.network.DhtPeerSource)1 I2PPacketDispatcher (i2p.bote.network.I2PPacketDispatcher)1 RelayPacketHandler (i2p.bote.network.RelayPacketHandler)1 KademliaDHT (i2p.bote.network.kademlia.KademliaDHT)1 IndexPacket (i2p.bote.packet.dht.IndexPacket)1 StoreRequest (i2p.bote.packet.dht.StoreRequest)1 DeliveryChecker (i2p.bote.service.DeliveryChecker)1 EmailChecker (i2p.bote.service.EmailChecker)1 ExpirationThread (i2p.bote.service.ExpirationThread)1 OutboxListener (i2p.bote.service.OutboxListener)1 OutboxProcessor (i2p.bote.service.OutboxProcessor)1