rwebtransport 0.2.3 → 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 (96) hide show
  1. package/Cargo.lock +153 -226
  2. package/Cargo.toml +5 -5
  3. package/README.md +4 -4
  4. package/crates/echo-server/src/bin/gen-test-cert.rs +1 -1
  5. package/crates/native/Cargo.toml +1 -1
  6. package/crates/native/src/config.rs +13 -1
  7. package/crates/native/src/driver.rs +249 -91
  8. package/crates/native/src/lib.rs +9 -10
  9. package/crates/native/src/parser_memory.rs +1 -0
  10. package/crates/native/src/server.rs +197 -182
  11. package/crates/native/src/session.rs +329 -177
  12. package/crates/native/src/test_support.rs +2 -2
  13. package/crates/wtcore/src/h3.rs +166 -10
  14. package/dist/index.js +92 -45
  15. package/dist/index.js.map +2 -2
  16. package/dist/index.mjs +92 -45
  17. package/dist/index.mjs.map +2 -2
  18. package/dist/native.d.ts +9 -4
  19. package/package.json +14 -11
  20. package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
  21. package/prebuilds/linux-arm64/rwebtransport.node +0 -0
  22. package/prebuilds/linux-x64/rwebtransport.node +0 -0
  23. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  24. package/scripts/build-linux-prebuilt.sh +46 -0
  25. package/scripts/build.js +10 -3
  26. package/vendor/quiche/AGENTS.md +10 -0
  27. package/vendor/quiche/Cargo.lock +239 -248
  28. package/vendor/quiche/Cargo.toml +23 -10
  29. package/vendor/quiche/examples/Makefile +4 -4
  30. package/vendor/quiche/examples/client.rs +10 -28
  31. package/vendor/quiche/examples/http3-client.rs +20 -34
  32. package/vendor/quiche/examples/http3-server.rs +47 -78
  33. package/vendor/quiche/examples/server.rs +19 -49
  34. package/vendor/quiche/include/quiche.h +35 -4
  35. package/vendor/quiche/src/build.rs +17 -0
  36. package/vendor/quiche/src/cid.rs +129 -61
  37. package/vendor/quiche/src/crypto/boringssl.rs +98 -86
  38. package/vendor/quiche/src/crypto/mod.rs +64 -77
  39. package/vendor/quiche/src/dgram.rs +2 -3
  40. package/vendor/quiche/src/error.rs +22 -20
  41. package/vendor/quiche/src/ffi.rs +558 -280
  42. package/vendor/quiche/src/flowcontrol.rs +0 -7
  43. package/vendor/quiche/src/frame.rs +134 -135
  44. package/vendor/quiche/src/h3/ffi.rs +73 -60
  45. package/vendor/quiche/src/h3/frame.rs +70 -90
  46. package/vendor/quiche/src/h3/mod.rs +1024 -593
  47. package/vendor/quiche/src/h3/qpack/decoder.rs +248 -34
  48. package/vendor/quiche/src/h3/qpack/dynamic_table.rs +859 -0
  49. package/vendor/quiche/src/h3/qpack/encoder.rs +14 -17
  50. package/vendor/quiche/src/h3/qpack/mod.rs +48 -0
  51. package/vendor/quiche/src/h3/qpack/static_table.rs +86 -73
  52. package/vendor/quiche/src/h3/stream.rs +1009 -194
  53. package/vendor/quiche/src/lib.rs +1346 -1195
  54. package/vendor/quiche/src/minmax.rs +2 -6
  55. package/vendor/quiche/src/packet.rs +420 -552
  56. package/vendor/quiche/src/path.rs +202 -72
  57. package/vendor/quiche/src/pmtud.rs +18 -16
  58. package/vendor/quiche/src/ranges.rs +184 -82
  59. package/vendor/quiche/src/recovery/AGENTS.md +5 -2
  60. package/vendor/quiche/src/recovery/bandwidth.rs +59 -40
  61. package/vendor/quiche/src/recovery/bytes_in_flight.rs +2 -2
  62. package/vendor/quiche/src/recovery/congestion/cubic.rs +38 -47
  63. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +54 -60
  64. package/vendor/quiche/src/recovery/congestion/hystart.rs +6 -10
  65. package/vendor/quiche/src/recovery/congestion/mod.rs +110 -42
  66. package/vendor/quiche/src/recovery/congestion/prr.rs +4 -1
  67. package/vendor/quiche/src/recovery/congestion/recovery.rs +91 -95
  68. package/vendor/quiche/src/recovery/congestion/reno.rs +17 -12
  69. package/vendor/quiche/src/recovery/congestion/test_sender.rs +8 -27
  70. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +159 -247
  71. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +9 -14
  72. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +18 -15
  73. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +43 -28
  74. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +349 -76
  75. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +147 -195
  76. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +29 -27
  77. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min.rs +180 -0
  78. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min_tests.rs +221 -0
  79. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm.rs +395 -0
  80. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm_tests.rs +473 -0
  81. package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/mod.rs +175 -0
  82. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +33 -26
  83. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +107 -60
  84. package/vendor/quiche/src/recovery/gcongestion/mod.rs +64 -11
  85. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +34 -25
  86. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +81 -86
  87. package/vendor/quiche/src/recovery/mod.rs +414 -173
  88. package/vendor/quiche/src/recovery/rtt.rs +8 -5
  89. package/vendor/quiche/src/stream/mod.rs +864 -133
  90. package/vendor/quiche/src/stream/recv_buf.rs +471 -172
  91. package/vendor/quiche/src/stream/send_buf.rs +338 -81
  92. package/vendor/quiche/src/test_utils.rs +78 -64
  93. package/vendor/quiche/src/tests.rs +2559 -1335
  94. package/vendor/quiche/src/tls/boringssl.rs +60 -63
  95. package/vendor/quiche/src/tls/mod.rs +146 -193
  96. package/vendor/quiche/src/transport_params.rs +87 -103
@@ -43,9 +43,7 @@ impl Encoder {
43
43
  }
44
44
 
45
45
  /// Encodes a list of headers into a QPACK header block.
46
- pub fn encode<T: NameValue>(
47
- &mut self, headers: &[T], out: &mut [u8],
48
- ) -> Result<usize> {
46
+ pub fn encode<T: NameValue>(&mut self, headers: &[T], out: &mut [u8]) -> Result<usize> {
49
47
  let mut b = octets::OctetsMut::with_slice(out);
50
48
 
51
49
  // Required Insert Count.
@@ -61,7 +59,7 @@ impl Encoder {
61
59
 
62
60
  // Encode as statically indexed.
63
61
  encode_int(idx, INDEXED | STATIC, 6, &mut b)?;
64
- },
62
+ }
65
63
 
66
64
  Some((idx, false)) => {
67
65
  const STATIC: u8 = 0x10;
@@ -69,14 +67,14 @@ impl Encoder {
69
67
  // Encode value as literal with static name reference.
70
68
  encode_int(idx, LITERAL_WITH_NAME_REF | STATIC, 4, &mut b)?;
71
69
  encode_str::<false>(h.value(), 0, 7, &mut b)?;
72
- },
70
+ }
73
71
 
74
72
  None => {
75
73
  // Encode as fully literal.
76
74
 
77
75
  encode_str::<true>(h.name(), LITERAL, 3, &mut b)?;
78
76
  encode_str::<false>(h.value(), 0, 7, &mut b)?;
79
- },
77
+ }
80
78
  };
81
79
  }
82
80
 
@@ -86,14 +84,12 @@ impl Encoder {
86
84
 
87
85
  fn lookup_static<T: NameValue>(h: &T) -> Option<(u64, bool)> {
88
86
  // Fetch the right encoding table for this header length.
89
- let table_for_len =
90
- super::static_table::STATIC_ENCODE_TABLE.get(h.name().len())?;
87
+ let table_for_len = super::static_table::STATIC_ENCODE_TABLE.get(h.name().len())?;
91
88
 
92
89
  // Similar to [`eq_ignore_ascii_case`], but only lowercases the second
93
90
  // operand, as the entries in the table are already lower cased.
94
- let cmp_lowercase = |a: &[u8], b: &[u8]| {
95
- std::iter::zip(a, b).all(|(a, b)| a.eq(&b.to_ascii_lowercase()))
96
- };
91
+ let cmp_lowercase =
92
+ |a: &[u8], b: &[u8]| std::iter::zip(a, b).all(|(a, b)| a.eq(&b.to_ascii_lowercase()));
97
93
 
98
94
  for (name, values) in table_for_len.iter() {
99
95
  // Match header name first.
@@ -117,9 +113,7 @@ fn lookup_static<T: NameValue>(h: &T) -> Option<(u64, bool)> {
117
113
  None
118
114
  }
119
115
 
120
- pub fn encode_int(
121
- mut v: u64, first: u8, prefix: usize, b: &mut octets::OctetsMut,
122
- ) -> Result<()> {
116
+ pub fn encode_int(mut v: u64, first: u8, prefix: usize, b: &mut octets::OctetsMut) -> Result<()> {
123
117
  let mask = 2u64.pow(prefix as u32) - 1;
124
118
 
125
119
  // Encode I on N bits.
@@ -148,7 +142,10 @@ pub fn encode_int(
148
142
 
149
143
  #[inline]
150
144
  pub fn encode_str<const LOWER_CASE: bool>(
151
- v: &[u8], first: u8, prefix: usize, b: &mut octets::OctetsMut,
145
+ v: &[u8],
146
+ first: u8,
147
+ prefix: usize,
148
+ b: &mut octets::OctetsMut,
152
149
  ) -> Result<()> {
153
150
  // Huffman-encoding generally saves space but in some cases it doesn't, for
154
151
  // those just encode the literal string.
@@ -156,7 +153,7 @@ pub fn encode_str<const LOWER_CASE: bool>(
156
153
  Ok(len) => {
157
154
  encode_int(len as u64, first | (1 << prefix), prefix, b)?;
158
155
  b.put_huffman_encoded::<LOWER_CASE>(v)?;
159
- },
156
+ }
160
157
 
161
158
  Err(_) => {
162
159
  encode_int(v.len() as u64, first, prefix, b)?;
@@ -165,7 +162,7 @@ pub fn encode_str<const LOWER_CASE: bool>(
165
162
  } else {
166
163
  b.put_bytes(v)?;
167
164
  }
168
- },
165
+ }
169
166
  }
170
167
 
171
168
  Ok(())
@@ -81,6 +81,7 @@ impl From<octets::BufferTooShortError> for Error {
81
81
 
82
82
  #[cfg(test)]
83
83
  mod tests {
84
+ use crate::h3::qpack::Error::HeaderListTooLarge;
84
85
  use crate::*;
85
86
 
86
87
  use super::*;
@@ -108,6 +109,45 @@ mod tests {
108
109
  assert_eq!(dec.decode(&encoded, u64::MAX), Ok(headers));
109
110
  }
110
111
 
112
+ #[test]
113
+ fn encode_decode_small_max_field_section_size() {
114
+ let mut encoded = [0u8; 102];
115
+
116
+ const NUM_HDRS: usize = 10;
117
+
118
+ let headers = vec![h3::Header::new(b"hello", b"world"); NUM_HDRS];
119
+
120
+ // The size of a field list is calculated based on the uncompressed size
121
+ // of fields, including the length of the name and value in bytes plus
122
+ // an overhead of 32 bytes for each field. See
123
+ // https://datatracker.ietf.org/doc/html/rfc9114#section-4.2.2
124
+ let qpack_field_section_size = (b"hello".len() + b"world".len() + 32) * NUM_HDRS;
125
+
126
+ let mut enc = Encoder::new();
127
+ assert_eq!(enc.encode(&headers, &mut encoded), Ok(102));
128
+
129
+ let mut dec = Decoder::new();
130
+
131
+ // Equal max_size param ok
132
+ assert_eq!(
133
+ dec.decode(&encoded, qpack_field_section_size as u64),
134
+ Ok(headers.clone())
135
+ );
136
+
137
+ // Oversized max_size param ok
138
+ assert_eq!(
139
+ dec.decode(&encoded, qpack_field_section_size as u64 + 1),
140
+ Ok(headers.clone())
141
+ );
142
+
143
+ // Smaller max_size param (forgetting 32 byte overhead) fails
144
+ let wrong_qpack_field_section_size = (b"hello".len() + b"world".len()) * NUM_HDRS;
145
+ assert_eq!(
146
+ dec.decode(&encoded, wrong_qpack_field_section_size as u64),
147
+ Err(HeaderListTooLarge)
148
+ );
149
+ }
150
+
111
151
  #[test]
112
152
  fn lower_case() {
113
153
  let mut encoded = [0u8; 35];
@@ -198,5 +238,13 @@ pub use decoder::Decoder;
198
238
  pub use encoder::Encoder;
199
239
 
200
240
  mod decoder;
241
+ #[cfg_attr(
242
+ not(test),
243
+ expect(
244
+ dead_code,
245
+ reason = "not used until the decoder processes encoder instructions"
246
+ )
247
+ )]
248
+ mod dynamic_table;
201
249
  mod encoder;
202
250
  mod static_table;
@@ -61,32 +61,38 @@ pub const STATIC_ENCODE_TABLE: &[&[(HeaderName, HeaderValueEncPairs)]] = &[
61
61
  (b"purpose", &[(b"prefetch", 91)]),
62
62
  (b"referer", &[(b"", 13)]),
63
63
  (b"alt-svc", &[(b"clear", 83)]),
64
- (b":status", &[
65
- (b"103", 24),
66
- (b"200", 25),
67
- (b"304", 26),
68
- (b"404", 27),
69
- (b"503", 28),
70
- (b"100", 63),
71
- (b"204", 64),
72
- (b"206", 65),
73
- (b"302", 66),
74
- (b"400", 67),
75
- (b"403", 68),
76
- (b"421", 69),
77
- (b"425", 70),
78
- (b"500", 71),
79
- ]),
64
+ (
65
+ b":status",
66
+ &[
67
+ (b"103", 24),
68
+ (b"200", 25),
69
+ (b"304", 26),
70
+ (b"404", 27),
71
+ (b"503", 28),
72
+ (b"100", 63),
73
+ (b"204", 64),
74
+ (b"206", 65),
75
+ (b"302", 66),
76
+ (b"400", 67),
77
+ (b"403", 68),
78
+ (b"421", 69),
79
+ (b"425", 70),
80
+ (b"500", 71),
81
+ ],
82
+ ),
80
83
  (b":scheme", &[(b"http", 22), (b"https", 23)]),
81
- (b":method", &[
82
- (b"CONNECT", 15),
83
- (b"DELETE", 16),
84
- (b"GET", 17),
85
- (b"HEAD", 18),
86
- (b"OPTIONS", 19),
87
- (b"POST", 20),
88
- (b"PUT", 21),
89
- ]),
84
+ (
85
+ b":method",
86
+ &[
87
+ (b"CONNECT", 15),
88
+ (b"DELETE", 16),
89
+ (b"GET", 17),
90
+ (b"HEAD", 18),
91
+ (b"OPTIONS", 19),
92
+ (b"POST", 20),
93
+ (b"PUT", 21),
94
+ ],
95
+ ),
90
96
  ],
91
97
  // Headers of len 8
92
98
  &[(b"location", &[(b"", 12)]), (b"if-range", &[(b"", 89)])],
@@ -102,33 +108,39 @@ pub const STATIC_ENCODE_TABLE: &[&[(HeaderName, HeaderValueEncPairs)]] = &[
102
108
  // Headers of len 11
103
109
  &[],
104
110
  // Headers of len 12
105
- &[(b"content-type", &[
106
- (b"application/dns-message", 44),
107
- (b"application/javascript", 45),
108
- (b"application/json", 46),
109
- (b"application/x-www-form-urlencoded", 47),
110
- (b"image/gif", 48),
111
- (b"image/jpeg", 49),
112
- (b"image/png", 50),
113
- (b"text/css", 51),
114
- (b"text/html; charset=utf-8", 52),
115
- (b"text/plain", 53),
116
- (b"text/plain;charset=utf-8", 54),
117
- ])],
111
+ &[(
112
+ b"content-type",
113
+ &[
114
+ (b"application/dns-message", 44),
115
+ (b"application/javascript", 45),
116
+ (b"application/json", 46),
117
+ (b"application/x-www-form-urlencoded", 47),
118
+ (b"image/gif", 48),
119
+ (b"image/jpeg", 49),
120
+ (b"image/png", 50),
121
+ (b"text/css", 51),
122
+ (b"text/html; charset=utf-8", 52),
123
+ (b"text/plain", 53),
124
+ (b"text/plain;charset=utf-8", 54),
125
+ ],
126
+ )],
118
127
  // Headers of len 13
119
128
  &[
120
129
  (b"last-modified", &[(b"", 10)]),
121
130
  (b"accept-ranges", &[(b"bytes", 32)]),
122
131
  (b"authorization", &[(b"", 84)]),
123
132
  (b"if-none-match", &[(b"", 9)]),
124
- (b"cache-control", &[
125
- (b"max-age=0", 36),
126
- (b"max-age=2592000", 37),
127
- (b"max-age=604800", 38),
128
- (b"no-cache", 39),
129
- (b"no-store", 40),
130
- (b"public, max-age=31536000", 41),
131
- ]),
133
+ (
134
+ b"cache-control",
135
+ &[
136
+ (b"max-age=0", 36),
137
+ (b"max-age=2592000", 37),
138
+ (b"max-age=604800", 38),
139
+ (b"no-cache", 39),
140
+ (b"no-store", 40),
141
+ (b"public, max-age=31536000", 41),
142
+ ],
143
+ ),
132
144
  ],
133
145
  // Headers of len 14
134
146
  &[(b"content-length", &[(b"0", 4)])],
@@ -160,20 +172,23 @@ pub const STATIC_ENCODE_TABLE: &[&[(HeaderName, HeaderValueEncPairs)]] = &[
160
172
  // Headers of len 22
161
173
  &[(b"x-content-type-options", &[(b"nosniff", 61)])],
162
174
  // Headers of len 23
163
- &[(b"content-security-policy", &[(
164
- b"script-src 'none'; object-src 'none'; base-uri 'none'",
165
- 85,
166
- )])],
175
+ &[(
176
+ b"content-security-policy",
177
+ &[(b"script-src 'none'; object-src 'none'; base-uri 'none'", 85)],
178
+ )],
167
179
  // Headers of len 24
168
180
  &[],
169
181
  // Headers of len 25
170
182
  &[
171
183
  (b"upgrade-insecure-requests", &[(b"1", 94)]),
172
- (b"strict-transport-security", &[
173
- (b"max-age=31536000", 56),
174
- (b"max-age=31536000; includesubdomains", 57),
175
- (b"max-age=31536000; includesubdomains; preload", 58),
176
- ]),
184
+ (
185
+ b"strict-transport-security",
186
+ &[
187
+ (b"max-age=31536000", 56),
188
+ (b"max-age=31536000; includesubdomains", 57),
189
+ (b"max-age=31536000; includesubdomains; preload", 58),
190
+ ],
191
+ ),
177
192
  ],
178
193
  // Headers of len 26
179
194
  &[],
@@ -181,34 +196,32 @@ pub const STATIC_ENCODE_TABLE: &[&[(HeaderName, HeaderValueEncPairs)]] = &[
181
196
  &[(b"access-control-allow-origin", &[(b"*", 35)])],
182
197
  // Headers of len 28
183
198
  &[
184
- (b"access-control-allow-methods", &[
185
- (b"get", 76),
186
- (b"get, post, options", 77),
187
- (b"options", 78),
188
- ]),
189
- (b"access-control-allow-headers", &[
190
- (b"cache-control", 33),
191
- (b"content-type", 34),
192
- (b"*", 75),
193
- ]),
199
+ (
200
+ b"access-control-allow-methods",
201
+ &[(b"get", 76), (b"get, post, options", 77), (b"options", 78)],
202
+ ),
203
+ (
204
+ b"access-control-allow-headers",
205
+ &[(b"cache-control", 33), (b"content-type", 34), (b"*", 75)],
206
+ ),
194
207
  ],
195
208
  // Headers of len 29
196
209
  &[
197
210
  (b"access-control-expose-headers", &[(b"content-length", 79)]),
198
- (b"access-control-request-method", &[
199
- (b"get", 81),
200
- (b"post", 82),
201
- ]),
211
+ (
212
+ b"access-control-request-method",
213
+ &[(b"get", 81), (b"post", 82)],
214
+ ),
202
215
  ],
203
216
  // Headers of len 30
204
217
  &[(b"access-control-request-headers", &[(b"content-type", 80)])],
205
218
  // Headers of len 31
206
219
  &[],
207
220
  // Headers of len 32
208
- &[(b"access-control-allow-credentials", &[
209
- (b"FALSE", 73),
210
- (b"TRUE", 74),
211
- ])],
221
+ &[(
222
+ b"access-control-allow-credentials",
223
+ &[(b"FALSE", 73), (b"TRUE", 74)],
224
+ )],
212
225
  ];
213
226
 
214
227
  pub const STATIC_DECODE_TABLE: [(&[u8], &[u8]); 99] = [