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.
- package/Cargo.lock +666 -666
- package/Cargo.toml +31 -31
- package/LICENSE +202 -202
- package/NOTICE +41 -41
- package/README.md +550 -550
- package/crates/echo-server/Cargo.toml +20 -20
- package/crates/echo-server/src/main.rs +666 -666
- package/crates/native/Cargo.toml +23 -23
- package/crates/native/src/config.rs +129 -129
- package/crates/native/src/driver.rs +463 -463
- package/crates/native/src/lib.rs +821 -821
- package/crates/native/src/server.rs +718 -718
- package/crates/native/src/session.rs +1191 -1191
- package/crates/native/src/tls.rs +96 -96
- package/crates/wtcore/Cargo.toml +15 -15
- package/crates/wtcore/src/h3.rs +226 -226
- package/crates/wtcore/src/lib.rs +9 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +80 -79
- 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/bench.mjs +180 -180
- package/scripts/build.js +67 -67
- package/scripts/postinstall.js +67 -67
- package/scripts/setup-unix.sh +129 -129
- package/scripts/setup-windows.ps1 +229 -229
- package/vendor/quiche/AGENTS.md +75 -75
- package/vendor/quiche/COPYING +23 -23
- package/vendor/quiche/Cargo.lock +1212 -1212
- package/vendor/quiche/Cargo.toml +215 -215
- package/vendor/quiche/README.md +466 -466
- package/vendor/quiche/examples/Makefile +46 -46
- package/vendor/quiche/examples/README.md +20 -20
- package/vendor/quiche/examples/cert-big.crt +90 -90
- package/vendor/quiche/examples/cert.crt +18 -18
- package/vendor/quiche/examples/cert.key +28 -28
- package/vendor/quiche/examples/client.c +343 -343
- package/vendor/quiche/examples/client.rs +281 -281
- package/vendor/quiche/examples/gen-certs.sh +15 -15
- package/vendor/quiche/examples/http3-client.c +473 -473
- package/vendor/quiche/examples/http3-client.rs +349 -349
- package/vendor/quiche/examples/http3-server.c +614 -614
- package/vendor/quiche/examples/http3-server.rs +680 -680
- package/vendor/quiche/examples/qpack-decode.rs +87 -87
- package/vendor/quiche/examples/qpack-encode.rs +88 -88
- package/vendor/quiche/examples/rootca.crt +21 -21
- package/vendor/quiche/examples/server.c +529 -529
- package/vendor/quiche/examples/server.rs +529 -529
- package/vendor/quiche/include/quiche.h +1282 -1282
- package/vendor/quiche/src/buffers.rs +105 -105
- package/vendor/quiche/src/build.rs +66 -66
- package/vendor/quiche/src/cid.rs +1079 -1079
- package/vendor/quiche/src/crypto/boringssl.rs +373 -373
- package/vendor/quiche/src/crypto/mod.rs +671 -671
- package/vendor/quiche/src/dgram.rs +118 -118
- package/vendor/quiche/src/error.rs +263 -263
- package/vendor/quiche/src/ffi.rs +2290 -2290
- package/vendor/quiche/src/flowcontrol.rs +246 -246
- package/vendor/quiche/src/frame.rs +2172 -2172
- package/vendor/quiche/src/h3/AGENTS.md +54 -54
- package/vendor/quiche/src/h3/ffi.rs +442 -442
- package/vendor/quiche/src/h3/frame.rs +1404 -1404
- package/vendor/quiche/src/h3/mod.rs +8223 -8223
- package/vendor/quiche/src/h3/qpack/decoder.rs +288 -288
- package/vendor/quiche/src/h3/qpack/encoder.rs +235 -235
- package/vendor/quiche/src/h3/qpack/mod.rs +202 -202
- package/vendor/quiche/src/h3/qpack/static_table.rs +323 -323
- package/vendor/quiche/src/h3/stream.rs +1595 -1595
- package/vendor/quiche/src/lib.rs +9556 -9556
- package/vendor/quiche/src/minmax.rs +446 -446
- package/vendor/quiche/src/packet.rs +2334 -2334
- package/vendor/quiche/src/path.rs +1374 -1374
- package/vendor/quiche/src/pmtud.rs +652 -652
- package/vendor/quiche/src/rand.rs +64 -64
- package/vendor/quiche/src/range_buf.rs +186 -186
- package/vendor/quiche/src/ranges.rs +755 -755
- package/vendor/quiche/src/recovery/AGENTS.md +80 -80
- package/vendor/quiche/src/recovery/bandwidth.rs +565 -565
- package/vendor/quiche/src/recovery/bytes_in_flight.rs +179 -179
- package/vendor/quiche/src/recovery/congestion/cubic.rs +1038 -1038
- package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +514 -514
- package/vendor/quiche/src/recovery/congestion/hystart.rs +241 -241
- package/vendor/quiche/src/recovery/congestion/mod.rs +361 -361
- package/vendor/quiche/src/recovery/congestion/prr.rs +238 -238
- package/vendor/quiche/src/recovery/congestion/recovery.rs +1170 -1170
- package/vendor/quiche/src/recovery/congestion/reno.rs +291 -291
- package/vendor/quiche/src/recovery/congestion/test_sender.rs +201 -201
- package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +1947 -1947
- package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +158 -158
- package/vendor/quiche/src/recovery/gcongestion/bbr.rs +37 -37
- package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +120 -120
- package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +318 -318
- package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +784 -784
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +729 -729
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +175 -175
- package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +190 -190
- package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +855 -855
- package/vendor/quiche/src/recovery/gcongestion/mod.rs +275 -275
- package/vendor/quiche/src/recovery/gcongestion/pacer.rs +294 -294
- package/vendor/quiche/src/recovery/gcongestion/recovery.rs +1384 -1384
- package/vendor/quiche/src/recovery/mod.rs +3086 -3086
- package/vendor/quiche/src/recovery/rtt.rs +152 -152
- package/vendor/quiche/src/stream/mod.rs +2210 -2210
- package/vendor/quiche/src/stream/recv_buf.rs +1236 -1236
- package/vendor/quiche/src/stream/send_buf.rs +849 -849
- package/vendor/quiche/src/test_utils.rs +681 -681
- package/vendor/quiche/src/tests.rs +12922 -12922
- package/vendor/quiche/src/tls/boringssl.rs +375 -375
- package/vendor/quiche/src/tls/mod.rs +1245 -1245
- package/vendor/quiche/src/transport_params.rs +628 -628
|
@@ -1,442 +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
|
-
}
|
|
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
|
+
}
|