Changeset 89d32e3


Ignore:
Timestamp:
Jul 24, 2011 3:15:19 PM (10 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
734444e1
Parents:
ec061eb
Message:
  • UDP:
    • Revert change in UDPPacket that caused massive corruption
    • Reduce buffer sizes from 2048 to 1536
    • Discard too-large received packets sooner
    • More cleanups
    • Notes on MTU
Location:
router/java/src/net/i2p/router/transport/udp
Files:
5 edited

Legend:

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

    rec061eb r89d32e3  
    3434    public static final int MAX_FRAGMENTS = 64;
    3535   
    36     private static final ByteCache _fragmentCache = ByteCache.getInstance(64, 2048);
     36    private static final int MAX_FRAGMENT_SIZE = UDPPacket.MAX_PACKET_SIZE;
     37    private static final ByteCache _fragmentCache = ByteCache.getInstance(64, MAX_FRAGMENT_SIZE);
    3738   
    3839    public InboundMessageState(RouterContext ctx, long messageId, Hash from) {
  • router/java/src/net/i2p/router/transport/udp/PeerState.java

    rec061eb r89d32e3  
    158158    private long _consecutiveSmall;
    159159    /** when did we last check the MTU? */
    160     private long _mtuLastChecked;
     160    //private long _mtuLastChecked;
    161161    private long _mtuIncreases;
    162162    private long _mtuDecreases;
     
    225225     *
    226226     * Well, we really need to count the acks as well, especially
    227      * 4 * MAX_RESEND_ACKS which can take up a significant amount of space.
     227     * 1 + (4 * MAX_RESEND_ACKS_SMALL) which can take up a significant amount of space.
    228228     * We reduce the max acks when using the small MTU but it may not be enough...
    229229     *
     
    235235     * (larger I2NP messages may be up to 1900B-4500B, which isn't going to fit
    236236     * into a live network MTU anyway)
     237     *
     238     * TODO
     239     * VTBM is 2646, it would be nice to fit in two large
     240     * 2646 / 2 = 1323
     241     * 1323 + 74 + 46 + 1 + (4 * 9) = 1480
     242     * So why not make it 1492 (old ethernet is 1492, new is 1500)
    237243     */
    238244    private static final int LARGE_MTU = 1350;
     
    262268        _mtu = getDefaultMTU();
    263269        _mtuReceive = _mtu;
    264         _mtuLastChecked = -1;
     270        //_mtuLastChecked = -1;
    265271        _lastACKSend = -1;
    266272        _rto = MIN_RTO;
     
    371377    /** what is the largest packet we can send to the peer? */
    372378    public int getMTU() { return _mtu; }
    373     /** estimate how large the other side is sending packets */
     379
     380    /**
     381     *  Estimate how large the other side's MTU is.
     382     *  This could be wrong.
     383     *  It is used only for the HTML status.
     384     */
    374385    public int getReceiveMTU() { return _mtuReceive; }
     386
    375387    /** when did we last check the MTU? */
     388  /****
    376389    public long getMTULastChecked() { return _mtuLastChecked; }
    377390    public long getMTUIncreases() { return _mtuIncreases; }
    378391    public long getMTUDecreases() { return _mtuDecreases; }
    379    
     392  ****/
    380393   
    381394    /**
     
    538551     */
    539552    public void setTheyRelayToUsAs(long tag) { _theyRelayToUsAs = tag; }
     553
    540554    /** what is the largest packet we can send to the peer? */
     555  /****
    541556    public void setMTU(int mtu) {
    542557        _mtu = mtu;
    543558        _mtuLastChecked = _context.clock().now();
    544559    }
     560  ****/
     561
    545562    public int getSlowStartThreshold() { return _slowStartThreshold; }
    546563    public int getConcurrentSends() { return _concurrentMessagesActive; }
     
    980997    public long getPacketsReceived() { return _packetsReceived; }
    981998    public long getPacketsReceivedDuplicate() { return _packetsReceivedDuplicate; }
     999
     1000    private static final int MTU_RCV_DISPLAY_THRESHOLD = 20;
     1001
    9821002    public void packetReceived(int size) {
    9831003        _packetsReceived++;
    984         if (size <= MIN_MTU)
     1004        if (size <= MIN_MTU) {
    9851005            _consecutiveSmall++;
    986         else
     1006        } else {
    9871007            _consecutiveSmall = 0;
    988        
    989         if (_packetsReceived > 50) {
    990             if (_consecutiveSmall < 50)
     1008            _mtuReceive = LARGE_MTU;
     1009            return;
     1010        }
     1011       
     1012        if (_packetsReceived > MTU_RCV_DISPLAY_THRESHOLD) {
     1013            if (_consecutiveSmall < MTU_RCV_DISPLAY_THRESHOLD)
    9911014                _mtuReceive = LARGE_MTU;
    9921015            else
     
    12881311    static final int UDP_HEADER_SIZE = 8;
    12891312    static final int IP_HEADER_SIZE = 20;
    1290     /** how much payload data can we shove in there? */
     1313
     1314    /**
     1315     *  how much payload data can we shove in there?
     1316     *  @return MTU - 74
     1317     */
    12911318    private static final int fragmentSize(int mtu) {
    12921319        return mtu - SSU_HEADER_SIZE - UDP_HEADER_SIZE - IP_HEADER_SIZE;
     
    12971324        if (state.getNextSendTime() <= now) {
    12981325            if (!state.isFragmented()) {
    1299                 state.fragment(fragmentSize(getMTU()));
     1326                state.fragment(fragmentSize(_mtu));
    13001327                if (state.getMessage() != null)
    13011328                    state.getMessage().timestamp("fragment into " + state.getFragmentCount());
  • router/java/src/net/i2p/router/transport/udp/UDPPacket.java

    rec061eb r89d32e3  
    5252    }
    5353   
    54     static final int MAX_PACKET_SIZE = 2048;
     54    /**
     55     *  Actually it is one less than this, we assume
     56     *  if a received packet is this big it is truncated.
     57     *  This is bigger than PeerState.LARGE_MTU, as the far-end's
     58     *  LARGE_MTU may be larger than ours.
     59     */
     60    static final int MAX_PACKET_SIZE = 1536;
    5561    public static final int IV_SIZE = 16;
    5662    public static final int MAC_SIZE = 16;
     
    97103        Arrays.fill(_data, (byte)0);
    98104        //_packet = new DatagramPacket(_data, MAX_PACKET_SIZE);
    99         //_packet.setData(_data);
     105        //
     106        // WARNING -
     107        // Doesn't seem like we should have to do this every time,
     108        // from reading the DatagramPacket javadocs,
     109        // but we get massive corruption without it.
     110        _packet.setData(_data);
    100111        // _isInbound = inbound;
    101112        _initializeTime = _context.clock().now();
  • router/java/src/net/i2p/router/transport/udp/UDPPacketReader.java

    rec061eb r89d32e3  
    355355            return ((int)DataHelper.fromLong(_message, off, 2)) & 0x3FFF;
    356356        }
    357         public void readMessageFragment(int fragmentNum, byte target[], int targetOffset) {
     357
     358        public void readMessageFragment(int fragmentNum, byte target[], int targetOffset)
     359                                                      throws ArrayIndexOutOfBoundsException {
    358360            int off = getFragmentBegin(fragmentNum);
    359361            off += 4; // messageId
  • router/java/src/net/i2p/router/transport/udp/UDPReceiver.java

    rec061eb r89d32e3  
    244244                    // and block after we know how much we read but before
    245245                    // we release the packet to the inbound queue
     246                    if (size >= UDPPacket.MAX_PACKET_SIZE) {
     247                        // DatagramSocket javadocs: If the message is longer than the packet's length, the message is truncated.
     248                        throw new IOException("packet too large! truncated and dropped");
     249                    }
    246250                    if (size > 0) {
    247251                        //FIFOBandwidthLimiter.Request req = _context.bandwidthLimiter().requestInbound(size, "UDP receiver");
Note: See TracChangeset for help on using the changeset viewer.