Skip to main content

moq_native/
quic.rs

1//! QUIC transport tuning, split by role.
2//!
3//! [`Client`] (`--client-quic-*`) and [`Server`] (`--server-quic-*`) carry the
4//! per-connection knobs (stream limits, GSO, timeouts) that each backend applies.
5//! [`Server`] additionally owns the knobs that only make sense when accepting
6//! connections: the QUIC preferred address and the QUIC-LB connection-ID encoding.
7//!
8//! Each is flattened directly onto [`crate::ClientConfig`] / [`crate::ServerConfig`],
9//! so the args parse straight into the config the endpoint is built from. Not
10//! every backend honors every knob, see the field docs.
11
12use std::net;
13use std::path::PathBuf;
14use std::time::Duration;
15
16/// The routable server ID a QUIC-LB load balancer encodes into connection IDs.
17///
18/// Parsed from, and serialized as, a hex string. Its length must match the load
19/// balancer's configured server-ID length.
20#[serde_with::serde_as]
21#[derive(Clone, serde::Serialize, serde::Deserialize)]
22pub struct ServerId(#[serde_as(as = "serde_with::hex::Hex")] pub(crate) Vec<u8>);
23
24impl ServerId {
25	#[allow(dead_code)]
26	pub(crate) fn len(&self) -> usize {
27		self.0.len()
28	}
29}
30
31impl std::fmt::Debug for ServerId {
32	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33		f.debug_tuple("ServerId").field(&hex::encode(&self.0)).finish()
34	}
35}
36
37impl std::str::FromStr for ServerId {
38	type Err = hex::FromHexError;
39
40	fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
41		hex::decode(s).map(Self)
42	}
43}
44
45/// The congestion control family for a QUIC connection.
46///
47/// This selects a family rather than a named algorithm because each backend ships a
48/// different generation: BBRv1 on quinn, BBRv2 on quiche, BBRv3 on noq and iroh. A
49/// `Bbr` variant would promise more than any one backend delivers.
50#[derive(Clone, Copy, Debug, PartialEq, Eq, clap::ValueEnum, serde::Serialize, serde::Deserialize)]
51#[serde(rename_all = "kebab-case")]
52#[non_exhaustive]
53pub enum CongestionControl {
54	/// Loss-based (CUBIC): grows until it drops packets, so the send rate sawtooths.
55	/// Throughput-oriented, and the default on most stacks.
56	Loss,
57	/// Delay-based (BBR): tracks the measured delivery rate and RTT instead of waiting
58	/// for loss, which keeps queues short and the send rate steady enough for an encoder
59	/// to track.
60	Delay,
61}
62
63/// Parses the same spellings the CLI and TOML accept (`loss`, `delay`), case-insensitively.
64impl std::str::FromStr for CongestionControl {
65	type Err = String;
66
67	fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
68		<Self as clap::ValueEnum>::from_str(s, true)
69	}
70}
71
72/// Default maximum number of concurrent QUIC streams (bidi and uni) per connection.
73pub(crate) const DEFAULT_MAX_STREAMS: u64 = 1024;
74
75/// Default idle timeout before an inactive connection is dropped.
76pub(crate) const DEFAULT_IDLE_TIMEOUT: Duration = Duration::from_secs(30);
77
78/// Default keep-alive ping interval.
79pub(crate) const DEFAULT_KEEP_ALIVE: Duration = Duration::from_secs(5);
80
81/// The `--client-quic-*` transport section.
82#[derive(Clone, Debug, Default, clap::Args, serde::Serialize, serde::Deserialize)]
83#[serde(deny_unknown_fields, default)]
84#[non_exhaustive]
85pub struct Client {
86	/// Maximum number of concurrent QUIC streams per connection (both bidi and uni).
87	/// Defaults to 1024. MoQ opens a stream per group, so busy endpoints want this high.
88	#[serde(skip_serializing_if = "Option::is_none")]
89	#[arg(
90		id = "client-quic-max-streams",
91		long = "client-quic-max-streams",
92		alias = "client-max-streams",
93		env = "MOQ_CLIENT_QUIC_MAX_STREAMS"
94	)]
95	pub max_streams: Option<u64>,
96
97	/// Enable UDP generic segmentation offload (GSO).
98	///
99	/// GSO batches sends into one syscall for throughput, but some NICs and
100	/// middleboxes mangle segmented packets. Defaults to on. The iroh backend
101	/// cannot turn it off and rejects an explicit `false`.
102	#[serde(skip_serializing_if = "Option::is_none")]
103	#[arg(
104		id = "client-quic-gso",
105		long = "client-quic-gso",
106		env = "MOQ_CLIENT_QUIC_GSO",
107		default_missing_value = "true",
108		num_args = 0..=1,
109		require_equals = true,
110		value_parser = clap::value_parser!(bool),
111	)]
112	pub gso: Option<bool>,
113
114	/// Idle timeout before an inactive connection is dropped. Defaults to 30s.
115	#[serde(default, skip_serializing_if = "Option::is_none", with = "humantime_serde::option")]
116	#[arg(
117		id = "client-quic-idle-timeout",
118		long = "client-quic-idle-timeout",
119		env = "MOQ_CLIENT_QUIC_IDLE_TIMEOUT",
120		value_parser = humantime::parse_duration,
121	)]
122	pub idle_timeout: Option<Duration>,
123
124	/// Keep-alive ping interval. Defaults to 5s; set `0s` to disable.
125	/// Ignored by the iroh backend, which has no keep-alive knob.
126	#[serde(default, skip_serializing_if = "Option::is_none", with = "humantime_serde::option")]
127	#[arg(
128		id = "client-quic-keep-alive",
129		long = "client-quic-keep-alive",
130		env = "MOQ_CLIENT_QUIC_KEEP_ALIVE",
131		value_parser = humantime::parse_duration,
132	)]
133	pub keep_alive: Option<Duration>,
134
135	/// Enable path MTU discovery. Defaults to off.
136	#[serde(skip_serializing_if = "Option::is_none")]
137	#[arg(
138		id = "client-quic-mtu-discovery",
139		long = "client-quic-mtu-discovery",
140		env = "MOQ_CLIENT_QUIC_MTU_DISCOVERY",
141		default_missing_value = "true",
142		num_args = 0..=1,
143		require_equals = true,
144		value_parser = clap::value_parser!(bool),
145	)]
146	pub mtu_discovery: Option<bool>,
147
148	/// Congestion control family. Defaults to `delay` on quinn and quiche, and to
149	/// `loss` on noq and iroh, whose shared BBRv3 can panic on packet loss and take
150	/// the process with it. Selecting `delay` there is for deliberate testing only.
151	#[serde(skip_serializing_if = "Option::is_none")]
152	#[arg(
153		id = "client-quic-congestion-control",
154		long = "client-quic-congestion-control",
155		env = "MOQ_CLIENT_QUIC_CONGESTION_CONTROL",
156		value_enum
157	)]
158	pub congestion_control: Option<CongestionControl>,
159
160	/// Write qlog traces into this directory. See [`Server::qlog`].
161	#[serde(default, skip_serializing_if = "Option::is_none")]
162	#[arg(id = "client-quic-qlog", long = "client-quic-qlog", env = "MOQ_CLIENT_QUIC_QLOG")]
163	pub qlog: Option<PathBuf>,
164}
165
166/// Reject a qlog directory that this build can't honor.
167///
168/// Erroring beats silently ignoring the flag: the operator asked for traces and would
169/// otherwise go looking for files that were never going to appear. Checked once when
170/// the client/server is built, so the backends can assume the directory is usable.
171fn validate_qlog(qlog: Option<&PathBuf>) -> crate::Result<()> {
172	match qlog {
173		Some(_) if cfg!(not(feature = "qlog")) => Err(crate::Error::QlogUnsupported),
174		_ => Ok(()),
175	}
176}
177
178/// QUIC carries `max_idle_timeout` as a varint of milliseconds, so anything past this
179/// can't go on the wire.
180const MAX_IDLE_TIMEOUT: Duration = Duration::from_millis((1 << 62) - 1);
181
182/// Reject an idle timeout no QUIC connection can express.
183///
184/// Checked here rather than in each backend because the conversion the backends do is
185/// infallible-by-panic, and this config reaches them from a TOML file or a C caller.
186fn validate_idle_timeout(idle_timeout: Option<Duration>) -> crate::Result<()> {
187	match idle_timeout {
188		Some(timeout) if timeout > MAX_IDLE_TIMEOUT => Err(crate::Error::IdleTimeoutRange),
189		_ => Ok(()),
190	}
191}
192
193impl Client {
194	/// Reject knobs this build can't honor. Called when the client is built.
195	pub(crate) fn validate(&self) -> crate::Result<()> {
196		validate_qlog(self.qlog.as_ref())?;
197		validate_idle_timeout(self.idle_timeout)
198	}
199
200	/// The per-connection knobs with defaults applied, ready to hand to a backend.
201	pub fn resolve(&self) -> Resolved {
202		Resolved::new(
203			self.max_streams,
204			self.gso,
205			self.idle_timeout,
206			self.keep_alive,
207			self.mtu_discovery,
208			self.congestion_control,
209			self.qlog.clone(),
210		)
211	}
212}
213
214/// Every knob at its default, which is what an untouched [`Client`] resolves to.
215impl Default for Resolved {
216	fn default() -> Self {
217		Client::default().resolve()
218	}
219}
220
221/// The `--server-quic-*` transport section.
222///
223/// Carries the same per-connection knobs as [`Client`] plus the accept-side knobs
224/// (preferred address, QUIC-LB connection IDs).
225#[derive(Clone, Debug, Default, clap::Args, serde::Serialize, serde::Deserialize)]
226#[serde(deny_unknown_fields, default)]
227#[non_exhaustive]
228pub struct Server {
229	/// Maximum number of concurrent QUIC streams per connection (both bidi and uni).
230	/// Defaults to 1024. MoQ opens a stream per group, so busy endpoints want this high.
231	#[serde(skip_serializing_if = "Option::is_none")]
232	#[arg(
233		id = "server-quic-max-streams",
234		long = "server-quic-max-streams",
235		alias = "server-max-streams",
236		env = "MOQ_SERVER_QUIC_MAX_STREAMS"
237	)]
238	pub max_streams: Option<u64>,
239
240	/// Enable UDP generic segmentation offload (GSO). See [`Client::gso`].
241	#[serde(skip_serializing_if = "Option::is_none")]
242	#[arg(
243		id = "server-quic-gso",
244		long = "server-quic-gso",
245		env = "MOQ_SERVER_QUIC_GSO",
246		default_missing_value = "true",
247		num_args = 0..=1,
248		require_equals = true,
249		value_parser = clap::value_parser!(bool),
250	)]
251	pub gso: Option<bool>,
252
253	/// Idle timeout before an inactive connection is dropped. Defaults to 30s.
254	#[serde(default, skip_serializing_if = "Option::is_none", with = "humantime_serde::option")]
255	#[arg(
256		id = "server-quic-idle-timeout",
257		long = "server-quic-idle-timeout",
258		env = "MOQ_SERVER_QUIC_IDLE_TIMEOUT",
259		value_parser = humantime::parse_duration,
260	)]
261	pub idle_timeout: Option<Duration>,
262
263	/// Keep-alive ping interval. Defaults to 5s; set `0s` to disable.
264	#[serde(default, skip_serializing_if = "Option::is_none", with = "humantime_serde::option")]
265	#[arg(
266		id = "server-quic-keep-alive",
267		long = "server-quic-keep-alive",
268		env = "MOQ_SERVER_QUIC_KEEP_ALIVE",
269		value_parser = humantime::parse_duration,
270	)]
271	pub keep_alive: Option<Duration>,
272
273	/// Enable path MTU discovery. Defaults to off.
274	#[serde(skip_serializing_if = "Option::is_none")]
275	#[arg(
276		id = "server-quic-mtu-discovery",
277		long = "server-quic-mtu-discovery",
278		env = "MOQ_SERVER_QUIC_MTU_DISCOVERY",
279		default_missing_value = "true",
280		num_args = 0..=1,
281		require_equals = true,
282		value_parser = clap::value_parser!(bool),
283	)]
284	pub mtu_discovery: Option<bool>,
285
286	/// Congestion control family. Defaults to `delay` on quinn and quiche, and to
287	/// `loss` on noq, whose BBRv3 can panic on packet loss and take the process with
288	/// it. Selecting `delay` there is for deliberate testing only.
289	#[serde(skip_serializing_if = "Option::is_none")]
290	#[arg(
291		id = "server-quic-congestion-control",
292		long = "server-quic-congestion-control",
293		env = "MOQ_SERVER_QUIC_CONGESTION_CONTROL",
294		value_enum
295	)]
296	pub congestion_control: Option<CongestionControl>,
297
298	/// IPv4 address advertised as the QUIC preferred_address.
299	///
300	/// Supporting clients (Chrome M131+, native Quinn) migrate to this address
301	/// shortly after the handshake completes. Typical use: handshake on an
302	/// anycast IP, steady-state on this host's unicast IP.
303	///
304	/// Honored by the Quinn and noq backends.
305	#[arg(
306		id = "server-preferred-v4",
307		long = "server-preferred-v4",
308		env = "MOQ_SERVER_PREFERRED_V4"
309	)]
310	#[serde(default, skip_serializing_if = "Option::is_none")]
311	pub preferred_v4: Option<net::SocketAddrV4>,
312
313	/// IPv6 address advertised as the QUIC preferred_address. See [`Self::preferred_v4`].
314	#[arg(
315		id = "server-preferred-v6",
316		long = "server-preferred-v6",
317		env = "MOQ_SERVER_PREFERRED_V6"
318	)]
319	#[serde(default, skip_serializing_if = "Option::is_none")]
320	pub preferred_v6: Option<net::SocketAddrV6>,
321
322	/// Server ID to embed in connection IDs for QUIC-LB compatibility.
323	/// If set, connection IDs will be derived semi-deterministically.
324	#[arg(id = "server-quic-lb-id", long = "server-quic-lb-id", env = "MOQ_SERVER_QUIC_LB_ID")]
325	#[serde(default, skip_serializing_if = "Option::is_none")]
326	pub quic_lb_id: Option<ServerId>,
327
328	/// Number of random nonce bytes in QUIC-LB connection IDs.
329	/// Must be at least 4, and server_id + nonce + 1 must not exceed 20.
330	#[arg(
331		id = "server-quic-lb-nonce",
332		long = "server-quic-lb-nonce",
333		requires = "server-quic-lb-id",
334		env = "MOQ_SERVER_QUIC_LB_NONCE"
335	)]
336	#[serde(default, skip_serializing_if = "Option::is_none")]
337	pub quic_lb_nonce: Option<usize>,
338
339	/// Write qlog traces into this directory, which must already exist.
340	///
341	/// The layout is backend-specific: quiche and noq write one file per connection,
342	/// while quinn writes one file per endpoint and tags each event with the qlog
343	/// `group_id` of the connection it belongs to.
344	///
345	/// Requires the `qlog` feature; setting it errors at init otherwise.
346	#[serde(default, skip_serializing_if = "Option::is_none")]
347	#[arg(id = "server-quic-qlog", long = "server-quic-qlog", env = "MOQ_SERVER_QUIC_QLOG")]
348	pub qlog: Option<PathBuf>,
349}
350
351impl Server {
352	/// Reject knobs this build can't honor. Called when the server is built.
353	pub(crate) fn validate(&self) -> crate::Result<()> {
354		validate_qlog(self.qlog.as_ref())?;
355		validate_idle_timeout(self.idle_timeout)
356	}
357
358	/// The per-connection knobs with defaults applied, ready to hand to a backend.
359	pub(crate) fn resolve(&self) -> Resolved {
360		Resolved::new(
361			self.max_streams,
362			self.gso,
363			self.idle_timeout,
364			self.keep_alive,
365			self.mtu_discovery,
366			self.congestion_control,
367			self.qlog.clone(),
368		)
369	}
370}
371
372/// A resolved view of the per-connection knobs (defaults filled in), shared by
373/// [`Client`] and [`Server`] so backends apply them the same way regardless of role.
374///
375/// The backends consume it, and [`Client::resolve`] produces it. [`Resolved::default`]
376/// is therefore the canonical statement of what every QUIC knob defaults to, which is
377/// what a UI should show rather than repeating the numbers.
378///
379/// Non-exhaustive because it gains a field for every knob [`Client`] gains, so build it
380/// from [`Client::resolve`] or [`Resolved::default`] rather than a struct literal.
381#[derive(Clone, Debug)]
382#[non_exhaustive]
383pub struct Resolved {
384	/// Max concurrent streams (bidi and uni).
385	pub max_streams: u64,
386	/// GSO override, or `None` to leave the backend default (on).
387	pub gso: Option<bool>,
388	/// Idle timeout.
389	pub idle_timeout: Duration,
390	/// Keep-alive interval, or `None` when disabled.
391	pub keep_alive: Option<Duration>,
392	/// Whether to run path MTU discovery.
393	pub mtu_discovery: bool,
394	/// Congestion control override, or `None` for the backend's own default. Each
395	/// backend picks that default itself, since they don't all agree.
396	pub congestion_control: Option<CongestionControl>,
397	/// Directory to write qlog traces into, or `None` to not capture them.
398	pub qlog: Option<PathBuf>,
399}
400
401impl Resolved {
402	fn new(
403		max_streams: Option<u64>,
404		gso: Option<bool>,
405		idle_timeout: Option<Duration>,
406		keep_alive: Option<Duration>,
407		mtu_discovery: Option<bool>,
408		congestion_control: Option<CongestionControl>,
409		qlog: Option<PathBuf>,
410	) -> Self {
411		// A zero keep-alive means "disabled"; anything else (including unset) keeps
412		// the connection warm, defaulting to 5s.
413		let keep_alive = match keep_alive {
414			Some(d) if d.is_zero() => None,
415			Some(d) => Some(d),
416			None => Some(DEFAULT_KEEP_ALIVE),
417		};
418
419		Self {
420			max_streams: max_streams.unwrap_or(DEFAULT_MAX_STREAMS),
421			gso,
422			idle_timeout: idle_timeout.unwrap_or(DEFAULT_IDLE_TIMEOUT),
423			keep_alive,
424			mtu_discovery: mtu_discovery.unwrap_or(false),
425			congestion_control,
426			qlog,
427		}
428	}
429
430	/// The directory to write qlog traces into, if any.
431	///
432	/// Only meaningful once [`Client::validate`] / [`Server::validate`] has passed; a
433	/// build without the `qlog` feature never gets here with a directory set.
434	#[cfg_attr(not(any(feature = "quinn", feature = "noq", feature = "quiche")), allow(dead_code))]
435	pub(crate) fn qlog_dir(&self) -> Option<&std::path::Path> {
436		self.qlog.as_deref()
437	}
438
439	/// Whether the config asks to turn GSO off, which not every backend can honor.
440	///
441	/// Only the iroh backend consults this, to reject a GSO-off request it can't
442	/// satisfy; the other backends toggle GSO directly.
443	#[cfg_attr(not(feature = "iroh"), allow(dead_code))]
444	pub(crate) fn gso_disabled(&self) -> bool {
445		self.gso == Some(false)
446	}
447}
448
449#[cfg(test)]
450mod tests {
451	use super::*;
452	use clap::Parser;
453
454	/// Minimal parsers so we can exercise the `--client-quic-*` / `--server-quic-*`
455	/// args in isolation (and together, the way relay/cli flatten both).
456	#[derive(Parser)]
457	struct Both {
458		#[command(flatten)]
459		client: Client,
460		#[command(flatten)]
461		server: Server,
462	}
463
464	fn parse(args: &[&str]) -> Both {
465		let mut full = vec!["test"];
466		full.extend_from_slice(args);
467		Both::parse_from(full)
468	}
469
470	#[test]
471	fn defaults_apply_when_unset() {
472		let quic = Client::default().resolve();
473		assert_eq!(quic.max_streams, DEFAULT_MAX_STREAMS);
474		assert_eq!(quic.idle_timeout, DEFAULT_IDLE_TIMEOUT);
475		assert_eq!(quic.keep_alive, Some(DEFAULT_KEEP_ALIVE));
476		assert!(!quic.mtu_discovery);
477		assert_eq!(quic.gso, None);
478		assert!(!quic.gso_disabled());
479	}
480
481	#[test]
482	fn zero_keep_alive_disables_it() {
483		let disabled = Server {
484			keep_alive: Some(Duration::ZERO),
485			..Default::default()
486		};
487		assert_eq!(disabled.resolve().keep_alive, None);
488
489		let explicit = Client {
490			keep_alive: Some(Duration::from_secs(2)),
491			..Default::default()
492		};
493		assert_eq!(explicit.resolve().keep_alive, Some(Duration::from_secs(2)));
494	}
495
496	#[test]
497	fn gso_disabled_only_on_explicit_false() {
498		let off = Client {
499			gso: Some(false),
500			..Default::default()
501		};
502		assert!(off.resolve().gso_disabled());
503		let on = Client {
504			gso: Some(true),
505			..Default::default()
506		};
507		assert!(!on.resolve().gso_disabled());
508	}
509
510	#[test]
511	fn client_and_server_flags_are_distinct() {
512		let both = parse(&["--client-quic-max-streams", "5000", "--server-quic-max-streams", "9000"]);
513		assert_eq!(both.client.max_streams, Some(5000));
514		assert_eq!(both.server.max_streams, Some(9000));
515	}
516
517	#[test]
518	fn server_only_knobs_parse() {
519		let both = parse(&["--server-preferred-v4", "192.0.2.1:443", "--server-quic-lb-id", "ab"]);
520		assert_eq!(both.server.preferred_v4, Some("192.0.2.1:443".parse().unwrap()));
521		assert!(both.server.quic_lb_id.is_some());
522		// The accept-side knobs live only on the server section.
523		assert_eq!(both.client.max_streams, None);
524	}
525
526	#[test]
527	fn deprecated_max_streams_aliases() {
528		let both = parse(&["--client-max-streams", "2048", "--server-max-streams", "4096"]);
529		assert_eq!(both.client.max_streams, Some(2048));
530		assert_eq!(both.server.max_streams, Some(4096));
531	}
532
533	#[test]
534	fn qlog_flags_are_distinct_per_role() {
535		let both = parse(&["--client-quic-qlog", "/tmp/client", "--server-quic-qlog", "/tmp/server"]);
536		assert_eq!(both.client.qlog.as_deref(), Some(std::path::Path::new("/tmp/client")));
537		assert_eq!(both.server.qlog.as_deref(), Some(std::path::Path::new("/tmp/server")));
538
539		assert_eq!(
540			both.client.resolve().qlog_dir(),
541			Some(std::path::Path::new("/tmp/client"))
542		);
543		assert_eq!(Client::default().resolve().qlog_dir(), None);
544	}
545
546	/// A build that can't capture must reject the flag rather than ignore it, so an
547	/// operator isn't left waiting on trace files that will never appear.
548	#[test]
549	fn qlog_requires_the_feature() {
550		let unset = Client::default().validate();
551		assert!(unset.is_ok(), "no directory configured is always fine");
552
553		let set = Client {
554			qlog: Some("/tmp/qlog".into()),
555			..Default::default()
556		};
557
558		if cfg!(feature = "qlog") {
559			assert!(set.validate().is_ok());
560		} else {
561			assert!(matches!(set.validate(), Err(crate::Error::QlogUnsupported)));
562		}
563	}
564
565	/// The backends convert this duration with an infallible-by-panic `expect`, and the
566	/// value arrives from a TOML file or a C caller, so validation has to catch it here.
567	#[test]
568	fn idle_timeout_beyond_the_varint_is_rejected() {
569		let over = Client {
570			idle_timeout: Some(MAX_IDLE_TIMEOUT + Duration::from_millis(1)),
571			..Default::default()
572		};
573		assert!(matches!(over.validate(), Err(crate::Error::IdleTimeoutRange)));
574
575		let server = Server {
576			idle_timeout: Some(Duration::from_millis(u64::MAX)),
577			..Default::default()
578		};
579		assert!(matches!(server.validate(), Err(crate::Error::IdleTimeoutRange)));
580
581		let at_limit = Client {
582			idle_timeout: Some(MAX_IDLE_TIMEOUT),
583			..Default::default()
584		};
585		assert!(at_limit.validate().is_ok());
586	}
587
588	#[test]
589	fn toml_round_trips() {
590		let toml = r#"
591			max_streams = 7000
592			gso = false
593			preferred_v4 = "192.0.2.1:443"
594			congestion_control = "delay"
595			qlog = "/tmp/qlog"
596		"#;
597		let quic: Server = toml::from_str(toml).unwrap();
598		assert_eq!(quic.max_streams, Some(7000));
599		assert_eq!(quic.gso, Some(false));
600		assert_eq!(quic.preferred_v4, Some("192.0.2.1:443".parse().unwrap()));
601		assert_eq!(quic.congestion_control, Some(CongestionControl::Delay));
602		assert_eq!(quic.qlog.as_deref(), Some(std::path::Path::new("/tmp/qlog")));
603	}
604
605	#[test]
606	fn congestion_control_flags_parse() {
607		let both = parse(&[
608			"--client-quic-congestion-control",
609			"delay",
610			"--server-quic-congestion-control",
611			"loss",
612		]);
613		assert_eq!(both.client.congestion_control, Some(CongestionControl::Delay));
614		assert_eq!(both.server.congestion_control, Some(CongestionControl::Loss));
615
616		// Unset stays None; each backend then picks its own default.
617		assert_eq!(Client::default().resolve().congestion_control, None);
618	}
619}