Search in sources :

Example 6 with I2PAppThread

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

the class I2PTunnelServer method startRunning.

/**
 *  Copy input stream to a byte array, so we can retry
 *  @since 0.7.10
 */
/**
 **
 *    private static ByteArrayInputStream copyOfInputStream(InputStream is) throws IOException {
 *        byte[] buf = new byte[128];
 *        ByteArrayOutputStream os = new ByteArrayOutputStream(768);
 *        try {
 *            int read;
 *            while ((read = is.read(buf)) >= 0) {
 *                os.write(buf, 0, read);
 *            }
 *        } finally {
 *             try { is.close(); } catch (IOException ioe) {}
 *             // don't need to close BAOS
 *        }
 *        return new ByteArrayInputStream(os.toByteArray());
 *    }
 ***
 */
/**
 * Start running the I2PTunnelServer.
 * Warning, blocks while connecting to router and building tunnels;
 *
 * @throws IllegalArgumentException if the I2CP configuration is b0rked so
 *                                  badly that we cant create a socketManager
 */
public synchronized void startRunning() {
    connectManager();
    // prevent JVM exit when running outside the router
    boolean isDaemon = getTunnel().getContext().isRouterContext();
    Thread t = new I2PAppThread(this, "Server " + remoteHost + ':' + remotePort, isDaemon);
    t.start();
}
Also used : I2PAppThread(net.i2p.util.I2PAppThread) I2PAppThread(net.i2p.util.I2PAppThread)

Example 7 with I2PAppThread

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

the class SnarkManager method start.

/**
 * Caller _must_ call loadConfig(file) before this if setting new values
 *  for i2cp host/port or i2psnark.dir
 */
public void start() {
    _running = true;
    if ("i2psnark".equals(_contextName)) {
        // Register with the ClientAppManager so the rpc plugin can find us
        // only if default instance
        ClientAppManager cmgr = _context.clientAppManager();
        if (cmgr != null)
            cmgr.register(this);
    }
    _peerCoordinatorSet = new PeerCoordinatorSet();
    _connectionAcceptor = new ConnectionAcceptor(_util, _peerCoordinatorSet);
    _monitor = new I2PAppThread(new DirMonitor(), "Snark DirMonitor", true);
    _monitor.start();
    // only if default instance
    if (_context.isRouterContext() && "i2psnark".equals(_contextName))
        // delay until UpdateManager is there
        _context.simpleTimer2().addEvent(new Register(), 4 * 60 * 1000);
    // Not required, Jetty has a shutdown hook
    // _context.addShutdownTask(new SnarkManagerShutdown());
    _idleChecker = new IdleChecker(this, _peerCoordinatorSet);
    _idleChecker.schedule(5 * 60 * 1000);
    if (!_context.isRouterContext()) {
        String lang = _config.getProperty(PROP_LANG);
        if (lang != null) {
            String country = _config.getProperty(PROP_COUNTRY, "");
            Translate.setLanguage(lang, country);
        }
    }
}
Also used : I2PAppThread(net.i2p.util.I2PAppThread) ClientAppManager(net.i2p.app.ClientAppManager)

Example 8 with I2PAppThread

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

the class TrackerClient method unannounce.

/**
 *  Creates a thread for each tracker in parallel if tunnel is still open
 *  @since 0.9.1
 */
private void unannounce() {
    // Local DHT tracker unannounce
    DHT dht = _util.getDHT();
    if (dht != null)
        dht.unannounce(snark.getInfoHash());
    int i = 0;
    for (TCTracker tr : trackers) {
        if (_util.connected() && tr.started && (!tr.stop) && tr.trackerProblems == null) {
            try {
                (new I2PAppThread(new Unannouncer(tr), _threadName + " U" + (++i), true)).start();
            } catch (OutOfMemoryError oom) {
                // probably ran out of threads, ignore
                tr.reset();
            }
        } else {
            tr.reset();
        }
    }
}
Also used : DHT(org.klomp.snark.dht.DHT) I2PAppThread(net.i2p.util.I2PAppThread)

Example 9 with I2PAppThread

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

the class TunnelControllerGroup method startControllers.

/**
 * Start all of the tunnels. Must call loadControllers() first.
 * @since 0.9.20
 */
private synchronized void startControllers() {
    changeState(STARTING);
    I2PAppThread startupThread = new I2PAppThread(new StartControllers(), "Startup tunnels");
    startupThread.start();
    changeState(RUNNING);
}
Also used : I2PAppThread(net.i2p.util.I2PAppThread)

Example 10 with I2PAppThread

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

the class RouterConsoleRunner method shutdown.

/**
 * @since 0.9.4
 */
public synchronized void shutdown(String[] args) {
    if (_state == STOPPED)
        return;
    changeState(STOPPING);
    if (PluginStarter.pluginsEnabled(_context))
        (new I2PAppThread(new PluginStopper(_context), "PluginStopper")).start();
    stopAllWebApps();
    try {
        _server.stop();
    } catch (Exception ie) {
    }
    PortMapper portMapper = _context.portMapper();
    portMapper.unregister(PortMapper.SVC_CONSOLE);
    portMapper.unregister(PortMapper.SVC_HTTPS_CONSOLE);
    synchronized (RouterConsoleRunner.class) {
        if (_jettyTimer != null) {
            try {
                _jettyTimer.stop();
            } catch (Exception e) {
            }
            _jettyTimer = null;
        }
    }
    changeState(STOPPED);
}
Also used : PortMapper(net.i2p.util.PortMapper) I2PAppThread(net.i2p.util.I2PAppThread) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

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