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.
- package/Cargo.lock +153 -226
- package/Cargo.toml +5 -5
- package/README.md +4 -4
- package/crates/echo-server/src/bin/gen-test-cert.rs +1 -1
- package/crates/native/Cargo.toml +1 -1
- package/crates/native/src/config.rs +13 -1
- package/crates/native/src/driver.rs +249 -91
- package/crates/native/src/lib.rs +9 -10
- package/crates/native/src/parser_memory.rs +1 -0
- package/crates/native/src/server.rs +197 -182
- package/crates/native/src/session.rs +329 -177
- package/crates/native/src/test_support.rs +2 -2
- package/crates/wtcore/src/h3.rs +166 -10
- package/dist/index.js +92 -45
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +92 -45
- package/dist/index.mjs.map +2 -2
- package/dist/native.d.ts +9 -4
- package/package.json +14 -11
- package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-x64/rwebtransport.node +0 -0
- package/prebuilds/win32-x64/rwebtransport.node +0 -0
- package/scripts/build-linux-prebuilt.sh +46 -0
- package/scripts/build.js +10 -3
- package/vendor/quiche/AGENTS.md +10 -0
- package/vendor/quiche/Cargo.lock +239 -248
- package/vendor/quiche/Cargo.toml +23 -10
- package/vendor/quiche/examples/Makefile +4 -4
- package/vendor/quiche/examples/client.rs +10 -28
- package/vendor/quiche/examples/http3-client.rs +20 -34
- package/vendor/quiche/examples/http3-server.rs +47 -78
- package/vendor/quiche/examples/server.rs +19 -49
- package/vendor/quiche/include/quiche.h +35 -4
- package/vendor/quiche/src/build.rs +17 -0
- package/vendor/quiche/src/cid.rs +129 -61
- package/vendor/quiche/src/crypto/boringssl.rs +98 -86
- package/vendor/quiche/src/crypto/mod.rs +64 -77
- package/vendor/quiche/src/dgram.rs +2 -3
- package/vendor/quiche/src/error.rs +22 -20
- package/vendor/quiche/src/ffi.rs +558 -280
- package/vendor/quiche/src/flowcontrol.rs +0 -7
- package/vendor/quiche/src/frame.rs +134 -135
- package/vendor/quiche/src/h3/ffi.rs +73 -60
- package/vendor/quiche/src/h3/frame.rs +70 -90
- package/vendor/quiche/src/h3/mod.rs +1024 -593
- package/vendor/quiche/src/h3/qpack/decoder.rs +248 -34
- package/vendor/quiche/src/h3/qpack/dynamic_table.rs +859 -0
- package/vendor/quiche/src/h3/qpack/encoder.rs +14 -17
- package/vendor/quiche/src/h3/qpack/mod.rs +48 -0
- package/vendor/quiche/src/h3/qpack/static_table.rs +86 -73
- package/vendor/quiche/src/h3/stream.rs +1009 -194
- package/vendor/quiche/src/lib.rs +1346 -1195
- package/vendor/quiche/src/minmax.rs +2 -6
- package/vendor/quiche/src/packet.rs +420 -552
- package/vendor/quiche/src/path.rs +202 -72
- package/vendor/quiche/src/pmtud.rs +18 -16
- package/vendor/quiche/src/ranges.rs +184 -82
- package/vendor/quiche/src/recovery/AGENTS.md +5 -2
- package/vendor/quiche/src/recovery/bandwidth.rs +59 -40
- package/vendor/quiche/src/recovery/bytes_in_flight.rs +2 -2
- package/vendor/quiche/src/recovery/congestion/cubic.rs +38 -47
- package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +54 -60
- package/vendor/quiche/src/recovery/congestion/hystart.rs +6 -10
- package/vendor/quiche/src/recovery/congestion/mod.rs +110 -42
- package/vendor/quiche/src/recovery/congestion/prr.rs +4 -1
- package/vendor/quiche/src/recovery/congestion/recovery.rs +91 -95
- package/vendor/quiche/src/recovery/congestion/reno.rs +17 -12
- package/vendor/quiche/src/recovery/congestion/test_sender.rs +8 -27
- package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +159 -247
- package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +9 -14
- package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +18 -15
- package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +43 -28
- package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +349 -76
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +147 -195
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +29 -27
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min.rs +180 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min_tests.rs +221 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm.rs +395 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm_tests.rs +473 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/mod.rs +175 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +33 -26
- package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +107 -60
- package/vendor/quiche/src/recovery/gcongestion/mod.rs +64 -11
- package/vendor/quiche/src/recovery/gcongestion/pacer.rs +34 -25
- package/vendor/quiche/src/recovery/gcongestion/recovery.rs +81 -86
- package/vendor/quiche/src/recovery/mod.rs +414 -173
- package/vendor/quiche/src/recovery/rtt.rs +8 -5
- package/vendor/quiche/src/stream/mod.rs +864 -133
- package/vendor/quiche/src/stream/recv_buf.rs +471 -172
- package/vendor/quiche/src/stream/send_buf.rs +338 -81
- package/vendor/quiche/src/test_utils.rs +78 -64
- package/vendor/quiche/src/tests.rs +2559 -1335
- package/vendor/quiche/src/tls/boringssl.rs +60 -63
- package/vendor/quiche/src/tls/mod.rs +146 -193
- package/vendor/quiche/src/transport_params.rs +87 -103
|
@@ -36,7 +36,7 @@ pub fn pair(
|
|
|
36
36
|
.unwrap();
|
|
37
37
|
cert.set_not_after(&Asn1Time::days_from_now(1).unwrap())
|
|
38
38
|
.unwrap();
|
|
39
|
-
cert.append_extension(BasicConstraints::new().critical().ca().build().unwrap())
|
|
39
|
+
cert.append_extension(&BasicConstraints::new().critical().ca().build().unwrap())
|
|
40
40
|
.unwrap();
|
|
41
41
|
let mut san = SubjectAlternativeName::new();
|
|
42
42
|
san.dns("wrong.example");
|
|
@@ -44,7 +44,7 @@ pub fn pair(
|
|
|
44
44
|
san.ip("127.0.0.1").ip("::1");
|
|
45
45
|
}
|
|
46
46
|
let san = san.build(&cert.x509v3_context(None, None)).unwrap();
|
|
47
|
-
cert.append_extension(san).unwrap();
|
|
47
|
+
cert.append_extension(&san).unwrap();
|
|
48
48
|
cert.sign(&key, MessageDigest::sha256()).unwrap();
|
|
49
49
|
static NEXT: AtomicU64 = AtomicU64::new(0);
|
|
50
50
|
let dir = std::env::temp_dir().join(format!(
|
package/crates/wtcore/src/h3.rs
CHANGED
|
@@ -33,6 +33,25 @@ pub const SETTINGS_H3_DATAGRAM: u64 = 0x33;
|
|
|
33
33
|
pub const SETTINGS_WT_MAX_SESSIONS: u64 = 0x14e9_cd29;
|
|
34
34
|
/// Older draft `SETTINGS_ENABLE_WEBTRANSPORT` (kept for maximum compatibility).
|
|
35
35
|
pub const SETTINGS_ENABLE_WEBTRANSPORT: u64 = 0x2b60_3742;
|
|
36
|
+
/// draft-ietf-webtrans-http3-17 SETTINGS_WT_ENABLED.
|
|
37
|
+
pub const SETTINGS_WT_ENABLED: u64 = 0x20b8_933b;
|
|
38
|
+
pub const SETTINGS_WT_ENABLED_DRAFT15: u64 = 0x2c7c_f000;
|
|
39
|
+
pub const LEGACY_WT_TOKEN: &[u8] = b"webtransport";
|
|
40
|
+
pub const WT_H3_TOKEN: &[u8] = b"webtransport-h3";
|
|
41
|
+
pub const WT_EXPORTER_LABEL: &[u8] = b"EXPORTER-WebTransport";
|
|
42
|
+
|
|
43
|
+
/// Serialize the session-bound exporter context from WebTransport-H3 §4.8.
|
|
44
|
+
pub fn exporter_context(session_id: u64, label: &[u8], context: &[u8]) -> Option<Vec<u8>> {
|
|
45
|
+
let label_len = u8::try_from(label.len()).ok()?;
|
|
46
|
+
let context_len = u8::try_from(context.len()).ok()?;
|
|
47
|
+
let mut output = Vec::with_capacity(10 + label.len() + context.len());
|
|
48
|
+
output.extend_from_slice(&session_id.to_be_bytes());
|
|
49
|
+
output.push(label_len);
|
|
50
|
+
output.extend_from_slice(label);
|
|
51
|
+
output.push(context_len);
|
|
52
|
+
output.extend_from_slice(context);
|
|
53
|
+
Some(output)
|
|
54
|
+
}
|
|
36
55
|
/// `SETTINGS_WT_INITIAL_MAX_DATA`: initial per-session send-data allowance.
|
|
37
56
|
pub const SETTINGS_WT_INITIAL_MAX_DATA: u64 = 0x2b61;
|
|
38
57
|
/// `SETTINGS_WT_INITIAL_MAX_STREAMS_UNI`: initial per-session uni stream limit.
|
|
@@ -171,9 +190,20 @@ pub fn frame(ty: u64, payload: &[u8]) -> Vec<u8> {
|
|
|
171
190
|
/// Bytes for the client control stream: the stream-type prefix followed by our
|
|
172
191
|
/// SETTINGS frame.
|
|
173
192
|
pub fn control_stream_prefix() -> Vec<u8> {
|
|
193
|
+
control_stream_prefix_for(false)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
pub fn control_stream_prefix_for(reliable_reset: bool) -> Vec<u8> {
|
|
174
197
|
let mut out = Vec::new();
|
|
175
198
|
put_varint(H3_CONTROL_STREAM_TYPE, &mut out);
|
|
176
|
-
|
|
199
|
+
let mut settings = settings_payload();
|
|
200
|
+
if reliable_reset {
|
|
201
|
+
put_varint(SETTINGS_WT_ENABLED, &mut settings);
|
|
202
|
+
put_varint(1, &mut settings);
|
|
203
|
+
put_varint(SETTINGS_WT_ENABLED_DRAFT15, &mut settings);
|
|
204
|
+
put_varint(1, &mut settings);
|
|
205
|
+
}
|
|
206
|
+
out.extend_from_slice(&frame(FRAME_SETTINGS, &settings));
|
|
177
207
|
out
|
|
178
208
|
}
|
|
179
209
|
|
|
@@ -188,7 +218,7 @@ pub fn settings_payload() -> Vec<u8> {
|
|
|
188
218
|
(SETTINGS_ENABLE_CONNECT_PROTOCOL, 1),
|
|
189
219
|
(SETTINGS_H3_DATAGRAM, 1),
|
|
190
220
|
(SETTINGS_ENABLE_WEBTRANSPORT, 1),
|
|
191
|
-
(SETTINGS_WT_MAX_SESSIONS,
|
|
221
|
+
(SETTINGS_WT_MAX_SESSIONS, 1),
|
|
192
222
|
(SETTINGS_WT_INITIAL_MAX_DATA, WT_INITIAL_MAX_DATA),
|
|
193
223
|
(SETTINGS_WT_INITIAL_MAX_STREAMS_BIDI, WT_INITIAL_MAX_STREAMS),
|
|
194
224
|
(SETTINGS_WT_INITIAL_MAX_STREAMS_UNI, WT_INITIAL_MAX_STREAMS),
|
|
@@ -206,6 +236,8 @@ pub struct PeerSettings {
|
|
|
206
236
|
pub enable_connect_protocol: bool,
|
|
207
237
|
pub h3_datagram: bool,
|
|
208
238
|
pub enable_webtransport: bool,
|
|
239
|
+
pub wt_enabled: bool,
|
|
240
|
+
pub wt_enabled_draft15: bool,
|
|
209
241
|
pub wt_max_sessions: u64,
|
|
210
242
|
/// Peer's initial per-session send-data allowance (SETTINGS_WT_INITIAL_MAX_DATA).
|
|
211
243
|
pub wt_initial_max_data: u64,
|
|
@@ -236,7 +268,10 @@ pub fn parse_settings(mut payload: &[u8]) -> Result<PeerSettings, String> {
|
|
|
236
268
|
}
|
|
237
269
|
if matches!(
|
|
238
270
|
id,
|
|
239
|
-
SETTINGS_ENABLE_CONNECT_PROTOCOL
|
|
271
|
+
SETTINGS_ENABLE_CONNECT_PROTOCOL
|
|
272
|
+
| SETTINGS_H3_DATAGRAM
|
|
273
|
+
| SETTINGS_ENABLE_WEBTRANSPORT
|
|
274
|
+
| SETTINGS_WT_ENABLED
|
|
240
275
|
) && val > 1
|
|
241
276
|
{
|
|
242
277
|
return Err("invalid boolean SETTINGS value".into());
|
|
@@ -252,6 +287,8 @@ pub fn parse_settings(mut payload: &[u8]) -> Result<PeerSettings, String> {
|
|
|
252
287
|
SETTINGS_ENABLE_CONNECT_PROTOCOL => s.enable_connect_protocol = val != 0,
|
|
253
288
|
SETTINGS_H3_DATAGRAM => s.h3_datagram = val != 0,
|
|
254
289
|
SETTINGS_ENABLE_WEBTRANSPORT => s.enable_webtransport = val != 0,
|
|
290
|
+
SETTINGS_WT_ENABLED => s.wt_enabled = val != 0,
|
|
291
|
+
SETTINGS_WT_ENABLED_DRAFT15 => s.wt_enabled_draft15 = val != 0,
|
|
255
292
|
SETTINGS_WT_MAX_SESSIONS => s.wt_max_sessions = val,
|
|
256
293
|
SETTINGS_WT_INITIAL_MAX_DATA => s.wt_initial_max_data = val,
|
|
257
294
|
SETTINGS_WT_INITIAL_MAX_STREAMS_BIDI => s.wt_initial_max_streams_bidi = val,
|
|
@@ -270,6 +307,84 @@ pub const WT_AVAILABLE_PROTOCOLS: &[u8] = b"wt-available-protocols";
|
|
|
270
307
|
/// Structured-Field Item String.
|
|
271
308
|
pub const WT_PROTOCOL: &[u8] = b"wt-protocol";
|
|
272
309
|
|
|
310
|
+
/// Validated request routing fields and the selected HTTP upgrade token.
|
|
311
|
+
pub struct ConnectTarget<'a> {
|
|
312
|
+
pub protocol: &'a [u8],
|
|
313
|
+
pub authority: &'a str,
|
|
314
|
+
pub path: &'a str,
|
|
315
|
+
pub origin: Option<&'a str>,
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
pub fn validate_connect_headers(headers: &[Header]) -> Option<ConnectTarget<'_>> {
|
|
319
|
+
use quiche::h3::NameValue;
|
|
320
|
+
|
|
321
|
+
let (mut method, mut protocol, mut scheme, mut authority, mut path, mut origin) =
|
|
322
|
+
(None, None, None, None, None, None);
|
|
323
|
+
let mut regular = false;
|
|
324
|
+
for header in headers {
|
|
325
|
+
let (name, value) = (header.name(), header.value());
|
|
326
|
+
if value.iter().any(|&b| b == 0 || b == b'\r' || b == b'\n') {
|
|
327
|
+
return None;
|
|
328
|
+
}
|
|
329
|
+
if name.first() == Some(&b':') {
|
|
330
|
+
if regular {
|
|
331
|
+
return None;
|
|
332
|
+
}
|
|
333
|
+
let field = match name {
|
|
334
|
+
b":method" => &mut method,
|
|
335
|
+
b":protocol" => &mut protocol,
|
|
336
|
+
b":scheme" => &mut scheme,
|
|
337
|
+
b":authority" => &mut authority,
|
|
338
|
+
b":path" => &mut path,
|
|
339
|
+
_ => return None,
|
|
340
|
+
};
|
|
341
|
+
if field.replace(value).is_some() {
|
|
342
|
+
return None;
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
regular = true;
|
|
346
|
+
if name.is_empty()
|
|
347
|
+
|| !name.iter().all(|b| {
|
|
348
|
+
b.is_ascii_lowercase() || b.is_ascii_digit() || b"!#$%&'*+-.^_`|~".contains(b)
|
|
349
|
+
})
|
|
350
|
+
|| matches!(
|
|
351
|
+
name,
|
|
352
|
+
b"connection"
|
|
353
|
+
| b"proxy-connection"
|
|
354
|
+
| b"keep-alive"
|
|
355
|
+
| b"transfer-encoding"
|
|
356
|
+
| b"upgrade"
|
|
357
|
+
)
|
|
358
|
+
|| (name == b"te" && !value.eq_ignore_ascii_case(b"trailers"))
|
|
359
|
+
{
|
|
360
|
+
return None;
|
|
361
|
+
}
|
|
362
|
+
if name == b"origin" && origin.replace(std::str::from_utf8(value).ok()?).is_some() {
|
|
363
|
+
return None;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
let authority = std::str::from_utf8(authority?).ok()?;
|
|
368
|
+
let path = std::str::from_utf8(path?).ok()?;
|
|
369
|
+
if method? != b"CONNECT"
|
|
370
|
+
|| scheme? != b"https"
|
|
371
|
+
|| authority.is_empty()
|
|
372
|
+
|| authority
|
|
373
|
+
.bytes()
|
|
374
|
+
.any(|b| !b.is_ascii_graphic() || b"@/?#".contains(&b))
|
|
375
|
+
|| !path.starts_with('/')
|
|
376
|
+
|| path.bytes().any(|b| !b.is_ascii_graphic() || b == b'#')
|
|
377
|
+
{
|
|
378
|
+
return None;
|
|
379
|
+
}
|
|
380
|
+
Some(ConnectTarget {
|
|
381
|
+
protocol: protocol?,
|
|
382
|
+
authority,
|
|
383
|
+
path,
|
|
384
|
+
origin,
|
|
385
|
+
})
|
|
386
|
+
}
|
|
387
|
+
|
|
273
388
|
/// Build the Extended CONNECT request header list for a WebTransport session.
|
|
274
389
|
pub fn connect_headers(
|
|
275
390
|
authority: &str,
|
|
@@ -277,10 +392,21 @@ pub fn connect_headers(
|
|
|
277
392
|
origin: Option<&str>,
|
|
278
393
|
extra: &[(String, String)],
|
|
279
394
|
protocols: &[String],
|
|
395
|
+
) -> Vec<Header> {
|
|
396
|
+
connect_headers_for(LEGACY_WT_TOKEN, authority, path, origin, extra, protocols)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
pub fn connect_headers_for(
|
|
400
|
+
token: &[u8],
|
|
401
|
+
authority: &str,
|
|
402
|
+
path: &str,
|
|
403
|
+
origin: Option<&str>,
|
|
404
|
+
extra: &[(String, String)],
|
|
405
|
+
protocols: &[String],
|
|
280
406
|
) -> Vec<Header> {
|
|
281
407
|
let mut h = vec![
|
|
282
408
|
Header::new(b":method", b"CONNECT"),
|
|
283
|
-
Header::new(b":protocol",
|
|
409
|
+
Header::new(b":protocol", token),
|
|
284
410
|
Header::new(b":scheme", b"https"),
|
|
285
411
|
Header::new(b":authority", authority.as_bytes()),
|
|
286
412
|
Header::new(b":path", path.as_bytes()),
|
|
@@ -408,18 +534,48 @@ pub fn decode_header_block(block: &[u8]) -> Result<Vec<Header>, String> {
|
|
|
408
534
|
|
|
409
535
|
/// Extract the numeric `:status` from a decoded response header list.
|
|
410
536
|
pub fn status_of(headers: &[Header]) -> Option<u16> {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
537
|
+
let (first, rest) = headers.split_first()?;
|
|
538
|
+
let status = first.value();
|
|
539
|
+
if first.name() != b":status"
|
|
540
|
+
|| status.len() != 3
|
|
541
|
+
|| !status.iter().all(u8::is_ascii_digit)
|
|
542
|
+
|| rest.iter().any(|field| field.name().starts_with(b":"))
|
|
543
|
+
{
|
|
544
|
+
return None;
|
|
415
545
|
}
|
|
416
|
-
|
|
546
|
+
let status = std::str::from_utf8(status).ok()?.parse().ok()?;
|
|
547
|
+
((100..600).contains(&status) && status != 101).then_some(status)
|
|
417
548
|
}
|
|
418
549
|
|
|
419
550
|
#[cfg(test)]
|
|
420
551
|
mod tests {
|
|
421
552
|
use super::*;
|
|
422
553
|
|
|
554
|
+
#[test]
|
|
555
|
+
fn validates_extended_connect_routing_fields() {
|
|
556
|
+
let mut request =
|
|
557
|
+
connect_headers_for(WT_H3_TOKEN, "example.test", "/x?q=1", None, &[], &[]);
|
|
558
|
+
assert_eq!(
|
|
559
|
+
validate_connect_headers(&request).unwrap().protocol,
|
|
560
|
+
WT_H3_TOKEN
|
|
561
|
+
);
|
|
562
|
+
request.push(Header::new(b":path", b"/other"));
|
|
563
|
+
assert!(validate_connect_headers(&request).is_none());
|
|
564
|
+
request.pop();
|
|
565
|
+
request.remove(2);
|
|
566
|
+
assert!(validate_connect_headers(&request).is_none());
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
#[test]
|
|
570
|
+
fn exporter_context_includes_session_id_and_both_field_lengths() {
|
|
571
|
+
assert_eq!(
|
|
572
|
+
exporter_context(4, b"ab", b"c").unwrap(),
|
|
573
|
+
[0, 0, 0, 0, 0, 0, 0, 4, 2, b'a', b'b', 1, b'c']
|
|
574
|
+
);
|
|
575
|
+
assert!(exporter_context(0, &[0; 256], b"").is_none());
|
|
576
|
+
assert!(exporter_context(0, b"", &[0; 256]).is_none());
|
|
577
|
+
}
|
|
578
|
+
|
|
423
579
|
#[test]
|
|
424
580
|
fn settings_reject_truncation_duplicates_and_invalid_boolean_values() {
|
|
425
581
|
for pairs in [
|
|
@@ -526,7 +682,7 @@ mod tests {
|
|
|
526
682
|
fn settings_advertise_and_parse_wt_flow_control() {
|
|
527
683
|
let s = parse_settings(&settings_payload()).unwrap();
|
|
528
684
|
assert!(s.webtransport_ok());
|
|
529
|
-
assert_eq!(s.wt_max_sessions,
|
|
685
|
+
assert_eq!(s.wt_max_sessions, 1);
|
|
530
686
|
assert_eq!(s.wt_initial_max_data, WT_INITIAL_MAX_DATA);
|
|
531
687
|
assert_eq!(s.wt_initial_max_streams_bidi, WT_INITIAL_MAX_STREAMS);
|
|
532
688
|
assert_eq!(s.wt_initial_max_streams_uni, WT_INITIAL_MAX_STREAMS);
|
package/dist/index.js
CHANGED
|
@@ -52,37 +52,58 @@ function assertSupportedRuntime() {
|
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
function prebuiltPath() {
|
|
56
|
-
return (0, import_node_path.join)(
|
|
57
|
-
PACKAGE_ROOT,
|
|
58
|
-
"prebuilds",
|
|
59
|
-
`${process.platform}-${process.arch}`,
|
|
60
|
-
"rwebtransport.node"
|
|
61
|
-
);
|
|
55
|
+
function prebuiltPath(name = "rwebtransport.node") {
|
|
56
|
+
return (0, import_node_path.join)(PACKAGE_ROOT, "prebuilds", `${process.platform}-${process.arch}`, name);
|
|
62
57
|
}
|
|
63
58
|
var cached;
|
|
64
59
|
function loadNative() {
|
|
65
60
|
if (cached) return cached;
|
|
66
61
|
assertSupportedRuntime();
|
|
67
62
|
const prebuilt = prebuiltPath();
|
|
63
|
+
let prebuildError;
|
|
64
|
+
let output = prebuilt;
|
|
68
65
|
if ((0, import_node_fs.existsSync)(prebuilt)) {
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
try {
|
|
67
|
+
cached = require2(prebuilt);
|
|
68
|
+
return cached;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (!(error instanceof Error) || error.code !== "ERR_DLOPEN_FAILED") {
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
prebuildError = error;
|
|
74
|
+
output = prebuiltPath("rwebtransport-local.node");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (output !== prebuilt && (0, import_node_fs.existsSync)(output)) {
|
|
78
|
+
try {
|
|
79
|
+
cached = require2(output);
|
|
80
|
+
return cached;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (!(error instanceof Error) || error.code !== "ERR_DLOPEN_FAILED") {
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
71
86
|
}
|
|
72
87
|
const builder = (0, import_node_path.join)(PACKAGE_ROOT, "scripts", "build.js");
|
|
73
88
|
if (!(0, import_node_fs.existsSync)(builder)) {
|
|
74
89
|
throw new Error(
|
|
75
|
-
`rwebtransport: no
|
|
90
|
+
`rwebtransport: no usable native binary at ${prebuilt} and no build script to compile one. Reinstall the package or build it manually (npm run build:rust).`,
|
|
91
|
+
{ cause: prebuildError }
|
|
76
92
|
);
|
|
77
93
|
}
|
|
78
94
|
process.stderr.write(
|
|
79
|
-
"rwebtransport: no
|
|
95
|
+
"rwebtransport: no usable native binary for this platform; compiling the native addon...\n"
|
|
80
96
|
);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
97
|
+
const args = output === prebuilt ? [builder] : [builder, "--fallback"];
|
|
98
|
+
try {
|
|
99
|
+
(0, import_node_child_process.execFileSync)(process.execPath, args, { cwd: PACKAGE_ROOT, stdio: "inherit" });
|
|
100
|
+
} catch (error) {
|
|
101
|
+
const detail = prebuildError instanceof Error ? ` (${prebuildError.message})` : "";
|
|
102
|
+
throw new Error(`rwebtransport: unable to build a native addon for this system${detail}`, {
|
|
103
|
+
cause: error
|
|
104
|
+
});
|
|
84
105
|
}
|
|
85
|
-
cached = require2(
|
|
106
|
+
cached = require2(output);
|
|
86
107
|
return cached;
|
|
87
108
|
}
|
|
88
109
|
|
|
@@ -166,6 +187,7 @@ var SessionCore = class {
|
|
|
166
187
|
cachedProtocol = "";
|
|
167
188
|
/** The CONNECT response headers, cached from the client ready event. */
|
|
168
189
|
cachedResponseHeaders = [];
|
|
190
|
+
advertisedDatagramSize;
|
|
169
191
|
/**
|
|
170
192
|
* Resolves when the session is established, rejects if it fails before then.
|
|
171
193
|
* Backs the public `WebTransport.ready` promise.
|
|
@@ -271,14 +293,18 @@ var SessionCore = class {
|
|
|
271
293
|
*/
|
|
272
294
|
resetStream(streamId, code) {
|
|
273
295
|
this.transport?.reset(streamId, code >>> 0);
|
|
296
|
+
this.rejectStreamWrites(
|
|
297
|
+
streamId,
|
|
298
|
+
new WebTransportError("stream aborted", {
|
|
299
|
+
source: "stream",
|
|
300
|
+
streamErrorCode: code >>> 0
|
|
301
|
+
})
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
rejectStreamWrites(streamId, error) {
|
|
274
305
|
for (const [requestId, write] of this.writes) {
|
|
275
306
|
if (write.streamId === streamId) {
|
|
276
|
-
write.deferred.reject(
|
|
277
|
-
new WebTransportError("stream aborted", {
|
|
278
|
-
source: "stream",
|
|
279
|
-
streamErrorCode: code >>> 0
|
|
280
|
-
})
|
|
281
|
-
);
|
|
307
|
+
write.deferred.reject(error);
|
|
282
308
|
this.writes.delete(requestId);
|
|
283
309
|
}
|
|
284
310
|
}
|
|
@@ -320,7 +346,8 @@ var SessionCore = class {
|
|
|
320
346
|
* @returns The maximum datagram payload size in bytes, or 0 if not attached.
|
|
321
347
|
*/
|
|
322
348
|
maxDatagramSize() {
|
|
323
|
-
|
|
349
|
+
if (this.closedState) return 0;
|
|
350
|
+
return this.advertisedDatagramSize ?? this.transport?.maxDatagramSize?.() ?? 0;
|
|
324
351
|
}
|
|
325
352
|
/**
|
|
326
353
|
* Gracefully close the session. No-op if already closed or not attached.
|
|
@@ -500,6 +527,10 @@ var SessionCore = class {
|
|
|
500
527
|
this.datagramSink?.(ev.data);
|
|
501
528
|
break;
|
|
502
529
|
}
|
|
530
|
+
case "datagramSize" /* DatagramSize */: {
|
|
531
|
+
this.advertisedDatagramSize = ev.size;
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
503
534
|
case "stream" /* Stream */: {
|
|
504
535
|
if (ev.bidi) this.incoming?.onBidi(ev.streamId);
|
|
505
536
|
else this.incoming?.onUni(ev.streamId);
|
|
@@ -518,6 +549,13 @@ var SessionCore = class {
|
|
|
518
549
|
break;
|
|
519
550
|
}
|
|
520
551
|
case "streamStopSending" /* StreamStopSending */: {
|
|
552
|
+
this.rejectStreamWrites(
|
|
553
|
+
ev.streamId,
|
|
554
|
+
new WebTransportError("peer sent STOP_SENDING", {
|
|
555
|
+
source: "stream",
|
|
556
|
+
streamErrorCode: ev.code
|
|
557
|
+
})
|
|
558
|
+
);
|
|
521
559
|
this.sends.get(ev.streamId)?.onStopSending(ev.code);
|
|
522
560
|
break;
|
|
523
561
|
}
|
|
@@ -527,8 +565,13 @@ var SessionCore = class {
|
|
|
527
565
|
break;
|
|
528
566
|
}
|
|
529
567
|
case "writeAck" /* WriteAck */: {
|
|
530
|
-
this.writes.get(ev.requestId)
|
|
568
|
+
const write = this.writes.get(ev.requestId);
|
|
531
569
|
this.writes.delete(ev.requestId);
|
|
570
|
+
if (ev.accepted) write?.deferred.resolve();
|
|
571
|
+
else
|
|
572
|
+
write?.deferred.reject(
|
|
573
|
+
new WebTransportError("stream is closed", { source: "stream" })
|
|
574
|
+
);
|
|
532
575
|
break;
|
|
533
576
|
}
|
|
534
577
|
case "datagramAck" /* DatagramAck */: {
|
|
@@ -809,10 +852,6 @@ var ServerTransport = class {
|
|
|
809
852
|
sendDatagram(bytes, requestId) {
|
|
810
853
|
this.native.serverSendDatagram(this.handle, this.session, bytes, requestId);
|
|
811
854
|
}
|
|
812
|
-
/** @returns The maximum datagram payload size, in bytes. */
|
|
813
|
-
maxDatagramSize() {
|
|
814
|
-
return this.native.serverMaxDatagramSize(this.handle);
|
|
815
|
-
}
|
|
816
855
|
/**
|
|
817
856
|
* @param code - The WebTransport close code.
|
|
818
857
|
* @param reason - The UTF-8 encoded close reason.
|
|
@@ -933,9 +972,8 @@ var WebTransportDatagramDuplexStream = class {
|
|
|
933
972
|
*
|
|
934
973
|
* 1. Creates {@link readable} and captures its controller from `start`.
|
|
935
974
|
* 2. Installs a datagram sink that enqueues each received datagram only
|
|
936
|
-
* while the controller's `desiredSize` is positive
|
|
937
|
-
*
|
|
938
|
-
* arrive when the queue is full are dropped.
|
|
975
|
+
* while the controller's `desiredSize` is positive. Datagrams that
|
|
976
|
+
* arrive after cancellation or when the queue is full are dropped.
|
|
939
977
|
* 3. Subscribes to the session's `closed` promise so the inbound stream is
|
|
940
978
|
* closed on both clean close and error, preventing a pending `read()`
|
|
941
979
|
* from hanging forever. A double-close is swallowed.
|
|
@@ -945,16 +983,20 @@ var WebTransportDatagramDuplexStream = class {
|
|
|
945
983
|
constructor(session) {
|
|
946
984
|
this.session = session;
|
|
947
985
|
let rController;
|
|
986
|
+
let receiving = true;
|
|
948
987
|
this.readable = new ReadableStream(
|
|
949
988
|
{
|
|
950
989
|
start(c) {
|
|
951
990
|
rController = c;
|
|
991
|
+
},
|
|
992
|
+
cancel() {
|
|
993
|
+
receiving = false;
|
|
952
994
|
}
|
|
953
995
|
},
|
|
954
996
|
new CountQueuingStrategy({ highWaterMark: this.incomingHwm })
|
|
955
997
|
);
|
|
956
998
|
session.setDatagramSink((data) => {
|
|
957
|
-
if ((rController.desiredSize ??
|
|
999
|
+
if (receiving && (rController.desiredSize ?? 0) > 0) {
|
|
958
1000
|
rController.enqueue(data);
|
|
959
1001
|
} else {
|
|
960
1002
|
session.recordDroppedIncomingDatagram();
|
|
@@ -1063,46 +1105,48 @@ var WebTransportReceiveStream = class extends ReadableStream {
|
|
|
1063
1105
|
* @remarks Installs the `ReadableStream` underlying source and registers a
|
|
1064
1106
|
* {@link ReceiveSink} on `session` for `streamId`:
|
|
1065
1107
|
*
|
|
1066
|
-
* - `pull`
|
|
1067
|
-
* quiche resumes draining inbound bytes when the consumer wants more.
|
|
1108
|
+
* - `pull` grants the native stream credit for one inbound chunk.
|
|
1068
1109
|
* - `cancel(reason)` sends `STOP_SENDING` to the peer with the code from
|
|
1069
1110
|
* {@link errorCode} and then unregisters the receive sink.
|
|
1070
|
-
* - The sink's `onData` enqueues each chunk and, once the controller's
|
|
1071
|
-
* `desiredSize` falls to zero or below (a nullish `desiredSize` is treated as
|
|
1072
|
-
* `1`, so it does not pause), pauses the native stream to flow-control the
|
|
1073
|
-
* peer.
|
|
1074
1111
|
* - The sink's `onFin` closes the controller (swallowing the error if it was
|
|
1075
1112
|
* already closed or errored) and unregisters.
|
|
1076
1113
|
* - The sink's `onReset(code)` errors the controller with a `'stream'`-sourced
|
|
1077
1114
|
* {@link WebTransportError} ('stream reset by peer') carrying the peer's code,
|
|
1078
1115
|
* then unregisters.
|
|
1079
1116
|
*
|
|
1080
|
-
* A
|
|
1081
|
-
* JS-side queue and thereby the pause threshold.
|
|
1117
|
+
* A zero high-water mark leaves unread payload in native flow control.
|
|
1082
1118
|
*/
|
|
1083
1119
|
constructor(session, streamId) {
|
|
1084
1120
|
let controller;
|
|
1121
|
+
let resolvePull;
|
|
1122
|
+
const finishPull = () => {
|
|
1123
|
+
const resolve = resolvePull;
|
|
1124
|
+
resolvePull = void 0;
|
|
1125
|
+
resolve?.();
|
|
1126
|
+
};
|
|
1085
1127
|
super(
|
|
1086
1128
|
{
|
|
1087
1129
|
start(c) {
|
|
1088
1130
|
controller = c;
|
|
1089
1131
|
},
|
|
1090
1132
|
pull() {
|
|
1133
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1134
|
+
resolvePull = resolve;
|
|
1091
1135
|
session.setPaused(streamId, false);
|
|
1136
|
+
return promise;
|
|
1092
1137
|
},
|
|
1093
1138
|
cancel(reason) {
|
|
1094
1139
|
session.stopSending(streamId, errorCode(reason));
|
|
1095
1140
|
session.unregisterReceive(streamId);
|
|
1141
|
+
finishPull();
|
|
1096
1142
|
}
|
|
1097
1143
|
},
|
|
1098
|
-
|
|
1144
|
+
{ highWaterMark: 0 }
|
|
1099
1145
|
);
|
|
1100
1146
|
session.registerReceive(streamId, {
|
|
1101
1147
|
onData(chunk) {
|
|
1102
1148
|
controller.enqueue(chunk);
|
|
1103
|
-
|
|
1104
|
-
session.setPaused(streamId, true);
|
|
1105
|
-
}
|
|
1149
|
+
finishPull();
|
|
1106
1150
|
},
|
|
1107
1151
|
onFin() {
|
|
1108
1152
|
try {
|
|
@@ -1110,6 +1154,7 @@ var WebTransportReceiveStream = class extends ReadableStream {
|
|
|
1110
1154
|
} catch {
|
|
1111
1155
|
}
|
|
1112
1156
|
session.unregisterReceive(streamId);
|
|
1157
|
+
finishPull();
|
|
1113
1158
|
},
|
|
1114
1159
|
onReset(code) {
|
|
1115
1160
|
controller.error(
|
|
@@ -1119,6 +1164,7 @@ var WebTransportReceiveStream = class extends ReadableStream {
|
|
|
1119
1164
|
})
|
|
1120
1165
|
);
|
|
1121
1166
|
session.unregisterReceive(streamId);
|
|
1167
|
+
finishPull();
|
|
1122
1168
|
},
|
|
1123
1169
|
onSessionClose(error) {
|
|
1124
1170
|
try {
|
|
@@ -1126,6 +1172,7 @@ var WebTransportReceiveStream = class extends ReadableStream {
|
|
|
1126
1172
|
} catch {
|
|
1127
1173
|
}
|
|
1128
1174
|
session.unregisterReceive(streamId);
|
|
1175
|
+
finishPull();
|
|
1129
1176
|
}
|
|
1130
1177
|
});
|
|
1131
1178
|
this.streamId = streamId;
|
|
@@ -1288,7 +1335,7 @@ function buildConfig(url, options) {
|
|
|
1288
1335
|
const headerNames = [];
|
|
1289
1336
|
const headerValues = [];
|
|
1290
1337
|
for (const [name, value] of Object.entries(options.headers ?? {})) {
|
|
1291
|
-
headerNames.push(name);
|
|
1338
|
+
headerNames.push(name.toLowerCase());
|
|
1292
1339
|
headerValues.push(value);
|
|
1293
1340
|
}
|
|
1294
1341
|
return {
|
|
@@ -1712,7 +1759,7 @@ var WebTransportServer = class {
|
|
|
1712
1759
|
const responseHeaderNames = [];
|
|
1713
1760
|
const responseHeaderValues = [];
|
|
1714
1761
|
for (const [name, value] of Object.entries(options.responseHeaders ?? {})) {
|
|
1715
|
-
responseHeaderNames.push(name);
|
|
1762
|
+
responseHeaderNames.push(name.toLowerCase());
|
|
1716
1763
|
responseHeaderValues.push(value);
|
|
1717
1764
|
}
|
|
1718
1765
|
this.handle = this.native.serverListen(
|