From fb21fb25eeade127fff5cd40233658979ad52cdc Mon Sep 17 00:00:00 2001 From: zzz Date: Mon, 7 Dec 2009 21:25:27 +0000 Subject: [PATCH] * I2PTunnel: - Switch all I2PThreads to I2PAppThreads - Run an InternalSocket as well for the HTTP Proxy * EepGet: Use InternalSocket * Console: Change "depth" to "length" --- .../i2ptunnel/HTTPResponseOutputStream.java | 4 +- .../i2p/i2ptunnel/I2PTunnelClientBase.java | 10 ++-- .../i2p/i2ptunnel/I2PTunnelHTTPClient.java | 23 ++++++++ .../i2p/i2ptunnel/I2PTunnelHTTPServer.java | 6 +- .../net/i2p/i2ptunnel/I2PTunnelIRCClient.java | 6 +- .../net/i2p/i2ptunnel/I2PTunnelRunner.java | 6 +- .../net/i2p/i2ptunnel/I2PTunnelServer.java | 8 +-- .../java/src/net/i2p/i2ptunnel/I2Ping.java | 6 +- .../i2p/i2ptunnel/InternalSocketRunner.java | 55 +++++++++++++++++++ .../net/i2p/i2ptunnel/TunnelController.java | 4 +- .../i2p/i2ptunnel/TunnelControllerGroup.java | 4 +- apps/i2ptunnel/jsp/editClient.jsp | 6 +- apps/i2ptunnel/jsp/editServer.jsp | 4 +- .../i2p/router/web/ConfigTunnelsHelper.java | 2 +- core/java/src/net/i2p/util/EepGet.java | 3 +- .../java/src/net/i2p/util/InternalSocket.java | 20 ++++--- 16 files changed, 126 insertions(+), 41 deletions(-) create mode 100644 apps/i2ptunnel/java/src/net/i2p/i2ptunnel/InternalSocketRunner.java diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/HTTPResponseOutputStream.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/HTTPResponseOutputStream.java index 12940a81b..de71ff3b2 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 6a6c83883..a7197a006 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 b729b659b..683c9d6aa 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 e1ce9084e..af9f1c1ec 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 b194ab702..007652673 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 76480a940..446ad5563 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 76246d7b6..2471fcc50 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 1f358abf0..a3cd1ad99 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 000000000..5e3eefd4f --- /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 b5ca6c3a1..06beffae5 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 fb330679a..4250dedd0 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 c0ad7cdb5..67452919d 100644 --- a/apps/i2ptunnel/jsp/editClient.jsp +++ b/apps/i2ptunnel/jsp/editClient.jsp @@ -205,9 +205,9 @@
- <% int tunnelDepth = editBean.getTunnelDepth(curTunnel, 2); %> @@ -222,7 +222,7 @@ - <% int tunnelVariance = editBean.getTunnelVariance(curTunnel, 0); %> diff --git a/apps/i2ptunnel/jsp/editServer.jsp b/apps/i2ptunnel/jsp/editServer.jsp index 958c7e8b1..610b68a51 100644 --- a/apps/i2ptunnel/jsp/editServer.jsp +++ b/apps/i2ptunnel/jsp/editServer.jsp @@ -172,9 +172,9 @@
- <% int tunnelDepth = editBean.getTunnelDepth(curTunnel, 2); %> 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 108b94e52..2be5a4a00 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("InboundOutbound\n"); // tunnel depth - buf.append("" + _("Depth") + ":\n"); + buf.append("" + _("Length") + ":\n"); buf.append("