rwebtransport 0.1.0 → 0.1.2

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 (113) hide show
  1. package/Cargo.lock +666 -666
  2. package/Cargo.toml +31 -31
  3. package/LICENSE +202 -202
  4. package/NOTICE +41 -41
  5. package/README.md +550 -550
  6. package/crates/echo-server/Cargo.toml +20 -20
  7. package/crates/echo-server/src/main.rs +666 -666
  8. package/crates/native/Cargo.toml +23 -23
  9. package/crates/native/src/config.rs +129 -129
  10. package/crates/native/src/driver.rs +463 -463
  11. package/crates/native/src/lib.rs +821 -821
  12. package/crates/native/src/server.rs +718 -718
  13. package/crates/native/src/session.rs +1191 -1191
  14. package/crates/native/src/tls.rs +96 -96
  15. package/crates/wtcore/Cargo.toml +15 -15
  16. package/crates/wtcore/src/h3.rs +226 -226
  17. package/crates/wtcore/src/lib.rs +9 -9
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs.map +1 -1
  20. package/package.json +80 -79
  21. package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
  22. package/prebuilds/linux-arm64/rwebtransport.node +0 -0
  23. package/prebuilds/linux-x64/rwebtransport.node +0 -0
  24. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  25. package/scripts/bench.mjs +180 -180
  26. package/scripts/build.js +67 -67
  27. package/scripts/postinstall.js +67 -67
  28. package/scripts/setup-unix.sh +129 -129
  29. package/scripts/setup-windows.ps1 +229 -229
  30. package/vendor/quiche/AGENTS.md +75 -75
  31. package/vendor/quiche/COPYING +23 -23
  32. package/vendor/quiche/Cargo.lock +1212 -1212
  33. package/vendor/quiche/Cargo.toml +215 -215
  34. package/vendor/quiche/README.md +466 -466
  35. package/vendor/quiche/examples/Makefile +46 -46
  36. package/vendor/quiche/examples/README.md +20 -20
  37. package/vendor/quiche/examples/cert-big.crt +90 -90
  38. package/vendor/quiche/examples/cert.crt +18 -18
  39. package/vendor/quiche/examples/cert.key +28 -28
  40. package/vendor/quiche/examples/client.c +343 -343
  41. package/vendor/quiche/examples/client.rs +281 -281
  42. package/vendor/quiche/examples/gen-certs.sh +15 -15
  43. package/vendor/quiche/examples/http3-client.c +473 -473
  44. package/vendor/quiche/examples/http3-client.rs +349 -349
  45. package/vendor/quiche/examples/http3-server.c +614 -614
  46. package/vendor/quiche/examples/http3-server.rs +680 -680
  47. package/vendor/quiche/examples/qpack-decode.rs +87 -87
  48. package/vendor/quiche/examples/qpack-encode.rs +88 -88
  49. package/vendor/quiche/examples/rootca.crt +21 -21
  50. package/vendor/quiche/examples/server.c +529 -529
  51. package/vendor/quiche/examples/server.rs +529 -529
  52. package/vendor/quiche/include/quiche.h +1282 -1282
  53. package/vendor/quiche/src/buffers.rs +105 -105
  54. package/vendor/quiche/src/build.rs +66 -66
  55. package/vendor/quiche/src/cid.rs +1079 -1079
  56. package/vendor/quiche/src/crypto/boringssl.rs +373 -373
  57. package/vendor/quiche/src/crypto/mod.rs +671 -671
  58. package/vendor/quiche/src/dgram.rs +118 -118
  59. package/vendor/quiche/src/error.rs +263 -263
  60. package/vendor/quiche/src/ffi.rs +2290 -2290
  61. package/vendor/quiche/src/flowcontrol.rs +246 -246
  62. package/vendor/quiche/src/frame.rs +2172 -2172
  63. package/vendor/quiche/src/h3/AGENTS.md +54 -54
  64. package/vendor/quiche/src/h3/ffi.rs +442 -442
  65. package/vendor/quiche/src/h3/frame.rs +1404 -1404
  66. package/vendor/quiche/src/h3/mod.rs +8223 -8223
  67. package/vendor/quiche/src/h3/qpack/decoder.rs +288 -288
  68. package/vendor/quiche/src/h3/qpack/encoder.rs +235 -235
  69. package/vendor/quiche/src/h3/qpack/mod.rs +202 -202
  70. package/vendor/quiche/src/h3/qpack/static_table.rs +323 -323
  71. package/vendor/quiche/src/h3/stream.rs +1595 -1595
  72. package/vendor/quiche/src/lib.rs +9556 -9556
  73. package/vendor/quiche/src/minmax.rs +446 -446
  74. package/vendor/quiche/src/packet.rs +2334 -2334
  75. package/vendor/quiche/src/path.rs +1374 -1374
  76. package/vendor/quiche/src/pmtud.rs +652 -652
  77. package/vendor/quiche/src/rand.rs +64 -64
  78. package/vendor/quiche/src/range_buf.rs +186 -186
  79. package/vendor/quiche/src/ranges.rs +755 -755
  80. package/vendor/quiche/src/recovery/AGENTS.md +80 -80
  81. package/vendor/quiche/src/recovery/bandwidth.rs +565 -565
  82. package/vendor/quiche/src/recovery/bytes_in_flight.rs +179 -179
  83. package/vendor/quiche/src/recovery/congestion/cubic.rs +1038 -1038
  84. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +514 -514
  85. package/vendor/quiche/src/recovery/congestion/hystart.rs +241 -241
  86. package/vendor/quiche/src/recovery/congestion/mod.rs +361 -361
  87. package/vendor/quiche/src/recovery/congestion/prr.rs +238 -238
  88. package/vendor/quiche/src/recovery/congestion/recovery.rs +1170 -1170
  89. package/vendor/quiche/src/recovery/congestion/reno.rs +291 -291
  90. package/vendor/quiche/src/recovery/congestion/test_sender.rs +201 -201
  91. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +1947 -1947
  92. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +158 -158
  93. package/vendor/quiche/src/recovery/gcongestion/bbr.rs +37 -37
  94. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +120 -120
  95. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +318 -318
  96. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +784 -784
  97. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +729 -729
  98. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +175 -175
  99. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +190 -190
  100. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +855 -855
  101. package/vendor/quiche/src/recovery/gcongestion/mod.rs +275 -275
  102. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +294 -294
  103. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +1384 -1384
  104. package/vendor/quiche/src/recovery/mod.rs +3086 -3086
  105. package/vendor/quiche/src/recovery/rtt.rs +152 -152
  106. package/vendor/quiche/src/stream/mod.rs +2210 -2210
  107. package/vendor/quiche/src/stream/recv_buf.rs +1236 -1236
  108. package/vendor/quiche/src/stream/send_buf.rs +849 -849
  109. package/vendor/quiche/src/test_utils.rs +681 -681
  110. package/vendor/quiche/src/tests.rs +12922 -12922
  111. package/vendor/quiche/src/tls/boringssl.rs +375 -375
  112. package/vendor/quiche/src/tls/mod.rs +1245 -1245
  113. package/vendor/quiche/src/transport_params.rs +628 -628
@@ -1,23 +1,23 @@
1
- # SPDX-License-Identifier: Apache-2.0
2
- [package]
3
- name = "rwebtransport-native"
4
- version.workspace = true
5
- edition.workspace = true
6
- license.workspace = true
7
- publish = false
8
-
9
- [lib]
10
- name = "rwebtransport_native"
11
- crate-type = ["cdylib"]
12
-
13
- [dependencies]
14
- neon = { version = "1", default-features = false, features = ["napi-8"] }
15
- wtcore.workspace = true
16
- quiche.workspace = true
17
- boring.workspace = true
18
- boring-sys.workspace = true
19
- octets.workspace = true
20
- log.workspace = true
21
- mio.workspace = true
22
- getrandom.workspace = true
23
- socket2.workspace = true
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ [package]
3
+ name = "rwebtransport-native"
4
+ version.workspace = true
5
+ edition.workspace = true
6
+ license.workspace = true
7
+ publish = false
8
+
9
+ [lib]
10
+ name = "rwebtransport_native"
11
+ crate-type = ["cdylib"]
12
+
13
+ [dependencies]
14
+ neon = { version = "1", default-features = false, features = ["napi-8"] }
15
+ wtcore.workspace = true
16
+ quiche.workspace = true
17
+ boring.workspace = true
18
+ boring-sys.workspace = true
19
+ octets.workspace = true
20
+ log.workspace = true
21
+ mio.workspace = true
22
+ getrandom.workspace = true
23
+ socket2.workspace = true
@@ -1,129 +1,129 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- //! QUIC client configuration built on the vendored Cloudflare quiche.
3
-
4
- use crate::tls::{build_client_tls, CertVerification};
5
-
6
- /// HTTP/3 ALPN token.
7
- pub const H3_ALPN: &[u8] = b"h3";
8
-
9
- /// Tunable client parameters. Defaults are chosen to comfortably run a
10
- /// WebTransport session (control + QPACK streams plus application streams and
11
- /// datagrams) against a public-internet server.
12
- #[derive(Clone, Debug)]
13
- pub struct ClientConfigParams {
14
- pub verify: CertVerification,
15
- pub max_idle_timeout_ms: u64,
16
- pub max_udp_payload_size: usize,
17
- pub initial_max_data: u64,
18
- pub initial_max_stream_data: u64,
19
- pub initial_max_streams_bidi: u64,
20
- pub initial_max_streams_uni: u64,
21
- pub dgram_recv_queue: usize,
22
- pub dgram_send_queue: usize,
23
- }
24
-
25
- impl Default for ClientConfigParams {
26
- fn default() -> Self {
27
- Self {
28
- verify: CertVerification::PkiDefault,
29
- max_idle_timeout_ms: 30_000,
30
- max_udp_payload_size: 1350,
31
- initial_max_data: 10 * 1024 * 1024,
32
- initial_max_stream_data: 1024 * 1024,
33
- initial_max_streams_bidi: 256,
34
- initial_max_streams_uni: 256,
35
- // Bounded so a hostile server flooding datagrams cannot balloon
36
- // memory: quiche drops incoming datagrams once this queue is full.
37
- dgram_recv_queue: 1024,
38
- dgram_send_queue: 1024,
39
- }
40
- }
41
- }
42
-
43
- /// Build a ready-to-use quiche client [`quiche::Config`].
44
- pub fn build_config(p: &ClientConfigParams) -> Result<quiche::Config, String> {
45
- let builder = build_client_tls(&p.verify)?;
46
- let mut config = quiche::Config::with_boring_ssl_ctx_builder(quiche::PROTOCOL_VERSION, builder)
47
- .map_err(|e| format!("quiche config: {e:?}"))?;
48
-
49
- config
50
- .set_application_protos(&[H3_ALPN])
51
- .map_err(|e| format!("set_application_protos: {e:?}"))?;
52
-
53
- match p.verify {
54
- CertVerification::PkiDefault => {
55
- // Turn on BoringSSL's built-in chain + hostname verification and give
56
- // it a trust anchor set. Hostname verification is wired by quiche's
57
- // `set_host_name` (X509_VERIFY_PARAM_set1_host).
58
- config.verify_peer(true);
59
- #[cfg(unix)]
60
- {
61
- // Best-effort system roots. If neither path exists the handshake
62
- // will fail closed, which is the correct default.
63
- let _ = config.load_verify_locations_from_directory("/etc/ssl/certs");
64
- }
65
- }
66
- CertVerification::Hashes(_) | CertVerification::Insecure => {
67
- // Verification is fully handled on the SSL context (custom callback /
68
- // NONE). Do NOT call verify_peer here — it would install quiche's own
69
- // None-callback over ours.
70
- }
71
- }
72
-
73
- config.set_max_idle_timeout(p.max_idle_timeout_ms);
74
- config.set_max_recv_udp_payload_size(p.max_udp_payload_size);
75
- config.set_max_send_udp_payload_size(p.max_udp_payload_size);
76
- config.set_initial_max_data(p.initial_max_data);
77
- config.set_initial_max_stream_data_bidi_local(p.initial_max_stream_data);
78
- config.set_initial_max_stream_data_bidi_remote(p.initial_max_stream_data);
79
- config.set_initial_max_stream_data_uni(p.initial_max_stream_data);
80
- config.set_initial_max_streams_bidi(p.initial_max_streams_bidi);
81
- config.set_initial_max_streams_uni(p.initial_max_streams_uni);
82
- config.set_disable_active_migration(true);
83
- config.enable_dgram(true, p.dgram_recv_queue, p.dgram_send_queue);
84
-
85
- Ok(config)
86
- }
87
-
88
- /// Build a QUIC **server** config from PEM certificate + private-key file paths.
89
- /// Uses the same conservative transport limits as the client and the same
90
- /// bounded datagram queues.
91
- pub fn build_server_config(cert_path: &str, key_path: &str) -> Result<quiche::Config, String> {
92
- use boring::ssl::{SslContextBuilder, SslMethod, SslVersion};
93
-
94
- let mut builder =
95
- SslContextBuilder::new(SslMethod::tls()).map_err(|e| format!("SslContextBuilder: {e}"))?;
96
- builder
97
- .set_min_proto_version(Some(SslVersion::TLS1_3))
98
- .map_err(|e| format!("set_min_proto_version: {e}"))?;
99
- builder
100
- .set_max_proto_version(Some(SslVersion::TLS1_3))
101
- .map_err(|e| format!("set_max_proto_version: {e}"))?;
102
-
103
- let mut config = quiche::Config::with_boring_ssl_ctx_builder(quiche::PROTOCOL_VERSION, builder)
104
- .map_err(|e| format!("quiche config: {e:?}"))?;
105
- config
106
- .load_cert_chain_from_pem_file(cert_path)
107
- .map_err(|e| format!("failed to load certificate {cert_path}: {e:?}"))?;
108
- config
109
- .load_priv_key_from_pem_file(key_path)
110
- .map_err(|e| format!("failed to load private key {key_path}: {e:?}"))?;
111
- config
112
- .set_application_protos(&[H3_ALPN])
113
- .map_err(|e| format!("set_application_protos: {e:?}"))?;
114
-
115
- let p = ClientConfigParams::default();
116
- config.set_max_idle_timeout(p.max_idle_timeout_ms);
117
- config.set_max_recv_udp_payload_size(p.max_udp_payload_size);
118
- config.set_max_send_udp_payload_size(p.max_udp_payload_size);
119
- config.set_initial_max_data(p.initial_max_data);
120
- config.set_initial_max_stream_data_bidi_local(p.initial_max_stream_data);
121
- config.set_initial_max_stream_data_bidi_remote(p.initial_max_stream_data);
122
- config.set_initial_max_stream_data_uni(p.initial_max_stream_data);
123
- config.set_initial_max_streams_bidi(p.initial_max_streams_bidi);
124
- config.set_initial_max_streams_uni(p.initial_max_streams_uni);
125
- config.set_disable_active_migration(true);
126
- config.enable_dgram(true, p.dgram_recv_queue, p.dgram_send_queue);
127
-
128
- Ok(config)
129
- }
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ //! QUIC client configuration built on the vendored Cloudflare quiche.
3
+
4
+ use crate::tls::{build_client_tls, CertVerification};
5
+
6
+ /// HTTP/3 ALPN token.
7
+ pub const H3_ALPN: &[u8] = b"h3";
8
+
9
+ /// Tunable client parameters. Defaults are chosen to comfortably run a
10
+ /// WebTransport session (control + QPACK streams plus application streams and
11
+ /// datagrams) against a public-internet server.
12
+ #[derive(Clone, Debug)]
13
+ pub struct ClientConfigParams {
14
+ pub verify: CertVerification,
15
+ pub max_idle_timeout_ms: u64,
16
+ pub max_udp_payload_size: usize,
17
+ pub initial_max_data: u64,
18
+ pub initial_max_stream_data: u64,
19
+ pub initial_max_streams_bidi: u64,
20
+ pub initial_max_streams_uni: u64,
21
+ pub dgram_recv_queue: usize,
22
+ pub dgram_send_queue: usize,
23
+ }
24
+
25
+ impl Default for ClientConfigParams {
26
+ fn default() -> Self {
27
+ Self {
28
+ verify: CertVerification::PkiDefault,
29
+ max_idle_timeout_ms: 30_000,
30
+ max_udp_payload_size: 1350,
31
+ initial_max_data: 10 * 1024 * 1024,
32
+ initial_max_stream_data: 1024 * 1024,
33
+ initial_max_streams_bidi: 256,
34
+ initial_max_streams_uni: 256,
35
+ // Bounded so a hostile server flooding datagrams cannot balloon
36
+ // memory: quiche drops incoming datagrams once this queue is full.
37
+ dgram_recv_queue: 1024,
38
+ dgram_send_queue: 1024,
39
+ }
40
+ }
41
+ }
42
+
43
+ /// Build a ready-to-use quiche client [`quiche::Config`].
44
+ pub fn build_config(p: &ClientConfigParams) -> Result<quiche::Config, String> {
45
+ let builder = build_client_tls(&p.verify)?;
46
+ let mut config = quiche::Config::with_boring_ssl_ctx_builder(quiche::PROTOCOL_VERSION, builder)
47
+ .map_err(|e| format!("quiche config: {e:?}"))?;
48
+
49
+ config
50
+ .set_application_protos(&[H3_ALPN])
51
+ .map_err(|e| format!("set_application_protos: {e:?}"))?;
52
+
53
+ match p.verify {
54
+ CertVerification::PkiDefault => {
55
+ // Turn on BoringSSL's built-in chain + hostname verification and give
56
+ // it a trust anchor set. Hostname verification is wired by quiche's
57
+ // `set_host_name` (X509_VERIFY_PARAM_set1_host).
58
+ config.verify_peer(true);
59
+ #[cfg(unix)]
60
+ {
61
+ // Best-effort system roots. If neither path exists the handshake
62
+ // will fail closed, which is the correct default.
63
+ let _ = config.load_verify_locations_from_directory("/etc/ssl/certs");
64
+ }
65
+ }
66
+ CertVerification::Hashes(_) | CertVerification::Insecure => {
67
+ // Verification is fully handled on the SSL context (custom callback /
68
+ // NONE). Do NOT call verify_peer here — it would install quiche's own
69
+ // None-callback over ours.
70
+ }
71
+ }
72
+
73
+ config.set_max_idle_timeout(p.max_idle_timeout_ms);
74
+ config.set_max_recv_udp_payload_size(p.max_udp_payload_size);
75
+ config.set_max_send_udp_payload_size(p.max_udp_payload_size);
76
+ config.set_initial_max_data(p.initial_max_data);
77
+ config.set_initial_max_stream_data_bidi_local(p.initial_max_stream_data);
78
+ config.set_initial_max_stream_data_bidi_remote(p.initial_max_stream_data);
79
+ config.set_initial_max_stream_data_uni(p.initial_max_stream_data);
80
+ config.set_initial_max_streams_bidi(p.initial_max_streams_bidi);
81
+ config.set_initial_max_streams_uni(p.initial_max_streams_uni);
82
+ config.set_disable_active_migration(true);
83
+ config.enable_dgram(true, p.dgram_recv_queue, p.dgram_send_queue);
84
+
85
+ Ok(config)
86
+ }
87
+
88
+ /// Build a QUIC **server** config from PEM certificate + private-key file paths.
89
+ /// Uses the same conservative transport limits as the client and the same
90
+ /// bounded datagram queues.
91
+ pub fn build_server_config(cert_path: &str, key_path: &str) -> Result<quiche::Config, String> {
92
+ use boring::ssl::{SslContextBuilder, SslMethod, SslVersion};
93
+
94
+ let mut builder =
95
+ SslContextBuilder::new(SslMethod::tls()).map_err(|e| format!("SslContextBuilder: {e}"))?;
96
+ builder
97
+ .set_min_proto_version(Some(SslVersion::TLS1_3))
98
+ .map_err(|e| format!("set_min_proto_version: {e}"))?;
99
+ builder
100
+ .set_max_proto_version(Some(SslVersion::TLS1_3))
101
+ .map_err(|e| format!("set_max_proto_version: {e}"))?;
102
+
103
+ let mut config = quiche::Config::with_boring_ssl_ctx_builder(quiche::PROTOCOL_VERSION, builder)
104
+ .map_err(|e| format!("quiche config: {e:?}"))?;
105
+ config
106
+ .load_cert_chain_from_pem_file(cert_path)
107
+ .map_err(|e| format!("failed to load certificate {cert_path}: {e:?}"))?;
108
+ config
109
+ .load_priv_key_from_pem_file(key_path)
110
+ .map_err(|e| format!("failed to load private key {key_path}: {e:?}"))?;
111
+ config
112
+ .set_application_protos(&[H3_ALPN])
113
+ .map_err(|e| format!("set_application_protos: {e:?}"))?;
114
+
115
+ let p = ClientConfigParams::default();
116
+ config.set_max_idle_timeout(p.max_idle_timeout_ms);
117
+ config.set_max_recv_udp_payload_size(p.max_udp_payload_size);
118
+ config.set_max_send_udp_payload_size(p.max_udp_payload_size);
119
+ config.set_initial_max_data(p.initial_max_data);
120
+ config.set_initial_max_stream_data_bidi_local(p.initial_max_stream_data);
121
+ config.set_initial_max_stream_data_bidi_remote(p.initial_max_stream_data);
122
+ config.set_initial_max_stream_data_uni(p.initial_max_stream_data);
123
+ config.set_initial_max_streams_bidi(p.initial_max_streams_bidi);
124
+ config.set_initial_max_streams_uni(p.initial_max_streams_uni);
125
+ config.set_disable_active_migration(true);
126
+ config.enable_dgram(true, p.dgram_recv_queue, p.dgram_send_queue);
127
+
128
+ Ok(config)
129
+ }