Search in sources :

Example 31 with I2PThread

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

the class EventPumper method startPumping.

public synchronized void startPumping() {
    if (_log.shouldLog(Log.INFO))
        _log.info("Starting pumper");
    try {
        _selector = Selector.open();
        _alive = true;
        new I2PThread(this, "NTCP Pumper", true).start();
    } catch (IOException ioe) {
        _log.log(Log.CRIT, "Error opening the NTCP selector", ioe);
    } catch (java.lang.InternalError jlie) {
        // "unable to get address of epoll functions, pre-2.6 kernel?"
        _log.log(Log.CRIT, "Error opening the NTCP selector", jlie);
    }
}
Also used : I2PThread(net.i2p.util.I2PThread) IOException(java.io.IOException)

Example 32 with I2PThread

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

the class UPnP method registerPorts.

/**
 *  postControlAction() can take many seconds, especially if it's failing,
 *  and onChangePublicPorts() may be called from threads we don't want to slow down,
 *  so throw this in a thread.
 */
private void registerPorts(Set<ForwardPort> portsToForwardNow) {
    if (_serviceLacksAPM) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("UPnP device does not support port forwarding");
        Map<ForwardPort, ForwardPortStatus> map = new HashMap<ForwardPort, ForwardPortStatus>(portsToForwardNow.size());
        for (ForwardPort port : portsToForwardNow) {
            ForwardPortStatus fps = new ForwardPortStatus(ForwardPortStatus.DEFINITE_FAILURE, "UPnP device does not support port forwarding", port.portNumber);
            map.put(port, fps);
        }
        forwardCallback.portForwardStatus(map);
        return;
    }
    if (_log.shouldLog(Log.INFO))
        _log.info("Starting thread to forward " + portsToForwardNow.size() + " ports");
    Thread t = new I2PThread(new RegisterPortsThread(portsToForwardNow));
    t.setName("UPnP Port Opener " + __id.incrementAndGet());
    t.setDaemon(true);
    t.start();
}
Also used : ForwardPort(org.freenetproject.ForwardPort) HashMap(java.util.HashMap) I2PThread(net.i2p.util.I2PThread) ForwardPortStatus(org.freenetproject.ForwardPortStatus) I2PThread(net.i2p.util.I2PThread)

Example 33 with I2PThread

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

the class UDPEndpointTestStandalone method runTest.

public void runTest(int numPeers) {
    _log.debug("Run test(" + numPeers + ")");
    _endpoints = new UDPEndpoint[numPeers];
    int base = 44000 + _context.random().nextInt(10000);
    for (int i = 0; i < numPeers; i++) {
        _log.debug("Building " + i);
        UDPEndpoint endpoint = new UDPEndpoint(_context, null, base + i, null);
        _endpoints[i] = endpoint;
        try {
            endpoint.startup();
        } catch (SocketException se) {
            _log.error("die", se);
            throw new RuntimeException(se);
        }
        I2PThread read = new I2PThread(new TestRead(endpoint), "Test read " + i);
        I2PThread write = new I2PThread(new TestWrite(endpoint), "Test write " + i);
        // read.setDaemon(true);
        read.start();
        // write.setDaemon(true);
        write.start();
    }
    _beginTest = true;
    _log.debug("Test begin");
}
Also used : SocketException(java.net.SocketException) I2PThread(net.i2p.util.I2PThread)

Example 34 with I2PThread

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

the class AdminRunner method shutdown.

private String shutdown(String cmd) {
    String password = _context.router().getConfigSetting(SHUTDOWN_PASSWORD_PROP);
    if (password == null)
        password = _context.getProperty(SHUTDOWN_PASSWORD_PROP);
    if (password == null)
        return "No shutdown password specified in the config or context - <b>REFUSING SHUTDOWN</b>." + "<a href=\"/routerConsole.html\">back</a>";
    if (cmd.indexOf(password) > 0) {
        I2PThread t = new I2PThread(new Runnable() {

            public void run() {
                try {
                    Thread.sleep(30 * 1000);
                } catch (InterruptedException ie) {
                }
                _context.router().shutdown(Router.EXIT_HARD);
            }
        });
        t.start();
        return "Shutdown request accepted.  Killing the router in 30 seconds";
    } else {
        return "Incorrect shutdown password specified.  Please edit your router.config appropriately." + "<a href=\"/routerConsole.html\">back</a>";
    }
}
Also used : I2PThread(net.i2p.util.I2PThread)

Example 35 with I2PThread

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

the class ClientManager method startListeners.

/**
 *  Call from synchronized method
 *  Todo: Start a 3rd listener for IPV6?
 */
protected void startListeners() {
    ClientListenerRunner listener;
    if (SystemVersion.isAndroid()) {
        try {
            Class<? extends ClientListenerRunner> clazz = Class.forName("net.i2p.router.client.DomainClientListenerRunner").asSubclass(ClientListenerRunner.class);
            Constructor<? extends ClientListenerRunner> ctor = clazz.getDeclaredConstructor(RouterContext.class, ClientManager.class);
            listener = ctor.newInstance(_ctx, this);
            Thread t = new I2PThread(listener, "DomainClientListener", true);
            t.start();
            _listeners.add(listener);
        } catch (ClassNotFoundException e) {
            _log.warn("Could not find DomainClientListenerRunner class", e);
        } catch (ClassCastException e) {
            _log.error("Error creating DomainClientListenerRunner", e);
        } catch (NoSuchMethodException e) {
            _log.error("Error creating DomainClientListenerRunner", e);
        } catch (InstantiationException e) {
            _log.error("Error creating DomainClientListenerRunner", e);
        } catch (IllegalAccessException e) {
            _log.error("Error creating DomainClientListenerRunner", e);
        } catch (InvocationTargetException e) {
            _log.error("Error creating DomainClientListenerRunner", e);
        }
    }
    if (!_ctx.getBooleanProperty(PROP_DISABLE_EXTERNAL)) {
        // there's no option to start both an SSL and non-SSL listener
        if (_ctx.getBooleanProperty(PROP_ENABLE_SSL))
            listener = new SSLClientListenerRunner(_ctx, this, _port);
        else
            listener = new ClientListenerRunner(_ctx, this, _port);
        Thread t = new I2PThread(listener, "ClientListener:" + _port, true);
        t.start();
        _listeners.add(listener);
        _clientTimestamper.schedule(ClientTimestamper.LOOP_TIME);
    }
    _isStarted = true;
}
Also used : I2PThread(net.i2p.util.I2PThread) InvocationTargetException(java.lang.reflect.InvocationTargetException) I2PThread(net.i2p.util.I2PThread)

Aggregations

I2PThread (net.i2p.util.I2PThread)35 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Socket (java.net.Socket)1 SocketException (java.net.SocketException)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 Destination (net.i2p.data.Destination)1 I2CPMessageReader (net.i2p.data.i2cp.I2CPMessageReader)1 I2PAppThread (net.i2p.util.I2PAppThread)1 ForwardPort (org.freenetproject.ForwardPort)1 ForwardPortStatus (org.freenetproject.ForwardPortStatus)1