- Implement config save of new IP address options

- Implement local address and UPnP configuration of UDP address
- Limit received port to 1024 minimum
This commit is contained in:
zzz
2009-05-01 00:42:31 +00:00
parent b21e011203
commit 79a963fcab
7 changed files with 146 additions and 71 deletions

View File

@ -26,7 +26,10 @@ public class ConfigNetHandler extends FormHandler {
private String _ntcpHostname;
private String _ntcpPort;
private String _tcpPort;
private String _udpHost1;
private String _udpHost2;
private String _udpPort;
private String _udpAutoIP;
private String _ntcpAutoIP;
private boolean _ntcpAutoPort;
private boolean _upnp;
@ -40,6 +43,7 @@ public class ConfigNetHandler extends FormHandler {
private boolean _enableLoadTesting;
private String _sharePct;
private boolean _ratesOnly; // always false
private static final String PROP_HIDDEN = Router.PROP_HIDDEN_HIDDEN; // see Router for other choice
protected void processForm() {
if (_saveRequested || ( (_action != null) && ("Save changes".equals(_action)) )) {
@ -55,9 +59,12 @@ public class ConfigNetHandler extends FormHandler {
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 setUdpAutoIP(String mode) {
_udpAutoIP = mode;
_hiddenMode = "hidden".equals(mode);
}
public void setNtcpAutoIP(String mode) {
_ntcpAutoIP = mode;
}
@ -78,6 +85,12 @@ public class ConfigNetHandler extends FormHandler {
public void setNtcpport(String port) {
_ntcpPort = (port != null ? port.trim() : null);
}
public void setUdpHost1(String host) {
_udpHost1 = (host != null ? host.trim() : null);
}
public void setUdpHost2(String host) {
_udpHost2 = (host != null ? host.trim() : null);
}
public void setUdpPort(String port) {
_udpPort = (port != null ? port.trim() : null);
}
@ -117,6 +130,28 @@ public class ConfigNetHandler extends FormHandler {
boolean restartRequired = false;
if (!_ratesOnly) {
// IP Settings
String oldUdp = _context.getProperty(UDPTransport.PROP_SOURCES, UDPTransport.DEFAULT_SOURCES);
String oldUHost = _context.getProperty(UDPTransport.PROP_EXTERNAL_HOST, "");
if (_udpAutoIP != null) {
String uhost = "";
if (_udpAutoIP.equals("fixed")) {
if (_udpHost1 != null && _udpHost1.length() > 0)
uhost = _udpHost1;
else if (_udpHost2 != null && _udpHost2.length() > 0)
uhost = _udpHost1;
else
_udpAutoIP = UDPTransport.DEFAULT_SOURCES;
}
_context.router().setConfigSetting(UDPTransport.PROP_SOURCES, _udpAutoIP);
_context.router().setConfigSetting(UDPTransport.PROP_EXTERNAL_HOST, uhost);
if ((!oldUdp.equals(_udpAutoIP)) || (!oldUHost.equals(uhost))) {
addFormNotice("Updating IP address");
restartRequired = true;
}
}
// NTCP Settings
// 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 = "";
@ -154,6 +189,7 @@ public class ConfigNetHandler extends FormHandler {
restartRequired = true;
}
// UDP Settings
if ( (_udpPort != null) && (_udpPort.length() > 0) ) {
String oldPort = "" + _context.getProperty(UDPTransport.PROP_INTERNAL_PORT, UDPTransport.DEFAULT_INTERNAL_PORT);
if (!oldPort.equals(_udpPort)) {
@ -168,6 +204,7 @@ public class ConfigNetHandler extends FormHandler {
updateRates();
boolean switchRequired = false;
if (!_ratesOnly) {
if (_sharePct != null) {
String old = _context.router().getConfigSetting(Router.PROP_BANDWIDTH_SHARE_PERCENTAGE);
@ -178,19 +215,14 @@ public class ConfigNetHandler extends FormHandler {
}
// 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 "
switchRequired = _hiddenMode != _context.router().isHidden();
if (switchRequired) {
_context.router().setConfigSetting(PROP_HIDDEN, "" + _hiddenMode);
if (_hiddenMode)
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();
else
addFormNotice("Gracefully restarting to exit Hidden Router Mode");
}
_context.router().setConfigSetting(Router.PROP_DYNAMIC_KEYS, "" + _dynamicKeys);
@ -225,7 +257,9 @@ public class ConfigNetHandler extends FormHandler {
addFormNotice("Error saving the configuration (applied but not saved) - please see the error logs");
}
if (restartRequired) {
if (switchRequired) {
hiddenSwitch();
} else if (restartRequired) {
//addFormNotice("Performing a soft restart");
//_context.router().restart();
//addFormNotice("Soft restart complete");

View File

@ -23,24 +23,19 @@ public class ConfigNetHelper extends HelperBase {
private final static String DISABLED = " disabled=\"true\" ";
public String getUdphostname() {
String hostname = _context.getProperty(UDPTransport.PROP_EXTERNAL_HOST);
if (hostname == null) return "";
return hostname;
return _context.getProperty(UDPTransport.PROP_EXTERNAL_HOST, "");
}
public String getNtcphostname() {
if (!TransportManager.enableNTCP(_context))
return "\" disabled=\"true";
String hostname = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME);
if (hostname == null) return "";
return hostname;
return _context.getProperty(PROP_I2NP_NTCP_HOSTNAME, "");
}
public String getNtcpport() {
if (!TransportManager.enableNTCP(_context))
return "\" disabled=\"true";
String port = _context.getProperty(PROP_I2NP_NTCP_PORT);
if (port == null) return "";
return port;
return _context.getProperty(PROP_I2NP_NTCP_PORT, "");
}
public String getUdpAddress() {
@ -90,10 +85,6 @@ public class ConfigNetHelper extends HelperBase {
return "";
}
public String getHiddenModeChecked() {
return getChecked(Router.PROP_HIDDEN);
}
public String getDynamicKeysChecked() {
return getChecked(Router.PROP_DYNAMIC_KEYS);
}
@ -125,14 +116,17 @@ public class ConfigNetHelper extends HelperBase {
return "";
}
//////////////// FIXME
public String getUdpAutoIPChecked(int mode) {
String hostname = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME);
String hostname = _context.getProperty(UDPTransport.PROP_EXTERNAL_HOST);
boolean specified = hostname != null && hostname.length() > 0;
boolean auto = Boolean.valueOf(_context.getProperty(PROP_I2NP_NTCP_AUTO_IP)).booleanValue();
if ((mode == 0 && (!specified) && !auto) ||
(mode == 1 && specified && !auto) ||
(mode == 2 && auto))
boolean hidden = _context.router().isHidden();
String sources = _context.getProperty(UDPTransport.PROP_SOURCES, UDPTransport.DEFAULT_SOURCES);
if ((mode == 0 && sources.equals("ssu") && !hidden) ||
(mode == 1 && specified && !hidden) ||
(mode == 2 && hidden) ||
(mode == 3 && sources.equals("local,upnp,ssu") && !hidden) ||
(mode == 4 && sources.equals("local,ssu") && !hidden) ||
(mode == 5 && sources.equals("upnp,ssu") && !hidden))
return CHECKED;
return "";
}

View File

@ -67,22 +67,27 @@
<a href="oldstats.jsp#test.rtt">test.rtt</a> and related stats.</p>
<hr />
-->
<b>UDP Configuration:</b><br />
<p>
<b>UPnP Configuration:</b><br />
<input type="checkbox" name="upnp" value="true" <jsp:getProperty name="nethelper" property="upnpChecked" /> />
Enable UPnP to open firewall ports
</p><p>
<b>IP Configuration:</b><br />
Externally reachable hostname or IP address:<br />
<input type="radio" name="udpAutoIP" value="0" <%=nethelper.getUdpAutoIPChecked(0) %> />
Use SSU detection only<br />
<input type="radio" name="udpAutoIP" value="24" <%=nethelper.getUdpAutoIPChecked(24) %> />
<input type="radio" name="udpAutoIP" value="local,upnp,ssu" <%=nethelper.getUdpAutoIPChecked(3) %> />
Use local public address if available, then UPnP detection, then SSU detection<br />
<input type="radio" name="udpAutoIP" value="16" <%=nethelper.getUdpAutoIPChecked(16) %> />
<input type="radio" name="udpAutoIP" value="local,ssu" <%=nethelper.getUdpAutoIPChecked(4) %> />
Use local public address if available, then SSU detection<br />
<input type="radio" name="udpAutoIP" value="8" <%=nethelper.getUdpAutoIPChecked(8) %> />
<input type="radio" name="udpAutoIP" value="upnp,ssu" <%=nethelper.getUdpAutoIPChecked(5) %> />
Use UPnP detection if available, then SSU detection<br />
<input type="radio" name="udpAutoIP" value="1" <%=nethelper.getUdpAutoIPChecked(1) %> />
<input type="radio" name="udpAutoIP" value="ssu" <%=nethelper.getUdpAutoIPChecked(0) %> />
Use SSU detection only<br />
<input type="radio" name="udpAutoIP" value="fixed" <%=nethelper.getUdpAutoIPChecked(1) %> />
Specify hostname or IP:
<input name ="udphost" type="text" size="16" value="<jsp:getProperty name="nethelper" property="udphostname" />" />
<input name ="udpHost1" type="text" size="16" value="<jsp:getProperty name="nethelper" property="udphostname" />" />
<% String[] ips = nethelper.getAddresses();
if (ips.length > 0) {
out.print(" or <select name=\"interface\"><option value=\"\" selected=\"true\">Select Interface</option>\n");
out.print(" or <select name=\"udpHost2\"><option value=\"\" selected=\"true\">Select Interface</option>\n");
for (int i = 0; i < ips.length; i++) {
out.print("<option value=\"");
out.print(ips[i]);
@ -94,14 +99,16 @@
}
%>
<br />
<input type="radio" name="udpAutoIP" value="2" <%=nethelper.getUdpAutoIPChecked(2) %> />
Hidden mode - do not publish IP<i>(not recommended)</i><br />
<input type="radio" name="udpAutoIP" value="hidden" <%=nethelper.getUdpAutoIPChecked(2) %> />
Hidden mode - do not publish IP<i>(not recommended; change restarts router)</i><br />
</p><p>
<b>UDP Configuration:</b><br />
Internal UDP port:
<input name ="udpPort" type="text" size="6" value="<jsp:getProperty name="nethelper" property="configuredUdpPort" />" /><br />
<input type="checkbox" name="requireIntroductions" value="true" <jsp:getProperty name="nethelper" property="requireIntroductionsChecked" /> />
Require SSU introductions
<i>(Enable if you cannot open your firewall)</i>
<p>
</p><p>
Current External UDP address: <i><jsp:getProperty name="nethelper" property="udpAddress" /></i><br />
</p><p>If you can, please poke a hole in your NAT or firewall to allow unsolicited UDP packets to reach
you on your external UDP address. If you can't, I2P now includes supports UDP hole punching
@ -111,8 +118,8 @@
the <i>Reachability: Firewalled</i> line), or you can manually require them here.
Users behind symmetric NATs, such as OpenBSD's pf, are not currently supported.</p>
<input type="submit" name="recheckReachability" value="Check network reachability..." />
<p>
<b>Inbound TCP connection configuration:</b><br />
</p><p>
<b>Inbound TCP Configuration:</b><br />
Externally reachable hostname or IP address:<br />
<input type="radio" name="ntcpAutoIP" value="false" <%=nethelper.getTcpAutoIPChecked(0) %> />
Disable (Firewalled)<br />
@ -125,7 +132,7 @@
Specify hostname or IP:
<input name ="ntcphost" type="text" size="16" value="<jsp:getProperty name="nethelper" property="ntcphostname" />" />
<i>(dyndns and the like are fine)</i><br />
<p>
</p><p>
Externally reachable TCP port:<br />
<input type="radio" name="ntcpAutoPort" value="2" <%=nethelper.getTcpAutoPortChecked(2) %> />
Use the same port configured for SSU
@ -133,8 +140,8 @@
<input type="radio" name="ntcpAutoPort" value="1" <%=nethelper.getTcpAutoPortChecked(1) %> />
Specify Port:
<input name ="ntcpport" type="text" size="6" value="<jsp:getProperty name="nethelper" property="ntcpport" />" /><br />
<p>A hostname entered here will be published in the network database.
It is <b>not private</b>.
</p><p>Hostnames entered here will be published in the network database.
They are <b>not private</b>.
Also, <b>do not enter a private IP address</b> like 127.0.0.1 or 192.168.1.1.
</p>
<p>You do <i>not</i> need to allow inbound TCP connections - outbound connections work with no
@ -142,11 +149,6 @@
in your NAT or firewall for unsolicited TCP connections. If you specify the wrong IP address or
hostname, or do not properly configure your NAT or firewall, your network performance will degrade
substantially. When in doubt, leave the hostname and port number blank.</p>
<p>
<b>UPnP Configuration:</b><br />
Open firewall port using UPnP:
<input type="checkbox" name="upnp" value="true" <jsp:getProperty name="nethelper" property="upnpChecked" /> /><br />
</p>
<p><b>Note: changing any of these settings will terminate all of your connections and effectively
restart your router.</b>
</p>