rwebtransport 0.2.2 → 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 (99) hide show
  1. package/Cargo.lock +523 -140
  2. package/Cargo.toml +5 -5
  3. package/README.md +8 -4
  4. package/crates/echo-server/src/bin/gen-test-cert.rs +1 -1
  5. package/crates/native/Cargo.toml +2 -0
  6. package/crates/native/src/config.rs +69 -8
  7. package/crates/native/src/driver.rs +253 -90
  8. package/crates/native/src/lib.rs +80 -57
  9. package/crates/native/src/parser_memory.rs +203 -0
  10. package/crates/native/src/server.rs +215 -183
  11. package/crates/native/src/session.rs +1341 -243
  12. package/crates/native/src/test_support.rs +119 -0
  13. package/crates/wtcore/Cargo.toml +1 -0
  14. package/crates/wtcore/src/h3.rs +250 -46
  15. package/dist/index.js +218 -75
  16. package/dist/index.js.map +7 -1
  17. package/dist/index.mjs +214 -69
  18. package/dist/index.mjs.map +7 -1
  19. package/dist/native.d.ts +10 -4
  20. package/dist/server.d.ts +1 -0
  21. package/package.json +84 -78
  22. package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
  23. package/prebuilds/linux-arm64/rwebtransport.node +0 -0
  24. package/prebuilds/linux-x64/rwebtransport.node +0 -0
  25. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  26. package/scripts/build-linux-prebuilt.sh +46 -0
  27. package/scripts/build-ts.js +41 -0
  28. package/scripts/build.js +10 -3
  29. package/vendor/quiche/AGENTS.md +10 -0
  30. package/vendor/quiche/Cargo.lock +239 -248
  31. package/vendor/quiche/Cargo.toml +23 -10
  32. package/vendor/quiche/examples/Makefile +4 -4
  33. package/vendor/quiche/examples/client.rs +10 -28
  34. package/vendor/quiche/examples/http3-client.rs +20 -34
  35. package/vendor/quiche/examples/http3-server.rs +47 -78
  36. package/vendor/quiche/examples/server.rs +19 -49
  37. package/vendor/quiche/include/quiche.h +35 -4
  38. package/vendor/quiche/src/build.rs +17 -0
  39. package/vendor/quiche/src/cid.rs +129 -61
  40. package/vendor/quiche/src/crypto/boringssl.rs +98 -86
  41. package/vendor/quiche/src/crypto/mod.rs +64 -77
  42. package/vendor/quiche/src/dgram.rs +2 -3
  43. package/vendor/quiche/src/error.rs +22 -20
  44. package/vendor/quiche/src/ffi.rs +558 -280
  45. package/vendor/quiche/src/flowcontrol.rs +0 -7
  46. package/vendor/quiche/src/frame.rs +134 -135
  47. package/vendor/quiche/src/h3/ffi.rs +73 -60
  48. package/vendor/quiche/src/h3/frame.rs +70 -90
  49. package/vendor/quiche/src/h3/mod.rs +1024 -593
  50. package/vendor/quiche/src/h3/qpack/decoder.rs +248 -34
  51. package/vendor/quiche/src/h3/qpack/dynamic_table.rs +859 -0
  52. package/vendor/quiche/src/h3/qpack/encoder.rs +14 -17
  53. package/vendor/quiche/src/h3/qpack/mod.rs +48 -0
  54. package/vendor/quiche/src/h3/qpack/static_table.rs +86 -73
  55. package/vendor/quiche/src/h3/stream.rs +1009 -194
  56. package/vendor/quiche/src/lib.rs +1361 -1195
  57. package/vendor/quiche/src/minmax.rs +2 -6
  58. package/vendor/quiche/src/packet.rs +420 -552
  59. package/vendor/quiche/src/path.rs +202 -72
  60. package/vendor/quiche/src/pmtud.rs +18 -16
  61. package/vendor/quiche/src/ranges.rs +184 -82
  62. package/vendor/quiche/src/recovery/AGENTS.md +5 -2
  63. package/vendor/quiche/src/recovery/bandwidth.rs +59 -40
  64. package/vendor/quiche/src/recovery/bytes_in_flight.rs +2 -2
  65. package/vendor/quiche/src/recovery/congestion/cubic.rs +38 -47
  66. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +54 -60
  67. package/vendor/quiche/src/recovery/congestion/hystart.rs +6 -10
  68. package/vendor/quiche/src/recovery/congestion/mod.rs +110 -42
  69. package/vendor/quiche/src/recovery/congestion/prr.rs +4 -1
  70. package/vendor/quiche/src/recovery/congestion/recovery.rs +91 -95
  71. package/vendor/quiche/src/recovery/congestion/reno.rs +17 -12
  72. package/vendor/quiche/src/recovery/congestion/test_sender.rs +8 -27
  73. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +159 -247
  74. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +9 -14
  75. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +18 -15
  76. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +43 -28
  77. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +349 -76
  78. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +147 -195
  79. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +29 -27
  80. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min.rs +180 -0
  81. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min_tests.rs +221 -0
  82. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm.rs +395 -0
  83. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm_tests.rs +473 -0
  84. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/mod.rs +175 -0
  85. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +33 -26
  86. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +107 -60
  87. package/vendor/quiche/src/recovery/gcongestion/mod.rs +64 -11
  88. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +34 -25
  89. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +81 -86
  90. package/vendor/quiche/src/recovery/mod.rs +414 -173
  91. package/vendor/quiche/src/recovery/rtt.rs +8 -5
  92. package/vendor/quiche/src/stream/mod.rs +864 -133
  93. package/vendor/quiche/src/stream/recv_buf.rs +476 -172
  94. package/vendor/quiche/src/stream/send_buf.rs +343 -81
  95. package/vendor/quiche/src/test_utils.rs +78 -64
  96. package/vendor/quiche/src/tests.rs +2559 -1335
  97. package/vendor/quiche/src/tls/boringssl.rs +60 -63
  98. package/vendor/quiche/src/tls/mod.rs +146 -193
  99. package/vendor/quiche/src/transport_params.rs +87 -103
@@ -51,8 +51,7 @@ const LUMPY_PACING_SIZE: usize = 2;
51
51
 
52
52
  /// The minimum estimated client bandwidth below which the pacing sender will
53
53
  /// not allow bursts.
54
- const LUMPY_PACING_MIN_BANDWIDTH_KBPS: Bandwidth =
55
- Bandwidth::from_kbits_per_second(1_200);
54
+ const LUMPY_PACING_MIN_BANDWIDTH_KBPS: Bandwidth = Bandwidth::from_kbits_per_second(1_200);
56
55
 
57
56
  /// Configured maximum size of the burst coming out of quiescence. The burst is
58
57
  /// never larger than the current CWND in packets.
@@ -84,7 +83,9 @@ impl Pacer {
84
83
  /// implementation, and an optional throttling as specified by
85
84
  /// `max_pacing_rate`.
86
85
  pub(crate) fn new(
87
- enabled: bool, congestion: BBRv2, max_pacing_rate: Option<Bandwidth>,
86
+ enabled: bool,
87
+ congestion: BBRv2,
88
+ max_pacing_rate: Option<Bandwidth>,
88
89
  ) -> Self {
89
90
  Pacer {
90
91
  enabled,
@@ -123,8 +124,12 @@ impl Pacer {
123
124
  }
124
125
 
125
126
  pub fn on_packet_sent(
126
- &mut self, sent_time: Instant, bytes_in_flight: usize,
127
- packet_number: u64, bytes: usize, is_retransmissible: bool,
127
+ &mut self,
128
+ sent_time: Instant,
129
+ bytes_in_flight: usize,
130
+ packet_number: u64,
131
+ bytes: usize,
132
+ is_retransmissible: bool,
128
133
  rtt_stats: &RttStats,
129
134
  ) {
130
135
  self.sender.on_packet_sent(
@@ -141,9 +146,8 @@ impl Pacer {
141
146
 
142
147
  // If in recovery, the connection is not coming out of quiescence.
143
148
  if bytes_in_flight == 0 && !self.sender.is_in_recovery() {
144
- // Add more burst tokens anytime the connection is leaving quiescence,
145
- // but limit it to the equivalent of a single bulk write,
146
- // not exceeding the current CWND in packets.
149
+ // When leaving quiescence, replenish burst tokens up to one bulk
150
+ // write without exceeding the current CWND in packets.
147
151
  self.burst_tokens = self
148
152
  .initial_burst_size
149
153
  .min(self.sender.get_congestion_window_in_packets());
@@ -164,16 +168,14 @@ impl Pacer {
164
168
  .transfer_time(bytes as u64);
165
169
 
166
170
  if !self.pacing_limited || self.lumpy_tokens == 0 {
167
- // Reset lumpy_tokens_ if either application or cwnd throttles sending
168
- // or token runs out.
171
+ // Reset `lumpy_tokens` if the application or congestion window
172
+ // throttles sending, or if the token runs out.
169
173
  self.lumpy_tokens = 1.max(LUMPY_PACING_SIZE.min(
170
- (self.sender.get_congestion_window_in_packets() as f64 *
171
- LUMPY_PACING_CWND_FRACTION) as usize,
174
+ (self.sender.get_congestion_window_in_packets() as f64 * LUMPY_PACING_CWND_FRACTION)
175
+ as usize,
172
176
  ));
173
177
 
174
- if self.sender.bandwidth_estimate(rtt_stats) <
175
- LUMPY_PACING_MIN_BANDWIDTH_KBPS
176
- {
178
+ if self.sender.bandwidth_estimate(rtt_stats) < LUMPY_PACING_MIN_BANDWIDTH_KBPS {
177
179
  // Below 1.2Mbps, send 1 packet at once, because one full-sized
178
180
  // packet is about 10ms of queueing.
179
181
  self.lumpy_tokens = 1;
@@ -196,9 +198,15 @@ impl Pacer {
196
198
  #[allow(clippy::too_many_arguments)]
197
199
  #[inline]
198
200
  pub fn on_congestion_event(
199
- &mut self, rtt_updated: bool, prior_in_flight: usize,
200
- bytes_in_flight: usize, event_time: Instant, acked_packets: &[Acked],
201
- lost_packets: &[Lost], least_unacked: u64, rtt_stats: &RttStats,
201
+ &mut self,
202
+ rtt_updated: bool,
203
+ prior_in_flight: usize,
204
+ bytes_in_flight: usize,
205
+ event_time: Instant,
206
+ acked_packets: &[Acked],
207
+ lost_packets: &[Lost],
208
+ least_unacked: u64,
209
+ rtt_stats: &RttStats,
202
210
  recovery_stats: &mut RecoveryStats,
203
211
  ) {
204
212
  self.sender.on_congestion_event(
@@ -225,8 +233,7 @@ impl Pacer {
225
233
  if let Some(max_pacing_rate) = self.max_pacing_rate {
226
234
  if rtt_updated {
227
235
  let max_rate = max_pacing_rate * 1.25f32;
228
- let max_cwnd =
229
- max_rate.to_bytes_per_period(rtt_stats.smoothed_rtt);
236
+ let max_cwnd = max_rate.to_bytes_per_period(rtt_stats.smoothed_rtt);
230
237
  self.sender.limit_cwnd(max_cwnd as usize);
231
238
  }
232
239
  }
@@ -240,9 +247,7 @@ impl Pacer {
240
247
  self.sender.on_retransmission_timeout(packets_retransmitted)
241
248
  }
242
249
 
243
- pub fn pacing_rate(
244
- &self, bytes_in_flight: usize, rtt_stats: &RttStats,
245
- ) -> Bandwidth {
250
+ pub fn pacing_rate(&self, bytes_in_flight: usize, rtt_stats: &RttStats) -> Bandwidth {
246
251
  let sender_rate = self.sender.pacing_rate(bytes_in_flight, rtt_stats);
247
252
  match self.max_pacing_rate {
248
253
  Some(rate) if self.enabled => rate.min(sender_rate),
@@ -258,6 +263,10 @@ impl Pacer {
258
263
  self.sender.max_bandwidth()
259
264
  }
260
265
 
266
+ pub fn rtt_persistent_jump_count(&self) -> u64 {
267
+ self.sender.rtt_persistent_jump_count()
268
+ }
269
+
261
270
  #[cfg(feature = "qlog")]
262
271
  pub fn send_rate(&self) -> Option<Bandwidth> {
263
272
  self.sender.send_rate()
@@ -282,12 +291,12 @@ impl Pacer {
282
291
  self.sender.ssthresh()
283
292
  }
284
293
 
285
- #[cfg(test)]
294
+ #[cfg(any(test, feature = "qlog"))]
286
295
  pub fn is_app_limited(&self, bytes_in_flight: usize) -> bool {
287
296
  !self.is_cwnd_limited(bytes_in_flight)
288
297
  }
289
298
 
290
- #[cfg(test)]
299
+ #[cfg(any(test, feature = "qlog"))]
291
300
  fn is_cwnd_limited(&self, bytes_in_flight: usize) -> bool {
292
301
  !self.pacing_limited && self.sender.is_cwnd_limited(bytes_in_flight)
293
302
  }
@@ -38,7 +38,6 @@ use crate::recovery::INITIAL_PACKET_THRESHOLD;
38
38
  use crate::recovery::INITIAL_TIME_THRESHOLD;
39
39
  use crate::recovery::MAX_OUTSTANDING_NON_ACK_ELICITING;
40
40
  use crate::recovery::MAX_PACKET_THRESHOLD;
41
- use crate::recovery::MAX_PTO_EXPONENT;
42
41
  use crate::recovery::MAX_PTO_PROBES_COUNT;
43
42
  use crate::recovery::PACKET_REORDER_TIME_THRESHOLD;
44
43
 
@@ -173,8 +172,11 @@ impl RecoveryEpoch {
173
172
 
174
173
  // `peer_sent_ack_ranges` should not be used without validation.
175
174
  fn detect_and_remove_acked_packets(
176
- &mut self, peer_sent_ack_ranges: &RangeSet, newly_acked: &mut Vec<Acked>,
177
- skip_pn: Option<u64>, trace_id: &str,
175
+ &mut self,
176
+ peer_sent_ack_ranges: &RangeSet,
177
+ newly_acked: &mut Vec<Acked>,
178
+ skip_pn: Option<u64>,
179
+ trace_id: &str,
178
180
  ) -> Result<AckedDetectionResult> {
179
181
  newly_acked.clear();
180
182
 
@@ -214,9 +216,7 @@ impl RecoveryEpoch {
214
216
  .unwrap_or_else(|e| e)
215
217
  };
216
218
 
217
- for SentPacket { pkt_num, status } in
218
- self.sent_packets.range_mut(start..)
219
- {
219
+ for SentPacket { pkt_num, status } in self.sent_packets.range_mut(start..) {
220
220
  if *pkt_num < peer_sent_range.end {
221
221
  match status.ack() {
222
222
  SentStatus::Sent {
@@ -241,15 +241,14 @@ impl RecoveryEpoch {
241
241
  has_ack_eliciting |= ack_eliciting;
242
242
 
243
243
  trace!("{trace_id} packet newly acked {pkt_num}");
244
- },
244
+ }
245
245
 
246
- SentStatus::Acked => {},
246
+ SentStatus::Acked => {}
247
247
  SentStatus::Lost => {
248
248
  // An acked packet was already declared lost
249
249
  spurious_losses += 1;
250
- spurious_pkt_thresh
251
- .get_or_insert(largest_acked - *pkt_num + 1);
252
- },
250
+ spurious_pkt_thresh.get_or_insert(largest_acked - *pkt_num + 1);
251
+ }
253
252
  }
254
253
  } else {
255
254
  break;
@@ -268,7 +267,10 @@ impl RecoveryEpoch {
268
267
  }
269
268
 
270
269
  fn detect_and_remove_lost_packets(
271
- &mut self, loss_delay: Duration, pkt_thresh: Option<u64>, now: Instant,
270
+ &mut self,
271
+ loss_delay: Duration,
272
+ pkt_thresh: Option<u64>,
273
+ now: Instant,
272
274
  newly_lost: &mut Vec<Lost>,
273
275
  ) -> LossDetectionResult {
274
276
  newly_lost.clear();
@@ -407,12 +409,11 @@ struct LossThreshold {
407
409
 
408
410
  impl LossThreshold {
409
411
  fn new(recovery_config: &RecoveryConfig) -> Self {
410
- let time_thresh_overhead =
411
- if recovery_config.enable_relaxed_loss_threshold {
412
- Some(INITIAL_TIME_THRESHOLD_OVERHEAD)
413
- } else {
414
- None
415
- };
412
+ let time_thresh_overhead = if recovery_config.enable_relaxed_loss_threshold {
413
+ Some(INITIAL_TIME_THRESHOLD_OVERHEAD)
414
+ } else {
415
+ None
416
+ };
416
417
  LossThreshold {
417
418
  pkt_thresh: Some(INITIAL_PACKET_THRESHOLD),
418
419
  time_thresh: INITIAL_TIME_THRESHOLD,
@@ -442,7 +443,7 @@ impl LossThreshold {
442
443
 
443
444
  self.time_thresh = 1.0 + *time_thresh_overhead;
444
445
  }
445
- },
446
+ }
446
447
  None => {
447
448
  let new_packet_threshold = self
448
449
  .pkt_thresh
@@ -451,7 +452,7 @@ impl LossThreshold {
451
452
  self.pkt_thresh = Some(new_packet_threshold);
452
453
 
453
454
  self.time_thresh = PACKET_REORDER_TIME_THRESHOLD;
454
- },
455
+ }
455
456
  }
456
457
  }
457
458
  }
@@ -526,10 +527,7 @@ impl GRecovery {
526
527
 
527
528
  Some(Self {
528
529
  epochs: Default::default(),
529
- rtt_stats: RttStats::new(
530
- recovery_config.initial_rtt,
531
- recovery_config.max_ack_delay,
532
- ),
530
+ rtt_stats: RttStats::new(recovery_config.initial_rtt, recovery_config.max_ack_delay),
533
531
  recovery_stats: RecoveryStats::default(),
534
532
  loss_timer: Default::default(),
535
533
  pto_count: 0,
@@ -567,10 +565,11 @@ impl GRecovery {
567
565
  }
568
566
 
569
567
  fn detect_and_remove_lost_packets(
570
- &mut self, epoch: packet::Epoch, now: Instant,
568
+ &mut self,
569
+ epoch: packet::Epoch,
570
+ now: Instant,
571
571
  ) -> (usize, usize) {
572
- let loss_delay =
573
- self.rtt_stats.loss_delay(self.loss_thresh.time_thresh());
572
+ let loss_delay = self.rtt_stats.loss_delay(self.loss_thresh.time_thresh());
574
573
  let lost = &mut self.lost_reuse;
575
574
 
576
575
  let LossDetectionResult {
@@ -612,10 +611,11 @@ impl GRecovery {
612
611
  }
613
612
 
614
613
  fn pto_time_and_space(
615
- &self, handshake_status: HandshakeStatus, now: Instant,
614
+ &self,
615
+ handshake_status: HandshakeStatus,
616
+ now: Instant,
616
617
  ) -> (Option<Instant>, packet::Epoch) {
617
- let mut duration =
618
- self.pto() * 2_u32.pow(self.pto_count.min(MAX_PTO_EXPONENT));
618
+ let mut duration = self.pto() * 2_u32.saturating_pow(self.pto_count);
619
619
 
620
620
  // Arm PTO from now when there are no inflight packets.
621
621
  if self.bytes_in_flight.is_zero() {
@@ -630,9 +630,7 @@ impl GRecovery {
630
630
  let mut pto_space = packet::Epoch::Initial;
631
631
 
632
632
  // Iterate over all packet number spaces.
633
- for &e in packet::Epoch::epochs(
634
- packet::Epoch::Initial..=packet::Epoch::Application,
635
- ) {
633
+ for &e in packet::Epoch::epochs(packet::Epoch::Initial..=packet::Epoch::Application) {
636
634
  if self.epochs[e].pkts_in_flight == 0 {
637
635
  continue;
638
636
  }
@@ -644,8 +642,7 @@ impl GRecovery {
644
642
  }
645
643
 
646
644
  // Include max_ack_delay and backoff for Application Data.
647
- duration += self.rtt_stats.max_ack_delay *
648
- 2_u32.pow(self.pto_count.min(MAX_PTO_EXPONENT));
645
+ duration += self.rtt_stats.max_ack_delay * 2_u32.saturating_pow(self.pto_count);
649
646
  }
650
647
 
651
648
  let new_time = self.epochs[e]
@@ -661,25 +658,20 @@ impl GRecovery {
661
658
  (pto_timeout, pto_space)
662
659
  }
663
660
 
664
- fn set_loss_detection_timer(
665
- &mut self, handshake_status: HandshakeStatus, now: Instant,
666
- ) {
661
+ fn set_loss_detection_timer(&mut self, handshake_status: HandshakeStatus, now: Instant) {
667
662
  if let (Some(earliest_loss_time), _) = self.loss_time_and_space() {
668
663
  // Time threshold loss detection.
669
664
  self.loss_timer.update(earliest_loss_time);
670
665
  return;
671
666
  }
672
667
 
673
- if self.bytes_in_flight.is_zero() &&
674
- handshake_status.peer_verified_address
675
- {
668
+ if self.bytes_in_flight.is_zero() && handshake_status.peer_verified_address {
676
669
  self.loss_timer.clear();
677
670
  return;
678
671
  }
679
672
 
680
673
  // PTO timer.
681
- if let (Some(timeout), _) = self.pto_time_and_space(handshake_status, now)
682
- {
674
+ if let (Some(timeout), _) = self.pto_time_and_space(handshake_status, now) {
683
675
  self.loss_timer.update(timeout);
684
676
  } else {
685
677
  self.loss_timer.clear();
@@ -697,9 +689,8 @@ impl RecoveryOps for GRecovery {
697
689
  }
698
690
 
699
691
  fn should_elicit_ack(&self, epoch: packet::Epoch) -> bool {
700
- self.epochs[epoch].loss_probes > 0 ||
701
- self.outstanding_non_ack_eliciting >=
702
- MAX_OUTSTANDING_NON_ACK_ELICITING
692
+ self.epochs[epoch].loss_probes > 0
693
+ || self.outstanding_non_ack_eliciting >= MAX_OUTSTANDING_NON_ACK_ELICITING
703
694
  }
704
695
 
705
696
  fn next_acked_frame(&mut self, epoch: packet::Epoch) -> Option<frame::Frame> {
@@ -733,13 +724,16 @@ impl RecoveryOps for GRecovery {
733
724
  }
734
725
 
735
726
  fn ping_sent(&mut self, epoch: packet::Epoch) {
736
- self.epochs[epoch].loss_probes =
737
- self.epochs[epoch].loss_probes.saturating_sub(1);
727
+ self.epochs[epoch].loss_probes = self.epochs[epoch].loss_probes.saturating_sub(1);
738
728
  }
739
729
 
740
730
  fn on_packet_sent(
741
- &mut self, pkt: Sent, epoch: packet::Epoch,
742
- handshake_status: HandshakeStatus, now: Instant, trace_id: &str,
731
+ &mut self,
732
+ pkt: Sent,
733
+ epoch: packet::Epoch,
734
+ handshake_status: HandshakeStatus,
735
+ now: Instant,
736
+ trace_id: &str,
743
737
  ) {
744
738
  let time_sent = if self.time_sent_set_to_now {
745
739
  now
@@ -811,9 +805,14 @@ impl RecoveryOps for GRecovery {
811
805
 
812
806
  // `peer_sent_ack_ranges` should not be used without validation.
813
807
  fn on_ack_received(
814
- &mut self, peer_sent_ack_ranges: &RangeSet, ack_delay: u64,
815
- epoch: packet::Epoch, handshake_status: HandshakeStatus, now: Instant,
816
- skip_pn: Option<u64>, trace_id: &str,
808
+ &mut self,
809
+ peer_sent_ack_ranges: &RangeSet,
810
+ ack_delay: u64,
811
+ epoch: packet::Epoch,
812
+ handshake_status: HandshakeStatus,
813
+ now: Instant,
814
+ skip_pn: Option<u64>,
815
+ trace_id: &str,
817
816
  ) -> Result<OnAckReceivedOutcome> {
818
817
  let prior_in_flight = self.bytes_in_flight.get();
819
818
 
@@ -855,8 +854,7 @@ impl RecoveryOps for GRecovery {
855
854
  self.epochs[epoch].largest_acked_packet = Some(largest_acked_pkt_num);
856
855
 
857
856
  // Check if largest packet is newly acked.
858
- let update_rtt = largest_newly_acked.pkt_num == largest_acked_pkt_num &&
859
- has_ack_eliciting;
857
+ let update_rtt = largest_newly_acked.pkt_num == largest_acked_pkt_num && has_ack_eliciting;
860
858
  if update_rtt {
861
859
  let latest_rtt = now - largest_newly_acked.time_sent;
862
860
  self.rtt_stats.update_rtt(
@@ -867,8 +865,7 @@ impl RecoveryOps for GRecovery {
867
865
  );
868
866
  }
869
867
 
870
- let (lost_bytes, lost_packets) =
871
- self.detect_and_remove_lost_packets(epoch, now);
868
+ let (lost_bytes, lost_packets) = self.detect_and_remove_lost_packets(epoch, now);
872
869
 
873
870
  self.pacer.on_congestion_event(
874
871
  update_rtt,
@@ -898,7 +895,9 @@ impl RecoveryOps for GRecovery {
898
895
  }
899
896
 
900
897
  fn on_loss_detection_timeout(
901
- &mut self, handshake_status: HandshakeStatus, now: Instant,
898
+ &mut self,
899
+ handshake_status: HandshakeStatus,
900
+ now: Instant,
902
901
  trace_id: &str,
903
902
  ) -> OnLossDetectionTimeoutOutcome {
904
903
  let (earliest_loss_time, epoch) = self.loss_time_and_space();
@@ -906,8 +905,7 @@ impl RecoveryOps for GRecovery {
906
905
  if earliest_loss_time.is_some() {
907
906
  let prior_in_flight = self.bytes_in_flight.get();
908
907
 
909
- let (lost_bytes, lost_packets) =
910
- self.detect_and_remove_lost_packets(epoch, now);
908
+ let (lost_bytes, lost_packets) = self.detect_and_remove_lost_packets(epoch, now);
911
909
 
912
910
  self.pacer.on_congestion_event(
913
911
  false,
@@ -1008,7 +1006,9 @@ impl RecoveryOps for GRecovery {
1008
1006
  }
1009
1007
 
1010
1008
  fn on_pkt_num_space_discarded(
1011
- &mut self, epoch: packet::Epoch, handshake_status: HandshakeStatus,
1009
+ &mut self,
1010
+ epoch: packet::Epoch,
1011
+ handshake_status: HandshakeStatus,
1012
1012
  now: Instant,
1013
1013
  ) {
1014
1014
  let epoch = &mut self.epochs[epoch];
@@ -1018,10 +1018,12 @@ impl RecoveryOps for GRecovery {
1018
1018
  }
1019
1019
 
1020
1020
  fn on_path_change(
1021
- &mut self, epoch: packet::Epoch, now: Instant, _trace_id: &str,
1021
+ &mut self,
1022
+ epoch: packet::Epoch,
1023
+ now: Instant,
1024
+ _trace_id: &str,
1022
1025
  ) -> (usize, usize) {
1023
- let (lost_bytes, lost_packets) =
1024
- self.detect_and_remove_lost_packets(epoch, now);
1026
+ let (lost_bytes, lost_packets) = self.detect_and_remove_lost_packets(epoch, now);
1025
1027
 
1026
1028
  (lost_packets, lost_bytes)
1027
1029
  }
@@ -1035,11 +1037,6 @@ impl RecoveryOps for GRecovery {
1035
1037
  }
1036
1038
 
1037
1039
  fn cwnd_available(&self) -> usize {
1038
- // Ignore cwnd when sending probe packets.
1039
- if self.epochs.iter().any(|e| e.loss_probes > 0) {
1040
- return usize::MAX;
1041
- }
1042
-
1043
1040
  self.cwnd().saturating_sub(self.bytes_in_flight.get())
1044
1041
  }
1045
1042
 
@@ -1073,6 +1070,10 @@ impl RecoveryOps for GRecovery {
1073
1070
  Some(self.pacer.max_bandwidth())
1074
1071
  }
1075
1072
 
1073
+ fn rtt_persistent_jump_count(&self) -> u64 {
1074
+ self.pacer.rtt_persistent_jump_count()
1075
+ }
1076
+
1076
1077
  /// Statistics from when a CCA first exited the startup phase.
1077
1078
  fn startup_exit(&self) -> Option<StartupExit> {
1078
1079
  self.recovery_stats.startup_exit
@@ -1088,9 +1089,7 @@ impl RecoveryOps for GRecovery {
1088
1089
  }
1089
1090
 
1090
1091
  fn update_max_datagram_size(&mut self, new_max_datagram_size: usize) {
1091
- self.pmtud_update_max_datagram_size(
1092
- self.max_datagram_size.min(new_max_datagram_size),
1093
- )
1092
+ self.pmtud_update_max_datagram_size(self.max_datagram_size.min(new_max_datagram_size))
1094
1093
  }
1095
1094
 
1096
1095
  // FIXME only used by gcongestion
@@ -1098,7 +1097,6 @@ impl RecoveryOps for GRecovery {
1098
1097
  self.pacer.on_app_limited(self.bytes_in_flight.get())
1099
1098
  }
1100
1099
 
1101
- #[cfg(test)]
1102
1100
  fn sent_packets_len(&self, epoch: packet::Epoch) -> usize {
1103
1101
  self.epochs[epoch].sent_packets.len()
1104
1102
  }
@@ -1145,7 +1143,9 @@ impl RecoveryOps for GRecovery {
1145
1143
 
1146
1144
  #[cfg(test)]
1147
1145
  fn detect_lost_packets_for_test(
1148
- &mut self, epoch: packet::Epoch, now: Instant,
1146
+ &mut self,
1147
+ epoch: packet::Epoch,
1148
+ now: Instant,
1149
1149
  ) -> (usize, usize) {
1150
1150
  let ret = self.detect_and_remove_lost_packets(epoch, now);
1151
1151
  self.epochs[epoch].drain_acked_and_lost_packets();
@@ -1157,7 +1157,7 @@ impl RecoveryOps for GRecovery {
1157
1157
  self.epochs[epoch].test_largest_sent_pkt_num_on_path
1158
1158
  }
1159
1159
 
1160
- #[cfg(test)]
1160
+ #[cfg(any(test, feature = "qlog"))]
1161
1161
  fn app_limited(&self) -> bool {
1162
1162
  self.pacer.is_app_limited(self.bytes_in_flight.get())
1163
1163
  }
@@ -1211,15 +1211,14 @@ impl RecoveryOps for GRecovery {
1211
1211
  lost_packets: Some(self.lost_count as u64),
1212
1212
  lost_bytes: Some(self.bytes_lost),
1213
1213
  pto_count: Some(self.pto_count),
1214
+ app_limited: Some(self.app_limited()),
1214
1215
  };
1215
1216
 
1216
1217
  self.qlog_metrics.maybe_update(qlog_metrics)
1217
1218
  }
1218
1219
 
1219
1220
  #[cfg(feature = "qlog")]
1220
- fn get_updated_qlog_cc_state(
1221
- &mut self, now: Instant,
1222
- ) -> Option<&'static str> {
1221
+ fn get_updated_qlog_cc_state(&mut self, now: Instant) -> Option<&'static str> {
1223
1222
  let cc_state = self.state_str(now);
1224
1223
  if cc_state != self.qlog_prev_cc_state {
1225
1224
  self.qlog_prev_cc_state = cc_state;
@@ -1284,10 +1283,7 @@ mod tests {
1284
1283
  loss_thresh.on_spurious_loss(packet_gap);
1285
1284
 
1286
1285
  // Packet threshold only increases once the packet gap increases.
1287
- assert_eq!(
1288
- loss_thresh.pkt_thresh().unwrap(),
1289
- INITIAL_PACKET_THRESHOLD
1290
- );
1286
+ assert_eq!(loss_thresh.pkt_thresh().unwrap(), INITIAL_PACKET_THRESHOLD);
1291
1287
  assert_eq!(loss_thresh.time_thresh(), PACKET_REORDER_TIME_THRESHOLD);
1292
1288
  }
1293
1289
 
@@ -1345,11 +1341,10 @@ mod tests {
1345
1341
  for subsequent_loss_count in 1..100 {
1346
1342
  // Double the overhead until it caps at `2.0`.
1347
1343
  //
1348
- // It takes `3` rounds of doubling for INITIAL_TIME_THRESHOLD_OVERHEAD
1349
- // to equal `1.0`.
1344
+ // The initial time-threshold overhead reaches `1.0` after three
1345
+ // rounds of doubling.
1350
1346
  let new_time_threshold = if subsequent_loss_count <= 3 {
1351
- 1.0 + INITIAL_TIME_THRESHOLD_OVERHEAD *
1352
- 2_f64.powi(subsequent_loss_count as i32)
1347
+ 1.0 + INITIAL_TIME_THRESHOLD_OVERHEAD * 2_f64.powi(subsequent_loss_count as i32)
1353
1348
  } else {
1354
1349
  2.0
1355
1350
  };