Files
i2p.i2p/apps/routerconsole/java/src/net/i2p/router/web/ConfigNetHandler.java

323 lines
14 KiB
Java
Raw Normal View History

package net.i2p.router.web;
import net.i2p.data.RouterInfo;
import net.i2p.router.LoadTestManager;
import net.i2p.router.Router;
import net.i2p.router.transport.FIFOBandwidthRefiller;
2009-04-28 19:49:09 +00:00
import net.i2p.router.transport.TransportManager;
import net.i2p.router.transport.udp.UDPTransport;
import net.i2p.router.web.ConfigServiceHandler.UpdateWrapperManagerAndRekeyTask;
import net.i2p.time.Timestamper;
/**
* Handler to deal with form submissions from the main config form and act
* upon the values.
*
*/
public class ConfigNetHandler extends FormHandler {
private String _hostname;
private boolean _reseedRequested;
private boolean _saveRequested;
private boolean _recheckReachabilityRequested;
private boolean _timeSyncEnabled;
private boolean _requireIntroductions;
private boolean _hiddenMode;
private boolean _dynamicKeys;
private String _ntcpHostname;
private String _ntcpPort;
private String _tcpPort;
private String _udpPort;
private boolean _ntcpAutoIP;
private boolean _ntcpAutoPort;
private boolean _ntcpInboundDisabled;
2009-04-28 19:49:09 +00:00
private boolean _upnp;
private String _inboundRate;
private String _inboundBurstRate;
private String _inboundBurst;
private String _outboundRate;
private String _outboundBurstRate;
private String _outboundBurst;
private String _reseedFrom;
private boolean _enableLoadTesting;
2005-02-16 jrandom * (Merged the 0.5-pre branch back into CVS HEAD) * Replaced the old tunnel routing crypto with the one specified in router/doc/tunnel-alt.html, including updates to the web console to view and tweak it. * Provide the means for routers to reject tunnel requests with a wider range of responses: probabalistic rejection, due to approaching overload transient rejection, due to temporary overload bandwidth rejection, due to persistent bandwidth overload critical rejection, due to general router fault (or imminent shutdown) The different responses are factored into the profiles accordingly. * Replaced the old I2CP tunnel related options (tunnels.depthInbound, etc) with a series of new properties, relevent to the new tunnel routing code: inbound.nickname (used on the console) inbound.quantity (# of tunnels to use in any leaseSets) inbound.backupQuantity (# of tunnels to keep in the ready) inbound.length (# of remote peers in the tunnel) inbound.lengthVariance (if > 0, permute the length by adding a random # up to the variance. if < 0, permute the length by adding or subtracting a random # up to the variance) outbound.* (same as the inbound, except for the, uh, outbound tunnels in that client's pool) There are other options, and more will be added later, but the above are the most relevent ones. * Replaced Jetty 4.2.21 with Jetty 5.1.2 * Compress all profile data on disk. * Adjust the reseeding functionality to work even when the JVM's http proxy is set. * Enable a poor-man's interactive-flow in the streaming lib by choking the max window size. * Reduced the default streaming lib max message size to 16KB (though still configurable by the user), also doubling the default maximum window size. * Replaced the RouterIdentity in a Lease with its SHA256 hash. * Reduced the overall I2NP message checksum from a full 32 byte SHA256 to the first byte of the SHA256. * Added a new "netId" flag to let routers drop references to other routers who we won't be able to talk to. * Extended the timestamper to get a second (or third) opinion whenever it wants to actually adjust the clock offset. * Replaced that kludge of a timestamp I2NP message with a full blown DateMessage. * Substantial memory optimizations within the router and the SDK to reduce GC churn. Client apps and the streaming libs have not been tuned, however. * More bugfixes thank you can shake a stick at. 2005-02-13 jrandom * Updated jbigi source to handle 64bit CPUs. The bundled jbigi.jar still only contains 32bit versions, so build your own, placing libjbigi.so in your install dir if necessary. (thanks mule!) * Added support for libjbigi-$os-athlon64 to NativeBigInteger and CPUID (thanks spaetz!)
2005-02-16 22:23:47 +00:00
private String _sharePct;
2009-04-28 19:49:09 +00:00
private boolean _ratesOnly; // always false
protected void processForm() {
if (_saveRequested || ( (_action != null) && ("Save changes".equals(_action)) )) {
saveChanges();
} else if (_recheckReachabilityRequested) {
recheckReachability();
} else {
// noop
}
}
public void setSave(String moo) { _saveRequested = true; }
public void setEnabletimesync(String moo) { _timeSyncEnabled = true; }
public void setRecheckReachability(String moo) { _recheckReachabilityRequested = true; }
public void setRequireIntroductions(String moo) { _requireIntroductions = true; }
public void setHiddenMode(String moo) { _hiddenMode = true; }
public void setDynamicKeys(String moo) { _dynamicKeys = true; }
public void setEnableloadtesting(String moo) { _enableLoadTesting = true; }
public void setNtcpAutoIP(String mode) {
_ntcpAutoIP = mode.equals("2");
if (mode.equals("0"))
_ntcpInboundDisabled = true;
}
public void setNtcpAutoPort(String mode) {
_ntcpAutoPort = mode.equals("2");
if (mode.equals("0"))
_ntcpInboundDisabled = true;
}
2009-04-28 19:49:09 +00:00
public void setUpnp(String moo) { _upnp = true; }
public void setHostname(String hostname) {
_hostname = (hostname != null ? hostname.trim() : null);
}
public void setTcpPort(String port) {
_tcpPort = (port != null ? port.trim() : null);
}
public void setNtcphost(String host) {
_ntcpHostname = (host != null ? host.trim() : null);
}
public void setNtcpport(String port) {
_ntcpPort = (port != null ? port.trim() : null);
}
public void setUdpPort(String port) {
_udpPort = (port != null ? port.trim() : null);
}
public void setInboundrate(String rate) {
_inboundRate = (rate != null ? rate.trim() : null);
}
public void setInboundburstrate(String rate) {
_inboundBurstRate = (rate != null ? rate.trim() : null);
}
public void setInboundburstfactor(String factor) {
_inboundBurst = (factor != null ? factor.trim() : null);
}
public void setOutboundrate(String rate) {
_outboundRate = (rate != null ? rate.trim() : null);
}
public void setOutboundburstrate(String rate) {
_outboundBurstRate = (rate != null ? rate.trim() : null);
}
public void setOutboundburstfactor(String factor) {
_outboundBurst = (factor != null ? factor.trim() : null);
}
2005-02-16 jrandom * (Merged the 0.5-pre branch back into CVS HEAD) * Replaced the old tunnel routing crypto with the one specified in router/doc/tunnel-alt.html, including updates to the web console to view and tweak it. * Provide the means for routers to reject tunnel requests with a wider range of responses: probabalistic rejection, due to approaching overload transient rejection, due to temporary overload bandwidth rejection, due to persistent bandwidth overload critical rejection, due to general router fault (or imminent shutdown) The different responses are factored into the profiles accordingly. * Replaced the old I2CP tunnel related options (tunnels.depthInbound, etc) with a series of new properties, relevent to the new tunnel routing code: inbound.nickname (used on the console) inbound.quantity (# of tunnels to use in any leaseSets) inbound.backupQuantity (# of tunnels to keep in the ready) inbound.length (# of remote peers in the tunnel) inbound.lengthVariance (if > 0, permute the length by adding a random # up to the variance. if < 0, permute the length by adding or subtracting a random # up to the variance) outbound.* (same as the inbound, except for the, uh, outbound tunnels in that client's pool) There are other options, and more will be added later, but the above are the most relevent ones. * Replaced Jetty 4.2.21 with Jetty 5.1.2 * Compress all profile data on disk. * Adjust the reseeding functionality to work even when the JVM's http proxy is set. * Enable a poor-man's interactive-flow in the streaming lib by choking the max window size. * Reduced the default streaming lib max message size to 16KB (though still configurable by the user), also doubling the default maximum window size. * Replaced the RouterIdentity in a Lease with its SHA256 hash. * Reduced the overall I2NP message checksum from a full 32 byte SHA256 to the first byte of the SHA256. * Added a new "netId" flag to let routers drop references to other routers who we won't be able to talk to. * Extended the timestamper to get a second (or third) opinion whenever it wants to actually adjust the clock offset. * Replaced that kludge of a timestamp I2NP message with a full blown DateMessage. * Substantial memory optimizations within the router and the SDK to reduce GC churn. Client apps and the streaming libs have not been tuned, however. * More bugfixes thank you can shake a stick at. 2005-02-13 jrandom * Updated jbigi source to handle 64bit CPUs. The bundled jbigi.jar still only contains 32bit versions, so build your own, placing libjbigi.so in your install dir if necessary. (thanks mule!) * Added support for libjbigi-$os-athlon64 to NativeBigInteger and CPUID (thanks spaetz!)
2005-02-16 22:23:47 +00:00
public void setSharePercentage(String pct) {
_sharePct = (pct != null ? pct.trim() : null);
}
private void recheckReachability() {
_context.commSystem().recheckReachability();
addFormNotice("Rechecking router reachability...");
}
/**
* The user made changes to the network config and wants to save them, so
* lets go ahead and do so.
*
*/
private void saveChanges() {
boolean restartRequired = false;
if (!_ratesOnly) {
// Normalize some things to make the following code a little easier...
String oldNHost = _context.router().getConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME);
if (oldNHost == null) oldNHost = "";
String oldNPort = _context.router().getConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT);
if (oldNPort == null) oldNPort = "";
String sAutoHost = _context.router().getConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_IP);
String sAutoPort = _context.router().getConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_PORT);
boolean oldAutoHost = "true".equalsIgnoreCase(sAutoHost);
boolean oldAutoPort = "true".equalsIgnoreCase(sAutoPort);
if (_ntcpHostname == null || _ntcpInboundDisabled) _ntcpHostname = "";
if (_ntcpPort == null || _ntcpInboundDisabled) _ntcpPort = "";
if (_ntcpInboundDisabled) {
_ntcpAutoIP = false;
_ntcpAutoPort = false;
}
if (oldAutoHost != _ntcpAutoIP || ! oldNHost.equalsIgnoreCase(_ntcpHostname)) {
if (_ntcpAutoIP) {
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_IP, "true");
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME);
addFormNotice("Updating inbound TCP address to auto");
} else if (_ntcpHostname.length() > 0) {
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME, _ntcpHostname);
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_IP);
addFormNotice("Updating inbound TCP address to " + _ntcpHostname);
} else {
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME);
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_IP);
addFormNotice("Disabling inbound TCP");
}
restartRequired = true;
}
if (oldAutoPort != _ntcpAutoPort || ! oldNPort.equals(_ntcpPort)) {
if ( _ntcpAutoPort ) {
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_PORT, "true");
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT);
addFormNotice("Updating inbound TCP port to auto");
} else if (_ntcpPort.length() > 0) {
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT, _ntcpPort);
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_PORT);
addFormNotice("Updating inbound TCP port to " + _ntcpPort);
} else {
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT);
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_PORT);
addFormNotice("Disabling inbound TCP");
}
restartRequired = true;
}
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);
addFormNotice("Updating UDP port from " + oldPort + " to " + _udpPort);
restartRequired = true;
}
}
}
updateRates();
if (!_ratesOnly) {
if (_sharePct != null) {
String old = _context.router().getConfigSetting(Router.PROP_BANDWIDTH_SHARE_PERCENTAGE);
if ( (old == null) || (!old.equalsIgnoreCase(_sharePct)) ) {
_context.router().setConfigSetting(Router.PROP_BANDWIDTH_SHARE_PERCENTAGE, _sharePct);
addFormNotice("Updating bandwidth share percentage");
}
2005-02-16 jrandom * (Merged the 0.5-pre branch back into CVS HEAD) * Replaced the old tunnel routing crypto with the one specified in router/doc/tunnel-alt.html, including updates to the web console to view and tweak it. * Provide the means for routers to reject tunnel requests with a wider range of responses: probabalistic rejection, due to approaching overload transient rejection, due to temporary overload bandwidth rejection, due to persistent bandwidth overload critical rejection, due to general router fault (or imminent shutdown) The different responses are factored into the profiles accordingly. * Replaced the old I2CP tunnel related options (tunnels.depthInbound, etc) with a series of new properties, relevent to the new tunnel routing code: inbound.nickname (used on the console) inbound.quantity (# of tunnels to use in any leaseSets) inbound.backupQuantity (# of tunnels to keep in the ready) inbound.length (# of remote peers in the tunnel) inbound.lengthVariance (if > 0, permute the length by adding a random # up to the variance. if < 0, permute the length by adding or subtracting a random # up to the variance) outbound.* (same as the inbound, except for the, uh, outbound tunnels in that client's pool) There are other options, and more will be added later, but the above are the most relevent ones. * Replaced Jetty 4.2.21 with Jetty 5.1.2 * Compress all profile data on disk. * Adjust the reseeding functionality to work even when the JVM's http proxy is set. * Enable a poor-man's interactive-flow in the streaming lib by choking the max window size. * Reduced the default streaming lib max message size to 16KB (though still configurable by the user), also doubling the default maximum window size. * Replaced the RouterIdentity in a Lease with its SHA256 hash. * Reduced the overall I2NP message checksum from a full 32 byte SHA256 to the first byte of the SHA256. * Added a new "netId" flag to let routers drop references to other routers who we won't be able to talk to. * Extended the timestamper to get a second (or third) opinion whenever it wants to actually adjust the clock offset. * Replaced that kludge of a timestamp I2NP message with a full blown DateMessage. * Substantial memory optimizations within the router and the SDK to reduce GC churn. Client apps and the streaming libs have not been tuned, however. * More bugfixes thank you can shake a stick at. 2005-02-13 jrandom * Updated jbigi source to handle 64bit CPUs. The bundled jbigi.jar still only contains 32bit versions, so build your own, placing libjbigi.so in your install dir if necessary. (thanks mule!) * Added support for libjbigi-$os-athlon64 to NativeBigInteger and CPUID (thanks spaetz!)
2005-02-16 22:23:47 +00:00
}
// If hidden mode value changes, restart is required
if (_hiddenMode && "false".equalsIgnoreCase(_context.getProperty(Router.PROP_HIDDEN, "false"))) {
_context.router().setConfigSetting(Router.PROP_HIDDEN, "true");
_context.router().addCapabilities(_context.router().getRouterInfo());
addFormNotice("Gracefully restarting into Hidden Router Mode. Make sure you have no 0-1 length "
+ "<a href=\"configtunnels.jsp\">tunnels!</a>");
hiddenSwitch();
}
if (!_hiddenMode && "true".equalsIgnoreCase(_context.getProperty(Router.PROP_HIDDEN, "false"))) {
_context.router().removeConfigSetting(Router.PROP_HIDDEN);
_context.router().getRouterInfo().delCapability(RouterInfo.CAPABILITY_HIDDEN);
addFormNotice("Gracefully restarting to exit Hidden Router Mode");
hiddenSwitch();
}
2009-04-28 19:49:09 +00:00
_context.router().setConfigSetting(Router.PROP_DYNAMIC_KEYS, "" + _dynamicKeys);
if (Boolean.valueOf(_context.getProperty(TransportManager.PROP_ENABLE_UPNP)).booleanValue() !=
_upnp) {
if (_upnp)
addFormNotice("Enabling UPnP, restart required to take effect");
else
addFormNotice("Disabling UPnP, restart required to take effect");
}
2009-04-28 19:49:09 +00:00
_context.router().setConfigSetting(TransportManager.PROP_ENABLE_UPNP, "" + _upnp);
if (_requireIntroductions) {
_context.router().setConfigSetting(UDPTransport.PROP_FORCE_INTRODUCERS, "true");
addFormNotice("Requiring SSU introduers");
} else {
_context.router().removeConfigSetting(UDPTransport.PROP_FORCE_INTRODUCERS);
}
2009-04-28 19:49:09 +00:00
// Time sync enable, means NOT disabled
_context.router().setConfigSetting(Timestamper.PROP_DISABLED, "false");
LoadTestManager.setEnableLoadTesting(_context, _enableLoadTesting);
}
boolean saved = _context.router().saveConfig();
if ( (_action != null) && ("Save changes".equals(_action)) ) {
if (saved)
addFormNotice("Configuration saved successfully");
else
addFormNotice("Error saving the configuration (applied but not saved) - please see the error logs");
}
if (restartRequired) {
//addFormNotice("Performing a soft restart");
//_context.router().restart();
//addFormNotice("Soft restart complete");
// Most of the time we aren't changing addresses, just enabling or disabling
// things, so let's try just a new routerInfo and see how that works.
// Maybe we should restart if we change addresses though?
_context.router().rebuildRouterInfo();
addFormNotice("Router Info rebuilt");
}
}
private void hiddenSwitch() {
// Full restart required to generate new keys
_context.addShutdownTask(new UpdateWrapperManagerAndRekeyTask(Router.EXIT_GRACEFUL_RESTART));
_context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
}
private void updateRates() {
boolean updated = false;
if ( (_inboundRate != null) && (_inboundRate.length() > 0) ) {
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH, _inboundRate);
updated = true;
}
if ( (_outboundRate != null) && (_outboundRate.length() > 0) ) {
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH, _outboundRate);
updated = true;
}
if ( (_inboundBurstRate != null) && (_inboundBurstRate.length() > 0) ) {
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH, _inboundBurstRate);
updated = true;
}
if ( (_outboundBurstRate != null) && (_outboundBurstRate.length() > 0) ) {
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH, _outboundBurstRate);
updated = true;
}
String inBurstRate = _context.router().getConfigSetting(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH);
if (_inboundBurst != null) {
int rateKBps = 0;
int burstSeconds = 0;
try {
rateKBps = Integer.parseInt(inBurstRate);
burstSeconds = Integer.parseInt(_inboundBurst);
} catch (NumberFormatException nfe) {
// ignore
}
if ( (rateKBps > 0) && (burstSeconds > 0) ) {
int kb = rateKBps * burstSeconds;
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH_PEAK, "" + kb);
updated = true;
}
}
String outBurstRate = _context.router().getConfigSetting(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH);
if (_outboundBurst != null) {
int rateKBps = 0;
int burstSeconds = 0;
try {
rateKBps = Integer.parseInt(outBurstRate);
burstSeconds = Integer.parseInt(_outboundBurst);
} catch (NumberFormatException nfe) {
// ignore
}
if ( (rateKBps > 0) && (burstSeconds > 0) ) {
int kb = rateKBps * burstSeconds;
_context.router().setConfigSetting(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH_PEAK, "" + kb);
updated = true;
}
}
if (updated && !_ratesOnly)
_context.bandwidthLimiter().reinitialize();
addFormNotice("Updated bandwidth limits");
}
}