Changeset c70e372


Ignore:
Timestamp:
Aug 11, 2012 11:27:28 AM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
f6c7691
Parents:
a6a0228
Message:
  • SSU MTU (ticket #682):
    • Use local MTU detection
    • i2np.udp.mtu now sets max MTU, not initial MTU
    • Put local MTU in netDb
    • Fix receive MTU calculations
    • Track remote MTU based on actual received packet size
    • Display local MTU on peers page
Location:
router/java/src/net/i2p/router/transport/udp
Files:
6 edited

Legend:

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

    ra6a0228 rc70e372  
    147147        InetAddress remAddr = addr.getHostAddress();
    148148        int port = addr.getPort();
    149         if ( (remAddr != null) && (port > 0) ) {
     149        if (remAddr != null && port > 0 && port <= 65535) {
    150150            to = new RemoteHostId(remAddr.getAddress(), port);
    151151
  • router/java/src/net/i2p/router/transport/udp/PeerState.java

    ra6a0228 rc70e372  
    153153     */
    154154    private long _theyRelayToUsAs;
    155     /** what is the largest packet we can send to the peer? */
     155    /** what is the largest packet we can currently send to the peer? */
    156156    private int _mtu;
    157157    private int _mtuReceive;
     158    /** what is the largest packet we will ever send to the peer? */
     159    private final int _largeMTU;
    158160    /* how many consecutive packets at or under the min MTU have been received */
    159161    private long _consecutiveSmall;
     
    260262    private static final int MIN_RTO = 100 + ACKSender.ACK_FREQUENCY;
    261263    private static final int MAX_RTO = 3000; // 5000;
    262     /** override the default MTU */
    263     private static final String PROP_DEFAULT_MTU = "i2np.udp.mtu";
    264264   
    265265    public PeerState(RouterContext ctx, UDPTransport transport,
     
    282282        _lastCongestionOccurred = -1;
    283283        _remotePort = remotePort;
    284         _mtu = getDefaultMTU();
     284        _mtu = DEFAULT_MTU;
    285285        _mtuReceive = _mtu;
     286        _largeMTU = transport.getMTU();
    286287        //_mtuLastChecked = -1;
    287288        _lastACKSend = -1;
     
    296297        _isInbound = isInbound;
    297298        _remoteHostId = new RemoteHostId(remoteIP, remotePort);
    298     }
    299    
    300     private int getDefaultMTU() {
    301         return _context.getProperty(PROP_DEFAULT_MTU, DEFAULT_MTU);
    302299    }
    303300   
     
    10261023            retransPct = (double)_packetsRetransmitted/(double)_packetsTransmitted;
    10271024            boolean wantLarge = retransPct < .30d; // heuristic to allow fairly lossy links to use large MTUs
    1028             if (wantLarge && _mtu != LARGE_MTU) {
     1025            if (wantLarge && _mtu != _largeMTU) {
    10291026                if (_context.random().nextLong(_mtuDecreases) <= 0) {
    1030                     _mtu = LARGE_MTU;
     1027                    _mtu = _largeMTU;
    10311028                    _mtuIncreases++;
    10321029                    _context.statManager().addRateData("udp.mtuIncrease", _mtuIncreases, _mtuDecreases);
    10331030                }
    1034             } else if (!wantLarge && _mtu == LARGE_MTU) {
     1031            } else if (!wantLarge && _mtu == _largeMTU) {
    10351032                _mtu = MIN_MTU;
    10361033                _mtuDecreases++;
     
    10611058        //_rto *= 2;
    10621059    }
     1060
    10631061    public void packetsTransmitted(int packets) {
    10641062        //long now = _context.clock().now();
     
    10741072        *****/
    10751073    }
     1074
    10761075    /** how long does it usually take to get a message ACKed? */
    10771076    public int getRTT() { return _rtt; }
     
    10931092
    10941093    private static final int MTU_RCV_DISPLAY_THRESHOLD = 20;
    1095 
     1094    /** 60 */
     1095    private static final int OVERHEAD_SIZE = PacketBuilder.IP_HEADER_SIZE + PacketBuilder.UDP_HEADER_SIZE +
     1096                                             UDPPacket.MAC_SIZE + UDPPacket.IV_SIZE;
     1097
     1098    /**
     1099     *  @param size not including IP header, UDP header, MAC or IV
     1100     */
    10961101    public void packetReceived(int size) {
    10971102        _packetsReceived++;
     1103        size += OVERHEAD_SIZE;
    10981104        if (size <= MIN_MTU) {
    10991105            _consecutiveSmall++;
     1106            if (_consecutiveSmall >= MTU_RCV_DISPLAY_THRESHOLD)
     1107                _mtuReceive = MIN_MTU;
    11001108        } else {
    11011109            _consecutiveSmall = 0;
    1102             _mtuReceive = LARGE_MTU;
    1103             return;
    1104         }
    1105        
    1106         if (_packetsReceived > MTU_RCV_DISPLAY_THRESHOLD) {
    1107             if (_consecutiveSmall < MTU_RCV_DISPLAY_THRESHOLD)
    1108                 _mtuReceive = LARGE_MTU;
    1109             else
    1110                 _mtuReceive = MIN_MTU;
    1111         }
     1110            if (size > _mtuReceive)
     1111                _mtuReceive = size;
     1112        }
    11121113    }
    11131114   
  • router/java/src/net/i2p/router/transport/udp/UDPAddress.java

    ra6a0228 rc70e372  
    2222    private byte[] _introKeys[];
    2323    private long _introTags[];
     24    private int _mtu;
    2425   
    2526    public static final String PROP_PORT = "port";
    2627    public static final String PROP_HOST = "host";
    2728    public static final String PROP_INTRO_KEY = "key";
     29    public static final String PROP_MTU = "mtu";
    2830   
    2931    public static final String PROP_CAPACITY = "caps";
     
    7375            _port = -1;
    7476        }
     77        try {
     78            String mtu = addr.getOption(PROP_MTU);
     79            if (mtu != null)
     80                _mtu = MTU.rectify(Integer.parseInt(mtu));
     81        } catch (NumberFormatException nfe) {}
    7582        String key = addr.getOption(PROP_INTRO_KEY);
    7683        if (key != null)
     
    9299            try {
    93100                p = Integer.parseInt(port);
    94                 if (p <= 0) continue;
     101                if (p <= 0 || p > 65535) continue;
    95102            } catch (NumberFormatException nfe) {
    96103                continue;
     
    162169        return _hostAddress;
    163170    }
     171
     172    /**
     173     *  @return 0 if unset; -1 if invalid
     174     */
    164175    public int getPort() { return _port; }
     176
    165177    byte[] getIntroKey() { return _introKey; }
    166178   
     
    180192    long getIntroducerTag(int i) { return _introTags[i]; }
    181193       
     194    /**
     195     *  @return 0 if unset or invalid; recitified via MTU.rectify()
     196     *  @since 0.9.2
     197     */
     198    int getMTU() {
     199        return _introPorts[i];
     200    }
    182201}
  • router/java/src/net/i2p/router/transport/udp/UDPEndpoint.java

    ra6a0228 rc70e372  
    155155        return _receiver.receiveNext();
    156156    }
    157    
    158     /**
    159      * The MTU for the socket interface, if available.
    160      * Not available for Java 5.
    161      * @return 0 if Java 5, or if bound to an address;
    162      *         limited to range MIN_MTU to LARGE_MTU.
    163      * @since 0.9.2
    164      */
    165     public int getMTU() {
    166         return MTU.getMTU(_bindAddress);
    167     }
    168157}
  • router/java/src/net/i2p/router/transport/udp/UDPPacketReader.java

    ra6a0228 rc70e372  
    258258    /** parse out the data message */
    259259    public class DataReader {
     260
     261        /**
     262         *  @return the data size, NOT including IP header, UDP header, IV, or MAC
     263         */
    260264        public int getPacketSize() { return _payloadLength; }
     265
    261266        public boolean readACKsIncluded() {
    262267            return flagSet(UDPPacket.DATA_FLAG_EXPLICIT_ACK);
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    ra6a0228 rc70e372  
    7272    private long _lastInboundReceivedOn;
    7373    private final DHSessionKeyBuilder.Factory _dhFactory;
     74    private int _mtu;
    7475   
    7576    /** do we need to rebuild our external router address asap? */
     
    142143    /** this is rarely if ever used, default is to bind to wildcard address */
    143144    public static final String PROP_BIND_INTERFACE = "i2np.udp.bindInterface";
     145    /** override the "large" (max) MTU, default is PeerState.LARGE_MTU */
     146    private static final String PROP_DEFAULT_MTU = "i2np.udp.mtu";
    144147       
    145148    /** how many relays offered to us will we use at a time? */
     
    214217        _introducersSelectedOn = -1;
    215218        _lastInboundReceivedOn = -1;
     219        _mtu = PeerState.LARGE_MTU;
    216220        _needsRebuild = true;
    217221       
     
    308312            _endpoint.setListenPort(port);
    309313        }
     314        setMTU(bindToAddr);
    310315       
    311316        if (_establisher == null)
     
    402407            return _externalListenPort;
    403408        return _context.getProperty(PROP_INTERNAL_PORT, -1);
     409    }
     410
     411    /**
     412     *  Set the MTU for the socket interface at addr.
     413     *  @param addr null ok
     414     *  @since 0.9.2
     415     */
     416    private void setMTU(InetAddress addr) {
     417        String p = _context.getProperty(PROP_DEFAULT_MTU);
     418        if (p != null) {
     419            try {
     420                _mtu = MTU.rectify(Integer.parseInt(p));
     421                return;
     422            } catch (NumberFormatException nfe) {}
     423        }
     424        int mtu = MTU.getMTU(addr);
     425        if (mtu <= 0)
     426            mtu = PeerState.LARGE_MTU;
     427        _mtu = mtu;
     428    }
     429
     430    /**
     431     * The MTU for the socket interface.
     432     * To be used as the "large" MTU.
     433     * @return limited to range PeerState.MIN_MTU to PeerState.LARGE_MTU.
     434     * @since 0.9.2
     435     */
     436    public int getMTU() {
     437        return _mtu;
    404438    }
    405439
     
    13311365        else
    13321366            options.setProperty(UDPAddress.PROP_CAPACITY, ""+UDPAddress.CAPACITY_TESTING + UDPAddress.CAPACITY_INTRODUCER);
     1367
     1368        // MTU since 0.9.2
     1369        if (_mtu < PeerState.LARGE_MTU)
     1370            options.setProperty(UDPAddress.PROP_MTU, Integer.toString(_mtu));
    13331371
    13341372        if (directIncluded || introducersIncluded) {
     
    21722210       
    21732211//        buf.append("<tr><td colspan=\"16\"><hr></td></tr>\n");
    2174         buf.append("<tr class=\"tablefooter\"> <td colspan=\"3\" align=\"left\"><b>").append(_("SUMMARY")).append("</b></td>" +
     2212        buf.append("<tr class=\"tablefooter\"><td colspan=\"3\" align=\"left\"><b>").append(_("SUMMARY")).append("</b></td>" +
    21752213                   "<td align=\"center\" nowrap><b>");
    21762214        buf.append(formatKBps(bpsIn)).append(THINSP).append(formatKBps(bpsOut));
     
    21852223                   "<td align=\"center\"><b>");
    21862224        buf.append(numPeers > 0 ? DataHelper.formatDuration2(rttTotal/numPeers) : '0');
    2187         buf.append("</b></td><td>&nbsp;</td> <td align=\"center\"><b>");
     2225        buf.append("</b></td><td>&nbsp;</td><td align=\"center\"><b>");
    21882226        buf.append(numPeers > 0 ? DataHelper.formatDuration2(rtoTotal/numPeers) : '0');
    2189         buf.append("</b></td><td>&nbsp;</td> <td align=\"center\"><b>");
    2190         buf.append(sendTotal).append("</b></td> <td align=\"center\"><b>").append(recvTotal).append("</b></td>\n" +
     2227        buf.append("</b></td><td align=\"center\"><b>").append(_mtu).append("</b></td><td align=\"center\"><b>");
     2228        buf.append(sendTotal).append("</b></td><td align=\"center\"><b>").append(recvTotal).append("</b></td>\n" +
    21912229                   "<td align=\"center\"><b>").append(resentTotal);
    21922230        buf.append("</b></td><td align=\"center\"><b>").append(dupRecvTotal).append("</b></td>\n" +
Note: See TracChangeset for help on using the changeset viewer.