forked from I2P_Developers/i2p.i2p
- Use new synchronized change-and-save-config methods
to eliminate races with ReadConfigJob
This commit is contained in:
@@ -31,16 +31,14 @@ public class PersistentKeyRing extends KeyRing {
|
||||
public SessionKey put(Hash h, SessionKey sk) {
|
||||
SessionKey old = super.put(h, sk);
|
||||
if (!sk.equals(old)) {
|
||||
_ctx.router().setConfigSetting(PROP_PFX + h.toBase64().replace("=", "$"),
|
||||
_ctx.router().saveConfig(PROP_PFX + h.toBase64().replace("=", "$"),
|
||||
sk.toBase64());
|
||||
_ctx.router().saveConfig();
|
||||
}
|
||||
return old;
|
||||
}
|
||||
|
||||
public SessionKey remove(Hash h) {
|
||||
_ctx.router().removeConfigSetting(PROP_PFX + h.toBase64().replace("=", "$"));
|
||||
_ctx.router().saveConfig();
|
||||
_ctx.router().saveConfig(PROP_PFX + h.toBase64().replace("=", "$"), null);
|
||||
return super.remove(h);
|
||||
}
|
||||
|
||||
|
@@ -660,9 +660,11 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
}
|
||||
|
||||
// now that we have random ports, keeping the same port would be bad
|
||||
removeConfigSetting(UDPTransport.PROP_INTERNAL_PORT);
|
||||
removeConfigSetting(UDPTransport.PROP_EXTERNAL_PORT);
|
||||
saveConfig();
|
||||
synchronized(this) {
|
||||
removeConfigSetting(UDPTransport.PROP_INTERNAL_PORT);
|
||||
removeConfigSetting(UDPTransport.PROP_EXTERNAL_PORT);
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
if (remCount > 0) {
|
||||
FileOutputStream log = null;
|
||||
@@ -1061,8 +1063,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
|
||||
// Set the last version to the current version, since 0.8.13
|
||||
if (!RouterVersion.VERSION.equals(_config.get("router.previousVersion"))) {
|
||||
_config.put("router.previousVersion", RouterVersion.VERSION);
|
||||
saveConfig();
|
||||
saveConfig("router.previousVersion", RouterVersion.VERSION);
|
||||
}
|
||||
|
||||
_context.removeShutdownTasks();
|
||||
@@ -1301,7 +1302,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
_config.putAll(toAdd);
|
||||
if (toRemove != null) {
|
||||
for (String s : toRemove) {
|
||||
_config.remove(toRemove);
|
||||
_config.remove(s);
|
||||
}
|
||||
}
|
||||
return saveConfig();
|
||||
|
@@ -15,6 +15,8 @@ import java.security.GeneralSecurityException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLServerSocketFactory;
|
||||
@@ -112,9 +114,10 @@ class SSLClientListenerRunner extends ClientListenerRunner {
|
||||
success = ks.exists();
|
||||
if (success) {
|
||||
SecureFileOutputStream.setPerms(ks);
|
||||
_context.router().setConfigSetting(PROP_KEYSTORE_PASSWORD, DEFAULT_KEYSTORE_PASSWORD);
|
||||
_context.router().setConfigSetting(PROP_KEY_PASSWORD, keyPassword);
|
||||
_context.router().saveConfig();
|
||||
Map<String, String> changes = new HashMap();
|
||||
changes.put(PROP_KEYSTORE_PASSWORD, DEFAULT_KEYSTORE_PASSWORD);
|
||||
changes.put(PROP_KEY_PASSWORD, keyPassword);
|
||||
_context.router().saveConfig(changes, null);
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
|
@@ -252,9 +252,10 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||
addr.setTransportStyle(NTCPTransport.STYLE);
|
||||
//if (isNew) {
|
||||
// why save the same thing?
|
||||
ctx.router().setConfigSetting(PROP_I2NP_NTCP_HOSTNAME, name);
|
||||
ctx.router().setConfigSetting(PROP_I2NP_NTCP_PORT, port);
|
||||
ctx.router().saveConfig();
|
||||
Map<String, String> changes = new HashMap();
|
||||
changes.put(PROP_I2NP_NTCP_HOSTNAME, name);
|
||||
changes.put(PROP_I2NP_NTCP_PORT, port);
|
||||
ctx.router().saveConfig(changes, null);
|
||||
//}
|
||||
return addr;
|
||||
}
|
||||
|
@@ -282,8 +282,7 @@ class GeoIP {
|
||||
return;
|
||||
String country = _context.commSystem().getCountry(ourHash);
|
||||
if (country != null && !country.equals(oldCountry)) {
|
||||
_context.router().setConfigSetting(PROP_IP_COUNTRY, country);
|
||||
_context.router().saveConfig();
|
||||
_context.router().saveConfig(PROP_IP_COUNTRY, country);
|
||||
if (_context.commSystem().isInBadCountry() && _context.getProperty(Router.PROP_HIDDEN_HIDDEN) == null) {
|
||||
String name = fullName(country);
|
||||
if (name == null)
|
||||
|
@@ -319,9 +319,10 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
if (newPort != port || newPort != oldIPort || newPort != oldEPort) {
|
||||
// attempt to use it as our external port - this will be overridden by
|
||||
// externalAddressReceived(...)
|
||||
_context.router().setConfigSetting(PROP_INTERNAL_PORT, newPort+"");
|
||||
_context.router().setConfigSetting(PROP_EXTERNAL_PORT, newPort+"");
|
||||
_context.router().saveConfig();
|
||||
Map<String, String> changes = new HashMap();
|
||||
changes.put(PROP_INTERNAL_PORT, newPort+"");
|
||||
changes.put(PROP_EXTERNAL_PORT, newPort+"");
|
||||
_context.router().saveConfig(changes, null);
|
||||
}
|
||||
|
||||
_establisher.startup();
|
||||
@@ -560,8 +561,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
_context.statManager().addRateData("udp.addressTestInsteadOfUpdate", 1, 0);
|
||||
} else if (updated) {
|
||||
_context.statManager().addRateData("udp.addressUpdated", 1, 0);
|
||||
Map<String, String> changes = new HashMap();
|
||||
if (!fixedPort)
|
||||
_context.router().setConfigSetting(PROP_EXTERNAL_PORT, ourPort+"");
|
||||
changes.put(PROP_EXTERNAL_PORT, ourPort+"");
|
||||
// queue a country code lookup of the new IP
|
||||
_context.commSystem().queueLookup(ourIP);
|
||||
// store these for laptop-mode (change ident on restart... or every time... when IP changes)
|
||||
@@ -576,9 +578,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
|
||||
_context.router().setConfigSetting(PROP_IP, _externalListenHost.getHostAddress());
|
||||
_context.router().setConfigSetting(PROP_IP_CHANGE, "" + now);
|
||||
_context.router().saveConfig();
|
||||
changes.put(PROP_IP, _externalListenHost.getHostAddress());
|
||||
changes.put(PROP_IP_CHANGE, "" + now);
|
||||
_context.router().saveConfig(changes, null);
|
||||
|
||||
// laptop mode
|
||||
// For now, only do this at startup
|
||||
@@ -596,6 +598,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
_context.router().shutdown(Router.EXIT_HARD_RESTART);
|
||||
// doesn't return
|
||||
}
|
||||
} else if (!fixedPort) {
|
||||
// save PROP_EXTERNAL_PORT
|
||||
_context.router().saveConfig(changes, null);
|
||||
}
|
||||
_context.router().rebuildRouterInfo();
|
||||
}
|
||||
|
Reference in New Issue
Block a user