I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit b4615edf authored by zzz's avatar zzz
Browse files

* UDP:

      - Better handle a test reply from bob with a 0-length IP
      - Add config options for min and max random port
parent 6019cf81
No related branches found
No related tags found
No related merge requests found
...@@ -163,7 +163,24 @@ class PeerTestManager { ...@@ -163,7 +163,24 @@ class PeerTestManager {
if (_currentTestComplete) if (_currentTestComplete)
return; return;
if ( (DataHelper.eq(from.getIP(), test.getBobIP().getAddress())) && (from.getPort() == test.getBobPort()) ) { 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); testInfo.readIP(ip, 0);
try { try {
InetAddress addr = InetAddress.getByAddress(ip); InetAddress addr = InetAddress.getByAddress(ip);
...@@ -177,10 +194,12 @@ class PeerTestManager { ...@@ -177,10 +194,12 @@ class PeerTestManager {
testComplete(false); testComplete(false);
} catch (UnknownHostException uhe) { } catch (UnknownHostException uhe) {
if (_log.shouldLog(Log.ERROR)) 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); ") from bob's reply: " + from + ", " + testInfo, uhe);
} }
} else { } else {
// The reply is from Charlie
PeerState charlieSession = _transport.getPeerState(from); PeerState charlieSession = _transport.getPeerState(from);
long recentBegin = _context.clock().now() - CHARLIE_RECENT_PERIOD; long recentBegin = _context.clock().now() - CHARLIE_RECENT_PERIOD;
if ( (charlieSession != null) && if ( (charlieSession != null) &&
......
...@@ -82,6 +82,8 @@ public class UDPEndpoint { ...@@ -82,6 +82,8 @@ public class UDPEndpoint {
********/ ********/
/** 8998 is monotone, and 32000 is the wrapper, so let's stay between those */ /** 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 MIN_RANDOM_PORT = 9111;
private static final int MAX_RANDOM_PORT = 31777; private static final int MAX_RANDOM_PORT = 31777;
private static final int MAX_PORT_RETRIES = 20; private static final int MAX_PORT_RETRIES = 20;
...@@ -100,7 +102,9 @@ public class UDPEndpoint { ...@@ -100,7 +102,9 @@ public class UDPEndpoint {
if (port <= 0) { if (port <= 0) {
// try random ports rather than just do new DatagramSocket() // try random ports rather than just do new DatagramSocket()
// so we stay out of the way of other I2P stuff // 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 { try {
if (_bindAddress == null) if (_bindAddress == null)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment