Skip to content
Merged
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
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ removed).
- [App-limited BBR3 estimate ages](/quest/m1/bbr-app-limited.md) - an app-limited BBR3 estimate falls within seconds after the path drops
- [Bindings name every session code](/quest/m1/ffi-malformed-auth-kind.md) - MALFORMED_AUTH_TOKEN and its siblings reach moq-ffi, moq-c, and the wrappers
- [Unbounded groups](/quest/m1/unbounded-groups/README.md) - groups and frames lose their size caps; the cache sheds parts of a group under pressure and refills the holes in place
- [Relay demand gaps](/quest/m1/relay-demand-gaps.md) - pre-07 backlog, IETF warm-relay newcomer, and double upstream pulls are fixed or ruled out
- [Segment cuts hold bounded state](/quest/m1/segmenter-cuts.md) - the HLS segmenter keeps one pending cut, so `styp` input without sync samples cannot grow it
- [Next Object on a cold Rust copy](/quest/m1/next-object-cold-copy.md) - a join after an upstream group report starts at the first frame received, never skipping
- [Container consumers buffer by backpressure](/quest/m1/container-backpressure.md) - Rust and JS container consumers decode ahead only a byte budget, so a hostile publisher cannot grow them
Expand Down
19 changes: 0 additions & 19 deletions quest/m1/relay-demand-gaps.md

This file was deleted.

3 changes: 3 additions & 0 deletions rs/moq-net/src/lite/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7719,6 +7719,9 @@ impl ServeLoop {
if serve.subscriber.version.resolves_anchors() {
serving.anchored();
}
if serve.subscriber.version.fills_from_start() {
serving.fills_from_start();
}
let serving = serving.commit();
Self {
edge: serving.consume(),
Expand Down
7 changes: 7 additions & 0 deletions rs/moq-net/src/lite/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ impl Version {
)
}

/// Whether a copy's fills stop at the start its publisher resolved from the budget.
/// Lite-06 resolves the start, but drops media time and sends FETCH without a max
/// delay, so nothing judges a group below that start against a reader's budget.
pub(crate) fn fills_from_start(self) -> bool {
self.resolves_start() && !self.has_media_time() && !self.has_fetch_max_delay()
}

/// Whether subscription completion waits for the subscriber's FIN.
pub(crate) fn waits_for_subscriber_fin(self) -> bool {
!matches!(
Expand Down
87 changes: 85 additions & 2 deletions rs/moq-net/src/model/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ pub(crate) struct TrackState {
anchored: bool,
// This copy can translate only anchors its cache has already settled.
cached_anchors: bool,
// Whether readers ask no fills below `start_sequence`: its publisher resolved it from the
// budget, but neither this copy's timestamps nor a fill can judge an older group against
// a reader's budget. A widened budget reaches lower groups through the feed's re-offer.
fills_from_start: bool,
// Sequences the upstream publisher gave up, with the error each was given up with: an
// incoming SUBSCRIBE_DROP or a producer cut. Kept apart from the cache so reclaiming a
// slot cannot erase a disposition a relay must forward, and as ranges so a wide DROP
Expand Down Expand Up @@ -3250,6 +3254,15 @@ impl Producer {
}
}

/// Have this received copy's readers ask no fills below the start its publisher resolved
/// from the budget, for a wire whose fills and timestamps cannot bound them by it.
#[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))]
pub(crate) fn fills_from_start(&self) {
if let Ok(mut state) = self.modify() {
state.fills_from_start = true;
}
}

/// Record that the publisher gave up `groups` with `err`: none will arrive, so a reader
/// waiting on one moves past it, a group still arriving in them ends with `err`, the
/// declared end does not wait for them, and a relay serving this track forwards the drop.
Expand Down Expand Up @@ -17193,9 +17206,19 @@ mod test {

// The backfill serves by sequence, but never in arrival order.
assert!(consumer.peek_group(1).is_some());
let mut walked = Vec::new();
let mut index = 0;
while let Poll::Ready(Ok(Some((group, next)))) = producer.state.read().poll_recv_group(index, 0) {
walked.push(group.sequence);
index = next + 1;
}
assert_eq!(walked, [0, 2]);
// A reader takes it as the fill answer for the group the feed gave up, as it would
// have asked a fill for it, and the stale arrival entry adds nothing.
let mut subscriber = producer.subscribe(replay());
assert_eq!(subscriber.assert_group().sequence, 0);
assert_eq!(subscriber.assert_group().sequence, 2);
let mut read: Vec<_> = (0..3).map(|_| subscriber.assert_group().sequence).collect();
read.sort();
assert_eq!(read, [0, 1, 2]);
subscriber.assert_no_group();
}

Expand Down Expand Up @@ -17769,6 +17792,66 @@ mod test {
);
}

/// A copy whose fills cannot carry a reader's budget asks none below the start its
/// publisher resolved from that budget, and names nothing there dropped: what a wider
/// budget reaches comes through the feed's re-offer, which a reader takes as it arrives.
#[test]
#[cfg(feature = "async")]
fn no_fill_below_a_start_resolved_from_the_budget() {
let write = |producer: &Producer, sequence| {
let mut group = producer.create_group(group::Info { sequence }).unwrap();
group.write_frame(None, &b"x"[..]).unwrap();
group.finish().unwrap();
};
let mut producer = track_producer("test", Info::default());
producer.fills_from_start();
let dynamic = producer.requests();
let mut subscriber = producer.subscribe(replay().with_range(0..));
producer.request_start(None).unwrap();
producer.start_at(2).unwrap();
write(&producer, 2);
write(&producer, 3);
let waiter = kio::Waiter::noop();
assert_eq!(drain_groups(&mut subscriber), [2, 3]);
assert!(
dynamic.poll_requested_fill(&waiter).is_pending(),
"below the start is no miss"
);
assert!(drained_drops(&mut subscriber).is_empty());

// The re-offer of a widened budget.
write(&producer, 1);
assert_eq!(drain_groups(&mut subscriber), [1]);
assert!(dynamic.poll_requested_fill(&waiter).is_pending());
}

/// A reader arriving after another's fill cached the groups under the start reads them
/// from the cache: the arrival walk never reaches a backfill, and no fill is asked again.
#[test]
#[cfg(feature = "async")]
fn a_newcomer_reads_the_backfill_another_fill_cached() {
let (producer, dynamic, mut first) = started_late();
let waiter = kio::Waiter::noop();
while let Poll::Ready(Ok(Some(_))) = first.poll_recv_group(&waiter) {}
let Poll::Ready(Ok(fill)) = dynamic.poll_requested_fill(&waiter) else {
panic!("below the start is a miss");
};
while let Some(sequence) = fill.next() {
write_filled(fill.accept(sequence, None), sequence);
}
let mut newcomer = producer.subscribe(replay().with_range(0..));
let mut read = Vec::new();
while let Poll::Ready(Ok(Some(group))) = newcomer.poll_recv_group(&waiter) {
read.push(group.sequence);
}
read.sort();
assert_eq!(read, [0, 1, 2, 3]);
assert!(
dynamic.poll_requested_fill(&waiter).is_pending(),
"the cache answers it"
);
}

/// Groups a fill answered before the reader came back are handed out in the reader's
/// order, so a warm cache keeps a descending reader newest first.
#[test]
Expand Down
27 changes: 27 additions & 0 deletions rs/moq-net/src/model/track/miss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,24 @@ impl Misses {
self.judged.insert(run.clone());
}
let start = state.start_sequence.unwrap_or(0);
// Below the start its publisher resolved from the budget, such a copy cannot tell a
// group a reader's budget reaches, so it leaves them to the feed's re-offer.
if state.fills_from_start && start > 0 {
candidates.remove(0..start);
}
for run in candidates.iter() {
// Backfill another reader's fill cached is no hole, yet the arrival walk never
// reaches it: this reader takes it as filled where it would ask for a hole.
for held in backfill(state, run.clone()).iter() {
let (unfed, awaited) = state.unfed(held.clone(), now);
for run in unfed.iter() {
self.filled.extend(run.clone());
}
for (run, folds) in awaited {
self.filled.extend(run.start..run.end.min(start));
self.deferred.insert(run.start.max(start)..run.end, folds);
}
}
for hole in holes(state, run.clone()) {
for hole in self.unclaimed(state, hole) {
let (unfed, awaited) = state.unfed(hole, now);
Expand Down Expand Up @@ -722,6 +739,16 @@ impl TrackState {
}
}

/// The runs of `run` the cache holds as backfill: servable, but out of the arrival walk.
fn backfill(state: &TrackState, run: ops::Range<u64>) -> RangeSet<u64> {
state
.lookup
.range(run)
.filter(|(_, slot)| !slot.is_walked() && slot.serves_end())
.map(|(&sequence, _)| sequence..sequence + 1)
.collect()
}

/// The runs of `run` the cache holds nothing servable for.
pub(super) fn holes(state: &TrackState, run: ops::Range<u64>) -> Vec<ops::Range<u64>> {
let mut holes = Vec::new();
Expand Down
1 change: 1 addition & 0 deletions rs/moq-net/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ mod tracks;
mod tracks_ietf;
mod unannounce_release;
mod untimed;
mod warm_backfill;
mod wide_hop;
mod wide_sequence;
mod widened_max_age;
Expand Down
90 changes: 90 additions & 0 deletions rs/moq-net/tests/integration/warm_backfill.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#![cfg(feature = "async")]

//! A relay that backfilled a reader's backlog serves the same backlog to the next reader
//! from its cache.
//!
//! Where the upstream starts the copy at its live edge, as moq-transport and moq-lite 05
//! do, the backlog below that start arrives through fills, outside the live feed's arrival
//! walk. A newcomer finds those groups cached, so it neither walks nor asks for them, and
//! read only the live edge until it took the cached backfill as filled.

use std::collections::BTreeSet;
use std::time::Duration;

use moq_net::track::{Info, Subscription};
use moq_net::{Hop, Timescale, Timestamp, Version, origin, track};

use crate::support::harness::{peer, spawn};

const TIMEOUT: Duration = Duration::from_secs(10);

const GROUPS: u64 = 10;

/// Reaches every group, however long the readers take.
const BUDGET: Duration = Duration::from_secs(100);

const VERSIONS: &[&str] = &[
"moq-lite-05",
"moq-lite-06",
"moq-lite-07-wip",
"moq-transport-18",
"moq-transport-22",
];

fn origin(hop: u64) -> origin::Producer {
let (origin, driver) = origin::Producer::new(origin::Config::new(Hop::new(hop).unwrap()));
spawn(driver);
origin
}

async fn subscribe(relay: &origin::Producer) -> track::Subscriber {
let consumer = relay.consume();
consumer.routed("live").await.unwrap();
let remote = consumer.request_broadcast("live", None).await.unwrap();
remote
.track("video")
.unwrap()
.subscribe(Subscription::default().with_max_delay(BUDGET))
.await
.unwrap()
}

/// Every group `subscriber` receives until it goes quiet.
async fn received(subscriber: &mut track::Subscriber) -> BTreeSet<u64> {
let mut got = BTreeSet::new();
while let Ok(group) = moq_clock::timeout(Duration::from_secs(1), subscriber.recv_group()).await {
let group = group.unwrap().expect("the track is live");
assert!(got.insert(group.sequence), "group {} delivered twice", group.sequence);
}
got
}

#[moq_clock::test]
async fn a_newcomer_on_a_warm_relay_gets_the_backfill() {
for &version in VERSIONS {
let publisher = origin(1);
let relay = origin(2);
let _link = peer(version.parse::<Version>().unwrap(), &publisher, &relay).await;
let broadcast = publisher.create_broadcast("live").unwrap();
let source = broadcast
.create_track("video", Info::default().with_timescale(Timescale::MILLI))
.unwrap();
for sequence in 0..GROUPS {
let mut group = source.create_group(moq_net::group::Info { sequence }).unwrap();
group
.write_frame(Timestamp::from_millis(sequence * 1000).unwrap(), &b"x"[..])
.unwrap();
group.finish().unwrap();
}
broadcast.announce(Default::default()).unwrap();

let mut first = moq_clock::timeout(TIMEOUT, subscribe(&relay)).await.unwrap();
let cold = moq_clock::timeout(TIMEOUT, received(&mut first)).await.unwrap();
assert_eq!(cold, (0..GROUPS).collect(), "{version}: cold");

// The same subscription changes nothing upstream, so only the cache can serve it.
let mut second = moq_clock::timeout(TIMEOUT, subscribe(&relay)).await.unwrap();
let warm = moq_clock::timeout(TIMEOUT, received(&mut second)).await.unwrap();
assert_eq!(warm, cold, "{version}: warm");
}
}
Loading
Loading