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: 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 `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.
- `Server::with_allocator`, the accepting mirror of `Client::with_allocator`: every session the server accepts reserves into one `bandwidth::Allocator` and probes for the sum, instead of each starting an empty registry.

## [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
49 changes: 46 additions & 3 deletions rs/moq-net/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub struct Server {
implementation: Option<String>,
timeout: Option<Duration>,
receive_window: Option<NonZeroU64>,
allocator: Option<crate::bandwidth::Allocator>,
}

impl Default for Server {
Expand All @@ -114,6 +115,7 @@ impl Default for Server {
implementation: None,
timeout: Some(DEFAULT_TIMEOUT),
receive_window: None,
allocator: None,
}
}
}
Expand All @@ -140,6 +142,22 @@ impl Server {
self
}

/// Share `allocator`'s reservations with every session this server accepts.
///
/// The accepting mirror of [`Client::with_allocator`](crate::Client::with_allocator):
/// each session probes for what the reservations add up to, and its
/// [`Session::allocator`](crate::Session::allocator) reserves into the same registry.
/// Without one, each session starts an empty registry of its own.
pub fn with_allocator(mut self, allocator: crate::bandwidth::Allocator) -> Self {
self.allocator = Some(allocator);
self
}

/// The registry the next session probes for.
fn allocator(&self) -> crate::bandwidth::Allocator {
self.allocator.clone().unwrap_or_default()
}

/// Attach a per-connection [`stats::Session`] context. The session's publish
/// (egress) and subscribe (ingress) origin handles are tagged with it, so all
/// traffic counters are attributed through the model for this session's lifetime,
Expand Down Expand Up @@ -293,7 +311,7 @@ impl Server {
credential: start.credential,
estimate: Some(start.estimate),
peer_target: Some(start.peer_target),
bandwidth: crate::bandwidth::Allocator::default(),
bandwidth: self.allocator(),
viewers,
peer_implementation: start.peer_implementation,
datagrams_unrouted: start.datagrams_unrouted,
Expand Down Expand Up @@ -937,7 +955,7 @@ impl PausedIetf {
credential: None,
estimate: None,
peer_target: None,
bandwidth: crate::bandwidth::Allocator::default(),
bandwidth: server.allocator(),
viewers: Default::default(),
peer_implementation,
datagrams_unrouted: None,
Expand Down Expand Up @@ -1068,7 +1086,7 @@ impl NegotiatedStart {
credential: start.credential,
estimate: Some(start.estimate),
peer_target: Some(start.peer_target),
bandwidth: crate::bandwidth::Allocator::default(),
bandwidth: server.allocator(),
viewers,
peer_implementation: start.peer_implementation,
datagrams_unrouted: start.datagrams_unrouted,
Expand Down Expand Up @@ -1822,6 +1840,31 @@ mod tests {
}
}

/// An accepted session reserves into the registry the server was given, so one
/// allocator spans every session a server accepts, as a client's spans its dials.
#[kio::test]
async fn an_accepted_session_shares_the_servers_allocator() {
let allocator = crate::bandwidth::Allocator::default();
let mut target = allocator.target();
let session = FakeSession::new(ALPN_18, [ietf_setup(ietf::Version::Draft18, None)]);
let request = Server::new()
.with_allocator(allocator.clone())
.accept_request(kio::clock::now(), session)
.await
.expect("accept");
let (session, _driver) = request.ok().await.expect("ok");

let broadcast = crate::broadcast::Info::default().produce();
let track = broadcast.create_track("t", crate::track::Info::timed()).unwrap();
let _reserved = session
.allocator()
.reserve(&track.demand(), crate::bandwidth::Rate::from_bps(1_000_000));
assert_eq!(
target.poll_changed(&kio::Waiter::noop()),
std::task::Poll::Ready(crate::bandwidth::Rate::from_bps(1_000_000))
);
}

/// A peer that never takes the SETUP reply is refused at the handshake's deadline
/// with the timeout code, and the session's stats count it.
#[kio::test]
Expand Down