Changeset cf1c0cb3 for router


Ignore:
Timestamp:
Feb 26, 2019 5:17:00 PM (17 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c8b7e82
Parents:
566df1c
Message:

SSU: Fix RTT/RTO calculations (ticket #2443)

Location:
router/java/src/net/i2p/router/transport/udp
Files:
6 edited

Legend:

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

    r566df1c rcf1c0cb3  
    6363    public synchronized void shutdown() {
    6464        _alive = false;
    65         PeerState poison = new PeerState(_context, _transport, new byte[4], 0, null, false);
     65        PeerState poison = new PeerState(_context, _transport, new byte[4], 0, null, false, 0);
    6666        poison.setTheyRelayToUsAs(POISON_PS);
    6767        _peersToACK.offer(poison);
  • router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java

    r566df1c rcf1c0cb3  
    695695        RouterIdentity remote = state.getConfirmedIdentity();
    696696        PeerState peer = new PeerState(_context, _transport,
    697                                        state.getSentIP(), state.getSentPort(), remote.calculateHash(), true);
     697                                       state.getSentIP(), state.getSentPort(), remote.calculateHash(), true, state.getRTT());
    698698        peer.setCurrentCipherKey(state.getCipherKey());
    699699        peer.setCurrentMACKey(state.getMACKey());
     
    814814        _outboundByHash.remove(remote.calculateHash(), state);
    815815        PeerState peer = new PeerState(_context, _transport,
    816                                        state.getSentIP(), state.getSentPort(), remote.calculateHash(), false);
     816                                       state.getSentIP(), state.getSentPort(), remote.calculateHash(), false, state.getRTT());
    817817        peer.setCurrentCipherKey(state.getCipherKey());
    818818        peer.setCurrentMACKey(state.getMACKey());
  • router/java/src/net/i2p/router/transport/udp/InboundEstablishState.java

    r566df1c rcf1c0cb3  
    6565    // default true
    6666    private boolean _introductionRequested = true;
     67
     68    private int _rtt;
    6769   
    6870    public enum InboundState {
     
    297299    public synchronized long getNextSendTime() { return _nextSend; }
    298300
     301    synchronized int getRTT() { return _rtt; }
     302
    299303    /** RemoteHostId, uniquely identifies an attempt */
    300304    RemoteHostId getRemoteHostId() { return _remoteHostId; }
     
    357361        }
    358362       
     363        if (_createdSentCount == 1) {
     364            _rtt = (int) ( _context.clock().now() - _lastSend );
     365        }       
     366
    359367        packetReceived();
    360368    }
  • router/java/src/net/i2p/router/transport/udp/OutboundEstablishState.java

    r566df1c rcf1c0cb3  
    7575    private long _requestSentTime;
    7676    private long _introSentTime;
     77    private int _rtt;
    7778   
    7879    public enum OutboundState {
     
    180181     */
    181182    public boolean needIntroduction() { return _needIntroduction; }
     183
     184    synchronized int getRTT() { return _rtt; }
    182185   
    183186    /**
     
    305308            _currentState == OutboundState.OB_STATE_PENDING_INTRO)
    306309            _currentState = OutboundState.OB_STATE_CREATED_RECEIVED;
     310
     311        if (_requestSentCount == 1) {
     312            _rtt = (int) (_context.clock().now() - _requestSentTime);
     313        }
    307314        packetReceived();
    308315    }
  • router/java/src/net/i2p/router/transport/udp/PeerState.java

    r566df1c rcf1c0cb3  
    315315    public static final int MAX_MTU = Math.max(LARGE_MTU, MAX_IPV6_MTU);
    316316   
    317     private static final int MIN_RTO = 100 + ACKSender.ACK_FREQUENCY;
    318     private static final int INIT_RTO = 3*1000;
    319     public static final int INIT_RTT = INIT_RTO / 2;
    320     private static final int MAX_RTO = 15*1000;
     317    private static final int MIN_RTO = 1000;
     318    private static final int INIT_RTO = 1000;
     319    private static final int INIT_RTT = 0;
     320    private static final int MAX_RTO = 60*1000;
    321321    private static final int CLOCK_SKEW_FUDGE = (ACKSender.ACK_FREQUENCY * 2) / 3;
    322322   
     
    337337
    338338   
     339    /**
     340     *  @param rtt from the EstablishState, or 0 if not available
     341     */
    339342    public PeerState(RouterContext ctx, UDPTransport transport,
    340                      byte[] remoteIP, int remotePort, Hash remotePeer, boolean isInbound) {
     343                     byte[] remoteIP, int remotePort, Hash remotePeer, boolean isInbound, int rtt) {
    341344        _context = ctx;
    342345        _log = ctx.logManager().getLog(PeerState.class);
     
    367370        //_mtuLastChecked = -1;
    368371        _lastACKSend = -1;
     372
    369373        _rto = INIT_RTO;
    370374        _rtt = INIT_RTT;
    371         _rttDeviation = _rtt;
     375        if (rtt > 0) 
     376            recalculateTimeouts(rtt);
     377        else
     378            _rttDeviation = _rtt;
     379           
    372380        _inboundMessages = new HashMap<Long, InboundMessageState>(8);
    373381        _outboundMessages = new CachedIteratorCollection<OutboundMessageState>();
     
    12271235     */
    12281236    private void recalculateTimeouts(long lifetime) {
    1229         // the rttDev calculation matches that recommended in RFC 2988 (beta = 1/4)
    1230         _rttDeviation = _rttDeviation + (int)(0.25d*(Math.abs(lifetime-_rtt)-_rttDeviation));
     1237        if (_rtt <= 0) {
     1238            // first measurement
     1239            _rtt = (int) lifetime;
     1240            _rttDeviation = (int)(lifetime / 2);
     1241        } else {
     1242            // the rttDev calculation matches that recommended in RFC 2988 (beta = 1/4)
     1243            _rttDeviation = (int)( 0.75*_rttDeviation + 0.25*Math.abs(lifetime-_rtt) );
    12311244       
    1232         float scale = RTT_DAMPENING;
    1233         // the faster we are going, the slower we want to reduce the rtt
    1234         //if (_sendBps > 0)
    1235         //    scale = lifetime / ((float)lifetime + (float)_sendBps);
    1236         //if (scale < 0.001f) scale = 0.001f;
     1245            float scale = RTT_DAMPENING;
    12371246       
    1238         _rtt = (int)(_rtt*(1.0f-scale) + (scale)*lifetime);
     1247            _rtt = (int)(_rtt*(1.0f-scale) + (scale)*lifetime);
     1248        }
    12391249        // K = 4
    12401250        _rto = Math.min(MAX_RTO, Math.max(minRTO(), _rtt + (_rttDeviation<<2)));
     
    18221832                              + " for message " + state.getMessageId() + ": " + state);
    18231833
    1824                 if (state.getPushCount() > 0)
     1834                int rto = getRTO();
     1835                if (state.getPushCount() > 0) {
    18251836                    _retransmitter = state;
     1837                    rto = Math.min(MAX_RTO, rto << state.getPushCount()); // Section 5.5 RFC 6298
     1838                }
    18261839
    18271840                if (state.push())
    18281841                    _messagesSent++;
    18291842           
    1830                 int rto = getRTO();
    18311843                state.setNextSendTime(now + rto);
    18321844
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    r566df1c rcf1c0cb3  
    27242724            if ((!includeEverybody) && now - peer.getLastReceiveTime() > 5*60*1000)
    27252725                continue; // skip old peers
    2726             if (peer.getRTT() > PeerState.INIT_RTT - 250)
     2726            if (peer.getRTT() > 1250)
    27272727                continue; // Big RTT makes for a poor calculation
    27282728            skews.addElement(Long.valueOf(peer.getClockSkew() / 1000));
Note: See TracChangeset for help on using the changeset viewer.