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
@@ -71,21 +71,16 @@ impl<T> UnknownTransportParameter<T> {
71
71
  }
72
72
 
73
73
  #[cfg(feature = "qlog")]
74
- impl From<UnknownTransportParameter<Vec<u8>>>
75
- for qlog::events::quic::UnknownTransportParameter
76
- {
74
+ impl From<UnknownTransportParameter<Vec<u8>>> for qlog::events::quic::UnknownTransportParameter {
77
75
  fn from(value: UnknownTransportParameter<Vec<u8>>) -> Self {
78
76
  Self {
79
77
  id: value.id,
80
- value: qlog::HexSlice::maybe_string(Some(value.value.as_slice()))
81
- .unwrap_or_default(),
78
+ value: qlog::HexSlice::maybe_string(Some(value.value.as_slice())).unwrap_or_default(),
82
79
  }
83
80
  }
84
81
  }
85
82
 
86
- impl From<UnknownTransportParameter<&[u8]>>
87
- for UnknownTransportParameter<Vec<u8>>
88
- {
83
+ impl From<UnknownTransportParameter<&[u8]>> for UnknownTransportParameter<Vec<u8>> {
89
84
  // When an instance of an UnknownTransportParameter is actually
90
85
  // stored in UnknownTransportParameters, then we make a copy
91
86
  // of the bytes if the source is an instance of an UnknownTransportParameter
@@ -189,6 +184,8 @@ pub struct TransportParams {
189
184
  pub retry_source_connection_id: Option<ConnectionId<'static>>,
190
185
  /// DATAGRAM frame extension parameter, if any.
191
186
  pub max_datagram_frame_size: Option<u64>,
187
+ /// Receive support for RESET_STREAM_AT (draft-ietf-quic-reliable-stream-reset).
188
+ pub reset_stream_at: bool,
192
189
  /// Unknown peer transport parameters and values, if any.
193
190
  pub unknown_params: Option<UnknownTransportParameters>,
194
191
  // pub preferred_address: ...,
@@ -214,6 +211,7 @@ impl Default for TransportParams {
214
211
  initial_source_connection_id: None,
215
212
  retry_source_connection_id: None,
216
213
  max_datagram_frame_size: None,
214
+ reset_stream_at: false,
217
215
  unknown_params: Default::default(),
218
216
  }
219
217
  }
@@ -221,7 +219,9 @@ impl Default for TransportParams {
221
219
 
222
220
  impl TransportParams {
223
221
  pub(crate) fn decode(
224
- buf: &[u8], is_server: bool, unknown_size: Option<usize>,
222
+ buf: &[u8],
223
+ is_server: bool,
224
+ unknown_size: Option<usize>,
225
225
  ) -> Result<TransportParams> {
226
226
  let mut params = octets::Octets::with_slice(buf);
227
227
  let mut seen_params = HashSet::new();
@@ -251,13 +251,12 @@ impl TransportParams {
251
251
  return Err(Error::InvalidTransportParam);
252
252
  }
253
253
 
254
- tp.original_destination_connection_id =
255
- Some(val.to_vec().into());
256
- },
254
+ tp.original_destination_connection_id = Some(val.to_vec().into());
255
+ }
257
256
 
258
257
  0x0001 => {
259
258
  tp.max_idle_timeout = val.get_varint()?;
260
- },
259
+ }
261
260
 
262
261
  0x0002 => {
263
262
  if is_server {
@@ -270,7 +269,7 @@ impl TransportParams {
270
269
  .try_into()
271
270
  .map_err(|_| Error::BufferTooShort)?,
272
271
  ));
273
- },
272
+ }
274
273
 
275
274
  0x0003 => {
276
275
  tp.max_udp_payload_size = val.get_varint()?;
@@ -278,23 +277,23 @@ impl TransportParams {
278
277
  if tp.max_udp_payload_size < 1200 {
279
278
  return Err(Error::InvalidTransportParam);
280
279
  }
281
- },
280
+ }
282
281
 
283
282
  0x0004 => {
284
283
  tp.initial_max_data = val.get_varint()?;
285
- },
284
+ }
286
285
 
287
286
  0x0005 => {
288
287
  tp.initial_max_stream_data_bidi_local = val.get_varint()?;
289
- },
288
+ }
290
289
 
291
290
  0x0006 => {
292
291
  tp.initial_max_stream_data_bidi_remote = val.get_varint()?;
293
- },
292
+ }
294
293
 
295
294
  0x0007 => {
296
295
  tp.initial_max_stream_data_uni = val.get_varint()?;
297
- },
296
+ }
298
297
 
299
298
  0x0008 => {
300
299
  let max = val.get_varint()?;
@@ -304,7 +303,7 @@ impl TransportParams {
304
303
  }
305
304
 
306
305
  tp.initial_max_streams_bidi = max;
307
- },
306
+ }
308
307
 
309
308
  0x0009 => {
310
309
  let max = val.get_varint()?;
@@ -314,7 +313,7 @@ impl TransportParams {
314
313
  }
315
314
 
316
315
  tp.initial_max_streams_uni = max;
317
- },
316
+ }
318
317
 
319
318
  0x000a => {
320
319
  let ack_delay_exponent = val.get_varint()?;
@@ -324,7 +323,7 @@ impl TransportParams {
324
323
  }
325
324
 
326
325
  tp.ack_delay_exponent = ack_delay_exponent;
327
- },
326
+ }
328
327
 
329
328
  0x000b => {
330
329
  let max_ack_delay = val.get_varint()?;
@@ -334,11 +333,11 @@ impl TransportParams {
334
333
  }
335
334
 
336
335
  tp.max_ack_delay = max_ack_delay;
337
- },
336
+ }
338
337
 
339
338
  0x000c => {
340
339
  tp.disable_active_migration = true;
341
- },
340
+ }
342
341
 
343
342
  0x000d => {
344
343
  if is_server {
@@ -346,7 +345,7 @@ impl TransportParams {
346
345
  }
347
346
 
348
347
  // TODO: decode preferred_address
349
- },
348
+ }
350
349
 
351
350
  0x000e => {
352
351
  let limit = val.get_varint()?;
@@ -356,11 +355,11 @@ impl TransportParams {
356
355
  }
357
356
 
358
357
  tp.active_conn_id_limit = limit;
359
- },
358
+ }
360
359
 
361
360
  0x000f => {
362
361
  tp.initial_source_connection_id = Some(val.to_vec().into());
363
- },
362
+ }
364
363
 
365
364
  0x00010 => {
366
365
  if is_server {
@@ -368,32 +367,36 @@ impl TransportParams {
368
367
  }
369
368
 
370
369
  tp.retry_source_connection_id = Some(val.to_vec().into());
371
- },
370
+ }
371
+
372
+ 0x001d => {
373
+ if val.cap() != 0 {
374
+ return Err(Error::InvalidTransportParam);
375
+ }
376
+ tp.reset_stream_at = true;
377
+ }
372
378
 
373
379
  0x0020 => {
374
380
  tp.max_datagram_frame_size = Some(val.get_varint()?);
375
- },
381
+ }
376
382
 
377
383
  // Track unknown transport parameters specially.
378
384
  unknown_tp_id => {
379
385
  if let Some(unknown_params) = &mut tp.unknown_params {
380
- // It is _not_ an error not to have space enough to track
381
- // an unknown parameter.
386
+ // Failing to track an unknown parameter is harmless.
382
387
  let _ = unknown_params.push(UnknownTransportParameter {
383
388
  id: unknown_tp_id,
384
389
  value: val.buf(),
385
390
  });
386
391
  }
387
- },
392
+ }
388
393
  }
389
394
  }
390
395
 
391
396
  Ok(tp)
392
397
  }
393
398
 
394
- pub(crate) fn encode_param(
395
- b: &mut octets::OctetsMut, ty: u64, len: usize,
396
- ) -> Result<()> {
399
+ pub(crate) fn encode_param(b: &mut octets::OctetsMut, ty: u64, len: usize) -> Result<()> {
397
400
  b.put_varint(ty)?;
398
401
  b.put_varint(len as u64)?;
399
402
 
@@ -401,7 +404,9 @@ impl TransportParams {
401
404
  }
402
405
 
403
406
  pub(crate) fn encode<'a>(
404
- tp: &TransportParams, is_server: bool, out: &'a mut [u8],
407
+ tp: &TransportParams,
408
+ is_server: bool,
409
+ out: &'a mut [u8],
405
410
  ) -> Result<&'a mut [u8]> {
406
411
  let mut b = octets::OctetsMut::with_slice(out);
407
412
 
@@ -414,11 +419,7 @@ impl TransportParams {
414
419
 
415
420
  if tp.max_idle_timeout != 0 {
416
421
  assert!(tp.max_idle_timeout <= octets::MAX_VAR_INT);
417
- TransportParams::encode_param(
418
- &mut b,
419
- 0x0001,
420
- octets::varint_len(tp.max_idle_timeout),
421
- )?;
422
+ TransportParams::encode_param(&mut b, 0x0001, octets::varint_len(tp.max_idle_timeout))?;
422
423
  b.put_varint(tp.max_idle_timeout)?;
423
424
  }
424
425
 
@@ -441,11 +442,7 @@ impl TransportParams {
441
442
 
442
443
  if tp.initial_max_data != 0 {
443
444
  assert!(tp.initial_max_data <= octets::MAX_VAR_INT);
444
- TransportParams::encode_param(
445
- &mut b,
446
- 0x0004,
447
- octets::varint_len(tp.initial_max_data),
448
- )?;
445
+ TransportParams::encode_param(&mut b, 0x0004, octets::varint_len(tp.initial_max_data))?;
449
446
  b.put_varint(tp.initial_max_data)?;
450
447
  }
451
448
 
@@ -460,9 +457,7 @@ impl TransportParams {
460
457
  }
461
458
 
462
459
  if tp.initial_max_stream_data_bidi_remote != 0 {
463
- assert!(
464
- tp.initial_max_stream_data_bidi_remote <= octets::MAX_VAR_INT
465
- );
460
+ assert!(tp.initial_max_stream_data_bidi_remote <= octets::MAX_VAR_INT);
466
461
  TransportParams::encode_param(
467
462
  &mut b,
468
463
  0x0006,
@@ -513,11 +508,7 @@ impl TransportParams {
513
508
 
514
509
  if tp.max_ack_delay != 0 {
515
510
  assert!(tp.max_ack_delay <= octets::MAX_VAR_INT);
516
- TransportParams::encode_param(
517
- &mut b,
518
- 0x000b,
519
- octets::varint_len(tp.max_ack_delay),
520
- )?;
511
+ TransportParams::encode_param(&mut b, 0x000b, octets::varint_len(tp.max_ack_delay))?;
521
512
  b.put_varint(tp.max_ack_delay)?;
522
513
  }
523
514
 
@@ -549,6 +540,10 @@ impl TransportParams {
549
540
  }
550
541
  }
551
542
 
543
+ if tp.reset_stream_at {
544
+ TransportParams::encode_param(&mut b, 0x001d, 0)?;
545
+ }
546
+
552
547
  if let Some(max_datagram_frame_size) = tp.max_datagram_frame_size {
553
548
  assert!(max_datagram_frame_size <= octets::MAX_VAR_INT);
554
549
  TransportParams::encode_param(
@@ -567,11 +562,12 @@ impl TransportParams {
567
562
  /// Creates a qlog event for connection transport parameters and TLS fields
568
563
  #[cfg(feature = "qlog")]
569
564
  pub fn to_qlog(
570
- &self, initiator: TransportInitiator, cipher: Option<crypto::Algorithm>,
565
+ &self,
566
+ initiator: TransportInitiator,
567
+ cipher: Option<crypto::Algorithm>,
571
568
  ) -> EventData {
572
- let original_destination_connection_id = qlog::HexSlice::maybe_string(
573
- self.original_destination_connection_id.as_ref(),
574
- );
569
+ let original_destination_connection_id =
570
+ qlog::HexSlice::maybe_string(self.original_destination_connection_id.as_ref());
575
571
 
576
572
  let stateless_reset_token = qlog::HexSlice::maybe_string(
577
573
  self.stateless_reset_token.map(|s| s.to_be_bytes()).as_ref(),
@@ -579,50 +575,38 @@ impl TransportParams {
579
575
 
580
576
  let tls_cipher: Option<String> = cipher.map(|f| format!("{f:?}"));
581
577
 
582
- EventData::QuicParametersSet(Box::new(
583
- qlog::events::quic::ParametersSet {
584
- initiator: Some(initiator),
585
- tls_cipher,
586
- original_destination_connection_id,
587
- stateless_reset_token,
588
- disable_active_migration: Some(self.disable_active_migration),
589
- max_idle_timeout: Some(self.max_idle_timeout),
590
- max_udp_payload_size: Some(self.max_udp_payload_size),
591
- ack_delay_exponent: Some(self.ack_delay_exponent),
592
- max_ack_delay: Some(self.max_ack_delay),
593
- active_connection_id_limit: Some(self.active_conn_id_limit),
594
-
595
- initial_max_data: Some(self.initial_max_data),
596
- initial_max_stream_data_bidi_local: Some(
597
- self.initial_max_stream_data_bidi_local,
598
- ),
599
- initial_max_stream_data_bidi_remote: Some(
600
- self.initial_max_stream_data_bidi_remote,
601
- ),
602
- initial_max_stream_data_uni: Some(
603
- self.initial_max_stream_data_uni,
604
- ),
605
- initial_max_streams_bidi: Some(self.initial_max_streams_bidi),
606
- initial_max_streams_uni: Some(self.initial_max_streams_uni),
607
-
608
- unknown_parameters: self
609
- .unknown_params
610
- .as_ref()
611
- .map(|unknown_params| {
612
- unknown_params
613
- .into_iter()
614
- .cloned()
615
- .map(
616
- Into::<
617
- qlog::events::quic::UnknownTransportParameter,
618
- >::into,
619
- )
620
- .collect()
621
- })
622
- .unwrap_or_default(),
623
-
624
- ..Default::default()
625
- },
626
- ))
578
+ EventData::QuicParametersSet(Box::new(qlog::events::quic::ParametersSet {
579
+ initiator: Some(initiator),
580
+ tls_cipher,
581
+ original_destination_connection_id,
582
+ stateless_reset_token,
583
+ disable_active_migration: Some(self.disable_active_migration),
584
+ max_idle_timeout: Some(self.max_idle_timeout),
585
+ max_udp_payload_size: Some(self.max_udp_payload_size),
586
+ ack_delay_exponent: Some(self.ack_delay_exponent),
587
+ max_ack_delay: Some(self.max_ack_delay),
588
+ active_connection_id_limit: Some(self.active_conn_id_limit),
589
+
590
+ initial_max_data: Some(self.initial_max_data),
591
+ initial_max_stream_data_bidi_local: Some(self.initial_max_stream_data_bidi_local),
592
+ initial_max_stream_data_bidi_remote: Some(self.initial_max_stream_data_bidi_remote),
593
+ initial_max_stream_data_uni: Some(self.initial_max_stream_data_uni),
594
+ initial_max_streams_bidi: Some(self.initial_max_streams_bidi),
595
+ initial_max_streams_uni: Some(self.initial_max_streams_uni),
596
+
597
+ unknown_parameters: self
598
+ .unknown_params
599
+ .as_ref()
600
+ .map(|unknown_params| {
601
+ unknown_params
602
+ .into_iter()
603
+ .cloned()
604
+ .map(Into::<qlog::events::quic::UnknownTransportParameter>::into)
605
+ .collect()
606
+ })
607
+ .unwrap_or_default(),
608
+
609
+ ..Default::default()
610
+ }))
627
611
  }
628
612
  }