- Simplify config.jsp some more

- No longer use i2np.udp.forceIntroducers
- Tweak UDP port qualification
- Fix allowing low ports again
- Add option to completely disable NTCP, for those behind nasty firewalls
- Use SSU reachability rather than global reachability for determining NTCP reachability,
  since we are now reporting NTCP reachability too
This commit is contained in:
zzz
2009-05-06 00:54:24 +00:00
parent e82f173f85
commit 0b7fb21263
6 changed files with 49 additions and 32 deletions

View File

@ -163,7 +163,9 @@ public class ConfigNetHandler extends FormHandler {
if (_ntcpAutoIP == null) _ntcpAutoIP = "true"; if (_ntcpAutoIP == null) _ntcpAutoIP = "true";
if ((!oldAutoHost.equals(_ntcpAutoIP)) || ! oldNHost.equalsIgnoreCase(_ntcpHostname)) { if ((!oldAutoHost.equals(_ntcpAutoIP)) || ! oldNHost.equalsIgnoreCase(_ntcpHostname)) {
if ("false".equals(_ntcpAutoIP) && _ntcpHostname.length() > 0) { if ("disabled".equals(_ntcpAutoIP)) {
addFormNotice("Disabling TCP completely");
} else if ("false".equals(_ntcpAutoIP) && _ntcpHostname.length() > 0) {
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME, _ntcpHostname); _context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME, _ntcpHostname);
addFormNotice("Updating inbound TCP address to " + _ntcpHostname); addFormNotice("Updating inbound TCP address to " + _ntcpHostname);
} else { } else {
@ -174,6 +176,7 @@ public class ConfigNetHandler extends FormHandler {
addFormNotice("Updating inbound TCP address to auto"); // true or always addFormNotice("Updating inbound TCP address to auto"); // true or always
} }
_context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_IP, _ntcpAutoIP); _context.router().setConfigSetting(ConfigNetHelper.PROP_I2NP_NTCP_AUTO_IP, _ntcpAutoIP);
_context.router().setConfigSetting(TransportManager.PROP_ENABLE_NTCP, "" + !"disabled".equals(_ntcpAutoIP));
restartRequired = true; restartRequired = true;
} }
if (oldAutoPort != _ntcpAutoPort || ! oldNPort.equals(_ntcpPort)) { if (oldAutoPort != _ntcpAutoPort || ! oldNPort.equals(_ntcpPort)) {

View File

@ -28,14 +28,10 @@ public class ConfigNetHelper extends HelperBase {
} }
public String getNtcphostname() { public String getNtcphostname() {
if (!TransportManager.enableNTCP(_context))
return "\" disabled=\"true";
return _context.getProperty(PROP_I2NP_NTCP_HOSTNAME, ""); return _context.getProperty(PROP_I2NP_NTCP_HOSTNAME, "");
} }
public String getNtcpport() { public String getNtcpport() {
if (!TransportManager.enableNTCP(_context))
return "\" disabled=\"true";
return _context.getProperty(PROP_I2NP_NTCP_PORT, ""); return _context.getProperty(PROP_I2NP_NTCP_PORT, "");
} }
@ -91,8 +87,6 @@ public class ConfigNetHelper extends HelperBase {
} }
public String getTcpAutoPortChecked(int mode) { public String getTcpAutoPortChecked(int mode) {
if (!TransportManager.enableNTCP(_context))
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;
if ((mode == 1 && specified) || if ((mode == 1 && specified) ||
@ -102,17 +96,15 @@ public class ConfigNetHelper extends HelperBase {
} }
public String getTcpAutoIPChecked(int mode) { public String getTcpAutoIPChecked(int mode) {
if (!TransportManager.enableNTCP(_context)) boolean enabled = TransportManager.enableNTCP(_context);
return DISABLED;
String hostname = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME); String hostname = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME);
boolean specified = hostname != null && hostname.length() > 0; boolean specified = hostname != null && hostname.length() > 0;
String auto = _context.getProperty(PROP_I2NP_NTCP_AUTO_IP); String auto = _context.getProperty(PROP_I2NP_NTCP_AUTO_IP, "false");
if (auto == null) if ((mode == 0 && (!specified) && auto.equals("false") && enabled) ||
auto = "false"; (mode == 1 && specified && auto.equals("false") && enabled) ||
if ((mode == 0 && (!specified) && auto.equals("false")) || (mode == 2 && auto.equals("true") && enabled) ||
(mode == 1 && specified && auto.equals("false")) || (mode == 3 && auto.equals("always") && enabled) ||
(mode == 2 && auto.equals("true")) || (mode == 4 && !enabled))
(mode == 3 && auto.equals("always")))
return CHECKED; return CHECKED;
return ""; return "";
} }

View File

@ -111,15 +111,17 @@
Hidden mode - do not publish IP<i>(not recommended; change restarts router)</i><br /> Hidden mode - do not publish IP<i>(not recommended; change restarts router)</i><br />
</p><p> </p><p>
<b>UDP Configuration:</b><br /> <b>UDP Configuration:</b><br />
Internal UDP port: UDP port:
<input name ="udpPort" type="text" size="5" maxlength="5" value="<jsp:getProperty name="nethelper" property="configuredUdpPort" />" /><br /> <input name ="udpPort" type="text" size="5" maxlength="5" value="<jsp:getProperty name="nethelper" property="configuredUdpPort" />" /><br />
<!-- let's keep this simple...
<input type="checkbox" name="requireIntroductions" value="true" <jsp:getProperty name="nethelper" property="requireIntroductionsChecked" /> /> <input type="checkbox" name="requireIntroductions" value="true" <jsp:getProperty name="nethelper" property="requireIntroductionsChecked" /> />
Require SSU introductions Require SSU introductions
<i>(Enable if you cannot open your firewall)</i> <i>(Enable if you cannot open your firewall)</i>
</p><p> </p><p>
Current External UDP address: <i><jsp:getProperty name="nethelper" property="udpAddress" /></i><br /> Current External UDP address: <i><jsp:getProperty name="nethelper" property="udpAddress" /></i><br />
-->
</p><p> </p><p>
<b>Inbound TCP Configuration:</b><br /> <b>TCP Configuration:</b><br />
Externally reachable hostname or IP address:<br /> Externally reachable hostname or IP address:<br />
<input type="radio" name="ntcpAutoIP" value="true" <%=nethelper.getTcpAutoIPChecked(2) %> /> <input type="radio" name="ntcpAutoIP" value="true" <%=nethelper.getTcpAutoIPChecked(2) %> />
Use auto-detected IP address Use auto-detected IP address
@ -128,11 +130,12 @@
<input type="radio" name="ntcpAutoIP" value="always" <%=nethelper.getTcpAutoIPChecked(3) %> /> <input type="radio" name="ntcpAutoIP" value="always" <%=nethelper.getTcpAutoIPChecked(3) %> />
Always use auto-detected IP address (Not firewalled)<br /> Always use auto-detected IP address (Not firewalled)<br />
<input type="radio" name="ntcpAutoIP" value="false" <%=nethelper.getTcpAutoIPChecked(0) %> /> <input type="radio" name="ntcpAutoIP" value="false" <%=nethelper.getTcpAutoIPChecked(0) %> />
Disable (Firewalled)<br /> Disable inbound (Firewalled)<br />
<input type="radio" name="ntcpAutoIP" value="false" <%=nethelper.getTcpAutoIPChecked(1) %> /> <input type="radio" name="ntcpAutoIP" value="false" <%=nethelper.getTcpAutoIPChecked(1) %> />
Specify hostname or IP: Specify hostname or IP:
<input name ="ntcphost" type="text" size="16" value="<jsp:getProperty name="nethelper" property="ntcphostname" />" /> <input name ="ntcphost" type="text" size="16" value="<jsp:getProperty name="nethelper" property="ntcphostname" />" /><br />
<br /> <input type="radio" name="ntcpAutoIP" value="disabled" <%=nethelper.getTcpAutoIPChecked(4) %> />
Completely disable <i>(select only if behind a firewall that throttles or blocks outbound TCP - restart required)</i><br />
</p><p> </p><p>
Externally reachable TCP port:<br /> Externally reachable TCP port:<br />
<input type="radio" name="ntcpAutoPort" value="2" <%=nethelper.getTcpAutoPortChecked(2) %> /> <input type="radio" name="ntcpAutoPort" value="2" <%=nethelper.getTcpAutoPortChecked(2) %> />
@ -152,9 +155,11 @@
with "SSU introductions" - peers who will relay a request from someone you don't know to your with "SSU introductions" - peers who will relay a request from someone you don't know to your
router for your router so that you can make an outbound connection to them. I2P will use these router for your router so that you can make an outbound connection to them. I2P will use these
introductions automatically if it detects that the port is not forwarded (as shown by introductions automatically if it detects that the port is not forwarded (as shown by
the <i>Reachability: Firewalled</i> line), or you can manually require them here. the <i>Reachability: Firewalled</i> line).
Users behind symmetric NATs, such as OpenBSD's pf, are not currently supported.</p> Users behind symmetric NATs, such as OpenBSD's pf, are not currently supported.</p>
<!-- let's keep this simple...
<input type="submit" name="recheckReachability" value="Check network reachability..." /> <input type="submit" name="recheckReachability" value="Check network reachability..." />
-->
<p>Hostnames entered here will be published in the network database. <p>Hostnames entered here will be published in the network database.
They are <b>not private</b>. 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. Also, <b>do not enter a private IP address</b> like 127.0.0.1 or 192.168.1.1.

View File

@ -27,6 +27,7 @@ import net.i2p.router.RouterContext;
import net.i2p.router.transport.ntcp.NTCPAddress; import net.i2p.router.transport.ntcp.NTCPAddress;
import net.i2p.router.transport.ntcp.NTCPTransport; import net.i2p.router.transport.ntcp.NTCPTransport;
import net.i2p.router.transport.udp.UDPAddress; import net.i2p.router.transport.udp.UDPAddress;
import net.i2p.router.transport.udp.UDPTransport;
import net.i2p.util.Log; import net.i2p.util.Log;
public class CommSystemFacadeImpl extends CommSystemFacade { public class CommSystemFacadeImpl extends CommSystemFacade {
@ -151,8 +152,8 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
@Override @Override
public short getReachabilityStatus() { public short getReachabilityStatus() {
if (_manager == null) return CommSystemFacade.STATUS_UNKNOWN; if (_manager == null) return STATUS_UNKNOWN;
if (_context.router().isHidden()) return CommSystemFacade.STATUS_OK; if (_context.router().isHidden()) return STATUS_OK;
return _manager.getReachabilityStatus(); return _manager.getReachabilityStatus();
} }
@Override @Override
@ -303,10 +304,14 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
String name = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME); String name = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME);
if (name != null && name.length() > 0) if (name != null && name.length() > 0)
enabled = "false"; enabled = "false";
Transport udp = _manager.getTransport(UDPTransport.STYLE);
short status = STATUS_UNKNOWN;
if (udp != null)
status = udp.getReachabilityStatus();
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("old: " + ohost + " config: " + name + " auto: " + enabled + " status: " + getReachabilityStatus()); _log.info("old: " + ohost + " config: " + name + " auto: " + enabled + " status: " + status);
if (enabled.equalsIgnoreCase("always") || if (enabled.equalsIgnoreCase("always") ||
(enabled.equalsIgnoreCase("true") && getReachabilityStatus() == CommSystemFacade.STATUS_OK)) { (enabled.equalsIgnoreCase("true") && status == STATUS_OK)) {
String nhost = UDPProps.getProperty(UDPAddress.PROP_HOST); String nhost = UDPProps.getProperty(UDPAddress.PROP_HOST);
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("old: " + ohost + " config: " + name + " new: " + nhost); _log.info("old: " + ohost + " config: " + name + " new: " + nhost);

View File

@ -40,10 +40,10 @@ public class TransportManager implements TransportEventListener {
private RouterContext _context; private RouterContext _context;
private UPnPManager _upnpManager; private UPnPManager _upnpManager;
private final static String PROP_ENABLE_UDP = "i2np.udp.enable"; public final static String PROP_ENABLE_UDP = "i2np.udp.enable";
private final static String PROP_ENABLE_NTCP = "i2np.ntcp.enable"; public final static String PROP_ENABLE_NTCP = "i2np.ntcp.enable";
private final static String DEFAULT_ENABLE_NTCP = "true"; public final static String DEFAULT_ENABLE_NTCP = "true";
private final static String DEFAULT_ENABLE_UDP = "true"; public final static String DEFAULT_ENABLE_UDP = "true";
/** default true */ /** default true */
public final static String PROP_ENABLE_UPNP = "i2np.upnp.enable"; public final static String PROP_ENABLE_UPNP = "i2np.upnp.enable";

View File

@ -100,6 +100,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
public static final String STYLE = "SSU"; public static final String STYLE = "SSU";
public static final String PROP_INTERNAL_PORT = "i2np.udp.internalPort"; public static final String PROP_INTERNAL_PORT = "i2np.udp.internalPort";
public static final int DEFAULT_INTERNAL_PORT = 8887; public static final int DEFAULT_INTERNAL_PORT = 8887;
/** since fixed port defaults to true, this doesnt do anything at the moment.
* We should have an exception if it matches the existing low port. */
private static final int MIN_EXTERNAL_PORT = 1024; private static final int MIN_EXTERNAL_PORT = 1024;
/** define this to explicitly set an external IP address */ /** define this to explicitly set an external IP address */
@ -386,7 +388,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
* @param ourPort >= 1024 * @param ourPort >= 1024
*/ */
void externalAddressReceived(Hash from, byte ourIP[], int ourPort) { void externalAddressReceived(Hash from, byte ourIP[], int ourPort) {
boolean isValid = isValid(ourIP) && ourPort >= MIN_EXTERNAL_PORT; boolean isValid = isValid(ourIP) &&
(ourPort >= MIN_EXTERNAL_PORT || ourPort == _externalListenPort || _externalListenPort <= 0);
boolean explicitSpecified = explicitAddressSpecified(); boolean explicitSpecified = explicitAddressSpecified();
boolean inboundRecent = _lastInboundReceivedOn + ALLOW_IP_CHANGE_INTERVAL > System.currentTimeMillis(); boolean inboundRecent = _lastInboundReceivedOn + ALLOW_IP_CHANGE_INTERVAL > System.currentTimeMillis();
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
@ -422,6 +425,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
* @param ourPort >= 1024 or 0 for no change * @param ourPort >= 1024 or 0 for no change
*/ */
private boolean changeAddress(byte ourIP[], int ourPort) { private boolean changeAddress(byte ourIP[], int ourPort) {
/** this defaults to true, which means we never change our external port based on what somebody tells us */
boolean fixedPort = getIsPortFixed(); boolean fixedPort = getIsPortFixed();
boolean updated = false; boolean updated = false;
boolean fireTest = false; boolean fireTest = false;
@ -437,9 +441,10 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
_log.info("Trying to change our external address..."); _log.info("Trying to change our external address...");
try { try {
_externalListenHost = InetAddress.getByAddress(ourIP); _externalListenHost = InetAddress.getByAddress(ourIP);
// fixed port defaults to true so we never do this
if (ourPort >= MIN_EXTERNAL_PORT && !fixedPort) if (ourPort >= MIN_EXTERNAL_PORT && !fixedPort)
_externalListenPort = ourPort; _externalListenPort = ourPort;
if (_externalListenPort >= MIN_EXTERNAL_PORT) { if (_externalListenPort > 0) {
rebuildExternalAddress(); rebuildExternalAddress();
replaceAddress(_externalAddress); replaceAddress(_externalAddress);
updated = true; updated = true;
@ -1171,12 +1176,18 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
} }
public boolean introducersRequired() { public boolean introducersRequired() {
/******************
* Don't do this anymore, as we are removing the checkbox from the UI,
* and we rarely if ever see the problem of false negatives for firewall detection -
* it's usually false positives.
******************
String forceIntroducers = _context.getProperty(PROP_FORCE_INTRODUCERS); String forceIntroducers = _context.getProperty(PROP_FORCE_INTRODUCERS);
if ( (forceIntroducers != null) && (Boolean.valueOf(forceIntroducers).booleanValue()) ) { if ( (forceIntroducers != null) && (Boolean.valueOf(forceIntroducers).booleanValue()) ) {
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Force introducers specified"); _log.info("Force introducers specified");
return true; return true;
} }
*******************/
short status = getReachabilityStatus(); short status = getReachabilityStatus();
switch (status) { switch (status) {
case CommSystemFacade.STATUS_REJECT_UNSOLICITED: case CommSystemFacade.STATUS_REJECT_UNSOLICITED:
@ -1194,6 +1205,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
} }
} }
/** default true */
private boolean allowDirectUDP() { private boolean allowDirectUDP() {
String allowDirect = _context.getProperty(PROP_ALLOW_DIRECT); String allowDirect = _context.getProperty(PROP_ALLOW_DIRECT);
return ( (allowDirect == null) || (Boolean.valueOf(allowDirect).booleanValue()) ); return ( (allowDirect == null) || (Boolean.valueOf(allowDirect).booleanValue()) );