@@ -50,21 +50,25 @@ pub struct RttEstimator {
50
50
}
51
51
52
52
impl Default for RttEstimator {
53
+ /// Creates a new RTT Estimator with default initial values
53
54
fn default ( ) -> Self {
54
- RttEstimator :: new ( Duration :: ZERO )
55
+ RttEstimator :: new ( DEFAULT_INITIAL_RTT )
55
56
}
56
57
}
57
58
58
59
impl RttEstimator {
59
- /// Creates a new RTT Estimator with default initial values using the given `max_ack_delay`.
60
+ /// Creates a new RTT Estimator with the given `initial_rtt`
61
+ ///
62
+ /// `on_max_ack_delay` must be called when the `max_ack_delay` transport
63
+ /// parameter is received to initialize the `max_ack_delay` value.
60
64
#[ inline]
61
- pub fn new ( max_ack_delay : Duration ) -> Self {
62
- Self :: new_with_initial ( max_ack_delay , DEFAULT_INITIAL_RTT )
65
+ pub fn new ( initial_rtt : Duration ) -> Self {
66
+ Self :: new_with_max_ack_delay ( Duration :: ZERO , initial_rtt )
63
67
}
64
68
65
69
/// Creates a new RTT Estimator with the provided initial values using the given `max_ack_delay`.
66
70
#[ inline]
67
- pub fn new_with_initial ( max_ack_delay : Duration , initial_rtt : Duration ) -> Self {
71
+ fn new_with_max_ack_delay ( max_ack_delay : Duration , initial_rtt : Duration ) -> Self {
68
72
debug_assert ! ( initial_rtt >= MIN_RTT ) ;
69
73
let initial_rtt = initial_rtt. max ( MIN_RTT ) ;
70
74
@@ -91,6 +95,11 @@ impl RttEstimator {
91
95
}
92
96
}
93
97
98
+ /// Creates a new RTT Estimator with the `max_ack_delay` from the current instance
99
+ pub fn for_new_path ( & self , initial_rtt : Duration ) -> Self {
100
+ Self :: new_with_max_ack_delay ( self . max_ack_delay , initial_rtt)
101
+ }
102
+
94
103
/// Gets the latest round trip time sample
95
104
#[ inline]
96
105
pub fn latest_rtt ( & self ) -> Duration {
@@ -385,7 +394,8 @@ mod test {
385
394
/// Test the initial values before any RTT samples
386
395
#[ test]
387
396
fn initial_rtt_across_spaces ( ) {
388
- let rtt_estimator = RttEstimator :: new ( Duration :: from_millis ( 10 ) ) ;
397
+ let rtt_estimator =
398
+ RttEstimator :: new_with_max_ack_delay ( Duration :: from_millis ( 10 ) , DEFAULT_INITIAL_RTT ) ;
389
399
assert_eq ! ( rtt_estimator. min_rtt, DEFAULT_INITIAL_RTT ) ;
390
400
assert_eq ! ( rtt_estimator. latest_rtt( ) , DEFAULT_INITIAL_RTT ) ;
391
401
assert_eq ! ( rtt_estimator. smoothed_rtt( ) , DEFAULT_INITIAL_RTT ) ;
@@ -407,7 +417,7 @@ mod test {
407
417
/// Test a zero RTT value is treated as 1 µs
408
418
#[ test]
409
419
fn zero_rtt_sample ( ) {
410
- let mut rtt_estimator = RttEstimator :: new ( Duration :: from_millis ( 10 ) ) ;
420
+ let mut rtt_estimator = RttEstimator :: new ( DEFAULT_INITIAL_RTT ) ;
411
421
let now = NoopClock . get_time ( ) ;
412
422
rtt_estimator. update_rtt (
413
423
Duration :: from_millis ( 10 ) ,
@@ -425,17 +435,26 @@ mod test {
425
435
) ;
426
436
}
427
437
438
+ #[ test]
439
+ fn for_new_path ( ) {
440
+ let mut rtt_estimator = RttEstimator :: default ( ) ;
441
+ let max_ack_delay = Duration :: from_millis ( 10 ) ;
442
+ rtt_estimator. on_max_ack_delay ( max_ack_delay. try_into ( ) . unwrap ( ) ) ;
443
+ let new_path_rtt_estimator = rtt_estimator. for_new_path ( DEFAULT_INITIAL_RTT ) ;
444
+ assert_eq ! ( max_ack_delay, new_path_rtt_estimator. max_ack_delay)
445
+ }
446
+
428
447
//= https://www.rfc-editor.org/rfc/rfc9002#section-5.3
429
448
//= type=test
430
449
//# * MUST use the lesser of the acknowledgement delay and the peer's
431
450
//# max_ack_delay after the handshake is confirmed;
432
451
#[ test]
433
452
fn max_ack_delay ( ) {
434
453
let mut rtt_estimator = RttEstimator :: default ( ) ;
435
- assert_eq ! ( Duration :: ZERO , rtt_estimator. max_ack_delay( ) ) ;
454
+ assert_eq ! ( Duration :: ZERO , rtt_estimator. max_ack_delay) ;
436
455
437
456
rtt_estimator. on_max_ack_delay ( MaxAckDelay :: new ( VarInt :: from_u8 ( 10 ) ) . unwrap ( ) ) ;
438
- assert_eq ! ( Duration :: from_millis( 10 ) , rtt_estimator. max_ack_delay( ) ) ;
457
+ assert_eq ! ( Duration :: from_millis( 10 ) , rtt_estimator. max_ack_delay) ;
439
458
440
459
let now = NoopClock . get_time ( ) ;
441
460
rtt_estimator. update_rtt (
@@ -495,7 +514,8 @@ mod test {
495
514
/// Test several rounds of RTT updates
496
515
#[ test]
497
516
fn update_rtt ( ) {
498
- let mut rtt_estimator = RttEstimator :: new ( Duration :: from_millis ( 10 ) ) ;
517
+ let mut rtt_estimator =
518
+ RttEstimator :: new_with_max_ack_delay ( Duration :: from_millis ( 10 ) , DEFAULT_INITIAL_RTT ) ;
499
519
let now = NoopClock . get_time ( ) ;
500
520
let rtt_sample = Duration :: from_millis ( 500 ) ;
501
521
assert ! ( rtt_estimator. first_rtt_sample. is_none( ) ) ;
@@ -574,7 +594,8 @@ mod test {
574
594
//# the resulting value is smaller than the min_rtt.
575
595
#[ test]
576
596
fn must_not_subtract_acknowledgement_delay_if_result_smaller_than_min_rtt ( ) {
577
- let mut rtt_estimator = RttEstimator :: new ( Duration :: from_millis ( 200 ) ) ;
597
+ let mut rtt_estimator =
598
+ RttEstimator :: new_with_max_ack_delay ( Duration :: from_millis ( 200 ) , DEFAULT_INITIAL_RTT ) ;
578
599
let now = NoopClock . get_time ( ) ;
579
600
580
601
rtt_estimator. min_rtt = Duration :: from_millis ( 500 ) ;
@@ -606,7 +627,8 @@ mod test {
606
627
//# the min_rtt.
607
628
#[ test]
608
629
fn prior_to_handshake_ignore_if_less_than_min_rtt ( ) {
609
- let mut rtt_estimator = RttEstimator :: new ( Duration :: from_millis ( 200 ) ) ;
630
+ let mut rtt_estimator =
631
+ RttEstimator :: new_with_max_ack_delay ( Duration :: from_millis ( 200 ) , DEFAULT_INITIAL_RTT ) ;
610
632
let now = NoopClock . get_time ( ) ;
611
633
let smoothed_rtt = Duration :: from_millis ( 700 ) ;
612
634
@@ -634,7 +656,8 @@ mod test {
634
656
// of [QUIC-TRANSPORT]);
635
657
#[ test]
636
658
fn initial_space ( ) {
637
- let mut rtt_estimator = RttEstimator :: new ( Duration :: from_millis ( 10 ) ) ;
659
+ let mut rtt_estimator =
660
+ RttEstimator :: new_with_max_ack_delay ( Duration :: from_millis ( 10 ) , DEFAULT_INITIAL_RTT ) ;
638
661
let now = NoopClock . get_time ( ) ;
639
662
let rtt_sample = Duration :: from_millis ( 500 ) ;
640
663
rtt_estimator. update_rtt (
@@ -671,7 +694,8 @@ mod test {
671
694
#[ test]
672
695
fn persistent_congestion_duration ( ) {
673
696
let max_ack_delay = Duration :: from_millis ( 10 ) ;
674
- let mut rtt_estimator = RttEstimator :: new ( max_ack_delay) ;
697
+ let mut rtt_estimator =
698
+ RttEstimator :: new_with_max_ack_delay ( max_ack_delay, DEFAULT_INITIAL_RTT ) ;
675
699
676
700
rtt_estimator. smoothed_rtt = Duration :: from_millis ( 100 ) ;
677
701
rtt_estimator. rttvar = Duration :: from_millis ( 50 ) ;
@@ -703,7 +727,8 @@ mod test {
703
727
704
728
#[ test]
705
729
fn set_min_rtt_to_latest_sample_after_persistent_congestion ( ) {
706
- let mut rtt_estimator = RttEstimator :: new ( Duration :: from_millis ( 10 ) ) ;
730
+ let mut rtt_estimator =
731
+ RttEstimator :: new_with_max_ack_delay ( Duration :: from_millis ( 10 ) , DEFAULT_INITIAL_RTT ) ;
707
732
let now = NoopClock . get_time ( ) ;
708
733
let mut rtt_sample = Duration :: from_millis ( 500 ) ;
709
734
rtt_estimator. update_rtt (
@@ -743,9 +768,8 @@ mod test {
743
768
#[ test]
744
769
fn pto_must_be_at_least_k_granularity ( ) {
745
770
let space = PacketNumberSpace :: Handshake ;
746
- let max_ack_delay = Duration :: from_millis ( 0 ) ;
747
771
let now = NoopClock . get_time ( ) ;
748
- let mut rtt_estimator = RttEstimator :: new ( max_ack_delay ) ;
772
+ let mut rtt_estimator = RttEstimator :: new ( DEFAULT_INITIAL_RTT ) ;
749
773
750
774
// Update RTT with the smallest possible sample
751
775
rtt_estimator. update_rtt (
@@ -795,7 +819,8 @@ mod test {
795
819
//# RTT multiplier, is 9/8.
796
820
#[ test]
797
821
fn time_threshold_multiplier_equals_nine_eighths ( ) {
798
- let mut rtt_estimator = RttEstimator :: new ( Duration :: from_millis ( 10 ) ) ;
822
+ let mut rtt_estimator =
823
+ RttEstimator :: new_with_max_ack_delay ( Duration :: from_millis ( 10 ) , DEFAULT_INITIAL_RTT ) ;
799
824
rtt_estimator. update_rtt (
800
825
Duration :: from_millis ( 10 ) ,
801
826
Duration :: from_secs ( 1 ) ,
0 commit comments