From ff499844a2ba801e03cd9b3ad2c4354bb27728a3 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Wed, 16 Nov 2011 00:56:45 +0000 Subject: [PATCH] * Router: Move router.ping file from temp directory to config directory --- core/java/src/net/i2p/I2PAppContext.java | 30 +++++++++++++------ router/java/src/net/i2p/router/Router.java | 9 +++--- .../src/net/i2p/router/RouterContext.java | 2 -- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/core/java/src/net/i2p/I2PAppContext.java b/core/java/src/net/i2p/I2PAppContext.java index 9fde92ab10..aabe150110 100644 --- a/core/java/src/net/i2p/I2PAppContext.java +++ b/core/java/src/net/i2p/I2PAppContext.java @@ -67,7 +67,7 @@ public class I2PAppContext { /** the context that components without explicit root are bound */ protected static volatile I2PAppContext _globalAppContext; - protected I2PProperties _overrideProps; + protected final I2PProperties _overrideProps; private StatManager _statManager; private SessionKeyManager _sessionKeyManager; @@ -85,6 +85,7 @@ public class I2PAppContext { private RandomSource _random; private KeyGenerator _keyGenerator; protected KeyRing _keyRing; // overridden in RouterContext + private final ServiceDirectory _serviceDir; private volatile boolean _statManagerInitialized; private volatile boolean _sessionKeyManagerInitialized; private volatile boolean _namingServiceInitialized; @@ -199,6 +200,7 @@ public class I2PAppContext { if (envProps != null) _overrideProps.putAll(envProps); _shutdownTasks = new ConcurrentHashSet(32); + _serviceDir = new ServiceDirectory(); initializeDirs(); } @@ -212,10 +214,10 @@ public class I2PAppContext { * Base i2p.dir.base getBaseDir() lib/, webapps/, docs/, geoip/, licenses/, ... * Temp i2p.dir.temp getTempDir() Temporary files * Config i2p.dir.config getConfigDir() *.config, hosts.txt, addressbook/, ... - * PID i2p.dir.pid getPIDDir() router.ping * * (the following all default to the same as Config) * + * PID i2p.dir.pid getPIDDir() router.ping * Router i2p.dir.router getRouterDir() netDb/, peerProfiles/, router.*, keyBackup/, ... * Log i2p.dir.log getLogDir() logs/ * App i2p.dir.app getAppDir() eepsite/, ... @@ -250,6 +252,7 @@ public class I2PAppContext { private void initializeDirs() { String s = getProperty("i2p.dir.base", System.getProperty("user.dir")); _baseDir = new File(s); + // config defaults to base s = getProperty("i2p.dir.config"); if (s != null) { @@ -259,6 +262,7 @@ public class I2PAppContext { } else { _configDir = _baseDir; } + // router defaults to config s = getProperty("i2p.dir.router"); if (s != null) { @@ -268,11 +272,17 @@ public class I2PAppContext { } else { _routerDir = _configDir; } - // pid defaults to system temp directory - s = getProperty("i2p.dir.pid", System.getProperty("java.io.tmpdir")); - _pidDir = new File(s); - if (!_pidDir.exists()) - _pidDir.mkdir(); + + // pid defaults to router directory (as of 0.8.12, was system temp dir previously) + s = getProperty("i2p.dir.pid"); + if (s != null) { + _pidDir = new SecureDirectory(s); + if (!_pidDir.exists()) + _pidDir.mkdir(); + } else { + _pidDir = _routerDir; + } + // these all default to router s = getProperty("i2p.dir.log"); if (s != null) { @@ -282,6 +292,7 @@ public class I2PAppContext { } else { _logDir = _routerDir; } + s = getProperty("i2p.dir.app"); if (s != null) { _appDir = new SecureDirectory(s); @@ -339,8 +350,9 @@ public class I2PAppContext { /** * Where router.ping goes. * Applications should not use this. - * The same as the system temp dir for now. - * Which is a problem for multi-user installations. + * The same as the router dir by default as of 0.8.12 + * Was the same as the system temp dir prior to that. + * Which was a problem for multi-user installations. * @since 0.7.6 * @return dir constant for the life of the context */ diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index 980c761bf1..26f22fbc86 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -1555,7 +1555,7 @@ public class Router implements RouterClock.ClockShiftListener { */ private void beginMarkingLiveliness() { File f = getPingFile(); - SimpleScheduler.getInstance().addPeriodicEvent(new MarkLiveliness(this, f), 0, LIVELINESS_DELAY); + SimpleScheduler.getInstance().addPeriodicEvent(new MarkLiveliness(this, f), 0, LIVELINESS_DELAY - (5*1000)); } public static final String PROP_BANDWIDTH_SHARE_PERCENTAGE = "router.sharePercentage"; @@ -1812,11 +1812,12 @@ private static class UpdateRoutingKeyModifierJob extends JobImpl { } /** - * Write a timestamp to the ping file where the wrapper can see it + * Write a timestamp to the ping file where + * other routers trying to use the same configuration can see it */ private static class MarkLiveliness implements SimpleTimer.TimedEvent { - private Router _router; - private File _pingFile; + private final Router _router; + private final File _pingFile; public MarkLiveliness(Router router, File pingFile) { _router = router; diff --git a/router/java/src/net/i2p/router/RouterContext.java b/router/java/src/net/i2p/router/RouterContext.java index 10ea970916..209ff218a1 100644 --- a/router/java/src/net/i2p/router/RouterContext.java +++ b/router/java/src/net/i2p/router/RouterContext.java @@ -117,9 +117,7 @@ public class RouterContext extends I2PAppContext { * @param value The new value for the property. */ public void setProperty(String propName, String value) { - if(_overrideProps != null) { _overrideProps.setProperty(propName, value); - } } -- GitLab