diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java index 782d67d36cd46598b2a7f9c75238f82ea7f6e94b..cb9cbaadaa58ab0983fb3be8fb21f6f260e7910a 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java @@ -54,6 +54,7 @@ import net.i2p.I2PAppContext; import net.i2p.I2PException; import net.i2p.client.I2PClient; import net.i2p.client.I2PClientFactory; +import net.i2p.client.I2PSession; import net.i2p.client.naming.NamingService; import net.i2p.data.Base64; import net.i2p.data.DataFormatException; @@ -71,6 +72,7 @@ public class I2PTunnel implements Logging, EventDispatcher { private static long __tunnelId = 0; private long _tunnelId; private Properties _clientOptions; + private List _sessions; public static final int PACKET_DELAY = 100; @@ -108,6 +110,7 @@ public class I2PTunnel implements Logging, EventDispatcher { _event = new EventDispatcherImpl(); _clientOptions = new Properties(); _clientOptions.putAll(System.getProperties()); + _sessions = new ArrayList(1); addConnectionEventListener(lsnr); boolean gui = true; @@ -172,6 +175,24 @@ public class I2PTunnel implements Logging, EventDispatcher { } } + List getSessions() { + synchronized (_sessions) { + return new ArrayList(_sessions); + } + } + void addSession(I2PSession session) { + if (session == null) return; + synchronized (_sessions) { + _sessions.add(session); + } + } + void removeSession(I2PSession session) { + if (session == null) return; + synchronized (_sessions) { + _sessions.remove(session); + } + } + public Properties getClientOptions() { return _clientOptions; } private void addtask(I2PTunnelTask tsk) { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java index 9c51f7e23f97ece83078a273158423e4e6683a2d..6a0a6f20aacb568a5766f8577ea4aecd9fca2400 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java @@ -86,6 +86,8 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna } l.log("I2P session created"); + getTunnel().addSession(sockMgr.getSession()); + Thread t = new I2PThread(this); t.setName("Client " + _clientId); listenerReady = false; @@ -275,6 +277,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna } return false; } + getTunnel().removeSession(sockMgr.getSession()); l.log("Closing client " + toString()); try { if (ss != null) ss.close(); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java index d40062821c295f42f4c1e40268f76887b39ff7c6..b669d1353c34326ef143eb60d4b203c991eb72ca 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java @@ -80,6 +80,7 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { } sockMgr.setName("Server"); + getTunnel().addSession(sockMgr.getSession()); l.log("Ready!"); notifyEvent("openServerResult", "ok"); open = true; @@ -130,6 +131,7 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { l.log("Shutting down server " + toString()); try { if (i2pss != null) i2pss.close(); + getTunnel().removeSession(sockMgr.getSession()); sockMgr.getSession().destroySession(); } catch (I2PException ex) { _log.error("Error destroying the session", ex); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelTask.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelTask.java index 9faf82ad493012531d7170e79e37b751240e854b..6aa8ca18f7314434d98ef52fd2d2eae1d9930fbc 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelTask.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelTask.java @@ -64,6 +64,7 @@ public abstract class I2PTunnelTask implements EventDispatcher { public void disconnected(I2PSession session) { routerDisconnected(); + getTunnel().removeSession(session); } public void errorOccurred(I2PSession session, String message, Throwable error) { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java index 7141e17384cd28f05e2fcef5a264c8d6f4d88f83..db9346bb7231a8ae13afebf476fb0cba8682a035 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java @@ -13,6 +13,7 @@ import net.i2p.I2PAppContext; import net.i2p.I2PException; import net.i2p.client.I2PClient; import net.i2p.client.I2PClientFactory; +import net.i2p.client.I2PSession; import net.i2p.data.Destination; import net.i2p.util.Log; @@ -39,7 +40,7 @@ public class TunnelController implements Logging { * @param prefix beginning of key values that are relevent to this tunnel */ public TunnelController(Properties config, String prefix) { - this(config, prefix, false); + this(config, prefix, true); } /** * @@ -53,7 +54,7 @@ public class TunnelController implements Logging { setConfig(config, prefix); _messages = new ArrayList(4); _running = false; - if (createKey) + if (createKey && ("server".equals(getType())) ) createPrivateKey(); if (getStartOnLoad()) startTunnel(); @@ -61,6 +62,12 @@ public class TunnelController implements Logging { private void createPrivateKey() { I2PClient client = I2PClientFactory.createClient(); + String filename = getPrivKeyFile(); + if ( (filename == null) || (filename.trim().length() <= 0) ) { + log("No filename specified for the private key"); + return; + } + File keyFile = new File(getPrivKeyFile()); if (keyFile.exists()) { log("Not overwriting existing private keys in " + keyFile.getAbsolutePath()); @@ -312,6 +319,24 @@ public class TunnelController implements Logging { String opts = getClientOptions(); if ( (opts != null) && (opts.length() > 0) ) buf.append("Network options: ").append(opts).append("<br />\n"); + if (_running) { + List sessions = _tunnel.getSessions(); + for (int i = 0; i < sessions.size(); i++) { + I2PSession session = (I2PSession)sessions.get(i); + Destination dest = session.getMyDestination(); + if (dest != null) { + buf.append("Destination hash: ").append(dest.calculateHash().toBase64()).append("<br />\n"); + buf.append("Full destination: "); + buf.append("<input type=\"text\" size=\"10\" onclick=\"this.select();\" "); + buf.append("value=\"").append(dest.toBase64()).append("\" />\n"); + if ("server".equals(getType())) { + buf.append(" Give that out to people so they can view your service."); + buf.append(" If you are going to share it on irc, be sure to split it on two lines"); + } + buf.append("<br />\n"); + } + } + } } public void log(String s) {