rwebtransport 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/Cargo.lock +153 -226
  2. package/Cargo.toml +5 -5
  3. package/README.md +4 -4
  4. package/crates/echo-server/src/bin/gen-test-cert.rs +1 -1
  5. package/crates/native/Cargo.toml +1 -1
  6. package/crates/native/src/config.rs +13 -1
  7. package/crates/native/src/driver.rs +249 -91
  8. package/crates/native/src/lib.rs +9 -10
  9. package/crates/native/src/parser_memory.rs +1 -0
  10. package/crates/native/src/server.rs +197 -182
  11. package/crates/native/src/session.rs +329 -177
  12. package/crates/native/src/test_support.rs +2 -2
  13. package/crates/wtcore/src/h3.rs +166 -10
  14. package/dist/index.js +92 -45
  15. package/dist/index.js.map +2 -2
  16. package/dist/index.mjs +92 -45
  17. package/dist/index.mjs.map +2 -2
  18. package/dist/native.d.ts +9 -4
  19. package/package.json +14 -11
  20. package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
  21. package/prebuilds/linux-arm64/rwebtransport.node +0 -0
  22. package/prebuilds/linux-x64/rwebtransport.node +0 -0
  23. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  24. package/scripts/build-linux-prebuilt.sh +46 -0
  25. package/scripts/build.js +10 -3
  26. package/vendor/quiche/AGENTS.md +10 -0
  27. package/vendor/quiche/Cargo.lock +239 -248
  28. package/vendor/quiche/Cargo.toml +23 -10
  29. package/vendor/quiche/examples/Makefile +4 -4
  30. package/vendor/quiche/examples/client.rs +10 -28
  31. package/vendor/quiche/examples/http3-client.rs +20 -34
  32. package/vendor/quiche/examples/http3-server.rs +47 -78
  33. package/vendor/quiche/examples/server.rs +19 -49
  34. package/vendor/quiche/include/quiche.h +35 -4
  35. package/vendor/quiche/src/build.rs +17 -0
  36. package/vendor/quiche/src/cid.rs +129 -61
  37. package/vendor/quiche/src/crypto/boringssl.rs +98 -86
  38. package/vendor/quiche/src/crypto/mod.rs +64 -77
  39. package/vendor/quiche/src/dgram.rs +2 -3
  40. package/vendor/quiche/src/error.rs +22 -20
  41. package/vendor/quiche/src/ffi.rs +558 -280
  42. package/vendor/quiche/src/flowcontrol.rs +0 -7
  43. package/vendor/quiche/src/frame.rs +134 -135
  44. package/vendor/quiche/src/h3/ffi.rs +73 -60
  45. package/vendor/quiche/src/h3/frame.rs +70 -90
  46. package/vendor/quiche/src/h3/mod.rs +1024 -593
  47. package/vendor/quiche/src/h3/qpack/decoder.rs +248 -34
  48. package/vendor/quiche/src/h3/qpack/dynamic_table.rs +859 -0
  49. package/vendor/quiche/src/h3/qpack/encoder.rs +14 -17
  50. package/vendor/quiche/src/h3/qpack/mod.rs +48 -0
  51. package/vendor/quiche/src/h3/qpack/static_table.rs +86 -73
  52. package/vendor/quiche/src/h3/stream.rs +1009 -194
  53. package/vendor/quiche/src/lib.rs +1346 -1195
  54. package/vendor/quiche/src/minmax.rs +2 -6
  55. package/vendor/quiche/src/packet.rs +420 -552
  56. package/vendor/quiche/src/path.rs +202 -72
  57. package/vendor/quiche/src/pmtud.rs +18 -16
  58. package/vendor/quiche/src/ranges.rs +184 -82
  59. package/vendor/quiche/src/recovery/AGENTS.md +5 -2
  60. package/vendor/quiche/src/recovery/bandwidth.rs +59 -40
  61. package/vendor/quiche/src/recovery/bytes_in_flight.rs +2 -2
  62. package/vendor/quiche/src/recovery/congestion/cubic.rs +38 -47
  63. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +54 -60
  64. package/vendor/quiche/src/recovery/congestion/hystart.rs +6 -10
  65. package/vendor/quiche/src/recovery/congestion/mod.rs +110 -42
  66. package/vendor/quiche/src/recovery/congestion/prr.rs +4 -1
  67. package/vendor/quiche/src/recovery/congestion/recovery.rs +91 -95
  68. package/vendor/quiche/src/recovery/congestion/reno.rs +17 -12
  69. package/vendor/quiche/src/recovery/congestion/test_sender.rs +8 -27
  70. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +159 -247
  71. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +9 -14
  72. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +18 -15
  73. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +43 -28
  74. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +349 -76
  75. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +147 -195
  76. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +29 -27
  77. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min.rs +180 -0
  78. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min_tests.rs +221 -0
  79. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm.rs +395 -0
  80. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm_tests.rs +473 -0
  81. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/mod.rs +175 -0
  82. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +33 -26
  83. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +107 -60
  84. package/vendor/quiche/src/recovery/gcongestion/mod.rs +64 -11
  85. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +34 -25
  86. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +81 -86
  87. package/vendor/quiche/src/recovery/mod.rs +414 -173
  88. package/vendor/quiche/src/recovery/rtt.rs +8 -5
  89. package/vendor/quiche/src/stream/mod.rs +864 -133
  90. package/vendor/quiche/src/stream/recv_buf.rs +471 -172
  91. package/vendor/quiche/src/stream/send_buf.rs +338 -81
  92. package/vendor/quiche/src/test_utils.rs +78 -64
  93. package/vendor/quiche/src/tests.rs +2559 -1335
  94. package/vendor/quiche/src/tls/boringssl.rs +60 -63
  95. package/vendor/quiche/src/tls/mod.rs +146 -193
  96. package/vendor/quiche/src/transport_params.rs +87 -103
@@ -59,11 +59,16 @@ impl ModeImpl for Startup {
59
59
  }
60
60
 
61
61
  fn on_congestion_event(
62
- mut self, _prior_in_flight: usize, event_time: Instant,
63
- _acked_packets: &[Acked], _lost_packets: &[Lost],
62
+ mut self,
63
+ _prior_in_flight: usize,
64
+ event_time: Instant,
65
+ _acked_packets: &[Acked],
66
+ _lost_packets: &[Lost],
64
67
  congestion_event: &mut BBRv2CongestionEvent,
65
- _target_bytes_inflight: usize, params: &Params,
66
- recovery_stats: &mut RecoveryStats, cwnd: usize,
68
+ _target_bytes_inflight: usize,
69
+ params: &Params,
70
+ recovery_stats: &mut RecoveryStats,
71
+ cwnd: usize,
67
72
  ) -> Mode {
68
73
  if self.model.full_bandwidth_reached() {
69
74
  return self.into_drain(event_time, Some(congestion_event), params);
@@ -73,8 +78,7 @@ impl ModeImpl for Startup {
73
78
  return Mode::Startup(self);
74
79
  }
75
80
 
76
- let has_bandwidth_growth =
77
- self.model.has_bandwidth_growth(congestion_event, params);
81
+ let has_bandwidth_growth = self.model.has_bandwidth_growth(congestion_event, params);
78
82
  if self.model.full_bandwidth_reached() {
79
83
  recovery_stats.set_startup_exit(StartupExit::new(
80
84
  cwnd,
@@ -83,8 +87,7 @@ impl ModeImpl for Startup {
83
87
  ));
84
88
  }
85
89
 
86
- let check_persisten_queue =
87
- params.max_startup_queue_rounds > 0 && !has_bandwidth_growth;
90
+ let check_persisten_queue = params.max_startup_queue_rounds > 0 && !has_bandwidth_growth;
88
91
  if check_persisten_queue {
89
92
  // https://github.com/google/quiche/blob/27eca0257490df89d2bd2c2a8bcea15565e7831c/quiche/quic/core/congestion_control/bbr2_startup.cc#L60-L62
90
93
  // 1.75 is less than the 2x CWND gain, but substantially more than
@@ -101,8 +104,8 @@ impl ModeImpl for Startup {
101
104
  }
102
105
 
103
106
  // TCP BBR always exits upon excessive losses. QUIC BBRv1 does not exit
104
- // upon excessive losses, if enough bandwidth growth is observed or if the
105
- // sample was app limited.
107
+ // upon excessive losses if enough bandwidth growth is observed or the
108
+ // sample was app-limited.
106
109
  let check_for_excessive_loss = !congestion_event.last_packet_send_state.is_app_limited &&
107
110
  !has_bandwidth_growth &&
108
111
  // check for excessive loss only if not exiting for other reasons
@@ -135,22 +138,24 @@ impl ModeImpl for Startup {
135
138
  }
136
139
 
137
140
  fn on_exit_quiescence(
138
- self, _now: Instant, _quiescence_start_time: Instant, _params: &Params,
141
+ self,
142
+ _now: Instant,
143
+ _quiescence_start_time: Instant,
144
+ _params: &Params,
139
145
  ) -> Mode {
140
146
  Mode::Startup(self)
141
147
  }
142
148
 
143
149
  fn enter(
144
- &mut self, _now: Instant,
145
- _congestion_event: Option<&BBRv2CongestionEvent>, _params: &Params,
150
+ &mut self,
151
+ _now: Instant,
152
+ _congestion_event: Option<&BBRv2CongestionEvent>,
153
+ _params: &Params,
146
154
  ) {
147
155
  unreachable!("Enter should never be called for startup")
148
156
  }
149
157
 
150
- fn leave(
151
- &mut self, _now: Instant,
152
- _congestion_event: Option<&BBRv2CongestionEvent>,
153
- ) {
158
+ fn leave(&mut self, _now: Instant, _congestion_event: Option<&BBRv2CongestionEvent>) {
154
159
  // Clear bandwidth_lo if it's set during STARTUP.
155
160
  self.model.clear_bandwidth_lo();
156
161
  }
@@ -158,7 +163,9 @@ impl ModeImpl for Startup {
158
163
 
159
164
  impl Startup {
160
165
  fn into_drain(
161
- mut self, now: Instant, congestion_event: Option<&BBRv2CongestionEvent>,
166
+ mut self,
167
+ now: Instant,
168
+ congestion_event: Option<&BBRv2CongestionEvent>,
162
169
  params: &Params,
163
170
  ) -> Mode {
164
171
  self.leave(now, congestion_event);
@@ -168,19 +175,19 @@ impl Startup {
168
175
  }
169
176
 
170
177
  fn check_excessive_losses(
171
- &mut self, congestion_event: &mut BBRv2CongestionEvent, params: &Params,
178
+ &mut self,
179
+ congestion_event: &mut BBRv2CongestionEvent,
180
+ params: &Params,
172
181
  ) {
173
182
  // At the end of a round trip. Check if loss is too high in this round.
174
- if self.model.is_inflight_too_high(
175
- congestion_event,
176
- params.startup_full_loss_count,
177
- params,
178
- ) {
183
+ if self
184
+ .model
185
+ .is_inflight_too_high(congestion_event, params.startup_full_loss_count, params)
186
+ {
179
187
  let mut new_inflight_hi = self.model.bdp0();
180
188
 
181
189
  if params.startup_loss_exit_use_max_delivered_for_inflight_hi {
182
- new_inflight_hi = new_inflight_hi
183
- .max(self.model.max_bytes_delivered_in_round());
190
+ new_inflight_hi = new_inflight_hi.max(self.model.max_bytes_delivered_in_round());
184
191
  }
185
192
 
186
193
  self.model.set_inflight_hi(new_inflight_hi);
@@ -33,6 +33,7 @@ mod mode;
33
33
  mod network_model;
34
34
  mod probe_bw;
35
35
  mod probe_rtt;
36
+ mod rtt_jump_detector;
36
37
  mod startup;
37
38
 
38
39
  use std::time::Duration;
@@ -50,6 +51,7 @@ use super::bbr::SendTimeState;
50
51
  use super::Acked;
51
52
  use super::BbrBwLoReductionStrategy;
52
53
  use super::BbrParams;
54
+ use super::BbrRttJumpDetector;
53
55
  use super::CongestionControl;
54
56
  use super::Lost;
55
57
  use super::RttStats;
@@ -190,6 +192,10 @@ struct Params {
190
192
  /// initial cwnd by the first RTT estimate.
191
193
  initial_pacing_rate_bytes_per_second: Option<u64>,
192
194
 
195
+ /// Lower bound on the congestion window in packets. If not set,
196
+ /// the initial congestion window is used as the lower bound.
197
+ min_cwnd_packets: Option<usize>,
198
+
193
199
  /// If true, scale the pacing rate when updating mss when doing pmtud.
194
200
  scale_pacing_rate_by_mss: bool,
195
201
 
@@ -207,6 +213,9 @@ struct Params {
207
213
  /// 1/8th of an RTT into the future, so the error introduced by
208
214
  /// setting `time_sent` to `now` is bounded.
209
215
  time_sent_set_to_now: bool,
216
+
217
+ /// Selects the RTT jump detector implementation.
218
+ rtt_jump_detector: BbrRttJumpDetector,
210
219
  }
211
220
 
212
221
  impl Params {
@@ -252,6 +261,14 @@ impl Params {
252
261
  apply_override!(disable_probe_down_early_exit);
253
262
  apply_override!(time_sent_set_to_now);
254
263
  apply_optional_override!(initial_pacing_rate_bytes_per_second);
264
+ apply_optional_override!(min_cwnd_packets);
265
+
266
+ #[cfg(feature = "internal")]
267
+ {
268
+ if let Some(custom_value) = custom_bbr_settings.rtt_jump_detector {
269
+ self.rtt_jump_detector = custom_value;
270
+ }
271
+ }
255
272
 
256
273
  if let Some(custom_value) = custom_bbr_settings.bw_lo_reduction_strategy {
257
274
  self.bw_lo_mode = custom_value.into();
@@ -342,11 +359,15 @@ const DEFAULT_PARAMS: Params = Params {
342
359
 
343
360
  initial_pacing_rate_bytes_per_second: None,
344
361
 
362
+ min_cwnd_packets: None,
363
+
345
364
  scale_pacing_rate_by_mss: false,
346
365
 
347
366
  disable_probe_down_early_exit: false,
348
367
 
349
368
  time_sent_set_to_now: true,
369
+
370
+ rtt_jump_detector: BbrRttJumpDetector::Disabled,
350
371
  };
351
372
 
352
373
  #[derive(Debug, PartialEq)]
@@ -378,10 +399,8 @@ impl From<BbrBwLoReductionStrategy> for BwLoMode {
378
399
  fn from(value: BbrBwLoReductionStrategy) -> Self {
379
400
  match value {
380
401
  BbrBwLoReductionStrategy::Default => BwLoMode::Default,
381
- BbrBwLoReductionStrategy::MinRttReduction =>
382
- BwLoMode::MinRttReduction,
383
- BbrBwLoReductionStrategy::InflightReduction =>
384
- BwLoMode::InflightReduction,
402
+ BbrBwLoReductionStrategy::MinRttReduction => BwLoMode::MinRttReduction,
403
+ BbrBwLoReductionStrategy::InflightReduction => BwLoMode::InflightReduction,
385
404
  BbrBwLoReductionStrategy::CwndReduction => BwLoMode::CwndReduction,
386
405
  }
387
406
  }
@@ -412,9 +431,7 @@ impl<T: Ord + Clone + Copy + From<u8>> Limits<T> {
412
431
  }
413
432
  }
414
433
 
415
- fn initial_pacing_rate(
416
- cwnd_in_bytes: usize, smoothed_rtt: Duration, params: &Params,
417
- ) -> Bandwidth {
434
+ fn initial_pacing_rate(cwnd_in_bytes: usize, smoothed_rtt: Duration, params: &Params) -> Bandwidth {
418
435
  if let Some(pacing_rate) = params.initial_pacing_rate_bytes_per_second {
419
436
  return Bandwidth::from_bytes_per_second(pacing_rate);
420
437
  }
@@ -477,7 +494,9 @@ struct BBRv2CongestionEvent {
477
494
 
478
495
  impl BBRv2CongestionEvent {
479
496
  fn new(
480
- event_time: Instant, prior_cwnd: usize, prior_bytes_in_flight: usize,
497
+ event_time: Instant,
498
+ prior_cwnd: usize,
499
+ prior_bytes_in_flight: usize,
481
500
  is_probing_for_bandwidth: bool,
482
501
  ) -> Self {
483
502
  BBRv2CongestionEvent {
@@ -498,8 +517,10 @@ impl BBRv2CongestionEvent {
498
517
 
499
518
  impl BBRv2 {
500
519
  pub fn new(
501
- initial_congestion_window: usize, max_congestion_window: usize,
502
- max_segment_size: usize, smoothed_rtt: Duration,
520
+ initial_congestion_window: usize,
521
+ max_congestion_window: usize,
522
+ max_segment_size: usize,
523
+ smoothed_rtt: Duration,
503
524
  custom_bbr_params: Option<&BbrParams>,
504
525
  ) -> Self {
505
526
  let cwnd = initial_congestion_window * max_segment_size;
@@ -510,12 +531,15 @@ impl BBRv2 {
510
531
  DEFAULT_PARAMS
511
532
  };
512
533
 
534
+ let min_cwnd =
535
+ params.min_cwnd_packets.unwrap_or(initial_congestion_window) * max_segment_size;
536
+
513
537
  BBRv2 {
514
538
  mode: Mode::startup(BBRv2NetworkModel::new(&params, smoothed_rtt)),
515
539
  cwnd,
516
540
  pacing_rate: initial_pacing_rate(cwnd, smoothed_rtt, &params),
517
541
  cwnd_limits: Limits {
518
- lo: initial_congestion_window * max_segment_size,
542
+ lo: min_cwnd,
519
543
  hi: max_congestion_window * max_segment_size,
520
544
  },
521
545
  initial_cwnd: initial_congestion_window * max_segment_size,
@@ -533,11 +557,8 @@ impl BBRv2 {
533
557
 
534
558
  fn on_exit_quiescence(&mut self, now: Instant) {
535
559
  if let Some(last_quiescence_start) = self.last_quiescence_start.take() {
536
- self.mode.do_on_exit_quiescence(
537
- now,
538
- last_quiescence_start,
539
- &self.params,
540
- )
560
+ self.mode
561
+ .do_on_exit_quiescence(now, last_quiescence_start, &self.params)
541
562
  }
542
563
  }
543
564
 
@@ -557,19 +578,14 @@ impl BBRv2 {
557
578
 
558
579
  if network_model.total_bytes_acked() == bytes_acked {
559
580
  // After the first ACK, cwnd is still the initial congestion window.
560
- self.pacing_rate = Bandwidth::from_bytes_and_time_delta(
561
- self.cwnd,
562
- network_model.min_rtt(),
563
- );
564
-
565
- if let Some(pacing_rate) =
566
- self.params.initial_pacing_rate_bytes_per_second
567
- {
581
+ self.pacing_rate =
582
+ Bandwidth::from_bytes_and_time_delta(self.cwnd, network_model.min_rtt());
583
+
584
+ if let Some(pacing_rate) = self.params.initial_pacing_rate_bytes_per_second {
568
585
  // Do not allow the pacing rate calculated from the first RTT
569
586
  // measurement to be higher than the configured initial pacing
570
587
  // rate.
571
- let initial_pacing_rate =
572
- Bandwidth::from_bytes_per_second(pacing_rate);
588
+ let initial_pacing_rate = Bandwidth::from_bytes_per_second(pacing_rate);
573
589
  self.pacing_rate = self.pacing_rate.min(initial_pacing_rate);
574
590
  }
575
591
 
@@ -582,16 +598,14 @@ impl BBRv2 {
582
598
  return;
583
599
  }
584
600
 
585
- if self.params.decrease_startup_pacing_at_end_of_round &&
586
- network_model.pacing_gain() < self.params.startup_pacing_gain
601
+ if self.params.decrease_startup_pacing_at_end_of_round
602
+ && network_model.pacing_gain() < self.params.startup_pacing_gain
587
603
  {
588
604
  self.pacing_rate = target_rate;
589
605
  return;
590
606
  }
591
607
 
592
- if self.params.bw_lo_mode != BwLoMode::Default &&
593
- network_model.loss_events_in_round() > 0
594
- {
608
+ if self.params.bw_lo_mode != BwLoMode::Default && network_model.loss_events_in_round() > 0 {
595
609
  self.pacing_rate = target_rate;
596
610
  return;
597
611
  }
@@ -602,8 +616,7 @@ impl BBRv2 {
602
616
 
603
617
  fn update_congestion_window(&mut self, bytes_acked: usize) {
604
618
  let network_model = self.mode.network_model();
605
- let mut target_cwnd =
606
- self.get_target_congestion_window(network_model.cwnd_gain());
619
+ let mut target_cwnd = self.get_target_congestion_window(network_model.cwnd_gain());
607
620
 
608
621
  let prior_cwnd = self.cwnd;
609
622
  if network_model.full_bandwidth_reached() {
@@ -639,6 +652,10 @@ impl BBRv2 {
639
652
  pub(crate) fn ack_rate(&self) -> Option<Bandwidth> {
640
653
  self.mode.network_model().ack_rate()
641
654
  }
655
+
656
+ pub(crate) fn rtt_persistent_jump_count(&self) -> u64 {
657
+ self.mode.network_model().rtt_persistent_jump_count()
658
+ }
642
659
  }
643
660
 
644
661
  impl CongestionControl for BBRv2 {
@@ -660,8 +677,12 @@ impl CongestionControl for BBRv2 {
660
677
  }
661
678
 
662
679
  fn on_packet_sent(
663
- &mut self, sent_time: Instant, bytes_in_flight: usize,
664
- packet_number: u64, bytes: usize, is_retransmissible: bool,
680
+ &mut self,
681
+ sent_time: Instant,
682
+ bytes_in_flight: usize,
683
+ packet_number: u64,
684
+ bytes: usize,
685
+ is_retransmissible: bool,
665
686
  ) {
666
687
  if bytes_in_flight == 0 && self.params.avoid_unnecessary_probe_rtt {
667
688
  self.on_exit_quiescence(sent_time);
@@ -678,9 +699,15 @@ impl CongestionControl for BBRv2 {
678
699
  }
679
700
 
680
701
  fn on_congestion_event(
681
- &mut self, _rtt_updated: bool, prior_in_flight: usize,
682
- _bytes_in_flight: usize, event_time: Instant, acked_packets: &[Acked],
683
- lost_packets: &[Lost], least_unacked: u64, _rtt_stats: &RttStats,
702
+ &mut self,
703
+ _rtt_updated: bool,
704
+ prior_in_flight: usize,
705
+ _bytes_in_flight: usize,
706
+ event_time: Instant,
707
+ acked_packets: &[Acked],
708
+ lost_packets: &[Lost],
709
+ least_unacked: u64,
710
+ _rtt_stats: &RttStats,
684
711
  recovery_stats: &mut RecoveryStats,
685
712
  ) {
686
713
  let mut congestion_event = BBRv2CongestionEvent::new(
@@ -700,8 +727,8 @@ impl CongestionControl for BBRv2 {
700
727
 
701
728
  // Number of mode changes allowed for this congestion event.
702
729
  let mut mode_changes_allowed = MAX_MODE_CHANGES_PER_CONGESTION_EVENT;
703
- while mode_changes_allowed > 0 &&
704
- self.mode.do_on_congestion_event(
730
+ while mode_changes_allowed > 0
731
+ && self.mode.do_on_congestion_event(
705
732
  prior_in_flight,
706
733
  event_time,
707
734
  acked_packets,
@@ -721,16 +748,12 @@ impl CongestionControl for BBRv2 {
721
748
  self.update_congestion_window(congestion_event.bytes_acked);
722
749
 
723
750
  let network_model = self.mode.network_model_mut();
724
- network_model
725
- .on_congestion_event_finish(least_unacked, &congestion_event);
726
- self.last_sample_is_app_limited =
727
- congestion_event.last_packet_send_state.is_app_limited;
751
+ network_model.on_congestion_event_finish(least_unacked, &congestion_event);
752
+ self.last_sample_is_app_limited = congestion_event.last_packet_send_state.is_app_limited;
728
753
  if !self.last_sample_is_app_limited {
729
754
  self.has_non_app_limited_sample = true;
730
755
  }
731
- if congestion_event.bytes_in_flight == 0 &&
732
- self.params.avoid_unnecessary_probe_rtt
733
- {
756
+ if congestion_event.bytes_in_flight == 0 && self.params.avoid_unnecessary_probe_rtt {
734
757
  self.on_enter_quiescence(event_time);
735
758
  }
736
759
  }
@@ -753,9 +776,7 @@ impl CongestionControl for BBRv2 {
753
776
  bytes_in_flight >= self.get_congestion_window()
754
777
  }
755
778
 
756
- fn pacing_rate(
757
- &self, _bytes_in_flight: usize, _rtt_stats: &RttStats,
758
- ) -> Bandwidth {
779
+ fn pacing_rate(&self, _bytes_in_flight: usize, _rtt_stats: &RttStats) -> Bandwidth {
759
780
  self.pacing_rate
760
781
  }
761
782
 
@@ -769,17 +790,14 @@ impl CongestionControl for BBRv2 {
769
790
  }
770
791
 
771
792
  fn update_mss(&mut self, new_mss: usize) {
772
- self.cwnd_limits.hi = (self.cwnd_limits.hi as u64 * new_mss as u64 /
773
- self.mss as u64) as usize;
774
- self.cwnd_limits.lo = (self.cwnd_limits.lo as u64 * new_mss as u64 /
775
- self.mss as u64) as usize;
776
- self.cwnd =
777
- (self.cwnd as u64 * new_mss as u64 / self.mss as u64) as usize;
778
- self.initial_cwnd = (self.initial_cwnd as u64 * new_mss as u64 /
779
- self.mss as u64) as usize;
793
+ self.cwnd_limits.hi =
794
+ (self.cwnd_limits.hi as u64 * new_mss as u64 / self.mss as u64) as usize;
795
+ self.cwnd_limits.lo =
796
+ (self.cwnd_limits.lo as u64 * new_mss as u64 / self.mss as u64) as usize;
797
+ self.cwnd = (self.cwnd as u64 * new_mss as u64 / self.mss as u64) as usize;
798
+ self.initial_cwnd = (self.initial_cwnd as u64 * new_mss as u64 / self.mss as u64) as usize;
780
799
  if self.params.scale_pacing_rate_by_mss {
781
- self.pacing_rate =
782
- self.pacing_rate * (new_mss as f64 / self.mss as f64);
800
+ self.pacing_rate = self.pacing_rate * (new_mss as f64 / self.mss as f64);
783
801
  }
784
802
  self.mss = new_mss;
785
803
  }
@@ -852,4 +870,33 @@ mod tests {
852
870
  (2.88499 * pacing_cwnd as f64) as u64
853
871
  );
854
872
  }
873
+
874
+ #[rstest]
875
+ fn min_cwnd_packets_override(
876
+ #[values(None, Some(4), Some(40))] min_cwnd_packets: Option<usize>,
877
+ ) {
878
+ const INIT_PACKET_SIZE: usize = 1200;
879
+ const INIT_WINDOW_PACKETS: usize = 10;
880
+ const MAX_WINDOW_PACKETS: usize = 10000;
881
+ let initial_rtt = Duration::from_millis(333);
882
+ let bbr_params = &BbrParams {
883
+ min_cwnd_packets,
884
+ ..Default::default()
885
+ };
886
+
887
+ let bbr2 = BBRv2::new(
888
+ INIT_WINDOW_PACKETS,
889
+ MAX_WINDOW_PACKETS,
890
+ INIT_PACKET_SIZE,
891
+ initial_rtt,
892
+ Some(bbr_params),
893
+ );
894
+
895
+ // If not set, the initial congestion window is the lower bound.
896
+ let expected_lo = min_cwnd_packets.unwrap_or(INIT_WINDOW_PACKETS) * INIT_PACKET_SIZE;
897
+ assert_eq!(bbr2.cwnd_limits.lo, expected_lo);
898
+ assert_eq!(bbr2.cwnd_limits.hi, MAX_WINDOW_PACKETS * INIT_PACKET_SIZE);
899
+ // The initial cwnd itself is not affected.
900
+ assert_eq!(bbr2.cwnd, INIT_WINDOW_PACKETS * INIT_PACKET_SIZE);
901
+ }
855
902
  }
@@ -76,8 +76,12 @@ pub(super) trait CongestionControl: Debug {
76
76
  /// before the packet was sent. Note: this function must be called for
77
77
  /// every packet sent to the wire.
78
78
  fn on_packet_sent(
79
- &mut self, sent_time: Instant, bytes_in_flight: usize,
80
- packet_number: u64, bytes: usize, is_retransmissible: bool,
79
+ &mut self,
80
+ sent_time: Instant,
81
+ bytes_in_flight: usize,
82
+ packet_number: u64,
83
+ bytes: usize,
84
+ is_retransmissible: bool,
81
85
  );
82
86
 
83
87
  /// Inform that `packet_number` has been neutered.
@@ -91,9 +95,15 @@ pub(super) trait CongestionControl: Debug {
91
95
  /// congestion event.
92
96
  #[allow(clippy::too_many_arguments)]
93
97
  fn on_congestion_event(
94
- &mut self, rtt_updated: bool, prior_in_flight: usize,
95
- bytes_in_flight: usize, event_time: Instant, acked_packets: &[Acked],
96
- lost_packets: &[Lost], least_unacked: u64, rtt_stats: &RttStats,
98
+ &mut self,
99
+ rtt_updated: bool,
100
+ prior_in_flight: usize,
101
+ bytes_in_flight: usize,
102
+ event_time: Instant,
103
+ acked_packets: &[Acked],
104
+ lost_packets: &[Lost],
105
+ least_unacked: u64,
106
+ rtt_stats: &RttStats,
97
107
  recovery_stats: &mut RecoveryStats,
98
108
  );
99
109
 
@@ -113,9 +123,7 @@ pub(super) trait CongestionControl: Debug {
113
123
  #[allow(dead_code)]
114
124
  fn is_cwnd_limited(&self, bytes_in_flight: usize) -> bool;
115
125
 
116
- fn pacing_rate(
117
- &self, bytes_in_flight: usize, rtt_stats: &RttStats,
118
- ) -> Bandwidth;
126
+ fn pacing_rate(&self, bytes_in_flight: usize, rtt_stats: &RttStats) -> Bandwidth;
119
127
 
120
128
  fn bandwidth_estimate(&self, rtt_stats: &RttStats) -> Bandwidth;
121
129
 
@@ -221,6 +229,10 @@ pub struct BbrParams {
221
229
  /// initial cwnd by the first RTT estimate.
222
230
  pub initial_pacing_rate_bytes_per_second: Option<u64>,
223
231
 
232
+ /// Lower bound on the congestion window in packets. If not set,
233
+ /// the initial congestion window is used as the lower bound.
234
+ pub min_cwnd_packets: Option<usize>,
235
+
224
236
  /// If true, scale the pacing rate when updating mss when doing pmtud.
225
237
  pub scale_pacing_rate_by_mss: Option<bool>,
226
238
 
@@ -233,6 +245,47 @@ pub struct BbrParams {
233
245
  /// on `get_next_release_time()` can result in artificially low
234
246
  /// minRTT measurements which will make BBR misbehave.
235
247
  pub time_sent_set_to_now: Option<bool>,
248
+
249
+ /// Selects the RTT jump detector implementation.
250
+ #[cfg(feature = "internal")]
251
+ pub rtt_jump_detector: Option<BbrRttJumpDetector>,
252
+ }
253
+
254
+ /// Selects which RTT jump detector BBR uses.
255
+ ///
256
+ /// This functionality is experimental and will be removed in the future.
257
+ #[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
258
+ #[repr(C)]
259
+ #[doc(hidden)]
260
+ pub enum BbrRttJumpDetector {
261
+ /// Disables RTT jump detection.
262
+ #[default]
263
+ Disabled = 0,
264
+
265
+ /// Connection-lifetime minimum baseline with a strict multiplicative jump
266
+ /// test and a sample/duration confirmation gate.
267
+ GlobalMin = 1,
268
+
269
+ /// 3-state Hidden Markov Model (HMM) decoded with a scaled forward filter.
270
+ Hmm = 2,
271
+ }
272
+
273
+ #[doc(hidden)]
274
+ impl FromStr for BbrRttJumpDetector {
275
+ type Err = crate::Error;
276
+
277
+ /// Converts a string to `BbrRttJumpDetector`.
278
+ ///
279
+ /// If `name` is not valid, `Error::CongestionControl` is returned.
280
+ fn from_str(name: &str) -> Result<Self, Self::Err> {
281
+ match name {
282
+ "none" => Ok(BbrRttJumpDetector::Disabled),
283
+ "global_min" => Ok(BbrRttJumpDetector::GlobalMin),
284
+ "hmm" => Ok(BbrRttJumpDetector::Hmm),
285
+
286
+ _ => Err(crate::Error::CongestionControl),
287
+ }
288
+ }
236
289
  }
237
290
 
238
291
  /// Controls BBR's bandwidth reduction strategy on congestion event.
@@ -243,16 +296,16 @@ pub struct BbrParams {
243
296
  #[doc(hidden)]
244
297
  pub enum BbrBwLoReductionStrategy {
245
298
  /// Uses the default strategy based on `BBRBeta`.
246
- Default = 0,
299
+ Default = 0,
247
300
 
248
301
  /// Considers min-rtt to estimate bandwidth reduction.
249
- MinRttReduction = 1,
302
+ MinRttReduction = 1,
250
303
 
251
304
  /// Considers inflight data to estimate bandwidth reduction.
252
305
  InflightReduction = 2,
253
306
 
254
307
  /// Considers cwnd to estimate bandwidth reduction.
255
- CwndReduction = 3,
308
+ CwndReduction = 3,
256
309
  }
257
310
 
258
311
  #[doc(hidden)]