use of net.i2p.client.streaming.I2PSocketAddress in project i2p.i2p by i2p.
the class I2PTunnelClient method clientConnectionRun.
protected void clientConnectionRun(Socket s) {
I2PSocket i2ps = null;
try {
I2PSocketAddress addr = pickDestination();
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);
I2PTunnelRunner t = new I2PTunnelRunner(s, i2ps, sockLock, null, null, mySockets, (I2PTunnelRunner.FailCallback) null);
// we are called from an unlimited thread pool, so run inline
// t.start();
t.run();
} catch (IOException ex) {
if (_log.shouldLog(Log.INFO))
_log.info("Error connecting", ex);
} catch (I2PException ex) {
if (_log.shouldLog(Log.INFO))
_log.info("Error connecting", ex);
} 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.client.streaming.I2PSocketAddress in project i2p.i2p by i2p.
the class I2PTunnelClient method startRunning.
/**
* Actually start working on incoming connections.
* Overridden to register with port mapper.
*
* @since 0.9.27
*/
@Override
public void startRunning() {
super.startRunning();
if (open) {
I2PSocketAddress addr = pickDestination();
if (addr != null) {
String svc = null;
String hostname = addr.getHostName();
if ("smtp.postman.i2p".equals(hostname)) {
svc = PortMapper.SVC_SMTP;
} else if ("pop.postman.i2p".equals(hostname)) {
svc = PortMapper.SVC_POP;
}
if (svc != null) {
_isr = new InternalSocketRunner(this);
_isr.start();
_context.portMapper().register(svc, getTunnel().listenHost, getLocalPort());
}
}
}
}
use of net.i2p.client.streaming.I2PSocketAddress in project i2p.i2p by i2p.
the class I2PTunnelClient method buildAddresses.
/**
* @since 0.9.9 moved from constructor
*/
private void buildAddresses(String destinations) {
if (destinations == null)
return;
StringTokenizer tok = new StringTokenizer(destinations, ", ");
synchronized (_addrs) {
_addrs.clear();
while (tok.hasMoreTokens()) {
String destination = tok.nextToken();
try {
// Try to resolve here but only log if it doesn't.
// Note that b32 _addrs will often not be resolvable at instantiation time.
// We will try again to resolve in clientConnectionRun()
I2PSocketAddress addr = new I2PSocketAddress(destination);
_addrs.add(addr);
if (addr.isUnresolved()) {
String name = addr.getHostName();
if (name.length() == 60 && name.endsWith(".b32.i2p"))
l.log("Warning - Could not resolve " + name + ", perhaps it is not up, will retry when connecting.");
else
l.log("Warning - Could not resolve " + name + ", you must add it to your address book for it to work.");
} else {
dests.add(addr.getAddress());
}
} catch (IllegalArgumentException iae) {
l.log("Bad destination " + destination + " - " + iae);
}
}
}
}
use of net.i2p.client.streaming.I2PSocketAddress in project i2p.i2p by i2p.
the class I2PTunnelIRCClient method buildAddresses.
/**
* @since 0.9.9 moved from constructor
*/
private void buildAddresses(String destinations) {
if (destinations == null)
return;
StringTokenizer tok = new StringTokenizer(destinations, ", ");
synchronized (_addrs) {
_addrs.clear();
while (tok.hasMoreTokens()) {
String destination = tok.nextToken();
try {
// Try to resolve here but only log if it doesn't.
// Note that b32 _addrs will often not be resolvable at instantiation time.
// We will try again to resolve in clientConnectionRun()
I2PSocketAddress addr = new I2PSocketAddress(destination);
_addrs.add(addr);
if (addr.isUnresolved()) {
String name = addr.getHostName();
if (name.length() == 60 && name.endsWith(".b32.i2p"))
l.log("Warning - Could not resolve " + name + ", perhaps it is not up, will retry when connecting.");
else
l.log("Warning - Could not resolve " + name + ", you must add it to your address book for it to work.");
}
} catch (IllegalArgumentException iae) {
l.log("Bad destination " + destination + " - " + iae);
}
}
}
}
use of net.i2p.client.streaming.I2PSocketAddress 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);
}
}
}
}
Aggregations