diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java
index 782d67d36..cb9cbaada 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 9c51f7e23..6a0a6f20a 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 d40062821..b669d1353 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 9faf82ad4..6aa8ca18f 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 7141e1738..db9346bb7 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("
\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("
\n");
+ buf.append("Full destination: ");
+ buf.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("
\n");
+ }
+ }
+ }
}
public void log(String s) {