diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/HTTPResponseOutputStream.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/HTTPResponseOutputStream.java index 12940a81bc06f4141f23632ba35726fcf3c84ac7..de71ff3b2fdd43336b2bf70e3dbc6007700c3fa2 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/HTTPResponseOutputStream.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/HTTPResponseOutputStream.java @@ -20,7 +20,7 @@ import java.util.zip.GZIPInputStream; import net.i2p.I2PAppContext; import net.i2p.data.ByteArray; import net.i2p.util.ByteCache; -import net.i2p.util.I2PThread; +import net.i2p.util.I2PAppThread; import net.i2p.util.Log; /** @@ -219,7 +219,7 @@ class HTTPResponseOutputStream extends FilterOutputStream { //out.flush(); PipedInputStream pi = new PipedInputStream(); PipedOutputStream po = new PipedOutputStream(pi); - new I2PThread(new Pusher(pi, out), "HTTP decompresser").start(); + new I2PAppThread(new Pusher(pi, out), "HTTP decompresser").start(); out = po; } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java index 6a6c83883af836be6afbf2bea2d3d462f9be67a6..a7197a006c82b560679f443bca8740c3ef06fbd9 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java @@ -27,7 +27,7 @@ import net.i2p.client.streaming.I2PSocketManagerFactory; import net.i2p.client.streaming.I2PSocketOptions; import net.i2p.data.Destination; import net.i2p.util.EventDispatcher; -import net.i2p.util.I2PThread; +import net.i2p.util.I2PAppThread; import net.i2p.util.Log; import net.i2p.util.SimpleScheduler; import net.i2p.util.SimpleTimer; @@ -153,7 +153,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna } // else delay creating session until createI2PSocket() is called - Thread t = new I2PThread(this); + Thread t = new I2PAppThread(this); t.setName("Client " + _clientId); listenerReady = false; t.start(); @@ -207,7 +207,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna for (int i = 0; i < _numConnectionBuilders; i++) { String name = "ClientBuilder" + _clientId + '.' + i; - I2PThread b = new I2PThread(new TunnelConnectionBuilder(), name); + I2PAppThread b = new I2PAppThread(new TunnelConnectionBuilder(), name); b.setDaemon(true); b.start(); } @@ -350,7 +350,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna * called by derived classes after initialization. * */ - public final void startRunning() { + public void startRunning() { synchronized (startLock) { startRunning = true; startLock.notify(); @@ -490,7 +490,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna protected void manageConnection(Socket s) { if (s == null) return; if (_numConnectionBuilders <= 0) { - new I2PThread(new BlockingRunner(s), "Clinet run").start(); + new I2PAppThread(new BlockingRunner(s), "Clinet run").start(); return; } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java index b729b659bab6e7ce7bcb196b06b0a14a24078f46..683c9d6aa00c51908ae5f9a0a72c9fdd08681d49 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java @@ -233,6 +233,29 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable return opts; } + private InternalSocketRunner isr; + + /** + * Actually start working on incoming connections. + * Overridden to start an internal socket too. + * + */ + @Override + public void startRunning() { + super.startRunning(); + this.isr = new InternalSocketRunner(this); + } + + /** + * Overridden to close internal socket too. + */ + public boolean close(boolean forced) { + boolean rv = super.close(forced); + if (this.isr != null) + this.isr.stopRunning(); + return rv; + } + private static final boolean DEFAULT_GZIP = true; // all default to false public static final String PROP_REFERER = "i2ptunnel.httpclient.sendReferer"; diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java index e1ce9084ecb9479dc5590a845f1b5e83f6c131ce..af9f1c1ecf440b2515bcb11488bb88f5ab5dd770 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java @@ -17,7 +17,7 @@ import java.util.zip.GZIPOutputStream; import net.i2p.client.streaming.I2PSocket; import net.i2p.data.DataHelper; import net.i2p.util.EventDispatcher; -import net.i2p.util.I2PThread; +import net.i2p.util.I2PAppThread; import net.i2p.util.Log; import net.i2p.data.Base32; @@ -118,7 +118,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer { useGZIP = true; if (allowGZIP && useGZIP) { - I2PThread req = new I2PThread(new CompressedRequestor(s, socket, modifiedHeader), Thread.currentThread().getName()+".hc"); + I2PAppThread req = new I2PAppThread(new CompressedRequestor(s, socket, modifiedHeader), Thread.currentThread().getName()+".hc"); req.start(); } else { new I2PTunnelRunner(s, socket, slock, null, modifiedHeader.getBytes(), null); @@ -174,7 +174,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer { _log.info("request headers: " + _headers); serverout.write(_headers.getBytes()); browserin = _browser.getInputStream(); - I2PThread sender = new I2PThread(new Sender(serverout, browserin, "server: browser to server"), Thread.currentThread().getName() + "hcs"); + I2PAppThread sender = new I2PAppThread(new Sender(serverout, browserin, "server: browser to server"), Thread.currentThread().getName() + "hcs"); sender.start(); browserout = _browser.getOutputStream(); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java index b194ab702278f15924f6ffa5221ca34ba9962d48..00765267333c32f01d3706527c809898e19f477e 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java @@ -14,7 +14,7 @@ import net.i2p.client.streaming.I2PSocket; import net.i2p.data.DataFormatException; import net.i2p.data.Destination; import net.i2p.util.EventDispatcher; -import net.i2p.util.I2PThread; +import net.i2p.util.I2PAppThread; import net.i2p.util.Log; public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable { @@ -83,9 +83,9 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable i2ps = createI2PSocket(clientDest); i2ps.setReadTimeout(readTimeout); StringBuilder expectedPong = new StringBuilder(); - Thread in = new I2PThread(new IrcInboundFilter(s,i2ps, expectedPong), "IRC Client " + __clientId + " in"); + Thread in = new I2PAppThread(new IrcInboundFilter(s,i2ps, expectedPong), "IRC Client " + __clientId + " in"); in.start(); - Thread out = new I2PThread(new IrcOutboundFilter(s,i2ps, expectedPong), "IRC Client " + __clientId + " out"); + Thread out = new I2PAppThread(new IrcOutboundFilter(s,i2ps, expectedPong), "IRC Client " + __clientId + " out"); out.start(); } catch (Exception ex) { if (_log.shouldLog(Log.ERROR)) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java index 76480a940393ad25f14a9704feb80fd23e7f84a5..446ad55630d0bec581669f248403ae969bfc958b 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java @@ -16,10 +16,10 @@ import net.i2p.client.streaming.I2PSocket; import net.i2p.data.ByteArray; import net.i2p.util.ByteCache; import net.i2p.util.Clock; -import net.i2p.util.I2PThread; +import net.i2p.util.I2PAppThread; import net.i2p.util.Log; -public class I2PTunnelRunner extends I2PThread implements I2PSocket.SocketErrorListener { +public class I2PTunnelRunner extends I2PAppThread implements I2PSocket.SocketErrorListener { private final static Log _log = new Log(I2PTunnelRunner.class); private static volatile long __runnerId; @@ -222,7 +222,7 @@ public class I2PTunnelRunner extends I2PThread implements I2PSocket.SocketErrorL } } - private class StreamForwarder extends I2PThread { + private class StreamForwarder extends I2PAppThread { InputStream in; OutputStream out; diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java index 76246d7b66b66fec7788dfa57b60986a0d5bcccd..2471fcc501987dbf00477b7cbad9ba5ff2e801c5 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java @@ -24,7 +24,7 @@ import net.i2p.client.streaming.I2PSocketManager; import net.i2p.client.streaming.I2PSocketManagerFactory; import net.i2p.data.Base64; import net.i2p.util.EventDispatcher; -import net.i2p.util.I2PThread; +import net.i2p.util.I2PAppThread; import net.i2p.util.Log; public class I2PTunnelServer extends I2PTunnelTask implements Runnable { @@ -132,7 +132,7 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { * */ public void startRunning() { - Thread t = new I2PThread(this); + Thread t = new I2PAppThread(this); t.setName("Server " + (++__serverId)); t.start(); } @@ -204,7 +204,7 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { I2PServerSocket i2pS_S = sockMgr.getServerSocket(); int handlers = getHandlerCount(); for (int i = 0; i < handlers; i++) { - I2PThread handler = new I2PThread(new Handler(i2pS_S), "Handle Server " + i); + I2PAppThread handler = new I2PAppThread(new Handler(i2pS_S), "Handle Server " + i); handler.start(); } } else { @@ -213,7 +213,7 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { try { final I2PSocket i2ps = i2pS_S.accept(); if (i2ps == null) throw new I2PException("I2PServerSocket closed"); - new I2PThread(new Runnable() { public void run() { blockingHandle(i2ps); } }).start(); + new I2PAppThread(new Runnable() { public void run() { blockingHandle(i2ps); } }).start(); } catch (I2PException ipe) { if (_log.shouldLog(Log.ERROR)) _log.error("Error accepting - KILLING THE TUNNEL SERVER", ipe); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java index 1f358abf0a0a4bdbd0548e41cbbc79d974fe7323..a3cd1ad992658f09d8c715c7512ab174ab8d8bbf 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java @@ -14,7 +14,7 @@ import net.i2p.I2PException; import net.i2p.client.streaming.I2PSocketManager; import net.i2p.data.Destination; import net.i2p.util.EventDispatcher; -import net.i2p.util.I2PThread; +import net.i2p.util.I2PAppThread; import net.i2p.util.Log; public class I2Ping extends I2PTunnelTask implements Runnable { @@ -59,7 +59,7 @@ public class I2Ping extends I2PTunnelTask implements Runnable { sockMgr = I2PTunnelClient.getSocketManager(tunnel); } } - Thread t = new I2PThread(this); + Thread t = new I2PAppThread(this); t.setName("Client"); t.start(); open = true; @@ -188,7 +188,7 @@ public class I2Ping extends I2PTunnelTask implements Runnable { } } - public class PingHandler extends I2PThread { + public class PingHandler extends I2PAppThread { private String destination; public PingHandler(String dest) { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/InternalSocketRunner.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/InternalSocketRunner.java new file mode 100644 index 0000000000000000000000000000000000000000..5e3eefd4f52ee2057c039590a4ff288021b5726d --- /dev/null +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/InternalSocketRunner.java @@ -0,0 +1,55 @@ +package net.i2p.i2ptunnel; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; + +import net.i2p.util.I2PAppThread; +import net.i2p.util.InternalServerSocket; +import net.i2p.util.Log; + +/** + * Listen for in-JVM connections on the internal "socket" + * + * @author zzz + */ +class InternalSocketRunner implements Runnable { + private I2PTunnelClientBase client; + private int port; + private ServerSocket ss; + private boolean open; + private static final Log _log = new Log(InternalSocketRunner.class); + + /** starts the runner */ + InternalSocketRunner(I2PTunnelClientBase client) { + this.client = client; + this.port = client.getLocalPort(); + Thread t = new I2PAppThread(this, "Internal socket port " + this.port, true); + t.start(); + } + + public final void run() { + try { + this.ss = new InternalServerSocket(this.port); + this.open = true; + while (true) { + Socket s = this.ss.accept(); + this.client.manageConnection(s); + } + } catch (IOException ex) { + if (this.open) { + _log.error("Error listening for internal connections on " + this.port, ex); + } + this.open = false; + } + } + + void stopRunning() { + if (this.open) { + try { + this.ss.close(); + } catch (IOException ex) {} + this.open = false; + } + } +} diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java index b5ca6c3a118131ab458ecd1f42e5b46dea676a55..06beffae5dba0d23f27417a970889b6e60f209aa 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java @@ -16,7 +16,7 @@ import net.i2p.client.I2PClientFactory; import net.i2p.client.I2PSession; import net.i2p.data.Base32; import net.i2p.data.Destination; -import net.i2p.util.I2PThread; +import net.i2p.util.I2PAppThread; import net.i2p.util.Log; /** @@ -106,7 +106,7 @@ public class TunnelController implements Logging { public void startTunnelBackground() { if (_running) return; _starting = true; - new I2PThread(new Runnable() { public void run() { startTunnel(); } }).start(); + new I2PAppThread(new Runnable() { public void run() { startTunnel(); } }).start(); } /** diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelControllerGroup.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelControllerGroup.java index fb330679a785fa684c064daff22d68882052198f..4250dedd07da820cb25351fc6f94e0841a9990cc 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelControllerGroup.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelControllerGroup.java @@ -18,7 +18,7 @@ import net.i2p.I2PAppContext; import net.i2p.client.I2PSession; import net.i2p.client.I2PSessionException; import net.i2p.data.DataHelper; -import net.i2p.util.I2PThread; +import net.i2p.util.I2PAppThread; import net.i2p.util.Log; /** @@ -94,7 +94,7 @@ public class TunnelControllerGroup { _controllers.add(controller); i++; } - I2PThread startupThread = new I2PThread(new StartControllers(), "Startup tunnels"); + I2PAppThread startupThread = new I2PAppThread(new StartControllers(), "Startup tunnels"); startupThread.start(); if (_log.shouldLog(Log.INFO)) diff --git a/apps/i2ptunnel/jsp/editClient.jsp b/apps/i2ptunnel/jsp/editClient.jsp index c0ad7cdb5b336bf8996ae8fc2bd5157696e4c019..67452919d249fed40de79a10edd9d0197ed1b9dd 100644 --- a/apps/i2ptunnel/jsp/editClient.jsp +++ b/apps/i2ptunnel/jsp/editClient.jsp @@ -205,9 +205,9 @@ </div> <div id="depthField" class="rowItem"> <label for="tunnelDepth" accesskey="t"> - Dep<span class="accessKey">t</span>h: + Leng<span class="accessKey">t</span>h: </label> - <select id="tunnelDepth" name="tunnelDepth" title="Depth of each Tunnel" class="selectbox"> + <select id="tunnelDepth" name="tunnelDepth" title="Length of each Tunnel" class="selectbox"> <% int tunnelDepth = editBean.getTunnelDepth(curTunnel, 2); %><option value="0"<%=(tunnelDepth == 0 ? " selected=\"selected\"" : "") %>>0 hop tunnel (low anonymity, low latency)</option> <option value="1"<%=(tunnelDepth == 1 ? " selected=\"selected\"" : "") %>>1 hop tunnel (medium anonymity, medium latency)</option> @@ -222,7 +222,7 @@ <label for="tunnelVariance" accesskey="v"> <span class="accessKey">V</span>ariance: </label> - <select id="tunnelVariance" name="tunnelVariance" title="Level of Randomization for Tunnel Depth" class="selectbox"> + <select id="tunnelVariance" name="tunnelVariance" title="Level of Randomization for Tunnel Length" class="selectbox"> <% int tunnelVariance = editBean.getTunnelVariance(curTunnel, 0); %><option value="0"<%=(tunnelVariance == 0 ? " selected=\"selected\"" : "") %>>0 hop variance (no randomisation, consistant performance)</option> <option value="1"<%=(tunnelVariance == 1 ? " selected=\"selected\"" : "") %>>+ 0-1 hop variance (medium additive randomisation, subtractive performance)</option> diff --git a/apps/i2ptunnel/jsp/editServer.jsp b/apps/i2ptunnel/jsp/editServer.jsp index 958c7e8b1fb1314bcd9f1f05bcb7df68e02c7c47..610b68a5151a996db4a17e72e4f7e07b40d6cd9d 100644 --- a/apps/i2ptunnel/jsp/editServer.jsp +++ b/apps/i2ptunnel/jsp/editServer.jsp @@ -172,9 +172,9 @@ </div> <div id="depthField" class="rowItem"> <label for="tunnelDepth" accesskey="t"> - Dep<span class="accessKey">t</span>h: + Leng<span class="accessKey">t</span>h: </label> - <select id="tunnelDepth" name="tunnelDepth" title="Depth of each Tunnel" class="selectbox"> + <select id="tunnelDepth" name="tunnelDepth" title="Length of each Tunnel" class="selectbox"> <% int tunnelDepth = editBean.getTunnelDepth(curTunnel, 2); %><option value="0"<%=(tunnelDepth == 0 ? " selected=\"selected\"" : "") %>>0 hop tunnel (low anonymity, low latency)</option> <option value="1"<%=(tunnelDepth == 1 ? " selected=\"selected\"" : "") %>>1 hop tunnel (medium anonymity, medium latency)</option> diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigTunnelsHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigTunnelsHelper.java index 108b94e5291f60f607479ba2a0c97e73ece6afab..2be5a4a00b5427a391aceae02241e96d5924c493 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigTunnelsHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigTunnelsHelper.java @@ -84,7 +84,7 @@ public class ConfigTunnelsHelper extends HelperBase { // buf.append("<tr><th></th><th>Inbound</th><th>Outbound</th></tr>\n"); // tunnel depth - buf.append("<tr><td align=\"right\" class=\"mediumtags\">" + _("Depth") + ":</td>\n"); + buf.append("<tr><td align=\"right\" class=\"mediumtags\">" + _("Length") + ":</td>\n"); buf.append("<td align=\"center\"><select name=\"").append(index).append(".depthInbound\">\n"); int now = in.getLength(); renderOptions(buf, 0, MAX_LENGTH, now, "", HOP); diff --git a/core/java/src/net/i2p/util/EepGet.java b/core/java/src/net/i2p/util/EepGet.java index 43c0e40c64bf5f910435547689fc9a6f825569f3..cf4543d8f7ec48f4ee4d0fab97bd76c1980d51fb 100644 --- a/core/java/src/net/i2p/util/EepGet.java +++ b/core/java/src/net/i2p/util/EepGet.java @@ -16,6 +16,7 @@ import java.util.StringTokenizer; import net.i2p.I2PAppContext; import net.i2p.data.DataHelper; +import net.i2p.util.InternalSocket; /** * EepGet [-p 127.0.0.1:4444] @@ -869,7 +870,7 @@ public class EepGet { if (_proxy != null) try { _proxy.close(); } catch (IOException ioe) {} if (_shouldProxy) { - _proxy = new Socket(_proxyHost, _proxyPort); + _proxy = InternalSocket.getSocket(_proxyHost, _proxyPort); } else { try { URL url = new URL(_actualURL); diff --git a/core/java/src/net/i2p/util/InternalSocket.java b/core/java/src/net/i2p/util/InternalSocket.java index b1feb847f8e6143afca6843c809db2d690d1414c..26280f254554ae56860c90fca076340f59ef5233 100644 --- a/core/java/src/net/i2p/util/InternalSocket.java +++ b/core/java/src/net/i2p/util/InternalSocket.java @@ -63,13 +63,24 @@ public class InternalSocket extends Socket { @Override public void close() { try { - if (_is != null) _is.close(); + if (_is != null) { + _is.close(); + _is = null; + } } catch (IOException ie) {} try { - if (_os != null) _os.close(); + if (_os != null) { + _os.close(); + _os = null; + } } catch (IOException ie) {} } + @Override + public boolean isClosed() { + return _is == null || _os == null; + } + @Override public String toString() { return ("Internal socket"); @@ -183,11 +194,6 @@ public class InternalSocket extends Socket { } /** @deprecated unsupported */ @Override - public boolean isClosed() { - throw new IllegalArgumentException("unsupported"); - } - /** @deprecated unsupported */ - @Override public boolean isConnected() { throw new IllegalArgumentException("unsupported"); }