Changeset b4615ed


Ignore:
Timestamp:
Nov 9, 2009 5:16:51 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
37a2ccc
Parents:
6019cf81
Message:
  • UDP:
    • Better handle a test reply from bob with a 0-length IP
    • Add config options for min and max random port
Location:
router/java/src/net/i2p/router/transport/udp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/transport/udp/PeerTestManager.java

    r6019cf81 rb4615ed  
    164164            return;
    165165        if ( (DataHelper.eq(from.getIP(), test.getBobIP().getAddress())) && (from.getPort() == test.getBobPort()) ) {
    166             byte ip[] = new byte[testInfo.readIPSize()];
     166            // The reply is from Bob
     167
     168            int ipSize = testInfo.readIPSize();
     169            if (ipSize != 4 && ipSize != 16) {
     170                // There appears to be a bug where Bob is sending us a zero-length IP.
     171                // We could proceed without setting the IP, but then when Charlie
     172                // sends us his message, we will think we are behind a symmetric NAT
     173                // because the Bob and Charlie IPs won't match.
     174                // So for now we just return and pretend we didn't hear from Bob at all.
     175                // Which is essentially what catching the uhe below did,
     176                // but without the error message to the log.
     177                // To do: fix the bug.
     178                if (_log.shouldLog(Log.WARN))
     179                    _log.warn("Bad IP length " + ipSize +
     180                               " from bob's reply: " + from + ", " + testInfo);
     181                return;
     182            }
     183            byte ip[] = new byte[ipSize];
    167184            testInfo.readIP(ip, 0);
    168185            try {
     
    178195            } catch (UnknownHostException uhe) {
    179196                if (_log.shouldLog(Log.ERROR))
    180                     _log.error("Unable to get our IP (length " + ip.length +
     197                    _log.error("Unable to get our IP (length " + ipSize +
    181198                               ") from bob's reply: " + from + ", " + testInfo, uhe);
    182199            }
    183200        } else {
     201            // The reply is from Charlie
     202
    184203            PeerState charlieSession = _transport.getPeerState(from);
    185204            long recentBegin = _context.clock().now() - CHARLIE_RECENT_PERIOD;
  • router/java/src/net/i2p/router/transport/udp/UDPEndpoint.java

    r6019cf81 rb4615ed  
    8383   
    8484    /** 8998 is monotone, and 32000 is the wrapper, so let's stay between those */
     85    public static final String PROP_MIN_PORT = "i2np.udp.minPort";
     86    public static final String PROP_MAX_PORT = "i2np.udp.maxPort";
    8587    private static final int MIN_RANDOM_PORT = 9111;
    8688    private static final int MAX_RANDOM_PORT = 31777;
     
    101103                 // try random ports rather than just do new DatagramSocket()
    102104                 // so we stay out of the way of other I2P stuff
    103                  port = MIN_RANDOM_PORT + _context.random().nextInt(MAX_RANDOM_PORT - MIN_RANDOM_PORT);
     105                 int minPort = _context.getProperty(PROP_MIN_PORT, MIN_RANDOM_PORT);
     106                 int maxPort = _context.getProperty(PROP_MAX_PORT, MAX_RANDOM_PORT);
     107                 port = minPort + _context.random().nextInt(maxPort - minPort);
    104108             }
    105109             try {
Note: See TracChangeset for help on using the changeset viewer.