diff --git a/doc/concept/socket.md b/doc/concept/socket.md index d096572d04f..8073f8a1ca9 100644 --- a/doc/concept/socket.md +++ b/doc/concept/socket.md @@ -20,8 +20,15 @@ subscriptions, not a wire extension. It uses no instances and no track listings, and relays carry it unchanged. It needs moq-lite-07 or moq-transport on every hop: an endpoint's broadcast is [hidden](/concept/moq-lite#hidden-broadcasts), and an older moq-lite hop -never carries hidden broadcasts, so a dial across one never finds its peer. This page is the convention, enough to implement it in any -language. +never carries hidden broadcasts, so a dial across one would never find its +peer. Clustered relays carry hidden broadcasts to each other on every version, +so the hop that decides is each endpoint's own session: while an endpoint's +client session is moq-lite before 07, its dials and accepts fail with +`Unsupported` instead of waiting, unless that session's publish half opts into +hidden broadcasts. A dialer can't tell a peer behind such a hop from one not +online yet, so its dial waits as for any absent peer, while the peer's own +accepts fail. This page is the convention, enough to +implement it in any language. [`moq_net::socket`](https://docs.rs/moq-net/latest/moq_net/socket/) implements it in Rust. diff --git a/doc/lib/rs/moq-net.md b/doc/lib/rs/moq-net.md index fe0dbd9c88c..b54f83999ed 100644 --- a/doc/lib/rs/moq-net.md +++ b/doc/lib/rs/moq-net.md @@ -20,7 +20,7 @@ What you use it for, beyond what the concept page already describes: - **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). - **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 or returns after an end, like JS `follow(path)`. 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-rtc 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. -- **Dial and accept sockets.** `socket::Endpoint::new(&origin, prefix, id)` announces a hidden endpoint at `/.socket/`, used only to route dials. A session speaks one of two protocols, each with its own dial and accept. `accept_tcp()` and `accept_track()` yield an `Incoming` dial to `accept` or `reject` (dropping it rejects). `dial_tcp(peer)` and an accepted `tcp` dial yield a `socket::TcpStream`, a `group::Producer` and `group::Consumer` pair carrying one reliable, ordered byte pipe each way (finish is FIN, abort is RST, and `ready` paces the writer to the reader); `dial_track(peer, info)` and an accepted `track` dial yield a `socket::TrackStream`, this side's `track::Producer` and a `track::Subscriber` of the peer's half, subscribed reliably and in order until the application updates it, one message per group. A dial resolves once the peer accepts, and an accept checks that the claimed dialer really dialed this endpoint, waiting for its endpoint while the dial stays open. Session tracks are never announced or listed. See [Sockets](/concept/socket). +- **Dial and accept sockets.** `socket::Endpoint::new(&origin, prefix, id)` announces a hidden endpoint at `/.socket/`, used only to route dials. A session speaks one of two protocols, each with its own dial and accept. `accept_tcp()` and `accept_track()` yield an `Incoming` dial to `accept` or `reject` (dropping it rejects). `dial_tcp(peer)` and an accepted `tcp` dial yield a `socket::TcpStream`, a `group::Producer` and `group::Consumer` pair carrying one reliable, ordered byte pipe each way (finish is FIN, abort is RST, and `ready` paces the writer to the reader); `dial_track(peer, info)` and an accepted `track` dial yield a `socket::TrackStream`, this side's `track::Producer` and a `track::Subscriber` of the peer's half, subscribed reliably and in order until the application updates it, one message per group. A dial resolves once the peer accepts, and an accept checks that the claimed dialer really dialed this endpoint, waiting for its endpoint while the dial stays open. Every hop needs moq-lite-07 or moq-transport: while the origin has an older moq-lite client session whose publish half doesn't opt into hidden broadcasts (`with_hidden(true)`), dials and accepts fail with `Unsupported`. A dial to a peer behind such a hop waits, as for a peer not online yet. Session tracks are never announced or listed. See [Sockets](/concept/socket). - **One track per name.** Concurrent subscriptions share one request and producer. The application owns sequence numbers: the broadcast keeps nothing of an ended track, so a producer that replaces it starts at 0. A name always means the same content, so the replacement continues past its predecessor's groups with `create_group` at an explicit sequence. Readers of an aborted track resume onto the replacement when they read through an origin request, whose route always names an instance; otherwise their subscription ends with the error. - **Authored tracks default to a zero `max_age`.** `track::Info::default()` sets `max_age` to `Some(Duration::ZERO)`, the live edge only; a publisher that wants readers to reach history sets a longer bound, or `with_max_age(None)` for no publisher limit. Media tracks from `hang::container::track_info` declare `hang::container::MAX_AGE` (30 seconds). `max_age` is how long a superseded group stays fresh, never the newest group; it frees no bytes, which the cache pool's expiry reclaims. Received metadata keeps absence as no limit, and an origin's `cache_duration` can only cap it lower. - **End content by finishing tracks.** A broadcast has no finished state. When the input ends, finish each track; the broadcast stays announced and keeps serving them until you close it or drop its last producer. How long to keep it up for late readers is yours to decide: `moq_mux::Linger` holds a hang broadcast for a fixed window. diff --git a/quest/m1/socket/README.md b/quest/m1/socket/README.md index b6bdb4f0136..190ef7452b1 100644 --- a/quest/m1/socket/README.md +++ b/quest/m1/socket/README.md @@ -147,8 +147,10 @@ standing where the 2026-11-04 decisions above don't replace it: [moq-dev/moq#7677](https://github.com/moq-dev/moq/pull/7677): it needs moq-lite-07 or moq-transport on every hop, since a moq-lite hop before 07 has no hidden opt-in and never carries an endpoint's `.socket/` - broadcast; [older hops](/quest/m1/socket/old-hop-dial.md) make such a dial - fail instead of waiting. + broadcast. Relays' cluster links carry hidden broadcasts on every version, + so an endpoint's own client session is the hop that decides: while one is + moq-lite before 07, its dials and accepts fail `Unsupported` instead of + waiting ([moq-dev/moq#7888](https://github.com/moq-dev/moq/pull/7888)). - Fixed channels become sessions or messages on one: boy's `command` and per-viewer latency, CARLA's `control`, ack, and e-stop. Shared state such as boy's `status` stays an ordinary broadcast. @@ -187,7 +189,6 @@ announce-watch-request pairing remains in `rs/moq-boy`, `js/moq-boy`, or ## Required - [JS sockets](/quest/m1/socket/js.md) - the same surface in `@moq/net`, interoperating with Rust -- [A socket dial over an older hop fails instead of waiting](/quest/m1/socket/old-hop-dial.md) - a dial through a pre-lite-07 hop fails `Unsupported` - [Python sockets](/quest/m1/socket/py.md) - moq-ffi and `py/moq-rs` bindings, interoperating with Rust - [moq-boy on sockets](/quest/m1/socket/boy.md) - viewers dial the emulator's endpoint and send commands and receive latency on their session - [CARLA on sockets](/quest/m1/socket/carla.md) - drivers dial the truck's endpoint and send control and receive acks on their session diff --git a/quest/m1/socket/js.md b/quest/m1/socket/js.md index e9a70cc0596..47b5454ddfc 100644 --- a/quest/m1/socket/js.md +++ b/quest/m1/socket/js.md @@ -23,5 +23,8 @@ request so no listing names them; an unknown or unaccepted protocol is reset as unsupported. JS reads without fastest-reader pacing until [JS fastest-reader pacing](/quest/m2/js-fastest-reader.md), so a JS `tcp` reader that falls a group tail behind fails with an eviction error; say so in -the docs. Add the Rust/JS pairs to `just test interop`, and document the -export in `doc/lib/js/net.md`. +the docs. As in Rust, dials and accepts fail as unsupported while the +endpoint's connection is moq-lite before 07, which never carries its hidden +broadcast, instead of waiting forever; test it against a lite-06 connection. +Add the Rust/JS pairs to `just test interop`, and document the export in +`doc/lib/js/net.md`. diff --git a/quest/m1/socket/old-hop-dial.md b/quest/m1/socket/old-hop-dial.md deleted file mode 100644 index 646a5884758..00000000000 --- a/quest/m1/socket/old-hop-dial.md +++ /dev/null @@ -1,43 +0,0 @@ -# [S] A socket dial over an older hop fails instead of waiting - -## Goal - -A socket dial or accept through a hop older than moq-lite-07 fails with -`Unsupported` instead of waiting forever. An endpoint's `.socket/` -broadcast is hidden, and a moq-lite hop before 07 has no hidden opt-in on its -announce requests, so it never carries the broadcast: a dial across one never -finds its peer's endpoint, and an acceptor reached by a dialer behind one waits -for the dialer's endpoint for as long as the dial stays open. - -## Plan - -Decided 2026-11-03 (maintainer, follow-up planning after the 2026-11-03 /quest-afk and /quest-complete runs), milestone: - -- m0 -- ✅ m1, in this epic -- m2 - -From [moq-dev/moq#7677](https://github.com/moq-dev/moq/pull/7677), which -landed Rust sockets on one hidden endpoint broadcast. Its first plan here, an -answer instance check, belonged to the earlier `.accept/` design, which -used instances; the endpoint design uses none. - -Facts from #7677's head, over the shared relay harness -(`rs/moq-net/tests/integration/socket.rs`): a moq-lite-06 client's request for -`room/.socket/bob` fails `Unroutable` where `room/plain/bob` resolves, and a -`tcp` session times out for lite-06 to lite-06, lite-07 to lite-06, and -lite-03 to lite-03. With a lite-06 dialer and a lite-07 acceptor, the acceptor -hears the dial, and its accept then waits until the dialer gives up. - -- Find where an endpoint can learn that a hop on the path can't carry hidden - broadcasts, such as the session's negotiated version, or a relay answering - a hidden request it can't route with a distinct error, and fail the dial or - accept `Unsupported` there. Weigh one that sees only the first hop against - one that covers relay-to-relay hops, and record the choice. -- Python inherits it through moq-ffi. If [JS sockets](/quest/m1/socket/js.md) - has landed, its dial and accept get the same check. -- Test through a pre-lite-07 hop: the dial and the accept fail promptly with - `Unsupported`. - -Public API: none (an existing error). Wire: none, unless a relay's answer -needs one. diff --git a/rs/moq-net/CHANGELOG.md b/rs/moq-net/CHANGELOG.md index 678445b1b56..60287cad324 100644 --- a/rs/moq-net/CHANGELOG.md +++ b/rs/moq-net/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- `socket`: `Endpoint`, which announces a hidden `/.socket/` broadcast, dials other endpoints, and accepts their dials in two protocols: `tcp` sessions (`dial_tcp`, `accept_tcp`, `TcpStream`), one group each way as a reliable, ordered byte pipe, and `track` sessions (`dial_track`, `accept_track`, `TrackStream`), a track each way with one message per group; see `doc/concept/socket.md`. +- `socket`: `Endpoint`, which announces a hidden `/.socket/` broadcast, dials other endpoints, and accepts their dials in two protocols: `tcp` sessions (`dial_tcp`, `accept_tcp`, `TcpStream`), one group each way as a reliable, ordered byte pipe, and `track` sessions (`dial_track`, `accept_track`, `TrackStream`), a track each way with one message per group. Dials and accepts fail `Unsupported` while the origin has a moq-lite client session before 07 whose publish half doesn't opt into hidden broadcasts, since its peer never hears the endpoint; see `doc/concept/socket.md`. - `transport::SETUP_RECEIVE_WINDOW`, the connection credit a server offers before it admits a session: enough for the SETUP and one in-band AUTH. ## [0.3.10](https://github.com/moq-dev/moq/compare/moq-net-v0.3.9...moq-net-v0.3.10) - 2026-10-05 diff --git a/rs/moq-net/src/lite/session.rs b/rs/moq-net/src/lite/session.rs index 3f63276c0f5..cacafe5d421 100644 --- a/rs/moq-net/src/lite/session.rs +++ b/rs/moq-net/src/lite/session.rs @@ -275,6 +275,11 @@ pub fn start(config: Config) -> Result { .with_stats(stats.clone()) }); let subscribe = subscribe.unwrap_or_else(|| origin::Producer::empty(Hop::random()).with_stats(stats.clone())); + // Before lite-07 the peer can't ask for hidden routes, so a client publishes none of + // them unless its publish half opted in, and a socket endpoint behind it is + // unreachable. A server leaves it to the client, whose origin holds that endpoint. + let withholding = + (client && !version.has_hidden() && !publish.includes_hidden()).then(|| publish.hidden_withheld().hold()); let subscriptions = crate::session::Slots::default().with_stats(publish.stats(), crate::stats::Cap::Subscriptions); let announces = crate::session::Slots::new(limits.announces).with_stats(subscribe.stats(), crate::stats::Cap::Announces); @@ -389,6 +394,7 @@ pub fn start(config: Config) -> Result { publisher, subscriber: SubscriberDriver::new(subscriber, early, client), session, + withholding, }; Ok(SessionStart { @@ -423,6 +429,9 @@ pub(crate) struct Driver { /// For the terminal close: the machine's last act reports the outcome to /// the peer through the transport. session: Transport, + /// Counts this session against the publish origin while it withholds that origin's + /// hidden routes from the peer. + withholding: Option, } impl Driver { @@ -452,6 +461,7 @@ impl Driver { } } self.ending = Some(res); + self.withholding = None; } // Closing the transport first bounds every read, including when a control // stream ended the protocol while the connection itself was still live. diff --git a/rs/moq-net/src/model/mod.rs b/rs/moq-net/src/model/mod.rs index 3f46801d4d9..83e3535032d 100644 --- a/rs/moq-net/src/model/mod.rs +++ b/rs/moq-net/src/model/mod.rs @@ -53,6 +53,9 @@ pub use timed::Timed; /// Publishing broadcasts, announcing routes, and consuming both through an origin. pub mod origin { pub use super::follow::Following; + pub(crate) use super::origin_impl::HiddenWithheld; + #[cfg(feature = "async")] + pub(crate) use super::origin_impl::HiddenWithholding; #[cfg(feature = "async")] // private: capability gap pub(crate) use super::origin_impl::Lookup; diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index 26eca71a138..149970f188d 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -1984,6 +1984,40 @@ fn hides(heads: &[Path], prefix: &Path) -> bool { .any(|head| prefix.strip_prefix(head).is_some_and(|below| below.is_hidden())) } +/// How many sessions withhold an origin's hidden routes from their peer, such as a +/// moq-lite client before 07, whose peer can't ask for them. +#[derive(Clone, Debug, Default)] +pub(crate) struct HiddenWithheld(kio::Shared); + +impl HiddenWithheld { + /// Count a session that withholds them, until the returned guard drops. + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] + pub fn hold(&self) -> HiddenWithholding { + *self.0.lock() += 1; + HiddenWithholding(self.clone()) + } + + /// Ready while a session withholds them. + pub fn poll(&self, waiter: &kio::Waiter) -> Poll<()> { + self.0 + .poll(waiter, |count| match **count { + 0 => Poll::Pending, + _ => Poll::Ready(()), + }) + .map(drop) + } +} + +/// A session counted by [`HiddenWithheld::hold`], until dropped. +#[derive(Debug)] +pub(crate) struct HiddenWithholding(HiddenWithheld); + +impl Drop for HiddenWithholding { + fn drop(&mut self) { + *self.0.0.lock() -= 1; + } +} + /// What an [`AnnounceConsumer`] yields. #[derive(Clone, Debug)] pub enum AnnounceEvent { @@ -5163,6 +5197,9 @@ struct OriginState { // discovered; see [`Interests`]. listeners: Vec, next_listener: u64, + + // The sessions withholding this origin's hidden routes from their peer. + hidden_withheld: HiddenWithheld, } impl OriginState { @@ -5179,6 +5216,7 @@ impl OriginState { closed: false, listeners: Vec::new(), next_listener: 0, + hidden_withheld: HiddenWithheld::default(), } } @@ -6590,6 +6628,11 @@ impl Consumer { self.hidden.include } + /// The sessions withholding this origin's hidden routes from their peer. + pub(crate) fn hidden_withheld(&self) -> HiddenWithheld { + self.shared.read().hidden_withheld.clone() + } + /// The egress stats context this handle was tagged with. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub(crate) fn stats(&self) -> &stats::Session { diff --git a/rs/moq-net/src/model/socket.rs b/rs/moq-net/src/model/socket.rs index 801d1d0d42a..3870d01f825 100644 --- a/rs/moq-net/src/model/socket.rs +++ b/rs/moq-net/src/model/socket.rs @@ -8,11 +8,12 @@ //! A session speaks one of two protocols: //! //! - `tcp`: one reliable, ordered byte pipe each way, as TCP gives. Each half is a single -//! group. Dial with [`Endpoint::dial_tcp`], accept with [`Endpoint::accept_tcp`], and -//! read and write a [`TcpStream`]. +//! group. Dial with [`Endpoint::dial_tcp`], accept with `accept_tcp` or +//! [`Endpoint::poll_accept_tcp`], and read and write a [`TcpStream`]. //! - `track`: each half is a whole track, so messages are groups, with the track's own //! priority, delay budget and order. Dial with [`Endpoint::dial_track`], accept with -//! [`Endpoint::accept_track`], and read and write a [`TrackStream`]. +//! `accept_track` or [`Endpoint::poll_accept_track`], and read and write a +//! [`TrackStream`]. //! //! A dialer `A` picks a random session id `S` and subscribes to `/.socket/` for //! the track `/A/B/S`. Endpoint `B` surfaces that request as an [`Incoming`] dial @@ -126,6 +127,8 @@ mod sealed { pub(super) tasks: crate::util::TasksWeak, /// This endpoint's broadcast. pub(super) publication: origin::Publication, + /// The sessions withholding the broadcast from their peer. + pub(super) withheld: origin::HiddenWithheld, pub(super) state: kio::Lock, } @@ -496,6 +499,16 @@ impl Shared { next } + /// Fail with [`Error::Unsupported`] while a session withholds this endpoint's broadcast + /// from its peer, so no peer beyond it can find it: a moq-lite client session before + /// 07, whose peer can't ask for hidden broadcasts. + fn poll_reachable(&self, waiter: &kio::Waiter) -> Result<(), Error> { + match self.withheld.poll(waiter) { + Poll::Ready(()) => Err(Error::Unsupported), + Poll::Pending => Ok(()), + } + } + /// Poll for the endpoint's end, registering `waiter` for it. fn poll_end(&self, waiter: &kio::Waiter) -> Result<(), Error> { if let Some(err) = &self.state.lock().end { @@ -558,6 +571,14 @@ impl Shared { /// its [`TrackStream::consumer`], which the application owns: drop the streams too, which /// releases the subscriptions. /// +/// Every hop between two endpoints must carry hidden broadcasts: moq-lite-07 or +/// moq-transport. While the origin has a moq-lite client session before 07, whose peer +/// never hears the endpoint's broadcast, dials and accepts fail with +/// [`Error::Unsupported`]; a session whose publish half opts into hidden broadcasts +/// ([`origin::Consumer::with_hidden`]) carries it and doesn't count. Nothing tells a +/// dialer that the peer sits behind such a hop, so a dial to it waits as for a peer not +/// announced yet, while the peer's own accepts fail. +/// /// `tcp` sessions run a task on the origin's driver, which must keep running. pub struct Endpoint { shared: Arc, @@ -578,11 +599,13 @@ impl Endpoint { let prefix = crate::path::convert(prefix)?; let publication = origin.create_broadcast(endpoint_path(&prefix, id)?)?; publication.announce(Route::default())?; + let consumer = origin.consume(); Ok(Self { shared: Arc::new(Shared { id: id.into(), prefix, - origin: origin.consume(), + withheld: consumer.hidden_withheld(), + origin: consumer, tasks: origin.tasks(), publication, state: kio::Lock::new(State { @@ -611,7 +634,8 @@ impl Endpoint { /// Waits for as long as the peer takes to accept: drop the returned future to give up, /// which resets the session. That includes waiting for the peer's endpoint to be /// announced. Fails with the peer's reset when it rejects the dial, or does not accept - /// `tcp` sessions, and with [`Error::Unsupported`] for a dial to this endpoint itself. + /// `tcp` sessions, and with [`Error::Unsupported`] for a dial to this endpoint itself + /// or across a hop that can't carry it (see [`Endpoint`]). pub fn dial_tcp(&self, peer: &str) -> Result>, Error> { self.dial(peer, None) } @@ -659,6 +683,7 @@ impl Endpoint { fn poll_accept(&self, waiter: &kio::Waiter) -> Poll, Error>> { let shared = &self.shared; + shared.poll_reachable(waiter)?; let request = ready!(shared.poll_dial(S::PROTOCOL, waiter))?; let name = parse(request.name()).expect("sorted as a dial"); Poll::Ready(Ok(Incoming { @@ -671,7 +696,8 @@ impl Endpoint { } /// Poll for the next `tcp` dial from a peer; fails with [`Error::Closed`] once the - /// endpoint closed. + /// endpoint closed, and with [`Error::Unsupported`] while no peer can reach it (see + /// [`Endpoint`]). /// /// The first call starts accepting `tcp` dials. They queue until taken, or until their /// dialer gives up, so keep accepting, and accept or reject each one. @@ -708,7 +734,8 @@ impl Drop for Endpoint { } } -/// A dial from a peer, from [`Endpoint::accept_tcp`] or [`Endpoint::accept_track`]: accept +/// A dial from a peer, from [`Endpoint::poll_accept_tcp`] or +/// [`Endpoint::poll_accept_track`] (or their async `accept_tcp` and `accept_track`): accept /// or reject it. /// /// Dropping it rejects it with [`Error::Cancel`]. @@ -920,6 +947,7 @@ impl Dialing { fn poll_inner(&mut self, waiter: &kio::Waiter) -> Poll> { self.shared.poll_end(waiter)?; + self.shared.poll_reachable(waiter)?; // The peer asks for this side's half when it accepts: serve it, which proves to the // peer that this endpoint dialed. @@ -987,9 +1015,10 @@ impl Accepting { /// Poll for the dialer to answer, which proves it dialed. /// /// Waits for the dialer's endpoint to be announced for as long as the dial stays open, - /// and fails with [`Error::Cancel`] once the dialer gives up. Fails with the dialer's - /// reset when it never dialed this session, such as a dial forged in its name, and - /// resets the dialer's request with the same error. + /// and fails with [`Error::Cancel`] once the dialer gives up, or with + /// [`Error::Unsupported`] while this endpoint can't reach it (see [`Endpoint`]). Fails + /// with the dialer's reset when it never dialed this session, such as a dial forged in + /// its name, and resets the dialer's request with the same error. pub fn poll_ok(&mut self, waiter: &kio::Waiter) -> Poll> { let result = self.poll_inner(waiter); if let Poll::Ready(Err(err)) = &result { @@ -1003,6 +1032,7 @@ impl Accepting { fn poll_inner(&mut self, waiter: &kio::Waiter) -> Poll> { self.shared.poll_end(waiter)?; + self.shared.poll_reachable(waiter)?; if self.demand.poll_state(waiter) != track::DemandState::Active { return Poll::Ready(Err(Error::Cancel)); } diff --git a/rs/moq-net/tests/integration/socket.rs b/rs/moq-net/tests/integration/socket.rs index 24ee7d76e00..7439ec46e6b 100644 --- a/rs/moq-net/tests/integration/socket.rs +++ b/rs/moq-net/tests/integration/socket.rs @@ -48,17 +48,27 @@ impl Fixture { /// A client publishing and subscribing through one origin, connected to the relay over /// `version`. async fn client(&mut self, version: &str) -> origin::Producer { - let client = origin(self.next); + let client = self.origin(); + self.connect(&client, version, client.consume()).await; + client + } + + /// An origin for a client, not connected yet. + fn origin(&mut self) -> origin::Producer { self.next += 1; + origin(self.next - 1) + } + + /// Connect `client` to the relay over `version`, publishing `publish`. + async fn connect(&mut self, client: &origin::Producer, version: &str, publish: origin::Consumer) { let mut options = MockConnectOptions::new(version.parse::().unwrap()); - options.client_publish = Some(client.consume()); + options.client_publish = Some(publish); options.client_subscribe = Some(client.clone()); options.server_publish = Some(self.relay.consume()); options.server_subscribe = Some(self.relay.clone()); // Discovery follows the endpoint's own requests, as it does for an application. options.client_discovers_all = false; self.sessions.push(connect_mock(options).await); - client } /// An endpoint `id` on its own client of the relay. @@ -849,3 +859,85 @@ async fn an_endpoint_not_accepting_resets_dials() { .expect("dial timeout"); assert!(dialed.is_err(), "a dial to an endpoint not accepting connected"); } + +/// The moq-lite versions before hidden broadcasts. +const OLDER: [&str; 2] = ["moq-lite-06", "moq-lite-03"]; + +/// An endpoint behind an older moq-lite hop, which never carries its hidden broadcast, +/// fails its dials and accepts at once, so its peer never hears a dial it can't answer. +#[kio::test] +async fn an_older_hop_fails_dials_and_accepts() { + for older in OLDER { + let mut fixture = Fixture::new(); + let alice = fixture.endpoint(older, "alice").await; + let bob = fixture.endpoint(LITE, "bob").await; + + let dialed = kio::clock::timeout(SETTLE, alice.dial_tcp("bob").unwrap()).await; + assert!(matches!(dialed, Ok(Err(Error::Unsupported))), "{older} tcp dial"); + let dialed = kio::clock::timeout(SETTLE, alice.dial_track("bob", None).unwrap()).await; + assert!(matches!(dialed, Ok(Err(Error::Unsupported))), "{older} track dial"); + let accepted = kio::clock::timeout(SETTLE, alice.accept_tcp()).await; + assert!(matches!(accepted, Ok(Err(Error::Unsupported))), "{older} accept"); + let accepted = kio::clock::timeout(SETTLE, alice.accept_track()).await; + assert!(matches!(accepted, Ok(Err(Error::Unsupported))), "{older} accept"); + + // So bob never heard a dial to hold an accept open for. + assert!( + kio::clock::timeout(SETTLE, bob.accept_tcp()).await.is_err(), + "{older}: bob heard a dial" + ); + } +} + +/// A dial to a peer behind an older moq-lite hop can't tell it from a peer not announced +/// yet, so it waits, while the peer's own accepts fail. +#[kio::test] +async fn a_peer_behind_an_older_hop_fails_its_accepts() { + for older in OLDER { + let mut fixture = Fixture::new(); + let alice = fixture.endpoint(LITE, "alice").await; + let bob = fixture.endpoint(older, "bob").await; + + let accepted = kio::clock::timeout(SETTLE, bob.accept_tcp()).await; + assert!(matches!(accepted, Ok(Err(Error::Unsupported))), "{older} accept"); + let mut dial = alice.dial_tcp("bob").unwrap(); + assert!( + kio::clock::timeout(SETTLE, &mut dial).await.is_err(), + "{older}: a dial behind an older hop resolved" + ); + } +} + +/// A dial already waiting fails once its origin gains an older moq-lite session, as an +/// endpoint whose client reconnects does. +#[kio::test] +async fn an_older_hop_fails_a_waiting_dial() { + let mut fixture = Fixture::new(); + let client = fixture.origin(); + let alice = Endpoint::new(&client, "room", "alice").unwrap(); + let mut dial = alice.dial_tcp("bob").unwrap(); + assert!( + kio::clock::timeout(SETTLE, &mut dial).await.is_err(), + "a dial to nobody resolved" + ); + + fixture.connect(&client, OLDER[0], client.consume()).await; + let dialed = kio::clock::timeout(SETTLE, dial).await; + assert!(matches!(dialed, Ok(Err(Error::Unsupported)))); +} + +/// A client whose publish half opts into hidden broadcasts, as a relay's link to a +/// cluster peer does, still carries its endpoint over an older moq-lite hop. +#[kio::test] +async fn an_older_hop_opted_into_hidden_connects() { + let mut fixture = Fixture::new(); + let client = fixture.origin(); + fixture + .connect(&client, OLDER[0], client.consume().with_hidden(true)) + .await; + let alice = Endpoint::new(&client, "room", "alice").unwrap(); + let bob = fixture.endpoint(LITE, "bob").await; + let (mut dialed, accepted) = connect_tcp(&alice, &bob).await; + assert_eq!(dialed.session(), accepted.session()); + dialed.producer.finish().unwrap(); +}