forked from I2P_Developers/i2p.i2p
- Use new synchronized change-and-save-config methods
to eliminate races with ReadConfigJob
This commit is contained in:
@ -38,8 +38,7 @@ public class CSSHelper extends HelperBase {
|
||||
public void setLang(String lang) {
|
||||
// Protected with nonce in css.jsi
|
||||
if (lang != null && lang.length() == 2 && !lang.equals(_context.getProperty(Messages.PROP_LANG))) {
|
||||
_context.router().setConfigSetting(Messages.PROP_LANG, lang);
|
||||
_context.router().saveConfig();
|
||||
_context.router().saveConfig(Messages.PROP_LANG, lang);
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,8 +60,7 @@ public class CSSHelper extends HelperBase {
|
||||
|
||||
/** change refresh and save it */
|
||||
public void setRefresh(String r) {
|
||||
_context.router().setConfigSetting(PROP_REFRESH, r);
|
||||
_context.router().saveConfig();
|
||||
_context.router().saveConfig(PROP_REFRESH, r);
|
||||
}
|
||||
|
||||
/** @return refresh time in seconds, as a string */
|
||||
|
@ -53,18 +53,11 @@ public class ConfigAdvancedHandler extends FormHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map.Entry e : props.entrySet()) {
|
||||
String key = (String) e.getKey();
|
||||
String val = (String) e.getValue();
|
||||
_context.router().setConfigSetting(key, val);
|
||||
for (Object key : props.keySet()) {
|
||||
unsetKeys.remove(key);
|
||||
}
|
||||
|
||||
for (String unsetKey : unsetKeys) {
|
||||
_context.router().removeConfigSetting(unsetKey);
|
||||
}
|
||||
|
||||
boolean saved = _context.router().saveConfig();
|
||||
boolean saved = _context.router().saveConfig(props, unsetKeys);
|
||||
if (saved)
|
||||
addFormNotice(_("Configuration saved successfully"));
|
||||
else
|
||||
|
@ -2,6 +2,10 @@ package net.i2p.router.web;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.router.transport.FIFOBandwidthRefiller;
|
||||
@ -45,6 +49,7 @@ public class ConfigNetHandler extends FormHandler {
|
||||
private boolean _enableLoadTesting;
|
||||
private String _sharePct;
|
||||
private boolean _ratesOnly;
|
||||
private final Map<String, String> changes = new HashMap();
|
||||
private static final String PROP_HIDDEN = Router.PROP_HIDDEN_HIDDEN; // see Router for other choice
|
||||
|
||||
@Override
|
||||
@ -137,6 +142,7 @@ public class ConfigNetHandler extends FormHandler {
|
||||
*/
|
||||
private void saveChanges() {
|
||||
boolean restartRequired = false;
|
||||
List<String> removes = new ArrayList();
|
||||
|
||||
if (!_ratesOnly) {
|
||||
// IP Settings
|
||||
@ -153,15 +159,15 @@ public class ConfigNetHandler extends FormHandler {
|
||||
else
|
||||
_udpAutoIP = UDPTransport.DEFAULT_SOURCES;
|
||||
}
|
||||
_context.router().setConfigSetting(UDPTransport.PROP_SOURCES, _udpAutoIP);
|
||||
changes.put(UDPTransport.PROP_SOURCES, _udpAutoIP);
|
||||
boolean valid = true;
|
||||
if (uhost.length() > 0) {
|
||||
valid = verifyAddress(uhost);
|
||||
if (valid) {
|
||||
_context.router().setConfigSetting(UDPTransport.PROP_EXTERNAL_HOST, uhost);
|
||||
changes.put(UDPTransport.PROP_EXTERNAL_HOST, uhost);
|
||||
}
|
||||
} else {
|
||||
_context.router().removeConfigSetting(UDPTransport.PROP_EXTERNAL_HOST);
|
||||
removes.add(UDPTransport.PROP_EXTERNAL_HOST);
|
||||
}
|
||||
if (valid && ((!oldUdp.equals(_udpAutoIP)) || (!oldUHost.equals(uhost)))) {
|
||||
addFormNotice(_("Updating IP address"));
|
||||
@ -187,31 +193,31 @@ public class ConfigNetHandler extends FormHandler {
|
||||
} else if ("false".equals(_ntcpAutoIP) && _ntcpHostname.length() > 0) {
|
||||
valid = verifyAddress(_ntcpHostname);
|
||||
if (valid) {
|
||||
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME, _ntcpHostname);
|
||||
changes.put(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME, _ntcpHostname);
|
||||
addFormNotice(_("Updating inbound TCP address to") + " " + _ntcpHostname);
|
||||
}
|
||||
} else {
|
||||
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME);
|
||||
removes.add(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME);
|
||||
if ("false".equals(_ntcpAutoIP))
|
||||
addFormNotice(_("Disabling inbound TCP"));
|
||||
else
|
||||
addFormNotice(_("Updating inbound TCP address to auto")); // true or always
|
||||
}
|
||||
if (valid) {
|
||||
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_IP, _ntcpAutoIP);
|
||||
_context.router().setConfigSetting(TransportManager.PROP_ENABLE_NTCP, "" + !"disabled".equals(_ntcpAutoIP));
|
||||
changes.put(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_IP, _ntcpAutoIP);
|
||||
changes.put(TransportManager.PROP_ENABLE_NTCP, "" + !"disabled".equals(_ntcpAutoIP));
|
||||
restartRequired = true;
|
||||
}
|
||||
}
|
||||
if (oldAutoPort != _ntcpAutoPort || ! oldNPort.equals(_ntcpPort)) {
|
||||
if (_ntcpPort.length() > 0 && !_ntcpAutoPort) {
|
||||
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT, _ntcpPort);
|
||||
changes.put(ConfigNetHelper.PROP_I2NP_NTCP_PORT, _ntcpPort);
|
||||
addFormNotice(_("Updating inbound TCP port to") + " " + _ntcpPort);
|
||||
} else {
|
||||
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT);
|
||||
removes.add(ConfigNetHelper.PROP_I2NP_NTCP_PORT);
|
||||
addFormNotice(_("Updating inbound TCP port to auto"));
|
||||
}
|
||||
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_PORT, "" + _ntcpAutoPort);
|
||||
changes.put(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_PORT, "" + _ntcpAutoPort);
|
||||
restartRequired = true;
|
||||
}
|
||||
|
||||
@ -219,8 +225,8 @@ public class ConfigNetHandler extends FormHandler {
|
||||
if ( (_udpPort != null) && (_udpPort.length() > 0) ) {
|
||||
String oldPort = "" + _context.getProperty(UDPTransport.PROP_INTERNAL_PORT, UDPTransport.DEFAULT_INTERNAL_PORT);
|
||||
if (!oldPort.equals(_udpPort)) {
|
||||
_context.router().setConfigSetting(UDPTransport.PROP_INTERNAL_PORT, _udpPort);
|
||||
_context.router().setConfigSetting(UDPTransport.PROP_EXTERNAL_PORT, _udpPort);
|
||||
changes.put(UDPTransport.PROP_INTERNAL_PORT, _udpPort);
|
||||
changes.put(UDPTransport.PROP_EXTERNAL_PORT, _udpPort);
|
||||
addFormNotice(_("Updating UDP port from") + " " + oldPort + " " + _("to") + " " + _udpPort);
|
||||
restartRequired = true;
|
||||
}
|
||||
@ -228,21 +234,21 @@ public class ConfigNetHandler extends FormHandler {
|
||||
|
||||
}
|
||||
|
||||
updateRates();
|
||||
boolean ratesUpdated = updateRates();
|
||||
|
||||
boolean switchRequired = false;
|
||||
if (!_ratesOnly) {
|
||||
// If hidden mode value changes, restart is required
|
||||
switchRequired = _hiddenMode != _context.router().isHidden();
|
||||
if (switchRequired) {
|
||||
_context.router().setConfigSetting(PROP_HIDDEN, "" + _hiddenMode);
|
||||
changes.put(PROP_HIDDEN, "" + _hiddenMode);
|
||||
if (_hiddenMode)
|
||||
addFormError(_("Gracefully restarting into Hidden Router Mode"));
|
||||
else
|
||||
addFormError(_("Gracefully restarting to exit Hidden Router Mode"));
|
||||
}
|
||||
|
||||
_context.router().setConfigSetting(Router.PROP_DYNAMIC_KEYS, "" + _dynamicKeys);
|
||||
changes.put(Router.PROP_DYNAMIC_KEYS, "" + _dynamicKeys);
|
||||
|
||||
if (Boolean.valueOf(_context.getProperty(TransportManager.PROP_ENABLE_UPNP)).booleanValue() !=
|
||||
_upnp) {
|
||||
@ -252,7 +258,7 @@ public class ConfigNetHandler extends FormHandler {
|
||||
else
|
||||
addFormNotice(_("Disabling UPnP, restart required to take effect"));
|
||||
}
|
||||
_context.router().setConfigSetting(TransportManager.PROP_ENABLE_UPNP, "" + _upnp);
|
||||
changes.put(TransportManager.PROP_ENABLE_UPNP, "" + _upnp);
|
||||
|
||||
if (Boolean.valueOf(_context.getProperty(UDPTransport.PROP_LAPTOP_MODE)).booleanValue() !=
|
||||
_laptop) {
|
||||
@ -262,28 +268,32 @@ public class ConfigNetHandler extends FormHandler {
|
||||
else
|
||||
addFormNotice(_("Disabling laptop mode"));
|
||||
}
|
||||
_context.router().setConfigSetting(UDPTransport.PROP_LAPTOP_MODE, "" + _laptop);
|
||||
changes.put(UDPTransport.PROP_LAPTOP_MODE, "" + _laptop);
|
||||
|
||||
if (_requireIntroductions) {
|
||||
_context.router().setConfigSetting(UDPTransport.PROP_FORCE_INTRODUCERS, "true");
|
||||
changes.put(UDPTransport.PROP_FORCE_INTRODUCERS, "true");
|
||||
addFormNotice(_("Requiring SSU introducers"));
|
||||
} else {
|
||||
_context.router().removeConfigSetting(UDPTransport.PROP_FORCE_INTRODUCERS);
|
||||
removes.add(UDPTransport.PROP_FORCE_INTRODUCERS);
|
||||
}
|
||||
|
||||
// Time sync enable, means NOT disabled
|
||||
// Hmm router sets this at startup, not required here
|
||||
//_context.router().setConfigSetting(Timestamper.PROP_DISABLED, "false");
|
||||
//changes.put(Timestamper.PROP_DISABLED, "false");
|
||||
|
||||
// Hidden in the GUI
|
||||
//LoadTestManager.setEnableLoadTesting(_context, _enableLoadTesting);
|
||||
}
|
||||
|
||||
boolean saved = _context.router().saveConfig();
|
||||
boolean saved = _context.router().saveConfig(changes, removes);
|
||||
if (saved)
|
||||
addFormNotice(_("Configuration saved successfully"));
|
||||
else
|
||||
addFormError(_("Error saving the configuration (applied but not saved) - please see the error logs"));
|
||||
|
||||
// this has to be after the save
|
||||
if (ratesUpdated)
|
||||
_context.bandwidthLimiter().reinitialize();
|
||||
|
||||
if (switchRequired) {
|
||||
hiddenSwitch();
|
||||
@ -343,14 +353,17 @@ public class ConfigNetHandler extends FormHandler {
|
||||
private static final int DEF_BURST_PCT = 10;
|
||||
private static final int DEF_BURST_TIME = 20;
|
||||
|
||||
private void updateRates() {
|
||||
/**
|
||||
* @return changed
|
||||
*/
|
||||
private boolean updateRates() {
|
||||
boolean updated = false;
|
||||
boolean bwUpdated = false;
|
||||
|
||||
if (_sharePct != null) {
|
||||
String old = _context.router().getConfigSetting(Router.PROP_BANDWIDTH_SHARE_PERCENTAGE);
|
||||
if ( (old == null) || (!old.equals(_sharePct)) ) {
|
||||
_context.router().setConfigSetting(Router.PROP_BANDWIDTH_SHARE_PERCENTAGE, _sharePct);
|
||||
changes.put(Router.PROP_BANDWIDTH_SHARE_PERCENTAGE, _sharePct);
|
||||
addFormNotice(_("Updating bandwidth share percentage"));
|
||||
updated = true;
|
||||
}
|
||||
@ -359,23 +372,23 @@ public class ConfigNetHandler extends FormHandler {
|
||||
// Since burst is now hidden in the gui, set burst to +10% for 20 seconds
|
||||
if ( (_inboundRate != null) && (_inboundRate.length() > 0) &&
|
||||
!_inboundRate.equals(_context.getProperty(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH, "" + FIFOBandwidthRefiller.DEFAULT_INBOUND_BANDWIDTH))) {
|
||||
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH, _inboundRate);
|
||||
changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH, _inboundRate);
|
||||
try {
|
||||
int rate = Integer.parseInt(_inboundRate) * (100 + DEF_BURST_PCT) / 100;
|
||||
int kb = DEF_BURST_TIME * rate;
|
||||
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH, "" + rate);
|
||||
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH_PEAK, "" + kb);
|
||||
changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH, "" + rate);
|
||||
changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH_PEAK, "" + kb);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
bwUpdated = true;
|
||||
}
|
||||
if ( (_outboundRate != null) && (_outboundRate.length() > 0) &&
|
||||
!_outboundRate.equals(_context.getProperty(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH, "" + FIFOBandwidthRefiller.DEFAULT_OUTBOUND_BANDWIDTH))) {
|
||||
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH, _outboundRate);
|
||||
changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH, _outboundRate);
|
||||
try {
|
||||
int rate = Integer.parseInt(_outboundRate) * (100 + DEF_BURST_PCT) / 100;
|
||||
int kb = DEF_BURST_TIME * rate;
|
||||
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH, "" + rate);
|
||||
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH_PEAK, "" + kb);
|
||||
changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH, "" + rate);
|
||||
changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH_PEAK, "" + kb);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
bwUpdated = true;
|
||||
}
|
||||
@ -389,12 +402,12 @@ public class ConfigNetHandler extends FormHandler {
|
||||
|
||||
if ( (_inboundBurstRate != null) && (_inboundBurstRate.length() > 0) &&
|
||||
!_inboundBurstRate.equals(_context.getProperty(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH, "" + FIFOBandwidthRefiller.DEFAULT_INBOUND_BURST_BANDWIDTH))) {
|
||||
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH, _inboundBurstRate);
|
||||
changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH, _inboundBurstRate);
|
||||
updated = true;
|
||||
}
|
||||
if ( (_outboundBurstRate != null) && (_outboundBurstRate.length() > 0) &&
|
||||
!_outboundBurstRate.equals(_context.getProperty(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH, "" + FIFOBandwidthRefiller.DEFAULT_OUTBOUND_BURST_BANDWIDTH))) {
|
||||
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH, _outboundBurstRate);
|
||||
changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH, _outboundBurstRate);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
@ -411,7 +424,7 @@ public class ConfigNetHandler extends FormHandler {
|
||||
}
|
||||
if ( (rateKBps > 0) && (burstSeconds > 0) ) {
|
||||
int kb = rateKBps * burstSeconds;
|
||||
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH_PEAK, "" + kb);
|
||||
changes.put(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH_PEAK, "" + kb);
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
@ -429,15 +442,13 @@ public class ConfigNetHandler extends FormHandler {
|
||||
}
|
||||
if ( (rateKBps > 0) && (burstSeconds > 0) ) {
|
||||
int kb = rateKBps * burstSeconds;
|
||||
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH_PEAK, "" + kb);
|
||||
changes.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH_PEAK, "" + kb);
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
***********/
|
||||
|
||||
|
||||
if (updated)
|
||||
_context.bandwidthLimiter().reinitialize();
|
||||
return updated;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.i2p.router.networkdb.reseed.Reseeder;
|
||||
@ -10,6 +12,8 @@ import net.i2p.router.networkdb.reseed.Reseeder;
|
||||
*/
|
||||
public class ConfigReseedHandler extends FormHandler {
|
||||
private Map _settings;
|
||||
private final Map<String, String> changes = new HashMap();
|
||||
private final List<String> removes = new ArrayList();
|
||||
|
||||
@Override
|
||||
protected void processForm() {
|
||||
@ -47,15 +51,15 @@ public class ConfigReseedHandler extends FormHandler {
|
||||
private void saveString(String config, String param) {
|
||||
String val = getJettyString(param);
|
||||
if (val != null && val.length() > 0)
|
||||
_context.router().setConfigSetting(config, val);
|
||||
changes.put(config, val);
|
||||
else
|
||||
_context.router().removeConfigSetting(config);
|
||||
removes.add(config);
|
||||
}
|
||||
|
||||
/** @since 0.8.9 */
|
||||
private void saveBoolean(String config, String param) {
|
||||
boolean val = getJettyString(param) != null;
|
||||
_context.router().setConfigSetting(config, Boolean.toString(val));
|
||||
changes.put(config, Boolean.toString(val));
|
||||
}
|
||||
|
||||
private void saveChanges() {
|
||||
@ -71,17 +75,19 @@ public class ConfigReseedHandler extends FormHandler {
|
||||
saveBoolean(Reseeder.PROP_SPROXY_AUTH_ENABLE, "sauth");
|
||||
String url = getJettyString("reseedURL");
|
||||
if (url != null)
|
||||
_context.router().setConfigSetting(Reseeder.PROP_RESEED_URL, url.trim().replace("\r\n", ",").replace("\n", ","));
|
||||
changes.put(Reseeder.PROP_RESEED_URL, url.trim().replace("\r\n", ",").replace("\n", ","));
|
||||
String mode = getJettyString("mode");
|
||||
boolean req = "1".equals(mode);
|
||||
boolean disabled = "2".equals(mode);
|
||||
_context.router().setConfigSetting(Reseeder.PROP_SSL_REQUIRED,
|
||||
changes.put(Reseeder.PROP_SSL_REQUIRED,
|
||||
Boolean.toString(req));
|
||||
_context.router().setConfigSetting(Reseeder.PROP_SSL_DISABLE,
|
||||
changes.put(Reseeder.PROP_SSL_DISABLE,
|
||||
Boolean.toString(disabled));
|
||||
saveBoolean(Reseeder.PROP_PROXY_ENABLE, "enable");
|
||||
saveBoolean(Reseeder.PROP_SPROXY_ENABLE, "senable");
|
||||
_context.router().saveConfig();
|
||||
addFormNotice(_("Configuration saved successfully."));
|
||||
if (_context.router().saveConfig(changes, removes))
|
||||
addFormNotice(_("Configuration saved successfully."));
|
||||
else
|
||||
addFormError(_("Error saving the configuration (applied but not saved) - please see the error logs"));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import net.i2p.stat.StatManager;
|
||||
@ -73,9 +75,10 @@ public class ConfigStatsHandler extends FormHandler {
|
||||
*
|
||||
*/
|
||||
private void saveChanges() {
|
||||
Map<String, String> changes = new HashMap();
|
||||
if (_filename == null)
|
||||
_filename = StatManager.DEFAULT_STAT_FILE;
|
||||
_context.router().setConfigSetting(StatManager.PROP_STAT_FILE, _filename);
|
||||
changes.put(StatManager.PROP_STAT_FILE, _filename);
|
||||
|
||||
if (_explicitFilter) {
|
||||
_stats.clear();
|
||||
@ -103,12 +106,12 @@ public class ConfigStatsHandler extends FormHandler {
|
||||
stats.append(',');
|
||||
}
|
||||
|
||||
_context.router().setConfigSetting(StatManager.PROP_STAT_FILTER, stats.toString());
|
||||
changes.put(StatManager.PROP_STAT_FILTER, stats.toString());
|
||||
boolean graphsChanged = !_graphs.equals(_context.getProperty("stat.summaries"));
|
||||
_context.router().setConfigSetting("stat.summaries", _graphs);
|
||||
changes.put("stat.summaries", _graphs);
|
||||
boolean fullChanged = _context.getBooleanProperty(StatManager.PROP_STAT_FULL) != _isFull;
|
||||
_context.router().setConfigSetting(StatManager.PROP_STAT_FULL, "" + _isFull);
|
||||
_context.router().saveConfig();
|
||||
changes.put(StatManager.PROP_STAT_FULL, "" + _isFull);
|
||||
_context.router().saveConfig(changes, null);
|
||||
if (!_stats.isEmpty())
|
||||
addFormNotice(_("Stat filter and location updated successfully to") + ": " + stats.toString());
|
||||
if (fullChanged) {
|
||||
|
@ -44,6 +44,7 @@ public class ConfigTunnelsHandler extends FormHandler {
|
||||
*/
|
||||
private void saveChanges() {
|
||||
boolean saveRequired = false;
|
||||
Map<String, String> changes = new HashMap();
|
||||
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Saving changes, with props = " + _settings + ".");
|
||||
@ -90,21 +91,21 @@ public class ConfigTunnelsHandler extends FormHandler {
|
||||
out.setBackupQuantity(getInt(_settings.get(index + ".backupOutbound")));
|
||||
|
||||
if ("exploratory".equals(poolName)) {
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
changes.put(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_LENGTH, in.getLength()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
changes.put(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_LENGTH, out.getLength()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
changes.put(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_LENGTH_VARIANCE, in.getLengthVariance()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
changes.put(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_LENGTH_VARIANCE, out.getLengthVariance()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
changes.put(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_QUANTITY, in.getQuantity()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
changes.put(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_QUANTITY, out.getQuantity()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
changes.put(TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_BACKUP_QUANTITY, in.getBackupQuantity()+"");
|
||||
_context.router().setConfigSetting(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
changes.put(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY +
|
||||
TunnelPoolSettings.PROP_BACKUP_QUANTITY, out.getBackupQuantity()+"");
|
||||
}
|
||||
|
||||
@ -135,7 +136,7 @@ public class ConfigTunnelsHandler extends FormHandler {
|
||||
addFormNotice(_("Updated settings for all pools."));
|
||||
|
||||
if (saveRequired) {
|
||||
boolean saved = _context.router().saveConfig();
|
||||
boolean saved = _context.router().saveConfig(changes, null);
|
||||
if (saved)
|
||||
addFormNotice(_("Exploratory tunnel configuration saved successfully."));
|
||||
else
|
||||
|
@ -22,11 +22,12 @@ public class ConfigUIHandler extends FormHandler {
|
||||
if (_config == null)
|
||||
return;
|
||||
String oldTheme = _context.getProperty(CSSHelper.PROP_THEME_NAME, CSSHelper.DEFAULT_THEME);
|
||||
boolean ok;
|
||||
if (_config.equals("default")) // obsolete
|
||||
_context.router().removeConfigSetting(CSSHelper.PROP_THEME_NAME);
|
||||
ok = _context.router().saveConfig(CSSHelper.PROP_THEME_NAME, null);
|
||||
else
|
||||
_context.router().setConfigSetting(CSSHelper.PROP_THEME_NAME, _config);
|
||||
if (_context.router().saveConfig()) {
|
||||
ok = _context.router().saveConfig(CSSHelper.PROP_THEME_NAME, _config);
|
||||
if (ok) {
|
||||
if (!oldTheme.equals(_config))
|
||||
addFormNotice(_("Theme change saved.") +
|
||||
" <a href=\"configui\">" +
|
||||
|
@ -1,5 +1,8 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.i2p.crypto.TrustedUpdate;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.FileUtil;
|
||||
@ -98,10 +101,12 @@ public class ConfigUpdateHandler extends FormHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, String> changes = new HashMap();
|
||||
|
||||
if ( (_newsURL != null) && (_newsURL.length() > 0) ) {
|
||||
String oldURL = ConfigUpdateHelper.getNewsURL(_context);
|
||||
if ( (oldURL == null) || (!_newsURL.equals(oldURL)) ) {
|
||||
_context.router().setConfigSetting(PROP_NEWS_URL, _newsURL);
|
||||
changes.put(PROP_NEWS_URL, _newsURL);
|
||||
NewsFetcher.getInstance(_context).invalidateNews();
|
||||
addFormNotice(_("Updating news URL to {0}", _newsURL));
|
||||
}
|
||||
@ -110,7 +115,7 @@ public class ConfigUpdateHandler extends FormHandler {
|
||||
if ( (_proxyHost != null) && (_proxyHost.length() > 0) ) {
|
||||
String oldHost = _context.router().getConfigSetting(PROP_PROXY_HOST);
|
||||
if ( (oldHost == null) || (!_proxyHost.equals(oldHost)) ) {
|
||||
_context.router().setConfigSetting(PROP_PROXY_HOST, _proxyHost);
|
||||
changes.put(PROP_PROXY_HOST, _proxyHost);
|
||||
addFormNotice(_("Updating proxy host to {0}", _proxyHost));
|
||||
}
|
||||
}
|
||||
@ -118,19 +123,19 @@ public class ConfigUpdateHandler extends FormHandler {
|
||||
if ( (_proxyPort != null) && (_proxyPort.length() > 0) ) {
|
||||
String oldPort = _context.router().getConfigSetting(PROP_PROXY_PORT);
|
||||
if ( (oldPort == null) || (!_proxyPort.equals(oldPort)) ) {
|
||||
_context.router().setConfigSetting(PROP_PROXY_PORT, _proxyPort);
|
||||
changes.put(PROP_PROXY_PORT, _proxyPort);
|
||||
addFormNotice(_("Updating proxy port to {0}", _proxyPort));
|
||||
}
|
||||
}
|
||||
|
||||
_context.router().setConfigSetting(PROP_SHOULD_PROXY, "" + _updateThroughProxy);
|
||||
_context.router().setConfigSetting(PROP_UPDATE_UNSIGNED, "" + _updateUnsigned);
|
||||
changes.put(PROP_SHOULD_PROXY, "" + _updateThroughProxy);
|
||||
changes.put(PROP_UPDATE_UNSIGNED, "" + _updateUnsigned);
|
||||
|
||||
String oldFreqStr = _context.getProperty(PROP_REFRESH_FREQUENCY, DEFAULT_REFRESH_FREQUENCY);
|
||||
long oldFreq = DEFAULT_REFRESH_FREQ;
|
||||
try { oldFreq = Long.parseLong(oldFreqStr); } catch (NumberFormatException nfe) {}
|
||||
if (_refreshFrequency != oldFreq) {
|
||||
_context.router().setConfigSetting(PROP_REFRESH_FREQUENCY, ""+_refreshFrequency);
|
||||
changes.put(PROP_REFRESH_FREQUENCY, ""+_refreshFrequency);
|
||||
addFormNotice(_("Updating refresh frequency to {0}",
|
||||
_refreshFrequency <= 0 ? _("Never") : DataHelper.formatDuration2(_refreshFrequency)));
|
||||
}
|
||||
@ -138,7 +143,7 @@ public class ConfigUpdateHandler extends FormHandler {
|
||||
if ( (_updatePolicy != null) && (_updatePolicy.length() > 0) ) {
|
||||
String oldPolicy = _context.router().getConfigSetting(PROP_UPDATE_POLICY);
|
||||
if ( (oldPolicy == null) || (!_updatePolicy.equals(oldPolicy)) ) {
|
||||
_context.router().setConfigSetting(PROP_UPDATE_POLICY, _updatePolicy);
|
||||
changes.put(PROP_UPDATE_POLICY, _updatePolicy);
|
||||
addFormNotice(_("Updating update policy to {0}", _updatePolicy));
|
||||
}
|
||||
}
|
||||
@ -147,7 +152,7 @@ public class ConfigUpdateHandler extends FormHandler {
|
||||
_updateURL = _updateURL.replace("\r\n", ",").replace("\n", ",");
|
||||
String oldURL = _context.router().getConfigSetting(PROP_UPDATE_URL);
|
||||
if ( (oldURL == null) || (!_updateURL.equals(oldURL)) ) {
|
||||
_context.router().setConfigSetting(PROP_UPDATE_URL, _updateURL);
|
||||
changes.put(PROP_UPDATE_URL, _updateURL);
|
||||
addFormNotice(_("Updating update URLs."));
|
||||
}
|
||||
}
|
||||
@ -158,7 +163,7 @@ public class ConfigUpdateHandler extends FormHandler {
|
||||
oldKeys = oldKeys.replace("\r\n", ",");
|
||||
if (!_trustedKeys.equals(oldKeys)) {
|
||||
// note that keys are not validated here and no console error message will be generated
|
||||
_context.router().setConfigSetting(PROP_TRUSTED_KEYS, _trustedKeys);
|
||||
changes.put(PROP_TRUSTED_KEYS, _trustedKeys);
|
||||
addFormNotice(_("Updating trusted keys."));
|
||||
}
|
||||
}
|
||||
@ -166,12 +171,12 @@ public class ConfigUpdateHandler extends FormHandler {
|
||||
if ( (_zipURL != null) && (_zipURL.length() > 0) ) {
|
||||
String oldURL = _context.router().getConfigSetting(PROP_ZIP_URL);
|
||||
if ( (oldURL == null) || (!_zipURL.equals(oldURL)) ) {
|
||||
_context.router().setConfigSetting(PROP_ZIP_URL, _zipURL);
|
||||
changes.put(PROP_ZIP_URL, _zipURL);
|
||||
addFormNotice(_("Updating unsigned update URL to {0}", _zipURL));
|
||||
}
|
||||
}
|
||||
|
||||
_context.router().saveConfig();
|
||||
_context.router().saveConfig(changes, null);
|
||||
}
|
||||
|
||||
public void setNewsURL(String url) { _newsURL = url; }
|
||||
|
@ -3,8 +3,10 @@ package net.i2p.router.web;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
@ -216,8 +218,7 @@ public class GraphHelper extends FormHandler {
|
||||
System.getProperty("java.runtime.version") + ')');
|
||||
if (_context.getProperty(PROP_REFRESH, 0) >= 0) {
|
||||
// force no refresh, save silently
|
||||
_context.router().setConfigSetting(PROP_REFRESH, "-1");
|
||||
_context.router().saveConfig();
|
||||
_context.router().saveConfig(PROP_REFRESH, "-1");
|
||||
}
|
||||
}
|
||||
return super.getAllMessages();
|
||||
@ -243,13 +244,14 @@ public class GraphHelper extends FormHandler {
|
||||
_refreshDelaySeconds != _context.getProperty(PROP_REFRESH, DEFAULT_REFRESH) ||
|
||||
_showEvents != _context.getBooleanProperty(PROP_EVENTS) ||
|
||||
_persistent != _context.getBooleanPropertyDefaultTrue(SummaryListener.PROP_PERSISTENT)) {
|
||||
_context.router().setConfigSetting(PROP_X, "" + _width);
|
||||
_context.router().setConfigSetting(PROP_Y, "" + _height);
|
||||
_context.router().setConfigSetting(PROP_PERIODS, "" + _periodCount);
|
||||
_context.router().setConfigSetting(PROP_REFRESH, "" + _refreshDelaySeconds);
|
||||
_context.router().setConfigSetting(PROP_EVENTS, "" + _showEvents);
|
||||
_context.router().setConfigSetting(SummaryListener.PROP_PERSISTENT, "" + _persistent);
|
||||
_context.router().saveConfig();
|
||||
Map<String, String> changes = new HashMap();
|
||||
changes.put(PROP_X, "" + _width);
|
||||
changes.put(PROP_Y, "" + _height);
|
||||
changes.put(PROP_PERIODS, "" + _periodCount);
|
||||
changes.put(PROP_REFRESH, "" + _refreshDelaySeconds);
|
||||
changes.put(PROP_EVENTS, "" + _showEvents);
|
||||
changes.put(SummaryListener.PROP_PERSISTENT, "" + _persistent);
|
||||
_context.router().saveConfig(changes, null);
|
||||
addFormNotice(_("Graph settings saved"));
|
||||
}
|
||||
}
|
||||
|
@ -119,8 +119,7 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
||||
*/
|
||||
public void showNews(boolean yes) {
|
||||
long stamp = yes ? 0 : _lastUpdated;
|
||||
_context.router().setConfigSetting(PROP_LAST_HIDDEN, Long.toString(stamp));
|
||||
_context.router().saveConfig();
|
||||
_context.router().saveConfig(PROP_LAST_HIDDEN, Long.toString(stamp));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -283,9 +282,8 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
||||
if (lastUpdate == null) {
|
||||
// we don't know what version you have, so stamp it with the current time,
|
||||
// and we'll look for something newer next time around.
|
||||
_context.router().setConfigSetting(UpdateHandler.PROP_LAST_UPDATE_TIME,
|
||||
_context.router().saveConfig(UpdateHandler.PROP_LAST_UPDATE_TIME,
|
||||
Long.toString(_context.clock().now()));
|
||||
_context.router().saveConfig();
|
||||
return;
|
||||
}
|
||||
long ms = 0;
|
||||
@ -407,8 +405,7 @@ public class NewsFetcher implements Runnable, EepGet.StatusListener {
|
||||
_log.warn("Transfer complete, but no file? - probably 304 Not Modified");
|
||||
}
|
||||
_lastFetch = now;
|
||||
_context.router().setConfigSetting(PROP_LAST_CHECKED, Long.toString(now));
|
||||
_context.router().saveConfig();
|
||||
_context.router().saveConfig(PROP_LAST_CHECKED, Long.toString(now));
|
||||
}
|
||||
|
||||
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) {
|
||||
|
@ -416,15 +416,17 @@ public class PluginStarter implements Runnable {
|
||||
File[] tfiles = dir.listFiles();
|
||||
if (tfiles != null) {
|
||||
String current = ctx.getProperty(CSSHelper.PROP_THEME_NAME);
|
||||
Map<String, String> changes = new HashMap();
|
||||
List<String> removes = new ArrayList();
|
||||
for (int i = 0; i < tfiles.length; i++) {
|
||||
String name = tfiles[i].getName();
|
||||
if (tfiles[i].isDirectory() && (!Arrays.asList(STANDARD_THEMES).contains(tfiles[i]))) {
|
||||
ctx.router().removeConfigSetting(ConfigUIHelper.PROP_THEME_PFX + name);
|
||||
removes.add(ConfigUIHelper.PROP_THEME_PFX + name);
|
||||
if (name.equals(current))
|
||||
ctx.router().setConfigSetting(CSSHelper.PROP_THEME_NAME, CSSHelper.DEFAULT_THEME);
|
||||
changes.put(CSSHelper.PROP_THEME_NAME, CSSHelper.DEFAULT_THEME);
|
||||
}
|
||||
}
|
||||
ctx.router().saveConfig();
|
||||
ctx.router().saveConfig(changes, removes);
|
||||
}
|
||||
|
||||
FileUtil.rmdir(pluginDir, false);
|
||||
|
@ -6,7 +6,9 @@ import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.security.KeyStore;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
@ -431,9 +433,10 @@ public class RouterConsoleRunner {
|
||||
SecureFileOutputStream.setPerms(ks);
|
||||
try {
|
||||
RouterContext rctx = (RouterContext) ctx;
|
||||
rctx.router().setConfigSetting(PROP_KEYSTORE_PASSWORD, DEFAULT_KEYSTORE_PASSWORD);
|
||||
rctx.router().setConfigSetting(PROP_KEY_PASSWORD, keyPassword);
|
||||
rctx.router().saveConfig();
|
||||
Map<String, String> changes = new HashMap();
|
||||
changes.put(PROP_KEYSTORE_PASSWORD, DEFAULT_KEYSTORE_PASSWORD);
|
||||
changes.put(PROP_KEY_PASSWORD, keyPassword);
|
||||
rctx.router().saveConfig(changes, null);
|
||||
} catch (Exception e) {} // class cast exception
|
||||
}
|
||||
}
|
||||
|
@ -105,8 +105,7 @@ public class UnsignedUpdateHandler extends UpdateHandler {
|
||||
modtime = RFC822Date.parse822Date(lastmod);
|
||||
if (modtime <= 0)
|
||||
modtime = _context.clock().now();
|
||||
_context.router().setConfigSetting(PROP_LAST_UPDATE_TIME, "" + modtime);
|
||||
_context.router().saveConfig();
|
||||
_context.router().saveConfig(PROP_LAST_UPDATE_TIME, "" + modtime);
|
||||
if ("install".equals(policy)) {
|
||||
_log.log(Log.CRIT, "Update was downloaded, restarting to install it");
|
||||
updateStatus("<b>" + _("Update downloaded") + "</b><br>" + _("Restarting"));
|
||||
|
@ -275,8 +275,7 @@ public class UpdateHandler {
|
||||
modtime = RFC822Date.parse822Date(lastmod);
|
||||
if (modtime <= 0)
|
||||
modtime = _context.clock().now();
|
||||
_context.router().setConfigSetting(PROP_LAST_UPDATE_TIME, "" + modtime);
|
||||
_context.router().saveConfig();
|
||||
_context.router().saveConfig(PROP_LAST_UPDATE_TIME, "" + modtime);
|
||||
if ("install".equals(policy)) {
|
||||
_log.log(Log.CRIT, "Update was VERIFIED, restarting to install it");
|
||||
updateStatus("<b>" + _("Update verified") + "</b><br>" + _("Restarting"));
|
||||
|
Reference in New Issue
Block a user