Search in sources :

Example 1 with DCCHelper

use of net.i2p.i2ptunnel.irc.DCCHelper 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)

Aggregations

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