* Fixes for IPv4 and other breakage after basic testing

* Catch exception from UPnP callback
* Log tweaks
This commit is contained in:
zzz
2013-05-10 18:34:02 +00:00
parent c76c80043f
commit 5e953b0857
5 changed files with 42 additions and 21 deletions

View File

@ -272,8 +272,8 @@ public class TransportManager implements TransportEventListener {
if ((tempSkews == null) || (tempSkews.isEmpty())) continue;
skews.addAll(tempSkews);
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("Transport manager returning " + skews.size() + " peer clock skews.");
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("Transport manager returning " + skews.size() + " peer clock skews.");
return skews;
}
@ -392,6 +392,8 @@ public class TransportManager implements TransportEventListener {
if (udp != null)
port = t.getRequestedPort();
}
if (port > 0)
rv.add(new Port(t.getStyle(), port));
}
return rv;
}
@ -492,11 +494,11 @@ public class TransportManager implements TransportEventListener {
*/
public void messageReceived(I2NPMessage message, RouterIdentity fromRouter, Hash fromRouterHash) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("I2NPMessage received: " + message.getClass().getName(), new Exception("Where did I come from again?"));
_log.debug("I2NPMessage received: " + message.getClass().getSimpleName() /*, new Exception("Where did I come from again?") */ );
try {
_context.inNetMessagePool().add(message, fromRouter, fromRouterHash);
if (_log.shouldLog(Log.DEBUG))
_log.debug("Added to in pool");
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("Added to in pool");
} catch (IllegalArgumentException iae) {
if (_log.shouldLog(Log.WARN))
_log.warn("Error receiving message", iae);

View File

@ -821,7 +821,11 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
fps = new ForwardPortStatus(ForwardPortStatus.PROBABLE_FAILURE, "UPnP port forwarding apparently failed", port.portNumber);
}
Map map = Collections.singletonMap(port, fps);
forwardCallback.portForwardStatus(map);
try {
forwardCallback.portForwardStatus(map);
} catch (Exception e) {
_log.error("UPnP RPT error", e);
}
}
}
}

View File

@ -845,16 +845,16 @@ public class NTCPTransport extends TransportImpl {
// without tearing down everything
// Especially on disabling the address, we shouldn't tear everything down.
//
_log.warn("Halting NTCP to change address");
if (_log.shouldLog(Log.WARN))
_log.warn("Halting NTCP to change address");
stopListening();
if (newAddr != null)
newAddr.setOptions(newProps);
// Wait for NTCP Pumper to stop so we don't end up with two...
while (isAlive()) {
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
}
restartListening(newAddr);
_log.warn("Changed NTCP Address and started up, address is now " + newAddr);
if (_log.shouldLog(Log.WARN))
_log.warn("Changed NTCP Address and started up, address is now " + newAddr);
return;
}

View File

@ -62,7 +62,7 @@ class ACKSender implements Runnable {
public synchronized void shutdown() {
_alive = false;
PeerState poison = new PeerState(_context, _transport, null, 0, null, false);
PeerState poison = new PeerState(_context, _transport, new byte[4], 0, null, false);
poison.setTheyRelayToUsAs(POISON_PS);
_peersToACK.offer(poison);
for (int i = 1; i <= 5 && !_peersToACK.isEmpty(); i++) {

View File

@ -1603,6 +1603,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
* @return the new address if changed, else null
*/
private RouterAddress rebuildExternalAddress() {
if (_log.shouldLog(Log.DEBUG))
_log.debug("REA1");
return rebuildExternalAddress(true);
}
@ -1613,19 +1615,24 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
* @return the new address if changed, else null
*/
private RouterAddress rebuildExternalAddress(boolean allowRebuildRouterInfo) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("REA2 " + allowRebuildRouterInfo);
// if the external port is specified, we want to use that to bind to even
// if we don't know the external host.
int port = _context.getProperty(PROP_EXTERNAL_PORT, -1);
byte[] ip = null;
String host = null;
if (explicitAddressSpecified()) {
String host = _context.getProperty(PROP_EXTERNAL_HOST);
return rebuildExternalAddress(host, port, allowRebuildRouterInfo);
host = _context.getProperty(PROP_EXTERNAL_HOST);
} else {
RouterAddress cur = getCurrentAddress(false);
if (cur != null)
host = cur.getHost();
}
return rebuildExternalAddress(ip, port, allowRebuildRouterInfo);
return rebuildExternalAddress(host, port, allowRebuildRouterInfo);
}
/**
* Update our IPv4 or IPv6 address and optionally tell the router to rebuild and republish the router info.
*
@ -1636,7 +1643,11 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
* @since IPv6
*/
private RouterAddress rebuildExternalAddress(byte[] ip, int port, boolean allowRebuildRouterInfo) {
if (ip == null || isValid(ip))
if (_log.shouldLog(Log.DEBUG))
_log.debug("REA3 " + Addresses.toString(ip, port));
if (ip == null)
return rebuildExternalAddress((String) null, port, allowRebuildRouterInfo);
if (isValid(ip))
return rebuildExternalAddress(Addresses.toString(ip), port, allowRebuildRouterInfo);
return null;
}
@ -1644,13 +1655,15 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
/**
* Update our IPv4 or IPv6 address and optionally tell the router to rebuild and republish the router info.
*
* @param host new valid IPv4 or IPv6 or DNS hostname or null
* @param port new valid port or -1
* @param host new validated IPv4 or IPv6 or DNS hostname or null
* @param port new validated port or 0/-1
* @param allowRebuildRouterInfo whether to tell the router
* @return the new address if changed, else null
* @since IPv6
*/
private RouterAddress rebuildExternalAddress(String host, int port, boolean allowRebuildRouterInfo) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("REA4 " + host + ':' + port);
if (_context.router().isHidden())
return null;
@ -1670,7 +1683,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
int found = _introManager.pickInbound(options, PUBLIC_RELAY_COUNT);
if (found > 0) {
if (_log.shouldLog(Log.INFO))
_log.info("Picked peers: " + found);
_log.info("Direct? " + directIncluded + " reqd? " + introducersRequired +
" picked introducers: " + found);
_introducersSelectedOn = _context.clock().now();
introducersIncluded = true;
} else {
@ -1678,7 +1692,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
// maybe we should fail to publish an address at all in this case?
// YES that would be better
if (_log.shouldLog(Log.WARN))
_log.warn("Need introducers but we don't know any");
_log.warn("Direct? " + directIncluded + " reqd? " + introducersRequired +
" no introducers");
}
}
@ -1710,7 +1725,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
if (wantsRebuild) {
if (_log.shouldLog(Log.INFO))
_log.info("Address rebuilt: " + addr);
_log.info("Address rebuilt: " + addr, new Exception());
replaceAddress(addr);
if (allowRebuildRouterInfo)
_context.router().rebuildRouterInfo();