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
@@ -30,6 +30,28 @@ use smallvec::smallvec;
30
30
 
31
31
  use crate::recovery::Sent;
32
32
 
33
+ /// Curve preference list that excludes post-quantum groups.
34
+ ///
35
+ /// Several tests were written against a pre-PQ world where the ClientHello
36
+ /// fit in a single Initial packet; those tests opt out of PQ to keep that
37
+ /// invariant. See [`config_no_pq`] and
38
+ /// [`Config::set_curves_list`](crate::Config::set_curves_list).
39
+ const NO_PQ_CURVES: &str = "X25519:P-256:P-384";
40
+
41
+ /// Returns a `Config` equivalent to `Config::new(version)` but with
42
+ /// post-quantum TLS curves disabled.
43
+ ///
44
+ /// Use this as a drop-in replacement for `Config::new(version)` in tests
45
+ /// whose expected packet counts/sizes were calibrated against a
46
+ /// single-Initial ClientHello. A post-quantum keyshare pushes the
47
+ /// ClientHello across two Initial packets, which perturbs those
48
+ /// expectations.
49
+ pub fn config_no_pq(version: u32) -> Result<Config> {
50
+ let mut config = Config::new(version)?;
51
+ config.set_curves_list(NO_PQ_CURVES)?;
52
+ Ok(config)
53
+ }
54
+
33
55
  pub struct Pipe<F = DefaultBufFactory>
34
56
  where
35
57
  F: BufFactory,
@@ -57,19 +79,23 @@ impl Pipe {
57
79
  Ok(config)
58
80
  }
59
81
 
82
+ /// Like [`default_config`](Self::default_config) but with post-quantum
83
+ /// TLS curves disabled. See [`config_no_pq`] for the rationale.
84
+ pub fn default_config_no_pq(cc_algorithm_name: &str) -> Result<Config> {
85
+ let mut config = Self::default_config(cc_algorithm_name)?;
86
+ config.set_curves_list(NO_PQ_CURVES)?;
87
+ Ok(config)
88
+ }
89
+
60
90
  #[cfg(feature = "boringssl-boring-crate")]
61
91
  pub fn default_tls_ctx_builder() -> boring::ssl::SslContextBuilder {
62
92
  let mut ctx_builder =
63
- boring::ssl::SslContextBuilder::new(boring::ssl::SslMethod::tls())
64
- .unwrap();
93
+ boring::ssl::SslContextBuilder::new(boring::ssl::SslMethod::tls()).unwrap();
65
94
  ctx_builder
66
95
  .set_certificate_chain_file("examples/cert.crt")
67
96
  .unwrap();
68
97
  ctx_builder
69
- .set_private_key_file(
70
- "examples/cert.key",
71
- boring::ssl::SslFiletype::PEM,
72
- )
98
+ .set_private_key_file("examples/cert.key", boring::ssl::SslFiletype::PEM)
73
99
  .unwrap();
74
100
 
75
101
  ctx_builder
@@ -93,7 +119,9 @@ impl Pipe {
93
119
  }
94
120
 
95
121
  pub fn with_config_and_scid_lengths(
96
- config: &mut Config, client_scid_len: usize, server_scid_len: usize,
122
+ config: &mut Config,
123
+ client_scid_len: usize,
124
+ server_scid_len: usize,
97
125
  ) -> Result<Pipe> {
98
126
  Pipe::<DefaultBufFactory>::with_config_and_scid_lengths_and_buf(
99
127
  config,
@@ -111,7 +139,8 @@ impl Pipe {
111
139
  }
112
140
 
113
141
  pub fn with_client_and_server_config(
114
- client_config: &mut Config, server_config: &mut Config,
142
+ client_config: &mut Config,
143
+ server_config: &mut Config,
115
144
  ) -> Result<Pipe> {
116
145
  Pipe::<DefaultBufFactory>::with_client_and_server_config_and_buf(
117
146
  client_config,
@@ -145,18 +174,14 @@ impl<F: BufFactory> Pipe<F> {
145
174
  server_addr,
146
175
  config,
147
176
  )?,
148
- server: accept_with_buf_factory(
149
- &server_scid,
150
- None,
151
- server_addr,
152
- client_addr,
153
- config,
154
- )?,
177
+ server: accept_with_buf_factory(&server_scid, None, server_addr, client_addr, config)?,
155
178
  })
156
179
  }
157
180
 
158
181
  pub fn with_config_and_scid_lengths_and_buf(
159
- config: &mut Config, client_scid_len: usize, server_scid_len: usize,
182
+ config: &mut Config,
183
+ client_scid_len: usize,
184
+ server_scid_len: usize,
160
185
  ) -> Result<Pipe<F>> {
161
186
  let mut client_scid = vec![0; client_scid_len];
162
187
  rand::rand_bytes(&mut client_scid[..]);
@@ -176,19 +201,11 @@ impl<F: BufFactory> Pipe<F> {
176
201
  server_addr,
177
202
  config,
178
203
  )?,
179
- server: accept_with_buf_factory(
180
- &server_scid,
181
- None,
182
- server_addr,
183
- client_addr,
184
- config,
185
- )?,
204
+ server: accept_with_buf_factory(&server_scid, None, server_addr, client_addr, config)?,
186
205
  })
187
206
  }
188
207
 
189
- pub fn with_client_config_and_buf(
190
- client_config: &mut Config,
191
- ) -> Result<Pipe<F>> {
208
+ pub fn with_client_config_and_buf(client_config: &mut Config) -> Result<Pipe<F>> {
192
209
  let mut client_scid = [0; 16];
193
210
  rand::rand_bytes(&mut client_scid[..]);
194
211
  let client_scid = ConnectionId::from_ref(&client_scid);
@@ -228,9 +245,7 @@ impl<F: BufFactory> Pipe<F> {
228
245
  })
229
246
  }
230
247
 
231
- pub fn with_server_config_and_buf(
232
- server_config: &mut Config,
233
- ) -> Result<Pipe<F>> {
248
+ pub fn with_server_config_and_buf(server_config: &mut Config) -> Result<Pipe<F>> {
234
249
  let mut client_scid = [0; 16];
235
250
  rand::rand_bytes(&mut client_scid[..]);
236
251
  let client_scid = ConnectionId::from_ref(&client_scid);
@@ -269,7 +284,8 @@ impl<F: BufFactory> Pipe<F> {
269
284
  }
270
285
 
271
286
  pub fn with_client_and_server_config_and_buf(
272
- client_config: &mut Config, server_config: &mut Config,
287
+ client_config: &mut Config,
288
+ server_config: &mut Config,
273
289
  ) -> Result<Pipe<F>> {
274
290
  let mut client_scid = [0; 16];
275
291
  rand::rand_bytes(&mut client_scid[..]);
@@ -357,7 +373,10 @@ impl<F: BufFactory> Pipe<F> {
357
373
  }
358
374
 
359
375
  pub fn send_pkt_to_server(
360
- &mut self, pkt_type: Type, frames: &[frame::Frame], buf: &mut [u8],
376
+ &mut self,
377
+ pkt_type: Type,
378
+ frames: &[frame::Frame],
379
+ buf: &mut [u8],
361
380
  ) -> Result<usize> {
362
381
  let written = encode_pkt(&mut self.client, pkt_type, frames, buf)?;
363
382
  recv_send(&mut self.server, buf, written)
@@ -396,7 +415,9 @@ impl<F: BufFactory> Pipe<F> {
396
415
  }
397
416
 
398
417
  pub fn recv_send<F: BufFactory>(
399
- conn: &mut Connection<F>, buf: &mut [u8], len: usize,
418
+ conn: &mut Connection<F>,
419
+ buf: &mut [u8],
420
+ len: usize,
400
421
  ) -> Result<usize> {
401
422
  let active_path = conn.paths.get_active()?;
402
423
  let info = RecvInfo {
@@ -420,7 +441,8 @@ pub fn recv_send<F: BufFactory>(
420
441
  }
421
442
 
422
443
  pub fn process_flight<F: BufFactory>(
423
- conn: &mut Connection<F>, flight: Vec<(Vec<u8>, SendInfo)>,
444
+ conn: &mut Connection<F>,
445
+ flight: Vec<(Vec<u8>, SendInfo)>,
424
446
  ) -> Result<()> {
425
447
  for (mut pkt, si) in flight {
426
448
  let info = RecvInfo {
@@ -435,7 +457,9 @@ pub fn process_flight<F: BufFactory>(
435
457
  }
436
458
 
437
459
  pub fn emit_flight_with_max_buffer<F: BufFactory>(
438
- conn: &mut Connection<F>, out_size: usize, from: Option<SocketAddr>,
460
+ conn: &mut Connection<F>,
461
+ out_size: usize,
462
+ from: Option<SocketAddr>,
439
463
  to: Option<SocketAddr>,
440
464
  ) -> Result<Vec<(Vec<u8>, SendInfo)>> {
441
465
  let mut flight = Vec::new();
@@ -447,7 +471,7 @@ pub fn emit_flight_with_max_buffer<F: BufFactory>(
447
471
  Ok((written, info)) => {
448
472
  out.truncate(written);
449
473
  info
450
- },
474
+ }
451
475
 
452
476
  Err(Error::Done) => break,
453
477
 
@@ -465,19 +489,21 @@ pub fn emit_flight_with_max_buffer<F: BufFactory>(
465
489
  }
466
490
 
467
491
  pub fn emit_flight_on_path<F: BufFactory>(
468
- conn: &mut Connection<F>, from: Option<SocketAddr>, to: Option<SocketAddr>,
492
+ conn: &mut Connection<F>,
493
+ from: Option<SocketAddr>,
494
+ to: Option<SocketAddr>,
469
495
  ) -> Result<Vec<(Vec<u8>, SendInfo)>> {
470
496
  emit_flight_with_max_buffer(conn, 65535, from, to)
471
497
  }
472
498
 
473
- pub fn emit_flight<F: BufFactory>(
474
- conn: &mut Connection<F>,
475
- ) -> Result<Vec<(Vec<u8>, SendInfo)>> {
499
+ pub fn emit_flight<F: BufFactory>(conn: &mut Connection<F>) -> Result<Vec<(Vec<u8>, SendInfo)>> {
476
500
  emit_flight_on_path(conn, None, None)
477
501
  }
478
502
 
479
503
  pub fn encode_pkt<F: BufFactory>(
480
- conn: &mut Connection<F>, pkt_type: Type, frames: &[frame::Frame],
504
+ conn: &mut Connection<F>,
505
+ pkt_type: Type,
506
+ frames: &[frame::Frame],
481
507
  buf: &mut [u8],
482
508
  ) -> Result<usize> {
483
509
  let mut b = octets::OctetsMut::with_slice(buf);
@@ -502,12 +528,8 @@ pub fn encode_pkt<F: BufFactory>(
502
528
  let hdr = Header {
503
529
  ty: pkt_type,
504
530
  version: conn.version,
505
- dcid: ConnectionId::from_ref(
506
- conn.ids.get_dcid(*active_dcid_seq)?.cid.as_ref(),
507
- ),
508
- scid: ConnectionId::from_ref(
509
- conn.ids.get_scid(*active_scid_seq)?.cid.as_ref(),
510
- ),
531
+ dcid: ConnectionId::from_ref(conn.ids.get_dcid(*active_dcid_seq)?.cid.as_ref()),
532
+ scid: ConnectionId::from_ref(conn.ids.get_scid(*active_scid_seq)?.cid.as_ref()),
511
533
  pkt_num: pn,
512
534
  pkt_num_len: pn_len,
513
535
  token: conn.token.clone(),
@@ -539,15 +561,7 @@ pub fn encode_pkt<F: BufFactory>(
539
561
  None => return Err(Error::InvalidState),
540
562
  };
541
563
 
542
- let written = packet::encrypt_pkt(
543
- &mut b,
544
- pn,
545
- pn_len,
546
- payload_len,
547
- payload_offset,
548
- None,
549
- aead,
550
- )?;
564
+ let written = packet::encrypt_pkt(&mut b, pn, pn_len, payload_len, payload_offset, None, aead)?;
551
565
 
552
566
  conn.next_pkt_num += 1;
553
567
 
@@ -555,7 +569,8 @@ pub fn encode_pkt<F: BufFactory>(
555
569
  }
556
570
 
557
571
  pub fn decode_pkt<F: BufFactory>(
558
- conn: &mut Connection<F>, buf: &mut [u8],
572
+ conn: &mut Connection<F>,
573
+ buf: &mut [u8],
559
574
  ) -> Result<Vec<frame::Frame>> {
560
575
  let mut b = octets::OctetsMut::with_slice(buf);
561
576
 
@@ -575,9 +590,7 @@ pub fn decode_pkt<F: BufFactory>(
575
590
  hdr.pkt_num_len,
576
591
  );
577
592
 
578
- let mut payload =
579
- packet::decrypt_pkt(&mut b, pn, hdr.pkt_num_len, payload_len, aead)
580
- .unwrap();
593
+ let mut payload = packet::decrypt_pkt(&mut b, pn, hdr.pkt_num_len, payload_len, aead).unwrap();
581
594
 
582
595
  let mut frames = Vec::new();
583
596
 
@@ -589,9 +602,7 @@ pub fn decode_pkt<F: BufFactory>(
589
602
  Ok(frames)
590
603
  }
591
604
 
592
- pub fn create_cid_and_reset_token(
593
- cid_len: usize,
594
- ) -> (ConnectionId<'static>, u128) {
605
+ pub fn create_cid_and_reset_token(cid_len: usize) -> (ConnectionId<'static>, u128) {
595
606
  let mut cid = vec![0; cid_len];
596
607
  rand::rand_bytes(&mut cid[..]);
597
608
  let cid = ConnectionId::from(cid);
@@ -626,7 +637,9 @@ pub fn helper_packet_sent(pkt_num: u64, now: Instant, size: usize) -> Sent {
626
637
 
627
638
  // Helper function for testing either stream receive or discard.
628
639
  pub fn stream_recv_discard<F: BufFactory>(
629
- conn: &mut Connection<F>, discard: bool, stream_id: u64,
640
+ conn: &mut Connection<F>,
641
+ discard: bool,
642
+ stream_id: u64,
630
643
  ) -> Result<(usize, bool)> {
631
644
  let mut buf = [0; 65535];
632
645
  if discard {
@@ -645,7 +658,8 @@ pub fn stream_recv_discard<F: BufFactory>(
645
658
  /// unacknowledged packets from the sender are detected as lost.
646
659
  #[cfg(test)]
647
660
  pub fn trigger_ack_based_loss<F: BufFactory>(
648
- sender: &mut Connection<F>, receiver: &mut Connection<F>,
661
+ sender: &mut Connection<F>,
662
+ receiver: &mut Connection<F>,
649
663
  ) {
650
664
  let mut buf = [0; 65535];
651
665