- Better handle a test reply from bob with a 0-length IP
      - Add config options for min and max random port
This commit is contained in:
zzz
2009-11-09 17:16:51 +00:00
parent 6019cf8148
commit b4615edfcc
2 changed files with 26 additions and 3 deletions

View File

@ -163,7 +163,24 @@ class PeerTestManager {
if (_currentTestComplete)
return;
if ( (DataHelper.eq(from.getIP(), test.getBobIP().getAddress())) && (from.getPort() == test.getBobPort()) ) {
byte ip[] = new byte[testInfo.readIPSize()];
// The reply is from Bob
int ipSize = testInfo.readIPSize();
if (ipSize != 4 && ipSize != 16) {
// There appears to be a bug where Bob is sending us a zero-length IP.
// We could proceed without setting the IP, but then when Charlie
// sends us his message, we will think we are behind a symmetric NAT
// because the Bob and Charlie IPs won't match.
// So for now we just return and pretend we didn't hear from Bob at all.
// Which is essentially what catching the uhe below did,
// but without the error message to the log.
// To do: fix the bug.
if (_log.shouldLog(Log.WARN))
_log.warn("Bad IP length " + ipSize +
" from bob's reply: " + from + ", " + testInfo);
return;
}
byte ip[] = new byte[ipSize];
testInfo.readIP(ip, 0);
try {
InetAddress addr = InetAddress.getByAddress(ip);
@ -177,10 +194,12 @@ class PeerTestManager {
testComplete(false);
} catch (UnknownHostException uhe) {
if (_log.shouldLog(Log.ERROR))
_log.error("Unable to get our IP (length " + ip.length +
_log.error("Unable to get our IP (length " + ipSize +
") from bob's reply: " + from + ", " + testInfo, uhe);
}
} else {
// The reply is from Charlie
PeerState charlieSession = _transport.getPeerState(from);
long recentBegin = _context.clock().now() - CHARLIE_RECENT_PERIOD;
if ( (charlieSession != null) &&

View File

@ -82,6 +82,8 @@ public class UDPEndpoint {
********/
/** 8998 is monotone, and 32000 is the wrapper, so let's stay between those */
public static final String PROP_MIN_PORT = "i2np.udp.minPort";
public static final String PROP_MAX_PORT = "i2np.udp.maxPort";
private static final int MIN_RANDOM_PORT = 9111;
private static final int MAX_RANDOM_PORT = 31777;
private static final int MAX_PORT_RETRIES = 20;
@ -100,7 +102,9 @@ public class UDPEndpoint {
if (port <= 0) {
// try random ports rather than just do new DatagramSocket()
// so we stay out of the way of other I2P stuff
port = MIN_RANDOM_PORT + _context.random().nextInt(MAX_RANDOM_PORT - MIN_RANDOM_PORT);
int minPort = _context.getProperty(PROP_MIN_PORT, MIN_RANDOM_PORT);
int maxPort = _context.getProperty(PROP_MAX_PORT, MAX_RANDOM_PORT);
port = minPort + _context.random().nextInt(maxPort - minPort);
}
try {
if (_bindAddress == null)