Search in sources :

Example 1 with I2PPacketDispatcher

use of i2p.bote.network.I2PPacketDispatcher 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)

Aggregations

Email (i2p.bote.email.Email)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 I2PSendQueue (i2p.bote.network.I2PSendQueue)1 RelayPacketHandler (i2p.bote.network.RelayPacketHandler)1 KademliaDHT (i2p.bote.network.kademlia.KademliaDHT)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 RelayPacketSender (i2p.bote.service.RelayPacketSender)1 RelayPeerManager (i2p.bote.service.RelayPeerManager)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1