Search in sources :

Example 1 with IrcInboundFilter

use of net.i2p.i2ptunnel.irc.IrcInboundFilter in project i2p.i2p by i2p.

the class I2PTunnelIRCClient method clientConnectionRun.

protected void clientConnectionRun(Socket s) {
    if (_log.shouldLog(Log.INFO))
        _log.info("New connection local addr is: " + s.getLocalAddress() + " from: " + s.getInetAddress());
    I2PSocket i2ps = null;
    I2PSocketAddress addr = pickDestination();
    try {
        if (addr == null)
            throw new UnknownHostException("No valid destination configured");
        Destination clientDest = addr.getAddress();
        if (clientDest == null)
            throw new UnknownHostException("Could not resolve " + addr.getHostName());
        int port = addr.getPort();
        i2ps = createI2PSocket(clientDest, port);
        i2ps.setReadTimeout(readTimeout);
        StringBuffer expectedPong = new StringBuffer();
        DCCHelper dcc = _dccEnabled ? new DCC(s.getLocalAddress().getAddress()) : null;
        Thread in = new I2PAppThread(new IrcInboundFilter(s, i2ps, expectedPong, _log, dcc), "IRC Client " + _clientId + " in", true);
        in.start();
        // Thread out = new I2PAppThread(new IrcOutboundFilter(s,i2ps, expectedPong, _log, dcc), "IRC Client " + _clientId + " out", true);
        Runnable out = new IrcOutboundFilter(s, i2ps, expectedPong, _log, dcc);
        // we are called from an unlimited thread pool, so run inline
        // out.start();
        out.run();
    } catch (IOException ex) {
        // generally NoRouteToHostException
        if (_log.shouldLog(Log.WARN))
            _log.warn("Error connecting", ex);
        // l.log("Error connecting: " + ex.getMessage());
        try {
            // Send a response so the user doesn't just see a disconnect
            // and blame his router or the network.
            String name = addr != null ? addr.getHostName() : "undefined";
            String msg = ":" + name + " 499 you :" + ex + "\r\n";
            s.getOutputStream().write(DataHelper.getUTF8(msg));
        } catch (IOException ioe) {
        }
    } catch (I2PException ex) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("Error connecting", ex);
        // l.log("Error connecting: " + ex.getMessage());
        try {
            // Send a response so the user doesn't just see a disconnect
            // and blame his router or the network.
            String name = addr != null ? addr.getHostName() : "undefined";
            String msg = ":" + name + " 499 you :" + ex + "\r\n";
            s.getOutputStream().write(DataHelper.getUTF8(msg));
        } catch (IOException ioe) {
        }
    } finally {
        // only because we are running it inline
        closeSocket(s);
        if (i2ps != null) {
            try {
                i2ps.close();
            } catch (IOException ioe) {
            }
            synchronized (sockLock) {
                mySockets.remove(i2ps);
            }
        }
    }
}
Also used : I2PException(net.i2p.I2PException) Destination(net.i2p.data.Destination) UnknownHostException(java.net.UnknownHostException) I2PSocketAddress(net.i2p.client.streaming.I2PSocketAddress) I2PSocket(net.i2p.client.streaming.I2PSocket) IOException(java.io.IOException) DCCHelper(net.i2p.i2ptunnel.irc.DCCHelper) I2PAppThread(net.i2p.util.I2PAppThread) I2PAppThread(net.i2p.util.I2PAppThread) IrcOutboundFilter(net.i2p.i2ptunnel.irc.IrcOutboundFilter) IrcInboundFilter(net.i2p.i2ptunnel.irc.IrcInboundFilter)

Example 2 with IrcInboundFilter

use of net.i2p.i2ptunnel.irc.IrcInboundFilter in project i2p.i2p by i2p.

the class I2PSOCKSIRCTunnel method clientConnectionRun.

/**
 *  Same as in I2PSOCKSTunnel, but run the filters from I2PTunnelIRCClient
 *  instead of I2PTunnelRunner
 */
@Override
protected void clientConnectionRun(Socket s) {
    I2PSocket destSock = null;
    try {
        // _log.error("SOCKS IRC Tunnel Start");
        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);
        StringBuffer expectedPong = new StringBuffer();
        int id = __clientId.incrementAndGet();
        Thread in = new I2PAppThread(new IrcInboundFilter(clientSock, destSock, expectedPong, _log), "SOCKS IRC Client " + id + " in", true);
        in.start();
        // Thread out = new I2PAppThread(new IrcOutboundFilter(clientSock, destSock, expectedPong, _log),
        // "SOCKS IRC Client " + id + " out", true);
        Runnable out = new IrcOutboundFilter(clientSock, destSock, expectedPong, _log);
        // we are called from an unlimited thread pool, so run inline
        // out.start();
        out.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) IOException(java.io.IOException) I2PAppThread(net.i2p.util.I2PAppThread) I2PAppThread(net.i2p.util.I2PAppThread) IrcOutboundFilter(net.i2p.i2ptunnel.irc.IrcOutboundFilter) IrcInboundFilter(net.i2p.i2ptunnel.irc.IrcInboundFilter) Socket(java.net.Socket) I2PSocket(net.i2p.client.streaming.I2PSocket)

Aggregations

IOException (java.io.IOException)2 I2PSocket (net.i2p.client.streaming.I2PSocket)2 IrcInboundFilter (net.i2p.i2ptunnel.irc.IrcInboundFilter)2 IrcOutboundFilter (net.i2p.i2ptunnel.irc.IrcOutboundFilter)2 I2PAppThread (net.i2p.util.I2PAppThread)2 Socket (java.net.Socket)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 I2PException (net.i2p.I2PException)1 I2PSocketAddress (net.i2p.client.streaming.I2PSocketAddress)1 Destination (net.i2p.data.Destination)1 DCCHelper (net.i2p.i2ptunnel.irc.DCCHelper)1 SOCKSException (net.i2p.socks.SOCKSException)1