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
|
@@ -14,6 +14,7 @@ use std::net::SocketAddr;
|
|
|
14
14
|
use std::sync::atomic::Ordering;
|
|
15
15
|
use std::sync::mpsc::Receiver;
|
|
16
16
|
use std::sync::Arc;
|
|
17
|
+
use std::time::{Duration, Instant};
|
|
17
18
|
|
|
18
19
|
use mio::net::UdpSocket;
|
|
19
20
|
use mio::{Events, Interest, Poll};
|
|
@@ -21,26 +22,23 @@ use mio::{Events, Interest, Poll};
|
|
|
21
22
|
use wtcore::h3;
|
|
22
23
|
|
|
23
24
|
use crate::config::build_server_config;
|
|
24
|
-
use crate::driver::{
|
|
25
|
+
use crate::driver::{
|
|
26
|
+
is_udp_port_unreachable, DriverShared, MAX_INFLIGHT_BATCHES, MAX_RECV_PER_WAKE,
|
|
27
|
+
MAX_RECV_UDP_PAYLOAD, SOCKET_TOKEN,
|
|
28
|
+
};
|
|
25
29
|
use crate::parser_memory::ParserMemory;
|
|
26
|
-
use crate::session::{Ev, WtSession};
|
|
30
|
+
use crate::session::{Ev, ReceiveBudget, WtSession};
|
|
27
31
|
|
|
28
32
|
const LOCAL_CONN_ID_LEN: usize = 16;
|
|
29
|
-
const MAX_INFLIGHT_BATCHES: i64 = 128;
|
|
30
33
|
|
|
31
|
-
///
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
+
/// Cap live transport state, including incomplete handshakes and draining connections.
|
|
35
|
+
const MAX_CONNECTIONS: usize = 256;
|
|
36
|
+
const SESSION_SETUP_TIMEOUT: Duration = Duration::from_secs(10);
|
|
34
37
|
|
|
35
38
|
/// Aggregate allocation capacity of HTTP/3, classification and capsule parser
|
|
36
39
|
/// buffers across all connections, including handshakes and draining sessions.
|
|
37
40
|
const MAX_PARSER_MEMORY: usize = 64 * 1024 * 1024;
|
|
38
41
|
|
|
39
|
-
/// Maximum UDP packets read per event-loop wake before yielding to the rest of
|
|
40
|
-
/// the loop (timeouts, commands, reaping). Bounds per-wake work so a sustained
|
|
41
|
-
/// inbound flood cannot starve `Shutdown` handling or idle-connection reaping.
|
|
42
|
-
const MAX_RECV_PER_WAKE: usize = 1024;
|
|
43
|
-
|
|
44
42
|
/// Everything the server thread needs to start listening.
|
|
45
43
|
pub struct ServerSetup {
|
|
46
44
|
pub host: String,
|
|
@@ -165,7 +163,8 @@ struct ServerConn {
|
|
|
165
163
|
conn: quiche::Connection,
|
|
166
164
|
session: WtSession,
|
|
167
165
|
session_id: u64,
|
|
168
|
-
|
|
166
|
+
setup_deadline: Option<Instant>,
|
|
167
|
+
max_datagram_size: usize,
|
|
169
168
|
}
|
|
170
169
|
|
|
171
170
|
/// Server thread entry point, wrapped in a panic boundary.
|
|
@@ -202,10 +201,17 @@ const TOKEN_TAG_LEN: usize = 16;
|
|
|
202
201
|
/// token is bound to. A spoofed source can never receive the Retry, and the tag
|
|
203
202
|
/// is keyed by a per-process secret it does not know, so it cannot forge one.
|
|
204
203
|
fn addr_identity(src: &SocketAddr) -> Vec<u8> {
|
|
205
|
-
let mut id =
|
|
206
|
-
|
|
207
|
-
std::net::IpAddr::
|
|
208
|
-
|
|
204
|
+
let mut id = Vec::with_capacity(19);
|
|
205
|
+
match src.ip() {
|
|
206
|
+
std::net::IpAddr::V4(a) => {
|
|
207
|
+
id.push(4);
|
|
208
|
+
id.extend_from_slice(&a.octets());
|
|
209
|
+
}
|
|
210
|
+
std::net::IpAddr::V6(a) => {
|
|
211
|
+
id.push(6);
|
|
212
|
+
id.extend_from_slice(&a.octets());
|
|
213
|
+
}
|
|
214
|
+
}
|
|
209
215
|
id.extend_from_slice(&src.port().to_be_bytes());
|
|
210
216
|
id
|
|
211
217
|
}
|
|
@@ -236,85 +242,55 @@ fn hmac_sha256(secret: &[u8], data: &[u8]) -> [u8; 32] {
|
|
|
236
242
|
boring::sha::sha256(&outer)
|
|
237
243
|
}
|
|
238
244
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if a.len() != b.len() {
|
|
243
|
-
return false;
|
|
244
|
-
}
|
|
245
|
-
let mut diff = 0u8;
|
|
246
|
-
for (x, y) in a.iter().zip(b.iter()) {
|
|
247
|
-
diff |= x ^ y;
|
|
248
|
-
}
|
|
249
|
-
diff == 0
|
|
245
|
+
struct RetryTokens {
|
|
246
|
+
secret: [u8; 32],
|
|
247
|
+
started: Instant,
|
|
250
248
|
}
|
|
251
249
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
/// `b"rwt1" || orig_dcid || HMAC(secret, addr || orig_dcid)[..16]`. Because the
|
|
255
|
-
/// tag is keyed by a secret known only to this process, a spoofed source cannot
|
|
256
|
-
/// forge a token it never received, which is what makes the Retry actually
|
|
257
|
-
/// prevent source-address spoofing (reflection) and state exhaustion rather than
|
|
258
|
-
/// just being a formality.
|
|
259
|
-
fn mint_token(secret: &[u8], orig_dcid: &[u8], src: &SocketAddr) -> Vec<u8> {
|
|
260
|
-
let mut mac_input = addr_identity(src);
|
|
261
|
-
mac_input.extend_from_slice(orig_dcid);
|
|
262
|
-
let tag = hmac_sha256(secret, &mac_input);
|
|
263
|
-
let mut token = Vec::with_capacity(4 + orig_dcid.len() + TOKEN_TAG_LEN);
|
|
264
|
-
token.extend_from_slice(b"rwt1");
|
|
265
|
-
token.extend_from_slice(orig_dcid);
|
|
266
|
-
token.extend_from_slice(&tag[..TOKEN_TAG_LEN]);
|
|
267
|
-
token
|
|
268
|
-
}
|
|
250
|
+
impl RetryTokens {
|
|
251
|
+
const TTL: Duration = Duration::from_secs(10);
|
|
269
252
|
|
|
270
|
-
///
|
|
271
|
-
///
|
|
272
|
-
fn
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
)
|
|
277
|
-
let rest = token.strip_prefix(b"rwt1")?;
|
|
278
|
-
if rest.len() < TOKEN_TAG_LEN {
|
|
279
|
-
return None;
|
|
280
|
-
}
|
|
281
|
-
let (orig_dcid, tag) = rest.split_at(rest.len() - TOKEN_TAG_LEN);
|
|
282
|
-
let mut mac_input = addr_identity(src);
|
|
283
|
-
mac_input.extend_from_slice(orig_dcid);
|
|
284
|
-
let expected = hmac_sha256(secret, &mac_input);
|
|
285
|
-
if !constant_time_eq(&expected[..TOKEN_TAG_LEN], tag) {
|
|
286
|
-
return None;
|
|
253
|
+
/// Authenticate the timestamp and original DCID, binding the token to both
|
|
254
|
+
/// the source address and the DCID that this Retry issued.
|
|
255
|
+
fn tag(&self, src: &SocketAddr, retry_scid: &[u8], body: &[u8]) -> [u8; 32] {
|
|
256
|
+
let mut input = addr_identity(src);
|
|
257
|
+
input.extend_from_slice(retry_scid);
|
|
258
|
+
input.extend_from_slice(body);
|
|
259
|
+
hmac_sha256(&self.secret, &input)
|
|
287
260
|
}
|
|
288
|
-
Some(quiche::ConnectionId::from_ref(orig_dcid))
|
|
289
|
-
}
|
|
290
261
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
let seed: u128 = std::time::SystemTime::now()
|
|
297
|
-
.duration_since(std::time::UNIX_EPOCH)
|
|
298
|
-
.map(|d| d.as_nanos())
|
|
299
|
-
.unwrap_or(0);
|
|
300
|
-
let s = seed.to_le_bytes();
|
|
301
|
-
for (i, slot) in b.iter_mut().enumerate() {
|
|
302
|
-
*slot = s[i % s.len()];
|
|
303
|
-
}
|
|
262
|
+
fn mint(&self, src: &SocketAddr, retry_scid: &[u8], orig_dcid: &[u8]) -> Vec<u8> {
|
|
263
|
+
let mut token = self.started.elapsed().as_secs().to_be_bytes().to_vec();
|
|
264
|
+
token.extend_from_slice(orig_dcid);
|
|
265
|
+
token.extend_from_slice(&self.tag(src, retry_scid, &token)[..TOKEN_TAG_LEN]);
|
|
266
|
+
token
|
|
304
267
|
}
|
|
305
|
-
b
|
|
306
|
-
}
|
|
307
268
|
|
|
308
|
-
fn
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
269
|
+
fn validate<'a>(
|
|
270
|
+
&self,
|
|
271
|
+
src: &SocketAddr,
|
|
272
|
+
retry_scid: &[u8],
|
|
273
|
+
token: &'a [u8],
|
|
274
|
+
) -> Option<quiche::ConnectionId<'a>> {
|
|
275
|
+
const TIMESTAMP_LEN: usize = size_of::<u64>();
|
|
276
|
+
if retry_scid.len() != LOCAL_CONN_ID_LEN
|
|
277
|
+
|| !(TIMESTAMP_LEN + 8 + TOKEN_TAG_LEN
|
|
278
|
+
..=TIMESTAMP_LEN + quiche::MAX_CONN_ID_LEN + TOKEN_TAG_LEN)
|
|
279
|
+
.contains(&token.len())
|
|
280
|
+
{
|
|
281
|
+
return None;
|
|
282
|
+
}
|
|
283
|
+
let (body, tag) = token.split_at(token.len() - TOKEN_TAG_LEN);
|
|
284
|
+
let (issued, orig_dcid) = body.split_at(TIMESTAMP_LEN);
|
|
285
|
+
let issued = u64::from_be_bytes(issued.try_into().ok()?);
|
|
286
|
+
let age = self.started.elapsed().as_secs().checked_sub(issued)?;
|
|
287
|
+
if age > Self::TTL.as_secs()
|
|
288
|
+
|| !boring::memcmp::eq(&self.tag(src, retry_scid, body)[..TOKEN_TAG_LEN], tag)
|
|
289
|
+
{
|
|
290
|
+
return None;
|
|
291
|
+
}
|
|
292
|
+
Some(quiche::ConnectionId::from_ref(orig_dcid))
|
|
316
293
|
}
|
|
317
|
-
b
|
|
318
294
|
}
|
|
319
295
|
|
|
320
296
|
fn run_inner(
|
|
@@ -367,6 +343,17 @@ fn run_inner(
|
|
|
367
343
|
return;
|
|
368
344
|
}
|
|
369
345
|
|
|
346
|
+
let mut secret = [0; 32];
|
|
347
|
+
if let Err(e) = getrandom::fill(&mut secret) {
|
|
348
|
+
sink.emit(vec![ServerMsg::ServerError(format!(
|
|
349
|
+
"Retry key generation: {e}"
|
|
350
|
+
))]);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
let tokens = RetryTokens {
|
|
354
|
+
secret,
|
|
355
|
+
started: Instant::now(),
|
|
356
|
+
};
|
|
370
357
|
sink.emit(vec![ServerMsg::Listening(local_addr.port())]);
|
|
371
358
|
|
|
372
359
|
let mut events = Events::with_capacity(1024);
|
|
@@ -379,32 +366,51 @@ fn run_inner(
|
|
|
379
366
|
let mut next_session_id: u64 = 1;
|
|
380
367
|
let parser_memory = ParserMemory::new(MAX_PARSER_MEMORY);
|
|
381
368
|
|
|
382
|
-
|
|
383
|
-
let
|
|
369
|
+
let mut udp_pending = false;
|
|
370
|
+
let mut read_pending = false;
|
|
371
|
+
let mut next_connection: usize = 0;
|
|
384
372
|
|
|
385
373
|
loop {
|
|
386
|
-
let
|
|
387
|
-
if
|
|
388
|
-
|
|
374
|
+
let can_read = shared.inflight.load(Ordering::Relaxed) < MAX_INFLIGHT_BATCHES;
|
|
375
|
+
let timeout = if udp_pending || (read_pending && can_read) {
|
|
376
|
+
Some(Duration::ZERO)
|
|
377
|
+
} else {
|
|
378
|
+
let now = Instant::now();
|
|
379
|
+
clients
|
|
380
|
+
.values()
|
|
381
|
+
.flat_map(|c| {
|
|
382
|
+
[
|
|
383
|
+
c.conn.timeout(),
|
|
384
|
+
c.setup_deadline.map(|d| d.saturating_duration_since(now)),
|
|
385
|
+
]
|
|
386
|
+
})
|
|
387
|
+
.flatten()
|
|
388
|
+
.min()
|
|
389
|
+
};
|
|
390
|
+
if let Err(e) = poll.poll(&mut events, timeout) {
|
|
391
|
+
if e.kind() == std::io::ErrorKind::Interrupted {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
sink.emit(vec![ServerMsg::ServerError(format!("poll error: {e}"))]);
|
|
395
|
+
return;
|
|
389
396
|
}
|
|
390
397
|
|
|
391
398
|
let mut out: Vec<ServerMsg> = Vec::new();
|
|
392
399
|
|
|
393
400
|
// 1. Read datagrams and route them, up to a per-wake budget so a flood
|
|
394
401
|
// cannot starve the rest of the loop (commands, timeouts, reaping).
|
|
395
|
-
let mut got_packet = false;
|
|
396
402
|
let mut budget = MAX_RECV_PER_WAKE;
|
|
397
|
-
|
|
398
|
-
if budget == 0 {
|
|
399
|
-
break;
|
|
400
|
-
}
|
|
403
|
+
while budget > 0 {
|
|
401
404
|
budget -= 1;
|
|
402
405
|
let (len, from) = match socket.recv_from(&mut recv_buf) {
|
|
403
406
|
Ok(v) => v,
|
|
404
407
|
Err(ref e) if e.kind() == std::io::ErrorKind::WouldBlock => break,
|
|
408
|
+
Err(ref e) if is_udp_port_unreachable(e) => continue,
|
|
405
409
|
Err(_) => break,
|
|
406
410
|
};
|
|
407
|
-
|
|
411
|
+
if len > MAX_RECV_UDP_PAYLOAD {
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
408
414
|
let pkt = &mut recv_buf[..len];
|
|
409
415
|
let hdr = match quiche::Header::from_slice(pkt, LOCAL_CONN_ID_LEN) {
|
|
410
416
|
Ok(h) => h,
|
|
@@ -414,7 +420,11 @@ fn run_inner(
|
|
|
414
420
|
let scid = match routing.get(&hdr.dcid.to_vec()).cloned() {
|
|
415
421
|
Some(s) => s,
|
|
416
422
|
None => {
|
|
417
|
-
if hdr.ty != quiche::Type::Initial
|
|
423
|
+
if hdr.ty != quiche::Type::Initial
|
|
424
|
+
|| len < 1200
|
|
425
|
+
|| !quiche::version_is_supported(hdr.version)
|
|
426
|
+
|| hdr.dcid.len() < 8
|
|
427
|
+
{
|
|
418
428
|
continue;
|
|
419
429
|
}
|
|
420
430
|
// Cap concurrent connections to bound memory under a flood.
|
|
@@ -429,9 +439,12 @@ fn run_inner(
|
|
|
429
439
|
// No address validation yet: reply with a stateless Retry.
|
|
430
440
|
// We create no connection state (and do not amplify) for a
|
|
431
441
|
// source that has not proven it owns its address.
|
|
432
|
-
let new_scid =
|
|
442
|
+
let mut new_scid = [0; LOCAL_CONN_ID_LEN];
|
|
443
|
+
if getrandom::fill(&mut new_scid).is_err() {
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
433
446
|
let new_scid_id = quiche::ConnectionId::from_ref(&new_scid);
|
|
434
|
-
let retry_token =
|
|
447
|
+
let retry_token = tokens.mint(&from, &new_scid, &hdr.dcid);
|
|
435
448
|
if let Ok(len) = quiche::retry(
|
|
436
449
|
&hdr.scid,
|
|
437
450
|
&hdr.dcid,
|
|
@@ -447,7 +460,7 @@ fn run_inner(
|
|
|
447
460
|
|
|
448
461
|
// The client echoed a Retry token: validate it before we
|
|
449
462
|
// allocate any connection state.
|
|
450
|
-
let Some(odcid) =
|
|
463
|
+
let Some(odcid) = tokens.validate(&from, &hdr.dcid, token) else {
|
|
451
464
|
continue;
|
|
452
465
|
};
|
|
453
466
|
// Our Retry SCID, echoed back as this Initial's DCID.
|
|
@@ -476,7 +489,8 @@ fn run_inner(
|
|
|
476
489
|
parser_memory.clone(),
|
|
477
490
|
),
|
|
478
491
|
session_id,
|
|
479
|
-
|
|
492
|
+
setup_deadline: Some(Instant::now() + SESSION_SETUP_TIMEOUT),
|
|
493
|
+
max_datagram_size: 0,
|
|
480
494
|
},
|
|
481
495
|
);
|
|
482
496
|
key
|
|
@@ -491,13 +505,24 @@ fn run_inner(
|
|
|
491
505
|
let _ = server.conn.recv(pkt, info);
|
|
492
506
|
}
|
|
493
507
|
}
|
|
508
|
+
udp_pending = budget == 0;
|
|
494
509
|
|
|
495
510
|
// 2. Fire elapsed timeouts for every connection. quiche's on_timeout is a
|
|
496
511
|
// no-op unless a timer is actually due, and it must run even while packets
|
|
497
512
|
// keep arriving so idle/half-open connections are reaped under a flood.
|
|
498
|
-
let
|
|
513
|
+
let now = Instant::now();
|
|
499
514
|
for server in clients.values_mut() {
|
|
500
515
|
server.conn.on_timeout();
|
|
516
|
+
if server
|
|
517
|
+
.setup_deadline
|
|
518
|
+
.is_some_and(|deadline| now >= deadline)
|
|
519
|
+
{
|
|
520
|
+
// The deadline covers both QUIC handshake and Extended CONNECT.
|
|
521
|
+
server.setup_deadline = None;
|
|
522
|
+
let _ = server
|
|
523
|
+
.conn
|
|
524
|
+
.close(true, h3::H3_NO_ERROR, b"session setup timed out");
|
|
525
|
+
}
|
|
501
526
|
}
|
|
502
527
|
|
|
503
528
|
// 3. Drain commands.
|
|
@@ -518,20 +543,34 @@ fn run_inner(
|
|
|
518
543
|
}
|
|
519
544
|
|
|
520
545
|
// 4. Drive every connection.
|
|
521
|
-
let
|
|
522
|
-
|
|
546
|
+
let can_read = shared.inflight.load(Ordering::Relaxed) < MAX_INFLIGHT_BATCHES;
|
|
547
|
+
let mut budget = ReceiveBudget::new();
|
|
548
|
+
let mut ordered: Vec<_> = clients.values_mut().collect();
|
|
549
|
+
let start = next_connection.checked_rem(ordered.len()).unwrap_or(0);
|
|
550
|
+
ordered.rotate_left(start);
|
|
551
|
+
read_pending = false;
|
|
552
|
+
for (index, server) in ordered.into_iter().enumerate() {
|
|
553
|
+
if server.conn.is_closed() || server.conn.local_error().is_some() {
|
|
554
|
+
flush_send(&mut server.conn, &socket, &mut send_buf);
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
523
557
|
let mut evs: Vec<Ev> = Vec::new();
|
|
524
558
|
if server.conn.is_established() {
|
|
525
|
-
server
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
server.session.on_datagrams(&mut server.conn, &mut evs);
|
|
559
|
+
server
|
|
560
|
+
.session
|
|
561
|
+
.on_established(server.conn.reliable_stream_reset_negotiated());
|
|
529
562
|
}
|
|
530
|
-
|
|
531
|
-
for id in readable {
|
|
563
|
+
if can_read && !budget.exhausted() {
|
|
532
564
|
server
|
|
533
565
|
.session
|
|
534
|
-
.
|
|
566
|
+
.read_pending(&mut server.conn, &mut budget, &mut evs);
|
|
567
|
+
if budget.exhausted() {
|
|
568
|
+
next_connection = start + index + 1;
|
|
569
|
+
read_pending = true;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if server.session.is_ready() {
|
|
573
|
+
server.setup_deadline = None;
|
|
535
574
|
}
|
|
536
575
|
server.session.flush(&mut server.conn, &mut evs);
|
|
537
576
|
|
|
@@ -543,10 +582,12 @@ fn run_inner(
|
|
|
543
582
|
let _ = server.conn.close(true, h3::H3_NO_ERROR, b"");
|
|
544
583
|
}
|
|
545
584
|
|
|
546
|
-
if
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
.
|
|
585
|
+
if server.session.is_ready() && !server.session.is_closed() {
|
|
586
|
+
let size = server.session.max_datagram_size(&server.conn);
|
|
587
|
+
if size != server.max_datagram_size {
|
|
588
|
+
server.max_datagram_size = size;
|
|
589
|
+
evs.push(Ev::DatagramSize(size));
|
|
590
|
+
}
|
|
550
591
|
}
|
|
551
592
|
|
|
552
593
|
for ev in evs {
|
|
@@ -561,24 +602,21 @@ fn run_inner(
|
|
|
561
602
|
|
|
562
603
|
// 5. Reap closed connections (emit a final Closed for the session).
|
|
563
604
|
for server in clients.values_mut() {
|
|
564
|
-
if server.conn.is_closed() && !server.
|
|
565
|
-
|
|
566
|
-
if
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
if let Some(msg) = err {
|
|
575
|
-
evs.push(Ev::Error(msg));
|
|
576
|
-
}
|
|
577
|
-
server.session.mark_closed(&mut evs, code, reason, remote);
|
|
578
|
-
}
|
|
579
|
-
for ev in evs {
|
|
580
|
-
out.push(ServerMsg::Session(server.session_id, ev));
|
|
605
|
+
if server.conn.is_closed() && server.session.is_ready() && !server.session.is_closed() {
|
|
606
|
+
let mut evs = Vec::new();
|
|
607
|
+
if let Some((code, reason)) = server.session.local_close_info() {
|
|
608
|
+
// Locally initiated graceful WebTransport close: surface the
|
|
609
|
+
// WT code/reason (the wire close used H3_NO_ERROR).
|
|
610
|
+
server.session.mark_closed(&mut evs, code, reason, false);
|
|
611
|
+
} else {
|
|
612
|
+
let (code, reason, remote, err) = closure_info(&server.conn);
|
|
613
|
+
if let Some(msg) = err {
|
|
614
|
+
evs.push(Ev::Error(msg));
|
|
581
615
|
}
|
|
616
|
+
server.session.mark_closed(&mut evs, code, reason, remote);
|
|
617
|
+
}
|
|
618
|
+
for ev in evs {
|
|
619
|
+
out.push(ServerMsg::Session(server.session_id, ev));
|
|
582
620
|
}
|
|
583
621
|
}
|
|
584
622
|
}
|
|
@@ -665,7 +703,7 @@ fn apply_command(
|
|
|
665
703
|
context,
|
|
666
704
|
length,
|
|
667
705
|
..
|
|
668
|
-
} => evs.push(
|
|
706
|
+
} => evs.push(server.session.build_keying_material(
|
|
669
707
|
&mut server.conn,
|
|
670
708
|
request_id,
|
|
671
709
|
&label,
|
|
@@ -759,54 +797,31 @@ mod tests {
|
|
|
759
797
|
}
|
|
760
798
|
|
|
761
799
|
#[test]
|
|
762
|
-
fn
|
|
763
|
-
let
|
|
764
|
-
|
|
800
|
+
fn retry_token_authenticates_address_and_connection() {
|
|
801
|
+
let mut tokens = RetryTokens {
|
|
802
|
+
secret: [7; 32],
|
|
803
|
+
started: Instant::now(),
|
|
804
|
+
};
|
|
765
805
|
let src = addr("192.0.2.10:4433");
|
|
766
|
-
let
|
|
767
|
-
let
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
assert!(
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
let src = addr("198.51.100.7:443");
|
|
786
|
-
let token = mint_token(&[1u8; 32], dcid, &src);
|
|
787
|
-
// A server that restarted (new secret) rejects the stale token.
|
|
788
|
-
assert!(validate_token(&[2u8; 32], &src, &token).is_none());
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
#[test]
|
|
792
|
-
fn forged_and_truncated_tokens_are_rejected() {
|
|
793
|
-
let secret = [9u8; 32];
|
|
794
|
-
let src = addr("198.51.100.7:443");
|
|
795
|
-
// Attacker who does not know the secret guesses the layout with a zero tag.
|
|
796
|
-
let mut forged = Vec::new();
|
|
797
|
-
forged.extend_from_slice(b"rwt1");
|
|
798
|
-
forged.extend_from_slice(b"deadbeefdcid");
|
|
799
|
-
forged.extend_from_slice(&[0u8; TOKEN_TAG_LEN]);
|
|
800
|
-
assert!(validate_token(&secret, &src, &forged).is_none());
|
|
801
|
-
// Too short to hold a tag, wrong prefix, empty.
|
|
802
|
-
assert!(validate_token(&secret, &src, b"rwt1short").is_none());
|
|
803
|
-
assert!(validate_token(&secret, &src, b"nope").is_none());
|
|
804
|
-
assert!(validate_token(&secret, &src, b"").is_none());
|
|
805
|
-
// A valid token with a single tag byte flipped.
|
|
806
|
-
let mut token = mint_token(&secret, b"abcdefghij", &src);
|
|
807
|
-
let last = token.len() - 1;
|
|
808
|
-
token[last] ^= 0xff;
|
|
809
|
-
assert!(validate_token(&secret, &src, &token).is_none());
|
|
806
|
+
let dcid = b"original id";
|
|
807
|
+
let scid = [42; LOCAL_CONN_ID_LEN];
|
|
808
|
+
let token = tokens.mint(&src, &scid, dcid);
|
|
809
|
+
assert_eq!(tokens.validate(&src, &scid, &token).unwrap().as_ref(), dcid);
|
|
810
|
+
assert!(tokens
|
|
811
|
+
.validate(&addr("192.0.2.11:4433"), &scid, &token)
|
|
812
|
+
.is_none());
|
|
813
|
+
assert!(tokens
|
|
814
|
+
.validate(&addr("192.0.2.10:1234"), &scid, &token)
|
|
815
|
+
.is_none());
|
|
816
|
+
assert!(tokens
|
|
817
|
+
.validate(&src, &[41; LOCAL_CONN_ID_LEN], &token)
|
|
818
|
+
.is_none());
|
|
819
|
+
assert!(tokens.validate(&src, &scid, &token[..7]).is_none());
|
|
820
|
+
let mut altered = token.clone();
|
|
821
|
+
*altered.last_mut().unwrap() ^= 1;
|
|
822
|
+
assert!(tokens.validate(&src, &scid, &altered).is_none());
|
|
823
|
+
tokens.started -= RetryTokens::TTL + Duration::from_secs(1);
|
|
824
|
+
assert!(tokens.validate(&src, &scid, &token).is_none());
|
|
810
825
|
}
|
|
811
826
|
|
|
812
827
|
#[test]
|