Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions rs/moq-gst/src/source/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4333,9 +4333,7 @@ mod session_tests {
matches!(event, moq_net::origin::RouteEvent::Start(_))
});
drop(first);
await_event(&mut follow, |event| {
matches!(event, moq_net::origin::RouteEvent::End(_))
});
await_event(&mut follow, moq_net::origin::RouteEvent::is_end);

let mut second = Publisher::sibling(&origin, Default::default());
assert_eq!(recorder.written(&mut second, 2), pad, "the return moved to another pad");
Expand Down Expand Up @@ -4394,9 +4392,7 @@ mod session_tests {
matches!(event, moq_net::origin::RouteEvent::Start(_))
});
drop(first);
await_event(&mut follow, |event| {
matches!(event, moq_net::origin::RouteEvent::End(_))
});
await_event(&mut follow, moq_net::origin::RouteEvent::is_end);
let mut second = Publisher::sibling(&origin, Default::default());
assert_eq!(recorder.written(&mut second, 3), pad, "the return moved to another pad");
assert_eq!(
Expand Down Expand Up @@ -4493,9 +4489,7 @@ mod session_tests {
matches!(event, moq_net::origin::RouteEvent::Start(_))
});
first.route.as_ref().unwrap().withdraw();
await_event(&mut follow, |event| {
matches!(event, moq_net::origin::RouteEvent::End(_))
});
await_event(&mut follow, moq_net::origin::RouteEvent::is_end);
first.route.as_ref().unwrap().announce().unwrap();
await_event(&mut follow, |event| {
matches!(event, moq_net::origin::RouteEvent::Start(_))
Expand Down Expand Up @@ -4578,9 +4572,7 @@ mod session_tests {
matches!(event, moq_net::origin::RouteEvent::Start(_))
});
drop(first);
await_event(&mut follow, |event| {
matches!(event, moq_net::origin::RouteEvent::End(_))
});
await_event(&mut follow, moq_net::origin::RouteEvent::is_end);

let mut second = Publisher::sibling(&origin, Default::default());
assert_eq!(recorder.written(&mut second, 2), pad, "the return moved to another pad");
Expand Down Expand Up @@ -4845,9 +4837,7 @@ mod session_tests {
matches!(event, moq_net::origin::RouteEvent::Start(_))
});
drop(first);
await_event(&mut follow, |event| {
matches!(event, moq_net::origin::RouteEvent::End(_))
});
await_event(&mut follow, moq_net::origin::RouteEvent::is_end);

room.catalog.modify().unwrap().video.renditions.clear();
for _ in 0..200 {
Expand Down Expand Up @@ -4893,9 +4883,7 @@ mod session_tests {
matches!(event, moq_net::origin::RouteEvent::Start(_))
});
drop(first);
await_event(&mut follow, |event| {
matches!(event, moq_net::origin::RouteEvent::End(_))
});
await_event(&mut follow, moq_net::origin::RouteEvent::is_end);

let listed = room.catalog.modify().unwrap().video.renditions.clone();
room.catalog.modify().unwrap().video.renditions.clear();
Expand Down Expand Up @@ -5264,9 +5252,7 @@ mod session_tests {
block(Duration::from_millis(100));
old.catalog.finish().unwrap();
drop(old);
await_event(&mut announced, |event| {
matches!(event, moq_net::origin::RouteEvent::End(_))
});
await_event(&mut announced, moq_net::origin::RouteEvent::is_end);

let mut new = Publisher::new(&origin, Default::default(), video_rendition());
assert_eq!(
Expand Down Expand Up @@ -5294,9 +5280,7 @@ mod session_tests {
let pad = recorder.written(&mut old, 1);

old.route.as_ref().unwrap().withdraw();
await_event(&mut announced, |event| {
matches!(event, moq_net::origin::RouteEvent::End(_))
});
await_event(&mut announced, moq_net::origin::RouteEvent::is_end);
drop(old);

let mut new = Publisher::new(&origin, Default::default(), video_rendition());
Expand Down Expand Up @@ -5369,9 +5353,7 @@ mod session_tests {
let mut announced = announced(&origin);
let route = next.route.as_ref().unwrap();
route.withdraw();
await_event(&mut announced, |event| {
matches!(event, moq_net::origin::RouteEvent::End(_))
});
await_event(&mut announced, moq_net::origin::RouteEvent::is_end);
route.announce().unwrap();
assert_eq!(
recorder.written(&mut next, tag + 2),
Expand Down Expand Up @@ -5865,9 +5847,7 @@ mod session_tests {

let mut announced = announced(&relay.origin);
session.abort(moq_net::Error::App(1));
await_event(&mut announced, |event| {
matches!(event, moq_net::origin::RouteEvent::End(_))
});
await_event(&mut announced, moq_net::origin::RouteEvent::is_end);

let mut new = Publisher::new(&relay.origin, Default::default(), video_rendition());
rendered(&sink, &mut new, 2);
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-net-tests/tests/integration/restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ async fn withdrawal_refuses_new_fetches_but_keeps_open_reads() {
write(&produced, "old:0");
assert_eq!(read(&mut subscription).await, "old:0");
source.withdraw();
assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::End(_)));
assert!(next_event(&mut announced).await.is_end());
assert!(track.fetch_group(1, None).await.is_err(), "{version}");
write(&produced, "old:1");
assert_eq!(read(&mut subscription).await, "old:1");
Expand Down
1 change: 1 addition & 0 deletions rs/moq-net/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `socket`: `Endpoint`, a server, a client, or both, which announces a hidden `<prefix>/.client/<id>` broadcast at its first dial and `<prefix>/.server/<id>` at its first accept, so grants decide its roles, dials servers, and accepts clients' 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.
- `origin::RouteEvent::{announce, into_announce, is_end}`, so a reader gets the route without matching every variant.

## [0.3.10](https://github.com/moq-dev/moq/compare/moq-net-v0.3.9...moq-net-v0.3.10) - 2026-10-05

Expand Down
9 changes: 2 additions & 7 deletions rs/moq-net/benches/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ mod replay;
fn scanned(events: Vec<origin::RouteEvent>) -> Vec<announce::Announce> {
let mut initial: Vec<announce::Announce> = Vec::new();
for event in events {
let (update, active) = match event {
origin::RouteEvent::Start(update)
| origin::RouteEvent::Update(update)
| origin::RouteEvent::Restart(update)
| origin::RouteEvent::Takeover { announce: update, .. } => (update, true),
origin::RouteEvent::End(update) => (update, false),
};
let active = !event.is_end();
let update = event.into_announce();
initial.retain(|held| held.prefix != update.prefix);
if active {
initial.push(update);
Expand Down
13 changes: 3 additions & 10 deletions rs/moq-net/benches/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,9 @@ fn waiting(c: &mut Criterion) {
let mut announced = receive.consume().routes();
let mut seen = std::collections::HashSet::new();
while seen.len() < paths {
match announced.next().await.unwrap() {
moq_net::origin::RouteEvent::Start(update)
| moq_net::origin::RouteEvent::Update(update)
| moq_net::origin::RouteEvent::Restart(update)
| moq_net::origin::RouteEvent::Takeover { announce: update, .. }
if update.prefix.as_str().starts_with(&prefix) =>
{
seen.insert(update.prefix);
}
_ => {}
let event = announced.next().await.unwrap();
if !event.is_end() && event.announce().prefix.as_str().starts_with(&prefix) {
seen.insert(event.into_announce().prefix);
}
}
drop(broadcasts);
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-net/benches/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@ pub(crate) fn withdrawal<B: Backend>(c: &mut Criterion) {
while let Ok(Some(event)) =
kio::clock::timeout(Duration::from_secs(1), announced.next()).await
{
assert!(matches!(event, moq_net::origin::RouteEvent::End(_)), "{event:?}");
assert!(event.is_end(), "{event:?}");
retracted += 1;
}
let elapsed = start.elapsed();
Expand Down
16 changes: 6 additions & 10 deletions rs/moq-net/src/ietf/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4137,16 +4137,12 @@ impl Publisher {
fn snapshot(announced: &mut crate::origin::Routes) -> Vec<crate::announce::Announce> {
let mut initial = std::collections::BTreeMap::new();
while let Some(event) = announced.try_next() {
match event {
crate::origin::RouteEvent::Start(update)
| crate::origin::RouteEvent::Update(update)
| crate::origin::RouteEvent::Restart(update)
| crate::origin::RouteEvent::Takeover { announce: update, .. } => {
initial.insert(update.prefix.clone(), update);
}
crate::origin::RouteEvent::End(update) => {
initial.remove(&update.prefix);
}
let active = !event.is_end();
let update = event.into_announce();
if active {
initial.insert(update.prefix.clone(), update);
} else {
initial.remove(&update.prefix);
}
}
initial.into_values().collect()
Expand Down
9 changes: 2 additions & 7 deletions rs/moq-net/src/ietf/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10860,13 +10860,8 @@ mod tests {
/// The current best route covering `path`, if any (synchronous peek).
fn routed_now(consumer: &crate::origin::Consumer, path: &str) -> Option<crate::origin::RouteInfo> {
use futures::FutureExt;
match consumer.path_routes(path).ok()?.next().now_or_never()?? {
crate::origin::RouteEvent::End(_) => None,
crate::origin::RouteEvent::Start(announce)
| crate::origin::RouteEvent::Update(announce)
| crate::origin::RouteEvent::Restart(announce)
| crate::origin::RouteEvent::Takeover { announce, .. } => Some(announce.route),
}
let event = consumer.path_routes(path).ok()?.next().now_or_never()??;
(!event.is_end()).then(|| event.into_announce().route)
}

fn hop_path(ids: &[u64]) -> cluster::HopPath {
Expand Down
16 changes: 6 additions & 10 deletions rs/moq-net/src/lite/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,16 +1231,12 @@ impl AnnounceRun {
let mut snapshot = origin.routes();
let mut current: HashMap<crate::Path, crate::origin::RouteInfo> = HashMap::new();
while let Some(event) = snapshot.try_next() {
match event {
origin::RouteEvent::Start(update)
| origin::RouteEvent::Update(update)
| origin::RouteEvent::Restart(update)
| origin::RouteEvent::Takeover { announce: update, .. } => {
current.insert(update.prefix, update.route);
}
origin::RouteEvent::End(update) => {
current.remove(&update.prefix);
}
let active = !event.is_end();
let update = event.into_announce();
if active {
current.insert(update.prefix, update.route);
} else {
current.remove(&update.prefix);
}
}

Expand Down
9 changes: 2 additions & 7 deletions rs/moq-net/src/lite/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ pub(super) fn initial(events: impl IntoIterator<Item = origin::RouteEvent>) -> V
let mut pending: Vec<Option<announce::Announce>> = Vec::new();
let mut positions = HashMap::new();
for event in events {
let (update, active) = match event {
origin::RouteEvent::Start(update)
| origin::RouteEvent::Update(update)
| origin::RouteEvent::Restart(update)
| origin::RouteEvent::Takeover { announce: update, .. } => (update, true),
origin::RouteEvent::End(update) => (update, false),
};
let active = !event.is_end();
let update = event.into_announce();
if let Some(index) = positions.remove(&update.prefix) {
pending[index] = None;
}
Expand Down
8 changes: 2 additions & 6 deletions rs/moq-net/src/model/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Follow {
return Poll::Ready(None);
};
if let Some(event) = self.fold(event) {
self.idle = matches!(event, RouteEvent::End(_));
self.idle = event.is_end();
return Poll::Ready(Some(event));
}
}
Expand Down Expand Up @@ -127,11 +127,7 @@ impl Follow {

/// Apply one route's event, returning what it means for the path, if anything.
fn fold(&mut self, event: RouteEvent) -> Option<RouteEvent> {
let (RouteEvent::Start(announce)
| RouteEvent::Update(announce)
| RouteEvent::Restart(announce)
| RouteEvent::Takeover { announce, .. }
| RouteEvent::End(announce)) = &event;
let announce = event.announce();
if !self.path.has_prefix(&announce.prefix) {
return None;
}
Expand Down
89 changes: 48 additions & 41 deletions rs/moq-net/src/model/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,13 +1211,8 @@ impl OriginConsumerState {
/// Take the pending update at `prefix` for delivery.
fn take_prefix(&mut self, prefix: Path) -> RouteEvent {
let (event, owed) = self.take_update(prefix);
let (RouteEvent::Start(announce)
| RouteEvent::Update(announce)
| RouteEvent::Restart(announce)
| RouteEvent::Takeover { announce, .. }
| RouteEvent::End(announce)) = &event;
// A trailing announce left pending is still owed.
if owed && !self.pending.contains_key(&announce.prefix) {
if owed && !self.pending.contains_key(&event.announce().prefix) {
self.owed -= 1;
}
event
Expand Down Expand Up @@ -2198,6 +2193,35 @@ pub enum RouteEvent {
},
}

impl RouteEvent {
/// The route the event carries; for [`End`](Self::End), its last advertised route.
pub fn announce(&self) -> &Announce {
match self {
Self::Start(announce)
| Self::Update(announce)
| Self::End(announce)
| Self::Restart(announce)
| Self::Takeover { announce, .. } => announce,
}
}

/// Consume the event, returning the route it carries.
pub fn into_announce(self) -> Announce {
match self {
Self::Start(announce)
| Self::Update(announce)
| Self::End(announce)
| Self::Restart(announce)
| Self::Takeover { announce, .. } => announce,
}
}

/// Whether no route covers the prefix any more; every other event leaves one in place.
pub fn is_end(&self) -> bool {
matches!(self, Self::End(_))
}
}

/// A route over a prefix, as an announcement listing or a [`Routes`] stream reports it.
///
/// An announcement is always a prefix, never a broadcast: it advertises that
Expand Down Expand Up @@ -3674,21 +3698,14 @@ impl OwnClaims {
/// The route not learned upstream changed at a prefix: whether the claim there may
/// go to an upstream peer follows it.
fn local(&mut self, event: RouteEvent) {
match event {
RouteEvent::End(announce) => {
self.local.remove(&announce.prefix);
self.feed(announce.prefix, None);
}
RouteEvent::Start(announce)
| RouteEvent::Update(announce)
| RouteEvent::Restart(announce)
| RouteEvent::Takeover { announce, .. } => {
if let Some(instance) = announce.route.instance {
self.local.insert(announce.prefix.clone(), instance);
}
self.feed(announce.prefix, None);
}
let end = event.is_end();
let announce = event.into_announce();
if end {
self.local.remove(&announce.prefix);
} else if let Some(instance) = announce.route.instance {
self.local.insert(announce.prefix.clone(), instance);
}
self.feed(announce.prefix, None);
}

/// Feed the node the claim at `prefix`, marked as learned upstream unless a route
Expand Down Expand Up @@ -6904,14 +6921,9 @@ impl Requesting {
if let Some(discovery) = &mut self.discovery {
loop {
match discovery.poll_next(waiter) {
Poll::Ready(Some(RouteEvent::End(_))) => self.routed = false,
Poll::Ready(Some(
RouteEvent::Start(announce)
| RouteEvent::Restart(announce)
| RouteEvent::Update(announce)
| RouteEvent::Takeover { announce, .. },
)) => {
self.routed = self.instance.is_none() || announce.route.instance == self.instance;
Poll::Ready(Some(event)) if event.is_end() => self.routed = false,
Poll::Ready(Some(event)) => {
self.routed = self.instance.is_none() || event.announce().route.instance == self.instance;
}
Poll::Ready(None) => return Poll::Ready(Err(Error::Closed)),
Poll::Pending => break,
Expand Down Expand Up @@ -8176,19 +8188,14 @@ impl Routes {

/// Drive the egress announce guards for one update.
fn hand_out(&mut self, event: RouteEvent) -> RouteEvent {
match &event {
RouteEvent::Start(announce)
| RouteEvent::Update(announce)
| RouteEvent::Restart(announce)
| RouteEvent::Takeover { announce, .. } => {
let scope = self.stats.egress(self.root.rejoin(&announce.prefix));
self.guards
.entry(announce.prefix.clone())
.or_insert_with(|| scope.announce());
}
RouteEvent::End(announce) => {
self.guards.remove(&announce.prefix);
}
let announce = event.announce();
if event.is_end() {
self.guards.remove(&announce.prefix);
} else {
let scope = self.stats.egress(self.root.rejoin(&announce.prefix));
self.guards
.entry(announce.prefix.clone())
.or_insert_with(|| scope.announce());
}
event
}
Expand Down
Loading
Loading