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
@@ -46,6 +46,8 @@ use self::congestion::recovery::LegacyRecovery;
46
46
  use self::gcongestion::GRecovery;
47
47
  pub use gcongestion::BbrBwLoReductionStrategy;
48
48
  pub use gcongestion::BbrParams;
49
+ #[cfg(feature = "internal")]
50
+ pub use gcongestion::BbrRttJumpDetector;
49
51
 
50
52
  // Loss Recovery
51
53
  const INITIAL_PACKET_THRESHOLD: u64 = 3;
@@ -94,11 +96,6 @@ const LOSS_REDUCTION_FACTOR: f64 = 0.5;
94
96
  // an ACK.
95
97
  pub(super) const MAX_OUTSTANDING_NON_ACK_ELICITING: usize = 24;
96
98
 
97
- // The upper cap on the exponent when using exponential backoff for probes. With
98
- // a value of 20, the maximum possible value is 2^20 = 1,048,576 times the
99
- // minimum PTO. This prevents arithmetic overflow.
100
- const MAX_PTO_EXPONENT: u32 = 20;
101
-
102
99
  #[derive(Default)]
103
100
  struct LossDetectionTimer {
104
101
  time: Option<Instant>,
@@ -125,7 +122,7 @@ impl std::fmt::Debug for LossDetectionTimer {
125
122
  } else {
126
123
  write!(f, "exp")
127
124
  }
128
- },
125
+ }
129
126
  None => write!(f, "none"),
130
127
  }
131
128
  }
@@ -142,6 +139,8 @@ pub struct RecoveryConfig {
142
139
  pub pacing: bool,
143
140
  pub max_pacing_rate: Option<u64>,
144
141
  pub initial_congestion_window_packets: usize,
142
+ /// Fixed congestion window in bytes for the unchecked controller.
143
+ pub unchecked_congestion_window: usize,
145
144
  pub enable_relaxed_loss_threshold: bool,
146
145
  pub enable_cubic_idle_restart_fix: bool,
147
146
  }
@@ -157,12 +156,20 @@ impl RecoveryConfig {
157
156
  hystart: config.hystart,
158
157
  pacing: config.pacing,
159
158
  max_pacing_rate: config.max_pacing_rate,
160
- initial_congestion_window_packets: config
161
- .initial_congestion_window_packets,
159
+ initial_congestion_window_packets: config.initial_congestion_window_packets,
160
+ unchecked_congestion_window: config.unchecked_congestion_window,
162
161
  enable_relaxed_loss_threshold: config.enable_relaxed_loss_threshold,
163
162
  enable_cubic_idle_restart_fix: config.enable_cubic_idle_restart_fix,
164
163
  }
165
164
  }
165
+
166
+ pub(crate) fn update_max_send_udp_payload_size(&mut self, peer_max: usize) {
167
+ // Max payload size can never grow, only shrink in response to peer
168
+ // transport parameters. It must also never fall below 1200 bytes per
169
+ // RFC 9000 §18.2.
170
+ let new_max = peer_max.max(crate::MAX_SEND_UDP_PAYLOAD_SIZE);
171
+ self.max_send_udp_payload_size = self.max_send_udp_payload_size.min(new_max);
172
+ }
166
173
  }
167
174
 
168
175
  #[enum_dispatch::enum_dispatch(RecoveryOps)]
@@ -212,28 +219,44 @@ pub trait RecoveryOps {
212
219
  fn ping_sent(&mut self, epoch: packet::Epoch);
213
220
 
214
221
  fn on_packet_sent(
215
- &mut self, pkt: Sent, epoch: packet::Epoch,
216
- handshake_status: HandshakeStatus, now: Instant, trace_id: &str,
222
+ &mut self,
223
+ pkt: Sent,
224
+ epoch: packet::Epoch,
225
+ handshake_status: HandshakeStatus,
226
+ now: Instant,
227
+ trace_id: &str,
217
228
  );
218
229
  fn get_packet_send_time(&self, now: Instant) -> Instant;
219
230
 
220
231
  #[allow(clippy::too_many_arguments)]
221
232
  fn on_ack_received(
222
- &mut self, ranges: &RangeSet, ack_delay: u64, epoch: packet::Epoch,
223
- handshake_status: HandshakeStatus, now: Instant, skip_pn: Option<u64>,
233
+ &mut self,
234
+ ranges: &RangeSet,
235
+ ack_delay: u64,
236
+ epoch: packet::Epoch,
237
+ handshake_status: HandshakeStatus,
238
+ now: Instant,
239
+ skip_pn: Option<u64>,
224
240
  trace_id: &str,
225
241
  ) -> Result<OnAckReceivedOutcome>;
226
242
 
227
243
  fn on_loss_detection_timeout(
228
- &mut self, handshake_status: HandshakeStatus, now: Instant,
244
+ &mut self,
245
+ handshake_status: HandshakeStatus,
246
+ now: Instant,
229
247
  trace_id: &str,
230
248
  ) -> OnLossDetectionTimeoutOutcome;
231
249
  fn on_pkt_num_space_discarded(
232
- &mut self, epoch: packet::Epoch, handshake_status: HandshakeStatus,
250
+ &mut self,
251
+ epoch: packet::Epoch,
252
+ handshake_status: HandshakeStatus,
233
253
  now: Instant,
234
254
  );
235
255
  fn on_path_change(
236
- &mut self, epoch: packet::Epoch, now: Instant, _trace_id: &str,
256
+ &mut self,
257
+ epoch: packet::Epoch,
258
+ now: Instant,
259
+ _trace_id: &str,
237
260
  ) -> (usize, usize);
238
261
  fn loss_detection_timer(&self) -> Option<Instant>;
239
262
  fn cwnd(&self) -> usize;
@@ -254,6 +277,9 @@ pub trait RecoveryOps {
254
277
  /// Maximum bandwidth estimate, if one is available.
255
278
  fn max_bandwidth(&self) -> Option<Bandwidth>;
256
279
 
280
+ /// Total number of confirmed persistent RTT jump episodes.
281
+ fn rtt_persistent_jump_count(&self) -> u64;
282
+
257
283
  /// Statistics from when a CCA first exited the startup phase.
258
284
  fn startup_exit(&self) -> Option<StartupExit>;
259
285
 
@@ -270,10 +296,9 @@ pub trait RecoveryOps {
270
296
  #[cfg(test)]
271
297
  fn largest_sent_pkt_num_on_path(&self, epoch: packet::Epoch) -> Option<u64>;
272
298
 
273
- #[cfg(test)]
299
+ #[cfg(any(test, feature = "qlog"))]
274
300
  fn app_limited(&self) -> bool;
275
301
 
276
- #[cfg(test)]
277
302
  fn sent_packets_len(&self, epoch: packet::Epoch) -> usize;
278
303
 
279
304
  fn bytes_in_flight(&self) -> usize;
@@ -289,8 +314,8 @@ pub trait RecoveryOps {
289
314
  #[cfg(test)]
290
315
  fn pto_count(&self) -> u32;
291
316
 
292
- // This value might be `None` when experiment `enable_relaxed_loss_threshold`
293
- // is enabled for gcongestion
317
+ // This value might be `None` when the `enable_relaxed_loss_threshold`
318
+ // experiment is enabled for gcongestion.
294
319
  #[cfg(test)]
295
320
  fn pkt_thresh(&self) -> Option<u64>;
296
321
 
@@ -302,7 +327,9 @@ pub trait RecoveryOps {
302
327
 
303
328
  #[cfg(test)]
304
329
  fn detect_lost_packets_for_test(
305
- &mut self, epoch: packet::Epoch, now: Instant,
330
+ &mut self,
331
+ epoch: packet::Epoch,
332
+ now: Instant,
306
333
  ) -> (usize, usize);
307
334
 
308
335
  fn update_app_limited(&mut self, v: bool);
@@ -318,8 +345,7 @@ pub trait RecoveryOps {
318
345
  fn get_updated_qlog_event_data(&mut self) -> Option<EventData>;
319
346
 
320
347
  #[cfg(feature = "qlog")]
321
- fn get_updated_qlog_cc_state(&mut self, now: Instant)
322
- -> Option<&'static str>;
348
+ fn get_updated_qlog_cc_state(&mut self, now: Instant) -> Option<&'static str>;
323
349
 
324
350
  fn send_quantum(&self) -> usize;
325
351
 
@@ -339,21 +365,18 @@ impl Recovery {
339
365
  }
340
366
 
341
367
  #[cfg(feature = "qlog")]
342
- pub fn maybe_qlog(
343
- &mut self, qlog: &mut qlog::streamer::QlogStreamer, now: Instant,
344
- ) {
368
+ pub fn maybe_qlog(&mut self, qlog: &mut qlog::streamer::QlogStreamer, now: Instant) {
345
369
  if let Some(ev_data) = self.get_updated_qlog_event_data() {
346
370
  qlog.add_event_data_with_instant(ev_data, now).ok();
347
371
  }
348
372
 
349
373
  if let Some(cc_state) = self.get_updated_qlog_cc_state(now) {
350
- let ev_data = EventData::QuicCongestionStateUpdated(
351
- qlog::events::quic::CongestionStateUpdated {
374
+ let ev_data =
375
+ EventData::QuicCongestionStateUpdated(qlog::events::quic::CongestionStateUpdated {
352
376
  old: None,
353
377
  new: cc_state.to_string(),
354
378
  trigger: None,
355
- },
356
- );
379
+ });
357
380
 
358
381
  qlog.add_event_data_with_instant(ev_data, now).ok();
359
382
  }
@@ -369,16 +392,39 @@ impl Recovery {
369
392
  ///
370
393
  /// This enum provides currently available list of congestion control
371
394
  /// algorithms.
395
+ ///
396
+ /// The `congestion_window_unchecked_available` Cargo feature adds a variant to
397
+ /// this enum. Cargo can enable it through another dependency, so exhaustive
398
+ /// matches must account for the feature-enabled enum.
372
399
  #[derive(Debug, Copy, Clone, PartialEq, Eq)]
373
400
  #[repr(C)]
374
401
  pub enum CongestionControlAlgorithm {
375
402
  /// Reno congestion control algorithm. `reno` in a string form.
376
- Reno = 0,
403
+ Reno = 0,
377
404
  /// CUBIC congestion control algorithm (default). `cubic` in a string form.
378
- CUBIC = 1,
405
+ CUBIC = 1,
379
406
  /// BBRv2 congestion control algorithm implementation from gcongestion
380
407
  /// branch. `bbr2_gcongestion` in a string form.
381
408
  Bbr2Gcongestion = 4,
409
+ /// Uses a fixed congestion window instead of responding to congestion.
410
+ /// The window defaults to `usize::MAX` and can be set through
411
+ /// [`Config::set_unchecked_congestion_window()`]. ACK processing, RTT
412
+ /// estimation, loss detection, and recovery remain enabled. The default
413
+ /// window provides no congestion-window protection and, on 64-bit targets,
414
+ /// effectively disables packet-skipping optimistic-ACK probes.
415
+ ///
416
+ /// This intentionally bypasses adaptive congestion control ([RFC 9002,
417
+ /// Section 7]) and does not pace packets. Callers must provide their own
418
+ /// transmission constraints and pace or limit bursts ([RFC 9002,
419
+ /// Section 7.7]).
420
+ ///
421
+ /// `congestion_window_unchecked` in string form.
422
+ ///
423
+ /// [RFC 9002, Section 7]: https://www.rfc-editor.org/rfc/rfc9002.html#section-7
424
+ /// [RFC 9002, Section 7.7]: https://www.rfc-editor.org/rfc/rfc9002.html#section-7.7
425
+ #[cfg(feature = "congestion_window_unchecked_available")]
426
+ #[cfg_attr(docsrs, doc(cfg(feature = "congestion_window_unchecked_available")))]
427
+ CongestionWindowUnchecked = 5,
382
428
  }
383
429
 
384
430
  impl FromStr for CongestionControlAlgorithm {
@@ -394,6 +440,10 @@ impl FromStr for CongestionControlAlgorithm {
394
440
  "bbr" => Ok(CongestionControlAlgorithm::Bbr2Gcongestion),
395
441
  "bbr2" => Ok(CongestionControlAlgorithm::Bbr2Gcongestion),
396
442
  "bbr2_gcongestion" => Ok(CongestionControlAlgorithm::Bbr2Gcongestion),
443
+ #[cfg(feature = "congestion_window_unchecked_available")]
444
+ "congestion_window_unchecked" => {
445
+ Ok(CongestionControlAlgorithm::CongestionWindowUnchecked)
446
+ }
397
447
  _ => Err(crate::Error::CongestionControl),
398
448
  }
399
449
  }
@@ -495,6 +545,7 @@ struct QlogMetrics {
495
545
  lost_packets: Option<u64>,
496
546
  lost_bytes: Option<u64>,
497
547
  pto_count: Option<u32>,
548
+ app_limited: Option<bool>,
498
549
  }
499
550
 
500
551
  #[cfg(feature = "qlog")]
@@ -605,14 +656,13 @@ impl QlogMetrics {
605
656
  None
606
657
  };
607
658
 
608
- let new_bytes_in_flight =
609
- if self.bytes_in_flight != latest.bytes_in_flight {
610
- self.bytes_in_flight = latest.bytes_in_flight;
611
- emit_event = true;
612
- Some(latest.bytes_in_flight)
613
- } else {
614
- None
615
- };
659
+ let new_bytes_in_flight = if self.bytes_in_flight != latest.bytes_in_flight {
660
+ self.bytes_in_flight = latest.bytes_in_flight;
661
+ emit_event = true;
662
+ Some(latest.bytes_in_flight)
663
+ } else {
664
+ None
665
+ };
616
666
 
617
667
  let new_ssthresh = if self.ssthresh != latest.ssthresh {
618
668
  self.ssthresh = latest.ssthresh;
@@ -630,17 +680,23 @@ impl QlogMetrics {
630
680
  None
631
681
  };
632
682
 
633
- let new_pto_count =
634
- if latest.pto_count.is_some() && self.pto_count != latest.pto_count {
635
- self.pto_count = latest.pto_count;
636
- emit_event = true;
637
- latest.pto_count.map(|v| v as u16)
638
- } else {
639
- None
640
- };
683
+ let new_pto_count = if latest.pto_count.is_some() && self.pto_count != latest.pto_count {
684
+ self.pto_count = latest.pto_count;
685
+ emit_event = true;
686
+ latest.pto_count.map(|v| v as u16)
687
+ } else {
688
+ None
689
+ };
641
690
 
642
691
  // Build ex_data for rate metrics
643
692
  let mut ex_data = CfExData::new();
693
+ if self.app_limited != latest.app_limited {
694
+ if let Some(app_limited) = latest.app_limited {
695
+ self.app_limited = latest.app_limited;
696
+ emit_event = true;
697
+ ex_data.insert("cf_app_limited", app_limited);
698
+ }
699
+ }
644
700
  if self.delivery_rate != latest.delivery_rate {
645
701
  if let Some(rate) = latest.delivery_rate {
646
702
  self.delivery_rate = latest.delivery_rate;
@@ -666,20 +722,26 @@ impl QlogMetrics {
666
722
  if self.lost_packets != latest.lost_packets {
667
723
  if let Some(val) = latest.lost_packets {
668
724
  emit_event = true;
669
- ex_data.insert("cf_lost_packets", TotalAndDelta {
670
- total: latest.lost_packets,
671
- delta: Some(val - self.lost_packets.unwrap_or(0)),
672
- });
725
+ ex_data.insert(
726
+ "cf_lost_packets",
727
+ TotalAndDelta {
728
+ total: latest.lost_packets,
729
+ delta: Some(val - self.lost_packets.unwrap_or(0)),
730
+ },
731
+ );
673
732
  self.lost_packets = latest.lost_packets;
674
733
  }
675
734
  }
676
735
  if self.lost_bytes != latest.lost_bytes {
677
736
  if let Some(val) = latest.lost_bytes {
678
737
  emit_event = true;
679
- ex_data.insert("cf_lost_bytes", TotalAndDelta {
680
- total: latest.lost_bytes,
681
- delta: Some(val - self.lost_bytes.unwrap_or(0)),
682
- });
738
+ ex_data.insert(
739
+ "cf_lost_bytes",
740
+ TotalAndDelta {
741
+ total: latest.lost_bytes,
742
+ delta: Some(val - self.lost_bytes.unwrap_or(0)),
743
+ },
744
+ );
683
745
  self.lost_bytes = latest.lost_bytes;
684
746
  }
685
747
  }
@@ -724,7 +786,7 @@ impl ReleaseTime {
724
786
  /// Add the specific delay to the current time
725
787
  fn inc(&mut self, delay: Duration) {
726
788
  match self {
727
- ReleaseTime::Immediate => {},
789
+ ReleaseTime::Immediate => {}
728
790
  ReleaseTime::At(time) => *time += delay,
729
791
  }
730
792
  }
@@ -800,9 +862,7 @@ pub struct StartupExit {
800
862
  }
801
863
 
802
864
  impl StartupExit {
803
- fn new(
804
- cwnd: usize, bandwidth: Option<Bandwidth>, reason: StartupExitReason,
805
- ) -> Self {
865
+ fn new(cwnd: usize, bandwidth: Option<Bandwidth>, reason: StartupExitReason) -> Self {
806
866
  let bandwidth = bandwidth.map(Bandwidth::to_bytes_per_second);
807
867
  Self {
808
868
  cwnd,
@@ -835,7 +895,11 @@ mod tests {
835
895
  use crate::range_buf::RangeBuf;
836
896
  use crate::test_utils;
837
897
  use crate::CongestionControlAlgorithm;
898
+ #[cfg(feature = "congestion_window_unchecked_available")]
899
+ use crate::DEFAULT_INITIAL_CONGESTION_WINDOW_PACKETS;
838
900
  use crate::DEFAULT_INITIAL_RTT;
901
+ #[cfg(feature = "congestion_window_unchecked_available")]
902
+ use crate::MAX_SEND_UDP_PAYLOAD_SIZE;
839
903
  use rstest::rstest;
840
904
  use smallvec::smallvec;
841
905
  use std::str::FromStr;
@@ -846,6 +910,73 @@ mod tests {
846
910
  Recovery::new(&cfg)
847
911
  }
848
912
 
913
+ #[cfg(feature = "qlog")]
914
+ fn app_limited_value(event: EventData) -> Option<serde_json::Value> {
915
+ let EventData::QuicMetricsUpdated(metrics) = event else {
916
+ panic!("expected recovery metrics updated event");
917
+ };
918
+
919
+ metrics.ex_data.get("cf_app_limited").cloned()
920
+ }
921
+
922
+ #[cfg(feature = "qlog")]
923
+ #[test]
924
+ fn qlog_app_limited_emits_initial_false_and_transitions() {
925
+ let mut metrics = QlogMetrics::default();
926
+
927
+ let event = metrics
928
+ .maybe_update(QlogMetrics {
929
+ app_limited: Some(false),
930
+ ..Default::default()
931
+ })
932
+ .unwrap();
933
+ assert_eq!(app_limited_value(event), Some(false.into()));
934
+
935
+ let event = metrics
936
+ .maybe_update(QlogMetrics {
937
+ app_limited: Some(true),
938
+ ..Default::default()
939
+ })
940
+ .unwrap();
941
+ assert_eq!(app_limited_value(event), Some(true.into()));
942
+
943
+ let event = metrics
944
+ .maybe_update(QlogMetrics {
945
+ app_limited: Some(false),
946
+ ..Default::default()
947
+ })
948
+ .unwrap();
949
+ assert_eq!(app_limited_value(event), Some(false.into()));
950
+ }
951
+
952
+ #[cfg(feature = "qlog")]
953
+ #[test]
954
+ fn qlog_app_limited_suppresses_unchanged_values() {
955
+ let mut metrics = QlogMetrics::default();
956
+ metrics
957
+ .maybe_update(QlogMetrics {
958
+ app_limited: Some(false),
959
+ ..Default::default()
960
+ })
961
+ .unwrap();
962
+
963
+ assert!(metrics
964
+ .maybe_update(QlogMetrics {
965
+ app_limited: Some(false),
966
+ ..Default::default()
967
+ })
968
+ .is_none());
969
+
970
+ let event = metrics
971
+ .maybe_update(QlogMetrics {
972
+ cwnd: 1,
973
+ app_limited: Some(false),
974
+ ..Default::default()
975
+ })
976
+ .unwrap();
977
+ assert_eq!(app_limited_value(event), None);
978
+ }
979
+
849
980
  #[test]
850
981
  fn lookup_cc_algo_ok() {
851
982
  let algo = CongestionControlAlgorithm::from_str("reno").unwrap();
@@ -864,8 +995,7 @@ mod tests {
864
995
  assert_eq!(algo, CongestionControlAlgorithm::Bbr2Gcongestion);
865
996
  assert!(recovery_for_alg(algo).gcongestion_enabled());
866
997
 
867
- let algo =
868
- CongestionControlAlgorithm::from_str("bbr2_gcongestion").unwrap();
998
+ let algo = CongestionControlAlgorithm::from_str("bbr2_gcongestion").unwrap();
869
999
  assert_eq!(algo, CongestionControlAlgorithm::Bbr2Gcongestion);
870
1000
  assert!(recovery_for_alg(algo).gcongestion_enabled());
871
1001
  }
@@ -878,10 +1008,138 @@ mod tests {
878
1008
  );
879
1009
  }
880
1010
 
1011
+ #[cfg(feature = "congestion_window_unchecked_available")]
1012
+ #[test]
1013
+ fn congestion_window_unchecked_discards_packet_space() {
1014
+ let mut config =
1015
+ Config::new(crate::PROTOCOL_VERSION).expect("create transport configuration");
1016
+ config.set_cc_algorithm(CongestionControlAlgorithm::CongestionWindowUnchecked);
1017
+ let packet_size = config.max_send_udp_payload_size;
1018
+ let window = packet_size * MINIMUM_WINDOW_PACKETS;
1019
+ config.set_unchecked_congestion_window(window);
1020
+ let mut recovery = Recovery::new(&config);
1021
+ let now = Instant::now();
1022
+ assert_eq!(recovery.cwnd(), window);
1023
+ assert_eq!(recovery.cwnd_available(), window);
1024
+ recovery.on_packet_sent(
1025
+ test_utils::helper_packet_sent(0, now, packet_size),
1026
+ packet::Epoch::Initial,
1027
+ HandshakeStatus::default(),
1028
+ now,
1029
+ "",
1030
+ );
1031
+ assert_eq!(recovery.bytes_in_flight(), packet_size);
1032
+ assert_eq!(recovery.cwnd(), window);
1033
+ assert_eq!(recovery.cwnd_available(), window - packet_size);
1034
+ recovery.on_pkt_num_space_discarded(
1035
+ packet::Epoch::Initial,
1036
+ HandshakeStatus::default(),
1037
+ now + Duration::from_secs(1),
1038
+ );
1039
+ assert_eq!(recovery.bytes_in_flight(), 0);
1040
+ assert_eq!(recovery.cwnd(), window);
1041
+ assert_eq!(recovery.cwnd_available(), window);
1042
+ }
1043
+
1044
+ #[cfg(feature = "congestion_window_unchecked_available")]
1045
+ #[test]
1046
+ fn congestion_window_unchecked_uses_configured_capacity() {
1047
+ let mut config =
1048
+ Config::new(crate::PROTOCOL_VERSION).expect("create transport configuration");
1049
+ config.set_cc_algorithm(CongestionControlAlgorithm::CongestionWindowUnchecked);
1050
+ let window = config.max_send_udp_payload_size * 2;
1051
+ config.set_unchecked_congestion_window(window);
1052
+ let mut recovery = Recovery::new(&config);
1053
+ let now = Instant::now();
1054
+
1055
+ assert_eq!(recovery.cwnd(), window);
1056
+ assert_eq!(recovery.cwnd_available(), window);
1057
+ for packet_number in 0..2 {
1058
+ recovery.on_packet_sent(
1059
+ test_utils::helper_packet_sent(
1060
+ packet_number,
1061
+ now,
1062
+ config.max_send_udp_payload_size,
1063
+ ),
1064
+ packet::Epoch::Application,
1065
+ HandshakeStatus::default(),
1066
+ now,
1067
+ "",
1068
+ );
1069
+ }
1070
+ assert_eq!(recovery.cwnd(), window);
1071
+ assert_eq!(recovery.cwnd_available(), 0);
1072
+ let mut acked = RangeSet::default();
1073
+ acked.insert(0..2);
1074
+ recovery
1075
+ .on_ack_received(
1076
+ &acked,
1077
+ 0,
1078
+ packet::Epoch::Application,
1079
+ HandshakeStatus::default(),
1080
+ now + Duration::from_millis(100),
1081
+ None,
1082
+ "",
1083
+ )
1084
+ .expect("acknowledge outstanding packets");
1085
+ assert_eq!(recovery.cwnd(), window);
1086
+ assert_eq!(recovery.cwnd_available(), window);
1087
+ }
1088
+
881
1089
  #[rstest]
882
- fn loss_on_pto(
883
- #[values("reno", "cubic", "bbr2_gcongestion")] cc_algorithm_name: &str,
1090
+ fn unchecked_window_configuration_does_not_change_other_algorithms(
1091
+ #[values("reno", "cubic", "bbr2_gcongestion")] algorithm: &str,
884
1092
  ) {
1093
+ let mut config =
1094
+ Config::new(crate::PROTOCOL_VERSION).expect("create transport configuration");
1095
+ config
1096
+ .set_cc_algorithm_name(algorithm)
1097
+ .expect("select congestion control algorithm");
1098
+ config.set_unchecked_congestion_window(40 * 1024 * 1024);
1099
+ let recovery = Recovery::new(&config);
1100
+ assert_eq!(
1101
+ recovery.cwnd(),
1102
+ config.max_send_udp_payload_size * config.initial_congestion_window_packets,
1103
+ );
1104
+ }
1105
+
1106
+ #[cfg(feature = "congestion_window_unchecked_available")]
1107
+ #[rstest]
1108
+ fn unchecked_window_is_fixed_across_mtu_updates(
1109
+ #[values(
1110
+ usize::MAX,
1111
+ MAX_SEND_UDP_PAYLOAD_SIZE * DEFAULT_INITIAL_CONGESTION_WINDOW_PACKETS,
1112
+ MAX_SEND_UDP_PAYLOAD_SIZE * DEFAULT_INITIAL_CONGESTION_WINDOW_PACKETS + 1
1113
+ )]
1114
+ window: usize,
1115
+ ) {
1116
+ let mut config =
1117
+ Config::new(crate::PROTOCOL_VERSION).expect("create transport configuration");
1118
+ config.set_cc_algorithm(CongestionControlAlgorithm::CongestionWindowUnchecked);
1119
+ config.set_max_send_udp_payload_size(MAX_SEND_UDP_PAYLOAD_SIZE);
1120
+ config.set_unchecked_congestion_window(window);
1121
+ let mut recovery = Recovery::new(&config);
1122
+
1123
+ recovery.pmtud_update_max_datagram_size(MAX_SEND_UDP_PAYLOAD_SIZE + 200);
1124
+ assert_eq!(recovery.cwnd(), window);
1125
+ assert_eq!(
1126
+ recovery.max_datagram_size(),
1127
+ MAX_SEND_UDP_PAYLOAD_SIZE + 200
1128
+ );
1129
+ recovery.update_max_datagram_size(MAX_SEND_UDP_PAYLOAD_SIZE);
1130
+ assert_eq!(recovery.cwnd(), window);
1131
+ assert_eq!(recovery.max_datagram_size(), MAX_SEND_UDP_PAYLOAD_SIZE);
1132
+ }
1133
+
1134
+ #[rstest]
1135
+ #[case::reno("reno")]
1136
+ #[case::cubic("cubic")]
1137
+ #[case::bbr2_gcongestion("bbr2_gcongestion")]
1138
+ #[cfg_attr(
1139
+ feature = "congestion_window_unchecked_available",
1140
+ case::congestion_window_unchecked("congestion_window_unchecked")
1141
+ )]
1142
+ fn loss_on_pto(#[case] cc_algorithm_name: &str) {
885
1143
  let mut cfg = Config::new(crate::PROTOCOL_VERSION).unwrap();
886
1144
  assert_eq!(cfg.set_cc_algorithm_name(cc_algorithm_name), Ok(()));
887
1145
 
@@ -1156,7 +1414,7 @@ mod tests {
1156
1414
  );
1157
1415
 
1158
1416
  assert_eq!(r.sent_packets_len(packet::Epoch::Application), 0);
1159
- if cc_algorithm_name == "reno" || cc_algorithm_name == "cubic" {
1417
+ if matches!(cc_algorithm_name, "reno" | "cubic") {
1160
1418
  assert!(r.startup_exit().is_some());
1161
1419
  assert_eq!(r.startup_exit().unwrap().reason, StartupExitReason::Loss);
1162
1420
  } else {
@@ -1165,9 +1423,14 @@ mod tests {
1165
1423
  }
1166
1424
 
1167
1425
  #[rstest]
1168
- fn loss_on_timer(
1169
- #[values("reno", "cubic", "bbr2_gcongestion")] cc_algorithm_name: &str,
1170
- ) {
1426
+ #[case::reno("reno")]
1427
+ #[case::cubic("cubic")]
1428
+ #[case::bbr2_gcongestion("bbr2_gcongestion")]
1429
+ #[cfg_attr(
1430
+ feature = "congestion_window_unchecked_available",
1431
+ case::congestion_window_unchecked("congestion_window_unchecked")
1432
+ )]
1433
+ fn loss_on_timer(#[case] cc_algorithm_name: &str) {
1171
1434
  let mut cfg = Config::new(crate::PROTOCOL_VERSION).unwrap();
1172
1435
  assert_eq!(cfg.set_cc_algorithm_name(cc_algorithm_name), Ok(()));
1173
1436
 
@@ -1352,7 +1615,7 @@ mod tests {
1352
1615
  );
1353
1616
 
1354
1617
  assert_eq!(r.sent_packets_len(packet::Epoch::Application), 0);
1355
- if cc_algorithm_name == "reno" || cc_algorithm_name == "cubic" {
1618
+ if matches!(cc_algorithm_name, "reno" | "cubic") {
1356
1619
  assert!(r.startup_exit().is_some());
1357
1620
  assert_eq!(r.startup_exit().unwrap().reason, StartupExitReason::Loss);
1358
1621
  } else {
@@ -1361,13 +1624,19 @@ mod tests {
1361
1624
  }
1362
1625
 
1363
1626
  #[rstest]
1364
- fn loss_on_reordering(
1365
- #[values("reno", "cubic", "bbr2_gcongestion")] cc_algorithm_name: &str,
1366
- ) {
1627
+ #[case::reno("reno")]
1628
+ #[case::cubic("cubic")]
1629
+ #[case::bbr2_gcongestion("bbr2_gcongestion")]
1630
+ #[cfg_attr(
1631
+ feature = "congestion_window_unchecked_available",
1632
+ case::congestion_window_unchecked("congestion_window_unchecked")
1633
+ )]
1634
+ fn loss_on_reordering(#[case] cc_algorithm_name: &str) {
1367
1635
  let mut cfg = Config::new(crate::PROTOCOL_VERSION).unwrap();
1368
1636
  assert_eq!(cfg.set_cc_algorithm_name(cc_algorithm_name), Ok(()));
1369
1637
 
1370
1638
  let mut r = Recovery::new(&cfg);
1639
+ let initial_cwnd = r.cwnd();
1371
1640
 
1372
1641
  let mut now = Instant::now();
1373
1642
 
@@ -1390,6 +1659,10 @@ mod tests {
1390
1659
  assert_eq!(r.sent_packets_len(packet::Epoch::Application), pkt_count);
1391
1660
  assert_eq!(r.bytes_in_flight(), pkt_count * 1000);
1392
1661
  assert_eq!(r.bytes_in_flight_duration(), Duration::ZERO);
1662
+ if cc_algorithm_name == "congestion_window_unchecked" {
1663
+ assert_eq!(r.cwnd(), usize::MAX);
1664
+ assert_eq!(r.cwnd_available(), usize::MAX - r.bytes_in_flight());
1665
+ }
1393
1666
  }
1394
1667
 
1395
1668
  // Wait for 10ms after sending.
@@ -1416,6 +1689,11 @@ mod tests {
1416
1689
  spurious_losses: 0,
1417
1690
  }
1418
1691
  );
1692
+ if cc_algorithm_name == "congestion_window_unchecked" {
1693
+ assert_eq!(r.cwnd(), initial_cwnd);
1694
+ assert_eq!(r.rtt(), Duration::from_millis(10));
1695
+ assert_eq!(r.min_rtt(), Some(Duration::from_millis(10)));
1696
+ }
1419
1697
  // Since we only remove packets from the back to avoid compaction, the
1420
1698
  // send length remains the same after receiving reordered ACKs
1421
1699
  assert_eq!(r.sent_packets_len(packet::Epoch::Application), 4);
@@ -1446,6 +1724,9 @@ mod tests {
1446
1724
  spurious_losses: 1,
1447
1725
  }
1448
1726
  );
1727
+ if cc_algorithm_name == "congestion_window_unchecked" {
1728
+ assert_eq!(r.cwnd(), initial_cwnd);
1729
+ }
1449
1730
  assert_eq!(r.sent_packets_len(packet::Epoch::Application), 0);
1450
1731
  assert_eq!(r.bytes_in_flight(), 0);
1451
1732
  assert_eq!(r.bytes_in_flight_duration(), Duration::from_millis(20));
@@ -1468,7 +1749,7 @@ mod tests {
1468
1749
  );
1469
1750
  assert_eq!(r.sent_packets_len(packet::Epoch::Application), 0);
1470
1751
 
1471
- if cc_algorithm_name == "reno" || cc_algorithm_name == "cubic" {
1752
+ if matches!(cc_algorithm_name, "reno" | "cubic") {
1472
1753
  assert!(r.startup_exit().is_some());
1473
1754
  assert_eq!(r.startup_exit().unwrap().reason, StartupExitReason::Loss);
1474
1755
  } else {
@@ -1481,9 +1762,7 @@ mod tests {
1481
1762
  // given the different algorithms but it would be ideal to merge and share
1482
1763
  // the logic.
1483
1764
  #[rstest]
1484
- fn time_thresholds_on_reordering(
1485
- #[values("bbr2_gcongestion")] cc_algorithm_name: &str,
1486
- ) {
1765
+ fn time_thresholds_on_reordering(#[values("bbr2_gcongestion")] cc_algorithm_name: &str) {
1487
1766
  let mut cfg = Config::new(crate::PROTOCOL_VERSION).unwrap();
1488
1767
  assert_eq!(cfg.set_cc_algorithm_name(cc_algorithm_name), Ok(()));
1489
1768
 
@@ -1491,9 +1770,9 @@ mod tests {
1491
1770
  let mut r = Recovery::new(&cfg);
1492
1771
  assert_eq!(r.rtt(), DEFAULT_INITIAL_RTT);
1493
1772
 
1494
- // Pick time between and above thresholds for testing threshold increase.
1773
+ // Choose times around the threshold to test its increase.
1495
1774
  //
1496
- //```
1775
+ // ```
1497
1776
  // between_thresh_ms
1498
1777
  // |
1499
1778
  // initial_thresh_ms | spurious_thresh_ms
@@ -1506,8 +1785,7 @@ mod tests {
1506
1785
  // Threshold gap time.
1507
1786
  const THRESH_GAP: Duration = Duration::from_millis(30);
1508
1787
  // Initial time theshold based on inital RTT.
1509
- let initial_thresh_ms =
1510
- DEFAULT_INITIAL_RTT.mul_f64(INITIAL_TIME_THRESHOLD);
1788
+ let initial_thresh_ms = DEFAULT_INITIAL_RTT.mul_f64(INITIAL_TIME_THRESHOLD);
1511
1789
  // The time threshold after spurious loss.
1512
1790
  let spurious_thresh_ms: Duration =
1513
1791
  DEFAULT_INITIAL_RTT.mul_f64(PACKET_REORDER_TIME_THRESHOLD);
@@ -1652,12 +1930,10 @@ mod tests {
1652
1930
  );
1653
1931
  }
1654
1932
 
1655
- // TODO: Implement enable_relaxed_loss_threshold and enable this test for the
1656
- // congestion module.
1933
+ // TODO: Implement `enable_relaxed_loss_threshold` and enable this test for
1934
+ // the congestion module.
1657
1935
  #[rstest]
1658
- fn relaxed_thresholds_on_reordering(
1659
- #[values("bbr2_gcongestion")] cc_algorithm_name: &str,
1660
- ) {
1936
+ fn relaxed_thresholds_on_reordering(#[values("bbr2_gcongestion")] cc_algorithm_name: &str) {
1661
1937
  let mut cfg = Config::new(crate::PROTOCOL_VERSION).unwrap();
1662
1938
  cfg.enable_relaxed_loss_threshold = true;
1663
1939
  assert_eq!(cfg.set_cc_algorithm_name(cc_algorithm_name), Ok(()));
@@ -1666,9 +1942,9 @@ mod tests {
1666
1942
  let mut r = Recovery::new(&cfg);
1667
1943
  assert_eq!(r.rtt(), DEFAULT_INITIAL_RTT);
1668
1944
 
1669
- // Pick time between and above thresholds for testing threshold increase.
1945
+ // Choose times around the threshold to test its increase.
1670
1946
  //
1671
- //```
1947
+ // ```
1672
1948
  // between_thresh_ms
1673
1949
  // |
1674
1950
  // initial_thresh_ms | spurious_thresh_ms
@@ -1680,8 +1956,7 @@ mod tests {
1680
1956
  // Threshold gap time.
1681
1957
  const THRESH_GAP: Duration = Duration::from_millis(30);
1682
1958
  // Initial time theshold based on inital RTT.
1683
- let initial_thresh_ms =
1684
- DEFAULT_INITIAL_RTT.mul_f64(INITIAL_TIME_THRESHOLD);
1959
+ let initial_thresh_ms = DEFAULT_INITIAL_RTT.mul_f64(INITIAL_TIME_THRESHOLD);
1685
1960
  // The time threshold after spurious loss.
1686
1961
  let spurious_thresh_ms: Duration =
1687
1962
  DEFAULT_INITIAL_RTT.mul_f64(PACKET_REORDER_TIME_THRESHOLD);
@@ -1841,8 +2116,7 @@ mod tests {
1841
2116
  //
1842
2117
  // Time threshold overhead should double.
1843
2118
  assert_eq!(r.pkt_thresh(), None);
1844
- let double_time_thresh_overhead =
1845
- 1.0 + 2.0 * INITIAL_TIME_THRESHOLD_OVERHEAD;
2119
+ let double_time_thresh_overhead = 1.0 + 2.0 * INITIAL_TIME_THRESHOLD_OVERHEAD;
1846
2120
  assert_eq!(r.time_thresh(), double_time_thresh_overhead);
1847
2121
  }
1848
2122
 
@@ -1851,8 +2125,7 @@ mod tests {
1851
2125
  #[values("reno", "cubic", "bbr2_gcongestion")] cc_algorithm_name: &str,
1852
2126
  #[values(false, true)] time_sent_set_to_now: bool,
1853
2127
  ) {
1854
- let pacing_enabled = cc_algorithm_name == "bbr2" ||
1855
- cc_algorithm_name == "bbr2_gcongestion";
2128
+ let pacing_enabled = cc_algorithm_name == "bbr2" || cc_algorithm_name == "bbr2_gcongestion";
1856
2129
 
1857
2130
  let mut cfg = Config::new(crate::PROTOCOL_VERSION).unwrap();
1858
2131
  assert_eq!(cfg.set_cc_algorithm_name(cc_algorithm_name), Ok(()));
@@ -2075,9 +2348,7 @@ mod tests {
2075
2348
  assert_eq!(
2076
2349
  r.get_packet_send_time(now) - now,
2077
2350
  if pacing_enabled {
2078
- Duration::from_secs_f64(
2079
- scale_factor * 12000.0 / pacing_rate as f64,
2080
- )
2351
+ Duration::from_secs_f64(scale_factor * 12000.0 / pacing_rate as f64)
2081
2352
  } else {
2082
2353
  Duration::ZERO
2083
2354
  }
@@ -2141,14 +2412,12 @@ mod tests {
2141
2412
  // When enabled, the pacer adds a 25msec delay to the packet
2142
2413
  // sends which will be applied to the sent times tracked by
2143
2414
  // the recovery module, bringing down RTT to 15msec.
2144
- let expected_min_rtt = if pacing_enabled &&
2145
- !time_sent_set_to_now &&
2146
- cfg!(feature = "internal")
2147
- {
2148
- reduced_rtt - Duration::from_millis(25)
2149
- } else {
2150
- reduced_rtt
2151
- };
2415
+ let expected_min_rtt =
2416
+ if pacing_enabled && !time_sent_set_to_now && cfg!(feature = "internal") {
2417
+ reduced_rtt - Duration::from_millis(25)
2418
+ } else {
2419
+ reduced_rtt
2420
+ };
2152
2421
 
2153
2422
  assert_eq!(r.sent_packets_len(packet::Epoch::Application), 1);
2154
2423
  assert_eq!(r.bytes_in_flight(), 1000);
@@ -2182,14 +2451,12 @@ mod tests {
2182
2451
 
2183
2452
  // Pacer adds 50msec delay to the second packet, resulting in
2184
2453
  // an effective RTT of 0.
2185
- let expected_min_rtt = if pacing_enabled &&
2186
- !time_sent_set_to_now &&
2187
- cfg!(feature = "internal")
2188
- {
2189
- Duration::from_millis(0)
2190
- } else {
2191
- reduced_rtt
2192
- };
2454
+ let expected_min_rtt =
2455
+ if pacing_enabled && !time_sent_set_to_now && cfg!(feature = "internal") {
2456
+ Duration::from_millis(0)
2457
+ } else {
2458
+ reduced_rtt
2459
+ };
2193
2460
  assert_eq!(r.sent_packets_len(packet::Epoch::Application), 0);
2194
2461
  assert_eq!(r.bytes_in_flight(), 0);
2195
2462
  assert_eq!(r.bytes_in_flight_duration(), initial_rtt + reduced_rtt);
@@ -2214,7 +2481,8 @@ mod tests {
2214
2481
  #[case::bw_estimate_increase_after_first_rtt(0.5, 0.5)]
2215
2482
  #[cfg(feature = "internal")]
2216
2483
  fn initial_pacing_rate_override(
2217
- #[case] initial_multipler: f64, #[case] expected_multiplier: f64,
2484
+ #[case] initial_multipler: f64,
2485
+ #[case] expected_multiplier: f64,
2218
2486
  ) {
2219
2487
  let rtt = Duration::from_millis(50);
2220
2488
  let bw = Bandwidth::from_bytes_and_time_delta(12000, rtt);
@@ -2333,16 +2601,8 @@ mod tests {
2333
2601
  acked.insert(0..2);
2334
2602
 
2335
2603
  assert_eq!(
2336
- r.on_ack_received(
2337
- &acked,
2338
- 25,
2339
- epoch,
2340
- HandshakeStatus::default(),
2341
- now,
2342
- None,
2343
- "",
2344
- )
2345
- .unwrap(),
2604
+ r.on_ack_received(&acked, 25, epoch, HandshakeStatus::default(), now, None, "",)
2605
+ .unwrap(),
2346
2606
  OnAckReceivedOutcome {
2347
2607
  lost_packets: 0,
2348
2608
  lost_bytes: 0,
@@ -2361,16 +2621,8 @@ mod tests {
2361
2621
  let mut acked = RangeSet::default();
2362
2622
  acked.insert(0..10);
2363
2623
  assert_eq!(
2364
- r.on_ack_received(
2365
- &acked,
2366
- 25,
2367
- epoch,
2368
- HandshakeStatus::default(),
2369
- now,
2370
- None,
2371
- "",
2372
- )
2373
- .unwrap(),
2624
+ r.on_ack_received(&acked, 25, epoch, HandshakeStatus::default(), now, None, "",)
2625
+ .unwrap(),
2374
2626
  OnAckReceivedOutcome {
2375
2627
  lost_packets: 0,
2376
2628
  lost_bytes: 0,
@@ -2386,9 +2638,7 @@ mod tests {
2386
2638
  }
2387
2639
 
2388
2640
  #[rstest]
2389
- fn pmtud_loss_on_timer(
2390
- #[values("reno", "cubic", "bbr2_gcongestion")] cc_algorithm_name: &str,
2391
- ) {
2641
+ fn pmtud_loss_on_timer(#[values("reno", "cubic", "bbr2_gcongestion")] cc_algorithm_name: &str) {
2392
2642
  let mut cfg = Config::new(crate::PROTOCOL_VERSION).unwrap();
2393
2643
  assert_eq!(cfg.set_cc_algorithm_name(cc_algorithm_name), Ok(()));
2394
2644
 
@@ -2556,9 +2806,7 @@ mod tests {
2556
2806
  // Modeling delivery_rate for gcongestion is non-trivial so we only test the
2557
2807
  // congestion specific algorithms.
2558
2808
  #[rstest]
2559
- fn congestion_delivery_rate(
2560
- #[values("reno", "cubic", "bbr2")] cc_algorithm_name: &str,
2561
- ) {
2809
+ fn congestion_delivery_rate(#[values("reno", "cubic", "bbr2")] cc_algorithm_name: &str) {
2562
2810
  let mut cfg = Config::new(crate::PROTOCOL_VERSION).unwrap();
2563
2811
  assert_eq!(cfg.set_cc_algorithm_name(cc_algorithm_name), Ok(()));
2564
2812
 
@@ -2616,9 +2864,14 @@ mod tests {
2616
2864
  }
2617
2865
 
2618
2866
  #[rstest]
2619
- fn acks_with_no_retransmittable_data(
2620
- #[values("reno", "cubic", "bbr2_gcongestion")] cc_algorithm_name: &str,
2621
- ) {
2867
+ #[case::reno("reno")]
2868
+ #[case::cubic("cubic")]
2869
+ #[case::bbr2_gcongestion("bbr2_gcongestion")]
2870
+ #[cfg_attr(
2871
+ feature = "congestion_window_unchecked_available",
2872
+ case::congestion_window_unchecked("congestion_window_unchecked")
2873
+ )]
2874
+ fn acks_with_no_retransmittable_data(#[case] cc_algorithm_name: &str) {
2622
2875
  let rtt = Duration::from_millis(100);
2623
2876
 
2624
2877
  let mut cfg = Config::new(crate::PROTOCOL_VERSION).unwrap();
@@ -2657,8 +2910,13 @@ mod tests {
2657
2910
  },
2658
2911
  );
2659
2912
  assert_eq!(r.get_packet_send_time(now), now);
2660
- assert_eq!(r.cwnd(), 12000);
2661
- assert_eq!(r.cwnd_available(), 8400);
2913
+ let initial_cwnd = if cc_algorithm_name == "congestion_window_unchecked" {
2914
+ usize::MAX
2915
+ } else {
2916
+ 12000
2917
+ };
2918
+ assert_eq!(r.cwnd(), initial_cwnd);
2919
+ assert_eq!(r.cwnd_available(), initial_cwnd - r.bytes_in_flight());
2662
2920
 
2663
2921
  // Wait 1 rtt for ACK.
2664
2922
  now += rtt;
@@ -2689,6 +2947,10 @@ mod tests {
2689
2947
  assert_eq!(r.bytes_in_flight(), 0);
2690
2948
  assert_eq!(r.bytes_in_flight_duration(), rtt);
2691
2949
  assert_eq!(r.rtt(), rtt);
2950
+ if cc_algorithm_name == "congestion_window_unchecked" {
2951
+ assert_eq!(r.cwnd(), usize::MAX);
2952
+ assert_eq!(r.min_rtt(), Some(rtt));
2953
+ }
2692
2954
 
2693
2955
  // Pacing rate is recalculated based on initial cwnd when the
2694
2956
  // first RTT estimate is available.
@@ -2744,18 +3006,12 @@ mod tests {
2744
3006
  assert_eq!(r.startup_exit(), None, "{iter}");
2745
3007
 
2746
3008
  // Unchanged metrics.
2747
- assert_eq!(
2748
- r.sent_packets_len(packet::Epoch::Application),
2749
- 0,
2750
- "{iter}"
2751
- );
3009
+ assert_eq!(r.sent_packets_len(packet::Epoch::Application), 0, "{iter}");
2752
3010
  assert_eq!(r.bytes_in_flight(), 0, "{iter}");
2753
3011
  assert_eq!(r.bytes_in_flight_duration(), rtt, "{iter}");
2754
3012
  assert_eq!(
2755
3013
  r.pacing_rate(),
2756
- if cc_algorithm_name == "bbr2_gcongestion" ||
2757
- cc_algorithm_name == "bbr2"
2758
- {
3014
+ if cc_algorithm_name == "bbr2_gcongestion" || cc_algorithm_name == "bbr2" {
2759
3015
  120000
2760
3016
  } else {
2761
3017
  0
@@ -2799,13 +3055,7 @@ mod tests {
2799
3055
  has_data: false,
2800
3056
  is_pmtud_probe: false,
2801
3057
  };
2802
- r.on_packet_sent(
2803
- p_initial,
2804
- packet::Epoch::Initial,
2805
- handshake_status,
2806
- now,
2807
- "",
2808
- );
3058
+ r.on_packet_sent(p_initial, packet::Epoch::Initial, handshake_status, now, "");
2809
3059
 
2810
3060
  // The timer should now be set for the Initial packet.
2811
3061
  assert!(r.loss_detection_timer().is_some());
@@ -2830,17 +3080,11 @@ mod tests {
2830
3080
  has_data: true,
2831
3081
  is_pmtud_probe: false,
2832
3082
  };
2833
- r.on_packet_sent(
2834
- p_app,
2835
- packet::Epoch::Application,
2836
- handshake_status,
2837
- now,
2838
- "",
2839
- );
3083
+ r.on_packet_sent(p_app, packet::Epoch::Application, handshake_status, now, "");
2840
3084
 
2841
3085
  // 3. Acknowledge the Initial packet.
2842
- // This empties the Initial space, but Application space still has data in
2843
- // flight.
3086
+ // This empties the Initial space, but Application space still has data
3087
+ // in flight.
2844
3088
  let mut ranges = RangeSet::default();
2845
3089
  ranges.insert(0..1);
2846
3090
  r.on_ack_received(
@@ -2916,8 +3160,7 @@ mod tests {
2916
3160
  r.on_loss_detection_timeout(HandshakeStatus::default(), now, "");
2917
3161
 
2918
3162
  assert_eq!(r.pto_count(), 1);
2919
- let frames_after_first_pto =
2920
- r.lost_frames_count(packet::Epoch::Application);
3163
+ let frames_after_first_pto = r.lost_frames_count(packet::Epoch::Application);
2921
3164
  assert_eq!(
2922
3165
  frames_after_first_pto, 1,
2923
3166
  "First PTO should add exactly 1 frame"
@@ -2935,8 +3178,7 @@ mod tests {
2935
3178
  r.on_loss_detection_timeout(HandshakeStatus::default(), now, "");
2936
3179
 
2937
3180
  assert_eq!(r.pto_count(), 2);
2938
- let frames_after_second_pto =
2939
- r.lost_frames_count(packet::Epoch::Application);
3181
+ let frames_after_second_pto = r.lost_frames_count(packet::Epoch::Application);
2940
3182
  assert_eq!(
2941
3183
  frames_after_second_pto, frames_after_first_pto,
2942
3184
  "Second PTO must NOT add duplicate frames (fix: `if \
@@ -2948,8 +3190,7 @@ mod tests {
2948
3190
  r.on_loss_detection_timeout(HandshakeStatus::default(), now, "");
2949
3191
 
2950
3192
  assert_eq!(r.pto_count(), 3);
2951
- let frames_after_third_pto =
2952
- r.lost_frames_count(packet::Epoch::Application);
3193
+ let frames_after_third_pto = r.lost_frames_count(packet::Epoch::Application);
2953
3194
  assert_eq!(
2954
3195
  frames_after_third_pto, frames_after_first_pto,
2955
3196
  "Third PTO must NOT add duplicate frames"