Changeset 171f0d2
- Timestamp:
- Jul 17, 2013 9:13:19 PM (8 years ago)
- Branches:
- master
- Children:
- 1e2fb4b
- Parents:
- 8937c4b
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java
r8937c4b r171f0d2 52 52 private int _maxConns; 53 53 private boolean _disableRejectLog; 54 54 private double _alpha; 55 private double _beta; 56 private double _kappa; 57 58 /** state of a connection */ 59 enum AckInit { 60 INIT, // just created 61 FIRST, // first received ack 62 STEADY 63 } 64 65 /** LOCKING: this */ 66 private AckInit _initState = AckInit.INIT; 67 55 68 // NOTE - almost all the options are below, but see 56 69 // I2PSocketOptions in ministreaming for a few more … … 66 79 public static final int INACTIVITY_ACTION_SEND = 2; 67 80 81 /* 82 * These values are specified in RFC 6298 83 * Do not change unless you know what you're doing 84 */ 85 private static final double TCP_ALPHA = 1.0/8; 86 private static final double TCP_BETA = 1.0/4; 87 private static final double TCP_KAPPA = 4; 88 private static final String PROP_TCP_ALPHA= "i2p.streaming.alpha"; 89 private static final String PROP_TCP_BETA= "i2p.streaming.beta"; 90 private static final String PROP_TCP_KAPPA = "i2p.streaming.kappa"; 91 92 private static final String PROP_INITIAL_RTO = "i2p.streaming.initialRTO"; 93 private static final int INITIAL_RTO = 12000; 94 68 95 public static final String PROP_CONNECT_DELAY = "i2p.streaming.connectDelay"; 69 96 public static final String PROP_PROFILE = "i2p.streaming.profile"; 70 97 public static final String PROP_MAX_MESSAGE_SIZE = "i2p.streaming.maxMessageSize"; 71 98 public static final String PROP_MAX_RESENDS = "i2p.streaming.maxResends"; 72 public static final String PROP_INITIAL_RTT = "i2p.streaming.initialRTT";73 99 public static final String PROP_INITIAL_RESEND_DELAY = "i2p.streaming.initialResendDelay"; 74 100 public static final String PROP_INITIAL_ACK_DELAY = "i2p.streaming.initialAckDelay"; … … 296 322 setConnectDelay(opts.getConnectDelay()); 297 323 setProfile(opts.getProfile()); 324 setRTTDev(opts.getRTTDev()); 298 325 setRTT(opts.getRTT()); 299 326 setRequireFullySigned(opts.getRequireFullySigned()); … … 333 360 setProfile(getInt(opts, PROP_PROFILE, PROFILE_BULK)); 334 361 setMaxMessageSize(getInt(opts, PROP_MAX_MESSAGE_SIZE, DEFAULT_MAX_MESSAGE_SIZE)); 335 setRTT(getInt(opts, PROP_INITIAL_RTT, DEFAULT_INITIAL_RTT));336 362 setReceiveWindow(getInt(opts, PROP_INITIAL_RECEIVE_WINDOW, 1)); 337 363 setResendDelay(getInt(opts, PROP_INITIAL_RESEND_DELAY, 1000)); … … 361 387 _maxTotalConnsPerDay = getInt(opts, PROP_MAX_TOTAL_CONNS_DAY, 0); 362 388 _maxConns = getInt(opts, PROP_MAX_STREAMS, 0); 389 390 _alpha = getDouble(opts, PROP_TCP_ALPHA, TCP_ALPHA); 391 _beta = getDouble(opts, PROP_TCP_BETA, TCP_BETA); 392 _kappa = getDouble(opts, PROP_TCP_KAPPA, TCP_KAPPA); 393 394 _rto = getInt(opts, PROP_INITIAL_RTO, INITIAL_RTO); 363 395 } 364 396 … … 378 410 if (opts.containsKey(PROP_MAX_MESSAGE_SIZE)) 379 411 setMaxMessageSize(getInt(opts, PROP_MAX_MESSAGE_SIZE, Packet.MAX_PAYLOAD_SIZE)); 380 if (opts.containsKey(PROP_INITIAL_RTT))381 setRTT(getInt(opts, PROP_INITIAL_RTT, DEFAULT_INITIAL_RTT));382 412 if (opts.containsKey(PROP_INITIAL_RECEIVE_WINDOW)) 383 413 setReceiveWindow(getInt(opts, PROP_INITIAL_RECEIVE_WINDOW, 1)); … … 428 458 if (opts.containsKey(PROP_MAX_STREAMS)) 429 459 _maxConns = getInt(opts, PROP_MAX_STREAMS, 0); 460 461 _alpha = getDouble(opts, PROP_TCP_ALPHA, TCP_ALPHA); 462 _beta = getDouble(opts, PROP_TCP_BETA, TCP_BETA); 463 _kappa = getDouble(opts, PROP_TCP_KAPPA, TCP_KAPPA); 464 _rto = getInt(opts, PROP_INITIAL_RTO, INITIAL_RTO); 430 465 } 431 466 … … 518 553 public int getRTT() { return _rtt; } 519 554 public void setRTT(int ms) { 520 if (_rto == 0) { // TODO: move this out521 _rttDev = ms / 2;522 _rto = ms + ms / 2;523 }524 555 synchronized (_trend) { 525 556 _trend[0] = _trend[1]; … … 545 576 void setRTTDev(int rttDev) { _rttDev = rttDev; } 546 577 578 /** 579 * mark these options as loaded from cache. 580 * affects the calculation of RTO 581 */ 582 synchronized void loadedFromCache() { 583 _initState = AckInit.STEADY; 584 } 585 586 /** 587 * computes RTO based on formula in RFC 588 */ 589 synchronized void computeRTO() { 590 switch(_initState) { 591 case INIT : 592 throw new IllegalStateException(); 593 case FIRST : 594 _rttDev = _rtt / 2; 595 _rto = _rtt + _rtt / 2; 596 break; 597 case STEADY : 598 _rto = _rtt + (int) (_rttDev * _kappa); 599 break; 600 } 601 602 if (_rto < Connection.MIN_RESEND_DELAY) 603 _rto = (int)Connection.MIN_RESEND_DELAY; 604 else if (_rto > Connection.MAX_RESEND_DELAY) 605 _rto = (int)Connection.MAX_RESEND_DELAY; 606 } 607 547 608 /** 548 609 * If we have 3 consecutive rtt increases, we are trending upwards (1), or if we have … … 561 622 } 562 623 563 /** rtt = rtt*RTT_DAMPENING + (1-RTT_DAMPENING)*currentPacketRTT */ 564 /** This is the value specified in RFC 2988, let's try it */ 565 private static final double RTT_DAMPENING = 0.875; 566 567 public void updateRTT(int measuredValue) { 568 // the rttDev calculation matches that recommended in RFC 2988 (beta = 1/4) 569 _rttDev = _rttDev + (int)(0.25d*(Math.abs(measuredValue-_rtt)-_rttDev)); 570 int smoothed = (int)(RTT_DAMPENING*_rtt + (1-RTT_DAMPENING)*measuredValue); 571 // K = 4 572 _rto = smoothed + (_rttDev<<2); 573 if (_rto < Connection.MIN_RESEND_DELAY) 574 _rto = (int)Connection.MIN_RESEND_DELAY; 575 else if (_rto > Connection.MAX_RESEND_DELAY) 576 _rto = (int)Connection.MAX_RESEND_DELAY; 577 578 setRTT(smoothed); 624 public synchronized void updateRTT(int measuredValue) { 625 switch(_initState) { 626 case INIT: 627 _initState = AckInit.FIRST; 628 setRTT(measuredValue); // no smoothing first sample 629 break; 630 case FIRST: 631 _initState = AckInit.STEADY; 632 case STEADY: 633 // calculation matches that recommended in RFC 6298 634 _rttDev = (int) ((1-_beta) *_rttDev + _beta * Math.abs(measuredValue-_rtt)); 635 int smoothed = (int)((1-_alpha)*_rtt + _alpha*measuredValue); 636 setRTT(smoothed); 637 } 638 computeRTO(); 579 639 } 580 640 -
apps/streaming/java/src/net/i2p/client/streaming/TCBShare.java
r8937c4b r171f0d2 100 100 " wdw: " + wdw ); 101 101 } 102 opts.loadedFromCache(); 102 103 opts.setRTT(rtt); 103 104 opts.setRTTDev(rttDev); 104 105 opts.setWindowSize(wdw); 106 opts.computeRTO(); 105 107 } 106 108 -
router/java/src/net/i2p/router/RouterVersion.java
r8937c4b r171f0d2 22 22 23 23 /** for example "-test" */ 24 public final static String EXTRA = " ";24 public final static String EXTRA = "-979"; 25 25 public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA; 26 26 public static void main(String args[]) {
Note: See TracChangeset
for help on using the changeset viewer.