From 466b5477a6b8c24972d30291b2958a891e5d2fcc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 9 Sep 2026 23:50:02 -0700 Subject: [PATCH 1/4] chore: claim quest/m1/config-provenance From d3b68cc602b97e33fc625a8994546b34926ca626 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 10 Sep 2026 01:39:17 -0700 Subject: [PATCH 2/4] feat(relay): merge config with recorded provenance Only a CLI or env value that was actually supplied overrides the TOML file. Precedence is CLI > env > file > defaults, declared in moq_tokio::cli::merge. Closes #3051 Closes #3221 Co-Authored-By: grok-4.6 --- Cargo.lock | 7 + doc/bin/relay/config.md | 3 + quest/m1/README.md | 1 - quest/m1/config-provenance.md | 67 ------ rs/moq-bench/Cargo.toml | 2 +- rs/moq-bench/src/config.rs | 190 +++++++++++++---- rs/moq-boy/Cargo.toml | 2 +- rs/moq-boy/src/main.rs | 2 +- rs/moq-cli/Cargo.toml | 2 +- rs/moq-cli/src/args.rs | 4 +- rs/moq-relay/CLAUDE.md | 4 +- rs/moq-relay/Cargo.toml | 2 +- rs/moq-relay/src/auth.rs | 46 +++- rs/moq-relay/src/cache.rs | 6 +- rs/moq-relay/src/cluster.rs | 64 ++++-- rs/moq-relay/src/config.rs | 290 ++++++++++++++++--------- rs/moq-relay/src/internal.rs | 7 +- rs/moq-relay/src/lib.rs | 1 + rs/moq-relay/src/runtime.rs | 36 ++-- rs/moq-relay/src/settings.rs | 235 ++++++++++++++++++++ rs/moq-relay/src/stats.rs | 41 ++-- rs/moq-relay/src/web.rs | 47 ++-- rs/moq-relay/tests/auth_lifetime.rs | 2 +- rs/moq-relay/tests/runtime_uring.rs | 4 +- rs/moq-relay/tests/runtime_workers.rs | 2 +- rs/moq-relay/tests/smoke.rs | 6 +- rs/moq-tokio/Cargo.toml | 3 +- rs/moq-tokio/examples/clock.rs | 1 + rs/moq-tokio/src/cli.rs | 207 +++++++++++++++++- rs/moq-tokio/src/client.rs | 1 + rs/moq-tokio/src/connect.rs | 37 +++- rs/moq-tokio/src/connection.rs | 45 +++- rs/moq-tokio/src/iroh.rs | 24 ++- rs/moq-tokio/src/lib.rs | 2 + rs/moq-tokio/src/listen.rs | 35 ++- rs/moq-tokio/src/log.rs | 8 +- rs/moq-tokio/src/quic.rs | 41 +++- rs/moq-tokio/src/server.rs | 1 + rs/moq-tokio/src/settings.rs | 294 ++++++++++++++++++++++++++ rs/moq-tokio/src/tcp.rs | 13 +- rs/moq-tokio/src/tls.rs | 69 +++++- rs/moq-tokio/src/unix.rs | 22 +- rs/moq-tokio/src/websocket.rs | 16 +- 43 files changed, 1525 insertions(+), 367 deletions(-) delete mode 100644 quest/m1/config-provenance.md create mode 100644 rs/moq-relay/src/settings.rs create mode 100644 rs/moq-tokio/src/settings.rs diff --git a/Cargo.lock b/Cargo.lock index 77a7f67e924..ca1c0e8cff8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10266,6 +10266,12 @@ version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ecb8bc2270df585912b1c3eca56c1319c441b6c4e4f977a107e93e709d5e7650" +[[package]] +name = "usage-config" +version = "6.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e19abc7aba3ff3392f63704558fd25d86fb3dd193de4809bf4173a7dd67b4129" + [[package]] name = "usage-derive" version = "6.3.0" @@ -10284,6 +10290,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da081ad5fff1d9a3e5d8ef4e2cb90a212fe23387682c99302f6562cb641b896f" dependencies = [ "usage-argv", + "usage-config", "usage-derive", "usage-test", ] diff --git a/doc/bin/relay/config.md b/doc/bin/relay/config.md index 75472ffd73e..6986c0959fe 100644 --- a/doc/bin/relay/config.md +++ b/doc/bin/relay/config.md @@ -7,6 +7,9 @@ description: TOML reference for moq-relay `moq-relay relay.toml`. Every key is also a CLI flag and environment variable (`--listen-backend`, `MOQ_LISTEN_BACKEND`), named by joining the section and key. +Precedence is CLI > env > file > defaults: a flag or environment variable that +was actually supplied overrides the file, and a file key that was actually +written (an empty list, a `false` boolean) overrides the built-in default. ## \[listen] diff --git a/quest/m1/README.md b/quest/m1/README.md index cc2945fb65e..e16c5f7be3c 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -37,7 +37,6 @@ quest here and merged main into dev. - [HLS 404](/quest/m1/hls-cache-miss-codes.md) - a relay miss and a disconnected publisher answer 404 over moq-lite; IETF upstreams stay 500 - [HLS sibling restart](/quest/m1/hls-sibling-epoch-identity.md) - a replaced sibling publisher restarts its rendition instead of serving stale rows - [A/V clock](/quest/m1/plan-av-clock.md) - the audio playhead drives Sync.reference while audio plays, through per-track sync handles -- [Config provenance](/quest/m1/config-provenance.md) - the merge records which source set a value, so an empty TOML list survives the environment and env outranks the file - [Cluster construction](/quest/m1/cluster-construction.md) - construct one stable origin after its cache settings are known, deleting the rebuilding builder - [LAN discovery app id](/quest/m1/lan-app.md) - every advertisement names an application as a DNS-SD subtype bound into the proofs, so unrelated apps on one network never meet - [One LAN mesh](/quest/m1/lan-mesh.md) - moq-cli drives the relay's Cluster, LAN peers authenticate by mDNS credential, and the two binaries mesh with each other diff --git a/quest/m1/config-provenance.md b/quest/m1/config-provenance.md deleted file mode 100644 index d933fb6abdc..00000000000 --- a/quest/m1/config-provenance.md +++ /dev/null @@ -1,67 +0,0 @@ -# [L] Config: track which source set each value - -## Goal - -`moq-relay` and `moq-bench` resolve configuration with recorded provenance. -Only a value the command line or the environment actually supplied overrides -the TOML file: a list the file sets to empty survives the merge, and a secret -injected by an orchestrator beats a placeholder in a checked-in file. -Precedence is `CLI > env > file > defaults`, declared in one place, and the -relay can say which source set a setting. - -## Plan - -`Config::parse_and_merge` (rs/moq-relay/src/config.rs:197-233) parses CLI plus -environment plus defaults, overlays the TOML file, then re-parses argv with -`update_from` so explicit flags win. Presence is inferred from the standing -value, so the re-parse refills whatever reads as empty: - -- A `Vec` reads empty when it has no items (usage-derive 6.3.0 - `standing_presence`, codegen.rs:3591), so a file that deliberately sets - `version = []` is refilled from the environment. About fifteen env-bound - list fields are affected: `moq-tokio`'s TLS roots, fingerprints, certs, - keys, and generated names (rs/moq-tokio/src/tls.rs:435,471,1211,1218,1230, - 1277), the accepted versions on both sides (listen.rs:73, connect.rs:495), - the Unix peer allowlists (unix.rs:150,160,171), and the relay's cluster - peers, auth roots and domains, and web HTTPS material - (rs/moq-relay/src/cluster.rs:419, auth.rs:323,472, web.rs:110,124,143). -- A plain scalar always reads as present (codegen.rs:3589), so a flag with a - declared default is safe. A bare `bool` is not, which is why every - TOML-overridable boolean is typed `Option` and resolved in code - (`web.ws`, rs/moq-relay/src/web.rs:62; the regression at config.rs:487-491). - That convention is a per-field workaround; `Option>` would multiply - it. -- The file outranks the environment, which no comparable tool does. - -Fix the merge instead of the types: - -- Enable the `config` feature of the workspace `usage` dependency - (Cargo.toml:201; usage-rs 6.3.0 already ships `usage::Config` and - `usage::config`). Build the layers from what the parser saw rather than - from the parsed struct: `usage::config`'s `CliLayer`, `EnvLayer` over a - `Registry` that declares which key each variable backs, and `Layers` in - caller-chosen order give exactly that, plus provenance. The cost is real: - `usage::Cli` and `usage::Config` reject each other's attributes, so every - merged setting is declared a second time: 44 relay flags plus the 100 - flattened in from `moq-tokio` (`long =` across rs/moq-relay/src and - rs/moq-tokio/src), and moq-bench's 13 own settings plus its three flattened - groups (rs/moq-bench/src/config.rs:81-93). `Registry::drift` is the test - that the two declarations stay in step. An all-optional overlay struct is - the fallback if the registry proves too heavy; either way, presence comes - from the source, never the value. -- Flip precedence to `CLI > env > file > defaults` and state it in - `doc/bin/relay/config.md`, which today only says every key is also a flag - and an environment variable (:8). -- Delete the `Option` resolve-in-code convention once the merge no - longer needs it, so a plain field is safe again. -- Table-driven regression coverage: empty lists, false booleans, optional - fields with declared defaults, nested flattened structs, environment - overrides, and explicit CLI overrides, each asserting both the value and - its source. - -Branch from `dev`: the relay config lives on `usage` there. - -## Closes - -- [#3051](https://github.com/moq-dev/moq/issues/3051) - close this issue when the quest finishes -- [#3221](https://github.com/moq-dev/moq/issues/3221) - the list half is what remains: a file's empty list is still refilled from the environment diff --git a/rs/moq-bench/Cargo.toml b/rs/moq-bench/Cargo.toml index d358fe3dd9d..5c64393ea1a 100644 --- a/rs/moq-bench/Cargo.toml +++ b/rs/moq-bench/Cargo.toml @@ -55,7 +55,7 @@ serde_json = { workspace = true } tokio = { workspace = true, features = ["full"] } toml = { workspace = true } tracing = { workspace = true } -usage = { workspace = true, features = ["completions"] } +usage = { workspace = true, features = ["completions", "config"] } # The host sampler reads /proc, so it is Linux-only (production relays are Linux). [target.'cfg(target_os = "linux")'.dependencies] diff --git a/rs/moq-bench/src/config.rs b/rs/moq-bench/src/config.rs index 87b9cc23258..c4beaba12dc 100644 --- a/rs/moq-bench/src/config.rs +++ b/rs/moq-bench/src/config.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::Range; /// moq-bench configuration, loadable from CLI arguments, environment variables, -/// or a TOML file. CLI flags always win over the TOML file. +/// or a TOML file. Precedence is CLI > env > file > defaults. /// /// Each `[min, max]` range is rolled once per connection, so a single config can /// describe a heterogeneous swarm (e.g. some connections at 24fps, others at 60). @@ -13,67 +13,67 @@ use crate::Range; #[usage(unknown_flags = "error", args_override_self = false)] #[serde(default, deny_unknown_fields)] #[usage(name = "moq-bench", version = env!("VERSION"))] -#[usage(completion)] +#[usage(completion, settings)] #[non_exhaustive] pub struct Config { /// The broadcast namespace prefix. Each broadcast is published under /// `///` and subscribers discover peers under ``. - #[usage(long, env = "MOQ_BENCH_NAME", default = "bench")] + #[usage(long, env = "MOQ_BENCH_NAME", default = "bench", setting = "name")] pub name: String, /// Run a 1:N benchmark around one named broadcast. The first connection /// publishes `//` and every remaining connection subscribes. - #[usage(long, env = "MOQ_BENCH_FANOUT")] + #[usage(long, env = "MOQ_BENCH_FANOUT", setting = "fanout")] #[serde(default, skip_serializing_if = "Option::is_none")] pub fanout: Option, /// Spread connection and subscription startup over this duration to avoid a thundering herd. - #[usage(long, env = "MOQ_BENCH_STARTUP", default = "10s")] + #[usage(long, env = "MOQ_BENCH_STARTUP", default = "10s", setting = "startup")] pub startup: moq_tokio::Duration, /// Stop the benchmark after this duration. Runs until interrupted if unset. - #[usage(long, env = "MOQ_BENCH_DURATION")] + #[usage(long, env = "MOQ_BENCH_DURATION", setting = "duration")] #[serde(default, skip_serializing_if = "Option::is_none")] pub duration: Option, /// How often to log throughput stats. - #[usage(long, env = "MOQ_BENCH_REPORT", default = "1s")] + #[usage(long, env = "MOQ_BENCH_REPORT", default = "1s", setting = "report")] pub report: moq_tokio::Duration, /// Number of connections (A) to establish. Rolled once for the whole run. - #[usage(long, env = "MOQ_BENCH_CONNECTIONS", default = "1")] + #[usage(long, env = "MOQ_BENCH_CONNECTIONS", default = "1", setting = "connections")] pub connections: Range, /// Broadcasts published per connection (B), each with a single track. /// /// `Option` because `--fanout` refuses to run alongside an explicit shape, and /// a materialized default cannot say whether one was given. - #[usage(long, env = "MOQ_BENCH_BROADCASTS")] + #[usage(long, env = "MOQ_BENCH_BROADCASTS", setting = "broadcasts")] #[serde(default, skip_serializing_if = "Option::is_none")] pub broadcasts: Option, /// Other broadcasts each connection subscribes to (C), discovered via announcements. /// /// `Option` for the same reason as [`Self::broadcasts`]. - #[usage(long, env = "MOQ_BENCH_SUBSCRIBE")] + #[usage(long, env = "MOQ_BENCH_SUBSCRIBE", setting = "subscribe")] #[serde(default, skip_serializing_if = "Option::is_none")] pub subscribe: Option, /// Frames per second per track (D). Zero leaves the track idle. - #[usage(long, env = "MOQ_BENCH_FPS", default = "30")] + #[usage(long, env = "MOQ_BENCH_FPS", default = "30", setting = "fps")] pub fps: Range, /// Bytes per frame (E). - #[usage(long, env = "MOQ_BENCH_FRAME_SIZE", default = "1200")] + #[usage(long, env = "MOQ_BENCH_FRAME_SIZE", default = "1200", setting = "frame_size")] pub frame_size: Range, /// Zeroed frames per group (F) following the JSON keyframe. May be zero. - #[usage(long, env = "MOQ_BENCH_GROUP_SIZE", default = "60")] + #[usage(long, env = "MOQ_BENCH_GROUP_SIZE", default = "60", setting = "group_size")] pub group_size: Range, /// Write machine-readable stats to this file: one JSON line of cumulative /// counters per report interval. Truncates on start. - #[usage(long, env = "MOQ_BENCH_OUTPUT")] + #[usage(long, env = "MOQ_BENCH_OUTPUT", setting = "output")] #[serde(default, skip_serializing_if = "Option::is_none")] pub output: Option, @@ -96,6 +96,11 @@ pub struct Config { #[usage(long)] #[serde(default, skip_serializing_if = "Option::is_none")] pub file: Option, + + /// Provenance from the last [`Self::parse_and_merge`]. + #[usage(skip)] + #[serde(skip)] + origins: Option, } impl Default for Config { @@ -117,6 +122,7 @@ impl Default for Config { quic: Default::default(), log: Default::default(), file: None, + origins: None, } } } @@ -151,7 +157,7 @@ impl Config { Ok(()) } - /// Merge defaults and environment, then TOML, then explicit CLI flags. + /// Merge CLI, environment, then TOML, then declared defaults. pub(crate) fn parse_and_merge(args: I) -> anyhow::Result where I: IntoIterator, @@ -167,8 +173,8 @@ impl Config { // here, because wrapping them renders an empty `anyhow` error and exits // non-zero having printed nothing. A real failure still comes back as an // error, so a caller that parses synthetic args keeps its Result. - let mut config = match Config::parse_from(&argv) { - Ok(config) => config, + let (config, cli_layer) = match Config::parse_from_with_settings(&argv) { + Ok(parsed) => parsed, Err(err) => { let answer = moq_tokio::cli::answer(Config::spec(), Config::command(), &argv, err); if answer.is_question() { @@ -177,15 +183,39 @@ impl Config { anyhow::bail!("{}", answer.message()); } }; - if let Some(file) = config.file.clone() { - let mut merged = toml::Value::try_from(&config)?; - let source = std::fs::read_to_string(file)?; - let mut file = toml::from_str::(&source)?; - normalize_client_aliases(&mut file)?; - merge_toml(&mut merged, file); - config = merged.try_into()?; - config.update_from(&argv); + let env = usage::config::EnvLayer::from_process(); + let file_path = config.file.clone(); + let file_body = file_path + .as_ref() + .map(|path| std::fs::read_to_string(path).map(|source| (path.clone(), source))) + .transpose()?; + let mut file_value = file_body + .as_ref() + .map(|(_, source)| toml::from_str::(source)) + .transpose()?; + if let Some(value) = file_value.as_mut() { + normalize_client_aliases(value)?; } + let file = file_body + .as_ref() + .zip(file_value.as_ref()) + .map(|((path, _), value)| moq_tokio::cli::FileSource { + path: std::path::Path::new(path), + value, + }); + let (mut config, resolved) = moq_tokio::cli::merge( + Settings::SETTINGS_REGISTRY, + config, + &cli_layer, + &env, + file, + |dst, src| { + dst.client.keep_parse_only(&src.client); + dst.quic.keep_parse_only(&src.quic); + }, + ) + .map_err(|err| anyhow::anyhow!("{err}"))?; + config.origins = Some(resolved); config.check_deprecated()?; // `Stats::report` feeds this into `tokio::time::interval`, which panics on a // zero period. Reject it up front with a clear message. @@ -205,6 +235,15 @@ impl Config { Ok(config) } + /// Where a dotted setting key got its value, when this config was loaded + /// through [`Self::parse_and_merge`]. + pub fn source(&self, key: &str) -> Option<&str> { + self.origins + .as_ref() + .and_then(|resolved| resolved.origin_key(key)) + .map(usage::config::Origin::describe) + } + pub fn name(&self) -> &str { &self.name } @@ -285,20 +324,53 @@ fn rename_toml_key(table: &mut toml::Table, alias: &str, canonical: &str) -> any Ok(()) } -fn merge_toml(base: &mut toml::Value, overlay: toml::Value) { - match (base, overlay) { - (toml::Value::Table(base), toml::Value::Table(overlay)) => { - for (key, value) in overlay { - match base.get_mut(&key) { - Some(base) => merge_toml(base, value), - None => { - base.insert(key, value); - } - } - } - } - (base, overlay) => *base = overlay, - } +#[allow(dead_code)] +#[derive(usage::Config)] +struct Settings { + #[usage(env = "MOQ_BENCH_NAME", cli("--name"))] + name: Option, + + #[usage(env = "MOQ_BENCH_FANOUT", cli("--fanout"))] + fanout: Option, + + #[usage(env = "MOQ_BENCH_STARTUP", cli("--startup"))] + startup: Option, + + #[usage(env = "MOQ_BENCH_DURATION", cli("--duration"))] + duration: Option, + + #[usage(env = "MOQ_BENCH_REPORT", cli("--report"))] + report: Option, + + #[usage(env = "MOQ_BENCH_CONNECTIONS", cli("--connections"))] + connections: Option, + + #[usage(env = "MOQ_BENCH_BROADCASTS", cli("--broadcasts"))] + broadcasts: Option, + + #[usage(env = "MOQ_BENCH_SUBSCRIBE", cli("--subscribe"))] + subscribe: Option, + + #[usage(env = "MOQ_BENCH_FPS", cli("--fps"))] + fps: Option, + + #[usage(env = "MOQ_BENCH_FRAME_SIZE", cli("--frame-size"))] + frame_size: Option, + + #[usage(env = "MOQ_BENCH_GROUP_SIZE", cli("--group-size"))] + group_size: Option, + + #[usage(env = "MOQ_BENCH_OUTPUT", cli("--output"))] + output: Option, + + #[usage(flatten)] + client: moq_tokio::settings::Connect, + + #[usage(flatten)] + quic: moq_tokio::settings::Quic, + + #[usage(flatten)] + log: moq_tokio::settings::Log, } #[cfg(test)] @@ -461,4 +533,44 @@ connect = "https://example.com" fn the_spec_is_named_for_the_binary() { assert_eq!(Config::spec().bin.unwrap_or(Config::spec().name), "moq-bench"); } + + #[test] + fn the_settings_registry_matches_the_cli() { + let drift = Settings::SETTINGS_REGISTRY.drift(Config::SETTINGS_BINDINGS); + assert!(drift.is_empty(), "{drift:#?}"); + } + + #[test] + fn env_overrides_toml_and_cli_overrides_env() { + let dir = std::env::temp_dir().join("moq-bench-provenance"); + std::fs::create_dir_all(&dir).unwrap(); + let path = dir.join("bench.toml"); + std::fs::write(&path, "name = \"from-file\"\nconnections = 100\n").unwrap(); + + let prev = std::env::var_os("MOQ_BENCH_NAME"); + unsafe { std::env::set_var("MOQ_BENCH_NAME", "from-env") }; + let config = Config::parse_and_merge([ + std::ffi::OsString::from("moq-bench"), + std::ffi::OsString::from("--file"), + path.clone().into(), + ]) + .unwrap(); + assert_eq!(config.name(), "from-env"); + assert!(config.source("name").unwrap().contains("MOQ_BENCH_NAME")); + + let config = Config::parse_and_merge([ + std::ffi::OsString::from("moq-bench"), + std::ffi::OsString::from("--file"), + path.into(), + std::ffi::OsString::from("--name"), + std::ffi::OsString::from("from-cli"), + ]) + .unwrap(); + assert_eq!(config.name(), "from-cli"); + assert!(config.source("name").unwrap().contains("--name")); + match prev { + Some(value) => unsafe { std::env::set_var("MOQ_BENCH_NAME", value) }, + None => unsafe { std::env::remove_var("MOQ_BENCH_NAME") }, + } + } } diff --git a/rs/moq-boy/Cargo.toml b/rs/moq-boy/Cargo.toml index ffb3462bb43..b04f1e81264 100644 --- a/rs/moq-boy/Cargo.toml +++ b/rs/moq-boy/Cargo.toml @@ -33,4 +33,4 @@ moq-video = { workspace = true, features = ["nvidia", "vaapi"] } serde = { workspace = true } tokio = { workspace = true, features = ["full"] } tracing = { workspace = true } -usage = { workspace = true, features = ["completions"] } +usage = { workspace = true, features = ["completions", "config"] } diff --git a/rs/moq-boy/src/main.rs b/rs/moq-boy/src/main.rs index 8fab1594c8c..47e893a3feb 100644 --- a/rs/moq-boy/src/main.rs +++ b/rs/moq-boy/src/main.rs @@ -45,7 +45,7 @@ mod video; #[derive(usage::Cli, Clone)] #[usage(unknown_flags = "error", args_override_self = false)] #[usage(name = "moq-boy")] -#[usage(completion)] +#[usage(completion, settings)] pub struct Config { /// Path to the Game Boy ROM file. #[usage(long, value_hint = usage::ValueHint::FilePath, extensions("gb", "gbc"))] diff --git a/rs/moq-cli/Cargo.toml b/rs/moq-cli/Cargo.toml index fe348ad89e7..cbc01faf523 100644 --- a/rs/moq-cli/Cargo.toml +++ b/rs/moq-cli/Cargo.toml @@ -109,7 +109,7 @@ tokio = { workspace = true, features = ["full"] } tower-http = { workspace = true } tracing = { workspace = true } url = { workspace = true } -usage = { workspace = true, features = ["completions"] } +usage = { workspace = true, features = ["completions", "config"] } winit = { version = "0.30.13", optional = true } [target.'cfg(unix)'.dependencies] diff --git a/rs/moq-cli/src/args.rs b/rs/moq-cli/src/args.rs index ab5f97351cf..51b2b1d81a6 100644 --- a/rs/moq-cli/src/args.rs +++ b/rs/moq-cli/src/args.rs @@ -43,7 +43,7 @@ use crate::subscribe::{CatalogFormatArg, SubscribeFormat}; #[derive(usage::Cli, Clone)] #[usage(unknown_flags = "error", args_override_self = false)] #[usage(name = "moq", version = env!("VERSION"))] -#[usage(completion)] +#[usage(completion, settings)] #[usage(after_help = "Separate additional import/export stages with `--`; they share one \ connection and one Origin. Every `--` starts a stage, so it is not an \ end-of-options marker: write a path starting with `-` as `./-name`.")] @@ -69,7 +69,7 @@ pub struct Cli { #[derive(usage::Cli, Clone)] #[usage(unknown_flags = "error", args_override_self = false)] #[usage(name = "moq")] -#[usage(completion)] +#[usage(completion, settings)] pub struct Stage { /// The verb and endpoint. #[usage(subcommand)] diff --git a/rs/moq-relay/CLAUDE.md b/rs/moq-relay/CLAUDE.md index c99c1ed6609..c09198a143c 100644 --- a/rs/moq-relay/CLAUDE.md +++ b/rs/moq-relay/CLAUDE.md @@ -2,9 +2,9 @@ The clusterable, media-agnostic relay. It routes by broadcast path and never ins # Config -Config structs are clap `Parser`s that also load from TOML, with the `moq-native` configs flattened in. +Config structs are Usage `Args` that also load from TOML, with the `moq-tokio` configs flattened in. -- Every `#[arg]` field on a TOML-loadable config must be `Option`, never a bare `bool`/`String`/number. The TOML -> CLI merge re-applies clap defaults, so a bare field silently clobbers the TOML value. Add a `cli_does_not_clobber_toml_*` test in `config.rs` for every new flag. +- Merge is CLI > env > file > defaults, declared in `moq_tokio::cli::merge`. Presence comes from the source (`CliLayer` / `EnvLayer` / the TOML document), never from whether a standing value looks empty. A new merged flag needs `setting = "dotted.key"` on the `Args` field and a matching `usage::Config` field in `settings.rs`; `Registry::drift` is the test they stay in step. - Relay behavior and config changes update `doc/bin/relay/`. Stats track names and frame shapes are documented in `doc/bin/relay/config.md`. # Testing diff --git a/rs/moq-relay/Cargo.toml b/rs/moq-relay/Cargo.toml index 065cfddfc4d..632b3af4b1a 100644 --- a/rs/moq-relay/Cargo.toml +++ b/rs/moq-relay/Cargo.toml @@ -92,7 +92,7 @@ tower-http = { workspace = true } tower-service = "0.3" tracing = { workspace = true } url = { workspace = true, features = ["serde"] } -usage = { workspace = true, features = ["completions"] } +usage = { workspace = true, features = ["completions", "config"] } web-transport-trait = { workspace = true } [target.'cfg(target_os = "linux")'.dependencies] diff --git a/rs/moq-relay/src/auth.rs b/rs/moq-relay/src/auth.rs index ab5631539d4..93670bf2ae3 100644 --- a/rs/moq-relay/src/auth.rs +++ b/rs/moq-relay/src/auth.rs @@ -317,6 +317,7 @@ pub struct AuthTls { name = "auth-tls-root", long = "auth-tls-root", env = "MOQ_AUTH_TLS_ROOT", + setting = "auth.tls.root", hide = true )] #[serde_as(as = "OneOrMany<_>")] @@ -327,12 +328,19 @@ pub struct AuthTls { name = "auth-tls-cert", long = "auth-tls-cert", env = "MOQ_AUTH_TLS_CERT", + setting = "auth.tls.cert", hide = true )] pub cert: Option, #[serde(skip_serializing_if = "Option::is_none")] - #[usage(name = "auth-tls-key", long = "auth-tls-key", env = "MOQ_AUTH_TLS_KEY", hide = true)] + #[usage( + name = "auth-tls-key", + long = "auth-tls-key", + env = "MOQ_AUTH_TLS_KEY", + setting = "auth.tls.key", + hide = true + )] pub key: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -340,6 +348,7 @@ pub struct AuthTls { name = "auth-tls-disable-verify", long = "auth-tls-disable-verify", env = "MOQ_AUTH_TLS_DISABLE_VERIFY", + setting = "auth.tls.disable_verify", hide = true, default_missing = "true", num_args = 0..=1, @@ -348,6 +357,13 @@ pub struct AuthTls { pub disable_verify: Option, } +impl AuthConfig { + /// Hidden parse-only fields a TOML round-trip would drop. + pub fn keep_parse_only(&mut self, from: &Self) { + self.client_tls = from.client_tls.clone(); + } +} + impl AuthTls { /// True when any deprecated `--auth-tls-*` override is configured, in which /// case it takes precedence over the shared `--connect-tls-*` identity. @@ -382,7 +398,7 @@ impl AuthTls { pub struct AuthConfig { /// A single JWK key file for authentication. /// No `kid` header is required in JWTs. - #[usage(long = "auth-key", env = "MOQ_AUTH_KEY")] + #[usage(long = "auth-key", env = "MOQ_AUTH_KEY", setting = "auth.key")] pub key: Option, /// A directory path or base URL containing JWK files named by key ID. @@ -393,7 +409,7 @@ pub struct AuthConfig { /// DEPRECATED (URL form): prefer the unified `--auth-api`, which resolves the /// key in the same call as public access and the alias. The file-directory /// form remains supported for standalone relays. - #[usage(long = "auth-key-dir", env = "MOQ_AUTH_KEY_DIR")] + #[usage(long = "auth-key-dir", env = "MOQ_AUTH_KEY_DIR", setting = "auth.key_dir")] pub key_dir: Option, /// Deprecated `--auth-tls-*` overrides; see [`AuthTls`]. @@ -413,7 +429,7 @@ pub struct AuthConfig { /// CLI: `--auth-public ` sets both subscribe and publish for the prefix. /// TOML: Accepts a string, array, or table `{ subscribe = ..., publish = ... }`. /// Any value starting with `http://` or `https://` is treated as a URL endpoint. - #[usage(long = "auth-public", env = "MOQ_AUTH_PUBLIC")] + #[usage(long = "auth-public", env = "MOQ_AUTH_PUBLIC", setting = "auth.public")] #[serde(default, deserialize_with = "PublicConfig::deserialize_option")] pub public: Option, @@ -421,7 +437,11 @@ pub struct AuthConfig { /// /// CLI-only shorthand: `--auth-public-subscribe ` sets subscribe-only access. /// For TOML, use `[auth.public]` with separate `subscribe`/`publish` fields instead. - #[usage(long = "auth-public-subscribe", env = "MOQ_AUTH_PUBLIC_SUBSCRIBE")] + #[usage( + long = "auth-public-subscribe", + env = "MOQ_AUTH_PUBLIC_SUBSCRIBE", + setting = "auth.public_subscribe" + )] #[serde(skip)] pub public_subscribe: Option, @@ -429,7 +449,11 @@ pub struct AuthConfig { /// /// CLI-only shorthand: `--auth-public-publish ` sets publish-only access. /// For TOML, use `[auth.public]` with separate `subscribe`/`publish` fields instead. - #[usage(long = "auth-public-publish", env = "MOQ_AUTH_PUBLIC_PUBLISH")] + #[usage( + long = "auth-public-publish", + env = "MOQ_AUTH_PUBLIC_PUBLISH", + setting = "auth.public_publish" + )] #[serde(skip)] pub public_publish: Option, @@ -439,7 +463,7 @@ pub struct AuthConfig { /// /// DEPRECATED: prefer the unified `--auth-api`, which returns public access in /// the same call as the key and alias. - #[usage(long = "auth-public-api", env = "MOQ_AUTH_PUBLIC_API")] + #[usage(long = "auth-public-api", env = "MOQ_AUTH_PUBLIC_API", setting = "auth.public_api")] #[serde(skip)] pub public_api: Option, @@ -466,7 +490,7 @@ pub struct AuthConfig { /// path `/usw/customer/foo`). /// /// In config files, accepts either a single string or a TOML array. - #[usage(long = "auth-domain", env = "MOQ_AUTH_DOMAIN")] + #[usage(long = "auth-domain", env = "MOQ_AUTH_DOMAIN", setting = "auth.domains")] #[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde_as(as = "OneOrMany<_>")] pub domains: Vec, @@ -511,7 +535,7 @@ pub struct AuthConfig { /// /// Example: `https://api.moq.dev/cluster/auth` (called as /// `?root=demo/room&kid=abc&mtls=true`). - #[usage(long = "auth-api", env = "MOQ_AUTH_API")] + #[usage(long = "auth-api", env = "MOQ_AUTH_API", setting = "auth.auth_api")] #[serde(default, skip_serializing_if = "Option::is_none")] pub auth_api: Option, @@ -529,13 +553,13 @@ pub struct AuthConfig { /// in either mode. /// /// `Option` so a TOML value survives the CLI re-parse. - #[usage(long = "auth-api-mode", env = "MOQ_AUTH_API_MODE")] + #[usage(long = "auth-api-mode", env = "MOQ_AUTH_API_MODE", setting = "auth.api_mode")] #[serde(default, skip_serializing_if = "Option::is_none")] pub api_mode: Option, /// Billing tier label for mTLS peers when the auth API doesn't return one /// (or no `--auth-api` is configured). Defaults to the unprefixed tier. - #[usage(long = "auth-mtls-tier", env = "MOQ_AUTH_MTLS_TIER")] + #[usage(long = "auth-mtls-tier", env = "MOQ_AUTH_MTLS_TIER", setting = "auth.mtls_tier")] #[serde(default, skip_serializing_if = "Option::is_none")] pub mtls_tier: Option, } diff --git a/rs/moq-relay/src/cache.rs b/rs/moq-relay/src/cache.rs index cb887b9ce12..d1e83b5835a 100644 --- a/rs/moq-relay/src/cache.rs +++ b/rs/moq-relay/src/cache.rs @@ -31,7 +31,7 @@ pub struct CacheConfig { /// A target that usage converges toward as tracks write, not a hard limit, and it /// counts cached group bytes (payload plus a fixed cost per group), not process /// RSS; leave some slack below physical memory or combine with `headroom`. - #[usage(long = "cache-capacity", env = "MOQ_CACHE_CAPACITY")] + #[usage(long = "cache-capacity", env = "MOQ_CACHE_CAPACITY", setting = "cache.capacity")] pub capacity: Option, /// Keep at least this much system memory available, e.g. "2GiB" or "10%". @@ -40,7 +40,7 @@ pub struct CacheConfig { /// so the cache soaks up idle memory but is the first thing reclaimed when /// the rest of the system needs it. Combine with `capacity` to also cap the /// absolute size. - #[usage(long = "cache-headroom", env = "MOQ_CACHE_HEADROOM")] + #[usage(long = "cache-headroom", env = "MOQ_CACHE_HEADROOM", setting = "cache.headroom")] pub headroom: Option, /// Maximum time a non-latest cached group is retained, e.g. "30s" or "500ms". @@ -60,7 +60,7 @@ pub struct CacheConfig { /// cadence. The `capacity` budget is the one that depends on writes: a /// publisher that stops writing pays none of it down, so under memory pressure /// it is repaid by the tracks that are still writing. - #[usage(long = "cache-duration", env = "MOQ_CACHE_DURATION")] + #[usage(long = "cache-duration", env = "MOQ_CACHE_DURATION", setting = "cache.duration")] pub duration: Option, } diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index 1d3ce8152cc..42244d14c99 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -394,7 +394,12 @@ pub struct ClusterConfig { /// (the wire varint limit); an out-of-range value errors at startup. Keep it /// below 2^53 for compatibility with older `@moq/lite` JS clients, which /// decode hop ids as a `u53` and reject anything larger. - #[usage(name = "cluster-id", long = "cluster-id", env = "MOQ_CLUSTER_ID")] + #[usage( + name = "cluster-id", + long = "cluster-id", + env = "MOQ_CLUSTER_ID", + setting = "cluster.id" + )] pub id: Option, /// Connect to one or more other cluster nodes. Each peer is a full URL, e.g. @@ -413,7 +418,8 @@ pub struct ClusterConfig { name = "cluster-connect", long = "cluster-connect", env = "MOQ_CLUSTER_CONNECT", - delimiter = ',' + delimiter = ',', + setting = "cluster.connect" )] #[serde_as(as = "serde_with::OneOrMany<_>")] pub connect: Vec, @@ -432,7 +438,8 @@ pub struct ClusterConfig { #[usage( name = "cluster-connect-api", long = "cluster-connect-api", - env = "MOQ_CLUSTER_CONNECT_API" + env = "MOQ_CLUSTER_CONNECT_API", + setting = "cluster.connect_api" )] pub connect_api: Option, @@ -440,7 +447,12 @@ pub struct ClusterConfig { /// [`Self::connect_api`] as a `?node=` query param so the endpoint can return /// this node's peers, and advertised to other relays when [`Self::mesh`] gossip /// is enabled. On its own it neither opens nor accepts a connection. - #[usage(name = "cluster-node", long = "cluster-node", env = "MOQ_CLUSTER_NODE")] + #[usage( + name = "cluster-node", + long = "cluster-node", + env = "MOQ_CLUSTER_NODE", + setting = "cluster.node" + )] pub node: Option, /// Enable gossip discovery: advertise this relay's [`Self::node`] URL on the @@ -456,6 +468,7 @@ pub struct ClusterConfig { name = "cluster-mesh", long = "cluster-mesh", env = "MOQ_CLUSTER_MESH", + setting = "cluster.mesh", default_missing = "true", num_args = 0..=1, require_equals = true, @@ -474,12 +487,22 @@ pub struct ClusterConfig { /// any peer whose URL has no inline token). An inline `?jwt=` can provide a /// per-peer credential for static or `connect_api` peers. Gossip should use /// this shared token or mTLS because the advertised node URL is public. - #[usage(name = "cluster-token", long = "cluster-token", env = "MOQ_CLUSTER_TOKEN")] + #[usage( + name = "cluster-token", + long = "cluster-token", + env = "MOQ_CLUSTER_TOKEN", + setting = "cluster.token" + )] pub token: Option, /// Billing tier label that cluster-peer (relay-to-relay) traffic records /// stats under. Defaults to the unprefixed tier. - #[usage(name = "cluster-tier", long = "cluster-tier", env = "MOQ_CLUSTER_TIER")] + #[usage( + name = "cluster-tier", + long = "cluster-tier", + env = "MOQ_CLUSTER_TIER", + setting = "cluster.tier" + )] pub tier: Option, // Accepted so existing configs keep parsing (`deny_unknown_fields`), but // ignored: a broadcast now closes as soon as its last publisher is lost. @@ -489,6 +512,7 @@ pub struct ClusterConfig { name = "cluster-linger", long = "cluster-linger", env = "MOQ_CLUSTER_LINGER", + setting = "cluster.linger", hide = true )] pub linger: Option, @@ -510,21 +534,14 @@ pub struct LanConfig { /// Enable mDNS discovery. Requires [`ClusterConfig::node`], so there is an /// address to advertise, and [`Self::secret`]. Boolean flag: pass /// `--cluster-lan` (or `=true` / `=false`). - /// `Option` rather than a materialized default: Usage reads a standing `false` - /// as an empty boolean, so `update_from` would refill it from the environment - /// (or a declared default) over whatever the TOML file said. An `Option` is - /// empty only when nothing set it. A bare `Vec` has the same hazard, since - /// an empty list also reads as absent; see moq-dev/moq#3051. #[usage( name = "cluster-lan", long = "cluster-lan", env = "MOQ_CLUSTER_LAN", - default_missing = "true", - num_args = 0..=1, - require_equals = true, + setting = "cluster.lan.enabled", + bool_value )] - #[serde(skip_serializing_if = "Option::is_none")] - pub enabled: Option, + pub enabled: bool, /// The shared key admitting a peer to the LAN mesh, as 64 hexadecimal /// characters or a path to a file containing them. Required by @@ -539,7 +556,8 @@ pub struct LanConfig { name = "cluster-lan-secret", long = "cluster-lan-secret", env = "MOQ_CLUSTER_LAN_SECRET", - value_name = "HEX_OR_PATH" + value_name = "HEX_OR_PATH", + setting = "cluster.lan.secret" )] pub secret: Option, } @@ -801,7 +819,7 @@ impl Cluster { /// Whether `--cluster-lan` asked this relay to discover peers over mDNS. fn lan(&self) -> bool { #[cfg(feature = "cluster-lan")] - return self.config.lan.enabled.unwrap_or(false); + return self.config.lan.enabled; #[cfg(not(feature = "cluster-lan"))] false } @@ -1637,7 +1655,7 @@ mod tests { #[tokio::test] async fn stats_publishing_outlives_the_producer_handle() { let config = crate::StatsConfig { - enabled: Some(true), + enabled: true, node: Some("test".to_string()), ..Default::default() }; @@ -2400,7 +2418,7 @@ mod tests { let args = vec![std::ffi::OsString::from("moq-relay"), std::ffi::OsString::from(&path)]; let config = Config::parse_and_merge(args).expect("config load"); - assert_eq!(config.cluster.lan.enabled, Some(true)); + assert!(config.cluster.lan.enabled); assert_eq!(config.cluster.lan.secret.as_deref(), Some("cluster.key")); assert_eq!(config.cluster.node.as_deref(), Some("https://relay.example.com")); } @@ -2426,7 +2444,7 @@ mod tests { ]; let config = Config::parse_and_merge(args).expect("config load"); assert_eq!(config.cluster.lan.secret.as_deref(), Some("from-cli.key")); - assert_eq!(config.cluster.lan.enabled, Some(true), "the untouched key survives"); + assert!(config.cluster.lan.enabled, "the untouched key survives"); } /// The LAN needs an address to advertise, like gossip does. @@ -2435,7 +2453,7 @@ mod tests { async fn lan_without_node_errors() { let config = ClusterConfig { lan: LanConfig { - enabled: Some(true), + enabled: true, ..Default::default() }, ..Default::default() @@ -2460,7 +2478,7 @@ mod tests { let config = ClusterConfig { node: Some("https://us-west.example.com".to_string()), lan: LanConfig { - enabled: Some(true), + enabled: true, ..Default::default() }, ..Default::default() diff --git a/rs/moq-relay/src/config.rs b/rs/moq-relay/src/config.rs index 7c084779c5c..8017489e0b1 100644 --- a/rs/moq-relay/src/config.rs +++ b/rs/moq-relay/src/config.rs @@ -2,9 +2,10 @@ use serde::{Deserialize, Serialize}; use crate::{AuthConfig, CacheConfig, ClusterConfig, InternalConfig, StatsConfig, WebConfig}; -/// Top-level relay configuration, loadable from CLI arguments, environment -/// variables, or a TOML file. -/// Top-level relay configuration, as a COMPOSABLE args group. +/// Top-level relay configuration, as a composable args group. +/// +/// Loadable from CLI arguments, environment variables, or a TOML file. +/// Precedence is CLI > env > file > defaults. /// /// `usage::Args` rather than `usage::Cli` on purpose: the program-level parts (a /// name, a version, the completion command) belong to whichever binary owns the @@ -89,7 +90,8 @@ pub struct Config { name = "drain-timeout", long = "drain-timeout", env = "MOQ_DRAIN_TIMEOUT", - default = "10s" + default = "10s", + setting = "drain_timeout" )] pub drain_timeout: moq_tokio::Duration, @@ -98,6 +100,11 @@ pub struct Config { #[usage(value_hint = usage::ValueHint::FilePath, extensions("toml"))] pub file: Option, + /// Provenance from the last load, skipped in TOML. + #[usage(skip)] + #[serde(skip)] + origins: Option, + /// Iroh specific configuration, used for both a client and server. #[usage(flatten)] #[serde(default)] @@ -121,6 +128,7 @@ impl Default for Config { internal: Default::default(), drain_timeout: crate::DEFAULT_DRAIN_TIMEOUT.into(), file: None, + origins: None, #[cfg(feature = "iroh")] iroh: Default::default(), } @@ -143,7 +151,7 @@ impl Default for Config { #[derive(usage::Cli, Clone, Debug)] #[usage(unknown_flags = "error", args_override_self = false)] #[usage(name = "moq-relay", version = env!("VERSION"))] -#[usage(completion)] +#[usage(completion, settings)] struct Cli { #[usage(flatten)] config: Config, @@ -183,17 +191,12 @@ impl Config { /// Pure version of [`Self::load`] without logger init, so tests can drive /// it with synthetic args and inspect the result. /// - /// Merge defaults and environment, then TOML, then explicit CLI flags. - /// - /// # Pitfall (see `rs/CLAUDE.md` and `tests` below) + /// Merge CLI, environment, then TOML, then declared defaults. /// - /// The final `update_from` re-parses `argv` over the merged config. Usage - /// fills a declared default only where the standing value is still empty, - /// and a bare `bool` reading `false` is what it counts as empty: a field - /// with `default = "true"` is therefore refilled over whatever the TOML - /// said. Type any new flag that should be TOML-overridable as - /// `Option` and resolve the default in code. Every other shape is - /// safe, because a plain value always reads as present. + /// Precedence is CLI > env > file > defaults, declared in + /// [`moq_tokio::cli::merge`]. Presence comes from what the parser and the + /// environment actually supplied, so a file that sets a list to empty or a + /// bool to false survives. pub(crate) fn parse_and_merge(args: I) -> anyhow::Result where I: IntoIterator, @@ -209,8 +212,8 @@ impl Config { // here, because wrapping them renders an empty `anyhow` error and exits // non-zero having printed nothing. A real failure still comes back as an // error, so a caller that parses synthetic args keeps its Result. - let mut cli = match Cli::parse_from(&argv) { - Ok(cli) => cli, + let (cli, cli_layer) = match Cli::parse_from_with_settings(&argv) { + Ok(parsed) => parsed, Err(err) => { let answer = moq_tokio::cli::answer(Cli::spec(), Cli::command(), &argv, err); if answer.is_question() { @@ -219,17 +222,51 @@ impl Config { anyhow::bail!("{}", answer.message()); } }; - if let Some(file) = cli.config.file.clone() { - let mut merged = toml::Value::try_from(&cli.config)?; - let source = std::fs::read_to_string(file)?; - let mut file = toml::from_str::(&source)?; - normalize_toml_aliases(&mut file)?; - merge_toml(&mut merged, file); - cli.config = merged.try_into()?; - // Re-applied over the merged config so explicit flags still beat the TOML. - cli.update_from(&argv); + let env = usage::config::EnvLayer::from_process(); + let file_path = cli.config.file.clone(); + let file_body = file_path + .as_ref() + .map(|path| std::fs::read_to_string(path).map(|source| (path.clone(), source))) + .transpose()?; + let mut file_value = file_body + .as_ref() + .map(|(_, source)| toml::from_str::(source)) + .transpose()?; + if let Some(value) = file_value.as_mut() { + normalize_toml_aliases(value)?; } - Ok(cli.config) + let file = file_body + .as_ref() + .zip(file_value.as_ref()) + .map(|((path, _), value)| moq_tokio::cli::FileSource { + path: std::path::Path::new(path), + value, + }); + let (mut config, resolved) = moq_tokio::cli::merge( + crate::settings::Settings::SETTINGS_REGISTRY, + cli.config, + &cli_layer, + &env, + file, + |dst, src| { + dst.listen.keep_parse_only(&src.listen); + dst.connect.keep_parse_only(&src.connect); + dst.quic.keep_parse_only(&src.quic); + dst.auth.keep_parse_only(&src.auth); + }, + ) + .map_err(|err| anyhow::anyhow!("{err}"))?; + config.origins = Some(resolved); + Ok(config) + } + + /// Where a dotted setting key got its value, when this config was loaded + /// from the command line, environment, and an optional TOML file. + pub fn source(&self, key: &str) -> Option<&str> { + self.origins + .as_ref() + .and_then(|resolved| resolved.origin_key(key)) + .map(usage::config::Origin::describe) } } @@ -265,22 +302,6 @@ fn rename_toml_key(table: &mut toml::Table, alias: &str, canonical: &str) -> any Ok(()) } -fn merge_toml(base: &mut toml::Value, overlay: toml::Value) { - match (base, overlay) { - (toml::Value::Table(base), toml::Value::Table(overlay)) => { - for (key, value) in overlay { - match base.get_mut(&key) { - Some(base) => merge_toml(base, value), - None => { - base.insert(key, value); - } - } - } - } - (base, overlay) => *base = overlay, - } -} - impl Config { /// Refuse a config parsed from released spellings, then apply the relay's own /// defaults. @@ -431,9 +452,8 @@ depth = 2 let args = vec![std::ffi::OsString::from("moq-relay"), std::ffi::OsString::from(&path)]; let config = Config::parse_and_merge(args).expect("config load"); - assert_eq!( + assert!( config.stats.enabled, - Some(true), "TOML's stats.enabled=true must not be clobbered by CLI defaults" ); assert_eq!(config.stats.interval, 5); @@ -473,28 +493,17 @@ ws = false let config = Config::parse_and_merge(args).expect("config load"); assert_eq!(config.runtime.workers, Some(8)); - assert_eq!( - config.runtime.pin, - Some(false), - "TOML's runtime.pin=false must survive the CLI re-parse \ - (a bare bool with a `true` default reads as empty and is refilled; \ - type it as Option)" - ); - assert_eq!( - config.runtime.io_uring, - Some(false), - "TOML's runtime.io_uring=false must survive the CLI re-parse" - ); - assert_eq!( - config.web.ws, - Some(false), - "TOML's web.ws=false must survive the CLI re-parse" + assert!(!config.runtime.pin, "TOML's runtime.pin=false must survive the merge"); + assert!( + !config.runtime.io_uring, + "TOML's runtime.io_uring=false must survive the merge" ); + assert!(!config.web.ws, "TOML's web.ws=false must survive the merge"); #[cfg(feature = "websocket")] assert_eq!( config.connect.websocket.enabled, Some(false), - "TOML's connect.websocket.enabled=false must survive the CLI re-parse" + "TOML's connect.websocket.enabled=false must survive the merge" ); let args = [ @@ -506,8 +515,8 @@ ws = false std::ffi::OsString::from("--connect-websocket-enabled=true"), ]; let config = Config::parse_and_merge(args).expect("config load"); - assert_eq!(config.runtime.pin, Some(true)); - assert_eq!(config.web.ws, Some(true)); + assert!(config.runtime.pin); + assert!(config.web.ws); #[cfg(feature = "websocket")] assert_eq!(config.connect.websocket.enabled, Some(true)); } @@ -775,7 +784,7 @@ key = ["cdn.key", "moq-pro.key"] std::ffi::OsString::from("--stats-enabled=false"), ]; let config = Config::parse_and_merge(args).expect("config load"); - assert_eq!(config.stats.enabled, Some(false)); + assert!(!config.stats.enabled); } /// An auth API loaded from TOML survives when the CLI omits it. @@ -1017,6 +1026,7 @@ uid = [1001] #[derive(usage::Cli, Clone, Debug)] #[usage(unknown_flags = "error", args_override_self = false)] #[usage(name = "embedder", version = "0")] + #[usage(settings)] struct Embedder { #[usage(flatten)] relay: Config, @@ -1082,50 +1092,124 @@ uid = [1001] assert_eq!(Cli::spec().bin.unwrap_or(Cli::spec().name), "moq-relay"); } - /// A TOML boolean survives an environment variable that says otherwise. - /// - /// Usage reads a standing `false` as an empty boolean, so a bare `bool` is - /// refilled from the environment during the CLI re-parse and the file loses. - /// Every merged boolean is therefore `Option`. A bare `Vec` is the - /// other unsafe shape, tracked in moq-dev/moq#3051; scalars are safe. + /// The two declarations of every merged flag stay in step. + #[test] + fn the_settings_registry_matches_the_cli() { + let drift = crate::settings::Settings::SETTINGS_REGISTRY.drift(Cli::SETTINGS_BINDINGS); + assert!(drift.is_empty(), "{drift:#?}"); + } + + /// Presence comes from the source, never from whether a standing value looks empty. #[test] - fn env_does_not_clobber_toml_booleans() { - let _env = EnvGuard::clear(&["MOQ_STATS_ENABLED", "MOQ_CLUSTER_LAN"]); - // SAFETY: EnvGuard serializes env mutation across these tests. - unsafe { - std::env::set_var("MOQ_STATS_ENABLED", "true"); - std::env::set_var("MOQ_CLUSTER_LAN", "true"); + fn provenance_merge_table() { + struct Case { + name: &'static str, + toml: &'static str, + env: &'static [(&'static str, &'static str)], + cli: &'static [&'static str], + key: &'static str, + check: fn(&Config), + source: &'static str, } - // `[cluster.lan]` is only a key when the feature that reads it is on, and - // `deny_unknown_fields` refuses it otherwise. - #[cfg(feature = "cluster-lan")] - let toml = "[stats]\nenabled = false\n\n[cluster.lan]\nenabled = false\n"; - #[cfg(not(feature = "cluster-lan"))] - let toml = "[stats]\nenabled = false\n"; - let dir = std::env::temp_dir().join("moq-relay-config-test"); + let dir = std::env::temp_dir().join("moq-relay-provenance"); std::fs::create_dir_all(&dir).unwrap(); - let path = dir.join("env-vs-toml-bools.toml"); - std::fs::write(&path, toml).unwrap(); - let args = vec![std::ffi::OsString::from("moq-relay"), std::ffi::OsString::from(&path)]; - let config = Config::parse_and_merge(args).expect("config load"); + let cases = [ + Case { + name: "empty-list-from-file", + toml: "[listen]\nversion = []\n", + env: &[], + cli: &[], + key: "listen.version", + check: |config| assert!(config.listen.version.is_empty(), "file empty list must survive"), + source: "version", + }, + Case { + name: "false-bool-from-file", + toml: "[stats]\nenabled = false\n", + env: &[], + cli: &[], + key: "stats.enabled", + check: |config| assert!(!config.stats.enabled), + source: "enabled", + }, + Case { + name: "declared-default-true-false-from-file", + toml: "[runtime]\npin = false\n", + env: &[], + cli: &[], + key: "runtime.pin", + check: |config| assert!(!config.runtime.pin, "file false must beat a declared true default"), + source: "pin", + }, + Case { + name: "optional-with-default-from-file", + toml: "[stats]\nprefix = \".custom\"\n", + env: &[], + cli: &[], + key: "stats.prefix", + check: |config| assert_eq!(config.stats.prefix, ".custom"), + source: "prefix", + }, + Case { + name: "nested-flatten-from-file", + toml: "[listen.tls]\ngenerate = [\"localhost\"]\n", + env: &[], + cli: &[], + key: "listen.tls.generate", + check: |config| { + assert_eq!(config.listen.tls.generate, vec!["localhost".to_string()]); + }, + source: "generate", + }, + Case { + name: "env-overrides-file", + toml: "[stats]\nenabled = false\n", + env: &[("MOQ_STATS_ENABLED", "true")], + cli: &[], + key: "stats.enabled", + check: |config| assert!(config.stats.enabled), + source: "MOQ_STATS_ENABLED", + }, + Case { + name: "cli-overrides-env-and-file", + toml: "[stats]\nenabled = true\n", + env: &[("MOQ_STATS_ENABLED", "true")], + cli: &["--stats-enabled=false"], + key: "stats.enabled", + check: |config| assert!(!config.stats.enabled), + source: "--stats-enabled", + }, + ]; - unsafe { - std::env::remove_var("MOQ_STATS_ENABLED"); - std::env::remove_var("MOQ_CLUSTER_LAN"); + for case in cases { + let _guard = EnvGuard::clear(&[ + "MOQ_STATS_ENABLED", + "MOQ_STATS_PREFIX", + "MOQ_LISTEN_VERSION", + "MOQ_LISTEN_TLS_GENERATE", + "MOQ_RUNTIME_PIN", + ]); + for (key, value) in case.env { + // SAFETY: EnvGuard serializes env mutation across these tests. + unsafe { std::env::set_var(key, value) }; + } + let path = dir.join(format!("{}.toml", case.name)); + std::fs::write(&path, case.toml).unwrap(); + let mut args = vec![std::ffi::OsString::from("moq-relay"), std::ffi::OsString::from(&path)]; + args.extend(case.cli.iter().map(std::ffi::OsString::from)); + let config = Config::parse_and_merge(args).unwrap_or_else(|err| panic!("{}: {err}", case.name)); + (case.check)(&config); + let source = config + .source(case.key) + .unwrap_or_else(|| panic!("{}: missing origin", case.name)); + assert!( + source.contains(case.source), + "{}: origin {source:?} should name {:?}", + case.name, + case.source + ); } - - assert_eq!( - config.stats.enabled, - Some(false), - "TOML stats.enabled=false must beat MOQ_STATS_ENABLED=true" - ); - #[cfg(feature = "cluster-lan")] - assert_eq!( - config.cluster.lan.enabled, - Some(false), - "TOML cluster.lan.enabled=false must beat MOQ_CLUSTER_LAN=true" - ); } } diff --git a/rs/moq-relay/src/internal.rs b/rs/moq-relay/src/internal.rs index 7408a9e832b..14f49f53314 100644 --- a/rs/moq-relay/src/internal.rs +++ b/rs/moq-relay/src/internal.rs @@ -68,7 +68,12 @@ pub struct InternalConfig { /// intentional: on loopback there's nothing to encrypt, and a private /// overlay (e.g. a mesh VPN) already provides transport encryption and peer /// identity. Unset (the default) disables the listener entirely. - #[usage(name = "internal-listen", long = "internal-listen", env = "MOQ_INTERNAL_LISTEN")] + #[usage( + name = "internal-listen", + long = "internal-listen", + env = "MOQ_INTERNAL_LISTEN", + setting = "internal.listen" + )] pub listen: Option, } diff --git a/rs/moq-relay/src/lib.rs b/rs/moq-relay/src/lib.rs index 3fa74cb89cb..52912c87d45 100644 --- a/rs/moq-relay/src/lib.rs +++ b/rs/moq-relay/src/lib.rs @@ -21,6 +21,7 @@ mod listener; mod nodes; mod relay; mod runtime; +mod settings; mod shutdown; mod stats; #[cfg(test)] diff --git a/rs/moq-relay/src/runtime.rs b/rs/moq-relay/src/runtime.rs index 7b23882a52f..239b7610f58 100644 --- a/rs/moq-relay/src/runtime.rs +++ b/rs/moq-relay/src/runtime.rs @@ -11,7 +11,6 @@ use serde::{Deserialize, Serialize}; #[usage(unknown_flags = "error", args_override_self = false)] #[serde(default, deny_unknown_fields)] #[non_exhaustive] -#[derive(Default)] pub struct RuntimeConfig { /// Serve QUIC from this many single-threaded workers instead of the shared /// runtime, each pinned to a core with its own socket on the listen address. @@ -21,7 +20,7 @@ pub struct RuntimeConfig { /// Linux-only, and mutually exclusive with `--listen-tls-generate`, since /// each worker would otherwise generate and serve a certificate of its own. /// Unset (the default) keeps QUIC on the shared runtime. - #[usage(long = "runtime-workers", env = "MOQ_RUNTIME_WORKERS")] + #[usage(long = "runtime-workers", env = "MOQ_RUNTIME_WORKERS", setting = "runtime.workers")] pub workers: Option, /// Pin each worker to a CPU core, defaulting to on. @@ -32,18 +31,14 @@ pub struct RuntimeConfig { /// scheduler migrating a busy worker, which should matter on a multi-socket /// or NUMA machine, and costs nothing elsewhere. Turn it off when sharing /// the machine with something that manages CPU placement itself. - /// - /// `Option` rather than a Usage `default`, which a config file could not - /// override: Usage reads a standing `false` as an empty boolean, so the - /// re-parse over the CLI args would refill it with the declared `true`. #[usage( long = "runtime-pin", env = "MOQ_RUNTIME_PIN", - default_missing = "true", - num_args = 0..=1, - require_equals = true, + setting = "runtime.pin", + default = "true", + bool_value )] - pub pin: Option, + pub pin: bool, /// Drive the QUIC workers with io_uring instead of tokio. /// @@ -56,11 +51,10 @@ pub struct RuntimeConfig { #[usage( long = "runtime-io-uring", env = "MOQ_RUNTIME_IO_URING", - default_missing = "true", - num_args = 0..=1, - require_equals = true, + setting = "runtime.io_uring", + bool_value )] - pub io_uring: Option, + pub io_uring: bool, } impl RuntimeConfig { @@ -71,11 +65,21 @@ impl RuntimeConfig { /// to switch the mode off from a config file that already has the section. pub fn workers(&self) -> Option { let count = self.workers.filter(|count| *count > 0)?; - Some(moq_tokio::worker::Config::new(count).with_pin(self.pin.unwrap_or(true))) + Some(moq_tokio::worker::Config::new(count).with_pin(self.pin)) } /// Whether the workers should run on io_uring instead of tokio. pub fn io_uring(&self) -> bool { - self.io_uring.unwrap_or(false) + self.io_uring + } +} + +impl Default for RuntimeConfig { + fn default() -> Self { + Self { + workers: None, + pin: true, + io_uring: false, + } } } diff --git a/rs/moq-relay/src/settings.rs b/rs/moq-relay/src/settings.rs new file mode 100644 index 00000000000..eee68b64e0a --- /dev/null +++ b/rs/moq-relay/src/settings.rs @@ -0,0 +1,235 @@ +//! Settings registry for `moq-relay`. +//! +//! `usage::Cli` and `usage::Config` reject each other's attributes, so every +//! merged flag is declared twice. [`usage::config::Registry::drift`] is the test +//! that the two stay in step. + +#![allow(dead_code)] + +/// Every setting `moq-relay` merges, flattened tokio groups included. +#[derive(usage::Config)] +pub struct Settings { + #[usage(flatten)] + listen: moq_tokio::settings::Listen, + + #[usage(flatten)] + connect: moq_tokio::settings::Connect, + + #[usage(flatten)] + quic: moq_tokio::settings::Quic, + + #[usage(flatten)] + log: moq_tokio::settings::Log, + + #[usage(flatten)] + runtime: Runtime, + + #[usage(flatten)] + cluster: Cluster, + + #[usage(flatten)] + auth: Auth, + + #[usage(flatten)] + web: Web, + + #[usage(flatten)] + stats: Stats, + + #[usage(flatten)] + cache: Cache, + + #[usage(flatten)] + internal: Internal, + + #[usage(env = "MOQ_DRAIN_TIMEOUT", cli("--drain-timeout"))] + drain_timeout: Option, + + #[cfg(feature = "iroh")] + #[usage(flatten)] + iroh: moq_tokio::settings::Iroh, +} + +#[derive(usage::Config)] +#[usage(prefix = "runtime")] +struct Runtime { + #[usage(env = "MOQ_RUNTIME_WORKERS", cli("--runtime-workers"))] + workers: Option, + + #[usage(env = "MOQ_RUNTIME_PIN", cli("--runtime-pin"))] + pin: Option, + + #[usage(env = "MOQ_RUNTIME_IO_URING", cli("--runtime-io-uring"))] + io_uring: Option, +} + +#[derive(usage::Config)] +#[usage(prefix = "cluster")] +struct Cluster { + #[usage(env = "MOQ_CLUSTER_ID", cli("--cluster-id"))] + id: Option, + + #[usage(env = "MOQ_CLUSTER_CONNECT", cli("--cluster-connect"), parse = "list_by_comma")] + connect: Option>, + + #[usage(env = "MOQ_CLUSTER_CONNECT_API", cli("--cluster-connect-api"))] + connect_api: Option, + + #[usage(env = "MOQ_CLUSTER_NODE", cli("--cluster-node"))] + node: Option, + + #[usage(env = "MOQ_CLUSTER_MESH", cli("--cluster-mesh"))] + mesh: Option, + + #[usage(env = "MOQ_CLUSTER_TOKEN", cli("--cluster-token"))] + token: Option, + + #[usage(env = "MOQ_CLUSTER_TIER", cli("--cluster-tier"))] + tier: Option, + + #[usage(env = "MOQ_CLUSTER_LINGER", cli("--cluster-linger"))] + linger: Option, + + #[cfg(feature = "cluster-lan")] + #[usage(flatten)] + lan: ClusterLan, +} + +#[cfg(feature = "cluster-lan")] +#[derive(usage::Config)] +#[usage(prefix = "cluster.lan")] +struct ClusterLan { + #[usage(env = "MOQ_CLUSTER_LAN", cli("--cluster-lan"))] + enabled: Option, + + #[usage(env = "MOQ_CLUSTER_LAN_SECRET", cli("--cluster-lan-secret"))] + secret: Option, +} + +#[derive(usage::Config)] +#[usage(prefix = "auth")] +struct Auth { + #[usage(env = "MOQ_AUTH_KEY", cli("--auth-key"))] + key: Option, + + #[usage(env = "MOQ_AUTH_KEY_DIR", cli("--auth-key-dir"))] + key_dir: Option, + + #[usage(env = "MOQ_AUTH_PUBLIC", cli("--auth-public"))] + public: Option, + + #[usage(env = "MOQ_AUTH_PUBLIC_SUBSCRIBE", cli("--auth-public-subscribe"))] + public_subscribe: Option, + + #[usage(env = "MOQ_AUTH_PUBLIC_PUBLISH", cli("--auth-public-publish"))] + public_publish: Option, + + #[usage(env = "MOQ_AUTH_PUBLIC_API", cli("--auth-public-api"))] + public_api: Option, + + #[usage(env = "MOQ_AUTH_DOMAIN", cli("--auth-domain"), parse = "list_by_comma")] + domains: Option>, + + #[usage(env = "MOQ_AUTH_API", cli("--auth-api"))] + auth_api: Option, + + #[usage(env = "MOQ_AUTH_API_MODE", cli("--auth-api-mode"))] + api_mode: Option, + + #[usage(env = "MOQ_AUTH_MTLS_TIER", cli("--auth-mtls-tier"))] + mtls_tier: Option, + + #[usage(flatten)] + tls: AuthTls, +} + +#[derive(usage::Config)] +#[usage(prefix = "auth.tls")] +struct AuthTls { + #[usage(env = "MOQ_AUTH_TLS_ROOT", cli("--auth-tls-root"), parse = "list_by_comma")] + root: Option>, + + #[usage(env = "MOQ_AUTH_TLS_CERT", cli("--auth-tls-cert"))] + cert: Option, + + #[usage(env = "MOQ_AUTH_TLS_KEY", cli("--auth-tls-key"))] + key: Option, + + #[usage(env = "MOQ_AUTH_TLS_DISABLE_VERIFY", cli("--auth-tls-disable-verify"))] + disable_verify: Option, +} + +#[derive(usage::Config)] +#[usage(prefix = "web")] +struct Web { + #[usage(env = "MOQ_WEB_WS", cli("--web-ws"))] + ws: Option, + + #[usage(flatten)] + http: WebHttp, + + #[usage(flatten)] + https: WebHttps, +} + +#[derive(usage::Config)] +#[usage(prefix = "web.http")] +struct WebHttp { + #[usage(env = "MOQ_WEB_HTTP_LISTEN", cli("--web-http-listen"))] + listen: Option, +} + +#[derive(usage::Config)] +#[usage(prefix = "web.https")] +struct WebHttps { + #[usage(env = "MOQ_WEB_HTTPS_LISTEN", cli("--web-https-listen"))] + listen: Option, + + #[usage(env = "MOQ_WEB_HTTPS_CERT", cli("--web-https-cert"), parse = "list_by_comma")] + cert: Option>, + + #[usage(env = "MOQ_WEB_HTTPS_KEY", cli("--web-https-key"), parse = "list_by_comma")] + key: Option>, + + #[usage(env = "MOQ_WEB_HTTPS_ROOT", cli("--web-https-root"), parse = "list_by_comma")] + root: Option>, +} + +#[derive(usage::Config)] +#[usage(prefix = "stats")] +struct Stats { + #[usage(env = "MOQ_STATS_ENABLED", cli("--stats-enabled"))] + enabled: Option, + + #[usage(env = "MOQ_STATS_PREFIX", cli("--stats-prefix"))] + prefix: Option, + + #[usage(env = "MOQ_STATS_INTERVAL", cli("--stats-interval"))] + interval: Option, + + #[usage(env = "MOQ_STATS_NODE", cli("--stats-node"))] + node: Option, + + #[usage(env = "MOQ_STATS_DEPTH", cli("--stats-depth"))] + depth: Option, +} + +#[derive(usage::Config)] +#[usage(prefix = "cache")] +struct Cache { + #[usage(env = "MOQ_CACHE_CAPACITY", cli("--cache-capacity"))] + capacity: Option, + + #[usage(env = "MOQ_CACHE_HEADROOM", cli("--cache-headroom"))] + headroom: Option, + + #[usage(env = "MOQ_CACHE_DURATION", cli("--cache-duration"))] + duration: Option, +} + +#[derive(usage::Config)] +#[usage(prefix = "internal")] +struct Internal { + #[usage(env = "MOQ_INTERNAL_LISTEN", cli("--internal-listen"))] + listen: Option, +} diff --git a/rs/moq-relay/src/stats.rs b/rs/moq-relay/src/stats.rs index 1b10b1141fa..84211bedd5f 100644 --- a/rs/moq-relay/src/stats.rs +++ b/rs/moq-relay/src/stats.rs @@ -25,30 +25,32 @@ use serde::{Deserialize, Serialize}; #[non_exhaustive] pub struct StatsConfig { /// Master switch for stats publishing. Defaults to false. - /// - /// `Option` rather than a materialized default: Usage reads a standing `false` - /// as an empty boolean, so `update_from` would refill it from the environment - /// (or a declared default) over whatever the TOML file said. An `Option` is - /// empty only when nothing set it. A bare `Vec` has the same hazard, since - /// an empty list also reads as absent; see moq-dev/moq#3051. #[usage( long = "stats-enabled", env = "MOQ_STATS_ENABLED", - default_missing = "true", - num_args = 0..=1, - require_equals = true, + setting = "stats.enabled", + bool_value )] - #[serde(skip_serializing_if = "Option::is_none")] - pub enabled: Option, + pub enabled: bool, /// Top-level path under which stats broadcasts are published. Defaults /// to `.stats`. Future stats categories (e.g. host-level node stats) /// will share the same prefix. - #[usage(long = "stats-prefix", env = "MOQ_STATS_PREFIX", default = ".stats")] + #[usage( + long = "stats-prefix", + env = "MOQ_STATS_PREFIX", + default = ".stats", + setting = "stats.prefix" + )] pub prefix: String, /// Interval (in seconds) between snapshot publishes. Defaults to 1. - #[usage(long = "stats-interval", env = "MOQ_STATS_INTERVAL", default = "1")] + #[usage( + long = "stats-interval", + env = "MOQ_STATS_INTERVAL", + default = "1", + setting = "stats.interval" + )] pub interval: u64, /// Node identifier appended to the advertised stats path to disambiguate @@ -59,7 +61,7 @@ pub struct StatsConfig { /// May be multi-segment (e.g. `sjc/1`, `sjc/2`) when a region has multiple /// hosts; the segments nest under a shared region key on the advertised /// path. Single-relay deployments can leave this unset. - #[usage(long = "stats-node", env = "MOQ_STATS_NODE")] + #[usage(long = "stats-node", env = "MOQ_STATS_NODE", setting = "stats.node")] pub node: Option, /// Number of leading broadcast-path segments to bucket stats by, one @@ -68,14 +70,19 @@ pub struct StatsConfig { /// publish a per-first-segment broadcast (e.g. per tenant), so a consumer can /// announce-scope to just that group rather than slurping every node's full /// stats. See [`moq_stats::ProducerConfig::depth`]. - #[usage(long = "stats-depth", env = "MOQ_STATS_DEPTH", default = "0")] + #[usage( + long = "stats-depth", + env = "MOQ_STATS_DEPTH", + default = "0", + setting = "stats.depth" + )] pub depth: usize, } impl Default for StatsConfig { fn default() -> Self { Self { - enabled: None, + enabled: false, prefix: ".stats".into(), interval: 1, node: None, @@ -93,7 +100,7 @@ impl StatsConfig { /// the registry and keeping the publish task alive (the task stops when the /// last clone of the producer drops). pub fn build(&self, origin: origin::Producer) -> moq_stats::Producer { - if !self.enabled.unwrap_or(false) { + if !self.enabled { return moq_stats::Producer::new(moq_stats::ProducerConfig::new()); } let prefix = self.prefix.clone(); diff --git a/rs/moq-relay/src/web.rs b/rs/moq-relay/src/web.rs index 321aeeca234..c0c55b596d5 100644 --- a/rs/moq-relay/src/web.rs +++ b/rs/moq-relay/src/web.rs @@ -30,7 +30,7 @@ use tower_service::Service; use crate::{Auth, AuthParams, Cluster}; /// Configuration for the HTTP/HTTPS web server. -#[derive(usage::Args, Clone, Debug, serde::Deserialize, serde::Serialize, Default)] +#[derive(usage::Args, Clone, Debug, serde::Deserialize, serde::Serialize)] #[usage(unknown_flags = "error", args_override_self = false)] #[serde(deny_unknown_fields, default)] #[non_exhaustive] @@ -46,26 +46,30 @@ pub struct WebConfig { pub https: HttpsConfig, /// If true (default), expose a WebTransport compatible WebSocket polyfill. - /// - /// `Option` with the default resolved by [`Self::resolved_ws`] rather than a - /// Usage `default`, which a config file could not override: Usage reads a - /// standing `false` as an empty boolean, so the re-parse over the CLI args - /// would refill it with the declared `true`. #[usage( long = "web-ws", env = "MOQ_WEB_WS", - default_missing = "true", - num_args = 0..=1, - require_equals = true, + setting = "web.ws", + default = "true", + bool_value )] - #[serde(skip_serializing_if = "Option::is_none")] - pub ws: Option, + pub ws: bool, +} + +impl Default for WebConfig { + fn default() -> Self { + Self { + http: HttpConfig::default(), + https: HttpsConfig::default(), + ws: true, + } + } } impl WebConfig { - /// Whether the WebSocket polyfill is served, resolving the default. + /// Whether the WebSocket polyfill is served. pub fn resolved_ws(&self) -> bool { - self.ws.unwrap_or(true) + self.ws } } @@ -76,7 +80,12 @@ impl WebConfig { #[non_exhaustive] pub struct HttpConfig { /// Socket address to bind the HTTP listener to. - #[usage(long = "web-http-listen", name = "http-listen", env = "MOQ_WEB_HTTP_LISTEN")] + #[usage( + long = "web-http-listen", + name = "http-listen", + env = "MOQ_WEB_HTTP_LISTEN", + setting = "web.http.listen" + )] pub listen: Option, } @@ -92,6 +101,7 @@ pub struct HttpsConfig { long = "web-https-listen", name = "web-https-listen", env = "MOQ_WEB_HTTPS_LISTEN", + setting = "web.https.listen", requires("--web-https-cert", "--web-https-key") )] pub listen: Option, @@ -103,7 +113,8 @@ pub struct HttpsConfig { long = "web-https-cert", name = "web-https-cert", delimiter = ',', - env = "MOQ_WEB_HTTPS_CERT" + env = "MOQ_WEB_HTTPS_CERT", + setting = "web.https.cert" )] #[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde_as(as = "serde_with::OneOrMany<_>")] @@ -117,7 +128,8 @@ pub struct HttpsConfig { long = "web-https-key", name = "web-https-key", delimiter = ',', - env = "MOQ_WEB_HTTPS_KEY" + env = "MOQ_WEB_HTTPS_KEY", + setting = "web.https.key" )] #[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde_as(as = "serde_with::OneOrMany<_>")] @@ -136,7 +148,8 @@ pub struct HttpsConfig { long = "web-https-root", name = "web-https-root", delimiter = ',', - env = "MOQ_WEB_HTTPS_ROOT" + env = "MOQ_WEB_HTTPS_ROOT", + setting = "web.https.root" )] #[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde_as(as = "serde_with::OneOrMany<_>")] diff --git a/rs/moq-relay/tests/auth_lifetime.rs b/rs/moq-relay/tests/auth_lifetime.rs index 66655e27a00..8d1aaad73a0 100644 --- a/rs/moq-relay/tests/auth_lifetime.rs +++ b/rs/moq-relay/tests/auth_lifetime.rs @@ -120,7 +120,7 @@ async fn spawn_ws_relay(auth: moq_relay::Auth) -> (u16, tokio::task::JoinHandle< .certificates(); let mut web_config = WebConfig::default(); - web_config.ws = Some(true); + web_config.ws = true; web_config.http.listen = Some(format!("127.0.0.1:{port}").parse().expect("parse listen")); let web = Web::new(auth, cluster, certificates, web_config); diff --git a/rs/moq-relay/tests/runtime_uring.rs b/rs/moq-relay/tests/runtime_uring.rs index d536b4b5cd1..26d54822883 100644 --- a/rs/moq-relay/tests/runtime_uring.rs +++ b/rs/moq-relay/tests/runtime_uring.rs @@ -84,8 +84,8 @@ fn uring_config(cert: &std::path::Path, key: &std::path::Path, port: u16) -> Con config.listen.tls.cert = vec![cert.to_path_buf()]; config.listen.tls.key = vec![key.to_path_buf()]; config.runtime.workers = Some(WORKERS); - config.runtime.pin = Some(false); - config.runtime.io_uring = Some(true); + config.runtime.pin = false; + config.runtime.io_uring = true; #[allow(deprecated)] let public = PublicConfig::Simple(vec![String::new()]); config.auth.public = Some(public); diff --git a/rs/moq-relay/tests/runtime_workers.rs b/rs/moq-relay/tests/runtime_workers.rs index d17b4b1f8a3..0a95e70f726 100644 --- a/rs/moq-relay/tests/runtime_workers.rs +++ b/rs/moq-relay/tests/runtime_workers.rs @@ -49,7 +49,7 @@ fn worker_config(cert: &std::path::Path, key: &std::path::Path, port: u16, worke config.listen.tls.cert = vec![cert.to_path_buf()]; config.listen.tls.key = vec![key.to_path_buf()]; config.runtime.workers = Some(workers); - config.runtime.pin = Some(false); + config.runtime.pin = false; #[allow(deprecated)] let public = PublicConfig::Simple(vec![String::new()]); config.auth.public = Some(public); diff --git a/rs/moq-relay/tests/smoke.rs b/rs/moq-relay/tests/smoke.rs index d7e6d347d60..f9bf8c9a799 100644 --- a/rs/moq-relay/tests/smoke.rs +++ b/rs/moq-relay/tests/smoke.rs @@ -31,7 +31,7 @@ fn newest_lite_version() -> moq_net::Version { async fn build_web(port: u16, ws: bool) -> Web { let mut config = WebConfig::default(); - config.ws = Some(ws); + config.ws = ws; config.http.listen = Some(format!("127.0.0.1:{port}").parse().expect("parse listen")); build_web_with(config).await } @@ -126,7 +126,7 @@ async fn spawn_versioned_relay(versions: Vec) -> (u16, tokio:: config.listen.bind = Some("127.0.0.1:0".to_string()); config.listen.tls.generate = vec!["localhost".into()]; config.listen.version = versions; - config.web.ws = Some(true); + config.web.ws = true; config.web.http.listen = Some(format!("127.0.0.1:{port}").parse().expect("parse listen")); #[allow(deprecated)] @@ -326,7 +326,7 @@ async fn relay_https_terminates_tls() { std::fs::write(&key_path, key.serialize_pem()).expect("write key"); let mut config = WebConfig::default(); - config.ws = Some(false); + config.ws = false; config.https.listen = Some(format!("127.0.0.1:{port}").parse().expect("parse listen")); config.https.cert = vec![cert_path]; config.https.key = vec![key_path]; diff --git a/rs/moq-tokio/Cargo.toml b/rs/moq-tokio/Cargo.toml index 8d4d6688d88..3bc4ce13028 100644 --- a/rs/moq-tokio/Cargo.toml +++ b/rs/moq-tokio/Cargo.toml @@ -93,10 +93,11 @@ tikv-jemalloc-ctl = { version = "0.6", optional = true } tikv-jemallocator = { version = "0.6", features = ["profiling", "unprefixed_malloc_on_supported_platforms"], optional = true } time = "0.3" tokio = { workspace = true, features = ["full"] } +toml = { workspace = true } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } url = { version = "2", features = ["serde"] } -usage = { workspace = true } +usage = { workspace = true, features = ["config"] } web-transport-iroh = { workspace = true, optional = true } web-transport-noq = { workspace = true, optional = true } web-transport-proto = { workspace = true, optional = true } diff --git a/rs/moq-tokio/examples/clock.rs b/rs/moq-tokio/examples/clock.rs index e30ea81dc17..1fead15063e 100644 --- a/rs/moq-tokio/examples/clock.rs +++ b/rs/moq-tokio/examples/clock.rs @@ -19,6 +19,7 @@ use moq_net::*; #[derive(usage::Cli, Clone)] #[usage(unknown_flags = "error", args_override_self = false)] #[usage(name = "clock")] +#[usage(settings)] struct Config { /// The name of the broadcast to publish or subscribe to. #[usage(long)] diff --git a/rs/moq-tokio/src/cli.rs b/rs/moq-tokio/src/cli.rs index 07a06e73864..7190745d91c 100644 --- a/rs/moq-tokio/src/cli.rs +++ b/rs/moq-tokio/src/cli.rs @@ -4,10 +4,19 @@ //! as an empty string: they are questions rather than failures, and the generated //! `parse()` is expected to take them first. A binary that parses more than once //! never reaches that code, so it has to answer them itself. Both shapes exist here: -//! a TOML merge that parses, overlays a file, then re-parses, and moq-cli's repeated -//! `--` stage grammar. +//! a TOML merge that layers CLI, env, and file with recorded provenance, and +//! moq-cli's repeated `--` stage grammar. +use std::collections::HashSet; use std::ffi::OsStr; +use std::path::Path; + +use serde::Serialize; +use serde::de::DeserializeOwned; +use usage::config::{ + CliLayer, EnvLayer, FileScope, Layer, LayerCtx, LayerError, LayerOutput, Layers, Origin, Registry, Resolved, + SourceKind, Value, resolve, +}; /// What a Usage parse result asks the process to do. #[non_exhaustive] @@ -82,3 +91,197 @@ pub fn answer( err => Answer::Failure(usage::render_failure(spec, argv, &err)), } } + +/// Merge CLI, environment, and an optional TOML file with recorded provenance. +/// +/// Precedence is CLI > env > file > defaults, declared here: [`Layers`] is +/// highest-first, and a key the command line or the environment actually supplied +/// is never taken from the file. Presence comes from [`CliLayer`] / [`EnvLayer`], +/// not from whether a standing value looks empty, so a file that sets a list to +/// `[]` or a bool to `false` survives. +/// +/// `parsed` is the struct Usage filled from argv+env+defaults. File keys that +/// neither the command line nor the environment set replace those defaults. +/// `keep` copies fields a TOML round-trip would drop (hidden CLI-only legacy). +pub fn merge( + registry: Registry, + parsed: T, + cli: &CliLayer, + env: &EnvLayer, + file: Option>, + keep: impl Fn(&mut T, &T), +) -> Result<(T, Resolved), String> +where + T: Serialize + DeserializeOwned, +{ + let file_layer = file.map(|source| TomlLayer { + path: source.path, + value: source.value, + }); + let mut layers = Layers::new().then(cli).then(env); + if let Some(ref file) = file_layer { + layers = layers.then(file); + } + let resolved = resolve(registry, layers).map_err(|err| err.to_string())?; + + let occupied = occupied_keys(registry, &resolved); + let original = parsed; + let mut merged = toml::Value::try_from(&original).map_err(|err| err.to_string())?; + if let Some(source) = file { + overlay_unoccupied(&mut merged, source.value, "", &occupied); + } + let mut config: T = merged.try_into().map_err(|err: toml::de::Error| err.to_string())?; + keep(&mut config, &original); + Ok((config, resolved)) +} + +/// A TOML document to merge, named for provenance. +#[derive(Clone, Copy)] +pub struct FileSource<'a> { + /// Path shown in origin descriptions. + pub path: &'a Path, + /// Already-parsed document, aliases already normalized. + pub value: &'a toml::Value, +} + +fn occupied_keys(registry: Registry, resolved: &Resolved) -> HashSet { + let mut keys: HashSet = registry + .props + .iter() + .filter(|meta| { + matches!( + resolved.origin_key(meta.key).map(|origin| origin.kind), + Some(kind) if kind == SourceKind::CLI || kind == SourceKind::ENV + ) + }) + .map(|meta| meta.key.to_string()) + .collect(); + // The dial group is `connect.*` in the registry and `client.*` on some serde + // structs (moq-bench). Occupying one occupies the other so a CLI flag still + // beats a file key written under the other name. + let aliases: Vec = keys + .iter() + .filter_map(|key| { + key.strip_prefix("connect.") + .map(|rest| format!("client.{rest}")) + .or_else(|| key.strip_prefix("client.").map(|rest| format!("connect.{rest}"))) + }) + .collect(); + keys.extend(aliases); + keys +} + +fn overlay_unoccupied(base: &mut toml::Value, overlay: &toml::Value, path: &str, occupied: &HashSet) { + if !path.is_empty() && occupied.contains(path) { + return; + } + match (base, overlay) { + (toml::Value::Table(base), toml::Value::Table(overlay)) => { + for (key, value) in overlay { + let child = if path.is_empty() { + key.clone() + } else { + format!("{path}.{key}") + }; + match base.get_mut(key) { + Some(existing) => overlay_unoccupied(existing, value, &child, occupied), + None if occupied.contains(child.as_str()) => {} + None => { + if value.is_table() && occupied.iter().any(|key| key.starts_with(&format!("{child}."))) { + base.insert(key.clone(), toml::Value::Table(toml::Table::new())); + overlay_unoccupied(base.get_mut(key).expect("just inserted"), value, &child, occupied); + } else { + base.insert(key.clone(), value.clone()); + } + } + } + } + } + (base, overlay) => *base = overlay.clone(), + } +} + +/// A TOML document as a [`usage::config`] layer: every key present in the file, +/// including empty lists and `false` booleans. +struct TomlLayer<'a> { + path: &'a Path, + value: &'a toml::Value, +} + +impl Layer for TomlLayer<'_> { + fn source(&self) -> SourceKind { + SourceKind::FILE + } + + fn load(&self, ctx: &LayerCtx) -> Result { + let mut out = LayerOutput::new(); + flatten_file(self.path, String::new(), self.value, ctx, &mut out, &|key| { + ctx.registry().names_file_value(key) + }); + Ok(out) + } +} + +fn flatten_file( + path: &Path, + prefix: String, + value: &toml::Value, + ctx: &LayerCtx, + out: &mut LayerOutput, + names: &dyn Fn(&str) -> bool, +) { + match value { + toml::Value::Table(_) if !prefix.is_empty() && names(&prefix) => { + push_shaped(path, prefix, table_value(value), ctx, out); + } + toml::Value::Table(table) => { + for (key, inner) in table { + let child = if prefix.is_empty() { + key.clone() + } else { + format!("{prefix}.{key}") + }; + flatten_file(path, child, inner, ctx, out, names); + } + } + toml::Value::Array(_) => push_shaped(path, prefix, table_value(value), ctx, out), + scalar => { + let origin = Origin::file(format!("{}#{prefix}", path.display()), FileScope::Project); + match ctx.entry_for_key(&prefix, &scalar_text(scalar), origin) { + Ok(entry) => out.push(entry), + Err(warning) => out.warn(warning), + } + } + } +} + +fn push_shaped(path: &Path, key: String, value: Value, ctx: &LayerCtx, out: &mut LayerOutput) { + let origin = Origin::file(format!("{}#{key}", path.display()), FileScope::Project); + match ctx.entry_from_value(&key, value, origin) { + Ok(entry) => out.push(entry), + Err(warning) => out.warn(warning), + } +} + +fn table_value(value: &toml::Value) -> Value { + match value { + toml::Value::Table(table) => Value::Map( + table + .iter() + .map(|(key, inner)| (key.clone(), table_value(inner))) + .collect(), + ), + toml::Value::Array(items) => Value::List(items.iter().map(table_value).collect()), + toml::Value::Boolean(flag) => Value::Bool(*flag), + toml::Value::Integer(int) => Value::Int(*int), + toml::Value::Float(float) => Value::Float(*float), + other => Value::String(scalar_text(other)), + } +} + +fn scalar_text(value: &toml::Value) -> String { + match value { + toml::Value::String(text) => text.clone(), + other => other.to_string(), + } +} diff --git a/rs/moq-tokio/src/client.rs b/rs/moq-tokio/src/client.rs index 9b538ee9aa4..b88ae495aa8 100644 --- a/rs/moq-tokio/src/client.rs +++ b/rs/moq-tokio/src/client.rs @@ -777,6 +777,7 @@ mod tests { /// role configs are flattened together). #[derive(usage::Cli)] #[usage(unknown_flags = "error", args_override_self = false)] + #[usage(settings)] struct Cli { #[usage(flatten)] config: crate::connect::Config, diff --git a/rs/moq-tokio/src/connect.rs b/rs/moq-tokio/src/connect.rs index 6ef1d21effa..2d561b22fb1 100644 --- a/rs/moq-tokio/src/connect.rs +++ b/rs/moq-tokio/src/connect.rs @@ -478,7 +478,7 @@ pub struct Config { /// token. `http://` first fetches `/certificate.sha256` for the (insecure) /// self-signed fingerprint; `https://` connects directly. #[serde(alias = "connect", skip_serializing_if = "Option::is_none")] - #[usage(name = "connect", long = "connect", env = "MOQ_CONNECT")] + #[usage(name = "connect", long = "connect", env = "MOQ_CONNECT", setting = "connect.url")] pub url: Option, /// Send from this local UDP address. Defaults to an ephemeral dual-stack port. @@ -486,12 +486,22 @@ pub struct Config { /// Kept optional because the compatibility fold must distinguish an explicit /// wildcard bind from an unset bind. #[serde(default, skip_serializing_if = "Option::is_none")] - #[usage(name = "connect-bind", long = "connect-bind", env = "MOQ_CONNECT_BIND")] + #[usage( + name = "connect-bind", + long = "connect-bind", + env = "MOQ_CONNECT_BIND", + setting = "connect.bind" + )] pub bind: Option, /// The QUIC backend to use. /// Auto-detected from compiled features if not specified. - #[usage(name = "connect-backend", long = "connect-backend", env = "MOQ_CONNECT_BACKEND")] + #[usage( + name = "connect-backend", + long = "connect-backend", + env = "MOQ_CONNECT_BACKEND", + setting = "connect.backend" + )] pub backend: Option, /// Delay before also dialing the next resolved address (Happy Eyeballs). @@ -508,7 +518,8 @@ pub struct Config { name = "connect-race", long = "connect-race", env = "MOQ_CONNECT_RACE", - default = "250ms" + default = "250ms", + setting = "connect.race" )] pub race: crate::Duration, @@ -523,7 +534,8 @@ pub struct Config { name = "connect-resolution-delay", long = "connect-resolution-delay", env = "MOQ_CONNECT_RESOLUTION_DELAY", - default = "50ms" + default = "50ms", + setting = "connect.resolution_delay" )] pub resolution_delay: crate::Duration, @@ -540,7 +552,8 @@ pub struct Config { name = "connect-timeout", long = "connect-timeout", env = "MOQ_CONNECT_TIMEOUT", - default = "30s" + default = "30s", + setting = "connect.timeout" )] pub timeout: crate::Duration, @@ -554,6 +567,7 @@ pub struct Config { name = "connect-version", long = "connect-version", env = "MOQ_CONNECT_VERSION", + setting = "connect.version", choices( "moq-lite-01", "moq-lite-02", @@ -587,6 +601,7 @@ pub struct Config { name = "connect-once", long = "connect-once", env = "MOQ_CONNECT_ONCE", + setting = "connect.once", default_missing = "true", num_args = 0..=1, require_equals = true, @@ -636,6 +651,16 @@ pub struct Config { pub quic: Option, } +impl Config { + /// Hidden CLI-only fields a TOML round-trip would drop. + pub fn keep_parse_only(&mut self, from: &Self) { + self.legacy = from.legacy.clone(); + self.tls.keep_parse_only(&from.tls); + #[cfg(feature = "websocket")] + self.websocket.keep_parse_only(&from.websocket); + } +} + impl Default for Config { fn default() -> Self { Self { diff --git a/rs/moq-tokio/src/connection.rs b/rs/moq-tokio/src/connection.rs index 13ea49b6872..cf8d7b1ca5e 100644 --- a/rs/moq-tokio/src/connection.rs +++ b/rs/moq-tokio/src/connection.rs @@ -89,15 +89,33 @@ pub struct Backoff { /// Doubles as the bar a session must stay up to count as healthy, so it is /// floored at 50ms: at zero every session would look healthy and the retry /// pacing would collapse. - #[usage(name = "backoff-initial", long, env = "MOQ_BACKOFF_INITIAL", default = "1s")] + #[usage( + name = "backoff-initial", + long, + env = "MOQ_BACKOFF_INITIAL", + default = "1s", + setting = "connect.backoff.initial" + )] pub initial: CliDuration, /// Multiplier applied to delay after each failure. Defaults to 2. - #[usage(name = "backoff-multiplier", long, env = "MOQ_BACKOFF_MULTIPLIER", default = "2")] + #[usage( + name = "backoff-multiplier", + long, + env = "MOQ_BACKOFF_MULTIPLIER", + default = "2", + setting = "connect.backoff.multiplier" + )] pub multiplier: u32, /// Maximum delay between reconnect attempts. Defaults to 5s. - #[usage(name = "backoff-max", long, env = "MOQ_BACKOFF_MAX", default = "5s")] + #[usage( + name = "backoff-max", + long, + env = "MOQ_BACKOFF_MAX", + default = "5s", + setting = "connect.backoff.max" + )] pub max: CliDuration, /// Maximum time to spend retrying before giving up. Defaults to 10s. @@ -105,7 +123,13 @@ pub struct Backoff { /// Resets after a stable connection (one that outlives the initial backoff), so a flapping /// session that reconnects then immediately drops still counts toward the timeout. Set to 0 for /// unlimited retries. - #[usage(name = "backoff-timeout", long, env = "MOQ_BACKOFF_TIMEOUT", default = "10s")] + #[usage( + name = "backoff-timeout", + long, + env = "MOQ_BACKOFF_TIMEOUT", + default = "10s", + setting = "connect.backoff.timeout" + )] pub timeout: CliDuration, } @@ -308,7 +332,8 @@ pub struct GoawayConfig { long, env = "MOQ_GOAWAY_REDIRECT", value_enum, - default = "same-host" + default = "same-host", + setting = "connect.goaway.redirect" )] pub redirect: Redirect, @@ -316,7 +341,13 @@ pub struct GoawayConfig { /// "10s" or "500ms". This is a cap: a GOAWAY naming a shorter deadline wins, /// since the peer force-closes at its own deadline regardless, but a longer one /// does not extend it. Defaults to 10 seconds. - #[usage(name = "goaway-handover", long, env = "MOQ_GOAWAY_HANDOVER", default = "10s")] + #[usage( + name = "goaway-handover", + long, + env = "MOQ_GOAWAY_HANDOVER", + default = "10s", + setting = "connect.goaway.handover" + )] pub handover: CliDuration, } @@ -1241,6 +1272,7 @@ mod tests { fn cli_does_not_clobber_toml_backoff() { #[derive(usage::Cli)] #[usage(unknown_flags = "error", args_override_self = false)] + #[usage(settings)] struct Wrapper { #[usage(flatten)] backoff: Backoff, @@ -1278,6 +1310,7 @@ mod tests { fn cli_does_not_clobber_toml_goaway() { #[derive(usage::Cli)] #[usage(unknown_flags = "error", args_override_self = false)] + #[usage(settings)] struct Wrapper { #[usage(flatten)] goaway: GoawayConfig, diff --git a/rs/moq-tokio/src/iroh.rs b/rs/moq-tokio/src/iroh.rs index 36e785f0ea8..c11ef37bee5 100644 --- a/rs/moq-tokio/src/iroh.rs +++ b/rs/moq-tokio/src/iroh.rs @@ -137,6 +137,7 @@ pub struct EndpointConfig { name = "iroh-enabled", long = "iroh-enabled", env = "MOQ_IROH_ENABLED", + setting = "iroh.enabled", default_missing = "true", num_args = 0..=1, require_equals = true, @@ -145,17 +146,32 @@ pub struct EndpointConfig { /// Secret key for the iroh endpoint, either a hex-encoded string or a path to a file. /// If the file does not exist, a random key will be generated and written to the path. - #[usage(name = "iroh-secret", long = "iroh-secret", env = "MOQ_IROH_SECRET")] + #[usage( + name = "iroh-secret", + long = "iroh-secret", + env = "MOQ_IROH_SECRET", + setting = "iroh.secret" + )] pub secret: Option, /// Listen for UDP packets on the given address. /// Defaults to `0.0.0.0:0` if not provided. - #[usage(name = "iroh-bind-v4", long = "iroh-bind-v4", env = "MOQ_IROH_BIND_V4")] + #[usage( + name = "iroh-bind-v4", + long = "iroh-bind-v4", + env = "MOQ_IROH_BIND_V4", + setting = "iroh.bind_v4" + )] pub bind_v4: Option, /// Listen for UDP packets on the given address. /// Defaults to `[::]:0` if not provided. - #[usage(name = "iroh-bind-v6", long = "iroh-bind-v6", env = "MOQ_IROH_BIND_V6")] + #[usage( + name = "iroh-bind-v6", + long = "iroh-bind-v6", + env = "MOQ_IROH_BIND_V6", + setting = "iroh.bind_v6" + )] pub bind_v6: Option, /// Disable the iroh relay, using only direct P2P connections. @@ -163,6 +179,7 @@ pub struct EndpointConfig { name = "iroh-disable-relay", long = "iroh-disable-relay", env = "MOQ_IROH_DISABLE_RELAY", + setting = "iroh.disable_relay", default_missing = "true", num_args = 0..=1, require_equals = true, @@ -407,6 +424,7 @@ mod tests { async fn bind_refuses_a_released_quic_spelling() { #[derive(usage::Cli)] #[usage(unknown_flags = "error", args_override_self = false)] + #[usage(settings)] struct Cli { #[usage(flatten)] quic: crate::quic::Config, diff --git a/rs/moq-tokio/src/lib.rs b/rs/moq-tokio/src/lib.rs index fa594b459bc..a9b9805a545 100644 --- a/rs/moq-tokio/src/lib.rs +++ b/rs/moq-tokio/src/lib.rs @@ -75,6 +75,8 @@ pub mod runtime; feature = "tcp" ))] pub mod server; +#[doc(hidden)] +pub mod settings; #[cfg(feature = "tcp")] pub mod tcp; pub mod tls; diff --git a/rs/moq-tokio/src/listen.rs b/rs/moq-tokio/src/listen.rs index cca4b3885d0..0122414290c 100644 --- a/rs/moq-tokio/src/listen.rs +++ b/rs/moq-tokio/src/listen.rs @@ -22,7 +22,7 @@ pub struct Config { /// `tcp`/`unix` listener is configured to run a stream-only server with no /// QUIC. #[serde(alias = "listen")] - #[usage(name = "listen", long = "listen", env = "MOQ_LISTEN")] + #[usage(name = "listen", long = "listen", env = "MOQ_LISTEN", setting = "listen.bind")] pub bind: Option, /// Plaintext qmux TCP listener (`--listen-tcp-bind`, no TLS). Requires the @@ -41,7 +41,12 @@ pub struct Config { /// The QUIC backend to use. /// Auto-detected from compiled features if not specified. - #[usage(name = "listen-backend", long = "listen-backend", env = "MOQ_LISTEN_BACKEND")] + #[usage( + name = "listen-backend", + long = "listen-backend", + env = "MOQ_LISTEN_BACKEND", + setting = "listen.backend" + )] pub backend: Option, /// Restrict the server to specific MoQ protocol version(s). @@ -54,6 +59,7 @@ pub struct Config { name = "listen-version", long = "listen-version", env = "MOQ_LISTEN_VERSION", + setting = "listen.version", choices( "moq-lite-01", "moq-lite-02", @@ -90,7 +96,8 @@ pub struct Config { #[usage( name = "listen-preferred-v4", long = "listen-preferred-v4", - env = "MOQ_LISTEN_PREFERRED_V4" + env = "MOQ_LISTEN_PREFERRED_V4", + setting = "listen.preferred_v4" )] #[serde(default, skip_serializing_if = "Option::is_none")] pub preferred_v4: Option, @@ -99,7 +106,8 @@ pub struct Config { #[usage( name = "listen-preferred-v6", long = "listen-preferred-v6", - env = "MOQ_LISTEN_PREFERRED_V6" + env = "MOQ_LISTEN_PREFERRED_V6", + setting = "listen.preferred_v6" )] #[serde(default, skip_serializing_if = "Option::is_none")] pub preferred_v6: Option, @@ -109,7 +117,8 @@ pub struct Config { #[usage( name = "listen-quic-lb-id", long = "listen-quic-lb-id", - env = "MOQ_LISTEN_QUIC_LB_ID" + env = "MOQ_LISTEN_QUIC_LB_ID", + setting = "listen.lb_id" )] #[serde(default, skip_serializing_if = "Option::is_none")] pub lb_id: Option, @@ -119,7 +128,8 @@ pub struct Config { #[usage( name = "listen-quic-lb-nonce", long = "listen-quic-lb-nonce", - env = "MOQ_LISTEN_QUIC_LB_NONCE" + env = "MOQ_LISTEN_QUIC_LB_NONCE", + setting = "listen.lb_nonce" )] #[serde(default, skip_serializing_if = "Option::is_none")] pub lb_nonce: Option, @@ -142,6 +152,18 @@ pub struct Config { pub quic: Option, } +impl Config { + /// Hidden CLI-only fields a TOML round-trip would drop. + pub fn keep_parse_only(&mut self, from: &Self) { + self.legacy = from.legacy.clone(); + self.tls.keep_parse_only(&from.tls); + #[cfg(feature = "tcp")] + self.tcp.keep_parse_only(&from.tcp); + #[cfg(all(feature = "uds", unix))] + self.unix.keep_parse_only(&from.unix); + } +} + /// One server's claim on a slot in a `SO_REUSEPORT` group, and the slot it /// names once bound. /// @@ -319,6 +341,7 @@ mod tests { /// [`crate::connect`]). #[derive(usage::Cli)] #[usage(unknown_flags = "error", args_override_self = false)] + #[usage(settings)] struct Cli { #[usage(flatten)] config: Config, diff --git a/rs/moq-tokio/src/log.rs b/rs/moq-tokio/src/log.rs index 8dbea277f77..b3de382b8a6 100644 --- a/rs/moq-tokio/src/log.rs +++ b/rs/moq-tokio/src/log.rs @@ -17,7 +17,13 @@ use url::Url; pub struct Log { /// The level filter to use. #[serde_as(as = "DisplayFromStr")] - #[usage(name = "log-level", long = "log-level", default = "info", env = "MOQ_LOG_LEVEL")] + #[usage( + name = "log-level", + long = "log-level", + default = "info", + env = "MOQ_LOG_LEVEL", + setting = "log.level" + )] pub level: Level, } diff --git a/rs/moq-tokio/src/quic.rs b/rs/moq-tokio/src/quic.rs index 475d6ea9ac3..6f221c5c271 100644 --- a/rs/moq-tokio/src/quic.rs +++ b/rs/moq-tokio/src/quic.rs @@ -89,7 +89,12 @@ pub struct Config { /// Maximum number of concurrent QUIC streams per connection (both bidi and uni). /// Defaults to 1024. MoQ opens a stream per group, so busy endpoints want this high. #[serde(skip_serializing_if = "Option::is_none")] - #[usage(name = "quic-max-streams", long = "quic-max-streams", env = "MOQ_QUIC_MAX_STREAMS")] + #[usage( + name = "quic-max-streams", + long = "quic-max-streams", + env = "MOQ_QUIC_MAX_STREAMS", + setting = "quic.max_streams" + )] pub max_streams: Option, /// Enable UDP generic segmentation offload (GSO). @@ -102,6 +107,7 @@ pub struct Config { name = "quic-gso", long = "quic-gso", env = "MOQ_QUIC_GSO", + setting = "quic.gso", default_missing = "true", num_args = 0..=1, require_equals = true, @@ -113,7 +119,8 @@ pub struct Config { name = "quic-idle-timeout", long = "quic-idle-timeout", env = "MOQ_QUIC_IDLE_TIMEOUT", - default = "30s" + default = "30s", + setting = "quic.idle_timeout" )] pub idle_timeout: CliDuration, @@ -123,7 +130,8 @@ pub struct Config { name = "quic-keep-alive", long = "quic-keep-alive", env = "MOQ_QUIC_KEEP_ALIVE", - default = "5s" + default = "5s", + setting = "quic.keep_alive" )] pub keep_alive: CliDuration, @@ -133,6 +141,7 @@ pub struct Config { name = "quic-mtu-discovery", long = "quic-mtu-discovery", env = "MOQ_QUIC_MTU_DISCOVERY", + setting = "quic.mtu_discovery", default_missing = "true", num_args = 0..=1, require_equals = true, @@ -146,7 +155,8 @@ pub struct Config { name = "quic-congestion-control", long = "quic-congestion-control", env = "MOQ_QUIC_CONGESTION_CONTROL", - value_enum + value_enum, + setting = "quic.congestion_control" )] pub congestion_control: Option, @@ -160,7 +170,8 @@ pub struct Config { #[usage( name = "quic-receive-window", long = "quic-receive-window", - env = "MOQ_QUIC_RECEIVE_WINDOW" + env = "MOQ_QUIC_RECEIVE_WINDOW", + setting = "quic.receive_window" )] pub receive_window: Option, @@ -172,7 +183,8 @@ pub struct Config { #[usage( name = "quic-stream-receive-window", long = "quic-stream-receive-window", - env = "MOQ_QUIC_STREAM_RECEIVE_WINDOW" + env = "MOQ_QUIC_STREAM_RECEIVE_WINDOW", + setting = "quic.stream_receive_window" )] pub stream_receive_window: Option, @@ -182,7 +194,12 @@ pub struct Config { /// This bounds the transport send buffer. The quiche backend has no local send /// cap and refuses this rather than dropping it. #[serde(skip_serializing_if = "Option::is_none")] - #[usage(name = "quic-send-window", long = "quic-send-window", env = "MOQ_QUIC_SEND_WINDOW")] + #[usage( + name = "quic-send-window", + long = "quic-send-window", + env = "MOQ_QUIC_SEND_WINDOW", + setting = "quic.send_window" + )] pub send_window: Option, /// Write qlog traces into this directory, which must already exist. @@ -193,7 +210,7 @@ pub struct Config { /// /// Requires the `qlog` feature; setting it errors at init otherwise. #[serde(default, skip_serializing_if = "Option::is_none")] - #[usage(name = "quic-qlog", long = "quic-qlog", env = "MOQ_QUIC_QLOG")] + #[usage(name = "quic-qlog", long = "quic-qlog", env = "MOQ_QUIC_QLOG", setting = "quic.qlog")] #[usage(value_hint = usage::ValueHint::DirPath)] pub qlog: Option, @@ -206,6 +223,13 @@ pub struct Config { pub(crate) legacy: Legacy, } +impl Config { + /// Hidden CLI-only fields a TOML round-trip would drop. + pub fn keep_parse_only(&mut self, from: &Self) { + self.legacy = from.legacy.clone(); + } +} + impl Default for Config { fn default() -> Self { Self { @@ -606,6 +630,7 @@ mod tests { /// role-prefixed spellings) in isolation. #[derive(usage::Cli)] #[usage(unknown_flags = "error", args_override_self = false)] + #[usage(settings)] struct Cli { #[usage(flatten)] quic: Config, diff --git a/rs/moq-tokio/src/server.rs b/rs/moq-tokio/src/server.rs index ba9c6a69522..351d2b811d5 100644 --- a/rs/moq-tokio/src/server.rs +++ b/rs/moq-tokio/src/server.rs @@ -1386,6 +1386,7 @@ mod tests { fn version_help_lists_every_parseable_name() { #[derive(usage::Cli)] #[usage(unknown_flags = "error", args_override_self = false)] + #[usage(settings)] struct Cli { #[usage(flatten)] _listen: crate::listen::Config, diff --git a/rs/moq-tokio/src/settings.rs b/rs/moq-tokio/src/settings.rs new file mode 100644 index 00000000000..8821781aecb --- /dev/null +++ b/rs/moq-tokio/src/settings.rs @@ -0,0 +1,294 @@ +//! Settings registry for the flattened `moq-tokio` CLI groups. +//! +//! `usage::Cli` and `usage::Config` reject each other's attributes, so every +//! merged flag is declared twice: once on the `Args` structs the binaries parse, +//! and once here. [`usage::config::Registry::drift`] is the test that the two stay in step. + +#![allow(dead_code)] + +/// Accept-side settings (`[listen]`, `--listen-*`). +#[derive(usage::Config)] +#[usage(prefix = "listen")] +#[doc(hidden)] +pub struct Listen { + #[usage(env = "MOQ_LISTEN", cli("--listen"))] + bind: Option, + + #[usage(env = "MOQ_LISTEN_BACKEND", cli("--listen-backend"))] + backend: Option, + + #[usage(env = "MOQ_LISTEN_VERSION", cli("--listen-version"), parse = "list_by_comma")] + version: Option>, + + #[usage(env = "MOQ_LISTEN_PREFERRED_V4", cli("--listen-preferred-v4"))] + preferred_v4: Option, + + #[usage(env = "MOQ_LISTEN_PREFERRED_V6", cli("--listen-preferred-v6"))] + preferred_v6: Option, + + #[usage(env = "MOQ_LISTEN_QUIC_LB_ID", cli("--listen-quic-lb-id"))] + lb_id: Option, + + #[usage(env = "MOQ_LISTEN_QUIC_LB_NONCE", cli("--listen-quic-lb-nonce"))] + lb_nonce: Option, + + #[usage(flatten)] + tls: ListenTls, + + #[cfg(feature = "tcp")] + #[usage(flatten)] + tcp: ListenTcp, + + #[cfg(all(feature = "uds", unix))] + #[usage(flatten)] + unix: ListenUnix, +} + +/// `[listen.tls]` / `--listen-tls-*`. +#[derive(usage::Config)] +#[usage(prefix = "listen.tls")] +struct ListenTls { + #[usage(env = "MOQ_LISTEN_TLS_CERT", cli("--listen-tls-cert"), parse = "list_by_comma")] + cert: Option>, + + #[usage(env = "MOQ_LISTEN_TLS_KEY", cli("--listen-tls-key"), parse = "list_by_comma")] + key: Option>, + + #[usage( + env = "MOQ_LISTEN_TLS_GENERATE", + cli("--listen-tls-generate"), + parse = "list_by_comma" + )] + generate: Option>, + + #[usage(env = "MOQ_LISTEN_TLS_ROOT", cli("--listen-tls-root"), parse = "list_by_comma")] + root: Option>, +} + +/// `[listen.tcp]` / `--listen-tcp-bind`. +#[cfg(feature = "tcp")] +#[derive(usage::Config)] +#[usage(prefix = "listen.tcp")] +struct ListenTcp { + #[usage(env = "MOQ_LISTEN_TCP_BIND", cli("--listen-tcp-bind"))] + bind: Option, +} + +/// `[listen.unix]` / `--listen-unix-*`. +#[cfg(all(feature = "uds", unix))] +#[derive(usage::Config)] +#[usage(prefix = "listen.unix")] +struct ListenUnix { + #[usage(env = "MOQ_LISTEN_UNIX_BIND", cli("--listen-unix-bind"))] + bind: Option, + + #[usage(flatten)] + allow: ListenUnixAllow, +} + +/// `[listen.unix.allow]`. +#[cfg(all(feature = "uds", unix))] +#[derive(usage::Config)] +#[usage(prefix = "listen.unix.allow")] +struct ListenUnixAllow { + #[usage( + env = "MOQ_LISTEN_UNIX_ALLOW_UID", + cli("--listen-unix-allow-uid"), + parse = "list_by_comma" + )] + uid: Option>, + + #[usage( + env = "MOQ_LISTEN_UNIX_ALLOW_GID", + cli("--listen-unix-allow-gid"), + parse = "list_by_comma" + )] + gid: Option>, + + #[usage( + env = "MOQ_LISTEN_UNIX_ALLOW_PID", + cli("--listen-unix-allow-pid"), + parse = "list_by_comma" + )] + pid: Option>, +} + +/// Dial-side settings (`[connect]`, `--connect-*`). +#[derive(usage::Config)] +#[usage(prefix = "connect")] +#[doc(hidden)] +pub struct Connect { + #[usage(env = "MOQ_CONNECT", cli("--connect"))] + url: Option, + + #[usage(env = "MOQ_CONNECT_BIND", cli("--connect-bind"))] + bind: Option, + + #[usage(env = "MOQ_CONNECT_BACKEND", cli("--connect-backend"))] + backend: Option, + + #[usage(env = "MOQ_CONNECT_RACE", cli("--connect-race"))] + race: Option, + + #[usage(env = "MOQ_CONNECT_RESOLUTION_DELAY", cli("--connect-resolution-delay"))] + resolution_delay: Option, + + #[usage(env = "MOQ_CONNECT_TIMEOUT", cli("--connect-timeout"))] + timeout: Option, + + #[usage(env = "MOQ_CONNECT_VERSION", cli("--connect-version"), parse = "list_by_comma")] + version: Option>, + + #[usage(env = "MOQ_CONNECT_ONCE", cli("--connect-once"))] + once: Option, + + #[usage(flatten)] + tls: ConnectTls, + + #[usage(flatten)] + backoff: ConnectBackoff, + + #[usage(flatten)] + goaway: ConnectGoaway, + + #[cfg(feature = "websocket")] + #[usage(flatten)] + websocket: ConnectWebsocket, +} + +/// `[connect.tls]` / `--connect-tls-*`. +#[derive(usage::Config)] +#[usage(prefix = "connect.tls")] +struct ConnectTls { + #[usage(env = "MOQ_CONNECT_TLS_ROOT", cli("--connect-tls-root"), parse = "list_by_comma")] + root: Option>, + + #[usage(env = "MOQ_CONNECT_TLS_SYSTEM_ROOTS", cli("--connect-tls-system-roots"))] + system_roots: Option, + + #[usage( + env = "MOQ_CONNECT_TLS_FINGERPRINT", + cli("--connect-tls-fingerprint"), + parse = "list_by_comma" + )] + fingerprint: Option>, + + #[usage(env = "MOQ_CONNECT_TLS_CERT", cli("--connect-tls-cert"))] + cert: Option, + + #[usage(env = "MOQ_CONNECT_TLS_KEY", cli("--connect-tls-key"))] + key: Option, + + #[usage(env = "MOQ_CONNECT_TLS_INSECURE", cli("--connect-tls-insecure"))] + insecure: Option, + + #[usage(env = "MOQ_CONNECT_TLS_HOST_NAME", cli("--connect-tls-host-name"))] + host_name: Option, +} + +/// `[connect.backoff]` / `--backoff-*`. +#[derive(usage::Config)] +#[usage(prefix = "connect.backoff")] +struct ConnectBackoff { + #[usage(env = "MOQ_BACKOFF_INITIAL", cli("--backoff-initial"))] + initial: Option, + + #[usage(env = "MOQ_BACKOFF_MULTIPLIER", cli("--backoff-multiplier"))] + multiplier: Option, + + #[usage(env = "MOQ_BACKOFF_MAX", cli("--backoff-max"))] + max: Option, + + #[usage(env = "MOQ_BACKOFF_TIMEOUT", cli("--backoff-timeout"))] + timeout: Option, +} + +/// `[connect.goaway]` / `--goaway-*`. +#[derive(usage::Config)] +#[usage(prefix = "connect.goaway")] +struct ConnectGoaway { + #[usage(env = "MOQ_GOAWAY_REDIRECT", cli("--goaway-redirect"))] + redirect: Option, + + #[usage(env = "MOQ_GOAWAY_HANDOVER", cli("--goaway-handover"))] + handover: Option, +} + +/// `[connect.websocket]` / `--connect-websocket-*`. +#[cfg(feature = "websocket")] +#[derive(usage::Config)] +#[usage(prefix = "connect.websocket")] +struct ConnectWebsocket { + #[usage(env = "MOQ_CONNECT_WEBSOCKET_ENABLED", cli("--connect-websocket-enabled"))] + enabled: Option, + + #[usage(env = "MOQ_CONNECT_WEBSOCKET_DELAY", cli("--connect-websocket-delay"))] + delay: Option, +} + +/// Shared QUIC tuning (`[quic]`, `--quic-*`). +#[derive(usage::Config)] +#[usage(prefix = "quic")] +#[doc(hidden)] +pub struct Quic { + #[usage(env = "MOQ_QUIC_MAX_STREAMS", cli("--quic-max-streams"))] + max_streams: Option, + + #[usage(env = "MOQ_QUIC_GSO", cli("--quic-gso"))] + gso: Option, + + #[usage(env = "MOQ_QUIC_IDLE_TIMEOUT", cli("--quic-idle-timeout"))] + idle_timeout: Option, + + #[usage(env = "MOQ_QUIC_KEEP_ALIVE", cli("--quic-keep-alive"))] + keep_alive: Option, + + #[usage(env = "MOQ_QUIC_MTU_DISCOVERY", cli("--quic-mtu-discovery"))] + mtu_discovery: Option, + + #[usage(env = "MOQ_QUIC_CONGESTION_CONTROL", cli("--quic-congestion-control"))] + congestion_control: Option, + + #[usage(env = "MOQ_QUIC_RECEIVE_WINDOW", cli("--quic-receive-window"))] + receive_window: Option, + + #[usage(env = "MOQ_QUIC_STREAM_RECEIVE_WINDOW", cli("--quic-stream-receive-window"))] + stream_receive_window: Option, + + #[usage(env = "MOQ_QUIC_SEND_WINDOW", cli("--quic-send-window"))] + send_window: Option, + + #[usage(env = "MOQ_QUIC_QLOG", cli("--quic-qlog"))] + qlog: Option, +} + +/// Log settings (`[log]`, `--log-level`). +#[derive(usage::Config)] +#[usage(prefix = "log")] +#[doc(hidden)] +pub struct Log { + #[usage(env = "MOQ_LOG_LEVEL", cli("--log-level"))] + level: Option, +} + +/// Iroh endpoint settings (`[iroh]`, `--iroh-*`). +#[cfg(feature = "iroh")] +#[derive(usage::Config)] +#[usage(prefix = "iroh")] +#[doc(hidden)] +pub struct Iroh { + #[usage(env = "MOQ_IROH_ENABLED", cli("--iroh-enabled"))] + enabled: Option, + + #[usage(env = "MOQ_IROH_SECRET", cli("--iroh-secret"))] + secret: Option, + + #[usage(env = "MOQ_IROH_BIND_V4", cli("--iroh-bind-v4"))] + bind_v4: Option, + + #[usage(env = "MOQ_IROH_BIND_V6", cli("--iroh-bind-v6"))] + bind_v6: Option, + + #[usage(env = "MOQ_IROH_DISABLE_RELAY", cli("--iroh-disable-relay"))] + disable_relay: Option, +} diff --git a/rs/moq-tokio/src/tcp.rs b/rs/moq-tokio/src/tcp.rs index 7ce21b17614..77f5daf3b80 100644 --- a/rs/moq-tokio/src/tcp.rs +++ b/rs/moq-tokio/src/tcp.rs @@ -28,7 +28,12 @@ const WIRE_VERSION: qmux::Version = qmux::Version::QMux01; #[non_exhaustive] pub struct Config { /// Bind a plaintext qmux TCP listener on this address. - #[usage(long = "listen-tcp-bind", name = "listen-tcp-bind", env = "MOQ_LISTEN_TCP_BIND")] + #[usage( + long = "listen-tcp-bind", + name = "listen-tcp-bind", + env = "MOQ_LISTEN_TCP_BIND", + setting = "listen.tcp.bind" + )] #[serde(default, skip_serializing_if = "Option::is_none")] pub bind: Option, @@ -56,6 +61,11 @@ pub(crate) struct Legacy { } impl Config { + /// Hidden CLI-only fields a TOML round-trip would drop. + pub fn keep_parse_only(&mut self, from: &Self) { + self.legacy = from.legacy.clone(); + } + /// The released spelling, if in use, paired with what replaced it. Reached /// through [`crate::listen::Config::deprecated`]. pub(crate) fn deprecated(&self) -> crate::Deprecated { @@ -302,6 +312,7 @@ mod legacy_tests { use super::*; #[derive(usage::Cli)] #[usage(unknown_flags = "error", args_override_self = false)] + #[usage(settings)] struct Cli { #[usage(flatten)] tcp: Config, diff --git a/rs/moq-tokio/src/tls.rs b/rs/moq-tokio/src/tls.rs index 97f07943810..862ea27ccfc 100644 --- a/rs/moq-tokio/src/tls.rs +++ b/rs/moq-tokio/src/tls.rs @@ -429,7 +429,12 @@ pub struct Connect { /// Files are hot reloaded for new connections, retaining the last valid roots /// if a rotation is temporarily missing or malformed. #[serde(skip_serializing_if = "Vec::is_empty")] - #[usage(name = "connect-tls-root", long = "connect-tls-root", env = "MOQ_CONNECT_TLS_ROOT")] + #[usage( + name = "connect-tls-root", + long = "connect-tls-root", + env = "MOQ_CONNECT_TLS_ROOT", + setting = "connect.tls.root" + )] #[usage(value_hint = usage::ValueHint::FilePath, extensions("pem", "crt", "cer"))] #[serde_as(as = "serde_with::OneOrMany<_>")] pub root: Vec, @@ -445,6 +450,7 @@ pub struct Connect { name = "connect-tls-system-roots", long = "connect-tls-system-roots", env = "MOQ_CONNECT_TLS_SYSTEM_ROOTS", + setting = "connect.tls.system_roots", default_missing = "true", num_args = 0..=1, require_equals = true, @@ -465,7 +471,8 @@ pub struct Connect { #[usage( name = "connect-tls-fingerprint", long = "connect-tls-fingerprint", - env = "MOQ_CONNECT_TLS_FINGERPRINT" + env = "MOQ_CONNECT_TLS_FINGERPRINT", + setting = "connect.tls.fingerprint" )] #[serde_as(as = "serde_with::OneOrMany<_>")] pub fingerprint: Vec, @@ -486,7 +493,12 @@ pub struct Connect { /// Only certificates are extracted; any private keys in the file are ignored. /// Must be paired with `--connect-tls-key`. #[serde(skip_serializing_if = "Option::is_none")] - #[usage(name = "connect-tls-cert", long = "connect-tls-cert", env = "MOQ_CONNECT_TLS_CERT")] + #[usage( + name = "connect-tls-cert", + long = "connect-tls-cert", + env = "MOQ_CONNECT_TLS_CERT", + setting = "connect.tls.cert" + )] #[usage(value_hint = usage::ValueHint::FilePath, extensions("pem", "crt", "cer"))] pub cert: Option, @@ -495,7 +507,12 @@ pub struct Connect { /// Only the private key is extracted; any certificates in the file are ignored. /// Must be paired with `--connect-tls-cert`. #[serde(skip_serializing_if = "Option::is_none")] - #[usage(name = "connect-tls-key", long = "connect-tls-key", env = "MOQ_CONNECT_TLS_KEY")] + #[usage( + name = "connect-tls-key", + long = "connect-tls-key", + env = "MOQ_CONNECT_TLS_KEY", + setting = "connect.tls.key" + )] #[usage(value_hint = usage::ValueHint::FilePath, extensions("pem", "key"))] pub key: Option, @@ -507,6 +524,7 @@ pub struct Connect { name = "connect-tls-insecure", long = "connect-tls-insecure", env = "MOQ_CONNECT_TLS_INSECURE", + setting = "connect.tls.insecure", default_missing = "true", num_args = 0..=1, require_equals = true, @@ -521,7 +539,8 @@ pub struct Connect { #[usage( name = "connect-tls-host-name", long = "connect-tls-host-name", - env = "MOQ_CONNECT_TLS_HOST_NAME" + env = "MOQ_CONNECT_TLS_HOST_NAME", + setting = "connect.tls.host_name" )] pub host_name: Option, @@ -800,6 +819,15 @@ pub(crate) enum Verification { } impl Connect { + /// Hidden CLI-only fields a TOML round-trip would drop. + pub fn keep_parse_only(&mut self, from: &Self) { + self.deprecated = from.deprecated.clone(); + #[cfg(any(feature = "aws-lc-rs", feature = "ring"))] + { + self.identity = from.identity.clone(); + } + } + /// The released spellings in use, each paired with what replaced it. /// /// Two generations of them: the bare `--tls-*` flags, which split by role, and @@ -1204,14 +1232,24 @@ pub fn init_android(env: &mut jni::Env, context: jni::objects::JObject) -> Resul #[non_exhaustive] pub struct Listen { /// Load the given certificate from disk. - #[usage(long = "listen-tls-cert", name = "listen-tls-cert", env = "MOQ_LISTEN_TLS_CERT")] + #[usage( + long = "listen-tls-cert", + name = "listen-tls-cert", + env = "MOQ_LISTEN_TLS_CERT", + setting = "listen.tls.cert" + )] #[usage(value_hint = usage::ValueHint::FilePath, extensions("pem", "crt", "cer"))] #[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde_as(as = "serde_with::OneOrMany<_>")] pub cert: Vec, /// Load the given key from disk. - #[usage(long = "listen-tls-key", name = "listen-tls-key", env = "MOQ_LISTEN_TLS_KEY")] + #[usage( + long = "listen-tls-key", + name = "listen-tls-key", + env = "MOQ_LISTEN_TLS_KEY", + setting = "listen.tls.key" + )] #[usage(value_hint = usage::ValueHint::FilePath, extensions("pem", "key"))] #[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde_as(as = "serde_with::OneOrMany<_>")] @@ -1223,7 +1261,8 @@ pub struct Listen { long = "listen-tls-generate", name = "listen-tls-generate", delimiter = ',', - env = "MOQ_LISTEN_TLS_GENERATE" + env = "MOQ_LISTEN_TLS_GENERATE", + setting = "listen.tls.generate" )] #[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde_as(as = "serde_with::OneOrMany<_>")] @@ -1269,7 +1308,8 @@ pub struct Listen { long = "listen-tls-root", name = "listen-tls-root", delimiter = ',', - env = "MOQ_LISTEN_TLS_ROOT" + env = "MOQ_LISTEN_TLS_ROOT", + setting = "listen.tls.root" )] #[usage(value_hint = usage::ValueHint::FilePath, extensions("pem", "crt", "cer"))] #[serde(default, skip_serializing_if = "Vec::is_empty")] @@ -1331,6 +1371,16 @@ pub(crate) struct ListenDeprecated { } impl Listen { + /// Hidden CLI-only fields a TOML round-trip would drop. + pub fn keep_parse_only(&mut self, from: &Self) { + self.deprecated = from.deprecated.clone(); + #[cfg(any(feature = "aws-lc-rs", feature = "ring"))] + { + self.identity = from.identity.clone(); + } + self.peers = from.peers.clone(); + } + /// The released spellings in use, each paired with what replaced it. /// /// Public for the same reason as [`Connect::deprecated`]: this type is flattened @@ -3012,6 +3062,7 @@ mod legacy_tests { /// A parser wrapping the sections, which derive `Args` rather than `Parser`. #[derive(usage::Cli)] #[usage(unknown_flags = "error", args_override_self = false)] + #[usage(settings)] struct Cli { #[usage(flatten)] connect: Connect, diff --git a/rs/moq-tokio/src/unix.rs b/rs/moq-tokio/src/unix.rs index f6adc6f9851..a3d670f3419 100644 --- a/rs/moq-tokio/src/unix.rs +++ b/rs/moq-tokio/src/unix.rs @@ -27,7 +27,12 @@ const WIRE_VERSION: qmux::Version = qmux::Version::QMux01; #[non_exhaustive] pub struct Config { /// Bind a plaintext qmux Unix-socket listener at this path. - #[usage(long = "listen-unix-bind", name = "listen-unix-bind", env = "MOQ_LISTEN_UNIX_BIND")] + #[usage( + long = "listen-unix-bind", + name = "listen-unix-bind", + env = "MOQ_LISTEN_UNIX_BIND", + setting = "listen.unix.bind" + )] #[usage(value_hint = usage::ValueHint::AnyPath)] #[serde(default, skip_serializing_if = "Option::is_none")] pub bind: Option, @@ -89,6 +94,11 @@ pub(crate) struct Legacy { } impl Config { + /// Hidden CLI-only fields a TOML round-trip would drop. + pub fn keep_parse_only(&mut self, from: &Self) { + self.legacy = from.legacy.clone(); + } + /// The released spellings in use, each paired with what replaced it. Reached /// through [`crate::listen::Config::deprecated`]. pub(crate) fn deprecated(&self) -> crate::Deprecated { @@ -144,7 +154,8 @@ pub struct Allow { long = "listen-unix-allow-uid", name = "listen-unix-allow-uid", env = "MOQ_LISTEN_UNIX_ALLOW_UID", - delimiter = ',' + delimiter = ',', + setting = "listen.unix.allow.uid" )] #[serde(default, skip_serializing_if = "Vec::is_empty")] pub uid: Vec, @@ -154,7 +165,8 @@ pub struct Allow { long = "listen-unix-allow-gid", name = "listen-unix-allow-gid", env = "MOQ_LISTEN_UNIX_ALLOW_GID", - delimiter = ',' + delimiter = ',', + setting = "listen.unix.allow.gid" )] #[serde(default, skip_serializing_if = "Vec::is_empty")] pub gid: Vec, @@ -165,7 +177,8 @@ pub struct Allow { long = "listen-unix-allow-pid", name = "listen-unix-allow-pid", env = "MOQ_LISTEN_UNIX_ALLOW_PID", - delimiter = ',' + delimiter = ',', + setting = "listen.unix.allow.pid" )] #[serde(default, skip_serializing_if = "Vec::is_empty")] pub pid: Vec, @@ -387,6 +400,7 @@ mod legacy_tests { use super::*; #[derive(usage::Cli)] #[usage(unknown_flags = "error", args_override_self = false)] + #[usage(settings)] struct Cli { #[usage(flatten)] unix: Config, diff --git a/rs/moq-tokio/src/websocket.rs b/rs/moq-tokio/src/websocket.rs index e483a356e30..00b80d9de26 100644 --- a/rs/moq-tokio/src/websocket.rs +++ b/rs/moq-tokio/src/websocket.rs @@ -114,15 +114,12 @@ static WEBSOCKET_WON: LazyLock>> = LazyLock::new(|| pub struct Config { /// Whether to enable the WebSocket fallback. Defaults to true. /// - /// `Option` with the default resolved by [`Self::resolved_enabled`] rather than - /// a Usage `default`, which a config file could not override: Usage reads a - /// standing `false` as an empty boolean, so the re-parse over the CLI args - /// would refill it with the declared `true`. An `Option` is empty only when - /// nothing set it. + /// `None` means the default (on). Distinct from `Some(false)`, which turns it off. #[usage( name = "connect-websocket-enabled", long = "connect-websocket-enabled", env = "MOQ_CONNECT_WEBSOCKET_ENABLED", + setting = "connect.websocket.enabled", default_missing = "true", num_args = 0..=1, require_equals = true, @@ -136,7 +133,8 @@ pub struct Config { name = "connect-websocket-delay", long = "connect-websocket-delay", env = "MOQ_CONNECT_WEBSOCKET_DELAY", - default = "200ms" + default = "200ms", + setting = "connect.websocket.delay" )] pub delay: CliDuration, @@ -190,6 +188,11 @@ pub(crate) struct Legacy { const DEFAULT_DELAY: time::Duration = time::Duration::from_millis(200); impl Config { + /// Hidden CLI-only fields a TOML round-trip would drop. + pub fn keep_parse_only(&mut self, from: &Self) { + self.legacy = from.legacy.clone(); + } + /// The released spellings in use, each paired with what replaced it. Reached /// through [`crate::connect::Config::deprecated`]. pub(crate) fn deprecated(&self) -> crate::Deprecated { @@ -785,6 +788,7 @@ mod legacy_tests { use super::*; #[derive(usage::Cli)] #[usage(unknown_flags = "error", args_override_self = false)] + #[usage(settings)] struct Cli { #[usage(flatten)] websocket: Config, From 65e41bf51c5f57925d8950a80abd26a7c1adf676 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 11 Sep 2026 22:32:23 -0700 Subject: [PATCH 3/4] fix(relay): keep CLI-only auth public flags across merge merge round-trips through TOML and drops #[serde(skip)] fields. keep_parse_only restored only client_tls, so --auth-public-subscribe, --auth-public-publish, and --auth-public-api vanished and the relay started as though authentication were empty. File provenance now maps bench [client] keys onto connect.* so source() records the file origin. SNI cert helpers compile only for the backends that call them, which default-feature clippy requires after the noq default. Co-Authored-By: grok-4.6 --- rs/moq-bench/src/config.rs | 48 +++++++++++++++++++++++++ rs/moq-relay/src/auth.rs | 5 ++- rs/moq-relay/src/config.rs | 68 +++++++++++++++++++++++++++++++++++ rs/moq-tokio/src/cli.rs | 41 +++++++++++++-------- rs/moq-tokio/tests/backend.rs | 8 ++--- 5 files changed, 151 insertions(+), 19 deletions(-) diff --git a/rs/moq-bench/src/config.rs b/rs/moq-bench/src/config.rs index c4beaba12dc..adf40929511 100644 --- a/rs/moq-bench/src/config.rs +++ b/rs/moq-bench/src/config.rs @@ -573,4 +573,52 @@ connect = "https://example.com" None => unsafe { std::env::remove_var("MOQ_BENCH_NAME") }, } } + + /// `[client]` in the file is the serde name; the registry key is `connect.*`. + /// Provenance has to follow that alias, or `source("connect.url")` looks unset. + #[test] + fn file_client_table_records_connect_provenance() { + let dir = std::env::temp_dir().join("moq-bench-client-provenance"); + std::fs::create_dir_all(&dir).unwrap(); + let path = dir.join("bench.toml"); + std::fs::write(&path, "[client]\nurl = \"https://from-file.example\"\n").unwrap(); + + let config = Config::parse_and_merge([ + std::ffi::OsString::from("moq-bench"), + std::ffi::OsString::from("--file"), + path.clone().into(), + ]) + .unwrap(); + assert_eq!( + config.client.url.as_ref().unwrap().as_str(), + "https://from-file.example/" + ); + let source = config + .source("connect.url") + .unwrap_or_else(|| panic!("missing file origin, got {:?}", config.source("connect.url"))); + assert!( + source.contains("url") || source.contains("bench.toml"), + "origin {source:?} should name the file" + ); + + let config = Config::parse_and_merge([ + std::ffi::OsString::from("moq-bench"), + std::ffi::OsString::from("--file"), + path.into(), + std::ffi::OsString::from("--connect"), + std::ffi::OsString::from("https://from-cli.example"), + ]) + .unwrap(); + assert_eq!( + config.client.url.as_ref().unwrap().as_str(), + "https://from-cli.example/" + ); + assert!( + config + .source("connect.url") + .is_some_and(|source| source.contains("--connect")), + "origin {:?}", + config.source("connect.url") + ); + } } diff --git a/rs/moq-relay/src/auth.rs b/rs/moq-relay/src/auth.rs index 93670bf2ae3..8e5aba86317 100644 --- a/rs/moq-relay/src/auth.rs +++ b/rs/moq-relay/src/auth.rs @@ -358,9 +358,12 @@ pub struct AuthTls { } impl AuthConfig { - /// Hidden parse-only fields a TOML round-trip would drop. + /// Fields a TOML round-trip would drop: injected TLS plus CLI-only public shorthands. pub fn keep_parse_only(&mut self, from: &Self) { self.client_tls = from.client_tls.clone(); + self.public_subscribe = from.public_subscribe.clone(); + self.public_publish = from.public_publish.clone(); + self.public_api = from.public_api.clone(); } } diff --git a/rs/moq-relay/src/config.rs b/rs/moq-relay/src/config.rs index 8017489e0b1..9fffa6d0eda 100644 --- a/rs/moq-relay/src/config.rs +++ b/rs/moq-relay/src/config.rs @@ -249,6 +249,7 @@ impl Config { &env, file, |dst, src| { + // Legacy listen/connect/quic flags, and CLI-only auth public shorthands. dst.listen.keep_parse_only(&src.listen); dst.connect.keep_parse_only(&src.connect); dst.quic.keep_parse_only(&src.quic); @@ -1212,4 +1213,71 @@ uid = [1001] ); } } + + /// CLI-only `#[serde(skip)]` public shorthands must survive the TOML round-trip. + /// Dropping them makes `AuthConfig::is_empty` true and the relay start with no + /// public access, as though the flags had never been passed. + #[test] + fn cli_public_shorthands_survive_merge() { + let _env = EnvGuard::clear(&[ + "MOQ_AUTH_PUBLIC", + "MOQ_AUTH_PUBLIC_SUBSCRIBE", + "MOQ_AUTH_PUBLIC_PUBLISH", + "MOQ_AUTH_PUBLIC_API", + "MOQ_AUTH_KEY", + "MOQ_AUTH_KEY_DIR", + "MOQ_AUTH_API", + ]); + + let config = Config::parse_and_merge([ + "moq-relay", + "--auth-public-subscribe", + "demo", + "--auth-public-publish", + "uploads", + "--auth-public-api", + "https://api.example.com/access", + ]) + .expect("config load"); + + assert!( + !config.auth.is_empty(), + "CLI-only public flags must keep auth non-empty" + ); + let subscribe = config + .auth + .public_subscribe + .clone() + .expect("public_subscribe") + .into_detailed(); + assert_eq!(subscribe.subscribe, vec!["demo".to_string()]); + let publish = config + .auth + .public_publish + .clone() + .expect("public_publish") + .into_detailed(); + assert_eq!(publish.publish, vec!["uploads".to_string()]); + assert_eq!( + config.auth.public_api.as_deref(), + Some("https://api.example.com/access") + ); + assert!( + config + .source("auth.public_subscribe") + .is_some_and(|source| source.contains("--auth-public-subscribe")), + "origin {:?}", + config.source("auth.public_subscribe") + ); + + unsafe { std::env::set_var("MOQ_AUTH_PUBLIC_SUBSCRIBE", "from-env") }; + let config = Config::parse_and_merge(["moq-relay"]).expect("env load"); + let subscribe = config + .auth + .public_subscribe + .clone() + .expect("env public_subscribe") + .into_detailed(); + assert_eq!(subscribe.subscribe, vec!["from-env".to_string()]); + } } diff --git a/rs/moq-tokio/src/cli.rs b/rs/moq-tokio/src/cli.rs index 7190745d91c..96a122d15a1 100644 --- a/rs/moq-tokio/src/cli.rs +++ b/rs/moq-tokio/src/cli.rs @@ -156,21 +156,34 @@ fn occupied_keys(registry: Registry, resolved: &Resolved) -> HashSet { }) .map(|meta| meta.key.to_string()) .collect(); - // The dial group is `connect.*` in the registry and `client.*` on some serde - // structs (moq-bench). Occupying one occupies the other so a CLI flag still - // beats a file key written under the other name. - let aliases: Vec = keys - .iter() - .filter_map(|key| { - key.strip_prefix("connect.") - .map(|rest| format!("client.{rest}")) - .or_else(|| key.strip_prefix("client.").map(|rest| format!("connect.{rest}"))) - }) - .collect(); + // Occupying one name occupies the other so a CLI flag still beats a file key + // written under the serde alias. + let aliases: Vec = keys.iter().filter_map(|key| dial_alias(key)).collect(); keys.extend(aliases); keys } +/// The dial group is `connect.*` in the registry and `client.*` on some serde +/// structs (moq-bench). File keys and occupancy checks have to name both. +fn dial_alias(key: &str) -> Option { + key.strip_prefix("connect.") + .map(|rest| format!("client.{rest}")) + .or_else(|| key.strip_prefix("client.").map(|rest| format!("connect.{rest}"))) +} + +/// Registry key for a file path, mapping `client.*` onto `connect.*` when needed. +fn registry_key(ctx: &LayerCtx, key: &str) -> String { + if ctx.registry().lookup(key).is_some() { + return key.to_string(); + } + if let Some(aliased) = dial_alias(key) + && ctx.registry().lookup(&aliased).is_some() + { + return aliased; + } + key.to_string() +} + fn overlay_unoccupied(base: &mut toml::Value, overlay: &toml::Value, path: &str, occupied: &HashSet) { if !path.is_empty() && occupied.contains(path) { return; @@ -216,7 +229,7 @@ impl Layer for TomlLayer<'_> { fn load(&self, ctx: &LayerCtx) -> Result { let mut out = LayerOutput::new(); flatten_file(self.path, String::new(), self.value, ctx, &mut out, &|key| { - ctx.registry().names_file_value(key) + ctx.registry().names_file_value(®istry_key(ctx, key)) }); Ok(out) } @@ -247,7 +260,7 @@ fn flatten_file( toml::Value::Array(_) => push_shaped(path, prefix, table_value(value), ctx, out), scalar => { let origin = Origin::file(format!("{}#{prefix}", path.display()), FileScope::Project); - match ctx.entry_for_key(&prefix, &scalar_text(scalar), origin) { + match ctx.entry_for_key(®istry_key(ctx, &prefix), &scalar_text(scalar), origin) { Ok(entry) => out.push(entry), Err(warning) => out.warn(warning), } @@ -257,7 +270,7 @@ fn flatten_file( fn push_shaped(path: &Path, key: String, value: Value, ctx: &LayerCtx, out: &mut LayerOutput) { let origin = Origin::file(format!("{}#{key}", path.display()), FileScope::Project); - match ctx.entry_from_value(&key, value, origin) { + match ctx.entry_from_value(®istry_key(ctx, &key), value, origin) { Ok(entry) => out.push(entry), Err(warning) => out.warn(warning), } diff --git a/rs/moq-tokio/tests/backend.rs b/rs/moq-tokio/tests/backend.rs index d6924de65b1..6ecffc2ce14 100644 --- a/rs/moq-tokio/tests/backend.rs +++ b/rs/moq-tokio/tests/backend.rs @@ -216,7 +216,7 @@ async fn connect_test(config: ConnectTest<'_>) { /// Write a self-signed PEM cert + key for `name` to `dir`, prefixed by `stem`. /// /// Returns the two paths, in the order the `cert` and `key` lists want them. -#[cfg(any(feature = "quinn", feature = "quiche", feature = "noq"))] +#[cfg(any(feature = "quinn", feature = "quiche"))] fn write_self_signed(dir: &std::path::Path, stem: &str, name: &str) -> (std::path::PathBuf, std::path::PathBuf) { use std::io::Write; @@ -244,7 +244,7 @@ fn write_self_signed(dir: &std::path::Path, stem: &str, name: &str) -> (std::pat /// when the server picked the certificate the SNI asked for. Without SNI /// selection every client would get the first configured certificate, so the /// `alt.localhost` pin below would never match. -#[cfg(any(feature = "quinn", feature = "quiche", feature = "noq"))] +#[cfg(any(feature = "quinn", feature = "quiche"))] async fn sni_test(backend: moq_tokio::QuicBackend) { let dir = tempfile::tempdir().expect("tempdir"); let (first_cert, first_key) = write_self_signed(dir.path(), "first", "localhost"); @@ -303,7 +303,7 @@ async fn sni_test(backend: moq_tokio::QuicBackend) { } /// A generated certificate joins the file-backed ones rather than replacing them. -#[cfg(any(feature = "quinn", feature = "quiche", feature = "noq"))] +#[cfg(any(feature = "quinn", feature = "quiche"))] async fn cert_sources_test(backend: moq_tokio::QuicBackend) { let dir = tempfile::tempdir().expect("tempdir"); let (cert, key) = write_self_signed(dir.path(), "server", "localhost"); @@ -329,7 +329,7 @@ async fn cert_sources_test(backend: moq_tokio::QuicBackend) { /// Rotate the certificate files under a running listener and assert the served /// set follows, without the listener being rebuilt. -#[cfg(any(feature = "quinn", feature = "quiche", feature = "noq"))] +#[cfg(any(feature = "quinn", feature = "quiche"))] async fn reload_test(backend: moq_tokio::QuicBackend) { let dir = tempfile::tempdir().expect("tempdir"); let (cert, key) = write_self_signed(dir.path(), "server", "localhost"); From 43604c5b7db310bd7cf2ca14357e4456150c2f87 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 11 Sep 2026 22:44:25 -0700 Subject: [PATCH 4/4] fix(wasm): pin wasm-bindgen to the Nix CLI schema origin/dev's wasm-bindgen-cli is 0.2.127; the crate was still pinned to 0.2.121, so wasm-bindgen refused the bindgen format. Co-Authored-By: grok-4.6 --- Cargo.lock | 51 +++++++++++++++++++++--------------------- rs/moq-net/Cargo.toml | 2 +- rs/moq-wasm/Cargo.toml | 2 +- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca1c0e8cff8..2da20164f8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3589,7 +3589,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2 0.5.10", + "socket2 0.6.5", "tokio", "tower-service", "tracing", @@ -4227,13 +4227,12 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.98" +version = "0.3.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08" +checksum = "0e0c1080212aad755ea003d18543e8768dd432c48819efd73a7bf1e39b7a5a3a" dependencies = [ "cfg-if", "futures-util", - "once_cell", "wasm-bindgen", ] @@ -5724,7 +5723,7 @@ dependencies = [ "pin-project-lite", "rustc-hash 2.1.3", "rustls", - "socket2 0.5.10", + "socket2 0.6.5", "thiserror 2.0.20", "tokio", "tokio-stream", @@ -5771,7 +5770,7 @@ checksum = "02bba20e097a5a16cd0ad14ec882fae1e80a092a124e9422fc4dddd92e96a647" dependencies = [ "cfg_aliases", "libc", - "socket2 0.5.10", + "socket2 0.6.5", "tracing", "windows-sys 0.61.2", ] @@ -7459,7 +7458,7 @@ dependencies = [ "quinn-udp", "rustc-hash 2.1.3", "rustls", - "socket2 0.5.10", + "socket2 0.6.5", "thiserror 2.0.20", "tokio", "tracing", @@ -7501,7 +7500,7 @@ dependencies = [ "cfg_aliases", "libc", "once_cell", - "socket2 0.5.10", + "socket2 0.6.5", "tracing", "windows-sys 0.52.0", ] @@ -10413,9 +10412,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.121" +version = "0.2.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790" +checksum = "1b70935747edd64d89de3efa29d73789b806c15798f8e7dca4d8ac356b50ce70" dependencies = [ "cfg-if", "once_cell", @@ -10426,9 +10425,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.71" +version = "0.4.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96492d0d3ffba25305a7dc88720d250b1401d7edca02cc3bcd50633b424673b8" +checksum = "6b7777d5cc23d0e91404e53ce2d5e8ec7acae3026b16233dba62cd3246457950" dependencies = [ "js-sys", "wasm-bindgen", @@ -10436,9 +10435,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.121" +version = "0.2.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578" +checksum = "77775f8f3f7217702089053b94958f8f54061a3f663417df76e19cbdcca29bc1" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -10446,9 +10445,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.121" +version = "0.2.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2" +checksum = "e11d33f857dc2fb11b8bc75aee111aa9cbeb12cd9f25efd3d4c2a3dd4e235284" dependencies = [ "bumpalo", "proc-macro2", @@ -10459,18 +10458,18 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.121" +version = "0.2.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441" +checksum = "7ef64dbcc55df09c7e5a46182d181c2cfa3e925f3da937ea764728b4bbb9dcbf" dependencies = [ "unicode-ident", ] [[package]] name = "wasm-bindgen-test" -version = "0.3.71" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af5ec93229ad9ccd0a545a516dec76dc276613f278f6a91aa6b463d5b33d42d0" +checksum = "895a2607575412a4eda1df892084a375ea10dfeadc4d7d2ab87b854e4ddc7ba1" dependencies = [ "async-trait", "cast", @@ -10490,9 +10489,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.71" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c81b9fef827e575e0e54431736d1baa0d700315d8c62cfef1f61fa3aad0cbeb" +checksum = "4288cb0ebe215033bf949ae1fd046726daa4c32a157f24b9dc6ac387a52aa759" dependencies = [ "proc-macro2", "quote", @@ -10501,9 +10500,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-shared" -version = "0.2.121" +version = "0.2.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4d8ae7ad5440360e9799dfd42857d126454a88441ddf72d288ef83fa47f527" +checksum = "33ff1c1b360982e93b6d8ea9c04836f71dba0817a16f91e229cf3a51bdd9d987" [[package]] name = "wasm-streams" @@ -10654,9 +10653,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.98" +version = "0.3.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b572dff8bcf38bad0fa19729c89bb5748b2b9b1d8be70cf90df697e3a8f32aa" +checksum = "c435338968042f4f59a557f690a253676d47ce13ceb55d70100e7facf6620a30" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/rs/moq-net/Cargo.toml b/rs/moq-net/Cargo.toml index d630acfafcc..1f0ff39b284 100644 --- a/rs/moq-net/Cargo.toml +++ b/rs/moq-net/Cargo.toml @@ -59,7 +59,7 @@ loom = { workspace = true } [target.'cfg(target_family = "wasm")'.dev-dependencies] getrandom = { workspace = true } # Keep this in lockstep with rs/moq-wasm's pinned wasm-bindgen CLI schema. -wasm-bindgen-test = "=0.3.71" +wasm-bindgen-test = "=0.3.77" [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)'] } diff --git a/rs/moq-wasm/Cargo.toml b/rs/moq-wasm/Cargo.toml index b7bac41dead..79f41629b96 100644 --- a/rs/moq-wasm/Cargo.toml +++ b/rs/moq-wasm/Cargo.toml @@ -33,7 +33,7 @@ tracing-wasm = "0.2" url = { workspace = true } # Pinned to the wasm-bindgen-cli version in the Nix dev shell: the bindgen # schema must match exactly between crate and CLI. Bump both together. -wasm-bindgen = "=0.2.121" +wasm-bindgen = "=0.2.127" wasm-bindgen-futures = "0.4" web-async = { workspace = true } web-transport-wasm = { workspace = true }