2007-07-07 zzz

* Add auto-detect IP/Port to NTCP. When enabled on config.jsp,
      SSU will notify/restart NTCP when the external address changes.
      Now you can enable inbound TCP without a static IP or dyndns service.
This commit is contained in:
zzz
2007-07-07 20:03:50 +00:00
committed by zzz
parent 409b71def5
commit d4a1bcf28f
10 changed files with 209 additions and 23 deletions

View File

@ -41,6 +41,8 @@ public class ConfigNetHandler extends FormHandler {
private String _ntcpPort;
private String _tcpPort;
private String _udpPort;
private boolean _ntcpAutoIP;
private boolean _ntcpAutoPort;
private String _inboundRate;
private String _inboundBurstRate;
private String _inboundBurst;
@ -70,6 +72,8 @@ public class ConfigNetHandler extends FormHandler {
public void setDynamicKeys(String moo) { _dynamicKeys = true; }
public void setUpdateratesonly(String moo) { _ratesOnly = true; }
public void setEnableloadtesting(String moo) { _enableLoadTesting = true; }
public void setNtcpAutoIP(String moo) { _ntcpAutoIP = true; }
public void setNtcpAutoPort(String moo) { _ntcpAutoPort = true; }
public void setHostname(String hostname) {
_hostname = (hostname != null ? hostname.trim() : null);
@ -142,27 +146,49 @@ public class ConfigNetHandler extends FormHandler {
}
}
if ( (_ntcpHostname != null) && (_ntcpHostname.length() > 0) && (_ntcpPort != null) && (_ntcpPort.length() > 0) ) {
String oldHost = _context.router().getConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME);
String oldPort = _context.router().getConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT);
if ( (oldHost == null) || (!oldHost.equalsIgnoreCase(_ntcpHostname)) ||
(oldPort == null) || (!oldPort.equalsIgnoreCase(_ntcpPort)) ) {
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME, _ntcpHostname);
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT, _ntcpPort);
addFormNotice("Updating inbound TCP settings from " + oldHost + ":" + oldPort
+ " to " + _ntcpHostname + ":" + _ntcpPort);
restartRequired = true;
}
} else {
String oldHost = _context.router().getConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME);
String oldPort = _context.router().getConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT);
if ( (oldHost != null) || (oldPort != null) ) {
// 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) _ntcpHostname = "";
if (_ntcpPort == null) _ntcpPort = "";
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);
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT);
addFormNotice("Updating inbound TCP settings from " + oldHost + ":" + oldPort
+ " so that we no longer receive inbound TCP connections");
restartRequired = true;
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) ) {

View File

@ -50,6 +50,8 @@ public class ConfigNetHelper {
}
public final static String PROP_I2NP_NTCP_HOSTNAME = "i2np.ntcp.hostname";
public final static String PROP_I2NP_NTCP_PORT = "i2np.ntcp.port";
public final static String PROP_I2NP_NTCP_AUTO_PORT = "i2np.ntcp.autoip";
public final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoport";
public String getNtcphostname() {
String hostname = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME);
if (hostname == null) return "";
@ -69,6 +71,26 @@ public class ConfigNetHelper {
return ua.toString();
}
public String getUdpIP() {
RouterAddress addr = _context.router().getRouterInfo().getTargetAddress("SSU");
if (addr == null)
return "unknown";
UDPAddress ua = new UDPAddress(addr);
if (ua.getHost() == null)
return "unknown";
return ua.getHost();
}
public String getUdpPort() {
RouterAddress addr = _context.router().getRouterInfo().getTargetAddress("SSU");
if (addr == null)
return "unknown";
UDPAddress ua = new UDPAddress(addr);
if (ua.getPort() <= 0)
return "unknown";
return "" + ua.getPort();
}
public String getEnableTimeSyncChecked() {
String disabled = _context.getProperty(Timestamper.PROP_DISABLED, "false");
if ( (disabled != null) && ("true".equalsIgnoreCase(disabled)) )
@ -93,6 +115,22 @@ public class ConfigNetHelper {
return "";
}
public String getTcpAutoPortChecked() {
String enabled = _context.getProperty(PROP_I2NP_NTCP_AUTO_PORT, "false");
if ( (enabled != null) && ("true".equalsIgnoreCase(enabled)) )
return " checked ";
else
return "";
}
public String getTcpAutoIPChecked() {
String enabled = _context.getProperty(PROP_I2NP_NTCP_AUTO_IP, "false");
if ( (enabled != null) && ("true".equalsIgnoreCase(enabled)) )
return " checked ";
else
return "";
}
public String getRequireIntroductionsChecked() {
short status = _context.commSystem().getReachabilityStatus();
switch (status) {

View File

@ -82,14 +82,21 @@
Externally reachable hostname or IP address:
<input name ="ntcphost" type="text" size="16" value="<jsp:getProperty name="nethelper" property="ntcphostname" />" />
(dyndns and the like are fine)<br />
OR use IP address detected by SSU
(currently <jsp:getProperty name="nethelper" property="udpIP" />)?
<input type="checkbox" name="ntcpAutoIP" value="true" <jsp:getProperty name="nethelper" property="tcpAutoIPChecked" /> /><br />
<p>
Externally reachable TCP port:
<input name ="ntcpport" type="text" size="6" value="<jsp:getProperty name="nethelper" property="ntcpport" />" /><br />
OR use the same port configured for SSU
(currently <jsp:getProperty name="nethelper" property="udpPort" />)?
<input type="checkbox" name="ntcpAutoPort" value="true" <jsp:getProperty name="nethelper" property="tcpAutoPortChecked" /> /><br />
<p>You do <i>not</i> need to allow inbound TCP connections - outbound connections work with no
configuration. However, if you want to receive inbound TCP connections, you <b>must</b> poke a hole
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>Note: changing this setting will terminate all of your connections and effectively
<p><b>Note: changing any of these settings will terminate all of your connections and effectively
restart your router.</b>
<hr />
<!--