From cbc1fd48af52dfc8bc7a3437fde4e66eafc35ef7 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 16 Nov 2026 08:32:36 -0800 Subject: [PATCH 1/4] chore(quest): claim quest/m2/net-renames.md Quest-Claim: 35fc36319b201084 From a291ee6b9d6d93fcd2eef774553e044512b54644 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 16 Nov 2026 08:42:32 -0800 Subject: [PATCH 2/4] feat(net)!: node, version, handshake, and route priority carry their wire names Co-Authored-By: Claude Sonnet 5.5 --- doc/bin/relay/index.md | 2 +- doc/concept/identity.md | 2 +- doc/concept/moq-lite.md | 6 +- doc/lib/rs/moq-net.md | 4 +- quest/m2/README.md | 4 +- quest/m2/cluster-routes/README.md | 2 +- quest/m2/multicast/switch.md | 8 +- quest/m2/net-renames.md | 86 -------- quest/m2/session-codes.md | 4 - quest/m2/unused-api/net.md | 11 +- rs/moq-ffi/src/test.rs | 4 +- rs/moq-net/benches/auth.rs | 4 +- rs/moq-net/src/client.rs | 110 +++++----- rs/moq-net/src/coding/codes.rs | 22 +- rs/moq-net/src/coding/reader.rs | 8 +- rs/moq-net/src/coding/varint.rs | 6 +- rs/moq-net/src/coding/writer.rs | 4 +- rs/moq-net/src/fuzz.rs | 10 +- rs/moq-net/src/ietf/publisher.rs | 18 +- rs/moq-net/src/ietf/session.rs | 62 +++--- rs/moq-net/src/ietf/subscriber.rs | 10 +- rs/moq-net/src/ietf/version.rs | 8 +- rs/moq-net/src/lite/corpus.rs | 2 +- rs/moq-net/src/lite/ietf.rs | 12 +- rs/moq-net/src/lite/publisher.rs | 66 +++--- rs/moq-net/src/lite/session.rs | 28 +-- rs/moq-net/src/lite/subscriber.rs | 136 ++++++------ rs/moq-net/src/lite/subscriber/routed.rs | 2 +- rs/moq-net/src/lite/version.rs | 20 +- rs/moq-net/src/model/mod.rs | 2 +- rs/moq-net/src/model/origin.rs | 155 +++++++------- rs/moq-net/src/model/resume_model.rs | 2 +- rs/moq-net/src/server.rs | 202 +++++++++--------- rs/moq-net/src/setup.rs | 12 +- rs/moq-net/src/version.rs | 170 ++++++++------- rs/moq-net/tests/integration/auth.rs | 2 +- rs/moq-net/tests/integration/control_stats.rs | 2 +- rs/moq-net/tests/integration/goaway.rs | 2 +- rs/moq-net/tests/integration/instance.rs | 2 +- rs/moq-net/tests/integration/mesh_withdraw.rs | 2 +- rs/moq-net/tests/integration/multi_cdn.rs | 4 +- .../tests/integration/route_acceptance.rs | 2 +- rs/moq-net/tests/integration/route_change.rs | 2 +- rs/moq-net/tests/integration/route_cluster.rs | 20 +- .../tests/integration/route_failover.rs | 2 +- rs/moq-relay/benches/session.rs | 2 +- rs/moq-relay/src/auth/refresh.rs | 4 +- rs/moq-relay/src/cluster.rs | 8 +- rs/moq-relay/src/connection.rs | 2 +- rs/moq-relay/src/incoming.rs | 10 +- rs/moq-relay/src/sim.rs | 2 +- rs/moq-relay/src/uring.rs | 6 +- rs/moq-relay/tests/integration/drain.rs | 2 +- rs/moq-relay/tests/integration/embed.rs | 2 +- rs/moq-relay/tests/integration/memory.rs | 2 +- .../tests/integration/runtime_uring.rs | 2 +- rs/moq-relay/tests/integration/socket_auth.rs | 2 +- rs/moq-tokio/src/client.rs | 16 +- rs/moq-tokio/src/connection.rs | 6 +- rs/moq-tokio/src/server.rs | 20 +- rs/moq-uring/src/transport/local.rs | 2 +- 61 files changed, 629 insertions(+), 703 deletions(-) delete mode 100644 quest/m2/net-renames.md diff --git a/doc/bin/relay/index.md b/doc/bin/relay/index.md index a50103b8e75..c0b5e9ad225 100644 --- a/doc/bin/relay/index.md +++ b/doc/bin/relay/index.md @@ -101,7 +101,7 @@ relay.with_web(web).run().await?; from `relay.shutdown().admission()` and pass `relay.shutdown().clone()` to `Connection::with_shutdown`, so the drain waits for its handshakes too. - To serve a session from any other moq-net transport, such as the in-memory - one in tests, enable the `test-support` feature, read its SETUP with `moq_net::Server::accept_request` and pass + one in tests, enable the `test-support` feature, read its SETUP with `moq_net::Server::handshake` and pass `Accepted::new(handshake, transport)` to `Connection::new`. The client must send its path in the SETUP. The server's accept timeout (`moq_net::Server::with_timeout`) bounds admission and, on moq-lite 01/02, the SETUP reply too. diff --git a/doc/concept/identity.md b/doc/concept/identity.md index a9a567375a7..bb4d433f167 100644 --- a/doc/concept/identity.md +++ b/doc/concept/identity.md @@ -74,7 +74,7 @@ A route resolving a path is chosen in this order: because the timeline continues. 3. Among eligible routes: a route from a peer that has not sent GOAWAY (a draining peer's routes rank below every other, whatever their preference - or cost, and serve only as a last resort), then the preferred link, then an + or cost, and serve only as a last resort), then the highest-priority link, then an identified chain over an anonymous one, then the lowest cost, then a broadcast published on this origin, then the shortest hop chain, then a hash of the full requested diff --git a/doc/concept/moq-lite.md b/doc/concept/moq-lite.md index f270c250a90..3ed961f5ce4 100644 --- a/doc/concept/moq-lite.md +++ b/doc/concept/moq-lite.md @@ -120,7 +120,7 @@ hidden names work exactly as before. instance, so it never inherits those viewers. - **Most specific, then highest epoch, then rank.** The most specific prefix wins. Within one instance only its highest epoch is eligible, ahead of cost. - Among instances the order is link preference, cost, a broadcast published + Among instances the order is link priority, cost, a broadcast published locally, hop length, then a hash of the instance and the path, so relays agree and a pool's paths spread over its hosts. See [choosing a route](/concept/identity#choosing-a-route). @@ -160,9 +160,9 @@ choosing instances, following restarts, and answering work on demand. An endpoint can hold sessions to several CDNs at once, each feeding one shared origin, and rank them: moq.pro as primary, another CDN as secondary. The rank is -a per-link preference the endpoint sets (higher wins, 0 is neutral, negative demotes), never sent on the wire. It decides +a per-link priority the endpoint sets (higher wins, 0 is neutral, negative demotes), unrelated to a subscription's priority. It decides among instances before cost, so metrics from different operators are never -compared. A subscription uses the preferred link that has a route and moves to the +compared. A subscription uses the highest-priority link that has a route and moves to the next when that route goes; a publisher pushes the same broadcast to every CDN. The move resumes without a seam only between routes with the same instance, diff --git a/doc/lib/rs/moq-net.md b/doc/lib/rs/moq-net.md index d8ff52e1e7c..d6e5cd74929 100644 --- a/doc/lib/rs/moq-net.md +++ b/doc/lib/rs/moq-net.md @@ -16,9 +16,9 @@ moq-transport at setup and presents one API either way. Media is a layer above What you use it for, beyond what the concept page already describes: - **An origin outlives the session.** `origin.route(path, options)` returns a `Route` that owns the broadcast to fill (`route.broadcast()`) and controls its announcement: `announce()`, `withdraw()`, `set_cost()`, and dropping the last clone retracts it. `origin.claim(prefix, options)` returns a `Claim` that serves requests beneath a prefix instead: `claim.requested()` yields each one, answered with `request.serve(held)`, `request.route(options)` (the path's own exact route) or `reject`. A `Claim` has the same announcement controls and no broadcast. A standalone broadcast cannot announce; publish one only through a claim's `serve`. A reconnect announces existing routes again, and closing the session does not delete them. -- **Routes report what the mesh filled in.** An announcement's `route` gives its `instance()` and `cost()`; an application sets only `RouteOptions`. The hop chain a relay uses for loop detection stays internal. An origin's own hop id is `origin::Config::hop`, random unless a relay names one. +- **Routes report what the mesh filled in.** An announcement's `route` gives its `instance()` and `cost()`; an application sets only `RouteOptions`. The hop chain a relay uses for loop detection stays internal. An origin's own Node ID is `origin::Config::node`, random unless a relay names one. - **Requests can pin an instance.** `consumer.request(path, Some(instance))` resolves only through a route announcing that [publisher instance](/concept/moq-lite#publisher-instances); `None` takes whichever route wins. The resolved consumer names its instance in `info().instance`, pinned or not. `origin.route(path, options)` serves a random instance minted when it is created and kept across `withdraw()` and `announce()`. Unless one is named, a claim moves to a fresh instance each time a job holding its current one ends, and a job takes the claim's. Set one with `RouteOptions::with_instance(instance, epoch)` only for a publisher that continues its timeline across restarts, so its group starts keep rising, and raises the epoch each time. `route.instance()` names it. -- **Rank several CDNs.** Dial each with its own subscribe handle, `origin.clone().with_preference(origin::Preference::new(rank))` (higher wins; 0 is neutral and a negative rank demotes), all on one origin. Requests use the preferred link that has a route and fail over to the next; see [multiple CDNs](/concept/moq-lite#multiple-cdns). +- **Rank several CDNs.** Dial each with its own subscribe handle, `origin.clone().with_priority(origin::Priority::new(rank))` (higher wins; 0 is neutral and a negative rank demotes), all on one origin. Requests use the highest-priority link that has a route and fail over to the next; see [multiple CDNs](/concept/moq-lite#multiple-cdns). - **Request one instance, or follow them all.** `consumer.request(path, None)` resolves the instance serving a path now, and fails `Unroutable` only once discovery has synced with no route for it. `consumer.follow(path, None)` hands out each publisher instance serving a path from `available()`: the first once announced, then each one that takes over, `None` once the path goes offline, and whatever serves it next, like JS `follow(path)`. `consumer.announced()` lists paths as present, then unavailable or available as a held route loses and recovers its path, and finally absent once the origin withdraws one or offline once this side lets go of it, which says nothing of whether the origin still serves it. A broadcast already resolved stays on the old instance until dropped or its route goes. See [identity and recovery](/concept/identity) to choose between following and holding one instance. - **Discovery follows what you watch.** A client session asks the relay for announcements only under the prefixes its subscribe origin's readers watch, with `announced()`, `request`, or `follow`, stops asking about a prefix 2s after nothing at or beneath it is watched, and asks again on reconnect. A broadcast resolved through a discovered route keeps its path watched until dropped. `request` owns discovery of its path, so no separate watch is needed. A server session, or a client fed into an origin handle marked `with_link(origin::Link::Peer)` or `Link::Upstream`, asks for everything it may, so a relay discovers everything. An HTTP gateway (the moq-hls `Server`, the moq-webrtc WHEP router) watches its whole scope while it lives, so the paths its callers name never open a request each. moq-lite-03/04 sessions, whose announcements mark no initial set, still ask for everything. - **Relay by opting into proxying.** On moq-lite-07 (`moq-lite-07-wip`, opt-in) a session sends its peer only the routes to its origin's own claims, so an application never becomes transit for anyone else. A relay built on the library marks the handle it publishes with `origin.clone().with_proxy(true)` to carry what it learned from other peers too; `moq-relay` does so for every session. Older versions advertise everything either way. diff --git a/quest/m2/README.md b/quest/m2/README.md index 42df4d4cfa6..460bc3ae13d 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -36,8 +36,8 @@ removal, a rename, or a wire, catalog, or format change that is free until [switch](/quest/m2/multicast/switch.md) also settles the public route API and retires the moq-cluster draft. - **moq-net API.** [Groups](/quest/m2/group-api.md), - [reconnect](/quest/m2/reconnect-off.md), [names](/quest/m2/net-renames.md), - and [session codes](/quest/m2/session-codes.md). + [reconnect](/quest/m2/reconnect-off.md), and + [session codes](/quest/m2/session-codes.md). [Socket endpoints](/quest/m2/sockets/README.md) leave for Kixel, and the demos return to their earlier format. - **Unused API.** [One sweep per area](/quest/m2/unused-api/README.md), each diff --git a/quest/m2/cluster-routes/README.md b/quest/m2/cluster-routes/README.md index 120d0325e49..1e5f2f673c4 100644 --- a/quest/m2/cluster-routes/README.md +++ b/quest/m2/cluster-routes/README.md @@ -181,7 +181,7 @@ the bullets below are the contract it carries. Switching between paths resumes only across a matching explicit epoch. Keep administrative identity and broadcast epoch separate. A node names itself in paths by a hop fresh per process, since its session numbers - restart with it (`Router::new`); the origin's `Config::hop` is both that + restart with it (`Router::new`); the origin's `Config::node` is both that hop and its declared identity, so one set by hand must be fresh per process too. A random identity alone does not keep a dead incarnation away. What bounds it is ordered sessions, state scoped to the session that diff --git a/quest/m2/multicast/switch.md b/quest/m2/multicast/switch.md index 8984b7e6f4b..aeb4a036604 100644 --- a/quest/m2/multicast/switch.md +++ b/quest/m2/multicast/switch.md @@ -161,11 +161,9 @@ omission. All in `rs/moq-net/src/model/origin.rs`: value, which AGENTS.md forbids in public API. Crate-private. - Before hiding each, grep Kixel and moq.pro for a caller (the maintainer's condition for every unused-API removal) and keep what one uses. -- Two renames ride [the moq-net renames](/quest/m2/net-renames.md), not - this PR: `Config::hop` to `node`, and `with_preference` to `priority`. - Whichever lands second rebases; this PR must not reintroduce the old - names. The Route Offer's priority byte stays on the wire: the relay has - no key to set it yet, and +- `Config::hop` is now `node` and `with_preference` is `with_priority`; + this PR must not reintroduce the old names. The Route Offer's priority + byte stays on the wire: the relay has no key to set it yet, and [outbound federation](/quest/m3/cluster-routing/federation.md) adds one. - moq-ffi exposes only a route's `cost` and `available` (`rs/moq-ffi/src/origin.rs`), so no binding changes. diff --git a/quest/m2/net-renames.md b/quest/m2/net-renames.md deleted file mode 100644 index c0d08a2a2ca..00000000000 --- a/quest/m2/net-renames.md +++ /dev/null @@ -1,86 +0,0 @@ -# [S] moq-net's node, version, handshake, and route priority carry their wire names - -## Goal - -Four public moq-net names match what they name before the cut publishes them: - -- An origin's identity is its `node`: `origin::Config::node`, - `origin::Producer::node()`, and `origin::Consumer::node()` replace `hop`, - matching the Node ID the lite-07 wire and SETUP carry. -- `moq_net::Version` is an opaque type. A caller parses it, prints it, and - asks `is_lite()`, `alpn()`, and `as_str()`; no variant is public, so adding - or dropping a draft is never an API change. -- `Server::handshake(now, session)` replaces `Server::accept_request`. -- A route's rank is its `priority`, as the Route Offer's byte is named: - `origin::Producer::with_priority` and `origin::Priority` replace - `with_preference` and `Preference`. - -Each rename mirrors into `@moq/net` and the bindings wherever the name exists -there. - -## Plan - -Decided 2026-11-16 (maintainer, /quest-plan of the pre-cut audit): - -- ✅ `origin::Config::hop` becomes `node` (rejected: keeping `hop`). Hop - chains went private in the window, so `hop` is a word with no public - referent, and the wire says Node ID - (`rs/moq-net/src/lite/setup.rs`). -- ✅ `Version` becomes opaque (rejected: keeping the enum). Its variants hold - `lite::Version` and `ietf::Version`, and both modules are private - (`rs/moq-net/src/lib.rs:107,110`), so no caller can build or match a draft. -- ✅ `Server::accept_request` becomes `handshake` (rejected: keeping it). It - is named for a `Request` type that no longer exists and returns an `Accept` - that yields a `Handshake`. -- ✅ Route `with_preference` becomes `priority` (rejected: making it private - until federation needs it; keeping the name). The API says preference - while the wire and the draft say priority. - -Facts found by the audit, checked at `80ca9787e3`: - -- `hop` is public at `rs/moq-net/src/model/origin.rs:107` (the field), - `:2459`, and `:7483` (the accessors). `Client::with_peer_hop` and - `peer_hop` name the peer's identity the same way and are read by moq-tokio - (`rs/moq-tokio/src/connection.rs:967`) and moq-relay - (`rs/moq-relay/src/incoming.rs:88`). `origin::Config::max_hops` counts the - hops of a path and keeps its name; - [the route switch](/quest/m2/multicast/switch.md) marks it legacy. -- The one match on a `Version` variant outside moq-net is a test - (`rs/moq-relay/tests/integration/runtime_uring.rs:436`), which - `is_lite()` replaces. `rs/moq-net/AGENTS.md` already says to branch on - `is_lite()` and `alpn()` outside the crate. The relay also calls the - crate-level `Version::has_request_path` (`rs/moq-relay/src/cluster.rs:1779`, - `:2334`), which stays. -- `accept_request` (`rs/moq-net/src/server.rs:396`) has callers in 18 files - across moq-net, moq-relay, moq-tokio, and moq-uring. -- `with_preference` (`rs/moq-net/src/model/origin.rs:2390`) has no caller - outside moq-net and its integration tests; `doc/lib/rs/moq-net.md:21` - documents it for ranking several CDNs. Its planned consumer is - [outbound federation](/quest/m3/cluster-routing/federation.md), which adds - the relay's key for it. - -For the PR: - -- Rename `peer_hop` and `with_peer_hop` to `peer_node` and `with_peer_node` - in the same pass, so one word names an identity. The relay's - `cluster.node` key is a URL, not this number: keep them apart in docs, and - say in the PR if the collision argues for another word. -- `Version`: keep `ALL`, `FromStr`, `Display`, and serde as they are. If a - caller turns up that must tell one draft from another, add a method for - that question instead of exposing the variant. -- `origin::Priority` keeps `Preference`'s range and meaning (higher wins, 0 - is neutral, negative demotes). `track::Subscription` already has a - `priority`; say in the docs which is which. -- Update `doc/lib/rs/moq-net.md`, `doc/concept/moq-lite.md`, and each - package's `MIGRATE.md` note through the PR's Impact section. - -Public API: breaking renames in Rust (`origin::Config::hop`, the `hop()` -accessors, `peer_hop`, the `Version` variants, `Server::accept_request`, -`with_preference`, `Preference`) and wherever JS and the bindings mirror -them. Wire: none. - -## Related - -- [The route switch](/quest/m2/multicast/switch.md) - removes the route key beside the node identity this renames -- [Session close codes](/quest/m2/session-codes.md) - the other public moq-net cleanup in `error.rs` -- [Unused moq-net API](/quest/m2/unused-api/net.md) - makes the lite version predicates crate-private beside the opaque `Version` diff --git a/quest/m2/session-codes.md b/quest/m2/session-codes.md index 9f62cb040c0..72982b867b5 100644 --- a/quest/m2/session-codes.md +++ b/quest/m2/session-codes.md @@ -62,7 +62,3 @@ holds its pads on a lost source and fails on a refusal, as today. Public API: breaking in Rust (`SessionError` variants), moq-ffi (`MoqProtocolKind`), moq-c (`moq.h` constants), the wrappers, and JS; adds the classification method. Wire: none. - -## Related - -- [moq-net's node, version, handshake, and route priority](/quest/m2/net-renames.md) - the renames beside this in the same crate diff --git a/quest/m2/unused-api/net.md b/quest/m2/unused-api/net.md index 6ab781f3d9b..615a1064a8e 100644 --- a/quest/m2/unused-api/net.md +++ b/quest/m2/unused-api/net.md @@ -45,12 +45,10 @@ Items, each with the grep that showed no caller at `80ca9787e3` (over `rs`, resume keep using it inside the crate. - The 17 `pub fn` predicates of `lite::Version` (`rs/moq-net/src/lite/version.rs`, `has_track_stream` to `has_route_cost`): - make `pub(crate)`. They are reachable today only through the public - `Version::Lite` variant, and no caller exists outside moq-net; the relay - uses only the crate-level `Version::has_request_path`. Each would - otherwise be a public name to keep or break as lite-08 moves the cut-offs. - [The opaque `Version`](/quest/m2/net-renames.md) closes the same door from - the other side; either order works. + make `pub(crate)`. The opaque `Version` already closed the only public path + to them, the `Version::Lite` variant, so this only makes the module's own + visibility say so; the relay uses only the crate-level + `Version::has_request_path`. - `Recovery` (`rs/moq-net/src/lite/subscriber/fills.rs:691-695`) matches `Error::Decode(DecodeError::Short)` and then `matches!(err, Error::ProtocolViolation)` to tell a reset from malformed @@ -81,5 +79,4 @@ Public API: breaking, removals only (`Position::after`, `after_group`, ## Related -- [moq-net's node, version, handshake, and route priority](/quest/m2/net-renames.md) - makes `Version` opaque - [A group a subscriber gives up on is always reported](/quest/m2/group-drops.md) - gives the container reader the `Gap` that frees three more methods diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index 7b55eaeedf9..9f2fa052862 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -8036,7 +8036,7 @@ async fn request_accept_inherits_overrides_and_captures_origins() { let fresh = MoqOriginProducer::new(MoqOriginConfig::default()); let publish = override_publish.then(|| fresh.clone()); let consume = override_consume.then(|| fresh.clone()); - let expected_publish = publish.as_ref().unwrap_or(&default_publish).inner().hop(); + let expected_publish = publish.as_ref().unwrap_or(&default_publish).inner().node(); let expected_consume = consume.as_ref().unwrap_or(&default_consume).consume(); let captured = Arc::downgrade(&fresh); let server = MoqServer::new(MoqServerConfig { @@ -8087,7 +8087,7 @@ async fn request_accept_inherits_overrides_and_captures_origins() { kio::clock::timeout(TIMEOUT, hold).await.unwrap().unwrap().unwrap(); let session = kio::clock::timeout(TIMEOUT, accept).await.unwrap().unwrap().unwrap(); let client_session = kio::clock::timeout(TIMEOUT, connect).await.unwrap().unwrap().unwrap(); - assert_eq!(session.publish().inner().hop(), expected_publish); + assert_eq!(session.publish().inner().node(), expected_publish); // Incoming broadcasts reach the selected consume origin, independently // of which publish side was selected. diff --git a/rs/moq-net/benches/auth.rs b/rs/moq-net/benches/auth.rs index 22c5b2cd459..d22f36f1870 100644 --- a/rs/moq-net/benches/auth.rs +++ b/rs/moq-net/benches/auth.rs @@ -55,7 +55,7 @@ async fn pair(origins: Option>) -> Pair { if let Some(origins) = &origins { config = config.with_subscriber(origins.subscribe.clone()); } - let mut request = config.accept_request(harness::now(), server).await.unwrap(); + let mut request = config.handshake(harness::now(), server).await.unwrap(); let requests = request.requests(); let (session, driver) = request.ok().await.unwrap(); harness::spawn(driver); @@ -143,7 +143,7 @@ async fn publisher(origin: &origin::Producer) -> (Session, Session, auth::Reques .with_versions(version.into()) .with_extensions(server_extensions) .with_subscriber(subscribe.clone()) - .accept_request(harness::now(), server) + .handshake(harness::now(), server) .await .unwrap(); let requests = request.requests(); diff --git a/rs/moq-net/src/client.rs b/rs/moq-net/src/client.rs index 43e87ec89f5..1a3958028db 100644 --- a/rs/moq-net/src/client.rs +++ b/rs/moq-net/src/client.rs @@ -21,7 +21,7 @@ pub struct Client { url: Option, setup_token: Option, cost: Option, - peer_hop: Option, + peer_node: Option, limits: crate::session::Limits, extensions: setup::Extensions, auth: Option, @@ -237,24 +237,24 @@ impl Client { self } - /// Assign the hop id this peer's routes are attributed to, overriding the fresh + /// Assign the Node ID this peer's routes are attributed to, overriding the fresh /// per-dial default. /// - /// A dialed session whose peer declares no hop gets a random one for that + /// A dialed session whose peer declares no Node ID gets a random one for that /// connection, the same way an accepted session does. That keeps a route /// learned from the peer off the session that learned it, and keeps a /// SUBSCRIBE that arrives on it from being routed back to it. An identity the /// peer declares on the wire still wins. /// /// Pass an id only for a peer whose identity the caller has actually - /// established. Two dials given the same hop are treated as one endpoint: + /// established. Two dials given the same node are treated as one endpoint: /// routes learned from either are kept off both, and content arriving on /// either is interchangeable with the other's. That is the point when they /// really are one peer reconnecting or running redundant links, and a bug /// otherwise. Derive it from the authenticated identity, never from something /// coarser like the remote address. - pub fn with_peer_hop(mut self, hop: std::num::NonZeroU64) -> Self { - self.peer_hop = Some(hop); + pub fn with_peer_node(mut self, node: std::num::NonZeroU64) -> Self { + self.peer_node = Some(node); self } @@ -264,7 +264,7 @@ impl Client { /// connection gets a fresh one, matching the per-session default an accepted /// session already has. fn assigned_hop(&self) -> crate::Hop { - self.peer_hop.map_or_else(crate::Hop::random, crate::Hop::from) + self.peer_node.map_or_else(crate::Hop::random, crate::Hop::from) } /// The new session's side of its auth handle: the one from [`with_auth`](Self::with_auth), @@ -282,12 +282,12 @@ impl Client { /// Reads through the publish (egress) consumer and writes through the /// subscribe (ingress) producer are attributed by the model through the /// stats context; one shared context, so presence and viewer counts are - /// never double-attributed across the two halves. `peer_hop` is the identity + /// never double-attributed across the two halves. `peer_node` is the identity /// this connection attributes the peer to when the peer declares none, so /// subscriptions from the peer resolve to a source whose route excludes it. /// A declared identity still wins inside each publisher; announce filtering /// is per-protocol and handled there too. - fn origins(&self, peer_hop: crate::Hop) -> (Option, Option) { + fn origins(&self, peer_node: crate::Hop) -> (Option, Option) { if self.publish.is_none() && self.subscribe.is_none() { tracing::warn!("not publishing or consuming anything"); } @@ -296,7 +296,7 @@ impl Client { .subscribe .clone() .map(|origin| origin.with_stats(self.stats.clone())); - let publish = publish.map(|origin| origin.excluding(peer_hop)); + let publish = publish.map(|origin| origin.excluding(peer_node)); (publish, subscribe) } @@ -307,9 +307,9 @@ impl Client { runtime: Deadlines, session: Transport, version: lite::Version, - peer_hop: crate::Hop, + peer_node: crate::Hop, ) -> Result<(Session, crate::Driver), Error> { - let (publish, subscribe) = self.origins(peer_hop); + let (publish, subscribe) = self.origins(peer_node); // Advertise our capabilities (we report what the transport measures, and // probe to the peer's target only with a sender) plus the request path on @@ -351,7 +351,7 @@ impl Client { setup_stream: None, publish, subscribe, - peer_hop: Some(peer_hop), + peer_node: Some(peer_node), version, our_setup, peer_setup: None, @@ -406,8 +406,8 @@ impl Client { /// Start the session the transport's ALPN picks, or begin negotiating moq-lite on a bidi /// SETUP when it picks none. fn start(&self, runtime: Deadlines, session: Transport) -> Result { - let peer_hop = self.assigned_hop(); - let (publish, subscribe) = self.origins(peer_hop); + let peer_node = self.assigned_hop(); + let (publish, subscribe) = self.origins(peer_node); let supported = match session.protocol() { Some(alpn @ (ALPN_22 | ALPN_20 | ALPN_18)) => { @@ -417,7 +417,7 @@ impl Client { _ => ietf::Version::Draft18, }; - let v = self.versions.select(Version::Ietf(draft)).ok_or(Error::Version)?; + let v = self.versions.select(Version::ietf(draft)).ok_or(Error::Version)?; // SETUP is exchanged by the connection driver. // We advertise the request path in our SETUP for URL-less transports. @@ -432,7 +432,7 @@ impl Client { client: true, publish, subscribe, - peer_hop: Some(peer_hop), + peer_node: Some(peer_node), cost: self.cost, version: draft, path: self.setup_path(session.address()), @@ -474,25 +474,25 @@ impl Client { ALPN_LITE_06 => lite::Version::Lite06, _ => lite::Version::Lite05, }; - self.versions.select(Version::Lite(version)).ok_or(Error::Version)?; + self.versions.select(Version::lite(version)).ok_or(Error::Version)?; return self - .start_lite(runtime, session, version, peer_hop) + .start_lite(runtime, session, version, peer_node) .map(|started| Connect::Started(Box::new(started))); } Some(ALPN_LITE_04) => { self.versions - .select(Version::Lite(lite::Version::Lite04)) + .select(Version::lite(lite::Version::Lite04)) .ok_or(Error::Version)?; return self - .start_lite(runtime, session, lite::Version::Lite04, peer_hop) + .start_lite(runtime, session, lite::Version::Lite04, peer_node) .map(|started| Connect::Started(Box::new(started))); } Some(ALPN_LITE_03) => { self.versions - .select(Version::Lite(lite::Version::Lite03)) + .select(Version::lite(lite::Version::Lite03)) .ok_or(Error::Version)?; return self - .start_lite(runtime, session, lite::Version::Lite03, peer_hop) + .start_lite(runtime, session, lite::Version::Lite03, peer_node) .map(|started| Connect::Started(Box::new(started))); } // No ALPN, or `moql`: negotiate moq-lite in a bidi SETUP. @@ -504,7 +504,7 @@ impl Client { negotiation: Negotiation { runtime, session, - peer_hop, + peer_node, publish, subscribe, supported, @@ -523,7 +523,7 @@ impl Client { let Negotiation { runtime, session, - peer_hop, + peer_node, publish, subscribe, .. @@ -541,7 +541,7 @@ impl Client { setup_stream: Some(stream), publish, subscribe, - peer_hop: Some(peer_hop), + peer_node: Some(peer_node), version, // Lite 01/02 continue on the bidi SETUP stream and have no Setup Stream. our_setup: lite::Setup::default(), @@ -553,7 +553,7 @@ impl Client { Ok(Session::new( runtime, session, - Version::Lite(version), + Version::lite(version), start.recv_bandwidth, crate::driver::Protocol::Lite(Box::new(start.driver)), crate::session::Handles { @@ -576,7 +576,7 @@ impl Client { struct Negotiation { runtime: Deadlines, session: Transport, - peer_hop: crate::Hop, + peer_node: crate::Hop, publish: Option, subscribe: Option, /// The versions offered in the client SETUP. @@ -648,7 +648,7 @@ impl Connect { let stream = ready!(Stream::poll_open( &negotiation.session, open, - Version::Lite(lite::Version::Lite01), + Version::lite(lite::Version::Lite01), waiter ))?; let mut stream = stream.with_stats(&client.stats); @@ -671,13 +671,13 @@ impl Connect { .find(|v| coding::Version::from(**v) == server.version) .copied() .ok_or(Error::Version)?; - let Version::Lite(version) = version else { + let Version(crate::Draft::Lite(version)) = version else { return Poll::Ready(Err(Error::Version)); }; let Self::Exchange { negotiation, stream } = std::mem::replace(self, Self::Done) else { unreachable!("matched above"); }; - if !Version::Lite(version).hands_off() { + if !Version::lite(version).hands_off() { return Poll::Ready(client.start_negotiated(negotiation, stream, version)); } *self = Self::HandOff { @@ -701,10 +701,10 @@ impl Connect { let Negotiation { runtime, session, - peer_hop, + peer_node, .. } = negotiation; - return Poll::Ready(client.start_lite(runtime, session, version, peer_hop)); + return Poll::Ready(client.start_lite(runtime, session, version, peer_node)); } Self::Done => panic!("handshake polled after it resolved"), } @@ -1002,12 +1002,12 @@ mod tests { } async fn run_alpn_lite_fallback_case(protocol: Option<&'static str>) { - let fake = FakeSession::new(protocol, mock_server_setup(Version::Lite(lite::Version::Lite01))); + let fake = FakeSession::new(protocol, mock_server_setup(Version::lite(lite::Version::Lite01))); let client = Client::new().with_versions( [ - Version::Lite(lite::Version::Lite03), - Version::Lite(lite::Version::Lite02), - Version::Lite(lite::Version::Lite01), + Version::lite(lite::Version::Lite03), + Version::lite(lite::Version::Lite02), + Version::lite(lite::Version::Lite01), ] .into(), ); @@ -1018,7 +1018,7 @@ mod tests { // Verify the client offered every configured moq-lite version over the `moql` SETUP. let mut setup_bytes = Bytes::from(fake.control_writes()); - let setup = crate::coding::decode_buf(&mut setup_bytes, Version::Lite(lite::Version::Lite02), |r, v| { + let setup = crate::coding::decode_buf(&mut setup_bytes, Version::lite(lite::Version::Lite02), |r, v| { setup::Client::decode(r, v) }) .unwrap(); @@ -1026,9 +1026,9 @@ mod tests { assert_eq!( advertised, vec![ - Version::Lite(lite::Version::Lite03), - Version::Lite(lite::Version::Lite02), - Version::Lite(lite::Version::Lite01), + Version::lite(lite::Version::Lite03), + Version::lite(lite::Version::Lite02), + Version::lite(lite::Version::Lite01), ] ); @@ -1058,7 +1058,7 @@ mod tests { // A subscribe origin is what makes the client open an announce stream at all. let origin = crate::origin::Config::new(std::num::NonZeroU64::new(1).unwrap()).produce(); let client = Client::new() - .with_versions([Version::Lite(lite::Version::Lite05)].into()) + .with_versions([Version::lite(lite::Version::Lite05)].into()) .with_subscriber(origin); // Paused time auto-advances while every task is idle, so a `connect` that waits @@ -1161,11 +1161,11 @@ mod tests { #[test] fn driver_is_caller_polled_and_holds_no_session() { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); - let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); + let client = Client::new().with_versions(Version::lite(lite::Version::Lite04).into()); let runtime = crate::time::Deadlines::new(crate::time::Instant::now()); let (session, mut driver) = futures::executor::block_on(client.connect(runtime.now(), fake.clone())).unwrap(); - assert_eq!(session.version(), Version::Lite(lite::Version::Lite04)); + assert_eq!(session.version(), Version::lite(lite::Version::Lite04)); // Construction leaves the driver idle until the caller polls it. assert!(driver.poll(runtime.now(), &kio::Waiter::noop()).is_ok()); @@ -1184,7 +1184,7 @@ mod tests { #[test] fn session_clones_share_the_close() { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); - let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); + let client = Client::new().with_versions(Version::lite(lite::Version::Lite04).into()); let runtime = crate::time::Deadlines::new(crate::time::Instant::now()); let (session, mut driver) = futures::executor::block_on(client.connect(runtime.now(), fake.clone())).unwrap(); @@ -1221,7 +1221,7 @@ mod tests { let registry = Registry::new(Default::default()); let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); let client = Client::new() - .with_versions(Version::Lite(lite::Version::Lite04).into()) + .with_versions(Version::lite(lite::Version::Lite04).into()) .with_stats( registry .tier(Tier::default()) @@ -1257,7 +1257,7 @@ mod tests { use crate::transport::poll::Session as _; let registry = Registry::new(Default::default()); let client = Client::new() - .with_versions(Version::Lite(lite::Version::Lite04).into()) + .with_versions(Version::lite(lite::Version::Lite04).into()) .with_stats( registry .tier(Tier::default()) @@ -1288,7 +1288,7 @@ mod tests { fn dropped_driver_resolves_closed() { for polled in [false, true] { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); - let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); + let client = Client::new().with_versions(Version::lite(lite::Version::Lite04).into()); let runtime = crate::time::Deadlines::new(crate::time::Instant::now()); let (session, mut driver) = futures::executor::block_on(client.connect(runtime.now(), fake)).unwrap(); if polled { @@ -1302,7 +1302,7 @@ mod tests { #[test] fn driver_panic_is_published_before_the_executor_drops_it() { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); - let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); + let client = Client::new().with_versions(Version::lite(lite::Version::Lite04).into()); let runtime = crate::time::Deadlines::new(crate::time::Instant::now()); let (session, mut driver) = futures::executor::block_on(client.connect(runtime.now(), fake.clone())).unwrap(); fake.state @@ -1336,7 +1336,7 @@ mod tests { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); fake.set_send_rate(Some(1_000_000)); - let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); + let client = Client::new().with_versions(Version::lite(lite::Version::Lite04).into()); let (session, driver) = client.connect(kio::clock::now(), fake.clone()).await.unwrap(); kio::clock::sim::spawn(crate::time::run(driver)); @@ -1366,7 +1366,7 @@ mod tests { fake.set_send_rate(None); fake.set_sent_bytes(0); - let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); + let client = Client::new().with_versions(Version::lite(lite::Version::Lite04).into()); let (session, driver) = client.connect(kio::clock::now(), fake.clone()).await.unwrap(); kio::clock::sim::spawn(crate::time::run(driver)); assert!( @@ -1394,7 +1394,7 @@ mod tests { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); fake.set_send_rate(Some(1_000_000)); - let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); + let client = Client::new().with_versions(Version::lite(lite::Version::Lite04).into()); let (session, driver) = client.connect(kio::clock::now(), fake.clone()).await.unwrap(); let mut bandwidth = session.send_bandwidth().expect("backend reports an estimate"); assert_eq!( @@ -1438,7 +1438,7 @@ mod tests { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()).with_probe(); fake.set_send_rate(Some(1_000_000)); - let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); + let client = Client::new().with_versions(Version::lite(lite::Version::Lite04).into()); let (session, driver) = client.connect(kio::clock::now(), fake.clone()).await.unwrap(); kio::clock::sim::spawn(crate::time::run(driver)); let bandwidth = session.allocator(); @@ -1466,7 +1466,7 @@ mod tests { #[kio::test] async fn an_override_replaces_the_reservations() { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()).with_probe(); - let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); + let client = Client::new().with_versions(Version::lite(lite::Version::Lite04).into()); let (session, driver) = client.connect(kio::clock::now(), fake.clone()).await.unwrap(); kio::clock::sim::spawn(crate::time::run(driver)); let bandwidth = session.allocator(); @@ -1491,7 +1491,7 @@ mod tests { async fn a_reconnect_keeps_following_the_reservations() { let bandwidth = crate::bandwidth::Allocator::default(); let client = Client::new() - .with_versions(Version::Lite(lite::Version::Lite04).into()) + .with_versions(Version::lite(lite::Version::Lite04).into()) .with_allocator(bandwidth.clone()); let (_broadcast, track) = reservable(); diff --git a/rs/moq-net/src/coding/codes.rs b/rs/moq-net/src/coding/codes.rs index 59f74bf43dd..4ab8833c24a 100644 --- a/rs/moq-net/src/coding/codes.rs +++ b/rs/moq-net/src/coding/codes.rs @@ -74,23 +74,23 @@ impl StreamCodes for ietf::Version { /// pre-lite-05 session opens. impl StreamCodes for crate::Version { fn decode_session_code(&self, code: u32) -> crate::SessionError { - match self { - Self::Lite(version) => version.decode_session_code(code), - Self::Ietf(version) => version.decode_session_code(code), + match self.0 { + crate::Draft::Lite(version) => version.decode_session_code(code), + crate::Draft::Ietf(version) => version.decode_session_code(code), } } fn encode_stream_code(&self, err: &StreamError) -> u32 { - match self { - Self::Lite(version) => version.encode_stream_code(err), - Self::Ietf(version) => version.encode_stream_code(err), + match self.0 { + crate::Draft::Lite(version) => version.encode_stream_code(err), + crate::Draft::Ietf(version) => version.encode_stream_code(err), } } fn decode_stream_code(&self, code: u32) -> StreamError { - match self { - Self::Lite(version) => version.decode_stream_code(code), - Self::Ietf(version) => version.decode_stream_code(code), + match self.0 { + crate::Draft::Lite(version) => version.decode_stream_code(code), + crate::Draft::Ietf(version) => version.decode_stream_code(code), } } } @@ -104,8 +104,8 @@ mod tests { /// wire, and the same number read back on each wire has to mean what that wire said. #[test] fn the_version_picks_the_registry() { - let lite = crate::Version::Lite(lite::Version::Lite05); - let ietf = crate::Version::Ietf(ietf::Version::Draft22); + let lite = crate::Version::lite(lite::Version::Lite05); + let ietf = crate::Version::ietf(ietf::Version::Draft22); assert_eq!(lite.encode_stream_code(&StreamError::Old), StreamError::Old.to_code()); assert_eq!(ietf.encode_stream_code(&StreamError::Old), ietf::error::INTERNAL_ERROR); diff --git a/rs/moq-net/src/coding/reader.rs b/rs/moq-net/src/coding/reader.rs index 3d06c29b81b..0c2489746c6 100644 --- a/rs/moq-net/src/coding/reader.rs +++ b/rs/moq-net/src/coding/reader.rs @@ -926,8 +926,8 @@ mod tests { ietf::GoAway::decode(r, ietf::Version::Draft22).map(|_| ()) }); for version in [lite::Version::Lite01, lite::Version::Lite02] { - refuses_frame::(&[0x20, 0, 0], Version::Lite(version), false); - refuses_frame::(&[0x21, 0, 0], Version::Lite(version), false); + refuses_frame::(&[0x20, 0, 0], Version::lite(version), false); + refuses_frame::(&[0x21, 0, 0], Version::lite(version), false); } } @@ -948,12 +948,12 @@ mod tests { let mut prefix = vec![0x20]; Encoder::new(&mut prefix, version.into()).varint(65535).unwrap(); assert!(matches!( - setup::Client::decode_slice(&prefix, Version::Lite(version)), + setup::Client::decode_slice(&prefix, Version::lite(version)), Err(DecodeError::Short) )); prefix[0] = 0x21; assert!(matches!( - setup::Server::decode_slice(&prefix, Version::Lite(version)), + setup::Server::decode_slice(&prefix, Version::lite(version)), Err(DecodeError::Short) )); } diff --git a/rs/moq-net/src/coding/varint.rs b/rs/moq-net/src/coding/varint.rs index a89e397db3e..3966df2bdf3 100644 --- a/rs/moq-net/src/coding/varint.rs +++ b/rs/moq-net/src/coding/varint.rs @@ -7,7 +7,7 @@ use thiserror::Error; use super::{DecodeError, EncodeError}; -use crate::{Version, ietf, lite}; +use crate::{Draft, Version, ietf, lite}; /// The number does not fit the target: a varint wire form or a narrower integer. #[derive(Debug, Copy, Clone, Eq, PartialEq, Error)] @@ -55,8 +55,8 @@ impl From for Form { impl From for Form { fn from(version: Version) -> Self { match version { - Version::Lite(v) => v.into(), - Version::Ietf(v) => v.into(), + Version(Draft::Lite(v)) => v.into(), + Version(Draft::Ietf(v)) => v.into(), } } } diff --git a/rs/moq-net/src/coding/writer.rs b/rs/moq-net/src/coding/writer.rs index 9236294e349..8b844586639 100644 --- a/rs/moq-net/src/coding/writer.rs +++ b/rs/moq-net/src/coding/writer.rs @@ -567,11 +567,11 @@ mod tests { async fn raw_payload_stop_uses_the_negotiated_registry() { for (version, expected) in [ ( - crate::Version::Ietf(crate::ietf::Version::Draft22), + crate::Version::ietf(crate::ietf::Version::Draft22), Error::Stream(crate::StreamError::GoingAway), ), ( - crate::Version::Lite(crate::lite::Version::Lite05), + crate::Version::lite(crate::lite::Version::Lite05), Error::Stream(crate::StreamError::GoingAway), ), ] { diff --git a/rs/moq-net/src/fuzz.rs b/rs/moq-net/src/fuzz.rs index 39fb2b122e6..66ad53cfea9 100644 --- a/rs/moq-net/src/fuzz.rs +++ b/rs/moq-net/src/fuzz.rs @@ -421,8 +421,8 @@ pub fn lite_wire(data: &[u8]) -> bool { 25 => roundtrip::(rest, &mut Vec::new(), version), 26 => roundtrip::(rest, &mut Vec::new(), version), 27 => roundtrip::(rest, &mut Vec::new(), version), - 28 => roundtrip::(rest, &mut Vec::new(), crate::Version::Lite(version)), - 29 => roundtrip::(rest, &mut Vec::new(), crate::Version::Lite(version)), + 28 => roundtrip::(rest, &mut Vec::new(), crate::Version::lite(version)), + 29 => roundtrip::(rest, &mut Vec::new(), crate::Version::lite(version)), 30 => roundtrip::, _>(rest, &mut Vec::new(), version), 31 => roundtrip::(rest, &mut Vec::new(), version), 32 => roundtrip::(rest, &mut Vec::new(), version), @@ -1605,7 +1605,7 @@ fn setup<'a, T>(data: &'a [u8], scratch: &'a mut Vec, version: ietf::Version where T: Decode<'a, crate::Version> + Encode, { - let outer = crate::Version::Ietf(version); + let outer = crate::Version::ietf(version); if let Ok((message, _)) = T::decode_slice(data, outer) { let parameters = parameters(&message); if ietf::decode_peer_setup(parameters, version, true).is_ok() { @@ -2189,7 +2189,7 @@ pub fn seeds() -> Vec { // SETUP has its own type prefix, which uniform bodies cannot synthesize. for (index, version) in IETF_VERSIONS.iter().enumerate() { - let outer = crate::Version::Ietf(*version); + let outer = crate::Version::ietf(*version); let parameters = ietf::Parameters::default().encode_bytes(*version).unwrap(); let messages = vec![(26, crate::setup::Setup { parameters }.encode_bytes(outer).unwrap())]; for (kind, message) in messages { @@ -2205,7 +2205,7 @@ pub fn seeds() -> Vec { // The `moql` SETUP pair, framed as lite-01/02, also has its own type prefix. for (index, version) in LITE_VERSIONS.iter().enumerate() { - let outer = crate::Version::Lite(*version); + let outer = crate::Version::lite(*version); let client = crate::setup::Client { versions: coding::Versions::from([outer.into()]), parameters: Default::default(), diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index e62d9bcc764..d3776f54686 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -939,10 +939,10 @@ pub(super) struct Publisher { // which is what makes cross-session loop detection work. self_origin: crate::Hop, // The identity assigned to the peer (a fresh per-session id, or one the caller - // pinned with `with_peer_hop`), used when the peer declares + // pinned with `with_peer_node`), used when the peer declares // none itself. A peer that negotiates the MoQ Cluster extension declares its own, // which wins unless it withheld it as the reserved 0. - peer_hop: Option, + peer_node: Option, // What the peer declared in its SETUP, filled when that stream is read. peer_setup: peer::PeerSetup, // Shared across request handlers; None marks a dispatched subscription still resolving. @@ -2820,7 +2820,7 @@ impl Publisher { session: Transport, origin: origin::Consumer, control: Control, - peer_hop: Option, + peer_node: Option, peer_setup: peer::PeerSetup, version: Version, ) -> Self { @@ -2828,11 +2828,11 @@ impl Publisher { withdrawal: Default::default(), runtime, session, - self_origin: crate::Hop::from(origin.hop()), + self_origin: crate::Hop::from(origin.node()), // Serving the peer is not a local reader asking to discover anything. origin: origin.serving(), control, - peer_hop, + peer_node, peer_setup, joins: Default::default(), version, @@ -2919,12 +2919,12 @@ impl Publisher { /// The Hop ID whose paths must not be advertised (or served) back to this peer. /// /// A peer that declared an identity supplies its own; otherwise fall back to the one - /// we assigned it (a fresh per-session id, or one pinned with `Client::with_peer_hop` - /// or `Request::with_peer_hop`), since moq-transport carries no identity + /// we assigned it (a fresh per-session id, or one pinned with `Client::with_peer_node` + /// or `Request::with_peer_node`), since moq-transport carries no identity /// of its own. A peer that declared the reserved 0 declared no identity, so it takes /// the fallback like any other anonymous peer. fn exclude(&self, peer: &cluster::Peer) -> crate::Hop { - peer.identity().or(self.peer_hop).unwrap_or(crate::Hop::UNKNOWN) + peer.identity().or(self.peer_node).unwrap_or(crate::Hop::UNKNOWN) } /// Pick what to advertise to this peer for one route. @@ -18714,7 +18714,7 @@ mod tests { } /// A broadcast whose every route flows through the peer's assigned identity - /// (`Client::with_peer_hop`) is never advertised to that peer; it would only + /// (`Client::with_peer_node`) is never advertised to that peer; it would only /// echo the peer's own content back at it. A broadcast with an independent /// route still is. #[kio::test] diff --git a/rs/moq-net/src/ietf/session.rs b/rs/moq-net/src/ietf/session.rs index 9f0a07cef7d..69ed87867aa 100644 --- a/rs/moq-net/src/ietf/session.rs +++ b/rs/moq-net/src/ietf/session.rs @@ -40,9 +40,9 @@ pub struct Config { pub subscribe: Option, /// The origin (hop) id to assign the peer when it declares none itself. See - /// `Client::with_peer_hop`; a peer that negotiates the MoQ Cluster extension + /// `Client::with_peer_node`; a peer that negotiates the MoQ Cluster extension /// declares its own, which wins. - pub peer_hop: Option, + pub peer_node: Option, /// What crossing this link costs. Declared in our SETUP (see /// [`cluster::RELAY_COST`]) for the peer to charge, and charged locally on what the @@ -165,7 +165,7 @@ pub fn start(config: Config) -> Result<(Driver, crate::goaway::Handle), Error> { client, publish, subscribe, - peer_hop, + peer_node, cost, version, path, @@ -219,7 +219,7 @@ pub fn start(config: Config) -> Result<(Driver, crate::goaway::Handle), Error> { client, publish, subscribe, - peer_hop, + peer_node, cost, version, setup: SetupParams { @@ -261,7 +261,7 @@ struct Launch { client: bool, publish: Option, subscribe: Option, - peer_hop: Option, + peer_node: Option, cost: Option, version: Version, setup: SetupParams, @@ -286,7 +286,7 @@ impl Launch { client, publish, subscribe, - peer_hop, + peer_node, cost, version, setup, @@ -343,7 +343,7 @@ impl Launch { session.clone(), publish, control.clone(), - peer_hop, + peer_node, peer_setup.clone(), version, ) @@ -363,7 +363,7 @@ impl Launch { session.clone(), subscribe, control.clone(), - peer_hop, + peer_node, peer_setup.clone(), self_origin, cost, @@ -620,8 +620,8 @@ pub struct PeerSetup { /// has no content to route, so a throwaway id is all it can offer. fn self_origin(publish: Option<&origin::Consumer>, subscribe: Option<&origin::Producer>) -> Hop { publish - .map(|origin| origin.hop()) - .or_else(|| subscribe.map(|origin| origin.hop())) + .map(|origin| origin.node()) + .or_else(|| subscribe.map(|origin| origin.node())) .map_or_else(Hop::random, Hop::from) } @@ -676,7 +676,7 @@ impl SetupAccept { } SetupStep::Accept => { let recv = ready!(session.poll_accept_uni(waiter)).map_err(Error::from_transport)?; - self.step = SetupStep::Peek(Reader::new(recv, crate::Version::Ietf(self.version))); + self.step = SetupStep::Peek(Reader::new(recv, crate::Version::ietf(self.version))); } SetupStep::Peek(reader) => { let kind = match ready!(reader.poll_varint_peek(waiter)) { @@ -895,7 +895,7 @@ impl SendSetup { unreachable!("matched above"); }; let mut writer: Writer = - Writer::new(send, crate::Version::Ietf(self.version)).with_stats(&self.stats); + Writer::new(send, crate::Version::ietf(self.version)).with_stats(&self.stats); let parameters = self.parameters(params)?; writer .buffer(&setup::Setup { parameters }) @@ -1071,7 +1071,7 @@ impl Unis { let reader = match self.early.pop_front() { Some(reader) => reader, None => match self.session.poll_accept_uni(waiter) { - Poll::Ready(Ok(recv)) => Reader::new(recv, crate::Version::Ietf(self.uni.version)), + Poll::Ready(Ok(recv)) => Reader::new(recv, crate::Version::ietf(self.uni.version)), Poll::Ready(Err(err)) => { self.ended = Some(Error::from_transport(err)); break; @@ -1821,7 +1821,7 @@ mod tests { client: true, publish: None, subscribe: Some(origin), - peer_hop: None, + peer_node: None, cost: None, version, path: None, @@ -1931,7 +1931,7 @@ mod tests { client: true, publish: None, subscribe: Some(origin), - peer_hop: None, + peer_node: None, cost: None, version: VERSION, path: None, @@ -1997,7 +1997,7 @@ mod tests { client: true, publish: None, subscribe: Some(scoped), - peer_hop: None, + peer_node: None, cost: None, version: Version::Draft18, path: None, @@ -2091,7 +2091,7 @@ mod tests { client: true, publish: None, subscribe: Some(subscribe), - peer_hop: None, + peer_node: None, cost: None, version, path: None, @@ -2250,7 +2250,7 @@ mod tests { client: true, publish: Some(origin.consume()), subscribe: None, - peer_hop: None, + peer_node: None, cost: None, version: Version::Draft18, path: None, @@ -2345,7 +2345,7 @@ mod tests { client: true, publish: Some(origin.consume()), subscribe: None, - peer_hop: None, + peer_node: None, cost: None, version: Version::Draft18, path: None, @@ -2410,7 +2410,7 @@ mod tests { client: true, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, cost: None, version: VERSION, path: None, @@ -2432,7 +2432,7 @@ mod tests { .expect_err("the session ended instead of parking after SETUP"); let writes = log.writes.lock().unwrap().clone(); - let (setup, _) = setup::Setup::decode_slice(&writes, crate::Version::Ietf(VERSION)).expect("our SETUP"); + let (setup, _) = setup::Setup::decode_slice(&writes, crate::Version::ietf(VERSION)).expect("our SETUP"); let (params, _) = ietf::Parameters::decode_slice(&setup.parameters, VERSION).expect("its options"); solicit::from_setup(¶ms, VERSION).unwrap() == Some(true) } @@ -2493,7 +2493,7 @@ mod tests { client: true, publish: None, subscribe: Some(origin), - peer_hop: None, + peer_node: None, cost: None, version: VERSION, path: None, @@ -2540,7 +2540,7 @@ mod tests { client: true, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, cost: None, version, path: None, @@ -2911,7 +2911,7 @@ mod tests { client: true, publish, subscribe: None, - peer_hop: None, + peer_node: None, cost: None, version: Version::Draft18, path: None, @@ -2977,7 +2977,7 @@ mod tests { } .encode( &mut crate::coding::Encoder::new(&mut setup, VERSION.into()), - crate::Version::Ietf(VERSION), + crate::Version::ietf(VERSION), ) .unwrap(); @@ -3039,7 +3039,7 @@ mod tests { client: false, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, cost: None, version, path: None, @@ -3108,7 +3108,7 @@ mod tests { client: false, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, cost: None, version, path: None, @@ -3195,7 +3195,7 @@ mod tests { client: false, publish: Some(origin.consume()), subscribe: None, - peer_hop: None, + peer_node: None, cost: None, version, path: None, @@ -3243,7 +3243,7 @@ mod tests { } .encode( &mut crate::coding::Encoder::new(&mut buf, version.into()), - crate::Version::Ietf(version), + crate::Version::ietf(version), ) .unwrap(); buf.extend_from_slice(after); @@ -3436,7 +3436,7 @@ mod tests { client: true, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, cost: None, version: VERSION, path: None, @@ -3545,7 +3545,7 @@ mod tests { client, publish: Some(origin.consume()), subscribe: None, - peer_hop: None, + peer_node: None, cost: None, version, path: None, diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index eb1ada63d65..e213d98577c 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -1124,7 +1124,7 @@ pub(super) struct Subscriber { // declares none of its own (see `session_route`). Base moq-transport carries no // hop ids, so a peer only has an identity if it negotiated the MoQ Cluster // extension; otherwise this is the one the session assigned it (a fresh id per - // dialed or accepted session, unless the caller pinned one with `with_peer_hop`), + // dialed or accepted session, unless the caller pinned one with `with_peer_node`), // or `Hop::UNKNOWN` (0) when none was assigned. // // The assigned id stays local: it is never written into a hop chain, so a peer @@ -1236,7 +1236,7 @@ impl Subscriber { session: Transport, origin: origin::Producer, control: Control, - peer_hop: Option, + peer_node: Option, peer_setup: peer::PeerSetup, self_origin: crate::Hop, cost: Option, @@ -1250,7 +1250,7 @@ impl Subscriber { // Its own frame budget, so a peer's declared sizes crowd out no other session. origin: origin.with_own_frames(), control, - session_origin: peer_hop.unwrap_or(crate::Hop::UNKNOWN), + session_origin: peer_node.unwrap_or(crate::Hop::UNKNOWN), self_origin, peer_setup, solicit: true, @@ -11035,7 +11035,7 @@ mod tests { } /// moq-transport carries no hop ids, so a peer's broadcasts are marked - /// anonymous (hop 0). An identity assigned via `Client::with_peer_hop` is + /// anonymous (hop 0). An identity assigned via `Client::with_peer_node` is /// stored as `via` for split-horizon and never written into the chain. #[kio::test] async fn assigned_peer_hop_attributes_announces() { @@ -11091,7 +11091,7 @@ mod tests { let mut announced = consumer.routes(); // The publish direction: an origin handle scoped to the peer, which is what - // `Client::with_peer_hop` hands the publisher. Holding its announce stream + // `Client::with_peer_node` hands the publisher. Holding its announce stream // is what records that the peer has been offered these paths. let mut publishing = consumer.clone().excluding(peer).routes(); diff --git a/rs/moq-net/src/ietf/version.rs b/rs/moq-net/src/ietf/version.rs index 85a226afb63..a9c71b829cf 100644 --- a/rs/moq-net/src/ietf/version.rs +++ b/rs/moq-net/src/ietf/version.rs @@ -21,7 +21,7 @@ impl fmt::Display for Version { impl From for crate::Version { fn from(v: Version) -> Self { - crate::Version::Ietf(v) + crate::Version::ietf(v) } } @@ -29,9 +29,9 @@ impl TryFrom for Version { type Error = (); fn try_from(v: crate::Version) -> Result { - match v { - crate::Version::Ietf(v) => Ok(v), - crate::Version::Lite(_) => Err(()), + match v.0 { + crate::Draft::Ietf(v) => Ok(v), + crate::Draft::Lite(_) => Err(()), } } } diff --git a/rs/moq-net/src/lite/corpus.rs b/rs/moq-net/src/lite/corpus.rs index 539f4cb67a9..db2d2d8cd65 100644 --- a/rs/moq-net/src/lite/corpus.rs +++ b/rs/moq-net/src/lite/corpus.rs @@ -67,7 +67,7 @@ fn outcome, V: Copy + Into
>( /// Decode `data` the way a session does, with what it refuses checked before what it decodes. fn run(case: &Case, data: &[u8]) -> String { - let crate::Version::Lite(version) = case.version else { + let crate::Version(crate::Draft::Lite(version)) = case.version else { return format!("{} is not a moq-lite version", case.version); }; let decoder = || Decoder::new(data, version.into()); diff --git a/rs/moq-net/src/lite/ietf.rs b/rs/moq-net/src/lite/ietf.rs index 85a1d4ad8ba..b5c2d4e4baa 100644 --- a/rs/moq-net/src/lite/ietf.rs +++ b/rs/moq-net/src/lite/ietf.rs @@ -125,7 +125,7 @@ fn encode_list(properties: &crate::model::object::TrackProperties) -> Result bool { - let code = crate::Version::Ietf(properties.version).code(); + let code = crate::Version::ietf(properties.version).code(); let Ok(code) = crate::coding::varint::size(code, Version::Lite07.into()) else { return false; }; @@ -323,7 +323,7 @@ impl<'a> Message<'a> for TrackProperties { let Some(properties) = &self.0 else { return w.varint(0); }; - w.varint(crate::Version::Ietf(properties.version).code())?; + w.varint(crate::Version::ietf(properties.version).code())?; w.slice(&encode_list(properties)?); Ok(()) } @@ -337,7 +337,7 @@ impl<'a> Message<'a> for TrackProperties { false => Err(DecodeError::InvalidValue), }; } - let Some(crate::Version::Ietf(version)) = crate::Version::from_code(code) else { + let Some(crate::Version(crate::Draft::Ietf(version))) = crate::Version::from_code(code) else { return Err(DecodeError::InvalidValue); }; let properties = crate::model::object::TrackProperties { @@ -387,7 +387,7 @@ mod tests { /// The moq-transport version code TRACK_PROPERTIES carries for `version`. fn code(version: Draft) -> u64 { - crate::Version::Ietf(version).code() + crate::Version::ietf(version).code() } #[test] @@ -605,7 +605,7 @@ mod tests { decode(&wire(&[opaque(0x40)], 0)).is_err(), "properties on a moq-lite track" ); - for code in [1, 0xff000099, crate::Version::Lite(V).code()] { + for code in [1, 0xff000099, crate::Version::lite(V).code()] { assert!(decode(&wire(&[], code)).is_err(), "{code:#x} is no moq-transport draft"); } @@ -741,7 +741,7 @@ pub(crate) async fn test_hop( offer: [bool; 2], ) -> (crate::origin::Producer, [crate::Session; 2]) { use crate::model::ProduceTest; - let version = crate::Version::Lite(Version::Lite07); + let version = crate::Version::lite(Version::Lite07); let downstream = crate::origin::Config::new(std::num::NonZeroU64::new(3).unwrap()).produce(); let (client, server) = crate::transport::memory::pair(crate::transport::memory::Config { protocol: Some(version.alpn().to_string()), diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index f60f510f90d..aafb98998b7 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -45,8 +45,8 @@ pub(super) struct PublisherConfig { /// Receive-side GOAWAY signal: recorded when the peer's Goaway stream arrives. pub goaway: crate::goaway::Protocol, /// The origin (hop) id assigned to the peer, used whenever the peer doesn't - /// declare one itself. See `Client::with_peer_hop`. - pub peer_hop: Option, + /// declare one itself. See `Client::with_peer_node`. + pub peer_node: Option, /// Our tokens' grants, which bound what we announce and serve, and the app's /// claim on answering the peer's tokens. pub auth: crate::auth::Link, @@ -72,10 +72,10 @@ struct Shared { // the same split-horizon rule as the announces we send them. peer_setup: super::PeerSetup, // The identity assigned to the peer (a fresh per-session id, or one the caller - // pinned with `with_peer_hop`), standing in wherever the + // pinned with `with_peer_node`), standing in wherever the // peer declines to declare one. Backs both the announce filter and the serving // origin, so a peer that names itself nowhere on the wire is still split-horizoned. - peer_hop: Option, + peer_node: Option, // The excluded origin handle, resolved once: the peer sends exactly one // SETUP, so its declared id never changes for the session. serving: std::sync::OnceLock, @@ -240,7 +240,7 @@ impl Shared { true => ready!(self.peer_setup.poll_hop(waiter)), false => None, }; - let origin = match declared.or(self.peer_hop) { + let origin = match declared.or(self.peer_node) { Some(peer) => self.origin.clone().excluding(peer), None => self.origin.clone(), }; @@ -269,7 +269,7 @@ impl Publisher { // Identity stamped onto outbound announce hops. Derived from the // origin we're consuming so it matches the local relay identity // across every session, required for cross-session loop detection. - let self_origin = crate::Hop::from(config.origin.hop()); + let self_origin = crate::Hop::from(config.origin.node()); let accept = config.session.clone(); let enforce = (config.client && config.version.has_auth()).then(Enforce::default); Self { @@ -282,7 +282,7 @@ impl Publisher { origin: config.origin.serving(), self_origin, peer_setup: config.peer_setup, - peer_hop: config.peer_hop, + peer_node: config.peer_node, serving: std::sync::OnceLock::new(), priority: Default::default(), version: config.version, @@ -1010,7 +1010,7 @@ impl AnnounceServe { // announce stream; lite-06+ reads the session-wide SETUP Hop // parameter, the same identity the subscribe path excludes. A peer that // declares nothing falls back to the identity the session assigned it. - let assigned: Hop = self.shared.peer_hop.unwrap_or(Hop::UNKNOWN); + let assigned: Hop = self.shared.peer_node.unwrap_or(Hop::UNKNOWN); let exclude_hop: Option = match self.shared.version.has_exclude_hop() { true => Some(match interest.exclude_hop { Hop::UNKNOWN => assigned, @@ -3919,7 +3919,7 @@ mod announce_test { }; let mut run = AnnounceRun::new( crate::Path::from_static(""), - crate::Hop::from(consumer.hop()), + crate::Hop::from(consumer.node()), Version::Lite07, ); let waiter = kio::Waiter::noop(); @@ -3965,7 +3965,7 @@ mod announce_test { }; let mut run = AnnounceRun::new( crate::Path::from_static(""), - crate::Hop::from(consumer.hop()), + crate::Hop::from(consumer.node()), Version::Lite07, ); let waiter = kio::Waiter::noop(); @@ -4011,7 +4011,7 @@ mod announce_test { }; let mut run = AnnounceRun::new( crate::Path::from_static(""), - crate::Hop::from(consumer.hop()), + crate::Hop::from(consumer.node()), Version::Lite07, ); let waiter = kio::Waiter::noop(); @@ -4071,7 +4071,7 @@ mod announce_test { }; let mut run = AnnounceRun::new( crate::Path::from_static(""), - crate::Hop::from(consumer.hop()), + crate::Hop::from(consumer.node()), Version::Lite07, ); let waiter = kio::Waiter::noop(); @@ -4115,7 +4115,7 @@ mod announce_test { }; let mut run = AnnounceRun::new( crate::Path::from_static(""), - crate::Hop::from(consumer.hop()), + crate::Hop::from(consumer.node()), Version::Lite07, ); assert!( @@ -4229,7 +4229,7 @@ mod announce_test { }; let _task = kio::clock::sim::spawn(async move { let mut announced = consumer.routes(); - let self_origin = crate::Hop::from(consumer.hop()); + let self_origin = crate::Hop::from(consumer.node()); TestPublisher::run_announce(&mut stream, &consumer, &mut announced, self_origin, VERSION, None).await }); settle().await; @@ -4262,7 +4262,7 @@ mod announce_test { }; let task = kio::clock::sim::spawn(async move { let mut announced = consumer.routes(); - let self_origin = crate::Hop::from(consumer.hop()); + let self_origin = crate::Hop::from(consumer.node()); TestPublisher::run_announce(&mut stream, &consumer, &mut announced, self_origin, version, auth).await }); settle().await; @@ -4526,7 +4526,7 @@ mod announce_test { }; let task = kio::clock::sim::spawn(async move { let mut announced = consumer.routes(); - let self_origin = crate::Hop::from(consumer.hop()); + let self_origin = crate::Hop::from(consumer.node()); TestPublisher::run_announce(&mut stream, &consumer, &mut announced, self_origin, VERSION, None).await }); settle().await; @@ -9574,7 +9574,7 @@ mod serve_group_test { publisher: &origin::Producer, subscriber: &origin::Producer, ) -> (crate::Session, crate::Session) { - let version = crate::Version::Lite(version); + let version = crate::Version::lite(version); let config = crate::transport::memory::Config { protocol: Some(version.alpn().into()), ..Default::default() @@ -10520,7 +10520,7 @@ mod tests { version: Version::Lite06, peer_setup, goaway, - peer_hop: Some(assigned), + peer_node: Some(assigned), auth: crate::auth::Link::new(false), peer_grant: Default::default(), client: false, @@ -10543,7 +10543,7 @@ mod tests { /// Lite01/02 send the initial active set as ANNOUNCE_INIT. It must apply the /// same per-peer route selection as the live loop: a broadcast whose only /// route flows through the excluded hop (here the peer's assigned identity, - /// `Client::with_peer_hop`) is filtered from the initial set too. + /// `Client::with_peer_node`) is filtered from the initial set too. #[kio::test] async fn announce_init_applies_route_selection() { let assigned = crate::Hop::new(777).unwrap(); @@ -10727,7 +10727,7 @@ mod tests { version: Version::Lite07, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), goaway, - peer_hop: None, + peer_node: None, auth: crate::auth::Link::new(false), peer_grant: Default::default(), client: false, @@ -10764,7 +10764,7 @@ mod tests { version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), goaway, - peer_hop: None, + peer_node: None, auth: crate::auth::Link::new(false), peer_grant: Default::default(), client: false, @@ -11098,7 +11098,7 @@ mod tests { version, peer_setup, goaway, - peer_hop: None, + peer_node: None, auth: crate::auth::Link::new(false), peer_grant: Default::default(), client: false, @@ -11233,7 +11233,7 @@ mod tests { version, peer_setup, goaway, - peer_hop: None, + peer_node: None, subscriptions: Default::default(), auth: crate::auth::Link::new(false), peer_grant: Default::default(), @@ -11302,7 +11302,7 @@ mod tests { version, peer_setup, goaway, - peer_hop: None, + peer_node: None, subscriptions: Default::default(), auth: crate::auth::Link::new(false), peer_grant: Default::default(), @@ -11355,7 +11355,7 @@ mod tests { version, peer_setup, goaway, - peer_hop: None, + peer_node: None, subscriptions: Default::default(), auth: crate::auth::Link::new(false), peer_grant: Default::default(), @@ -11586,7 +11586,7 @@ mod tests { version, peer_setup, goaway, - peer_hop: None, + peer_node: None, subscriptions: Default::default(), auth: crate::auth::Link::new(false), peer_grant: Default::default(), @@ -11735,7 +11735,7 @@ mod tests { version, peer_setup, goaway, - peer_hop: None, + peer_node: None, auth: crate::auth::Link::new(false), peer_grant: Default::default(), client: false, @@ -11869,7 +11869,7 @@ mod tests { version, peer_setup, goaway, - peer_hop: None, + peer_node: None, auth: crate::auth::Link::new(false), peer_grant: Default::default(), client: false, @@ -12004,7 +12004,7 @@ mod tests { version, peer_setup, goaway, - peer_hop: None, + peer_node: None, subscriptions: Default::default(), auth: crate::auth::Link::new(false), peer_grant: Default::default(), @@ -12260,7 +12260,7 @@ mod tests { version: Version::Lite07, peer_setup, goaway, - peer_hop: None, + peer_node: None, auth: crate::auth::Link::new(false), peer_grant: Default::default(), client: false, @@ -12332,7 +12332,7 @@ mod tests { version: VERSION, peer_setup, goaway, - peer_hop: None, + peer_node: None, auth: crate::auth::Link::new(false), peer_grant: Default::default(), client: false, @@ -12409,7 +12409,7 @@ mod tests { version: VERSION, peer_setup, goaway, - peer_hop: None, + peer_node: None, auth: crate::auth::Link::new(false), peer_grant: Default::default(), client: false, @@ -12778,7 +12778,7 @@ mod tests { version: Version::Lite07, peer_setup, goaway, - peer_hop: None, + peer_node: None, auth: crate::auth::Link::new(false), peer_grant: Default::default(), client: false, diff --git a/rs/moq-net/src/lite/session.rs b/rs/moq-net/src/lite/session.rs index 224d7db4747..3da037d0188 100644 --- a/rs/moq-net/src/lite/session.rs +++ b/rs/moq-net/src/lite/session.rs @@ -193,8 +193,8 @@ pub struct Config { pub subscribe: Option, /// The origin (hop) id assigned to the peer, used whenever the peer doesn't - /// declare one itself. See `Client::with_peer_hop`. - pub peer_hop: Option, + /// declare one itself. See `Client::with_peer_node`. + pub peer_node: Option, /// The version of the protocol to use. pub version: Version, @@ -231,7 +231,7 @@ pub fn start(config: Config) -> Result { setup_stream, publish, subscribe, - peer_hop, + peer_node, version, mut our_setup, peer_setup, @@ -261,8 +261,8 @@ pub fn start(config: Config) -> Result { if our_setup.hop.is_none() { our_setup.hop = publish .as_ref() - .map(|origin| origin.hop()) - .or_else(|| subscribe.as_ref().map(|origin| origin.hop())) + .map(|origin| origin.node()) + .or_else(|| subscribe.as_ref().map(|origin| origin.node())) .map(Hop::from); } // Lite-07 declares the Node ID our routes originate under instead, so a peer that is @@ -373,7 +373,7 @@ pub fn start(config: Config) -> Result { version, peer_setup: peer_setup.clone(), goaway: goaway.clone(), - peer_hop, + peer_node, auth: auth.clone(), peer_grant, client, @@ -387,7 +387,7 @@ pub fn start(config: Config) -> Result { recv_bandwidth: recv_bw_for_sub, version, peer_setup, - peer_hop, + peer_node, // Local policy for what pulling from this peer costs. Set only when we // configured a price; otherwise the subscriber charges what the peer declared // for its own egress. @@ -1020,7 +1020,7 @@ mod tests { setup_stream: None, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, version: Version::Lite07, our_setup: Setup::default(), peer_setup: None, @@ -1066,7 +1066,7 @@ mod tests { setup_stream: None, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, version: Version::Lite07, our_setup: Setup::default(), peer_setup: None, @@ -1147,7 +1147,7 @@ mod tests { setup_stream: None, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, version: Version::Lite07, our_setup: Setup::default(), peer_setup: None, @@ -1235,7 +1235,7 @@ mod tests { setup_stream: None, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, version: Version::Lite07, our_setup, peer_setup: None, @@ -1305,7 +1305,7 @@ mod tests { setup_stream: None, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, version, our_setup: Setup::default(), peer_setup: None, @@ -1361,7 +1361,7 @@ mod tests { setup_stream: None, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, version, our_setup: Setup::default(), peer_setup: None, @@ -1396,7 +1396,7 @@ mod tests { setup_stream: None, publish: None, subscribe: None, - peer_hop: None, + peer_node: None, version, our_setup: Setup::default(), peer_setup, diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 2dcfa8c5857..b22a6196335 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -41,8 +41,8 @@ pub(super) struct SubscriberConfig { /// stream is read; the probe stream waits on it before opening. pub peer_setup: super::PeerSetup, /// The origin (hop) id assigned to the peer, used whenever the peer doesn't - /// declare one itself. See `Client::with_peer_hop`. - pub peer_hop: Option, + /// declare one itself. See `Client::with_peer_node`. + pub peer_node: Option, /// Local policy for what pulling from this peer costs, overriding whatever it /// declared in its SETUP. `None` charges the peer's declared price. pub cost: Option, @@ -70,9 +70,9 @@ pub(super) struct Subscriber { // carry real hop ids on the wire (Lite01/02/03), and for a peer that reports // 0 in AnnounceOk. Lite03 placeholders stay 0 and count as anonymous. // - // This is the peer's assigned identity (`peer_hop`): a fresh id per dialed or + // This is the peer's assigned identity (`peer_node`): a fresh id per dialed or // accepted session, so its routes are distinguishable from another session's, - // unless the caller pinned a stable one with `with_peer_hop`. Without one it is + // unless the caller pinned a stable one with `with_peer_node`. Without one it is // `Hop::UNKNOWN` (0), the reserved "no identity" value. The assigned id stays // local and is never written into a hop chain. session_origin: crate::Hop, @@ -737,7 +737,7 @@ impl Subscriber { // origin we publish into so it matches the relay identity across // every session sharing that origin, required for cross-session // loop detection. - let self_origin = crate::Hop::from(config.origin.hop()); + let self_origin = crate::Hop::from(config.origin.node()); Self { session: config.session, runtime: config.runtime, @@ -745,7 +745,7 @@ impl Subscriber { origin: config.origin.with_own_frames(), recv_bandwidth: config.recv_bandwidth, self_origin, - session_origin: config.peer_hop.unwrap_or(crate::Hop::UNKNOWN), + session_origin: config.peer_node.unwrap_or(crate::Hop::UNKNOWN), subscribes: Default::default(), datagrams: Default::default(), legacy_datagrams: Default::default(), @@ -4674,7 +4674,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -4728,7 +4728,7 @@ mod tests { recv_bandwidth: None, version: Version::Lite07, peer_setup: lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -4761,7 +4761,7 @@ mod tests { recv_bandwidth: None, version: Version::Lite07, peer_setup: lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -4797,7 +4797,7 @@ mod tests { recv_bandwidth: None, version: Version::Lite07, peer_setup: lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -4859,7 +4859,7 @@ mod tests { recv_bandwidth: None, version: Version::Lite07, peer_setup: lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -5011,7 +5011,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: peer_setup.clone(), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -5067,7 +5067,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -5187,7 +5187,7 @@ mod tests { recv_bandwidth: None, version, peer_setup, - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -5369,7 +5369,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -5527,7 +5527,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -5601,7 +5601,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -5751,7 +5751,7 @@ mod tests { recv_bandwidth: None, version, peer_setup, - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -5871,7 +5871,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -5956,7 +5956,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -6037,7 +6037,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -6120,7 +6120,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -6200,7 +6200,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -6275,7 +6275,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -6385,7 +6385,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -6440,7 +6440,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -6951,7 +6951,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -7031,7 +7031,7 @@ mod tests { recv_bandwidth: None, version: Version::Lite07, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: auth.clone(), @@ -7101,7 +7101,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -7224,7 +7224,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -7299,7 +7299,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -7394,7 +7394,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -7467,7 +7467,7 @@ mod tests { recv_bandwidth: None, version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -7523,7 +7523,7 @@ mod tests { version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: Some(1), - peer_hop: None, + peer_node: None, going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -7552,7 +7552,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -7626,7 +7626,7 @@ mod tests { recv_bandwidth: None, version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -7681,7 +7681,7 @@ mod tests { recv_bandwidth: None, version, peer_setup, - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -8024,7 +8024,7 @@ mod tests { recv_bandwidth: None, version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -8081,7 +8081,7 @@ mod tests { recv_bandwidth: None, version: Version::Lite07, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth, @@ -8221,7 +8221,7 @@ mod tests { recv_bandwidth: None, version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth, @@ -8283,7 +8283,7 @@ mod tests { recv_bandwidth: None, version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -8353,7 +8353,7 @@ mod tests { recv_bandwidth: None, version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: auth.clone(), @@ -8420,7 +8420,7 @@ mod tests { recv_bandwidth: None, version: Version::Lite07, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -8520,7 +8520,7 @@ mod tests { recv_bandwidth: None, version: Version::Lite07, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -8584,7 +8584,7 @@ mod tests { recv_bandwidth: None, version: Version::Lite07, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -8700,7 +8700,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -8783,7 +8783,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -8858,7 +8858,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -8936,7 +8936,7 @@ mod tests { recv_bandwidth: Some(producer), version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -9001,7 +9001,7 @@ mod tests { recv_bandwidth: Some(producer), version, peer_setup, - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -9371,7 +9371,7 @@ mod tests { version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: None, - peer_hop: Some(assigned), + peer_node: Some(assigned), going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -9464,7 +9464,7 @@ mod tests { version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: None, - peer_hop: Some(crate::Hop::new(777).unwrap()), + peer_node: Some(crate::Hop::new(777).unwrap()), going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -9518,7 +9518,7 @@ mod tests { version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: None, - peer_hop: Some(crate::Hop::new(777).unwrap()), + peer_node: Some(crate::Hop::new(777).unwrap()), going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -9587,7 +9587,7 @@ mod tests { version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: None, - peer_hop: Some(crate::Hop::new(777).unwrap()), + peer_node: Some(crate::Hop::new(777).unwrap()), going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -9643,7 +9643,7 @@ mod tests { version: Version::Lite03, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: None, - peer_hop: Some(assigned), + peer_node: Some(assigned), going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -9702,7 +9702,7 @@ mod tests { version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: None, - peer_hop: Some(assigned), + peer_node: Some(assigned), going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -9761,7 +9761,7 @@ mod tests { version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: None, - peer_hop: Some(assigned), + peer_node: Some(assigned), going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -9833,7 +9833,7 @@ mod tests { version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: None, - peer_hop: Some(assigned), + peer_node: Some(assigned), going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -9892,7 +9892,7 @@ mod tests { recv_bandwidth: None, version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: Some(assigned), + peer_node: Some(assigned), cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -9940,7 +9940,7 @@ mod tests { version: Version::Lite03, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: None, - peer_hop: Some(assigned), + peer_node: Some(assigned), going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -10022,7 +10022,7 @@ mod tests { version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: None, - peer_hop: None, + peer_node: None, going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -10131,7 +10131,7 @@ mod tests { version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: None, - peer_hop: None, + peer_node: None, going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -10218,7 +10218,7 @@ mod tests { version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: Some(1), - peer_hop: None, + peer_node: None, going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -10329,7 +10329,7 @@ mod tests { version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: Some(1), - peer_hop: None, + peer_node: None, going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -10887,7 +10887,7 @@ mod tests { version: Version::Lite07, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: Some(1), - peer_hop: None, + peer_node: None, going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -11112,7 +11112,7 @@ mod tests { version: VERSION, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), cost: Some(1), - peer_hop: None, + peer_node: None, going_away: Default::default(), auth: crate::auth::Link::new(false), }); @@ -11148,7 +11148,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), @@ -11210,7 +11210,7 @@ mod tests { recv_bandwidth: None, version, peer_setup: crate::lite::PeerSetup::new(false, crate::transport::Address::Setup), - peer_hop: None, + peer_node: None, cost: None, going_away: Default::default(), auth: crate::auth::Link::new(false), diff --git a/rs/moq-net/src/lite/subscriber/routed.rs b/rs/moq-net/src/lite/subscriber/routed.rs index 4250224f79f..b3c9c090f8e 100644 --- a/rs/moq-net/src/lite/subscriber/routed.rs +++ b/rs/moq-net/src/lite/subscriber/routed.rs @@ -178,7 +178,7 @@ impl Routed { let link = route::Link { // A zero-cost link never reaches here: SETUP refuses it on lite-07. cost: link_cost.max(1), - priority: subscriber.origin.preference().value(), + priority: subscriber.origin.priority().value(), upstream: subscriber.origin.link() == crate::origin::Link::Upstream, // Only a stream this node answers is sent routes. proxy: false, diff --git a/rs/moq-net/src/lite/version.rs b/rs/moq-net/src/lite/version.rs index ed399c5e5ff..606914287e9 100644 --- a/rs/moq-net/src/lite/version.rs +++ b/rs/moq-net/src/lite/version.rs @@ -469,13 +469,13 @@ impl fmt::Display for Version { impl From for crate::Version { fn from(v: Version) -> Self { match v { - Version::Lite01 => crate::Version::Lite(Version::Lite01), - Version::Lite02 => crate::Version::Lite(Version::Lite02), - Version::Lite03 => crate::Version::Lite(Version::Lite03), - Version::Lite04 => crate::Version::Lite(Version::Lite04), - Version::Lite05 => crate::Version::Lite(Version::Lite05), - Version::Lite06 => crate::Version::Lite(Version::Lite06), - Version::Lite07 => crate::Version::Lite(Version::Lite07), + Version::Lite01 => crate::Version::lite(Version::Lite01), + Version::Lite02 => crate::Version::lite(Version::Lite02), + Version::Lite03 => crate::Version::lite(Version::Lite03), + Version::Lite04 => crate::Version::lite(Version::Lite04), + Version::Lite05 => crate::Version::lite(Version::Lite05), + Version::Lite06 => crate::Version::lite(Version::Lite06), + Version::Lite07 => crate::Version::lite(Version::Lite07), } } } @@ -484,9 +484,9 @@ impl TryFrom for Version { type Error = (); fn try_from(v: crate::Version) -> Result { - match v { - crate::Version::Lite(v) => Ok(v), - crate::Version::Ietf(_) => Err(()), + match v.0 { + crate::Draft::Lite(v) => Ok(v), + crate::Draft::Ietf(_) => Err(()), } } } diff --git a/rs/moq-net/src/model/mod.rs b/rs/moq-net/src/model/mod.rs index 823fe2446f5..acfdaa53a9b 100644 --- a/rs/moq-net/src/model/mod.rs +++ b/rs/moq-net/src/model/mod.rs @@ -63,7 +63,7 @@ pub mod origin { #[cfg(feature = "async")] pub(crate) use super::origin_impl::Mounted; pub use super::origin_impl::{ - Claim, Config, Consumer, Cost, Driver, Link, Preference, Producer, Request, Requesting, Route, RouteInfo, + Claim, Config, Consumer, Cost, Driver, Link, Priority, Producer, Request, Requesting, Route, RouteInfo, RouteOptions, Source, }; #[cfg(feature = "async")] diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index eda22ae8a92..007d0b62fd3 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -34,7 +34,7 @@ use crate::{ /// passes through, so a receiver can spot its own id and reject a loop. /// /// A transit fact the origin and the relays fill in: applications pass plain ids -/// ([`Config::hop`]) and read them back ([`RouteInfo::hops`]). +/// ([`Config::node`]) and read them back ([`RouteInfo::hops`]). /// /// Local hops come from a [`NonZeroU64`] or [`Hop::random`], so loop detection can work. /// Remote peers may still send `0`; it is legal on the wire, names nobody, and marks the @@ -97,14 +97,14 @@ impl Hop { #[derive(Clone, Debug)] #[non_exhaustive] pub struct Config { - /// The origin's identity on every wire: the hop id appended to broadcast hop chains - /// for loop detection, and the route identity it declares on moq-lite-07, which also + /// The origin's Node ID: its identity on every wire, appended to broadcast hop chains + /// for loop detection and declared as the route identity on moq-lite-07, which also /// names it in the hops of each route it forwards there. Random by /// default, so each process is a fresh identity. Set one only if it is fresh per /// process too: a restarted process numbers its lite-07 sessions from 1 again, so a /// peer that still remembers one of the old process's sessions as closed refuses /// the routes through the new one's session of the same number. - pub hop: NonZeroU64, + pub node: NonZeroU64, /// The key this origin proves to every lite-07 peer, which files the routes it sends /// under it when its grant is scoped. Origins sharing a key fail over as one. `None` @@ -164,11 +164,11 @@ pub(super) const DEFAULT_UPDATE_HOLD: Duration = Duration::from_millis(300); const RETRACT_QUARANTINE: Duration = Duration::from_secs(2); impl Default for Config { - /// A fresh random hop with no byte target and the default idle expiry. + /// A fresh random node with no byte target and the default idle expiry. fn default() -> Self { let pool = cache::Pool::new(cache::Config::default().with_expiry(cache::DEFAULT_EXPIRY)); Self { - hop: random_id(), + node: random_id(), route_key: None, max_hops: MAX_HOP_LIMIT, pool, @@ -179,9 +179,12 @@ impl Default for Config { } impl Config { - /// Config for the given origin hop id with no byte target and the default idle expiry. - pub fn new(hop: NonZeroU64) -> Self { - Self { hop, ..Self::default() } + /// Config for the given origin node with no byte target and the default idle expiry. + pub fn new(node: NonZeroU64) -> Self { + Self { + node, + ..Self::default() + } } } @@ -189,7 +192,7 @@ impl Config { /// restarts. /// /// Older `@moq/lite` clients decode the exclude hop as a JavaScript number and reject -/// values above 2^53-1, so generated ids stay in that range while [`Config::hop`] accepts +/// values above 2^53-1, so generated ids stay in that range while [`Config::node`] accepts /// any non-zero 64-bit id. pub(crate) fn random_id() -> NonZeroU64 { NonZeroU64::MIN.saturating_add(kio::clock::rng().random_range(0..(1u64 << 53) - 1)) @@ -421,16 +424,20 @@ impl From for Cost { /// How much an endpoint prefers a link over its others; higher wins. /// -/// Every link starts at the neutral [`Preference::default`] (0), which is also what +/// Every link starts at the neutral [`Priority::default`] (0), which is also what /// a broadcast published locally ranks. A positive value promotes a link and a -/// negative one demotes it. See [`Producer::with_preference`]. +/// negative one demotes it. See [`Producer::with_priority`]. +/// +/// This ranks a route's link, as a Route Offer's priority does. A +/// [`track::Subscription`](crate::track::Subscription)'s `priority` ranks one +/// subscription against the others sharing a connection. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct Preference(i8); +pub struct Priority(i8); -impl Preference { +impl Priority { /// Rank a link. - pub const fn new(preference: i8) -> Self { - Self(preference) + pub const fn new(priority: i8) -> Self { + Self(priority) } /// The rank. @@ -439,9 +446,9 @@ impl Preference { } } -impl From for Preference { - fn from(preference: i8) -> Self { - Self::new(preference) +impl From for Priority { + fn from(priority: i8) -> Self { + Self::new(priority) } } @@ -509,10 +516,10 @@ pub struct RouteInfo { pub(crate) lane: Lane, /// The session it arrived on is going away (the peer sent a GOAWAY): it ranks below - /// every other eligible route, whatever its preference or cost, yet still serves when + /// every other eligible route, whatever its priority or cost, yet still serves when /// nothing else does. /// - /// A preference state, never a saturated metric. Local, like [`Self::via`]: never + /// A priority state, never a saturated metric. Local, like [`Self::via`]: never /// forwarded, so a relay advertises a draining route at its real cost and its /// readers never see the flag. pub(crate) draining: bool, @@ -557,7 +564,7 @@ pub(crate) struct Lane { /// them never follows it. pub path: std::sync::Arc<[u64]>, /// The lowest priority of a link on the route's path, which ranks the route where a - /// session's preference does, or `None` for a route the route layer did not select. + /// session's priority does, or `None` for a route the route layer did not select. pub priority: Option, /// How many segments the claim's own prefix lacks of the path it entered at, which a /// stream presenting a broader claim at a narrower request reports: 0 for a claim @@ -604,7 +611,7 @@ impl RouteInfo { } /// What pulling content via this route costs, accumulated per link: lower wins - /// among routes of the same link preference and anonymity, with ties broken by a + /// among routes of the same link priority and anonymity, with ties broken by a /// broadcast published on this origin, then hop length, then a hash of the instance /// and the requested path (except for a route that entered here, at its own path), /// and finally the most recently announced route. See [`Cost`]. @@ -851,7 +858,7 @@ impl<'a> Epochs<'a> { /// neither draining (see [`RouteInfo::draining`]) nor unavailable (see /// [`RouteInfo::available`]), so a peer that sent a GOAWAY or a held route ranks below /// every other eligible route and serves only as a last resort. Then the route layer's -/// selected route ahead of its alternates. Then the higher link [`Preference`], so +/// selected route ahead of its alternates. Then the higher link [`Priority`], so /// metrics from different operators are never compared. Then an identified chain (no 0) outranks an anonymous one regardless /// of cost, then the cheapest cost, then a broadcast published on this origin (it serves /// what is here, not a claim that has to ask), then the shortest hop chain, then a hash @@ -888,10 +895,10 @@ fn route_order(path: &Path, entry: &RouteEntry) -> RouteOrder { entry.draining || !entry.available, // The route layer's selected route ahead of its alternates. !entry.lane.selected, - // A lite-07 route ranks by the lowest preference of any link on its path. + // A lite-07 route ranks by the lowest priority of any link on its path. Reverse(match entry.lane.priority { - Some(priority) => entry.preference.min(Preference::new(priority)), - None => entry.preference, + Some(priority) => entry.priority.min(Priority::new(priority)), + None => entry.priority, }), anonymous, entry.cost, @@ -916,7 +923,7 @@ type RouteOrder = ( bool, bool, bool, - Reverse, + Reverse, bool, Cost, bool, @@ -1366,8 +1373,8 @@ struct RouteEntry { cost: Cost, /// The auth the request advertising the route carries; see [`RouteInfo::auth`]. auth: Option, - /// The rank of the link the entry arrived on; see [`Producer::with_preference`]. - preference: Preference, + /// The rank of the link the entry arrived on; see [`Producer::with_priority`]. + priority: Priority, /// The announcing session's declared or assigned identity. Split-horizon /// matches this as well as [`Self::hops`], so an anonymous hop 0 still /// cannot echo back to the session it came from. @@ -2249,7 +2256,7 @@ pub struct Announce { pub struct Producer { // Identity for this origin. Appended to route hops when re-announcing so // downstream relays can detect loops and prefer the shortest path. - hop: NonZeroU64, + node: NonZeroU64, max_hops: NonZeroUsize, // The absolute patterns this handle may publish under. @@ -2279,8 +2286,8 @@ pub struct Producer { // [`Self::with_link`]). link: Link, - // The rank of that link; see [`Self::with_preference`]. - preference: Preference, + // The rank of that link; see [`Self::with_priority`]. + priority: Priority, // Whether the consumers taken from this handle proxy; see [`Self::with_proxy`]. proxy: bool, @@ -2312,7 +2319,7 @@ impl Producer { let shared = SendCell::new(kio::Shared::new(OriginState::new(config.update_hold, config.route_key))); let pool = config.pool.clone(); let producer = Self { - hop: config.hop, + node: config.node, max_hops: config.max_hops.min(MAX_HOP_LIMIT), scope: scope.clone(), root: Path::default(), @@ -2321,7 +2328,7 @@ impl Producer { cache_duration: config.cache_duration, stats: stats::Session::default(), link: Link::Local, - preference: Preference::default(), + priority: Priority::default(), proxy: false, tasks, timers: timers.clone(), @@ -2375,20 +2382,20 @@ impl Producer { } /// Rank the link this handle (and any handle derived from it) is given to: - /// higher wins, and every handle starts at the neutral [`Preference::default`]. + /// higher wins, and every handle starts at the neutral [`Priority::default`]. /// /// Applies to the routes a session lands from its peer through this handle, not to /// a route created here. Only an instance's newest epoch is - /// eligible, but among eligible routes preference decides before cost, so links to different + /// eligible, but among eligible routes priority decides before cost, so links to different /// operators rank by this instead of comparing their metrics. Hand each CDN's /// session its own rank to use the primary while it has a route and fail over to /// the next. /// - /// A moq-lite-07 route ranks by the lowest preference of any link on its path, so + /// A moq-lite-07 route ranks by the lowest priority of any link on its path, so /// two relays never prefer each other's paths forever. A link promoted above the /// links before it gains nothing there: demote the fallbacks instead. - pub fn with_preference(mut self, preference: Preference) -> Self { - self.preference = preference; + pub fn with_priority(mut self, priority: Priority) -> Self { + self.priority = priority; self } @@ -2406,10 +2413,10 @@ impl Producer { self } - /// The rank of the link this handle is given to; see [`Self::with_preference`]. + /// The rank of the link this handle is given to; see [`Self::with_priority`]. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(crate) fn preference(&self) -> Preference { - self.preference + pub(crate) fn priority(&self) -> Priority { + self.priority } /// The link this handle's routes arrive on; see [`Self::with_link`]. @@ -2446,7 +2453,7 @@ impl Producer { pub fn config(&self) -> Config { let shared = self.shared.lock(); Config { - hop: self.hop, + node: self.node, max_hops: self.max_hops, pool: self.pool.clone(), cache_duration: self.cache_duration, @@ -2455,15 +2462,15 @@ impl Producer { } } - /// This origin's hop id; see [`Config::hop`]. - pub fn hop(&self) -> NonZeroU64 { - self.hop + /// This origin's Node ID; see [`Config::node`]. + pub fn node(&self) -> NonZeroU64 { + self.node } - /// Whether `id`, as a peer declared it, names this origin: its hop id, or the Node ID + /// Whether `id`, as a peer declared it, names this origin: its node, or the Node ID /// its moq-lite-07 sessions declare. pub fn is_own(&self, id: NonZeroU64) -> bool { - id == self.hop || self.consume().node_id() == Some(id) + id == self.node || self.consume().node_id() == Some(id) } /// The key sessions prove for this origin. @@ -2488,7 +2495,7 @@ impl Producer { // ever be queued on the detached submission handle. let (tasks, _) = TaskSet::new(); Self { - hop: random_id(), + node: random_id(), scope: OriginScope::empty(), max_hops: MAX_HOP_LIMIT, root: Path::default(), @@ -2497,7 +2504,7 @@ impl Producer { cache_duration: None, stats: stats::Session::default(), link: Link::Local, - preference: Preference::default(), + priority: Priority::default(), proxy: false, tasks, timers: Deadlines::new(Instant::ZERO), @@ -2574,7 +2581,7 @@ impl Producer { // hidden from cursors and requests until it announces. The entry lives // as long as the route, or until the broadcast closes. let announcing = Announcing { - hop: Hop::from(self.hop), + hop: Hop::from(self.node), shared: self.shared.clone(), requested: full.clone(), prefixes: vec![(full.clone(), claim)], @@ -2582,7 +2589,7 @@ impl Producer { excluded: self.scope.excluded.clone(), local: true, link: self.link, - preference: Preference::default(), + priority: Priority::default(), stats: self.stats.clone(), }; let info = broadcast::Info { @@ -2867,7 +2874,7 @@ impl Producer { let rooted = patterns.rooted(root.as_str()).map_err(|_| BoundsExceeded)?; let scope = self.scope.narrow(&rooted).ok_or(Error::Unauthorized)?; Ok(Producer { - hop: self.hop, + node: self.node, max_hops: self.max_hops, scope, root, @@ -2876,7 +2883,7 @@ impl Producer { cache_duration: self.cache_duration, stats: self.stats.clone(), link: self.link, - preference: self.preference, + priority: self.priority, proxy: self.proxy, tasks: self.tasks.clone(), timers: self.timers.clone(), @@ -3006,7 +3013,7 @@ struct Announcing { /// The link the producer's routes arrive on. link: Link, /// The rank of that link; a broadcast published here is on none, so it ranks at the default. - preference: Preference, + priority: Priority, stats: stats::Session, } @@ -3023,7 +3030,7 @@ impl Announcing { return Err(Error::Unauthorized); } Ok(Self { - hop: Hop::from(producer.hop), + hop: Hop::from(producer.node), shared: producer.shared.clone(), requested: requested.clone(), prefixes: vec![(requested, claim)], @@ -3031,7 +3038,7 @@ impl Announcing { excluded: producer.scope.excluded.clone(), local: false, link: producer.link, - preference: producer.preference, + priority: producer.priority, stats: producer.stats.clone(), }) } @@ -3078,7 +3085,7 @@ impl Announcing { hops: route.hops.clone(), cost: route.cost, auth: route.auth.clone(), - preference: self.preference, + priority: self.priority, via, local: self.local, link: self.link, @@ -7402,7 +7409,7 @@ impl Consume for track::Consumer { #[derive(Clone)] pub struct Consumer { // Identity of the origin this consumer was derived from. - hop: NonZeroU64, + node: NonZeroU64, max_hops: NonZeroUsize, scope: OriginScope, @@ -7458,7 +7465,7 @@ pub struct Consumer { impl Consumer { fn from_producer(producer: &Producer, stats: stats::Session) -> Self { Self { - hop: producer.hop, + node: producer.node, max_hops: producer.max_hops, scope: producer.scope.clone(), root: producer.root.clone(), @@ -7479,9 +7486,9 @@ impl Consumer { } } - /// This origin's hop id; see [`Config::hop`]. - pub fn hop(&self) -> NonZeroU64 { - self.hop + /// This origin's Node ID; see [`Config::node`]. + pub fn node(&self) -> NonZeroU64 { + self.node } /// The key sessions prove for this origin. @@ -7510,7 +7517,7 @@ impl Consumer { let node = self.shared.lock().route_node.clone(); let id = match node { Some((node, _)) => Some(node.declared()), - None => crate::route::node::declared_for(self.hop), + None => crate::route::node::declared_for(self.node), }; id.and_then(NonZeroU64::new) } @@ -7548,7 +7555,7 @@ impl Consumer { // is the same whichever handle creates it. No `..self` here, so a new per-handle // field cannot leak in. let own = |upstream| Self { - hop: self.hop, + node: self.node, max_hops: self.max_hops, scope: OriginScope::default(), root: Path::default(), @@ -7573,7 +7580,7 @@ impl Consumer { timers: self.timers.clone(), }; // Built before taking the lock, since opening a cursor takes it. - let node = crate::route::Node::origin(self.hop(), self.timers.clone()); + let node = crate::route::Node::origin(self.node(), self.timers.clone()); let claims = OwnClaims { routes: own(false).routes(), downstream: own(true).routes(), @@ -8073,7 +8080,7 @@ impl Consumer { /// one instance's route covering it and materializes it, from the broadcast itself /// or from the peer that announced the route. The order is the most specific prefix, /// then, within one instance, only its highest epoch is eligible, cheaper or not. - /// Among instances it is the preferred link ([`Producer::with_preference`]), then + /// Among instances it is the preferred link ([`Producer::with_priority`]), then /// the cheapest, then a broadcast published on this origin, then the shortest hop /// chain, then a hash of the instance and the path, which every relay agrees on and /// which spreads a pool's paths over its hosts. @@ -9093,10 +9100,10 @@ mod tests { #[kio::test] async fn default_config_mints_a_real_hop() { let config = Config::default(); - assert!(config.hop.get() < 1 << 53, "older JS clients decode it as a number"); + assert!(config.node.get() < 1 << 53, "older JS clients decode it as a number"); let (producer, _driver) = Producer::new(config.clone()); - assert_eq!(producer.hop(), config.hop); - assert_eq!(producer.consume().hop(), config.hop); + assert_eq!(producer.node(), config.node); + assert_eq!(producer.consume().node(), config.node); } #[kio::test] @@ -10642,7 +10649,7 @@ mod tests { let demoted = producer .clone() - .with_preference(Preference::new(-1)) + .with_priority(Priority::new(-1)) .forward("room", RouteInfo::new().with_hops(hops(&[10])).with_cost(1)) .unwrap(); let unranked = producer @@ -10813,7 +10820,7 @@ mod tests { let draining = producer .clone() - .with_preference(Preference::new(1)) + .with_priority(Priority::new(1)) .forward( "room", RouteInfo::new().with_hops(hops(&[10])).with_cost(1).with_draining(true), @@ -10821,7 +10828,7 @@ mod tests { .unwrap(); let demoted = producer .clone() - .with_preference(Preference::new(-1)) + .with_priority(Priority::new(-1)) .forward("room", RouteInfo::new().with_hops(hops(&[11])).with_cost(5)) .unwrap(); let _bob = consumer.request("room/bob", None); diff --git a/rs/moq-net/src/model/resume_model.rs b/rs/moq-net/src/model/resume_model.rs index dc20efe6c7d..b60e4467ba2 100644 --- a/rs/moq-net/src/model/resume_model.rs +++ b/rs/moq-net/src/model/resume_model.rs @@ -338,7 +338,7 @@ struct Model { impl Model { fn new() -> Self { let origin = origin::Config { - hop: std::num::NonZeroU64::MIN, + node: std::num::NonZeroU64::MIN, update_hold: Duration::ZERO, ..Default::default() }; diff --git a/rs/moq-net/src/server.rs b/rs/moq-net/src/server.rs index 1856657c471..8e40c315fdf 100644 --- a/rs/moq-net/src/server.rs +++ b/rs/moq-net/src/server.rs @@ -190,7 +190,7 @@ impl Server { /// When a connection that arrived at `arrived` must be accepted by, or `None` to wait /// forever, including past the clock's range. /// - /// A caller that runs a transport handshake before [`accept_request`](Self::accept_request) + /// A caller that runs a transport handshake before [`handshake`](Self::handshake) /// bounds that handshake by this instant, then hands it to [`Accept::with_deadline`]. pub fn deadline(&self, arrived: Instant) -> Option { arrived.checked_add(self.timeout?) @@ -232,7 +232,7 @@ impl Server { session: Transport, version: lite::Version, client_setup: Option, - peer_hop: Option, + peer_node: Option, auth: crate::auth::Link, ) -> Result<(Session, crate::Driver), Error> { let (publish, subscribe) = self.stat_tagged_origins(); @@ -273,7 +273,7 @@ impl Server { setup_stream: None, publish, subscribe, - peer_hop, + peer_node, version, our_setup, peer_setup: client_setup, @@ -357,15 +357,15 @@ impl Server { /// Poll the returned driver with nondecreasing time, starting at `now`. The accept /// deadline counts from `now` too. /// - /// Convenience wrapper over [`accept_request`](Self::accept_request) that - /// completes the handshake immediately. Use `accept_request` when you need to + /// Convenience wrapper over [`handshake`](Self::handshake) that + /// completes the handshake immediately. Use `handshake` when you need to /// inspect the client's advertised path before deciding what to serve. pub fn accept( &self, now: Instant, session: impl crate::transport::poll::Boxable, ) -> impl Future> { - let mut accept = self.accept_request(now, session); + let mut accept = self.handshake(now, session); let mut answer = None; kio::wait(move |waiter| { let answer = match &mut answer { @@ -394,7 +394,7 @@ impl Server { /// ([`with_timeout`](Self::with_timeout)) unless [`Accept::with_deadline`] moves it. The /// deadline goes on to bound the caller's admission ([`Handshake::expired`]) and the SETUP /// reply ([`Handshake::ok`]). - pub fn accept_request(&self, now: Instant, session: impl crate::transport::poll::Boxable) -> Accept { + pub fn handshake(&self, now: Instant, session: impl crate::transport::poll::Boxable) -> Accept { Accept { server: self.clone(), timer: Timer::new(self.deadline(now)), @@ -654,7 +654,7 @@ impl Handshaking { ALPN_20 => ietf::Version::Draft20, _ => ietf::Version::Draft18, }; - server.versions.select(Version::Ietf(version)).ok_or(Error::Version)?; + server.versions.select(Version::ietf(version)).ok_or(Error::Version)?; AcceptStep::Ietf { runtime, session, @@ -723,7 +723,7 @@ impl Handshaking { Some(stream) => stream, None => stream.insert(ready!(Stream::poll_accept( session, - Version::Lite(lite::Version::Lite01), + Version::lite(lite::Version::Lite01), waiter ))?), }; @@ -739,7 +739,7 @@ impl Handshaking { else { unreachable!("matched above"); }; - if !Version::Lite(version).hands_off() { + if !Version::lite(version).hands_off() { return Poll::Ready(Ok(server.negotiated_handshake( runtime, session, @@ -751,7 +751,7 @@ impl Handshaking { // Answer, close the stream, and continue as that version's ALPN would. let reply = setup::Server { - version: Version::Lite(version).into(), + version: Version::lite(version).into(), parameters: lite::Parameters::default().encode_bytes(version)?, }; let Stream { mut writer, reader } = stream; @@ -807,7 +807,7 @@ impl Handshaking { session: Transport, version: lite::Version, ) -> Result { - server.versions.select(Version::Lite(version)).ok_or(Error::Version)?; + server.versions.select(Version::lite(version)).ok_or(Error::Version)?; Ok(AcceptStep::Lite { runtime, session, @@ -819,7 +819,7 @@ impl Handshaking { /// A paused server-side handshake. /// -/// Returned by [`Server::accept_request`] once the peer's advertised +/// Returned by [`Server::handshake`] once the peer's advertised /// [`path`](Self::path) is known but before the session is granted anything. Set /// the origins to serve, then call [`ok`](Self::ok) to complete the handshake, or /// [`close`](Self::close) to reject it. Modeled on the WebTransport `Request` in @@ -832,7 +832,7 @@ pub struct Handshake { peer_implementation: Option, /// The identity this session's routes are attributed to for split horizon when the /// peer declares none on the wire; it never enters a hop chain. Fresh per request unless the caller overrides it - /// ([`Handshake::with_peer_hop`]). + /// ([`Handshake::with_peer_node`]). assigned_hop: crate::Hop, /// The session's auth handle, available before [`Handshake::ok`] so the caller can /// take the peer's token requests before any arrive. @@ -885,7 +885,7 @@ impl PausedIetf { self, server: Server, runtime: Deadlines, - peer_hop: Option, + peer_node: Option, auth: crate::auth::Link, ) -> Result<(Session, crate::Driver), Error> { let Self { @@ -908,7 +908,7 @@ impl PausedIetf { client: false, publish, subscribe, - peer_hop, + peer_node, // Only the dialing side prices a link. cost: None, version, @@ -963,7 +963,7 @@ impl PausedNegotiated { self, server: Server, runtime: Deadlines, - peer_hop: Option, + peer_node: Option, auth: crate::auth::Link, ) -> Result { let Self { @@ -977,7 +977,7 @@ impl PausedNegotiated { let (publish, subscribe) = server.stat_tagged_origins(); stream.writer.buffer(&setup::Server { - version: Version::Lite(version).into(), + version: Version::lite(version).into(), parameters: lite::Parameters::default().encode_bytes(version)?, })?; Ok(NegotiatedReply(Some(NegotiatedStart { @@ -986,7 +986,7 @@ impl PausedNegotiated { session, stream, version, - peer_hop, + peer_node, auth, publish, subscribe, @@ -1015,7 +1015,7 @@ struct NegotiatedStart { session: Transport, stream: Stream, version: lite::Version, - peer_hop: Option, + peer_node: Option, auth: crate::auth::Link, publish: Option, subscribe: Option, @@ -1029,7 +1029,7 @@ impl NegotiatedStart { session, stream, version, - peer_hop, + peer_node, auth, publish, subscribe, @@ -1048,7 +1048,7 @@ impl NegotiatedStart { setup_stream: Some(stream), publish, subscribe, - peer_hop, + peer_node, version, our_setup: lite::Setup::default(), peer_setup: None, @@ -1083,7 +1083,7 @@ impl Handshake { /// Empty when the client advertised none: either it sent an empty path, or the /// version carries none in-band (lite 01-04). Those mean the same thing, so the /// wire distinction isn't surfaced. Populated for moq-lite-05 and newer, - /// and every moq-transport draft we speak. See the note on [`Server::accept_request`]. + /// and every moq-transport draft we speak. See the note on [`Server::handshake`]. pub fn path(&self) -> &str { self.path.as_deref().unwrap_or("") } @@ -1095,7 +1095,7 @@ impl Handshake { /// that the wire doesn't distinguish: an older version, a client that omitted the parameter, and a /// client that explicitly advertised both directions. All three mean the same thing /// (the client may publish and subscribe), so authorize on what the token grants. - /// See the note on [`Server::accept_request`]. + /// See the note on [`Server::handshake`]. pub fn role(&self) -> Option { self.role } @@ -1109,7 +1109,7 @@ impl Handshake { /// /// Self-declared, so treat it as a correlation hint rather than an /// authenticated identity: authorize on the token or client certificate. - pub fn peer_hop(&self) -> Option { + pub fn peer_node(&self) -> Option { self.origin.and_then(|hop| std::num::NonZeroU64::new(hop.id())) } @@ -1170,7 +1170,7 @@ impl Handshake { /// per-session default. /// /// Only for a peer whose identity the server has actually established, such as one - /// authenticated by mTLS or a token ([`crate::Client::with_peer_hop`] is the + /// authenticated by mTLS or a token ([`crate::Client::with_peer_node`] is the /// dialing-side equivalent). An identity the peer declares on the wire still wins. /// /// Two sessions given the same origin are treated as one endpoint: routes learned @@ -1178,8 +1178,8 @@ impl Handshake { /// with the other's. That is the point when they really are one peer reconnecting or /// running redundant links, and a bug otherwise. Derive it from the authenticated /// identity, never from something coarser like the remote address. - pub fn with_peer_hop(mut self, hop: std::num::NonZeroU64) -> Self { - self.assigned_hop = crate::Hop::from(hop); + pub fn with_peer_node(mut self, node: std::num::NonZeroU64) -> Self { + self.assigned_hop = crate::Hop::from(node); self } @@ -1325,11 +1325,11 @@ impl Answer { if let Err(err) = open_window(&server, &paused) { return Poll::Ready(Some(Err(err))); } - let peer_hop = Some(self.handshake.assigned_hop); + let peer_node = Some(self.handshake.assigned_hop); let auth = self.handshake.auth.clone(); let started = match paused { PausedHandshake::LiteBare { session, version } => { - server.start_lite(runtime, session, version, None, peer_hop, auth) + server.start_lite(runtime, session, version, None, peer_node, auth) } PausedHandshake::LiteSetup { session, @@ -1337,10 +1337,10 @@ impl Answer { client_setup, } => { server.stats.control(stats::Message::Session, client_setup.size, true); - server.start_lite(runtime, session, version, Some(client_setup), peer_hop, auth) + server.start_lite(runtime, session, version, Some(client_setup), peer_node, auth) } - PausedHandshake::Ietf(paused) => paused.ok(server, runtime, peer_hop, auth), - PausedHandshake::Negotiated(paused) => match paused.reply(server, runtime, peer_hop, auth) { + PausedHandshake::Ietf(paused) => paused.ok(server, runtime, peer_node, auth), + PausedHandshake::Negotiated(paused) => match paused.reply(server, runtime, peer_node, auth) { Ok(reply) => { self.reply = Some(Box::new(reply)); return self.poll_reply(waiter); @@ -1751,8 +1751,8 @@ mod tests { let mut buf = Vec::new(); setup::Setup { parameters } .encode( - &mut crate::coding::Encoder::new(&mut buf, (crate::Version::Ietf(version)).into()), - crate::Version::Ietf(version), + &mut crate::coding::Encoder::new(&mut buf, (crate::Version::ietf(version)).into()), + crate::Version::ietf(version), ) .unwrap(); buf @@ -1760,7 +1760,7 @@ mod tests { /// A moq-lite-02 CLIENT_SETUP, sent on the bidi stream the `moql` ALPN negotiates over. fn moql_setup() -> Vec { - let version = crate::Version::Lite(lite::Version::Lite02); + let version = crate::Version::lite(lite::Version::Lite02); let mut buf = Vec::new(); setup::Client { versions: crate::coding::Versions::from([version.into()]), @@ -1785,7 +1785,7 @@ mod tests { } /// An acceptor taken with `Handshake::requests()` BEFORE `ok()` must govern the - /// session the driver then runs, through the REAL accept path (`accept_request` -> `ok`). + /// session the driver then runs, through the REAL accept path (`handshake` -> `ok`). /// Its auth link routes a request token to that pre-ok consumer after `ok()`, instead of /// falling to the `Unsupported` default, and granting admits. /// A QUIC server has no other point to install the verifier. @@ -1798,7 +1798,7 @@ mod tests { for (session, version) in cases { let mut request = Server::new() - .accept_request(kio::clock::now(), session) + .handshake(kio::clock::now(), session) .await .unwrap_or_else(|e| panic!("accept at {version:?}: {e}")); @@ -1827,14 +1827,14 @@ mod tests { #[kio::test] async fn a_reply_the_peer_never_takes_fails_at_the_deadline() { let registry = stats::Registry::new(Default::default()); - let version = Version::Lite(lite::Version::Lite02); + let version = Version::lite(lite::Version::Lite02); let session = FakeSession::new(ALPN_LITE, []) .with_bi(moql_setup()) .withholding_credit(); let start = kio::clock::now(); let deadline = start.saturating_add(DEFAULT_TIMEOUT); let request = Server::new() - .accept_request(start, session.clone()) + .handshake(start, session.clone()) .await .unwrap() .with_stats( @@ -1864,7 +1864,7 @@ mod tests { ] { let deadline = kio::clock::now().saturating_add(std::time::Duration::from_secs(3)); let accept = Server::new() - .accept_request(kio::clock::now(), session.clone()) + .handshake(kio::clock::now(), session.clone()) .with_deadline(Some(deadline)); let Err(err) = accept.await else { panic!("{:?}: accepted without a SETUP", session.protocol); @@ -1884,7 +1884,7 @@ mod tests { let start = kio::clock::now(); let mut request = Server::new() .with_timeout(Some(std::time::Duration::from_secs(5))) - .accept_request(start, session.clone()) + .handshake(start, session.clone()) .await .unwrap() .with_stats( @@ -1897,7 +1897,7 @@ mod tests { kio::clock::now(), start.saturating_add(std::time::Duration::from_secs(5)) ); - let version = Version::Lite(lite::Version::Lite05); + let version = Version::lite(lite::Version::Lite05); assert_eq!(session.close_code(), Some(version.session_code(&SessionError::Timeout))); let failed = registry.snapshot().sessions()[0].1.sessions_failed; assert_eq!(failed.count(stats::Failure::Application), 1, "{failed:?}"); @@ -1913,7 +1913,7 @@ mod tests { let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]); let request = Server::new() .with_timeout(Some(std::time::Duration::from_secs(1))) - .accept_request(kio::clock::now(), session.clone()) + .handshake(kio::clock::now(), session.clone()) .await .unwrap(); kio::clock::sleep(std::time::Duration::from_secs(1)).await; @@ -1921,7 +1921,7 @@ mod tests { panic!("a late admission started"); }; assert!(matches!(err, Error::Timeout), "{err:?}"); - let version = Version::Lite(lite::Version::Lite05); + let version = Version::lite(lite::Version::Lite05); assert_eq!(session.close_code(), Some(version.session_code(&SessionError::Timeout))); } @@ -1934,17 +1934,17 @@ mod tests { let server = Server::new().with_receive_window(window); let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]).widening(None); - let request = server.accept_request(kio::clock::now(), session.clone()).await.unwrap(); + let request = server.handshake(kio::clock::now(), session.clone()).await.unwrap(); let _accepted = request.ok().await.expect("ok"); assert_eq!(session.window(), Some(window)); let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]).widening(None); - let request = server.accept_request(kio::clock::now(), session.clone()).await.unwrap(); + let request = server.handshake(kio::clock::now(), session.clone()).await.unwrap(); let _accepted = request.with_receive_window(wider).ok().await.expect("ok"); assert_eq!(session.window(), Some(wider)); let fixed = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]); - let request = server.accept_request(kio::clock::now(), fixed.clone()).await.unwrap(); + let request = server.handshake(kio::clock::now(), fixed.clone()).await.unwrap(); let _accepted = request.ok().await.expect("a transport that can't widen starts"); assert_eq!(fixed.close_code(), None); } @@ -1957,14 +1957,14 @@ mod tests { let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]).widening(Some("too small")); let request = Server::new() .with_receive_window(window) - .accept_request(kio::clock::now(), session.clone()) + .handshake(kio::clock::now(), session.clone()) .await .unwrap(); let Err(err) = request.ok().await else { panic!("served on a refused window"); }; assert!(matches!(err, Error::Transport(_)), "{err:?}"); - let version = Version::Lite(lite::Version::Lite05); + let version = Version::lite(lite::Version::Lite05); let code = version.session_code(&SessionError::from(&err)); assert_eq!(session.close_code(), Some(code)); } @@ -1974,12 +1974,12 @@ mod tests { #[kio::test] async fn an_abandoned_reply_fails_like_the_deadline() { let registry = stats::Registry::new(Default::default()); - let version = Version::Lite(lite::Version::Lite02); + let version = Version::lite(lite::Version::Lite02); let session = FakeSession::new(ALPN_LITE, []) .with_bi(moql_setup()) .withholding_credit(); let request = Server::new() - .accept_request(kio::clock::now(), session.clone()) + .handshake(kio::clock::now(), session.clone()) .await .unwrap() .with_stats( @@ -2006,7 +2006,7 @@ mod tests { let observed = session.clone(); let abandoned = kio::clock::timeout( std::time::Duration::from_secs(1), - Server::new().accept_request(kio::clock::now(), session), + Server::new().handshake(kio::clock::now(), session), ) .await; assert!(abandoned.is_err(), "{:?}: accepted without a SETUP", observed.protocol); @@ -2027,7 +2027,7 @@ mod tests { let registry = stats::Registry::new(Default::default()); let session = FakeSession::new(ALPN_22, [ietf_setup(ietf::Version::Draft22, None)]); Server::new() - .accept_request(kio::clock::now(), session) + .handshake(kio::clock::now(), session) .await .unwrap() .with_stats( @@ -2045,7 +2045,7 @@ mod tests { } #[kio::test] - async fn accept_request_exposes_the_setup_token() { + async fn handshake_exposes_the_setup_token() { let ietf = FakeSession::new( ALPN_22, [ietf_setup_with( @@ -2053,16 +2053,16 @@ mod tests { token_params(ietf::Version::Draft22), )], ); - let request = Server::new().accept_request(kio::clock::now(), ietf).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), ietf).await.unwrap(); assert_eq!(request.token(), Some(&setup_token())); } #[kio::test] - async fn accept_request_without_a_token_reports_none() { + async fn handshake_without_a_token_reports_none() { let ietf = FakeSession::new(ALPN_22, [ietf_setup(ietf::Version::Draft22, None)]); let lite = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]); for (name, session) in [("draft-22", ietf), ("lite-05", lite)] { - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); assert_eq!(request.token(), None, "{name}"); } } @@ -2080,34 +2080,34 @@ mod tests { params.set_bytes(ietf::ParameterBytes::AuthorizationToken, raw.to_vec()); let session = FakeSession::new(ALPN_22, [ietf_setup_with(ietf::Version::Draft22, params)]); - let result = Server::new().accept_request(kio::clock::now(), session.clone()).await; + let result = Server::new().handshake(kio::clock::now(), session.clone()).await; assert!(result.is_err()); assert_eq!(session.close_code(), Some(code.to_code()), "{code}"); } } #[kio::test] - async fn accept_request_reads_ietf_path() { + async fn handshake_reads_ietf_path() { // Every draft gates on the SETUP stream before starting, so the // path is known at authorization time just like lite-05. for (alpn, version) in [(ALPN_18, ietf::Version::Draft18), (ALPN_22, ietf::Version::Draft22)] { let session = FakeSession::new(alpn, [ietf_setup(version, Some("/team/room"))]); - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), "/team/room", "{alpn}"); } } #[kio::test] - async fn accept_request_ietf_without_path_is_empty() { + async fn handshake_ietf_without_path_is_empty() { let session = FakeSession::new(ALPN_22, [ietf_setup(ietf::Version::Draft22, None)]); - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), ""); } #[kio::test] - async fn accept_request_ietf_empty_path_is_accepted() { + async fn handshake_ietf_empty_path_is_accepted() { let session = FakeSession::new(ALPN_22, [ietf_setup(ietf::Version::Draft22, Some(""))]); - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), ""); } @@ -2124,50 +2124,50 @@ mod tests { } #[kio::test] - async fn accept_request_reads_lite05_path() { + async fn handshake_reads_lite05_path() { let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(Some("/team/room"), None, None)]); - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), "/team/room"); assert_eq!(request.role(), None, "a client that omits the role is bidirectional"); } #[kio::test] - async fn accept_request_lite05_without_path_is_empty() { + async fn handshake_lite05_without_path_is_empty() { let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]); - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), ""); } #[kio::test] - async fn accept_request_lite05_empty_path_is_accepted() { + async fn handshake_lite05_empty_path_is_accepted() { // An empty path is valid on the wire and means the same as omitting it, so a // client that wants the root doesn't have to special-case the parameter. let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(Some(""), None, None)]); - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), ""); } #[kio::test] async fn uri_address_rejects_setup_path_presence() { for version in [ - Version::Lite(lite::Version::Lite05), - Version::Lite(lite::Version::Lite06), - Version::Lite(lite::Version::Lite07), - Version::Ietf(ietf::Version::Draft18), - Version::Ietf(ietf::Version::Draft22), + Version::lite(lite::Version::Lite05), + Version::lite(lite::Version::Lite06), + Version::lite(lite::Version::Lite07), + Version::ietf(ietf::Version::Draft18), + Version::ietf(ietf::Version::Draft22), ] { let alpn = version.alpn(); for path in ["", "/team/room?jwt=other"] { let setup = match version { - Version::Lite(_) => lite05_setup(Some(path), None, None), - Version::Ietf(version) => ietf_setup(version, Some(path)), + Version(crate::Draft::Lite(_)) => lite05_setup(Some(path), None, None), + Version(crate::Draft::Ietf(version)) => ietf_setup(version, Some(path)), }; let mut session = FakeSession::new(alpn, [setup]); session.address = crate::transport::Address::Uri; let observed = session.clone(); let result = Server::new() .with_versions(version.into()) - .accept_request(kio::clock::now(), session) + .handshake(kio::clock::now(), session) .await; assert!( matches!(result, Err(Error::ProtocolViolation)), @@ -2181,22 +2181,22 @@ mod tests { #[kio::test] async fn uri_address_accepts_setup_without_path() { for version in [ - Version::Lite(lite::Version::Lite05), - Version::Lite(lite::Version::Lite06), - Version::Lite(lite::Version::Lite07), - Version::Ietf(ietf::Version::Draft18), - Version::Ietf(ietf::Version::Draft22), + Version::lite(lite::Version::Lite05), + Version::lite(lite::Version::Lite06), + Version::lite(lite::Version::Lite07), + Version::ietf(ietf::Version::Draft18), + Version::ietf(ietf::Version::Draft22), ] { let alpn = version.alpn(); let setup = match version { - Version::Lite(_) => lite05_setup(None, None, None), - Version::Ietf(version) => ietf_setup(version, None), + Version(crate::Draft::Lite(_)) => lite05_setup(None, None, None), + Version(crate::Draft::Ietf(version)) => ietf_setup(version, None), }; let mut session = FakeSession::new(alpn, [setup]); session.address = crate::transport::Address::Uri; let request = Server::new() .with_versions(version.into()) - .accept_request(kio::clock::now(), session) + .handshake(kio::clock::now(), session) .await .unwrap(); assert_eq!(request.path(), ""); @@ -2204,32 +2204,32 @@ mod tests { } #[kio::test] - async fn accept_request_reads_lite05_role() { + async fn handshake_reads_lite05_role() { let session = FakeSession::new( ALPN_LITE_05, [lite05_setup(Some("/team/room"), Some(Role::Publisher), None)], ); - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); assert_eq!(request.role(), Some(Role::Publisher)); } #[kio::test] - async fn accept_request_holds_uni_stream_before_setup() { + async fn handshake_holds_uni_stream_before_setup() { let session = FakeSession::new( ALPN_LITE_05, [lite05_group(), lite05_setup(Some("/team/room"), None, None)], ); let stops = session.stops.clone(); - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), "/team/room"); assert!(stops.lock().unwrap().is_empty(), "the early stream must stay open"); } #[kio::test] - async fn accept_request_reads_buffered_setup_after_transport_close() { + async fn handshake_reads_buffered_setup_after_transport_close() { let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(Some("/closed"), None, None)]); crate::transport::poll::Session::close(&session, SessionError::Cancel.to_code(), "closed"); - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), "/closed"); } @@ -2253,14 +2253,14 @@ mod tests { let session = FakeSession::new(ALPN_LITE_07_WIP, [setup]); let transport = session.clone(); let request = Server::new() - .with_versions(Version::Lite(v).into()) - .accept_request(kio::clock::now(), session) + .with_versions(Version::lite(v).into()) + .handshake(kio::clock::now(), session) .await .unwrap(); assert!(matches!(request.ok().await, Err(Error::ProtocolViolation))); assert_eq!( transport.close_code(), - Some(Version::Lite(v).session_code(&SessionError::ProtocolViolation)) + Some(Version::lite(v).session_code(&SessionError::ProtocolViolation)) ); } @@ -2268,7 +2268,7 @@ mod tests { async fn accepted_lite_setup_refuses_a_second_setup_stream() { let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]); let transport = session.clone(); - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); let (_session, mut driver) = request.ok().await.unwrap(); transport.uni.lock().unwrap().push_back(vec![1]); let _ = driver.poll(kio::clock::now(), &kio::Waiter::noop()); @@ -2276,11 +2276,11 @@ mod tests { } #[kio::test] - async fn accept_request_reads_lite05_peer_hop() { + async fn handshake_reads_lite05_peer_hop() { let hop = Hop::new(42).unwrap(); let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, Some(hop))]); - let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); - assert_eq!(request.peer_hop(), Some(std::num::NonZeroU64::new(42).unwrap())); + let request = Server::new().handshake(kio::clock::now(), session).await.unwrap(); + assert_eq!(request.peer_node(), Some(std::num::NonZeroU64::new(42).unwrap())); } #[kio::test] @@ -2310,7 +2310,7 @@ mod tests { peer_setup: ietf::PeerSetup { stream: crate::coding::Reader::new( crate::transport::boxed::RecvStream::new(crate::lite::test_transport::PendingRecv), - Version::Ietf(version), + Version::ietf(version), ), size: 0, options: ietf::SetupOptions { diff --git a/rs/moq-net/src/setup.rs b/rs/moq-net/src/setup.rs index 2889392d3ab..3bfb3f5a745 100644 --- a/rs/moq-net/src/setup.rs +++ b/rs/moq-net/src/setup.rs @@ -167,7 +167,7 @@ impl<'a> Decode<'a, Version> for Setup { /// Whether `v` encodes the `moql` bidi SETUP exchange: moq-lite 01/02, whose draft-14 framing /// and QUIC varints it keeps whichever moq-lite version it negotiates. fn framed(v: Version) -> bool { - matches!(v, Version::Lite(lite::Version::Lite01 | lite::Version::Lite02)) + matches!(v.0, crate::Draft::Lite(lite::Version::Lite01 | lite::Version::Lite02)) } /// The client half of the `moql` bidi SETUP exchange, offering moq-lite versions. @@ -202,7 +202,7 @@ impl Client { .flat_map(|v| Version::try_from(*v).ok()) .find(|v| supported.contains(v)); match version { - Some(Version::Lite(version)) => Ok(version), + Some(Version(crate::Draft::Lite(version))) => Ok(version), _ => { // The client only learns that the session closed, so this is the one place // that can name both sides of the mismatch. @@ -360,8 +360,8 @@ mod tests { let setup = Setup { parameters: params.encode_bytes(version).unwrap(), }; - let wire = setup.encode_bytes(crate::Version::Ietf(version)).unwrap(); - let decoded = Setup::decode_slice(&wire, crate::Version::Ietf(version)).unwrap().0; + let wire = setup.encode_bytes(crate::Version::ietf(version)).unwrap(); + let decoded = Setup::decode_slice(&wire, crate::Version::ietf(version)).unwrap().0; let (params, _) = crate::ietf::Parameters::decode_slice(&decoded.parameters, version).unwrap(); assert_eq!(crate::ietf::token::from_setup(¶ms, version).unwrap(), Some(token)); tracing::trace!(?setup, ?decoded, ?params, "SETUP diagnostics"); @@ -397,7 +397,7 @@ mod tests { #[test] fn the_moql_setup_has_a_u16_size() { for v in [lite::Version::Lite01, lite::Version::Lite02] { - let v = Version::Lite(v); + let v = Version::lite(v); let client = Client { versions: coding::Versions::from([v.into()]), parameters: Bytes::from_static(&[0]), @@ -419,7 +419,7 @@ mod tests { /// Never emit a legacy SETUP our own receiver would refuse. #[test] fn encode_enforces_the_setup_limit() { - let v = Version::Lite(lite::Version::Lite01); + let v = Version::lite(lite::Version::Lite01); let parameters = Bytes::from(vec![0; MAX_SETUP_SIZE]); let client = Client { diff --git a/rs/moq-net/src/version.rs b/rs/moq-net/src/version.rs index ec59ed20794..1ed2612157c 100644 --- a/rs/moq-net/src/version.rs +++ b/rs/moq-net/src/version.rs @@ -11,13 +11,13 @@ use crate::{coding, ietf, lite}; /// moq-transport negotiates only by ALPN. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub(crate) const NEGOTIATED: [Version; 7] = [ - Version::Lite(lite::Version::Lite07), - Version::Lite(lite::Version::Lite06), - Version::Lite(lite::Version::Lite05), - Version::Lite(lite::Version::Lite04), - Version::Lite(lite::Version::Lite03), - Version::Lite(lite::Version::Lite02), - Version::Lite(lite::Version::Lite01), + Version::lite(lite::Version::Lite07), + Version::lite(lite::Version::Lite06), + Version::lite(lite::Version::Lite05), + Version::lite(lite::Version::Lite04), + Version::lite(lite::Version::Lite03), + Version::lite(lite::Version::Lite02), + Version::lite(lite::Version::Lite01), ]; /// ALPN strings for supported versions, most-preferred first. `ALPNS[0]` is the @@ -49,38 +49,52 @@ pub(crate) const ALPN_20: &str = "moqt-20"; pub(crate) const ALPN_22: &str = "moqt-22"; const ALL: [Version; 10] = [ - Version::Lite(lite::Version::Lite07), - Version::Lite(lite::Version::Lite06), - Version::Lite(lite::Version::Lite05), - Version::Lite(lite::Version::Lite04), - Version::Lite(lite::Version::Lite03), - Version::Lite(lite::Version::Lite02), - Version::Lite(lite::Version::Lite01), - Version::Ietf(ietf::Version::Draft22), - Version::Ietf(ietf::Version::Draft20), - Version::Ietf(ietf::Version::Draft18), + Version::lite(lite::Version::Lite07), + Version::lite(lite::Version::Lite06), + Version::lite(lite::Version::Lite05), + Version::lite(lite::Version::Lite04), + Version::lite(lite::Version::Lite03), + Version::lite(lite::Version::Lite02), + Version::lite(lite::Version::Lite01), + Version::ietf(ietf::Version::Draft22), + Version::ietf(ietf::Version::Draft20), + Version::ietf(ietf::Version::Draft18), ]; -/// A MoQ protocol version. +/// The draft a [`Version`] names, which only this crate tells apart. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -#[non_exhaustive] -pub enum Version { +pub(crate) enum Draft { /// A `moq-lite` draft, the simplified protocol this project specifies. Lite(lite::Version), /// An IETF `moq-transport` draft. Ietf(ietf::Version), } +/// A MoQ protocol version, such as `moq-lite-06`. +/// +/// Opaque: parse it ([`FromStr`]), print it, and ask [`is_lite`](Self::is_lite) or +/// [`alpn`](Self::alpn), so adding or dropping a draft is never an API change. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct Version(pub(crate) Draft); + impl Version { + pub(crate) const fn lite(version: lite::Version) -> Self { + Self(Draft::Lite(version)) + } + + pub(crate) const fn ietf(version: ietf::Version) -> Self { + Self(Draft::Ietf(version)) + } + /// Every version this crate speaks, newest first, including the opt-in `-wip` drafts /// that [`Versions::all`] leaves out. pub const ALL: &'static [Version] = &ALL; #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub(crate) fn session_code(self, error: &crate::SessionError) -> u32 { - match self { - Self::Lite(_) => crate::lite::error::to_session_code(error), - Self::Ietf(_) => crate::ietf::error::to_session_code(error), + match self.0 { + Draft::Lite(_) => crate::lite::error::to_session_code(error), + Draft::Ietf(_) => crate::ietf::error::to_session_code(error), } } @@ -88,9 +102,9 @@ impl Version { /// `Client::with_token`, behind the `async` feature). Every moq-transport draft can; /// moq-lite gained it in lite-07, so older versions need the credential in the URL. pub(crate) fn has_setup_token(self) -> bool { - match self { - Self::Lite(version) => version.has_auth(), - Self::Ietf(_) => true, + match self.0 { + Draft::Lite(version) => version.has_auth(), + Draft::Ietf(_) => true, } } @@ -98,73 +112,73 @@ impl Version { /// QUIC, qmux over TCP) can still name its target: moq-lite-05 and newer, and every /// moq-transport draft. pub fn has_request_path(&self) -> bool { - match self { - Self::Lite(version) => version.has_setup_stream(), - Self::Ietf(_) => true, + match self.0 { + Draft::Lite(version) => version.has_setup_stream(), + Draft::Ietf(_) => true, } } /// Handshake / config name, e.g. `moq-lite-05` or `moq-transport-22`. pub fn as_str(&self) -> &'static str { - match self { - Self::Lite(lite::Version::Lite01) => "moq-lite-01", - Self::Lite(lite::Version::Lite02) => "moq-lite-02", - Self::Lite(lite::Version::Lite03) => "moq-lite-03", - Self::Lite(lite::Version::Lite04) => "moq-lite-04", - Self::Lite(lite::Version::Lite05) => "moq-lite-05", - Self::Lite(lite::Version::Lite06) => "moq-lite-06", - Self::Lite(lite::Version::Lite07) => "moq-lite-07-wip", - Self::Ietf(ietf::Version::Draft18) => "moq-transport-18", - Self::Ietf(ietf::Version::Draft20) => "moq-transport-20", - Self::Ietf(ietf::Version::Draft22) => "moq-transport-22", + match self.0 { + Draft::Lite(lite::Version::Lite01) => "moq-lite-01", + Draft::Lite(lite::Version::Lite02) => "moq-lite-02", + Draft::Lite(lite::Version::Lite03) => "moq-lite-03", + Draft::Lite(lite::Version::Lite04) => "moq-lite-04", + Draft::Lite(lite::Version::Lite05) => "moq-lite-05", + Draft::Lite(lite::Version::Lite06) => "moq-lite-06", + Draft::Lite(lite::Version::Lite07) => "moq-lite-07-wip", + Draft::Ietf(ietf::Version::Draft18) => "moq-transport-18", + Draft::Ietf(ietf::Version::Draft20) => "moq-transport-20", + Draft::Ietf(ietf::Version::Draft22) => "moq-transport-22", } } /// Parse from wire version code (used during SETUP negotiation). pub(crate) fn from_code(code: u64) -> Option { match code { - 0xff0dad01 => Some(Self::Lite(lite::Version::Lite01)), - 0xff0dad02 => Some(Self::Lite(lite::Version::Lite02)), - 0xff0dad03 => Some(Self::Lite(lite::Version::Lite03)), - 0xff0dad04 => Some(Self::Lite(lite::Version::Lite04)), - 0xff0dad05 => Some(Self::Lite(lite::Version::Lite05)), - 0xff0dad06 => Some(Self::Lite(lite::Version::Lite06)), - 0xff0dad07 => Some(Self::Lite(lite::Version::Lite07)), - 0xff000012 => Some(Self::Ietf(ietf::Version::Draft18)), - 0xff000014 => Some(Self::Ietf(ietf::Version::Draft20)), - 0xff000016 => Some(Self::Ietf(ietf::Version::Draft22)), + 0xff0dad01 => Some(Self::lite(lite::Version::Lite01)), + 0xff0dad02 => Some(Self::lite(lite::Version::Lite02)), + 0xff0dad03 => Some(Self::lite(lite::Version::Lite03)), + 0xff0dad04 => Some(Self::lite(lite::Version::Lite04)), + 0xff0dad05 => Some(Self::lite(lite::Version::Lite05)), + 0xff0dad06 => Some(Self::lite(lite::Version::Lite06)), + 0xff0dad07 => Some(Self::lite(lite::Version::Lite07)), + 0xff000012 => Some(Self::ietf(ietf::Version::Draft18)), + 0xff000014 => Some(Self::ietf(ietf::Version::Draft20)), + 0xff000016 => Some(Self::ietf(ietf::Version::Draft22)), _ => None, } } /// Get the wire version code. pub(crate) fn code(&self) -> u64 { - match self { - Self::Lite(lite::Version::Lite01) => 0xff0dad01, - Self::Lite(lite::Version::Lite02) => 0xff0dad02, - Self::Lite(lite::Version::Lite03) => 0xff0dad03, - Self::Lite(lite::Version::Lite04) => 0xff0dad04, - Self::Lite(lite::Version::Lite05) => 0xff0dad05, - Self::Lite(lite::Version::Lite06) => 0xff0dad06, - Self::Lite(lite::Version::Lite07) => 0xff0dad07, - Self::Ietf(ietf::Version::Draft18) => 0xff000012, - Self::Ietf(ietf::Version::Draft20) => 0xff000014, - Self::Ietf(ietf::Version::Draft22) => 0xff000016, + match self.0 { + Draft::Lite(lite::Version::Lite01) => 0xff0dad01, + Draft::Lite(lite::Version::Lite02) => 0xff0dad02, + Draft::Lite(lite::Version::Lite03) => 0xff0dad03, + Draft::Lite(lite::Version::Lite04) => 0xff0dad04, + Draft::Lite(lite::Version::Lite05) => 0xff0dad05, + Draft::Lite(lite::Version::Lite06) => 0xff0dad06, + Draft::Lite(lite::Version::Lite07) => 0xff0dad07, + Draft::Ietf(ietf::Version::Draft18) => 0xff000012, + Draft::Ietf(ietf::Version::Draft20) => 0xff000014, + Draft::Ietf(ietf::Version::Draft22) => 0xff000016, } } /// Returns the ALPN string for this version. pub fn alpn(&self) -> &'static str { - match self { - Self::Lite(lite::Version::Lite07) => ALPN_LITE_07_WIP, - Self::Lite(lite::Version::Lite06) => ALPN_LITE_06, - Self::Lite(lite::Version::Lite05) => ALPN_LITE_05, - Self::Lite(lite::Version::Lite04) => ALPN_LITE_04, - Self::Lite(lite::Version::Lite03) => ALPN_LITE_03, - Self::Lite(lite::Version::Lite01 | lite::Version::Lite02) => ALPN_LITE, - Self::Ietf(ietf::Version::Draft18) => ALPN_18, - Self::Ietf(ietf::Version::Draft20) => ALPN_20, - Self::Ietf(ietf::Version::Draft22) => ALPN_22, + match self.0 { + Draft::Lite(lite::Version::Lite07) => ALPN_LITE_07_WIP, + Draft::Lite(lite::Version::Lite06) => ALPN_LITE_06, + Draft::Lite(lite::Version::Lite05) => ALPN_LITE_05, + Draft::Lite(lite::Version::Lite04) => ALPN_LITE_04, + Draft::Lite(lite::Version::Lite03) => ALPN_LITE_03, + Draft::Lite(lite::Version::Lite01 | lite::Version::Lite02) => ALPN_LITE, + Draft::Ietf(ietf::Version::Draft18) => ALPN_18, + Draft::Ietf(ietf::Version::Draft20) => ALPN_20, + Draft::Ietf(ietf::Version::Draft22) => ALPN_22, } } @@ -172,14 +186,14 @@ impl Version { /// as this version's ALPN would rather than on that stream. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub(crate) fn hands_off(self) -> bool { - matches!(self, Self::Lite(v) if !matches!(v, lite::Version::Lite01 | lite::Version::Lite02)) + matches!(self.0, Draft::Lite(v) if !matches!(v, lite::Version::Lite01 | lite::Version::Lite02)) } /// Whether this is a lite protocol version. pub fn is_lite(&self) -> bool { - match self { - Self::Lite(_) => true, - Self::Ietf(_) => false, + match self.0 { + Draft::Lite(_) => true, + Draft::Ietf(_) => false, } } } @@ -260,7 +274,7 @@ impl Versions { pub fn all() -> Self { Self( ALL.iter() - .filter(|version| !matches!(version, Version::Lite(lite::Version::Lite07))) + .filter(|version| **version != Version::lite(lite::Version::Lite07)) .copied() .collect(), ) @@ -341,7 +355,7 @@ mod tests { #[test] fn default_versions_prefer_lite_06() { - let newest = Version::Lite(lite::Version::Lite06); + let newest = Version::lite(lite::Version::Lite06); assert_eq!(newest.alpn(), "moq-lite-06"); assert!("moq-lite-06-wip".parse::().is_err()); assert_eq!(Versions::all().iter().next(), Some(&newest)); @@ -351,7 +365,7 @@ mod tests { #[test] fn lite_07_wip_is_opt_in_only() { - let wip = Version::Lite(lite::Version::Lite07); + let wip = Version::lite(lite::Version::Lite07); assert_eq!(wip.alpn(), "moq-lite-07-wip"); assert_eq!(wip.to_string(), "moq-lite-07-wip"); assert_eq!("moq-lite-07-wip".parse::(), Ok(wip)); diff --git a/rs/moq-net/tests/integration/auth.rs b/rs/moq-net/tests/integration/auth.rs index 91a70d96bee..b0e6f440f2b 100644 --- a/rs/moq-net/tests/integration/auth.rs +++ b/rs/moq-net/tests/integration/auth.rs @@ -479,7 +479,7 @@ async fn connect(opts: Options) -> Pair { }; let server_fut = async { let mut handshake = server - .accept_request(now(), server_transport) + .handshake(now(), server_transport) .await .expect("server handshake"); let setup_token = handshake.token().cloned(); diff --git a/rs/moq-net/tests/integration/control_stats.rs b/rs/moq-net/tests/integration/control_stats.rs index 22fd3f30f37..4e23984e3fa 100644 --- a/rs/moq-net/tests/integration/control_stats.rs +++ b/rs/moq-net/tests/integration/control_stats.rs @@ -99,7 +99,7 @@ async fn setup_counts_under_the_admitted_stats() { session }; let server = async { - let request = server.accept_request(now(), server_transport).await.unwrap(); + let request = server.handshake(now(), server_transport).await.unwrap(); let (session, driver) = request.with_stats(stats).ok().await.unwrap(); spawn(driver); session diff --git a/rs/moq-net/tests/integration/goaway.rs b/rs/moq-net/tests/integration/goaway.rs index dae27219687..b14515a8ebd 100644 --- a/rs/moq-net/tests/integration/goaway.rs +++ b/rs/moq-net/tests/integration/goaway.rs @@ -511,7 +511,7 @@ async fn goaway_drains_routes(version: Version) { let (standby_origin, _standby) = publish(); let mut opts = MockConnectOptions::new(version); opts.server_publish = Some(standby_origin.consume()); - opts.client_subscribe = Some(sub_origin.clone().with_preference(moq_net::origin::Preference::new(-1))); + opts.client_subscribe = Some(sub_origin.clone().with_priority(moq_net::origin::Priority::new(-1))); let _standby_pair = connect_mock(opts).await; let standby = route_at(&mut announced, |_| true).await.instance().clone(); diff --git a/rs/moq-net/tests/integration/instance.rs b/rs/moq-net/tests/integration/instance.rs index 4bdcfb3f313..bee6e8fefca 100644 --- a/rs/moq-net/tests/integration/instance.rs +++ b/rs/moq-net/tests/integration/instance.rs @@ -145,7 +145,7 @@ async fn next_hop_lost(version: &str) { let _second_hop = link( version, &standby, - &relay.clone().with_preference(origin::Preference::new(-1)), + &relay.clone().with_priority(origin::Priority::new(-1)), ) .await; if let Ok(event) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { diff --git a/rs/moq-net/tests/integration/mesh_withdraw.rs b/rs/moq-net/tests/integration/mesh_withdraw.rs index d0ed803addb..cc6fd7d6909 100644 --- a/rs/moq-net/tests/integration/mesh_withdraw.rs +++ b/rs/moq-net/tests/integration/mesh_withdraw.rs @@ -288,7 +288,7 @@ impl Cluster { let relays: Vec<_> = (1..=n as u64) .map(|id| { let mut config = config.clone(); - config.hop = std::num::NonZeroU64::new(id).unwrap(); + config.node = std::num::NonZeroU64::new(id).unwrap(); let (origin, driver) = origin::Producer::new(config); support::harness::spawn(driver); origin.with_proxy(true) diff --git a/rs/moq-net/tests/integration/multi_cdn.rs b/rs/moq-net/tests/integration/multi_cdn.rs index ff1eac34806..63dbdd2ef5d 100644 --- a/rs/moq-net/tests/integration/multi_cdn.rs +++ b/rs/moq-net/tests/integration/multi_cdn.rs @@ -4,7 +4,7 @@ //! //! A publisher `P` pushes one broadcast, under one instance, to CDN relays `A` and `B`. A //! subscriber `S` links to both, ranking `A` first by demoting `B` with -//! [`origin::Producer::with_preference`] while pricing `B` cheaper, so only the +//! [`origin::Producer::with_priority`] while pricing `B` cheaper, so only the //! preference puts `A` ahead. A lite-07 route ranks by the lowest preference on its path, //! and `P`'s links to both CDNs are neutral, so promoting `A` instead would gain nothing. Losing `A` moves `S` to `B`, and `A` returning moves it //! back. Between lite-07 routes, which carry the instance, each move resumes the @@ -65,7 +65,7 @@ async fn dial( ) -> MockPair { let mut options = MockConnectOptions::new(version); options.server_publish = Some(cdn.consume()); - options.client_subscribe = Some(subscriber.clone().with_preference(origin::Preference::new(preference))); + options.client_subscribe = Some(subscriber.clone().with_priority(origin::Priority::new(preference))); options.cost = Some(cost); connect_mock(options).await } diff --git a/rs/moq-net/tests/integration/route_acceptance.rs b/rs/moq-net/tests/integration/route_acceptance.rs index 14d22f1ffc5..1abd046ca10 100644 --- a/rs/moq-net/tests/integration/route_acceptance.rs +++ b/rs/moq-net/tests/integration/route_acceptance.rs @@ -36,7 +36,7 @@ async fn join(version: Version, a: &origin::Producer, b: &origin::Producer, join let [a, b] = [(a, join.preference[0]), (b, join.preference[1])].map(|(node, preference)| { node.clone() .with_link(origin::Link::Peer) - .with_preference(origin::Preference::new(preference)) + .with_priority(origin::Priority::new(preference)) }); let mut options = MockConnectOptions::new(version); options.client_publish = Some(a.consume().with_hidden(true)); diff --git a/rs/moq-net/tests/integration/route_change.rs b/rs/moq-net/tests/integration/route_change.rs index fa67d9da085..9af275db917 100644 --- a/rs/moq-net/tests/integration/route_change.rs +++ b/rs/moq-net/tests/integration/route_change.rs @@ -433,7 +433,7 @@ async fn route_dies_across_instances(version: &str, trigger: Trigger) { // A local preference keeps `B` on standby even on versions that carry no // cost, where equal-length routes of different instances rank by a hash. - let standby = relay.clone().with_preference(origin::Preference::new(-1)); + let standby = relay.clone().with_priority(origin::Priority::new(-1)); let _b_to_r = link(version, &relay_b, &standby).await; settle().await; diff --git a/rs/moq-net/tests/integration/route_cluster.rs b/rs/moq-net/tests/integration/route_cluster.rs index e0147ba7721..1c3c356aa61 100644 --- a/rs/moq-net/tests/integration/route_cluster.rs +++ b/rs/moq-net/tests/integration/route_cluster.rs @@ -46,7 +46,7 @@ async fn join( let acceptor = acceptor.clone().with_link(origin::Link::Peer); let mut options = MockConnectOptions::new(lite07()); options.client_publish = Some(dialer.consume().with_hidden(true)); - options.client_subscribe = Some(dialer.with_preference(origin::Preference::new(preference))); + options.client_subscribe = Some(dialer.with_priority(origin::Priority::new(preference))); options.server_publish = Some(acceptor.consume().with_hidden(true)); options.server_subscribe = Some(acceptor); options.cost = Some(cost); @@ -78,12 +78,12 @@ impl Links { preference: i8, ) { let pair = join(dialer, link, acceptor, cost, preference).await; - self.0.push((dialer.hop().get(), acceptor.hop().get(), pair)); + self.0.push((dialer.node().get(), acceptor.node().get(), pair)); } /// Close the session between `a` and `b`, and forget it. fn cut(&mut self, a: &origin::Producer, b: &origin::Producer) { - let (a, b) = (a.hop().get(), b.hop().get()); + let (a, b) = (a.node().get(), b.node().get()); let between = |(x, y, _): &(u64, u64, MockPair)| (*x, *y) == (a, b) || (*x, *y) == (b, a); let (_, _, pair) = self.0.iter().find(|link| between(link)).expect("no such link"); cut(pair); @@ -92,7 +92,7 @@ impl Links { /// `node` dies: every session it holds closes. fn kill(&mut self, node: &origin::Producer) { - let hop = node.hop().get(); + let hop = node.node().get(); let touches = |(x, y, _): &(u64, u64, MockPair)| *x == hop || *y == hop; self.0 .iter() @@ -328,7 +328,7 @@ async fn a_far_edge_reads_a_claim_and_sees_its_withdrawal_once() { quiesce().await; for (relay, watch) in regions.relays().zip(&mut watched) { let seen = watch.seen(); - assert_eq!(kinds(&seen), [Kind::End], "relay {}: {seen:?}", relay.hop()); + assert_eq!(kinds(&seen), [Kind::End], "relay {}: {seen:?}", relay.node()); } } @@ -620,7 +620,7 @@ async fn overlapping_wildcards_resolve_to_the_most_specific_claim_everywhere() { let mut subscribing = Vec::new(); for relay in lan.relays() { for (under, instance) in [("a", &narrow_instance), ("b", &wide_instance)] { - let path = format!("live/{under}/{}", relay.hop()); + let path = format!("live/{under}/{}", relay.node()); let broadcast = relay.consume().request(path.as_str(), None).await.unwrap(); assert_eq!(broadcast.info().instance.as_ref(), Some(instance), "{path}"); // Reading a track sends the request on to the claim. @@ -637,7 +637,7 @@ async fn overlapping_wildcards_resolve_to_the_most_specific_claim_everywhere() { narrow_paths.sort(); let expected = |under: &str| { let mut paths: Vec<_> = (lan.relays()) - .map(|relay| format!("live/{under}/{}", relay.hop())) + .map(|relay| format!("live/{under}/{}", relay.node())) .collect(); paths.sort(); paths @@ -700,7 +700,7 @@ async fn an_epochless_replacement_restarts_everywhere() { assert!( matches!(start.as_slice(), [Seen { kind: Kind::Start, .. }]), "relay {}: {start:?}", - relay.hop() + relay.node() ); watched.push((watch, start[0].instance.clone())); } @@ -709,7 +709,7 @@ async fn an_epochless_replacement_restarts_everywhere() { quiesce().await; for (relay, (watch, before)) in lan.relays().zip(&mut watched) { let seen = watch.seen(); - let hop = relay.hop(); + let hop = relay.node(); assert!( seen.iter() .all(|seen| seen.kind != Kind::End && seen.kind != Kind::Offline), @@ -756,7 +756,7 @@ async fn tokened_uplink(dialer: &origin::Producer, acceptor: &origin::Producer) session }; let server_fut = async { - let mut handshake = (server.accept_request(now(), server_transport.clone()).await).expect("server handshake"); + let mut handshake = (server.handshake(now(), server_transport.clone()).await).expect("server handshake"); let requests = handshake.requests(); let (session, driver) = handshake.ok().await.expect("server accept"); spawn(driver); diff --git a/rs/moq-net/tests/integration/route_failover.rs b/rs/moq-net/tests/integration/route_failover.rs index cecf4ac3df8..da827593a62 100644 --- a/rs/moq-net/tests/integration/route_failover.rs +++ b/rs/moq-net/tests/integration/route_failover.rs @@ -1018,7 +1018,7 @@ async fn a_name_announced_back_over_moq_transport_waits_without_retrying() { live.broadcast().create_track("video", timed()).unwrap(); live.announce().unwrap(); let mut options = links.options("p-r", &p, &r); - options.client_subscribe = Some(r.clone().with_preference(origin::Preference::new(-1))); + options.client_subscribe = Some(r.clone().with_priority(origin::Priority::new(-1))); let _p_r = connect_mock(options).await; kio::clock::sleep(Duration::from_secs(1)).await; let mut pairs = Vec::new(); diff --git a/rs/moq-relay/benches/session.rs b/rs/moq-relay/benches/session.rs index e07d0df77ab..89507e059e3 100644 --- a/rs/moq-relay/benches/session.rs +++ b/rs/moq-relay/benches/session.rs @@ -124,7 +124,7 @@ impl Backend for Relay { .with_versions(version.into()) .with_extensions(extensions); let handshake = server - .accept_request(moq_net::time::Instant::now(), server_link) + .handshake(moq_net::time::Instant::now(), server_link) .await .unwrap(); Connection::new(Accepted::new(handshake, moq_auth::Transport::Quic), cluster, auth) diff --git a/rs/moq-relay/src/auth/refresh.rs b/rs/moq-relay/src/auth/refresh.rs index 9589a96b0a4..0e0e3c1945a 100644 --- a/rs/moq-relay/src/auth/refresh.rs +++ b/rs/moq-relay/src/auth/refresh.rs @@ -605,7 +605,7 @@ mod tests { .with_versions("moq-lite-07-wip".parse::().unwrap().into()) .with_subscriber(origin) .with_stats(lease.stats.clone()) - .accept_request(now, server) + .handshake(now, server) .await .unwrap(); let lease = lease @@ -713,7 +713,7 @@ mod tests { .with_versions("moq-lite-07-wip".parse::().unwrap().into()) .with_subscriber(origin) .with_stats(stats.clone()) - .accept_request(now, server) + .handshake(now, server) .await .unwrap(); let mut changed = initial; diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index 9ddc6d776f5..84bd1136fe5 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -1417,7 +1417,7 @@ impl Cluster { /// The origin ID used by this relay on the wire. pub fn id(&self) -> u64 { - self.origin.hop().get() + self.origin.node().get() } /// Creates a cluster with one origin, using [`Options`] for identity, cache, @@ -1504,7 +1504,7 @@ impl Cluster { })); let stats = stats_producer.registry().clone(); let nodes = crate::nodes::Nodes::default(); - tracing::info!(hop_id = %origin.hop(), "cluster initialized"); + tracing::info!(hop_id = %origin.node(), "cluster initialized"); let cluster = Cluster { client_limits: client.resolve(), peer_limits: peer.resolve(), @@ -4079,7 +4079,7 @@ mod tests { .expect("origin closed"); assert_eq!(update.prefix.as_str(), "from-node"); // The dialer marks what the peer forwards: it entered at `node`, not here. - assert_eq!(update.route.source(), origin::Source::Peer(node.origin.hop().get())); + assert_eq!(update.route.source(), origin::Source::Peer(node.origin.node().get())); let _from_fp = fingerprint .origin @@ -4095,7 +4095,7 @@ mod tests { // The acceptor marks a LAN peer the same way. assert_eq!( update.route.source(), - origin::Source::Peer(fingerprint.origin.hop().get()) + origin::Source::Peer(fingerprint.origin.node().get()) ); break; } diff --git a/rs/moq-relay/src/connection.rs b/rs/moq-relay/src/connection.rs index ee68dfaece6..36b44a46c02 100644 --- a/rs/moq-relay/src/connection.rs +++ b/rs/moq-relay/src/connection.rs @@ -98,7 +98,7 @@ impl Connection { // Only this relay's origin holds its identity, so a session declaring it is this // relay dialing itself under a spelling its self filter missed. Every route // from it would be dropped as reflected, so refuse it rather than serve it. - if let Some(id) = request.peer_hop().filter(|id| lifecycle.cluster.origin.is_own(*id)) { + if let Some(id) = request.peer_node().filter(|id| lifecycle.cluster.origin.is_own(*id)) { request.reject(moq_net::SessionError::Internal).await; anyhow::bail!( "refused a session declaring this relay's own identity {id}: a cluster peer URL reaches this relay itself" diff --git a/rs/moq-relay/src/incoming.rs b/rs/moq-relay/src/incoming.rs index d065b759781..ca1dbc0d7fc 100644 --- a/rs/moq-relay/src/incoming.rs +++ b/rs/moq-relay/src/incoming.rs @@ -85,7 +85,7 @@ pub trait Sealed: Sized { fn requests(&mut self) -> moq_net::auth::Requests; fn role(&self) -> Option; /// The identity the peer declared in its SETUP, if any: its Hop ID, or from moq-lite-07 its Node ID. - fn peer_hop(&self) -> Option; + fn peer_node(&self) -> Option; fn with_stats(self, stats: moq_net::stats::Session) -> Self; fn with_limits(self, limits: moq_net::session::Limits) -> Self; fn with_publisher(self, publish: moq_net::origin::Consumer) -> Self; @@ -147,8 +147,8 @@ impl Sealed for moq_tokio::server::Request { moq_tokio::server::Request::role(self) } - fn peer_hop(&self) -> Option { - moq_tokio::server::Request::peer_hop(self) + fn peer_node(&self) -> Option { + moq_tokio::server::Request::peer_node(self) } fn with_stats(self, stats: moq_net::stats::Session) -> Self { @@ -217,8 +217,8 @@ impl Sealed for Accepted { self.handshake.role() } - fn peer_hop(&self) -> Option { - self.handshake.peer_hop() + fn peer_node(&self) -> Option { + self.handshake.peer_node() } fn with_stats(mut self, stats: moq_net::stats::Session) -> Self { diff --git a/rs/moq-relay/src/sim.rs b/rs/moq-relay/src/sim.rs index 63792023402..aa6d0669606 100644 --- a/rs/moq-relay/src/sim.rs +++ b/rs/moq-relay/src/sim.rs @@ -259,7 +259,7 @@ impl Net { let (cluster, auth, shutdown) = (cluster.clone(), auth.clone(), shutdown.clone()); drop(kio::clock::sim::spawn(async move { let server = moq_net::Server::new().with_versions(version.into()); - let Ok(handshake) = server.accept_request(moq_net::time::Instant::now(), link).await else { + let Ok(handshake) = server.handshake(moq_net::time::Instant::now(), link).await else { return; }; let request = Accepted::new(handshake, moq_auth::Transport::Quic); diff --git a/rs/moq-relay/src/uring.rs b/rs/moq-relay/src/uring.rs index 842f4325c51..7aec07b445d 100644 --- a/rs/moq-relay/src/uring.rs +++ b/rs/moq-relay/src/uring.rs @@ -726,7 +726,7 @@ async fn accept( let session = moq_uring::transport::Local::new(conn.clone()); let handshake = serve .moq - .accept_request(moq_net::time::Instant::now(), session) + .handshake(moq_net::time::Instant::now(), session) .with_deadline(deadline) .await .context("moq handshake failed")?; @@ -860,8 +860,8 @@ impl crate::incoming::Sealed for Request { self.handshake.role() } - fn peer_hop(&self) -> Option { - self.handshake.peer_hop() + fn peer_node(&self) -> Option { + self.handshake.peer_node() } fn with_stats(mut self, stats: moq_net::stats::Session) -> Self { diff --git a/rs/moq-relay/tests/integration/drain.rs b/rs/moq-relay/tests/integration/drain.rs index 2e6b918f512..3d6867fd350 100644 --- a/rs/moq-relay/tests/integration/drain.rs +++ b/rs/moq-relay/tests/integration/drain.rs @@ -41,7 +41,7 @@ async fn admit(observer: &shutdown::Observer, version: moq_net::Version, stalled drop(kio::clock::sim::spawn(async move { let server = moq_net::Server::new().with_versions(version.into()); let handshake = server - .accept_request(moq_net::time::Instant::now(), relay_link) + .handshake(moq_net::time::Instant::now(), relay_link) .await .expect("relay handshake"); let request = Accepted::new(handshake, moq_auth::Transport::Quic); diff --git a/rs/moq-relay/tests/integration/embed.rs b/rs/moq-relay/tests/integration/embed.rs index 179f118a32a..5e4870189c0 100644 --- a/rs/moq-relay/tests/integration/embed.rs +++ b/rs/moq-relay/tests/integration/embed.rs @@ -171,7 +171,7 @@ async fn embed_and_stop(mut config: Config) { relay.config().quic.max_streams, Some(moq_tokio::quic::DEFAULT_MAX_STREAMS) ); - assert_eq!(relay.cluster().id(), relay.cluster().origin.hop().get()); + assert_eq!(relay.cluster().id(), relay.cluster().origin.node().get()); // The application handles: in-process workers publish into the origin the // QUIC sessions see, and the trigger stops the owner from any task. Both diff --git a/rs/moq-relay/tests/integration/memory.rs b/rs/moq-relay/tests/integration/memory.rs index b4fd2f6ef17..feca46f991f 100644 --- a/rs/moq-relay/tests/integration/memory.rs +++ b/rs/moq-relay/tests/integration/memory.rs @@ -35,7 +35,7 @@ pub async fn connect( let (cluster, auth) = (cluster.clone(), auth.clone()); drop(kio::clock::sim::spawn(async move { let server = moq_net::Server::new().with_versions(version.into()); - let Ok(handshake) = server.accept_request(moq_net::time::Instant::now(), relay_link).await else { + let Ok(handshake) = server.handshake(moq_net::time::Instant::now(), relay_link).await else { return; }; let request = Accepted::new(handshake, moq_auth::Transport::Quic); diff --git a/rs/moq-relay/tests/integration/runtime_uring.rs b/rs/moq-relay/tests/integration/runtime_uring.rs index c84e6aebe5f..f9a0de883bc 100644 --- a/rs/moq-relay/tests/integration/runtime_uring.rs +++ b/rs/moq-relay/tests/integration/runtime_uring.rs @@ -433,7 +433,7 @@ async fn drain_on_the_trigger(version: Option) { let url: url::Url = format!("moql://127.0.0.1:{port}/drain").parse().expect("parse url"); let label = version.map_or("every version", |version| version.as_str()); // Only moq-transport puts the deadline on the wire. - let ietf = matches!(version, Some(moq_net::Version::Ietf(_))); + let ietf = version.is_some_and(|version| !version.is_lite()); let connecting = tokio::spawn(connect(client.clone(), url.clone())); let first = admissions.next().await.expect("first admission"); diff --git a/rs/moq-relay/tests/integration/socket_auth.rs b/rs/moq-relay/tests/integration/socket_auth.rs index 8cdbc722f74..6a21886964a 100644 --- a/rs/moq-relay/tests/integration/socket_auth.rs +++ b/rs/moq-relay/tests/integration/socket_auth.rs @@ -101,7 +101,7 @@ impl Fixture { let (cluster, auth) = (self.cluster.clone(), self.auth.clone()); tokio::spawn(async move { let server = moq_net::Server::new().with_versions(version.into()); - let Ok(handshake) = server.accept_request(moq_net::time::Instant::now(), relay_link).await else { + let Ok(handshake) = server.handshake(moq_net::time::Instant::now(), relay_link).await else { return; }; let request = Accepted::new(handshake, moq_auth::Transport::Quic); diff --git a/rs/moq-tokio/src/client.rs b/rs/moq-tokio/src/client.rs index 4f0026ebce2..dba21349454 100644 --- a/rs/moq-tokio/src/client.rs +++ b/rs/moq-tokio/src/client.rs @@ -45,8 +45,8 @@ impl Config { #[derive(Clone)] pub struct Client { pub(crate) moq: moq_net::Client, - /// The hop from [`Client::with_peer_hop`], or `None` for a fresh one per [`Connection`]. - pub(crate) peer_hop: Option, + /// The node from [`Client::with_peer_node`], or `None` for a fresh one per [`Connection`]. + pub(crate) peer_node: Option, /// The single resolved set of protocol versions, used for credentials and moq ALPNs across /// every transport (passed into the QUIC backend's `connect` and used directly for /// raw TCP/UDS qmux and WebSocket). Resolved once in [`Client::new`] so the ALPN list @@ -159,7 +159,7 @@ impl Client { Ok(Self { moq, - peer_hop: None, + peer_node: None, versions, connect: config.url, tokens: config.tokens, @@ -225,12 +225,12 @@ impl Client { self } - /// Pin the hop id a dialed peer's routes are attributed to, for a peer whose - /// identity the caller has established; see [`moq_net::Client::with_peer_hop`]. + /// Pin the Node ID a dialed peer's routes are attributed to, for a peer whose + /// identity the caller has established; see [`moq_net::Client::with_peer_node`]. /// Without one, each [`Connection`] draws its own and keeps it across reconnects. - pub fn with_peer_hop(mut self, hop: std::num::NonZeroU64) -> Self { - self.peer_hop = Some(hop); - self.moq = self.moq.with_peer_hop(hop); + pub fn with_peer_node(mut self, node: std::num::NonZeroU64) -> Self { + self.peer_node = Some(node); + self.moq = self.moq.with_peer_node(node); self } diff --git a/rs/moq-tokio/src/connection.rs b/rs/moq-tokio/src/connection.rs index 2549cda8e4b..726539100ea 100644 --- a/rs/moq-tokio/src/connection.rs +++ b/rs/moq-tokio/src/connection.rs @@ -964,9 +964,9 @@ impl Connection { // Every session of one connection reaches the same peer, so they share one hop: a // route one learned is then never another's to announce, such as a successor's // grant check judging what its draining predecessor learned. - let client = match client.peer_hop { + let client = match client.peer_node { Some(_) => client, - None => client.with_peer_hop(random_hop()), + None => client.with_peer_node(random_hop()), }; let closed: CloseGuard = Default::default(); @@ -3142,7 +3142,7 @@ mod tests { let mut request = moq_net::Server::new() .with_versions(versions.clone()) .with_subscriber(server_origin) - .accept_request(now, server) + .handshake(now, server) .await .unwrap(); // The connection credential grants nothing; only the configured token diff --git a/rs/moq-tokio/src/server.rs b/rs/moq-tokio/src/server.rs index 86ba46fea38..edc00fc858f 100644 --- a/rs/moq-tokio/src/server.rs +++ b/rs/moq-tokio/src/server.rs @@ -1430,7 +1430,7 @@ impl Request { active, } = incoming; let handshake = server - .accept_request(moq_net::time::Instant::now(), session) + .handshake(moq_net::time::Instant::now(), session) .with_deadline(deadline) .await?; Ok(Self { @@ -1475,11 +1475,11 @@ impl Request { self } - /// Assign the hop id this peer's routes are attributed to; see - /// [`moq_net::server::Handshake::with_peer_hop`]. Derive it from [`Self::peer_identity`], + /// Assign the Node ID this peer's routes are attributed to; see + /// [`moq_net::server::Handshake::with_peer_node`]. Derive it from [`Self::peer_identity`], /// never from something coarser. - pub fn with_peer_hop(mut self, hop: std::num::NonZeroU64) -> Self { - *self.handshake = (*self.handshake).with_peer_hop(hop); + pub fn with_peer_node(mut self, node: std::num::NonZeroU64) -> Self { + *self.handshake = (*self.handshake).with_peer_node(node); self } @@ -1684,8 +1684,8 @@ impl Request { /// /// Self-declared, so treat it as a correlation hint rather than an /// authenticated identity: authorize on the token or client certificate. - pub fn peer_hop(&self) -> Option { - self.handshake.peer_hop() + pub fn peer_node(&self) -> Option { + self.handshake.peer_node() } /// The implementation the client advertised in its SETUP, such as @@ -2189,7 +2189,7 @@ mod tests { } let handshake = moq_net::Server::new() .with_timeout(Some(std::time::Duration::from_secs(60))) - .accept_request(moq_net::time::Instant::now(), server) + .handshake(moq_net::time::Instant::now(), server) .await .expect("a buffered SETUP"); let request = Request { @@ -2426,7 +2426,7 @@ mod tests { server: moq_net::Server::new().with_timeout(Some(timeout)), }; let start = kio::clock::now(); - let accept = setup.server.accept_request(moq_net::time::Instant::now(), peer.clone()); + let accept = setup.server.handshake(moq_net::time::Instant::now(), peer.clone()); let Err(err) = accept.with_deadline(setup.deadline()).await else { panic!("a peer that never sent SETUP was accepted"); }; @@ -2518,7 +2518,7 @@ mod tests { session }); - let accept = setup.server.accept_request(moq_net::time::Instant::now(), server); + let accept = setup.server.handshake(moq_net::time::Instant::now(), server); let Ok(request) = accept.with_deadline(deadline).await else { panic!("a prompt SETUP was refused"); }; diff --git a/rs/moq-uring/src/transport/local.rs b/rs/moq-uring/src/transport/local.rs index 26e668cde95..afef70fd706 100644 --- a/rs/moq-uring/src/transport/local.rs +++ b/rs/moq-uring/src/transport/local.rs @@ -7,7 +7,7 @@ use std::task::Poll; /// /// moq-net boxes every transport with a native `Send` bound, which a worker's /// `!Send` session cannot meet, so wrap the session in this -/// before `Server::accept_request` or `Client::connect`. The session, its +/// before `Server::handshake` or `Client::connect`. The session, its /// streams, and its send groups never leave the worker that polls them, so /// this checks the thread on every use and panics anywhere else instead of /// proving it at compile time. From 7e491647ccc4f7025b423e19b21896b4d39bd482 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 17 Nov 2026 06:18:43 -0800 Subject: [PATCH 3/4] test(compat): the draft decides whether FETCH runs The adapter asked moq-net whether a lite draft has FETCH through `Version::Lite(v).has_track_stream()`, which the opaque `Version` and the crate-private predicates no longer expose, so `just test wire-compat` could not build its current adapter. The draft defines FETCH (lite-05 onward), so the harness decides from the version name, and a library that drops it fails the FETCH cells instead of a separate capability cell. Co-Authored-By: Claude Opus 5.5 --- test/interop/README.md | 7 +++--- test/interop/compat.sh | 33 +++++++++-------------------- test/interop/compat/container.rs | 10 +-------- test/interop/compat/resolve.test.ts | 4 ---- test/interop/staging.test.py | 3 --- 5 files changed, 14 insertions(+), 43 deletions(-) diff --git a/test/interop/README.md b/test/interop/README.md index 8e49f83bea0..c54040e5236 100644 --- a/test/interop/README.md +++ b/test/interop/README.md @@ -380,10 +380,9 @@ with their own relay, publisher, and Rust/JS readers on moq-lite-06. These controls always run, including when a planned break skips cross-version lanes, so a broken reader cannot make compatibility failures ambiguous. -Each `moq-net` library states whether a draft has FETCH (lite-05 onward -today). A draft without it in both is logged and its FETCH lanes skipped; one -the release supports and the checkout dropped fails, unless a planned break covers -the `fetch-capability` cell for that version. Both Rust versions FETCH the group the +The draft decides whether FETCH runs (lite-05 onward); an older draft is logged +and its FETCH lanes skipped, so a library that drops FETCH on a draft that has it +fails those lanes. Both Rust versions FETCH the group the publisher's own compat client observed and compare every frame's exact payload. JS publishers write one group after that subscriber's demand, and the opposite-source Rust CLI FETCHes it by the same observed ID. diff --git a/test/interop/compat.sh b/test/interop/compat.sh index 38ff6d98e15..c8aebcbed37 100755 --- a/test/interop/compat.sh +++ b/test/interop/compat.sh @@ -132,13 +132,6 @@ edition = "2024" hang = $dependency bytes = "1" TOML - # The adapter names moq-net itself, so it takes the copy this hang resolves. - if [[ "$source" == current ]]; then - net="{ path = \"$WORKSPACE/rs/moq-net\" }" - else - net="\"=$(cargo tree --manifest-path "$manifest" --invert moq-net --depth 0 --prefix none | awk '{ print substr($2, 2) }')\"" - fi - echo "moq-net = $net" >>"$manifest" cargo build --manifest-path "$manifest" --target-dir "$TARGET/compat-hang-$source" harness_stage "hang-$source/compat-container" "$TARGET/compat-hang-$source/debug/compat-container" "$HARNESS_RUN/hang-$source/compat-container" encode "$HARNESS_RUN/$source.catalog" "$HARNESS_RUN/$source.frame" @@ -168,7 +161,7 @@ cell() { local name="$version relay=$relay_source publisher=$source $lane" # A control reads its own source's output; every other cell reads the opposite one's. case "$lane:$source" in - media-control:* | *:both) reader="$source" ;; + media-control:*) reader="$source" ;; *:current) reader=released ;; *) reader=current ;; esac @@ -233,22 +226,16 @@ done 3<"$HARNESS_RUN/controls" # drafts are listed: our clients and relays always prefer lite with each other, so # IETF between them is not compared here (`just test interop` covers IETF). # Fd 3, so a child reading stdin (ffmpeg does) cannot consume the version list. -# Dropping a released FETCH is a cell, so a planned break on its version covers it too. -fetch_kept() { - [[ "$1" != true || "$2" == true ]] || { - echo "the checkout removed published FETCH" - return 1 - } -} while read -r version <&3; do released_relay="$HARNESS_RUN/released/bin/moq-relay" - # Each moq-net library states whether the draft has FETCH, so a FETCH cell that - # fails is a failure, never a skip. Dropping a released capability fails too. - current_fetch=$("$HARNESS_RUN/hang-current/compat-container" fetch-supported "$version") - released_fetch=$("$HARNESS_RUN/hang-released/compat-container" fetch-supported "$version") - cell fetch-capability "$version" both both fetch_kept "$released_fetch" "$current_fetch" - if [[ "$released_fetch" != true || "$current_fetch" != true ]]; then - echo "SKIP $version fetch and js-publish: no FETCH on this draft in both libraries" + # The draft defines FETCH (lite-05 onward), so a library that drops it fails the + # FETCH cells rather than skipping them. + case "$version" in + moq-lite-0[1-4]) has_fetch=false ;; + *) has_fetch=true ;; + esac + if [[ "$has_fetch" != true ]]; then + echo "SKIP $version fetch and js-publish: the draft has no FETCH" skipped=$((skipped + 8)) fi for relay_source in current released; do @@ -265,7 +252,7 @@ while read -r version <&3; do cell "media-$reader" "$version" "$relay_source" "$source" env RELAY_BIN="$relay" CLI_BIN="$pub" INTEROP_SUB_MOQ="$sub" INTEROP_VERSION="$version" \ INTEROP_COMPAT_CLIENT="$other_js" INTEROP_DECODE=1 INTEROP_PUB_LIVE="$(live_publisher "$pub")" bash "$DIR/interop.sh" --subscribers "$reader" done - [[ "$released_fetch" == true && "$current_fetch" == true ]] || continue + [[ "$has_fetch" == true ]] || continue # Drive JS publication from actual subscriber demand: the publisher's own JS # subscribes and observes the group, which the opposite Rust CLI then # FETCHes by ID. Reading the newest group races its live delivery. diff --git a/test/interop/compat/container.rs b/test/interop/compat/container.rs index adcc0d8ba4f..8ab2e4bc017 100644 --- a/test/interop/compat/container.rs +++ b/test/interop/compat/container.rs @@ -12,14 +12,6 @@ use std::{env, fs}; fn main() -> Result<(), Box> { let args: Vec<_> = env::args().collect(); match args[1].as_str() { - "fetch-supported" => { - // The library's own capability, so a failing FETCH cell is a failure, not a skip. - let supported = match args[2].parse::()? { - moq_net::Version::Lite(version) => version.has_track_stream(), - _ => return Err("the released comparison runs only moq-lite".into()), - }; - println!("{supported}"); - } "encode" => { let catalog = Catalog::<()>::from_str( r#"{"video":{"renditions":{"video":{"codec":"avc3.42001e","container":{"kind":"legacy"}}}},"audio":{"renditions":{}}}"#, @@ -40,7 +32,7 @@ fn main() -> Result<(), Box> { assert_eq!(frame.timestamp, Timestamp::from_micros(1000001)?); assert_eq!(frame.payload.as_ref(), b"compat-frame"); } - _ => return Err("expected fetch-supported, encode, or decode".into()), + _ => return Err("expected encode or decode".into()), } Ok(()) } diff --git a/test/interop/compat/resolve.test.ts b/test/interop/compat/resolve.test.ts index 48d4f0bda06..a9f59d9d849 100644 --- a/test/interop/compat/resolve.test.ts +++ b/test/interop/compat/resolve.test.ts @@ -37,10 +37,6 @@ test("an approved wire break can retain its protocol name, but new drafts still expect(matrix([OLD], [OLD], { [OLD]: exception }).shared).toEqual([OLD]); const cell = { lane: "fetch", version: OLD, relay: "current", publisher: "released" }; expect(planned({ [OLD]: exception }, cell)).toEqual([OLD]); - // The FETCH capability check is a cell too, so the break covers it. - expect( - planned({ [OLD]: exception }, { lane: "fetch-capability", version: OLD, relay: "both", publisher: "both" }), - ).toEqual([OLD]); expect(planned({ [OLD]: exception }, { ...cell, version: NEW })).toEqual([]); expect(() => matrix([OLD], [OLD, NEW], { [OLD]: exception })).toThrow("removed published"); }); diff --git a/test/interop/staging.test.py b/test/interop/staging.test.py index e75f205d468..6584924d921 100644 --- a/test/interop/staging.test.py +++ b/test/interop/staging.test.py @@ -45,7 +45,6 @@ def setUp(self): self.tools / "cargo", """ case "$1" in - tree) echo "moq-net v0.1.0" ;; metadata) printf '{"target_directory":"%s"}\n' "$FIXTURE_TARGET" ;; install) while [[ "$1" != --root ]]; do shift; done @@ -189,7 +188,6 @@ def test_wire_compat_adapters_and_current_binaries_are_owned(self): case "$1" in encode) echo catalog >"$2"; echo frame >"$3" ;; decode) [[ "$(cat "$2")" == catalog && "$(cat "$3")" == frame ]] ;; - fetch-supported) echo false ;; *) exit 2 ;; esac """, @@ -210,7 +208,6 @@ def test_wire_compat_adapters_and_current_binaries_are_owned(self): "$HARNESS_RUN/current/moq-relay" --help for source in current released; do "$HARNESS_RUN/hang-$source/compat-container" decode "$HARNESS_RUN/current.catalog" "$HARNESS_RUN/current.frame" - [[ "$("$HARNESS_RUN/hang-$source/compat-container" fetch-supported moq-lite-07)" == false ]] done """ ) From 76e6ef03161eebd7e064cab9db748963d302dd02 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 17 Nov 2026 06:37:21 -0800 Subject: [PATCH 4/4] docs: a lite-07 route ranks by the lowest link priority on its path Co-Authored-By: Claude Opus 5.5 --- doc/concept/identity.md | 3 ++- doc/concept/moq-lite.md | 3 ++- doc/lib/rs/moq-net.md | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/concept/identity.md b/doc/concept/identity.md index bb4d433f167..c1e958adf06 100644 --- a/doc/concept/identity.md +++ b/doc/concept/identity.md @@ -74,7 +74,8 @@ A route resolving a path is chosen in this order: because the timeline continues. 3. Among eligible routes: a route from a peer that has not sent GOAWAY (a draining peer's routes rank below every other, whatever their preference - or cost, and serve only as a last resort), then the highest-priority link, then an + or cost, and serve only as a last resort), then the highest priority, which on + moq-lite 07 is the lowest of any link along the route's path, then an identified chain over an anonymous one, then the lowest cost, then a broadcast published on this origin, then the shortest hop chain, then a hash of the full requested diff --git a/doc/concept/moq-lite.md b/doc/concept/moq-lite.md index 3ca9d7753d3..8221336c0da 100644 --- a/doc/concept/moq-lite.md +++ b/doc/concept/moq-lite.md @@ -163,7 +163,8 @@ An endpoint can hold sessions to several CDNs at once, each feeding one shared origin, and rank them: moq.pro as primary, another CDN as secondary. The rank is a per-link priority the endpoint sets (higher wins, 0 is neutral, negative demotes), unrelated to a subscription's priority. It decides among instances before cost, so metrics from different operators are never -compared. A subscription uses the highest-priority link that has a route and moves to the +compared. After the earlier keys of [choosing a route](/concept/identity#choosing-a-route), a subscription uses the +route with the highest priority, on moq-lite 07 the lowest of any link along its path, and moves to the next when that route goes; a publisher pushes the same broadcast to every CDN. The move resumes without a seam only between routes with the same instance, diff --git a/doc/lib/rs/moq-net.md b/doc/lib/rs/moq-net.md index c9cabcae43d..00e6e89f273 100644 --- a/doc/lib/rs/moq-net.md +++ b/doc/lib/rs/moq-net.md @@ -18,7 +18,7 @@ What you use it for, beyond what the concept page already describes: - **An origin outlives the session.** `origin.route(path, options)` returns a `Route` that owns the broadcast to fill (`route.broadcast()`) and controls its announcement: `announce()`, `withdraw()`, `set_cost()`, and dropping the last clone retracts it. `origin.claim(prefix, options)` returns a `Claim` that serves requests beneath a prefix instead: `claim.requested()` yields each one, answered with `request.serve(held)`, `request.route(options)` (the path's own exact route) or `reject`. A `Claim` has the same announcement controls and no broadcast. A standalone broadcast cannot announce; publish one only through a claim's `serve`. A reconnect announces existing routes again, and closing the session does not delete them. - **Routes report what the mesh filled in.** An announcement's `route` gives its `instance()` and `cost()`; an application sets only `RouteOptions`. The hop chain a relay uses for loop detection stays internal. An origin's own Node ID is `origin::Config::node`, random unless a relay names one. - **Requests can pin an instance.** `consumer.request(path, Some(instance))` resolves only through a route announcing that [publisher instance](/concept/moq-lite#publisher-instances); `None` takes whichever route wins. The resolved consumer names its instance in `info().instance`, pinned or not. `origin.route(path, options)` serves a random instance minted when it is created and kept across `withdraw()` and `announce()`. Unless one is named, a claim moves to a fresh instance each time a job holding its current one ends, and a job takes the claim's. Set one with `RouteOptions::with_instance(instance, epoch)` only for a publisher that continues its timeline across restarts, so its group starts keep rising, and raises the epoch each time. `route.instance()` names it. -- **Rank several CDNs.** Dial each with its own subscribe handle, `origin.clone().with_priority(origin::Priority::new(rank))` (higher wins; 0 is neutral and a negative rank demotes), all on one origin. Requests use the highest-priority link that has a route and fail over to the next; see [multiple CDNs](/concept/moq-lite#multiple-cdns). +- **Rank several CDNs.** Dial each with its own subscribe handle, `origin.clone().with_priority(origin::Priority::new(rank))` (higher wins; 0 is neutral and a negative rank demotes), all on one origin. After the earlier route keys, requests use the route with the highest priority, on moq-lite 07 the lowest of any link along its path, and fail over to the next; see [multiple CDNs](/concept/moq-lite#multiple-cdns). - **Request one instance, or follow them all.** `consumer.request(path, None)` resolves the instance serving a path now, and fails `Unroutable` only once discovery has synced with no route for it. `consumer.follow(path, None)` hands out each publisher instance serving a path from `available()`: the first once announced, then each one that takes over, `None` once the path goes offline, and whatever serves it next, like JS `follow(path)`. `consumer.announced()` lists paths as present, then unavailable or available as a held route loses and recovers its path, and finally absent once the origin withdraws one or offline once this side lets go of it, which says nothing of whether the origin still serves it. A broadcast already resolved stays on the old instance until dropped or its route goes. See [identity and recovery](/concept/identity) to choose between following and holding one instance. - **Discovery follows what you watch.** A client session asks the relay for announcements only under the prefixes its subscribe origin's readers watch, with `announced()`, `request`, or `follow`, stops asking about a prefix 2s after nothing at or beneath it is watched, and asks again on reconnect. A broadcast resolved through a discovered route keeps its path watched until dropped. `request` owns discovery of its path, so no separate watch is needed. A server session, or a client fed into an origin handle marked `with_link(origin::Link::Peer)` or `Link::Upstream`, asks for everything it may, so a relay discovers everything. An HTTP gateway (the moq-hls `Server`, the moq-webrtc WHEP router) watches its whole scope while it lives, so the paths its callers name never open a request each. moq-lite-03/04 sessions, whose announcements mark no initial set, still ask for everything. - **Relay by opting into proxying.** On moq-lite-07 (`moq-lite-07-wip`, opt-in) a session sends its peer only the routes to its origin's own claims, so an application never becomes transit for anyone else. A relay built on the library marks the handle it publishes with `origin.clone().with_proxy(true)` to carry what it learned from other peers too; `moq-relay` does so for every session. Older versions advertise everything either way.