From 5ed29b6c278f4f0e1b73f136faf0d96152e9b646 Mon Sep 17 00:00:00 2001
From: zzz
/>
<%=intl._("Hidden mode - do not publish IP")%> <%=intl._("(prevents participating traffic)")%>
+
+ <%=intl._("Action when IP changes")%>:
+ />
+ <%=intl._("Laptop mode - Change router identity and UDP port when IP changes for enhanced anonymity")%>
+ (<%=intl._("Experimental")%>)
<%=intl._("UDP Configuration:")%>
<%=intl._("UDP port:")%>
" />
diff --git a/history.txt b/history.txt
index 6dbb8c8c3..064ce2c62 100644
--- a/history.txt
+++ b/history.txt
@@ -1,3 +1,11 @@
+2010-01-02 zzz
+ * Console: Save refresh setting
+ * i2psnark:
+ - Don't URL-encode chars we don't have to
+ - CSS tweaks
+ * Transport: Implement 'laptop mode' to change ident and port
+ when the IP changes
+
2010-01-01 sponge
* Happy New year everyone!
* Added a target to generate a stand-alone BOB jar file.
diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java
index 4ed70a772..6c97b2124 100644
--- a/router/java/src/net/i2p/router/Router.java
+++ b/router/java/src/net/i2p/router/Router.java
@@ -37,6 +37,7 @@ import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.router.startup.StartupJob;
import net.i2p.router.startup.WorkingDir;
import net.i2p.router.transport.FIFOBandwidthLimiter;
+import net.i2p.router.transport.udp.UDPTransport;
import net.i2p.stat.Rate;
import net.i2p.stat.RateStat;
import net.i2p.stat.StatManager;
@@ -314,10 +315,10 @@ public class Router {
readConfig();
setupHandlers();
- if (ALLOW_DYNAMIC_KEYS) {
- if ("true".equalsIgnoreCase(_context.getProperty(Router.PROP_HIDDEN, "false")))
- killKeys();
- }
+ //if (ALLOW_DYNAMIC_KEYS) {
+ // if ("true".equalsIgnoreCase(_context.getProperty(Router.PROP_HIDDEN, "false")))
+ // killKeys();
+ //}
_context.messageValidator().startup();
_context.tunnelDispatcher().startup();
@@ -526,7 +527,7 @@ public class Router {
static final String IDENTLOG = "identlog.txt";
public void killKeys() {
- new Exception("Clearing identity files").printStackTrace();
+ //new Exception("Clearing identity files").printStackTrace();
int remCount = 0;
for (int i = 0; i < _rebuildFiles.length; i++) {
File f = new File(_context.getRouterDir(),_rebuildFiles[i]);
@@ -540,6 +541,12 @@ public class Router {
}
}
}
+
+ // now that we have random ports, keeping the same port would be bad
+ removeConfigSetting(UDPTransport.PROP_INTERNAL_PORT);
+ removeConfigSetting(UDPTransport.PROP_EXTERNAL_PORT);
+ saveConfig();
+
if (remCount > 0) {
FileOutputStream log = null;
try {
@@ -909,11 +916,11 @@ public class Router {
*/
private static final boolean ALLOW_DYNAMIC_KEYS = false;
- public void finalShutdown(int exitCode) {
+ private void finalShutdown(int exitCode) {
_log.log(Log.CRIT, "Shutdown(" + exitCode + ") complete", new Exception("Shutdown"));
try { _context.logManager().shutdown(); } catch (Throwable t) { }
if (ALLOW_DYNAMIC_KEYS) {
- if ("true".equalsIgnoreCase(_context.getProperty(PROP_DYNAMIC_KEYS, "false")))
+ if (Boolean.valueOf(_context.getProperty(PROP_DYNAMIC_KEYS)).booleanValue())
killKeys();
}
diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java
index 983dd2f06..8c1e82035 100644
--- a/router/java/src/net/i2p/router/RouterVersion.java
+++ b/router/java/src/net/i2p/router/RouterVersion.java
@@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
- public final static long BUILD = 13;
+ public final static long BUILD = 14;
/** for example "-test" */
public final static String EXTRA = "";
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
index c5d5e6106..075326c53 100644
--- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
+++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java
@@ -132,6 +132,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
/** remember IP changes */
public static final String PROP_IP= "i2np.lastIP";
public static final String PROP_IP_CHANGE = "i2np.lastIPChange";
+ public static final String PROP_LAPTOP_MODE = "i2np.laptopMode";
/** do we require introducers, regardless of our status? */
public static final String PROP_FORCE_INTRODUCERS = "i2np.udp.forceIntroducers";
@@ -516,9 +517,35 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
// store these for laptop-mode (change ident on restart... or every time... when IP changes)
String oldIP = _context.getProperty(PROP_IP);
if (!_externalListenHost.getHostAddress().equals(oldIP)) {
+ long lastChanged = 0;
+ long now = _context.clock().now();
+ String lcs = _context.getProperty(PROP_IP_CHANGE);
+ if (lcs != null) {
+ try {
+ lastChanged = Long.parseLong(lcs);
+ } catch (NumberFormatException nfe) {}
+ }
+
_context.router().setConfigSetting(PROP_IP, _externalListenHost.getHostAddress());
- _context.router().setConfigSetting(PROP_IP_CHANGE, "" + _context.clock().now());
+ _context.router().setConfigSetting(PROP_IP_CHANGE, "" + now);
_context.router().saveConfig();
+
+ // laptop mode
+ // For now, only do this at startup
+ if (oldIP != null &&
+ System.getProperty("wrapper.version") != null &&
+ Boolean.valueOf(_context.getProperty(PROP_LAPTOP_MODE)).booleanValue() &&
+ now - lastChanged > 10*60*1000 &&
+ _context.router().getUptime() < 10*60*1000) {
+ _log.log(Log.CRIT, "IP changed, restarting with a new identity and port");
+ // this removes the UDP port config
+ _context.router().killKeys();
+ // do we need WrapperManager.signalStopped() like in ConfigServiceHandler ???
+ // without it, the wrapper complains "shutdown unexpectedly"
+ // but we can't have that dependency in the router
+ _context.router().shutdown(Router.EXIT_HARD_RESTART);
+ // doesn't return
+ }
}
_context.router().rebuildRouterInfo();
}