- NTCP Port must now be either auto or configured;

now defaults to auto; and configured now trumps auto.
  Port configuration now does not affect whether inbound
  NTCP is enabled - the host configuration alone can do that.
This commit is contained in:
zzz
2009-04-30 16:50:47 +00:00
parent 4929a7e635
commit 5b44bcb44f
4 changed files with 32 additions and 30 deletions

View File

@ -66,8 +66,6 @@ public class ConfigNetHandler extends FormHandler {
} }
public void setNtcpAutoPort(String mode) { public void setNtcpAutoPort(String mode) {
_ntcpAutoPort = mode.equals("2"); _ntcpAutoPort = mode.equals("2");
if (mode.equals("0"))
_ntcpInboundDisabled = true;
} }
public void setUpnp(String moo) { _upnp = true; } public void setUpnp(String moo) { _upnp = true; }
@ -155,19 +153,14 @@ public class ConfigNetHandler extends FormHandler {
restartRequired = true; restartRequired = true;
} }
if (oldAutoPort != _ntcpAutoPort || ! oldNPort.equals(_ntcpPort)) { if (oldAutoPort != _ntcpAutoPort || ! oldNPort.equals(_ntcpPort)) {
if ( _ntcpAutoPort ) { if (_ntcpPort.length() > 0 && !_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().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT, _ntcpPort);
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_PORT);
addFormNotice("Updating inbound TCP port to " + _ntcpPort); addFormNotice("Updating inbound TCP port to " + _ntcpPort);
} else { } else {
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT); _context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_PORT);
_context.router().removeConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_PORT); addFormNotice("Updating inbound TCP port to auto");
addFormNotice("Disabling inbound TCP");
} }
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_PORT, "" + _ntcpAutoPort);
restartRequired = true; restartRequired = true;
} }

View File

@ -103,10 +103,8 @@ public class ConfigNetHelper extends HelperBase {
return DISABLED; return DISABLED;
String port = _context.getProperty(PROP_I2NP_NTCP_PORT); String port = _context.getProperty(PROP_I2NP_NTCP_PORT);
boolean specified = port != null && port.length() > 0; boolean specified = port != null && port.length() > 0;
boolean auto = Boolean.valueOf(_context.getProperty(PROP_I2NP_NTCP_AUTO_PORT)).booleanValue(); if ((mode == 1 && specified) ||
if ((mode == 0 && (!specified) && !auto) || (mode == 2 && !specified))
(mode == 1 && specified && !auto) ||
(mode == 2 && auto))
return CHECKED; return CHECKED;
return ""; return "";
} }

View File

@ -125,8 +125,6 @@
<i>(dyndns and the like are fine)</i><br /> <i>(dyndns and the like are fine)</i><br />
<p> <p>
Externally reachable TCP port:<br /> Externally reachable TCP port:<br />
<input type="radio" name="ntcpAutoPort" value="0" <%=nethelper.getTcpAutoPortChecked(0) %> />
Disable<br />
<input type="radio" name="ntcpAutoPort" value="2" <%=nethelper.getTcpAutoPortChecked(2) %> /> <input type="radio" name="ntcpAutoPort" value="2" <%=nethelper.getTcpAutoPortChecked(2) %> />
Use the same port configured for SSU Use the same port configured for SSU
<i>(currently <jsp:getProperty name="nethelper" property="udpPort" />)</i><br /> <i>(currently <jsp:getProperty name="nethelper" property="udpPort" />)</i><br />

View File

@ -193,6 +193,9 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
public final static String PROP_I2NP_NTCP_AUTO_PORT = "i2np.ntcp.autoport"; public final static String PROP_I2NP_NTCP_AUTO_PORT = "i2np.ntcp.autoport";
public final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip"; public final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip";
/**
* This should really be moved to ntcp/NTCPTransport.java, why is it here?
*/
public static RouterAddress createNTCPAddress(RouterContext ctx) { public static RouterAddress createNTCPAddress(RouterContext ctx) {
if (!TransportManager.enableNTCP(ctx)) return null; if (!TransportManager.enableNTCP(ctx)) return null;
RouterAddress addr = new RouterAddress(); RouterAddress addr = new RouterAddress();
@ -236,6 +239,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
/** /**
* UDP changed addresses, tell NTCP and restart * UDP changed addresses, tell NTCP and restart
* This should really be moved to ntcp/NTCPTransport.java, why is it here?
*/ */
@Override @Override
public void notifyReplaceAddress(RouterAddress UDPAddr) { public void notifyReplaceAddress(RouterAddress UDPAddr) {
@ -249,7 +253,8 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
return; return;
Properties newProps; Properties newProps;
RouterAddress oldAddr = t.getCurrentAddress(); RouterAddress oldAddr = t.getCurrentAddress();
//_log.warn("Changing NTCP Address? was " + oldAddr); if (_log.shouldLog(Log.INFO))
_log.info("Changing NTCP Address? was " + oldAddr);
RouterAddress newAddr = oldAddr; RouterAddress newAddr = oldAddr;
if (newAddr == null) { if (newAddr == null) {
newAddr = new RouterAddress(); newAddr = new RouterAddress();
@ -264,23 +269,27 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
} }
boolean changed = false; boolean changed = false;
// old behavior (<= 0.7.3): auto-port defaults to false, and true trumps explicit setting
// new behavior (>= 0.7.4): auto-port defaults to true, but explicit setting trumps auto
String oport = newProps.getProperty(NTCPAddress.PROP_PORT); String oport = newProps.getProperty(NTCPAddress.PROP_PORT);
String enabled = _context.getProperty(PROP_I2NP_NTCP_AUTO_PORT, "false"); String nport = null;
if ( (enabled != null) && ("true".equalsIgnoreCase(enabled)) ) { String cport = _context.getProperty(PROP_I2NP_NTCP_PORT);
String nport = UDPProps.getProperty(UDPAddress.PROP_PORT); if (cport != null && cport.length() > 0) {
nport = cport;
} else if (Boolean.valueOf(_context.getProperty(PROP_I2NP_NTCP_AUTO_PORT, "true")).booleanValue()) {
nport = UDPProps.getProperty(UDPAddress.PROP_PORT);
}
if (_log.shouldLog(Log.INFO))
_log.info("old: " + oport + " config: " + cport + " new: " + nport);
if (nport == null || nport.length() <= 0) if (nport == null || nport.length() <= 0)
return; return;
if (oport == null || ! oport.equals(nport)) { if (oport == null || ! oport.equals(nport)) {
newProps.setProperty(NTCPAddress.PROP_PORT, nport); newProps.setProperty(NTCPAddress.PROP_PORT, nport);
changed = true; changed = true;
} }
} else if (oport == null || oport.length() <= 0) {
return;
}
String ohost = newProps.getProperty(NTCPAddress.PROP_HOST); String ohost = newProps.getProperty(NTCPAddress.PROP_HOST);
enabled = _context.getProperty(PROP_I2NP_NTCP_AUTO_IP, "false"); if (Boolean.valueOf(_context.getProperty(PROP_I2NP_NTCP_AUTO_IP)).booleanValue()) {
if ( (enabled != null) && ("true".equalsIgnoreCase(enabled)) ) {
String nhost = UDPProps.getProperty(UDPAddress.PROP_HOST); String nhost = UDPProps.getProperty(UDPAddress.PROP_HOST);
if (nhost == null || nhost.length() <= 0) if (nhost == null || nhost.length() <= 0)
return; return;
@ -293,12 +302,16 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
} }
if (!changed) { if (!changed) {
//_log.warn("No change to NTCP Address"); _log.warn("No change to NTCP Address");
return; return;
} }
// stopListening stops the pumper, readers, and writers, so required even if // stopListening stops the pumper, readers, and writers, so required even if
// oldAddr == null since startListening starts them all again // oldAddr == null since startListening starts them all again
//
// really need to fix this so that we can change or create an inbound address
// without tearing down everything
//
_log.warn("Halting NTCP to change address"); _log.warn("Halting NTCP to change address");
t.stopListening(); t.stopListening();
newAddr.setOptions(newProps); newAddr.setOptions(newProps);