laptop mode

This commit is contained in:
zzz
2010-01-02 02:46:23 +00:00
parent 2d5decd943
commit 5ed29b6c27
7 changed files with 75 additions and 11 deletions

View File

@ -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();
}

View File

@ -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;

View File

@ -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();
}