rwebtransport 0.1.0

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 (122) hide show
  1. package/Cargo.lock +666 -0
  2. package/Cargo.toml +31 -0
  3. package/LICENSE +202 -0
  4. package/NOTICE +41 -0
  5. package/README.md +550 -0
  6. package/crates/echo-server/Cargo.toml +20 -0
  7. package/crates/echo-server/src/main.rs +666 -0
  8. package/crates/native/Cargo.toml +23 -0
  9. package/crates/native/src/config.rs +129 -0
  10. package/crates/native/src/driver.rs +463 -0
  11. package/crates/native/src/lib.rs +821 -0
  12. package/crates/native/src/server.rs +718 -0
  13. package/crates/native/src/session.rs +1191 -0
  14. package/crates/native/src/tls.rs +96 -0
  15. package/crates/wtcore/Cargo.toml +15 -0
  16. package/crates/wtcore/src/h3.rs +226 -0
  17. package/crates/wtcore/src/lib.rs +9 -0
  18. package/dist/datagrams.d.ts +16 -0
  19. package/dist/errors.d.ts +10 -0
  20. package/dist/index.d.ts +7 -0
  21. package/dist/index.js +1512 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/index.mjs +1473 -0
  24. package/dist/index.mjs.map +1 -0
  25. package/dist/loader.d.ts +2 -0
  26. package/dist/native.d.ts +226 -0
  27. package/dist/server.d.ts +44 -0
  28. package/dist/streams.d.ts +14 -0
  29. package/dist/types.d.ts +24 -0
  30. package/dist/webtransport.d.ts +20 -0
  31. package/package.json +79 -0
  32. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  33. package/scripts/bench.mjs +180 -0
  34. package/scripts/build.js +67 -0
  35. package/scripts/postinstall.js +67 -0
  36. package/scripts/setup-unix.sh +129 -0
  37. package/scripts/setup-windows.ps1 +229 -0
  38. package/vendor/quiche/AGENTS.md +75 -0
  39. package/vendor/quiche/COPYING +23 -0
  40. package/vendor/quiche/Cargo.lock +1212 -0
  41. package/vendor/quiche/Cargo.toml +215 -0
  42. package/vendor/quiche/README.md +466 -0
  43. package/vendor/quiche/examples/Makefile +46 -0
  44. package/vendor/quiche/examples/README.md +20 -0
  45. package/vendor/quiche/examples/cert-big.crt +90 -0
  46. package/vendor/quiche/examples/cert.crt +18 -0
  47. package/vendor/quiche/examples/cert.key +28 -0
  48. package/vendor/quiche/examples/client.c +343 -0
  49. package/vendor/quiche/examples/client.rs +281 -0
  50. package/vendor/quiche/examples/gen-certs.sh +15 -0
  51. package/vendor/quiche/examples/http3-client.c +473 -0
  52. package/vendor/quiche/examples/http3-client.rs +349 -0
  53. package/vendor/quiche/examples/http3-server.c +614 -0
  54. package/vendor/quiche/examples/http3-server.rs +680 -0
  55. package/vendor/quiche/examples/qpack-decode.rs +87 -0
  56. package/vendor/quiche/examples/qpack-encode.rs +88 -0
  57. package/vendor/quiche/examples/rootca.crt +21 -0
  58. package/vendor/quiche/examples/server.c +529 -0
  59. package/vendor/quiche/examples/server.rs +529 -0
  60. package/vendor/quiche/include/quiche.h +1282 -0
  61. package/vendor/quiche/quiche.svg +1 -0
  62. package/vendor/quiche/src/buffers.rs +105 -0
  63. package/vendor/quiche/src/build.rs +66 -0
  64. package/vendor/quiche/src/cid.rs +1079 -0
  65. package/vendor/quiche/src/crypto/boringssl.rs +373 -0
  66. package/vendor/quiche/src/crypto/mod.rs +671 -0
  67. package/vendor/quiche/src/dgram.rs +118 -0
  68. package/vendor/quiche/src/error.rs +263 -0
  69. package/vendor/quiche/src/ffi.rs +2290 -0
  70. package/vendor/quiche/src/flowcontrol.rs +246 -0
  71. package/vendor/quiche/src/frame.rs +2172 -0
  72. package/vendor/quiche/src/h3/AGENTS.md +54 -0
  73. package/vendor/quiche/src/h3/ffi.rs +442 -0
  74. package/vendor/quiche/src/h3/frame.rs +1404 -0
  75. package/vendor/quiche/src/h3/mod.rs +8223 -0
  76. package/vendor/quiche/src/h3/qpack/decoder.rs +288 -0
  77. package/vendor/quiche/src/h3/qpack/encoder.rs +235 -0
  78. package/vendor/quiche/src/h3/qpack/mod.rs +202 -0
  79. package/vendor/quiche/src/h3/qpack/static_table.rs +323 -0
  80. package/vendor/quiche/src/h3/stream.rs +1595 -0
  81. package/vendor/quiche/src/lib.rs +9556 -0
  82. package/vendor/quiche/src/minmax.rs +446 -0
  83. package/vendor/quiche/src/packet.rs +2334 -0
  84. package/vendor/quiche/src/path.rs +1374 -0
  85. package/vendor/quiche/src/pmtud.rs +652 -0
  86. package/vendor/quiche/src/rand.rs +64 -0
  87. package/vendor/quiche/src/range_buf.rs +186 -0
  88. package/vendor/quiche/src/ranges.rs +755 -0
  89. package/vendor/quiche/src/recovery/AGENTS.md +80 -0
  90. package/vendor/quiche/src/recovery/bandwidth.rs +565 -0
  91. package/vendor/quiche/src/recovery/bytes_in_flight.rs +179 -0
  92. package/vendor/quiche/src/recovery/congestion/cubic.rs +1038 -0
  93. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +514 -0
  94. package/vendor/quiche/src/recovery/congestion/hystart.rs +241 -0
  95. package/vendor/quiche/src/recovery/congestion/mod.rs +361 -0
  96. package/vendor/quiche/src/recovery/congestion/prr.rs +238 -0
  97. package/vendor/quiche/src/recovery/congestion/recovery.rs +1170 -0
  98. package/vendor/quiche/src/recovery/congestion/reno.rs +291 -0
  99. package/vendor/quiche/src/recovery/congestion/test_sender.rs +201 -0
  100. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +1947 -0
  101. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +158 -0
  102. package/vendor/quiche/src/recovery/gcongestion/bbr.rs +37 -0
  103. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +120 -0
  104. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +318 -0
  105. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +784 -0
  106. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +729 -0
  107. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +175 -0
  108. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +190 -0
  109. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +855 -0
  110. package/vendor/quiche/src/recovery/gcongestion/mod.rs +275 -0
  111. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +294 -0
  112. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +1384 -0
  113. package/vendor/quiche/src/recovery/mod.rs +3086 -0
  114. package/vendor/quiche/src/recovery/rtt.rs +152 -0
  115. package/vendor/quiche/src/stream/mod.rs +2210 -0
  116. package/vendor/quiche/src/stream/recv_buf.rs +1236 -0
  117. package/vendor/quiche/src/stream/send_buf.rs +849 -0
  118. package/vendor/quiche/src/test_utils.rs +681 -0
  119. package/vendor/quiche/src/tests.rs +12922 -0
  120. package/vendor/quiche/src/tls/boringssl.rs +375 -0
  121. package/vendor/quiche/src/tls/mod.rs +1245 -0
  122. package/vendor/quiche/src/transport_params.rs +628 -0
@@ -0,0 +1,54 @@
1
+ # quiche/src/h3/ — HTTP/3 Module
2
+
3
+ ## OVERVIEW
4
+
5
+ HTTP/3 wire protocol over QUIC. `Connection` manages H3 state (streams, QPACK, SETTINGS, GOAWAY) on top of `quiche::Connection<F>`. Event-driven: caller loops `poll()` → `Event`. Own `Error`/`Result` types, separate from `quiche::Error`.
6
+
7
+ ## STRUCTURE
8
+
9
+ ```
10
+ mod.rs (7549 lines) H3 Connection, Config, Error, Event, Header, NameValue, Priority
11
+ stream.rs (1565) H3 stream state machine (Type, State enums; frame parsing FSM)
12
+ frame.rs (1337) H3 frame encode/decode (Frame enum, settings constants)
13
+ ffi.rs C FFI for H3 — behind `ffi` feature
14
+ qpack/
15
+ mod.rs Re-exports
16
+ encoder.rs QPACK encoder
17
+ decoder.rs QPACK decoder
18
+ static_table.rs Static header table (RFC 9204)
19
+ ```
20
+
21
+ ## WHERE TO LOOK
22
+
23
+ | Task | Location |
24
+ |------|----------|
25
+ | Send/recv requests+responses | `mod.rs` — `send_request()`, `send_response()`, `poll()` |
26
+ | Body data | `mod.rs` — `send_body()`, `recv_body()` |
27
+ | Priority handling | `mod.rs` — `Priority` struct, `send_priority_update_for_request()` |
28
+ | H3 stream lifecycle | `stream.rs` — `Stream` struct, `State` FSM |
29
+ | Frame wire format | `frame.rs` — `Frame` enum, `encode()`/`decode()` |
30
+ | QPACK header compression | `qpack/encoder.rs`, `qpack/decoder.rs` |
31
+ | H3 C API | `ffi.rs` |
32
+
33
+ ## ANTI-PATTERNS
34
+
35
+ - **h3::Error != quiche::Error.** 19 variants; `TransportError(quiche::Error)` wraps transport errors. Don't confuse.
36
+ - **`Error::Done` is success** in poll/read loops. Not a failure — signals "no more work".
37
+ - **`to_wire()` maps `BufferTooShort` → `0x999`** — non-standard wire code. Don't propagate this pattern.
38
+ - **`to_c()` skips -12** — was previously `TransportError`. Gap is intentional for ABI stability.
39
+ - **`to_c()` for `TransportError`:** offsets by `-1000` from underlying `quic_error.to_c()`.
40
+ - **`send_request()` sends empty `b""` to create QUIC stream** before writing headers. Required because QUIC stream doesn't exist until first write.
41
+ - **stream.rs `Stream` ≠ quiche::stream::Stream.** H3 stream is a frame-parsing state machine layered on top.
42
+
43
+ ## NOTES
44
+
45
+ - Methods are generic over `F: BufFactory` (zero-copy) and `T: NameValue` (header access).
46
+ - `NameValue` trait: `name() -> &[u8]`, `value() -> &[u8]`. Blanket impl for `(N, V)` tuples.
47
+ - `Header` is `(Vec<u8>, Vec<u8>)` newtype implementing `NameValue`.
48
+ - `Event` variants: `Headers`, `Data`, `Finished`, `Reset(u64)`, `PriorityUpdate`, `GoAway`.
49
+ - Priority: RFC 9218 Extensible Priorities. `sfv` feature enables `TryFrom` parsing.
50
+ - `PRIORITY_URGENCY_OFFSET = 124` maps external urgency 0-7 to internal quiche priority.
51
+ - `APPLICATION_PROTOCOL = &[b"h3"]` — ALPN constant.
52
+ - `From<quiche::Error>` converts `Done→Done`, everything else → `TransportError(e)`.
53
+ - `From<octets::BufferTooShortError>` → `Error::BufferTooShort`.
54
+ - All `#[cfg(feature = "qlog")]` instrumentation inline in mod.rs — heavy conditional compilation.
@@ -0,0 +1,442 @@
1
+ // Copyright (C) 2019, Cloudflare, Inc.
2
+ // All rights reserved.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without
5
+ // modification, are permitted provided that the following conditions are
6
+ // met:
7
+ //
8
+ // * Redistributions of source code must retain the above copyright notice,
9
+ // this list of conditions and the following disclaimer.
10
+ //
11
+ // * Redistributions in binary form must reproduce the above copyright
12
+ // notice, this list of conditions and the following disclaimer in the
13
+ // documentation and/or other materials provided with the distribution.
14
+ //
15
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
+ // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
+ // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
+ // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19
+ // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
+ // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
+ // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
+ // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
+ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ #[cfg(feature = "sfv")]
28
+ use std::convert::TryFrom;
29
+
30
+ use std::ptr;
31
+ use std::slice;
32
+
33
+ use libc::c_int;
34
+ use libc::c_void;
35
+ use libc::size_t;
36
+ use libc::ssize_t;
37
+
38
+ use crate::*;
39
+
40
+ use crate::h3::NameValue;
41
+ use crate::h3::Priority;
42
+
43
+ #[no_mangle]
44
+ pub extern "C" fn quiche_h3_config_new() -> *mut h3::Config {
45
+ match h3::Config::new() {
46
+ Ok(c) => Box::into_raw(Box::new(c)),
47
+
48
+ Err(_) => ptr::null_mut(),
49
+ }
50
+ }
51
+
52
+ #[no_mangle]
53
+ pub extern "C" fn quiche_h3_config_set_max_field_section_size(
54
+ config: &mut h3::Config, v: u64,
55
+ ) {
56
+ config.set_max_field_section_size(v);
57
+ }
58
+
59
+ #[no_mangle]
60
+ pub extern "C" fn quiche_h3_config_set_qpack_max_table_capacity(
61
+ config: &mut h3::Config, v: u64,
62
+ ) {
63
+ config.set_qpack_max_table_capacity(v);
64
+ }
65
+
66
+ #[no_mangle]
67
+ pub extern "C" fn quiche_h3_config_set_qpack_blocked_streams(
68
+ config: &mut h3::Config, v: u64,
69
+ ) {
70
+ config.set_qpack_blocked_streams(v);
71
+ }
72
+
73
+ #[no_mangle]
74
+ pub extern "C" fn quiche_h3_config_enable_extended_connect(
75
+ config: &mut h3::Config, enabled: bool,
76
+ ) {
77
+ config.enable_extended_connect(enabled);
78
+ }
79
+
80
+ #[no_mangle]
81
+ pub extern "C" fn quiche_h3_config_free(config: *mut h3::Config) {
82
+ if !config.is_null() {
83
+ drop(unsafe { Box::from_raw(config) });
84
+ }
85
+ }
86
+
87
+ #[no_mangle]
88
+ pub extern "C" fn quiche_h3_conn_new_with_transport(
89
+ quic_conn: &mut Connection, config: &mut h3::Config,
90
+ ) -> *mut h3::Connection {
91
+ match h3::Connection::with_transport(quic_conn, config) {
92
+ Ok(c) => Box::into_raw(Box::new(c)),
93
+
94
+ Err(_) => ptr::null_mut(),
95
+ }
96
+ }
97
+
98
+ #[no_mangle]
99
+ pub extern "C" fn quiche_h3_for_each_setting(
100
+ conn: &h3::Connection,
101
+ cb: extern "C" fn(identifier: u64, value: u64, argp: *mut c_void) -> c_int,
102
+ argp: *mut c_void,
103
+ ) -> c_int {
104
+ match conn.peer_settings_raw() {
105
+ Some(raw) => {
106
+ for setting in raw {
107
+ let rc = cb(setting.0, setting.1, argp);
108
+
109
+ if rc != 0 {
110
+ return rc;
111
+ }
112
+ }
113
+
114
+ 0
115
+ },
116
+
117
+ None => -1,
118
+ }
119
+ }
120
+
121
+ #[no_mangle]
122
+ pub extern "C" fn quiche_h3_conn_poll(
123
+ conn: &mut h3::Connection, quic_conn: &mut Connection,
124
+ ev: *mut *const h3::Event,
125
+ ) -> i64 {
126
+ match conn.poll(quic_conn) {
127
+ Ok((id, v)) => {
128
+ unsafe {
129
+ *ev = Box::into_raw(Box::new(v));
130
+ }
131
+
132
+ id as i64
133
+ },
134
+
135
+ Err(e) => e.to_c() as i64,
136
+ }
137
+ }
138
+
139
+ #[no_mangle]
140
+ pub extern "C" fn quiche_h3_event_type(ev: &h3::Event) -> u32 {
141
+ match ev {
142
+ h3::Event::Headers { .. } => 0,
143
+
144
+ h3::Event::Data => 1,
145
+
146
+ h3::Event::Finished => 2,
147
+
148
+ h3::Event::GoAway => 3,
149
+
150
+ h3::Event::Reset { .. } => 4,
151
+
152
+ h3::Event::PriorityUpdate => 5,
153
+ }
154
+ }
155
+
156
+ #[no_mangle]
157
+ pub extern "C" fn quiche_h3_event_for_each_header(
158
+ ev: &h3::Event,
159
+ cb: extern "C" fn(
160
+ name: *const u8,
161
+ name_len: size_t,
162
+
163
+ value: *const u8,
164
+ value_len: size_t,
165
+
166
+ argp: *mut c_void,
167
+ ) -> c_int,
168
+ argp: *mut c_void,
169
+ ) -> c_int {
170
+ match ev {
171
+ h3::Event::Headers { list, .. } =>
172
+ for h in list {
173
+ let rc = cb(
174
+ h.name().as_ptr(),
175
+ h.name().len(),
176
+ h.value().as_ptr(),
177
+ h.value().len(),
178
+ argp,
179
+ );
180
+
181
+ if rc != 0 {
182
+ return rc;
183
+ }
184
+ },
185
+
186
+ _ => unreachable!(),
187
+ }
188
+
189
+ 0
190
+ }
191
+
192
+ #[no_mangle]
193
+ pub extern "C" fn quiche_h3_event_headers_has_more_frames(
194
+ ev: &h3::Event,
195
+ ) -> bool {
196
+ match ev {
197
+ h3::Event::Headers { more_frames, .. } => *more_frames,
198
+
199
+ _ => unreachable!(),
200
+ }
201
+ }
202
+
203
+ #[no_mangle]
204
+ pub extern "C" fn quiche_h3_extended_connect_enabled_by_peer(
205
+ conn: &h3::Connection,
206
+ ) -> bool {
207
+ conn.extended_connect_enabled_by_peer()
208
+ }
209
+
210
+ #[no_mangle]
211
+ pub extern "C" fn quiche_h3_event_free(ev: *mut h3::Event) {
212
+ if !ev.is_null() {
213
+ drop(unsafe { Box::from_raw(ev) });
214
+ }
215
+ }
216
+
217
+ #[repr(C)]
218
+ pub struct Header {
219
+ name: *mut u8,
220
+ name_len: usize,
221
+
222
+ value: *mut u8,
223
+ value_len: usize,
224
+ }
225
+
226
+ #[no_mangle]
227
+ pub extern "C" fn quiche_h3_send_request(
228
+ conn: &mut h3::Connection, quic_conn: &mut Connection,
229
+ headers: *const Header, headers_len: size_t, fin: bool,
230
+ ) -> i64 {
231
+ let req_headers = headers_from_ptr(headers, headers_len);
232
+
233
+ match conn.send_request(quic_conn, &req_headers, fin) {
234
+ Ok(v) => v as i64,
235
+
236
+ Err(e) => e.to_c() as i64,
237
+ }
238
+ }
239
+
240
+ #[no_mangle]
241
+ pub extern "C" fn quiche_h3_send_response(
242
+ conn: &mut h3::Connection, quic_conn: &mut Connection, stream_id: u64,
243
+ headers: *const Header, headers_len: size_t, fin: bool,
244
+ ) -> c_int {
245
+ let resp_headers = headers_from_ptr(headers, headers_len);
246
+
247
+ match conn.send_response(quic_conn, stream_id, &resp_headers, fin) {
248
+ Ok(_) => 0,
249
+
250
+ Err(e) => e.to_c() as c_int,
251
+ }
252
+ }
253
+
254
+ #[no_mangle]
255
+ pub extern "C" fn quiche_h3_send_response_with_priority(
256
+ conn: &mut h3::Connection, quic_conn: &mut Connection, stream_id: u64,
257
+ headers: *const Header, headers_len: size_t, priority: &Priority, fin: bool,
258
+ ) -> c_int {
259
+ let resp_headers = headers_from_ptr(headers, headers_len);
260
+
261
+ match conn.send_response_with_priority(
262
+ quic_conn,
263
+ stream_id,
264
+ &resp_headers,
265
+ priority,
266
+ fin,
267
+ ) {
268
+ Ok(_) => 0,
269
+
270
+ Err(e) => e.to_c() as c_int,
271
+ }
272
+ }
273
+
274
+ #[no_mangle]
275
+ pub extern "C" fn quiche_h3_send_additional_headers(
276
+ conn: &mut h3::Connection, quic_conn: &mut Connection, stream_id: u64,
277
+ headers: *const Header, headers_len: size_t, is_trailer_section: bool,
278
+ fin: bool,
279
+ ) -> c_int {
280
+ let headers = headers_from_ptr(headers, headers_len);
281
+
282
+ match conn.send_additional_headers(
283
+ quic_conn,
284
+ stream_id,
285
+ &headers,
286
+ is_trailer_section,
287
+ fin,
288
+ ) {
289
+ Ok(_) => 0,
290
+
291
+ Err(e) => e.to_c() as c_int,
292
+ }
293
+ }
294
+
295
+ #[no_mangle]
296
+ pub extern "C" fn quiche_h3_send_body(
297
+ conn: &mut h3::Connection, quic_conn: &mut Connection, stream_id: u64,
298
+ body: *const u8, body_len: size_t, fin: bool,
299
+ ) -> ssize_t {
300
+ if body_len > <ssize_t>::MAX as usize {
301
+ panic!("The provided buffer is too large");
302
+ }
303
+
304
+ let body = unsafe { slice::from_raw_parts(body, body_len) };
305
+
306
+ match conn.send_body(quic_conn, stream_id, body, fin) {
307
+ Ok(v) => v as ssize_t,
308
+
309
+ Err(e) => e.to_c(),
310
+ }
311
+ }
312
+
313
+ #[no_mangle]
314
+ pub extern "C" fn quiche_h3_recv_body(
315
+ conn: &mut h3::Connection, quic_conn: &mut Connection, stream_id: u64,
316
+ out: *mut u8, out_len: size_t,
317
+ ) -> ssize_t {
318
+ if out_len > <ssize_t>::MAX as usize {
319
+ panic!("The provided buffer is too large");
320
+ }
321
+
322
+ let out = unsafe { slice::from_raw_parts_mut(out, out_len) };
323
+
324
+ match conn.recv_body(quic_conn, stream_id, out) {
325
+ Ok(v) => v as ssize_t,
326
+
327
+ Err(e) => e.to_c(),
328
+ }
329
+ }
330
+
331
+ #[no_mangle]
332
+ pub extern "C" fn quiche_h3_send_goaway(
333
+ conn: &mut h3::Connection, quic_conn: &mut Connection, id: u64,
334
+ ) -> c_int {
335
+ match conn.send_goaway(quic_conn, id) {
336
+ Ok(()) => 0,
337
+
338
+ Err(e) => e.to_c() as c_int,
339
+ }
340
+ }
341
+
342
+ #[no_mangle]
343
+ #[cfg(feature = "sfv")]
344
+ pub extern "C" fn quiche_h3_parse_extensible_priority(
345
+ priority: *const u8, priority_len: size_t, parsed: &mut Priority,
346
+ ) -> c_int {
347
+ let priority = unsafe { slice::from_raw_parts(priority, priority_len) };
348
+
349
+ match Priority::try_from(priority) {
350
+ Ok(v) => {
351
+ parsed.urgency = v.urgency;
352
+ parsed.incremental = v.incremental;
353
+ 0
354
+ },
355
+
356
+ Err(e) => e.to_c() as c_int,
357
+ }
358
+ }
359
+
360
+ #[no_mangle]
361
+ pub extern "C" fn quiche_h3_send_priority_update_for_request(
362
+ conn: &mut h3::Connection, quic_conn: &mut Connection, stream_id: u64,
363
+ priority: &Priority,
364
+ ) -> c_int {
365
+ match conn.send_priority_update_for_request(quic_conn, stream_id, priority) {
366
+ Ok(()) => 0,
367
+
368
+ Err(e) => e.to_c() as c_int,
369
+ }
370
+ }
371
+
372
+ #[no_mangle]
373
+ pub extern "C" fn quiche_h3_take_last_priority_update(
374
+ conn: &mut h3::Connection, prioritized_element_id: u64,
375
+ cb: extern "C" fn(
376
+ priority_field_value: *const u8,
377
+ priority_field_value_len: size_t,
378
+ argp: *mut c_void,
379
+ ) -> c_int,
380
+ argp: *mut c_void,
381
+ ) -> c_int {
382
+ match conn.take_last_priority_update(prioritized_element_id) {
383
+ Ok(priority) => {
384
+ let rc = cb(priority.as_ptr(), priority.len(), argp);
385
+
386
+ if rc != 0 {
387
+ return rc;
388
+ }
389
+
390
+ 0
391
+ },
392
+
393
+ Err(e) => e.to_c() as c_int,
394
+ }
395
+ }
396
+
397
+ #[no_mangle]
398
+ pub extern "C" fn quiche_h3_dgram_enabled_by_peer(
399
+ conn: &h3::Connection, quic_conn: &Connection,
400
+ ) -> bool {
401
+ conn.dgram_enabled_by_peer(quic_conn)
402
+ }
403
+
404
+ #[no_mangle]
405
+ pub extern "C" fn quiche_h3_conn_free(conn: *mut h3::Connection) {
406
+ if !conn.is_null() {
407
+ drop(unsafe { Box::from_raw(conn) });
408
+ }
409
+ }
410
+
411
+ fn headers_from_ptr<'a>(
412
+ ptr: *const Header, len: size_t,
413
+ ) -> Vec<h3::HeaderRef<'a>> {
414
+ let headers = unsafe { slice::from_raw_parts(ptr, len) };
415
+
416
+ let mut out = Vec::new();
417
+
418
+ for h in headers {
419
+ out.push({
420
+ let name = unsafe { slice::from_raw_parts(h.name, h.name_len) };
421
+ let value = unsafe { slice::from_raw_parts(h.value, h.value_len) };
422
+
423
+ h3::HeaderRef::new(name, value)
424
+ });
425
+ }
426
+
427
+ out
428
+ }
429
+
430
+ #[repr(C)]
431
+ pub struct Stats {
432
+ qpack_encoder_stream_recv_bytes: u64,
433
+ qpack_decoder_stream_recv_bytes: u64,
434
+ }
435
+
436
+ #[no_mangle]
437
+ pub extern "C" fn quiche_h3_conn_stats(conn: &h3::Connection, out: &mut Stats) {
438
+ let stats = conn.stats();
439
+
440
+ out.qpack_encoder_stream_recv_bytes = stats.qpack_encoder_stream_recv_bytes;
441
+ out.qpack_decoder_stream_recv_bytes = stats.qpack_decoder_stream_recv_bytes;
442
+ }