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
@@ -113,6 +113,10 @@ pub struct Congestion {
113
113
  /// Initial congestion window size in terms of packet count.
114
114
  pub(crate) initial_congestion_window_packets: usize,
115
115
 
116
+ #[cfg(feature = "congestion_window_unchecked_available")]
117
+ /// Fixed congestion window in bytes for the unchecked controller.
118
+ pub(crate) unchecked_congestion_window: usize,
119
+
116
120
  max_datagram_size: usize,
117
121
 
118
122
  pub(crate) lost_count: usize,
@@ -122,8 +126,8 @@ pub struct Congestion {
122
126
 
123
127
  impl Congestion {
124
128
  pub(crate) fn from_config(recovery_config: &RecoveryConfig) -> Self {
125
- let initial_congestion_window = recovery_config.max_send_udp_payload_size *
126
- recovery_config.initial_congestion_window_packets;
129
+ let initial_congestion_window = recovery_config.max_send_udp_payload_size
130
+ * recovery_config.initial_congestion_window_packets;
127
131
 
128
132
  let mut cc = Congestion {
129
133
  congestion_window: initial_congestion_window,
@@ -144,8 +148,9 @@ impl Congestion {
144
148
 
145
149
  lost_count: 0,
146
150
 
147
- initial_congestion_window_packets: recovery_config
148
- .initial_congestion_window_packets,
151
+ initial_congestion_window_packets: recovery_config.initial_congestion_window_packets,
152
+ #[cfg(feature = "congestion_window_unchecked_available")]
153
+ unchecked_congestion_window: recovery_config.unchecked_congestion_window,
149
154
 
150
155
  max_datagram_size: recovery_config.max_send_udp_payload_size,
151
156
 
@@ -157,8 +162,7 @@ impl Congestion {
157
162
 
158
163
  prr: prr::PRR::default(),
159
164
 
160
- enable_cubic_idle_restart_fix: recovery_config
161
- .enable_cubic_idle_restart_fix,
165
+ enable_cubic_idle_restart_fix: recovery_config.enable_cubic_idle_restart_fix,
162
166
  };
163
167
 
164
168
  (cc.cc_ops.on_init)(&mut cc);
@@ -168,8 +172,7 @@ impl Congestion {
168
172
 
169
173
  pub(crate) fn in_congestion_recovery(&self, sent_time: Instant) -> bool {
170
174
  match self.congestion_recovery_start_time {
171
- Some(congestion_recovery_start_time) =>
172
- sent_time <= congestion_recovery_start_time,
175
+ Some(congestion_recovery_start_time) => sent_time <= congestion_recovery_start_time,
173
176
 
174
177
  None => false,
175
178
  }
@@ -194,22 +197,23 @@ impl Congestion {
194
197
 
195
198
  #[allow(clippy::too_many_arguments)]
196
199
  pub(crate) fn on_packet_sent(
197
- &mut self, bytes_in_flight: usize, sent_bytes: usize, now: Instant,
198
- pkt: &mut Sent, bytes_lost: u64, in_flight: bool,
200
+ &mut self,
201
+ bytes_in_flight: usize,
202
+ sent_bytes: usize,
203
+ now: Instant,
204
+ pkt: &mut Sent,
205
+ bytes_lost: u64,
206
+ in_flight: bool,
199
207
  ) {
200
208
  if in_flight {
201
- self.update_app_limited(
202
- (bytes_in_flight + sent_bytes) < self.congestion_window,
203
- );
209
+ self.update_app_limited((bytes_in_flight + sent_bytes) < self.congestion_window);
204
210
 
205
211
  (self.cc_ops.on_packet_sent)(self, sent_bytes, bytes_in_flight, now);
206
212
 
207
213
  self.prr.on_packet_sent(sent_bytes);
208
214
 
209
215
  // HyStart++: Start of the round in a slow start.
210
- if self.hystart.enabled() &&
211
- self.congestion_window < self.ssthresh.get()
212
- {
216
+ if self.hystart.enabled() && self.congestion_window < self.ssthresh.get() {
213
217
  self.hystart.start_round(pkt.pkt_num);
214
218
  }
215
219
  }
@@ -222,8 +226,11 @@ impl Congestion {
222
226
  }
223
227
 
224
228
  pub(crate) fn on_packets_acked(
225
- &mut self, bytes_in_flight: usize, acked: &mut Vec<Acked>,
226
- rtt_stats: &RttStats, now: Instant,
229
+ &mut self,
230
+ bytes_in_flight: usize,
231
+ acked: &mut Vec<Acked>,
232
+ rtt_stats: &RttStats,
233
+ now: Instant,
227
234
  ) {
228
235
  // Update delivery rate sample per acked packet.
229
236
  for pkt in acked.iter() {
@@ -234,25 +241,18 @@ impl Congestion {
234
241
  self.delivery_rate.generate_rate_sample(*rtt_stats.min_rtt);
235
242
 
236
243
  // Call congestion control hooks.
237
- (self.cc_ops.on_packets_acked)(
238
- self,
239
- bytes_in_flight,
240
- acked,
241
- now,
242
- rtt_stats,
243
- );
244
+ (self.cc_ops.on_packets_acked)(self, bytes_in_flight, acked, now, rtt_stats);
244
245
  }
245
246
  }
246
247
 
247
248
  pub(crate) struct CongestionControlOps {
248
249
  pub on_init: fn(r: &mut Congestion),
249
250
 
250
- pub on_packet_sent: fn(
251
- r: &mut Congestion,
252
- sent_bytes: usize,
253
- bytes_in_flight: usize,
254
- now: Instant,
255
- ),
251
+ /// Updates controller state after the packet-size limit changes.
252
+ pub on_mtu_update: fn(congestion: &mut Congestion),
253
+
254
+ pub on_packet_sent:
255
+ fn(r: &mut Congestion, sent_bytes: usize, bytes_in_flight: usize, now: Instant),
256
256
 
257
257
  pub on_packets_acked: fn(
258
258
  r: &mut Congestion,
@@ -277,10 +277,29 @@ pub(crate) struct CongestionControlOps {
277
277
  #[cfg(feature = "qlog")]
278
278
  pub state_str: fn(r: &Congestion, now: Instant) -> &'static str,
279
279
 
280
- pub debug_fmt: fn(
281
- r: &Congestion,
282
- formatter: &mut std::fmt::Formatter,
283
- ) -> std::fmt::Result,
280
+ pub debug_fmt: fn(r: &Congestion, formatter: &mut std::fmt::Formatter) -> std::fmt::Result,
281
+ }
282
+
283
+ #[cfg(feature = "congestion_window_unchecked_available")]
284
+ static CONGESTION_WINDOW_UNCHECKED: CongestionControlOps = CongestionControlOps {
285
+ on_init: reset_unchecked_congestion_window,
286
+ on_mtu_update: reset_unchecked_congestion_window,
287
+ on_packet_sent: |congestion, _, _, _| reset_unchecked_congestion_window(congestion),
288
+ on_packets_acked: |congestion, _, _, _, _| reset_unchecked_congestion_window(congestion),
289
+ congestion_event: |congestion, _, _, _, _| reset_unchecked_congestion_window(congestion),
290
+ checkpoint: reset_unchecked_congestion_window,
291
+ rollback: |congestion| {
292
+ reset_unchecked_congestion_window(congestion);
293
+ true
294
+ },
295
+ #[cfg(feature = "qlog")]
296
+ state_str: |_, _| "congestion_window_unchecked",
297
+ debug_fmt: |_, _| Ok(()),
298
+ };
299
+
300
+ #[cfg(feature = "congestion_window_unchecked_available")]
301
+ fn reset_unchecked_congestion_window(congestion: &mut Congestion) {
302
+ congestion.congestion_window = congestion.unchecked_congestion_window;
284
303
  }
285
304
 
286
305
  impl From<CongestionControlAlgorithm> for &'static CongestionControlOps {
@@ -293,6 +312,8 @@ impl From<CongestionControlAlgorithm> for &'static CongestionControlOps {
293
312
  // LegacyRecovery never gets a RecoveryConfig with the
294
313
  // Bbr2Gcongestion algorithm.
295
314
  CongestionControlAlgorithm::Bbr2Gcongestion => unreachable!(),
315
+ #[cfg(feature = "congestion_window_unchecked_available")]
316
+ CongestionControlAlgorithm::CongestionWindowUnchecked => &CONGESTION_WINDOW_UNCHECKED,
296
317
  }
297
318
  }
298
319
  }
@@ -300,6 +321,57 @@ impl From<CongestionControlAlgorithm> for &'static CongestionControlOps {
300
321
  #[cfg(test)]
301
322
  mod tests {
302
323
  use super::*;
324
+ #[cfg(feature = "congestion_window_unchecked_available")]
325
+ use crate::test_utils;
326
+ #[cfg(feature = "congestion_window_unchecked_available")]
327
+ use crate::Config;
328
+ #[cfg(feature = "congestion_window_unchecked_available")]
329
+ use rstest::rstest;
330
+ #[cfg(feature = "congestion_window_unchecked_available")]
331
+ use std::time::Duration;
332
+
333
+ #[cfg(feature = "congestion_window_unchecked_available")]
334
+ #[rstest]
335
+ fn unchecked_window_is_restored_by_callbacks(
336
+ #[values(usize::MAX, 40 * 1024 * 1024)] window: usize,
337
+ ) {
338
+ let mut config =
339
+ Config::new(crate::PROTOCOL_VERSION).expect("create transport configuration");
340
+ config.set_cc_algorithm(CongestionControlAlgorithm::CongestionWindowUnchecked);
341
+ config.set_unchecked_congestion_window(window);
342
+ let mut congestion = Congestion::from_config(&RecoveryConfig::from_config(&config));
343
+ assert_eq!(congestion.congestion_window(), window);
344
+
345
+ let callbacks: [fn(&mut Congestion); 5] = [
346
+ |congestion| {
347
+ (congestion.cc_ops.on_packet_sent)(congestion, 1_200, 0, Instant::now());
348
+ },
349
+ |congestion| {
350
+ (congestion.cc_ops.on_packets_acked)(
351
+ congestion,
352
+ 0,
353
+ &mut Vec::new(),
354
+ Instant::now(),
355
+ &RttStats::new(Duration::from_millis(100), Duration::from_millis(25)),
356
+ );
357
+ },
358
+ |congestion| {
359
+ let now = Instant::now();
360
+ let packet = test_utils::helper_packet_sent(0, now, 1_200);
361
+ (congestion.cc_ops.congestion_event)(congestion, 1_200, 1_200, &packet, now);
362
+ },
363
+ |congestion| (congestion.cc_ops.checkpoint)(congestion),
364
+ |congestion| {
365
+ assert!((congestion.cc_ops.rollback)(congestion));
366
+ },
367
+ ];
368
+
369
+ for callback in callbacks {
370
+ congestion.congestion_window = 0;
371
+ callback(&mut congestion);
372
+ assert_eq!(congestion.congestion_window(), window);
373
+ }
374
+ }
303
375
 
304
376
  #[test]
305
377
  fn ssthresh_init() {
@@ -310,11 +382,8 @@ mod tests {
310
382
 
311
383
  #[test]
312
384
  fn ssthresh_in_css() {
313
- let expected_startup_exit = StartupExit::new(
314
- 1000,
315
- None,
316
- StartupExitReason::ConservativeSlowStartRounds,
317
- );
385
+ let expected_startup_exit =
386
+ StartupExit::new(1000, None, StartupExitReason::ConservativeSlowStartRounds);
318
387
  let mut ssthresh: SsThresh = Default::default();
319
388
  ssthresh.update(1000, true);
320
389
  assert_eq!(ssthresh.get(), 1000);
@@ -332,8 +401,7 @@ mod tests {
332
401
 
333
402
  #[test]
334
403
  fn ssthresh_in_slow_start() {
335
- let expected_startup_exit =
336
- StartupExit::new(1000, None, StartupExitReason::Loss);
404
+ let expected_startup_exit = StartupExit::new(1000, None, StartupExitReason::Loss);
337
405
  let mut ssthresh: SsThresh = Default::default();
338
406
  ssthresh.update(1000, false);
339
407
  assert_eq!(ssthresh.get(), 1000);
@@ -65,7 +65,10 @@ impl PRR {
65
65
  }
66
66
 
67
67
  pub fn on_packet_acked(
68
- &mut self, delivered_data: usize, pipe: usize, ssthresh: usize,
68
+ &mut self,
69
+ delivered_data: usize,
70
+ pipe: usize,
71
+ ssthresh: usize,
69
72
  max_datagram_size: usize,
70
73
  ) {
71
74
  self.prr_delivered += delivered_data;