diff --git a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java index eb6767c38..a426c4530 100644 --- a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java +++ b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java @@ -206,14 +206,15 @@ public class CommSystemFacadeImpl extends CommSystemFacade { public final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip"; /** + * This only creates an address if the hostname AND port are set in router.config, + * which should be rare. + * Otherwise, notifyReplaceAddress() below takes care of it. + * Note this is called both from above and from NTCPTransport.startListening() + * * This should really be moved to ntcp/NTCPTransport.java, why is it here? */ public static RouterAddress createNTCPAddress(RouterContext ctx) { if (!TransportManager.enableNTCP(ctx)) return null; - RouterAddress addr = new RouterAddress(); - addr.setCost(10); - addr.setExpiration(null); - Properties props = new Properties(); String name = ctx.router().getConfigSetting(PROP_I2NP_NTCP_HOSTNAME); String port = ctx.router().getConfigSetting(PROP_I2NP_NTCP_PORT); /* @@ -236,12 +237,16 @@ public class CommSystemFacadeImpl extends CommSystemFacade { } catch (NumberFormatException nfe) { return null; } + Properties props = new Properties(); props.setProperty(NTCPAddress.PROP_HOST, name); props.setProperty(NTCPAddress.PROP_PORT, port); + RouterAddress addr = new RouterAddress(); + addr.setCost(10); + addr.setExpiration(null); addr.setOptions(props); addr.setTransportStyle(NTCPTransport.STYLE); //if (isNew) { - if (false) return null; + // why save the same thing? ctx.router().setConfigSetting(PROP_I2NP_NTCP_HOSTNAME, name); ctx.router().setConfigSetting(PROP_I2NP_NTCP_PORT, port); ctx.router().saveConfig(); @@ -334,6 +339,15 @@ public class CommSystemFacadeImpl extends CommSystemFacade { } } else if (ohost == null || ohost.length() <= 0) { return; + } else if (enabled.equalsIgnoreCase("true") && status != STATUS_OK) { + // UDP transitioned to not-OK, turn off NTCP address + // This will commonly happen at startup if we were initially OK + // because UPnP was successful, but a subsequent SSU Peer Test determines + // we are still firewalled (SW firewall, bad UPnP indication, etc.) + if (_log.shouldLog(Log.INFO)) + _log.info("old: " + ohost + " config: " + name + " new: null"); + newAddr = null; + changed = true; } if (!changed) { @@ -346,10 +360,12 @@ public class CommSystemFacadeImpl extends CommSystemFacade { // // really need to fix this so that we can change or create an inbound address // without tearing down everything + // Especially on disabling the address, we shouldn't tear everything down. // _log.warn("Halting NTCP to change address"); t.stopListening(); - newAddr.setOptions(newProps); + if (newAddr != null) + newAddr.setOptions(newProps); // Wait for NTCP Pumper to stop so we don't end up with two... while (t.isAlive()) { try { Thread.sleep(5*1000); } catch (InterruptedException ie) {} diff --git a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java index de4559b28..5fa10b310 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java +++ b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java @@ -417,7 +417,7 @@ public class NTCPTransport extends TransportImpl { private static final int NUM_CONCURRENT_WRITERS = 3; public synchronized RouterAddress startListening() { - if (_log.shouldLog(Log.DEBUG)) _log.debug("Starting ntcp transport listening"); + if (_log.shouldLog(Log.WARN)) _log.warn("Starting ntcp transport listening"); _finisher.start(); _pumper.startPumping(); @@ -429,14 +429,17 @@ public class NTCPTransport extends TransportImpl { } public synchronized RouterAddress restartListening(RouterAddress addr) { - if (_log.shouldLog(Log.DEBUG)) _log.debug("Restarting ntcp transport listening"); + if (_log.shouldLog(Log.WARN)) _log.warn("Restarting ntcp transport listening"); _finisher.start(); _pumper.startPumping(); _reader.startReading(NUM_CONCURRENT_READERS); _writer.startWriting(NUM_CONCURRENT_WRITERS); - _myAddress = new NTCPAddress(addr); + if (addr == null) + _myAddress = null; + else + _myAddress = new NTCPAddress(addr); return bindAddress(); } @@ -603,7 +606,7 @@ public class NTCPTransport extends TransportImpl { * before calling startListening() or restartListening() */ public synchronized void stopListening() { - if (_log.shouldLog(Log.DEBUG)) _log.debug("Stopping ntcp transport"); + if (_log.shouldLog(Log.WARN)) _log.warn("Stopping ntcp transport"); _pumper.stopPumping(); _writer.stopWriting(); _reader.stopReading(); diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java index 8102c2c7c..47edd62c3 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java @@ -437,12 +437,16 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority synchronized (this) { if ( (_externalListenHost == null) || (!eq(_externalListenHost.getAddress(), _externalListenPort, ourIP, ourPort)) ) { + if (_log.shouldLog(Log.WARN)) + _log.warn("Change address? status = " + _reachabilityStatus + + " diff = " + (_context.clock().now() - _reachabilityStatusLastUpdated) + + " old = " + _externalListenHost + ':' + _externalListenPort); if ( (_reachabilityStatus != CommSystemFacade.STATUS_OK) || (_externalListenHost == null) || (_externalListenPort <= 0) || (_context.clock().now() - _reachabilityStatusLastUpdated > 2*TEST_FREQUENCY) ) { // they told us something different and our tests are either old or failing - if (_log.shouldLog(Log.INFO)) - _log.info("Trying to change our external address..."); + if (_log.shouldLog(Log.WARN)) + _log.warn("Trying to change our external address..."); try { _externalListenHost = InetAddress.getByAddress(ourIP); // fixed port defaults to true so we never do this @@ -455,15 +459,15 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority } } catch (UnknownHostException uhe) { _externalListenHost = null; - if (_log.shouldLog(Log.INFO)) - _log.info("Error trying to change our external address", uhe); + if (_log.shouldLog(Log.WARN)) + _log.warn("Error trying to change our external address", uhe); } } else { // they told us something different, but our tests are recent and positive, // so lets test again fireTest = true; - if (_log.shouldLog(Log.INFO)) - _log.info("Different address, but we're fine.. (" + _reachabilityStatus + ")"); + if (_log.shouldLog(Log.WARN)) + _log.warn("Different address, but we're fine.. (" + _reachabilityStatus + ")"); } } else { // matched what we expect