Search in sources :

Example 1 with I2PTunnelRunner

use of net.i2p.i2ptunnel.I2PTunnelRunner in project i2p.i2p by i2p.

the class I2PTunnelDCCServer method blockingHandle.

/**
 *  An incoming DCC connection, only accept for a known port.
 *  Passed through without filtering.
 */
@Override
protected void blockingHandle(I2PSocket socket) {
    if (_log.shouldLog(Log.INFO))
        _log.info("Incoming connection to '" + toString() + "' from: " + socket.getPeerDestination().calculateHash().toBase64());
    try {
        expireOutbound();
        int myPort = socket.getLocalPort();
        // Port is a one-time-use only
        LocalAddress local = _outgoing.remove(Integer.valueOf(myPort));
        if (local == null) {
            if (_log.shouldLog(Log.WARN))
                _log.warn("Rejecting incoming DCC connection for unknown port " + myPort);
            try {
                socket.close();
            } catch (IOException ioe) {
            }
            return;
        }
        if (_log.shouldLog(Log.WARN))
            _log.warn("Incoming DCC connection for I2P port " + myPort + " sending to " + local.ia + ':' + local.port);
        try {
            Socket s = new Socket(local.ia, local.port);
            _sockList.add(socket);
            Thread t = new I2PTunnelRunner(s, socket, slock, null, null, _sockList, (I2PTunnelRunner.FailCallback) null);
            // run in the unlimited client pool
            // t.start();
            _clientExecutor.execute(t);
            local.socket = socket;
            local.expire = getTunnel().getContext().clock().now() + OUTBOUND_EXPIRE;
            _active.put(Integer.valueOf(myPort), local);
        } catch (SocketException ex) {
            try {
                socket.reset();
            } catch (IOException ioe) {
            }
            _log.error("Error relaying incoming DCC connection to IRC client at " + local.ia + ':' + local.port, ex);
        }
    } catch (IOException ex) {
        _log.error("Error while waiting for I2PConnections", ex);
    }
}
Also used : SocketException(java.net.SocketException) IOException(java.io.IOException) I2PTunnelRunner(net.i2p.i2ptunnel.I2PTunnelRunner) Socket(java.net.Socket) I2PSocket(net.i2p.client.streaming.I2PSocket)

Example 2 with I2PTunnelRunner

use of net.i2p.i2ptunnel.I2PTunnelRunner in project i2p.i2p by i2p.

the class I2PSOCKSTunnel method clientConnectionRun.

protected void clientConnectionRun(Socket s) {
    I2PSocket destSock = null;
    try {
        try {
            s.setSoTimeout(INITIAL_SO_TIMEOUT);
        } catch (SocketException ioe) {
        }
        SOCKSServer serv = SOCKSServerFactory.createSOCKSServer(_context, s, getTunnel().getClientOptions());
        Socket clientSock = serv.getClientSocket();
        try {
            s.setSoTimeout(0);
        } catch (SocketException ioe) {
        }
        destSock = serv.getDestinationI2PSocket(this);
        Thread t = new I2PTunnelRunner(clientSock, destSock, sockLock, null, null, mySockets, (I2PTunnelRunner.FailCallback) null);
        // we are called from an unlimited thread pool, so run inline
        // t.start();
        t.run();
    } catch (SOCKSException e) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("Error from SOCKS connection", e);
    } finally {
        // only because we are running it inline
        closeSocket(s);
        if (destSock != null)
            try {
                destSock.close();
            } catch (IOException ioe) {
            }
    }
}
Also used : SocketException(java.net.SocketException) I2PSocket(net.i2p.client.streaming.I2PSocket) SOCKSException(net.i2p.socks.SOCKSException) I2PTunnelRunner(net.i2p.i2ptunnel.I2PTunnelRunner) IOException(java.io.IOException) Socket(java.net.Socket) I2PSocket(net.i2p.client.streaming.I2PSocket)

Aggregations

IOException (java.io.IOException)2 Socket (java.net.Socket)2 SocketException (java.net.SocketException)2 I2PSocket (net.i2p.client.streaming.I2PSocket)2 I2PTunnelRunner (net.i2p.i2ptunnel.I2PTunnelRunner)2 SOCKSException (net.i2p.socks.SOCKSException)1