forked from I2P_Developers/i2p.i2p
* don't use static props on the I2PTunnel for I2CP / etc so that we can safely keep multiple instances alive
* propogate errors (if the I2CP host isnt reachable, the socket manager won't be created) and handle appropriately
This commit is contained in:
@@ -74,13 +74,13 @@ public class I2PTunnel implements Logging, EventDispatcher {
|
|||||||
|
|
||||||
public static final int PACKET_DELAY = 100;
|
public static final int PACKET_DELAY = 100;
|
||||||
|
|
||||||
public static boolean ownDest = false;
|
public boolean ownDest = false;
|
||||||
|
|
||||||
public static String port = System.getProperty(I2PClient.PROP_TCP_PORT, "7654");
|
public String port = System.getProperty(I2PClient.PROP_TCP_PORT, "7654");
|
||||||
public static String host = System.getProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1");
|
public String host = System.getProperty(I2PClient.PROP_TCP_HOST, "127.0.0.1");
|
||||||
public static String listenHost = host;
|
public String listenHost = host;
|
||||||
|
|
||||||
public static long readTimeout = -1;
|
public long readTimeout = -1;
|
||||||
|
|
||||||
private static final String nocli_args[] = { "-nocli", "-die"};
|
private static final String nocli_args[] = { "-nocli", "-die"};
|
||||||
|
|
||||||
@@ -408,9 +408,9 @@ public class I2PTunnel implements Logging, EventDispatcher {
|
|||||||
*/
|
*/
|
||||||
public void runClient(String args[], Logging l) {
|
public void runClient(String args[], Logging l) {
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
int port = -1;
|
int portNum = -1;
|
||||||
try {
|
try {
|
||||||
port = Integer.parseInt(args[0]);
|
portNum = Integer.parseInt(args[0]);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
l.log("invalid port");
|
l.log("invalid port");
|
||||||
_log.error(getPrefix() + "Port specified is not valid: " + args[0], nfe);
|
_log.error(getPrefix() + "Port specified is not valid: " + args[0], nfe);
|
||||||
@@ -418,9 +418,15 @@ public class I2PTunnel implements Logging, EventDispatcher {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
I2PTunnelTask task;
|
I2PTunnelTask task;
|
||||||
task = new I2PTunnelClient(port, args[1], l, ownDest, (EventDispatcher) this, this);
|
try {
|
||||||
|
task = new I2PTunnelClient(portNum, args[1], l, ownDest, (EventDispatcher) this, this);
|
||||||
addtask(task);
|
addtask(task);
|
||||||
notifyEvent("clientTaskId", new Integer(task.getId()));
|
notifyEvent("clientTaskId", new Integer(task.getId()));
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
_log.error(getPrefix() + "Invalid I2PTunnel config to create a client [" + host + ":"+ port + "]", iae);
|
||||||
|
l.log("Invalid I2PTunnel configuration [" + host + ":" + port + "]");
|
||||||
|
notifyEvent("clientTaskId", new Integer(-1));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
l.log("client <port> <pubkey>|file:<pubkeyfile>");
|
l.log("client <port> <pubkey>|file:<pubkeyfile>");
|
||||||
l.log(" creates a client that forwards port to the pubkey.\n"
|
l.log(" creates a client that forwards port to the pubkey.\n"
|
||||||
@@ -455,9 +461,15 @@ public class I2PTunnel implements Logging, EventDispatcher {
|
|||||||
proxy = args[1];
|
proxy = args[1];
|
||||||
}
|
}
|
||||||
I2PTunnelTask task;
|
I2PTunnelTask task;
|
||||||
|
try {
|
||||||
task = new I2PTunnelHTTPClient(port, l, ownDest, proxy, (EventDispatcher) this, this);
|
task = new I2PTunnelHTTPClient(port, l, ownDest, proxy, (EventDispatcher) this, this);
|
||||||
addtask(task);
|
addtask(task);
|
||||||
notifyEvent("httpclientTaskId", new Integer(task.getId()));
|
notifyEvent("httpclientTaskId", new Integer(task.getId()));
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
_log.error(getPrefix() + "Invalid I2PTunnel config to create an httpclient [" + host + ":"+ port + "]", iae);
|
||||||
|
l.log("Invalid I2PTunnel configuration [" + host + ":" + port + "]");
|
||||||
|
notifyEvent("httpclientTaskId", new Integer(-1));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
l.log("httpclient <port> [<proxy>]");
|
l.log("httpclient <port> [<proxy>]");
|
||||||
l.log(" creates a client that distributes HTTP requests.");
|
l.log(" creates a client that distributes HTTP requests.");
|
||||||
|
@@ -19,7 +19,13 @@ public class I2PTunnelClient extends I2PTunnelClientBase {
|
|||||||
private static final long DEFAULT_READ_TIMEOUT = 5*60*1000; // -1
|
private static final long DEFAULT_READ_TIMEOUT = 5*60*1000; // -1
|
||||||
protected long readTimeout = DEFAULT_READ_TIMEOUT;
|
protected long readTimeout = DEFAULT_READ_TIMEOUT;
|
||||||
|
|
||||||
public I2PTunnelClient(int localPort, String destination, Logging l, boolean ownDest, EventDispatcher notifyThis, I2PTunnel tunnel) {
|
/**
|
||||||
|
* @throws IllegalArgumentException if the I2PTunnel does not contain
|
||||||
|
* valid config to contact the router
|
||||||
|
*/
|
||||||
|
public I2PTunnelClient(int localPort, String destination, Logging l,
|
||||||
|
boolean ownDest, EventDispatcher notifyThis,
|
||||||
|
I2PTunnel tunnel) throws IllegalArgumentException {
|
||||||
super(localPort, ownDest, l, notifyThis, "SynSender", tunnel);
|
super(localPort, ownDest, l, notifyThis, "SynSender", tunnel);
|
||||||
|
|
||||||
if (waitEventValue("openBaseClientResult").equals("error")) {
|
if (waitEventValue("openBaseClientResult").equals("error")) {
|
||||||
|
@@ -60,7 +60,13 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
|
|||||||
// I2PTunnelClientBase(localPort, ownDest, l, (EventDispatcher)null);
|
// I2PTunnelClientBase(localPort, ownDest, l, (EventDispatcher)null);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
public I2PTunnelClientBase(int localPort, boolean ownDest, Logging l, EventDispatcher notifyThis, String handlerName, I2PTunnel tunnel) {
|
/**
|
||||||
|
* @throws IllegalArgumentException if the I2CP configuration is b0rked so
|
||||||
|
* badly that we cant create a socketManager
|
||||||
|
*/
|
||||||
|
public I2PTunnelClientBase(int localPort, boolean ownDest, Logging l,
|
||||||
|
EventDispatcher notifyThis, String handlerName,
|
||||||
|
I2PTunnel tunnel) throws IllegalArgumentException{
|
||||||
super(localPort + " (uninitialized)", notifyThis, tunnel);
|
super(localPort + " (uninitialized)", notifyThis, tunnel);
|
||||||
_clientId = ++__clientId;
|
_clientId = ++__clientId;
|
||||||
this.localPort = localPort;
|
this.localPort = localPort;
|
||||||
@@ -74,7 +80,10 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
|
|||||||
sockMgr = getSocketManager();
|
sockMgr = getSocketManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sockMgr == null) throw new NullPointerException();
|
if (sockMgr == null) {
|
||||||
|
l.log("Invalid I2CP configuration");
|
||||||
|
throw new IllegalArgumentException("Socket manager could not be created");
|
||||||
|
}
|
||||||
l.log("I2P session created");
|
l.log("I2P session created");
|
||||||
|
|
||||||
Thread t = new I2PThread(this);
|
Thread t = new I2PThread(this);
|
||||||
@@ -122,7 +131,8 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
|
|||||||
props.putAll(System.getProperties());
|
props.putAll(System.getProperties());
|
||||||
else
|
else
|
||||||
props.putAll(tunnel.getClientOptions());
|
props.putAll(tunnel.getClientOptions());
|
||||||
I2PSocketManager sockManager = I2PSocketManagerFactory.createManager(I2PTunnel.host, Integer.parseInt(I2PTunnel.port), props);
|
I2PSocketManager sockManager = I2PSocketManagerFactory.createManager(tunnel.host, Integer.parseInt(tunnel.port), props);
|
||||||
|
if (sockManager == null) return null;
|
||||||
sockManager.setName("Client");
|
sockManager.setName("Client");
|
||||||
return sockManager;
|
return sockManager;
|
||||||
}
|
}
|
||||||
@@ -133,9 +143,9 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
|
|||||||
|
|
||||||
protected final InetAddress getListenHost(Logging l) {
|
protected final InetAddress getListenHost(Logging l) {
|
||||||
try {
|
try {
|
||||||
return InetAddress.getByName(I2PTunnel.listenHost);
|
return InetAddress.getByName(getTunnel().listenHost);
|
||||||
} catch (UnknownHostException uhe) {
|
} catch (UnknownHostException uhe) {
|
||||||
l.log("Could not find listen host to bind to [" + I2PTunnel.host + "]");
|
l.log("Could not find listen host to bind to [" + getTunnel().host + "]");
|
||||||
_log.error("Error finding host to bind", uhe);
|
_log.error("Error finding host to bind", uhe);
|
||||||
notifyEvent("openBaseClientResult", "error");
|
notifyEvent("openBaseClientResult", "error");
|
||||||
return null;
|
return null;
|
||||||
@@ -212,7 +222,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
|
|||||||
localPort = ss.getLocalPort();
|
localPort = ss.getLocalPort();
|
||||||
}
|
}
|
||||||
notifyEvent("clientLocalPort", new Integer(ss.getLocalPort()));
|
notifyEvent("clientLocalPort", new Integer(ss.getLocalPort()));
|
||||||
l.log("Listening for clients on port " + localPort + " of " + I2PTunnel.listenHost);
|
l.log("Listening for clients on port " + localPort + " of " + getTunnel().listenHost);
|
||||||
|
|
||||||
// Notify constructor that port is ready
|
// Notify constructor that port is ready
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
@@ -81,7 +81,13 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
|
|||||||
/** used to assign unique IDs to the threads / clients. no logic or functionality */
|
/** used to assign unique IDs to the threads / clients. no logic or functionality */
|
||||||
private static volatile long __clientId = 0;
|
private static volatile long __clientId = 0;
|
||||||
|
|
||||||
public I2PTunnelHTTPClient(int localPort, Logging l, boolean ownDest, String wwwProxy, EventDispatcher notifyThis, I2PTunnel tunnel) {
|
/**
|
||||||
|
* @throws IllegalArgumentException if the I2PTunnel does not contain
|
||||||
|
* valid config to contact the router
|
||||||
|
*/
|
||||||
|
public I2PTunnelHTTPClient(int localPort, Logging l, boolean ownDest,
|
||||||
|
String wwwProxy, EventDispatcher notifyThis,
|
||||||
|
I2PTunnel tunnel) throws IllegalArgumentException {
|
||||||
super(localPort, ownDest, l, notifyThis, "HTTPHandler " + (++__clientId), tunnel);
|
super(localPort, ownDest, l, notifyThis, "HTTPHandler " + (++__clientId), tunnel);
|
||||||
|
|
||||||
if (waitEventValue("openBaseClientResult").equals("error")) {
|
if (waitEventValue("openBaseClientResult").equals("error")) {
|
||||||
|
@@ -75,7 +75,7 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable {
|
|||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.putAll(getTunnel().getClientOptions());
|
props.putAll(getTunnel().getClientOptions());
|
||||||
synchronized (slock) {
|
synchronized (slock) {
|
||||||
sockMgr = I2PSocketManagerFactory.createManager(privData, I2PTunnel.host, Integer.parseInt(I2PTunnel.port),
|
sockMgr = I2PSocketManagerFactory.createManager(privData, getTunnel().host, Integer.parseInt(getTunnel().port),
|
||||||
props);
|
props);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user