Search in sources :

Example 51 with I2PAppThread

use of net.i2p.util.I2PAppThread in project i2p.i2p-bote by i2p.

the class I2PBote method stopAllServices.

private void stopAllServices() {
    if (backgroundThreads != null) {
        // interrupt all threads
        for (I2PAppThread thread : backgroundThreads) if (thread != null && thread.isAlive())
            thread.interrupt();
    }
    if (apiService != null)
        apiService.stopAll();
    if (backgroundThreads != null) {
        awaitShutdown(5 * 1000);
        printRunningThreads();
    }
}
Also used : I2PAppThread(net.i2p.util.I2PAppThread)

Example 52 with I2PAppThread

use of net.i2p.util.I2PAppThread 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

I2PAppThread (net.i2p.util.I2PAppThread)52 IOException (java.io.IOException)18 I2PException (net.i2p.I2PException)9 I2PSocket (net.i2p.client.streaming.I2PSocket)7 InterruptedIOException (java.io.InterruptedIOException)6 ConnectException (java.net.ConnectException)5 Socket (java.net.Socket)5 I2PSessionException (net.i2p.client.I2PSessionException)5 Destination (net.i2p.data.Destination)5 File (java.io.File)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ServerSocket (java.net.ServerSocket)3 SocketTimeoutException (java.net.SocketTimeoutException)3 UnknownHostException (java.net.UnknownHostException)3 Properties (java.util.Properties)3 I2PServerSocket (net.i2p.client.streaming.I2PServerSocket)3 DataFormatException (net.i2p.data.DataFormatException)3 FileNotFoundException (java.io.FileNotFoundException)2