feat(relay): add --cluster-id to set a fixed origin id#1786
Conversation
A relay previously always generated a random origin id on startup, so it looked like a brand-new node after every restart. Add `cluster.id` (--cluster-id / MOQ_CLUSTER_ID) so an operator can pin a stable origin/hop id across restarts. Typed as Option<u64> per the config-flag convention so an absent CLI flag doesn't clobber a TOML value during the merge re-parse. A reserved (0) or out-of-range (>= 2^62) value is ignored in favor of a random id, and a value >= 2^53 logs a warning since older @moq/lite JS clients decode hop ids as a u53. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
Walkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Make Cluster::new return a Result and reject a configured cluster id of 0 or >= 2^62 (the wire varint limit) at startup, rather than logging a warning and silently falling back to a random id. Drop the >= 2^53 warning; the doc still recommends staying below 2^53 for older @moq/lite JS clients. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Summary
A relay previously always generated a random origin id on startup (
Origin::random()), so it looked like a brand-new node to the cluster after every restart. There was no way for an operator to assign a stable identity.This adds a
cluster.idconfig field (--cluster-id/MOQ_CLUSTER_ID) to pin the relay's origin/hop id across restarts. The origin id is the value a relay adds to a broadcast's hop list for loop detection and shortest-path routing.Behavior
1 .. 2^62): used verbatim as the origin id.0) or out of range (>= 2^62, the wire varint limit): errors at startup (Cluster::newreturnsErr), rather than producing an unencodable hop id.Keep an explicit id below 2^53 if older
@moq/litebrowser clients connect, since they decode hop ids as au53; this is documented but not enforced.Typed as
Option<u64>per the repo's config-flag convention so an absent CLI flag doesn't clobber a TOML-configured value during the merge re-parse.Public API changes
ClusterConfiggains apub id: Option<u64>field.ClusterConfigis#[non_exhaustive]with aDefault, so additive.Cluster::newsignature changes from-> Selfto-> anyhow::Result<Self>so an invalid id fails loudly. Technically breaking for the (in-repo only) callers; all call sites updated.Files
rs/moq-relay/src/cluster.rs: newidfield;Cluster::newvalidates it and returnsResult.rs/moq-relay/src/main.rs: propagate the newResult.rs/moq-relay/src/config.rs: regression tests for the clap+TOML clobber and CLI-override paths.rs/moq-relay/tests/smoke.rs: updated for the newResult.doc/bin/relay/cluster.md: new "Origin id" section (Cross-Package Sync).Test plan
cargo test -p moq-relay— all pass, including new tests (cluster_id_sets_origin,cluster_id_out_of_range_errors,cli_does_not_clobber_toml_cluster_id,cli_flag_overrides_toml_cluster_id)cargo clippy -p moq-relayclean (via nix)cargo fmt --checkclean (via nix)Notes
Related to (but independent of) #1785, which caps the randomly generated id at 53 bits for the same
@moq/liteu53 compatibility reason. This PR lets operators set an explicit id.(Written by Claude)