From f37c0ed612493d083c65a89a7ad60033cc5ec14e Mon Sep 17 00:00:00 2001
From: jrandom <jrandom>
Date: Fri, 9 Apr 2004 01:22:04 +0000
Subject: [PATCH] name all threads, and (nearly) always use I2PThread (in case
 we add some pooling/throttling/monitoring or whatnot later)

---
 .../java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java      | 5 +++--
 .../java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java      | 1 +
 .../java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java          | 5 +++--
 .../java/src/net/i2p/i2ptunnel/I2PTunnelServer.java          | 3 ++-
 apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java        | 5 +++--
 apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelManager.java | 2 +-
 .../java/src/net/i2p/client/streaming/I2PSocketImpl.java     | 4 +++-
 core/java/src/net/i2p/crypto/DHSessionKeyBuilder.java        | 3 ++-
 core/java/src/net/i2p/crypto/YKGenerator.java                | 3 ++-
 9 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java
index 21cf31ed02..e63cd98783 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java
@@ -21,6 +21,7 @@ import net.i2p.client.streaming.I2PSocketOptions;
 import net.i2p.data.Destination;
 import net.i2p.util.EventDispatcher;
 import net.i2p.util.Log;
+import net.i2p.util.I2PThread;
 
 public abstract class I2PTunnelClientBase extends I2PTunnelTask 
     implements Runnable {
@@ -73,7 +74,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask
 	if (sockMgr == null) throw new NullPointerException();
 	l.log("I2P session created");
         
-	Thread t = new Thread(this);
+	Thread t = new I2PThread(this);
 	t.setName("Client");
 	listenerReady=false;
 	t.start();
@@ -270,7 +271,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask
 	}
     }
 
-    public class ClientConnectionRunner extends Thread {
+    public class ClientConnectionRunner extends I2PThread {
 	private Socket s;
 	
 	public ClientConnectionRunner(Socket s, String name) {
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java
index 5914410cc5..da1024fcc5 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java
@@ -208,6 +208,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase
 		_targetRequest = targetRequest;
 		_useWWWProxy = useWWWProxy;
 		_disabled = false;
+		setName("InactivityThread");
 	    }
 	    public void disable() { 
 		_disabled = true; 
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java
index ca39bf401f..0042535959 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java
@@ -15,8 +15,9 @@ import net.i2p.client.I2PSession;
 import net.i2p.client.streaming.I2PSocket;
 import net.i2p.util.Log;
 import net.i2p.util.Clock;
+import net.i2p.util.I2PThread;
 
-public class I2PTunnelRunner extends Thread {
+public class I2PTunnelRunner extends I2PThread {
     private final static Log _log = new Log(I2PTunnelRunner.class);
     
     /** 
@@ -121,7 +122,7 @@ public class I2PTunnelRunner extends Thread {
 	}
     }
 
-    private class StreamForwarder extends Thread {
+    private class StreamForwarder extends I2PThread {
 
 	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 1711baae9b..acc6a5082c 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java
@@ -23,6 +23,7 @@ import net.i2p.client.streaming.I2PSocketManagerFactory;
 import net.i2p.data.Base64;
 import net.i2p.util.EventDispatcher;
 import net.i2p.util.Log;
+import net.i2p.util.I2PThread;
 
 public class I2PTunnelServer extends I2PTunnelTask
     implements Runnable {
@@ -82,7 +83,7 @@ public class I2PTunnelServer extends I2PTunnelTask
 	l.log("Ready!");
 	notifyEvent("openServerResult", "ok");
 	open=true;
-	Thread t = new Thread(this);
+	Thread t = new I2PThread(this);
 	t.setName("Server");
 	t.start();
     }
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java
index 49b5be5b3e..48f0b16b15 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java
@@ -15,6 +15,7 @@ import net.i2p.client.streaming.I2PSocketManager;
 import net.i2p.data.Destination;
 import net.i2p.util.EventDispatcher;
 import net.i2p.util.Log;
+import net.i2p.util.I2PThread;
 
 public class I2Ping extends I2PTunnelTask implements Runnable {
     private final static Log _log = new Log(I2Ping.class);
@@ -58,7 +59,7 @@ public class I2Ping extends I2PTunnelTask implements Runnable {
 		sockMgr = I2PTunnelClient.getSocketManager();
 	    }
 	}
-	Thread t = new Thread(this);
+	Thread t = new I2PThread(this);
 	t.setName("Client");
 	t.start();
 	open=true;
@@ -180,7 +181,7 @@ public class I2Ping extends I2PTunnelTask implements Runnable {
 	
 
 
-    public class PingHandler extends Thread {
+    public class PingHandler extends I2PThread {
 	private String destination;
 	
 	public PingHandler(String dest) {
diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelManager.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelManager.java
index dda9a2219d..f314fb3112 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelManager.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelManager.java
@@ -192,7 +192,7 @@ public class TunnelManager implements Runnable {
 	}
 
 	TunnelManager mgr = new TunnelManager(host, port);
-	Thread t = new Thread(mgr, "Listener");
+	Thread t = new I2PThread(mgr, "Listener");
 	t.start();
     }
     
diff --git a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketImpl.java b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketImpl.java
index 73303e15ba..0accb2a6ec 100644
--- a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketImpl.java
+++ b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketImpl.java
@@ -9,6 +9,7 @@ import net.i2p.I2PException;
 import net.i2p.client.I2PSessionException;
 import net.i2p.data.Destination;
 import net.i2p.util.Log;
+import net.i2p.util.I2PThread;
 
 /**
  * Initial stub implementation for the socket
@@ -227,13 +228,14 @@ class I2PSocketImpl implements I2PSocket {
 	}
     }
 
-    public class I2PSocketRunner extends Thread {
+    public class I2PSocketRunner extends I2PThread {
 
 	public InputStream in;
 
 	public I2PSocketRunner(InputStream in) {
 	    _log.debug("Runner's input stream is: "+in.hashCode());
 	    this.in=in;
+	    setName("SocketRunner from " + I2PSocketImpl.this.remote.calculateHash().toBase64().substring(0, 4));
 	    start();
 	}
 
diff --git a/core/java/src/net/i2p/crypto/DHSessionKeyBuilder.java b/core/java/src/net/i2p/crypto/DHSessionKeyBuilder.java
index 8ec981e262..022218420f 100644
--- a/core/java/src/net/i2p/crypto/DHSessionKeyBuilder.java
+++ b/core/java/src/net/i2p/crypto/DHSessionKeyBuilder.java
@@ -14,6 +14,7 @@ import net.i2p.util.RandomSource;
 import net.i2p.util.Log;
 import net.i2p.util.NativeBigInteger;
 import net.i2p.util.Clock;
+import net.i2p.util.I2PThread;
 import java.math.BigInteger;
 
 import java.util.ArrayList;
@@ -84,7 +85,7 @@ public class DHSessionKeyBuilder {
 	
 	if (_log.shouldLog(Log.DEBUG)) _log.debug("DH Precalc (minimum: " + MIN_NUM_BUILDERS + " max: " + MAX_NUM_BUILDERS + ", delay: " + CALC_DELAY + ")");
 	
-	_precalcThread = new Thread(new DHSessionKeyBuilderPrecalcRunner(MIN_NUM_BUILDERS, MAX_NUM_BUILDERS));
+	_precalcThread = new I2PThread(new DHSessionKeyBuilderPrecalcRunner(MIN_NUM_BUILDERS, MAX_NUM_BUILDERS));
 	_precalcThread.setName("DH Precalc");
 	_precalcThread.setDaemon(true);
 	_precalcThread.setPriority(Thread.MIN_PRIORITY);
diff --git a/core/java/src/net/i2p/crypto/YKGenerator.java b/core/java/src/net/i2p/crypto/YKGenerator.java
index beb160c51a..39bc4be9c8 100644
--- a/core/java/src/net/i2p/crypto/YKGenerator.java
+++ b/core/java/src/net/i2p/crypto/YKGenerator.java
@@ -14,6 +14,7 @@ import java.util.List;
 
 import net.i2p.util.Clock;
 import net.i2p.util.Log;
+import net.i2p.util.I2PThread;
 import net.i2p.util.NativeBigInteger;
 import net.i2p.util.RandomSource;
 
@@ -78,7 +79,7 @@ class YKGenerator {
 	
 	if (_log.shouldLog(Log.DEBUG)) _log.debug("ElGamal YK Precalc (minimum: " + MIN_NUM_BUILDERS + " max: " + MAX_NUM_BUILDERS + ", delay: " + CALC_DELAY + ")");
 	
-	_precalcThread = new Thread(new YKPrecalcRunner(MIN_NUM_BUILDERS, MAX_NUM_BUILDERS));
+	_precalcThread = new I2PThread(new YKPrecalcRunner(MIN_NUM_BUILDERS, MAX_NUM_BUILDERS));
 	_precalcThread.setName("YK Precalc");
 	_precalcThread.setDaemon(true);
 	_precalcThread.setPriority(Thread.MIN_PRIORITY);
-- 
GitLab