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);
}
}
}
}
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) {
}
}
}
Aggregations