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
@@ -82,6 +82,7 @@ impl PathState {
82
82
 
83
83
  /// A path-specific event.
84
84
  #[derive(Clone, Debug, PartialEq, Eq)]
85
+ #[non_exhaustive]
85
86
  pub enum PathEvent {
86
87
  /// A new network path (local address, peer address) has been seen on a
87
88
  /// received packet. Note that this event is only triggered for servers, as
@@ -105,11 +106,7 @@ pub enum PathEvent {
105
106
  /// The stack observes that the Source Connection ID with the given sequence
106
107
  /// number, initially used by the peer over the first pair of `SocketAddr`s,
107
108
  /// is now reused over the second pair of `SocketAddr`s.
108
- ReusedSourceConnectionId(
109
- u64,
110
- (SocketAddr, SocketAddr),
111
- (SocketAddr, SocketAddr),
112
- ),
109
+ ReusedSourceConnectionId(u64, (SocketAddr, SocketAddr), (SocketAddr, SocketAddr)),
113
110
 
114
111
  /// The connection observed that the peer migrated over the network path
115
112
  /// denoted by the pair of `SocketAddr`, i.e., non-probing packets have been
@@ -117,6 +114,37 @@ pub enum PathEvent {
117
114
  ///
118
115
  /// Note that this event is only raised if the path has been validated.
119
116
  PeerMigrated(SocketAddr, SocketAddr),
117
+
118
+ /// The validated PMTU available for normal application traffic changed on
119
+ /// the network path between `local` and `peer`.
120
+ ///
121
+ /// This event is generated only while PMTUD is enabled. It reports the
122
+ /// largest successfully probed size, falling back to QUIC's minimum packet
123
+ /// size while no larger size is validated. Unvalidated probe sizes and the
124
+ /// initial minimum set when the path is created are not reported.
125
+ PmtuUpdated {
126
+ /// The path's local address.
127
+ local: SocketAddr,
128
+
129
+ /// The path's peer address.
130
+ peer: SocketAddr,
131
+
132
+ /// The current validated PMTU limit for normal application traffic.
133
+ pmtu: usize,
134
+ },
135
+ }
136
+
137
+ pub(crate) fn pmtu_event(
138
+ local: SocketAddr,
139
+ peer: SocketAddr,
140
+ old: usize,
141
+ new: usize,
142
+ ) -> Option<PathEvent> {
143
+ (old != new).then_some(PathEvent::PmtuUpdated {
144
+ local,
145
+ peer,
146
+ pmtu: new,
147
+ })
120
148
  }
121
149
 
122
150
  /// A network path on which QUIC packets can be sent.
@@ -229,9 +257,11 @@ impl Path {
229
257
  /// Create a new Path instance with the provided addresses, the remaining of
230
258
  /// the fields being set to their default value.
231
259
  pub fn new(
232
- local_addr: SocketAddr, peer_addr: SocketAddr,
260
+ local_addr: SocketAddr,
261
+ peer_addr: SocketAddr,
233
262
  recovery_config: &recovery::RecoveryConfig,
234
- path_challenge_recv_max_queue_len: usize, is_initial: bool,
263
+ path_challenge_recv_max_queue_len: usize,
264
+ is_initial: bool,
235
265
  config: Option<&Config>,
236
266
  ) -> Self {
237
267
  let (state, active_scid_seq, active_dcid_seq) = if is_initial {
@@ -243,8 +273,9 @@ impl Path {
243
273
  let pmtud = config.and_then(|c| {
244
274
  if c.pmtud {
245
275
  let maximum_supported_mtu: usize = std::cmp::min(
246
- // if the max_udp_payload_size doesn't fit into a usize, then
247
- // max_send_udp_payload_size must be smaller so use that
276
+ // if the max_udp_payload_size doesn't fit into a usize,
277
+ // then max_send_udp_payload_size must be smaller so use
278
+ // that
248
279
  c.local_transport_params
249
280
  .max_udp_payload_size
250
281
  .try_into()
@@ -270,9 +301,7 @@ impl Path {
270
301
  max_challenge_size: 0,
271
302
  probing_lost: 0,
272
303
  last_probe_lost_time: None,
273
- received_challenges: VecDeque::with_capacity(
274
- path_challenge_recv_max_queue_len,
275
- ),
304
+ received_challenges: VecDeque::with_capacity(path_challenge_recv_max_queue_len),
276
305
  received_challenges_max_len: path_challenge_recv_max_queue_len,
277
306
  sent_count: 0,
278
307
  recv_count: 0,
@@ -321,9 +350,7 @@ impl Path {
321
350
  /// Returns whether the path can be used to send non-probing packets.
322
351
  #[inline]
323
352
  pub fn usable(&self) -> bool {
324
- self.active() ||
325
- (self.state == PathState::Validated &&
326
- self.active_dcid_seq.is_some())
353
+ self.active() || (self.state == PathState::Validated && self.active_dcid_seq.is_some())
327
354
  }
328
355
 
329
356
  /// Returns whether the path is unused.
@@ -378,19 +405,23 @@ impl Path {
378
405
  }
379
406
 
380
407
  pub fn should_send_pmtu_probe(
381
- &mut self, hs_confirmed: bool, hs_done: bool, out_len: usize,
382
- is_closing: bool, frames_empty: bool,
408
+ &mut self,
409
+ hs_confirmed: bool,
410
+ hs_done: bool,
411
+ out_len: usize,
412
+ is_closing: bool,
413
+ frames_empty: bool,
383
414
  ) -> bool {
384
415
  let Some(pmtud) = self.pmtud.as_mut() else {
385
416
  return false;
386
417
  };
387
418
 
388
- (hs_confirmed && hs_done) &&
389
- self.recovery.cwnd_available() > pmtud.get_probe_size() &&
390
- out_len >= pmtud.get_probe_size() &&
391
- pmtud.should_probe() &&
392
- !is_closing &&
393
- frames_empty
419
+ (hs_confirmed && hs_done)
420
+ && self.recovery.cwnd_available() > pmtud.get_probe_size()
421
+ && out_len >= pmtud.get_probe_size()
422
+ && pmtud.should_probe()
423
+ && !is_closing
424
+ && frames_empty
394
425
  }
395
426
 
396
427
  pub fn on_challenge_sent(&mut self) {
@@ -399,9 +430,7 @@ impl Path {
399
430
  }
400
431
 
401
432
  /// Handles the sending of PATH_CHALLENGE.
402
- pub fn add_challenge_sent(
403
- &mut self, data: [u8; 8], pkt_size: usize, sent_time: Instant,
404
- ) {
433
+ pub fn add_challenge_sent(&mut self, data: [u8; 8], pkt_size: usize, sent_time: Instant) {
405
434
  self.on_challenge_sent();
406
435
  self.in_flight_challenges
407
436
  .push_back((data, pkt_size, sent_time));
@@ -439,8 +468,7 @@ impl Path {
439
468
  // The 4-tuple is reachable, but we didn't check Path MTU yet.
440
469
  self.promote_to(PathState::ValidatingMTU);
441
470
 
442
- self.max_challenge_size =
443
- std::cmp::max(self.max_challenge_size, challenge_size);
471
+ self.max_challenge_size = std::cmp::max(self.max_challenge_size, challenge_size);
444
472
 
445
473
  if self.state == PathState::ValidatingMTU {
446
474
  if self.max_challenge_size >= crate::MIN_CLIENT_INITIAL_LEN {
@@ -467,14 +495,15 @@ impl Path {
467
495
  }
468
496
 
469
497
  pub fn on_loss_detection_timeout(
470
- &mut self, handshake_status: HandshakeStatus, now: Instant,
471
- is_server: bool, trace_id: &str,
498
+ &mut self,
499
+ handshake_status: HandshakeStatus,
500
+ now: Instant,
501
+ is_server: bool,
502
+ trace_id: &str,
472
503
  ) -> OnLossDetectionTimeoutOutcome {
473
- let outcome = self.recovery.on_loss_detection_timeout(
474
- handshake_status,
475
- now,
476
- trace_id,
477
- );
504
+ let outcome = self
505
+ .recovery
506
+ .on_loss_detection_timeout(handshake_status, now, trace_id);
478
507
 
479
508
  let mut lost_probe_time = None;
480
509
  self.in_flight_challenges.retain(|(_, _, sent_time)| {
@@ -500,17 +529,17 @@ impl Path {
500
529
  } else {
501
530
  Some(last)
502
531
  }
503
- },
532
+ }
504
533
  None => {
505
534
  self.probing_lost += 1;
506
535
  Some(lost_probe_time)
507
- },
536
+ }
508
537
  };
509
538
  // As a server, if requesting a challenge is not
510
539
  // possible due to the amplification attack, declare the
511
540
  // validation as failed.
512
- if self.probing_lost >= crate::MAX_PROBING_TIMEOUTS ||
513
- (is_server && self.max_send_bytes < crate::MIN_PROBING_SIZE)
541
+ if self.probing_lost >= crate::MAX_PROBING_TIMEOUTS
542
+ || (is_server && self.max_send_bytes < crate::MIN_PROBING_SIZE)
514
543
  {
515
544
  self.on_failed_validation();
516
545
  } else {
@@ -528,19 +557,15 @@ impl Path {
528
557
  /// packets, and it is still OK to fully reinitialize the recovery module to
529
558
  /// pickup changes to congestion control config.
530
559
  pub fn can_reinit_recovery(&self) -> bool {
531
- // The recovery module can be reinitialized until the connection attempts
532
- // to send a packet with inflight data. The congestion
533
- // controller doesn't track anything interesting until inflight
534
- // data is sent. Handshake ACKs may be sent prior to arrival of
535
- // the full ClientHello, but the send of ACK only packets
536
- // shouldn't prevent the reinit of the recovery module.
537
- self.recovery.bytes_in_flight() == 0 &&
538
- self.recovery.bytes_in_flight_duration() == Duration::ZERO
560
+ // Recovery can be reinitialized until the connection sends in-flight
561
+ // data. The congestion controller has no relevant state before then.
562
+ // ACK-only packets sent before the full ClientHello arrives should not
563
+ // prevent reinitialization.
564
+ self.recovery.bytes_in_flight() == 0
565
+ && self.recovery.bytes_in_flight_duration() == Duration::ZERO
539
566
  }
540
567
 
541
- pub fn reinit_recovery(
542
- &mut self, recovery_config: &recovery::RecoveryConfig,
543
- ) {
568
+ pub fn reinit_recovery(&mut self, recovery_config: &recovery::RecoveryConfig) {
544
569
  self.recovery = recovery::Recovery::new_with_config(recovery_config)
545
570
  }
546
571
 
@@ -579,6 +604,7 @@ impl Path {
579
604
  .recovery
580
605
  .max_bandwidth()
581
606
  .map(Bandwidth::to_bytes_per_second),
607
+ rtt_persistent_jump_count: self.recovery.rtt_persistent_jump_count(),
582
608
  startup_exit: self.recovery.startup_exit(),
583
609
  }
584
610
  }
@@ -636,10 +662,9 @@ pub struct PathMap {
636
662
  impl PathMap {
637
663
  /// Creates a new `PathMap` with the initial provided `path` and a
638
664
  /// capacity limit.
639
- pub fn new(
640
- mut initial_path: Path, max_concurrent_paths: usize, is_server: bool,
641
- ) -> Self {
642
- let mut paths = Slab::with_capacity(1); // most connections only have one path
665
+ pub fn new(mut initial_path: Path, max_concurrent_paths: usize, is_server: bool) -> Self {
666
+ // Most connections only have one path.
667
+ let mut paths = Slab::with_capacity(1);
643
668
  let mut addrs_to_paths = BTreeMap::new();
644
669
 
645
670
  let local_addr = initial_path.local_addr;
@@ -734,6 +759,15 @@ impl PathMap {
734
759
  self.paths.iter_mut()
735
760
  }
736
761
 
762
+ /// Returns a mutable iterator over all existing paths and the path event
763
+ /// queue.
764
+ #[inline]
765
+ pub(crate) fn iter_mut_and_events(
766
+ &mut self,
767
+ ) -> (slab::IterMut<'_, Path>, &mut VecDeque<PathEvent>) {
768
+ (self.paths.iter_mut(), &mut self.events)
769
+ }
770
+
737
771
  /// Returns the number of existing paths.
738
772
  #[inline]
739
773
  pub fn len(&self) -> usize {
@@ -742,9 +776,7 @@ impl PathMap {
742
776
 
743
777
  /// Returns the `Path` identifier related to the provided `addrs`.
744
778
  #[inline]
745
- pub fn path_id_from_addrs(
746
- &self, addrs: &(SocketAddr, SocketAddr),
747
- ) -> Option<usize> {
779
+ pub fn path_id_from_addrs(&self, addrs: &(SocketAddr, SocketAddr)) -> Option<usize> {
748
780
  self.addrs_to_paths.get(addrs).copied()
749
781
  }
750
782
 
@@ -818,10 +850,8 @@ impl PathMap {
818
850
  .filter(|(_, p)| p.validation_failed() && !p.failure_notified);
819
851
 
820
852
  for (_, p) in validation_failed {
821
- self.events.push_back(PathEvent::FailedValidation(
822
- p.local_addr,
823
- p.peer_addr,
824
- ));
853
+ self.events
854
+ .push_back(PathEvent::FailedValidation(p.local_addr, p.peer_addr));
825
855
 
826
856
  p.failure_notified = true;
827
857
  }
@@ -840,8 +870,7 @@ impl PathMap {
840
870
  pub fn on_response_received(&mut self, data: [u8; 8]) -> Result<()> {
841
871
  let active_pid = self.get_active_path_id()?;
842
872
 
843
- let challenge_pending =
844
- self.iter_mut().find(|(_, p)| p.has_pending_challenge(data));
873
+ let challenge_pending = self.iter_mut().find(|(_, p)| p.has_pending_challenge(data));
845
874
 
846
875
  if let Some((pid, p)) = challenge_pending {
847
876
  if p.on_response_received(data) {
@@ -857,9 +886,7 @@ impl PathMap {
857
886
  // If this path was the candidate for migration, notifies the
858
887
  // application.
859
888
  if pid == active_pid && was_migrating {
860
- self.notify_event(PathEvent::PeerMigrated(
861
- local_addr, peer_addr,
862
- ));
889
+ self.notify_event(PathEvent::PeerMigrated(local_addr, peer_addr));
863
890
  }
864
891
  }
865
892
  }
@@ -907,10 +934,19 @@ impl PathMap {
907
934
 
908
935
  /// Configures path MTU discovery on all existing paths.
909
936
  pub fn set_discover_pmtu_on_existing_paths(
910
- &mut self, discover: bool, max_send_udp_payload_size: usize,
937
+ &mut self,
938
+ discover: bool,
939
+ max_send_udp_payload_size: usize,
911
940
  pmtud_max_probes: u8,
912
941
  ) {
913
942
  for (_, path) in self.paths.iter_mut() {
943
+ let old_pmtu = path
944
+ .pmtud
945
+ .as_ref()
946
+ .map_or(path.recovery.max_datagram_size(), |pmtud| {
947
+ pmtud.get_current_mtu()
948
+ });
949
+
914
950
  path.pmtud = if discover {
915
951
  Some(pmtud::Pmtud::new(
916
952
  max_send_udp_payload_size,
@@ -919,6 +955,17 @@ impl PathMap {
919
955
  } else {
920
956
  None
921
957
  };
958
+
959
+ if let Some(pmtud) = path.pmtud.as_ref() {
960
+ if let Some(event) = pmtu_event(
961
+ path.local_addr,
962
+ path.peer_addr,
963
+ old_pmtu,
964
+ pmtud.get_current_mtu(),
965
+ ) {
966
+ self.events.push_back(event);
967
+ }
968
+ }
922
969
  }
923
970
  }
924
971
  }
@@ -1020,6 +1067,9 @@ pub struct PathStats {
1020
1067
  /// it is currently only implemented for bbr2_gcongestion.
1021
1068
  pub max_bandwidth: Option<u64>,
1022
1069
 
1070
+ /// The total number of confirmed persistent RTT jump episodes.
1071
+ pub rtt_persistent_jump_count: u64,
1072
+
1023
1073
  /// Statistics from when a CCA first exited the startup phase.
1024
1074
  pub startup_exit: Option<StartupExit>,
1025
1075
  }
@@ -1040,7 +1090,14 @@ impl std::fmt::Debug for PathStats {
1040
1090
  write!(
1041
1091
  f,
1042
1092
  "recv={} sent={} lost={} retrans={} rtt={:?} min_rtt={:?} rttvar={:?} cwnd={}",
1043
- self.recv, self.sent, self.lost, self.retrans, self.rtt, self.min_rtt, self.rttvar, self.cwnd,
1093
+ self.recv,
1094
+ self.sent,
1095
+ self.lost,
1096
+ self.retrans,
1097
+ self.rtt,
1098
+ self.min_rtt,
1099
+ self.rttvar,
1100
+ self.cwnd,
1044
1101
  )?;
1045
1102
 
1046
1103
  write!(
@@ -1051,8 +1108,11 @@ impl std::fmt::Debug for PathStats {
1051
1108
 
1052
1109
  write!(
1053
1110
  f,
1054
- " stream_retrans_bytes={} pmtu={} delivery_rate={}",
1055
- self.stream_retrans_bytes, self.pmtu, self.delivery_rate,
1111
+ " stream_retrans_bytes={} pmtu={} delivery_rate={} rtt_persistent_jump_count={}",
1112
+ self.stream_retrans_bytes,
1113
+ self.pmtu,
1114
+ self.delivery_rate,
1115
+ self.rtt_persistent_jump_count,
1056
1116
  )
1057
1117
  }
1058
1118
  }
@@ -1060,6 +1120,7 @@ impl std::fmt::Debug for PathStats {
1060
1120
  #[cfg(test)]
1061
1121
  mod tests {
1062
1122
  use crate::rand;
1123
+ use crate::test_utils;
1063
1124
  use crate::MIN_CLIENT_INITIAL_LEN;
1064
1125
 
1065
1126
  use crate::recovery::RecoveryConfig;
@@ -1067,6 +1128,76 @@ mod tests {
1067
1128
 
1068
1129
  use super::*;
1069
1130
 
1131
+ #[test]
1132
+ fn pmtud_probe_respects_cwnd_during_pto() {
1133
+ let local = "127.0.0.1:1234".parse().unwrap();
1134
+ let peer = "127.0.0.1:4321".parse().unwrap();
1135
+ let mut config = Config::new(crate::PROTOCOL_VERSION).unwrap();
1136
+ config.discover_pmtu(true);
1137
+ config.set_max_send_udp_payload_size(1400);
1138
+ let recovery_config = RecoveryConfig::from_config(&config);
1139
+ let mut path = Path::new(
1140
+ local,
1141
+ peer,
1142
+ &recovery_config,
1143
+ config.path_challenge_recv_max_queue_len,
1144
+ true,
1145
+ Some(&config),
1146
+ );
1147
+ let now = Instant::now();
1148
+ let cwnd = path.recovery.cwnd();
1149
+
1150
+ path.recovery.on_packet_sent(
1151
+ test_utils::helper_packet_sent(0, now, cwnd),
1152
+ crate::packet::Epoch::Application,
1153
+ HandshakeStatus {
1154
+ has_handshake_keys: false,
1155
+ peer_verified_address: true,
1156
+ completed: true,
1157
+ },
1158
+ now,
1159
+ "",
1160
+ );
1161
+ path.recovery
1162
+ .inc_loss_probes(crate::packet::Epoch::Application);
1163
+
1164
+ assert!(path.pmtud.as_ref().unwrap().should_probe());
1165
+ assert!(!path.should_send_pmtu_probe(true, true, 1400, false, true));
1166
+ }
1167
+
1168
+ #[test]
1169
+ fn reinitializing_pmtud_notifies_fallback_limit() {
1170
+ let local = "127.0.0.1:1234".parse().unwrap();
1171
+ let peer = "127.0.0.1:4321".parse().unwrap();
1172
+ let mut config = Config::new(crate::PROTOCOL_VERSION).unwrap();
1173
+ config.discover_pmtu(true);
1174
+ config.set_max_send_udp_payload_size(1400);
1175
+ let recovery_config = RecoveryConfig::from_config(&config);
1176
+ let mut path = Path::new(
1177
+ local,
1178
+ peer,
1179
+ &recovery_config,
1180
+ config.path_challenge_recv_max_queue_len,
1181
+ true,
1182
+ Some(&config),
1183
+ );
1184
+ path.pmtud.as_mut().unwrap().successful_probe(1400);
1185
+ let mut paths = PathMap::new(path, 1, false);
1186
+
1187
+ paths.set_discover_pmtu_on_existing_paths(false, 1400, 1);
1188
+ assert_eq!(paths.pop_event(), None);
1189
+
1190
+ paths.set_discover_pmtu_on_existing_paths(true, 1400, 1);
1191
+ assert_eq!(
1192
+ paths.pop_event(),
1193
+ Some(PathEvent::PmtuUpdated {
1194
+ local,
1195
+ peer,
1196
+ pmtu: MIN_CLIENT_INITIAL_LEN,
1197
+ })
1198
+ );
1199
+ }
1200
+
1070
1201
  #[test]
1071
1202
  fn path_validation_limited_mtu() {
1072
1203
  let client_addr = "127.0.0.1:1234".parse().unwrap();
@@ -1103,8 +1234,7 @@ mod tests {
1103
1234
  assert!(path_mgr.get_mut(pid).unwrap().validation_requested());
1104
1235
  assert!(path_mgr.get_mut(pid).unwrap().probing_required());
1105
1236
 
1106
- // Fake sending of PathChallenge in a packet of MIN_CLIENT_INITIAL_LEN - 1
1107
- // bytes.
1237
+ // Send `PathChallenge` one byte below `MIN_CLIENT_INITIAL_LEN`.
1108
1238
  let data = rand::rand_u64().to_be_bytes();
1109
1239
  path_mgr.get_mut(pid).unwrap().add_challenge_sent(
1110
1240
  data,
@@ -84,9 +84,9 @@ impl Pmtud {
84
84
  /// Checks there are no probes in flight, that a PMTU has not been
85
85
  /// found, and that the minimum supported MTU has not been reached.
86
86
  pub fn should_probe(&self) -> bool {
87
- !self.in_flight &&
88
- self.pmtu.is_none() &&
89
- self.smallest_failed_probe_size != Some(MIN_PLPMTU)
87
+ !self.in_flight
88
+ && self.pmtu.is_none()
89
+ && self.smallest_failed_probe_size != Some(MIN_PLPMTU)
90
90
  }
91
91
 
92
92
  /// Sets the PMTUD probe size.
@@ -138,22 +138,22 @@ impl Pmtud {
138
138
  debug!("Found PMTU: {successful_probe_size}");
139
139
  self.set_pmtu(successful_probe_size);
140
140
  } else {
141
- self.probe_size =
142
- (successful_probe_size + failed_probe_size) / 2
141
+ self.probe_size = (successful_probe_size + failed_probe_size) / 2
143
142
  }
144
- },
143
+ }
145
144
 
146
- // With only failed probes, binary search between the smallest failed
147
- // probe and the minimum supported MTU
148
- (Some(failed_probe_size), None) =>
149
- self.probe_size = (MIN_PLPMTU + failed_probe_size) / 2,
145
+ // With only failed probes, binary search between the smallest
146
+ // failed probe and the minimum supported MTU
147
+ (Some(failed_probe_size), None) => {
148
+ self.probe_size = (MIN_PLPMTU + failed_probe_size) / 2
149
+ }
150
150
 
151
151
  // As the algorithm is optimistic in that the initial probe size
152
152
  // is the maximum supported MTU, then having only a successful probe
153
153
  // means the maximum supported MTU is <= PMTU
154
154
  (None, Some(successful_probe_size)) => {
155
155
  self.set_pmtu(successful_probe_size);
156
- },
156
+ }
157
157
 
158
158
  // Use the initial probe size if no record of success/failures
159
159
  (None, None) => self.probe_size = self.maximum_supported_mtu,
@@ -535,19 +535,21 @@ mod tests {
535
535
  let probe_size = pmtud.get_probe_size();
536
536
 
537
537
  if probe_size <= target_mtu {
538
- // First probe fails (random loss)
538
+ // The first probe fails due to random loss.
539
539
  pmtud.failed_probe(probe_size);
540
540
  assert_eq!(pmtud.probe_failure_count, 1);
541
541
 
542
- // Second probe succeeds
542
+ // The second probe succeeds.
543
543
  pmtud.successful_probe(probe_size);
544
- assert_eq!(pmtud.probe_failure_count, 0); // Reset on success
544
+ // A successful probe resets the failure count.
545
+ assert_eq!(pmtud.probe_failure_count, 0);
545
546
  } else {
546
- // Size exceeds MTU - all probes fail
547
+ // All probes fail because their size exceeds the MTU.
547
548
  let old_probe_size = probe_size;
548
549
  fail_probe_max_times(&mut pmtud, probe_size);
549
550
 
550
- // After max failures, probe_failure_count resets and size changes
551
+ // After the maximum failures, `probe_failure_count` resets and
552
+ // the probe size changes.
551
553
  assert_eq!(pmtud.probe_failure_count, 0);
552
554
  if pmtud.get_pmtu().is_none() {
553
555
  assert!(pmtud.get_probe_size() < old_probe_size);