From 4b6e2d9c7021ac76039e19cd0fd5e601ba173d6e Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 19 Oct 2026 11:54:01 -0700 Subject: [PATCH 1/6] Start transport stream snapshot support Co-Authored-By: GPT-6 From af762c71c73fc38b7ab98a7ba444371e93d4dcba Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 19 Oct 2026 12:16:18 -0700 Subject: [PATCH 2/6] Forward native transport stream occupancy and opening credit Co-Authored-By: GPT-6 --- Cargo.lock | 27 ++-- Cargo.toml | 4 + rs/moq-ffi/src/transport/adapter.rs | 27 ++++ rs/moq-net/src/client.rs | 15 +++ rs/moq-net/src/session.rs | 4 + rs/moq-net/src/transport.rs | 29 +++++ rs/moq-quic/src/connection/mod.rs | 9 +- rs/moq-quic/src/connection/stats.rs | 21 +++ rs/moq-quic/src/connection/streams/state.rs | 134 ++++++++++++++++++-- rs/moq-quic/src/lib.rs | 2 +- rs/moq-tokio/src/quic/web/session.rs | 14 ++ rs/moq-tokio/src/transport/owned.rs | 13 ++ rs/moq-uring/src/quic/driver/connection.rs | 15 +++ rs/moq-uring/src/transport/adapter.rs | 27 ++++ rs/moq-wasm/src/transport/adapter.rs | 27 ++++ 15 files changed, 350 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5f68f976317..0e069b90e36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5327,7 +5327,7 @@ dependencies = [ "url", "usage-rs", "web-transport-iroh", - "web-transport-proto", + "web-transport-proto 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "web-transport-trait", "webpki-roots 1.0.9", "x509-parser", @@ -5381,7 +5381,7 @@ dependencies = [ "tokio", "tracing", "url", - "web-transport-proto", + "web-transport-proto 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "web-transport-trait", ] @@ -7489,8 +7489,7 @@ dependencies = [ [[package]] name = "qmux" version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "542edbed299cac6d624d3964c423c2b2a94b19ffcde4eef5fde09b74c64799e4" +source = "git+https://github.com/moq-dev/web-transport?rev=13bd407#13bd407b864e60c5c46c2762e82ca6c001516e51" dependencies = [ "bytes", "futures", @@ -7501,7 +7500,7 @@ dependencies = [ "tokio-rustls", "tokio-tungstenite 0.30.0", "tracing", - "web-transport-proto", + "web-transport-proto 0.6.2 (git+https://github.com/moq-dev/web-transport?rev=13bd407)", "web-transport-trait", ] @@ -11034,7 +11033,7 @@ dependencies = [ "tokio", "tracing", "url", - "web-transport-proto", + "web-transport-proto 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "web-transport-trait", ] @@ -11052,11 +11051,23 @@ dependencies = [ "url", ] +[[package]] +name = "web-transport-proto" +version = "0.6.2" +source = "git+https://github.com/moq-dev/web-transport?rev=13bd407#13bd407b864e60c5c46c2762e82ca6c001516e51" +dependencies = [ + "bytes", + "http", + "sfv", + "thiserror 2.0.21", + "tokio", + "url", +] + [[package]] name = "web-transport-trait" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f1e801f997864ab0074afb1c7d3262df46d5d9ad9b78274c47694544db2dba7" +source = "git+https://github.com/moq-dev/web-transport?rev=13bd407#13bd407b864e60c5c46c2762e82ca6c001516e51" dependencies = [ "bytes", ] diff --git a/Cargo.toml b/Cargo.toml index 6a4f1c1cd39..b180305ef16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -268,6 +268,10 @@ x509-parser = "0.18" zeroize = { version = "1", features = ["derive"] } [patch.crates-io] +# Stream snapshots require the proposed transport API until its next release. +web-transport-trait = { git = "https://github.com/moq-dev/web-transport", rev = "13bd407" } +qmux = { git = "https://github.com/moq-dev/web-transport", rev = "13bd407" } + # web-transport-iroh depends on kio from crates.io. Without # this, the lock carries a second kio whose pin drifts behind the member, and the # next publish that reaches both fails to resolve a single version (#3551). diff --git a/rs/moq-ffi/src/transport/adapter.rs b/rs/moq-ffi/src/transport/adapter.rs index 7b6a08e2e10..060aa6510dd 100644 --- a/rs/moq-ffi/src/transport/adapter.rs +++ b/rs/moq-ffi/src/transport/adapter.rs @@ -19,6 +19,19 @@ impl moq::Error for Error { struct Stats(S); impl moq::Stats for Stats { + fn streams(&self) -> Option { + self.0.streams().map(|streams| moq::Streams { + bidi: moq::StreamState { + open: streams.bidi.open, + available: streams.bidi.available, + }, + uni: moq::StreamState { + open: streams.uni.open, + available: streams.uni.available, + }, + }) + } + fn bytes_sent(&self) -> Option { self.0.bytes_sent() } @@ -234,6 +247,13 @@ mod tests { } struct Sample; impl wt::Stats for Sample { + fn streams(&self) -> Option { + Some(wt::Streams { + bidi: wt::StreamState { open: 3, available: 5 }, + uni: wt::StreamState { open: 7, available: 11 }, + }) + } + fn rtt(&self) -> Option { Some(std::time::Duration::from_millis(7)) } @@ -304,6 +324,13 @@ mod tests { let mut session = Session::new(Backend(state.clone())); let mut cx = Context::from_waker(std::task::Waker::noop()); assert_eq!(poll::Session::protocol(&session), Some("moq-lite-06")); + assert_eq!( + poll::Session::stats(&session).streams(), + Some(moq::Streams { + bidi: moq::StreamState { open: 3, available: 5 }, + uni: moq::StreamState { open: 7, available: 11 }, + }) + ); assert_eq!( poll::Session::stats(&session).rtt(), Some(std::time::Duration::from_millis(7)) diff --git a/rs/moq-net/src/client.rs b/rs/moq-net/src/client.rs index 2596354e2c5..9de92948de4 100644 --- a/rs/moq-net/src/client.rs +++ b/rs/moq-net/src/client.rs @@ -552,6 +552,7 @@ mod tests { control_writes: Arc>>, send_rate: Mutex>, bytes_sent: Mutex>, + streams: Mutex>, } fn any_close(events: &kio::Ref<'_, Vec<(u32, String)>>) -> Poll<()> { @@ -575,6 +576,7 @@ mod tests { control_writes: writes, send_rate: Mutex::new(None), bytes_sent: Mutex::new(None), + streams: Mutex::new(None), }; Self { state: Arc::new(state), @@ -672,16 +674,22 @@ mod tests { FakeStats { send_rate: *self.state.send_rate.lock().unwrap(), bytes_sent: *self.state.bytes_sent.lock().unwrap(), + streams: *self.state.streams.lock().unwrap(), } } } struct FakeStats { + streams: Option, send_rate: Option, bytes_sent: Option, } impl crate::transport::Stats for FakeStats { + fn streams(&self) -> Option { + self.streams + } + fn estimated_send_rate(&self) -> Option { self.send_rate } @@ -1220,6 +1228,10 @@ mod tests { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); fake.set_send_rate(None); fake.set_bytes_sent(Some(0)); + *fake.state.streams.lock().unwrap() = Some(crate::transport::Streams { + bidi: crate::transport::StreamState { open: 3, available: 5 }, + uni: crate::transport::StreamState { open: 7, available: 11 }, + }); let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); let (session, driver) = client.connect(moq_clock::now(), fake.clone()).await.unwrap(); @@ -1230,6 +1242,8 @@ mod tests { ); fake.set_bytes_sent(Some(4242)); + assert_eq!(session.stats().streams.unwrap().bidi.open, 3); + *fake.state.streams.lock().unwrap() = Some(crate::transport::Streams::default()); session.abort(Error::Cancel); session.closed().await; @@ -1239,6 +1253,7 @@ mod tests { Some(4242), "the closing snapshot must carry the session's final counters" ); + assert_eq!(session.stats().streams, Some(crate::transport::Streams::default())); } // The send-bandwidth sampler lives inside the driver: it samples as soon as a diff --git a/rs/moq-net/src/session.rs b/rs/moq-net/src/session.rs index 09a0d80bac5..d3116c28a0b 100644 --- a/rs/moq-net/src/session.rs +++ b/rs/moq-net/src/session.rs @@ -44,6 +44,9 @@ struct StatsState { #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] pub struct Stats { + /// Locally initiated stream occupancy and remaining peer stream-ID credit. + pub streams: Option, + /// Smoothed round-trip time estimate. pub rtt: Option, @@ -641,6 +644,7 @@ impl Supervisor { fn snapshot(session: &S) -> Stats { let stats = session.stats(); Stats { + streams: stats.streams(), rtt: stats.rtt(), estimated_send_rate: stats.estimated_send_rate().map(bandwidth::Rate::from_bps), bytes_sent: stats.bytes_sent(), diff --git a/rs/moq-net/src/transport.rs b/rs/moq-net/src/transport.rs index ddde6f50650..20fc16692d5 100644 --- a/rs/moq-net/src/transport.rs +++ b/rs/moq-net/src/transport.rs @@ -88,11 +88,40 @@ impl Wire { } } +/// A snapshot of locally initiated transport streams. +/// +/// Counts describe backend protocol state, not application stream handles. +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +pub struct Streams { + /// Bidirectional streams initiated by this endpoint. + pub bidi: StreamState, + /// Unidirectional streams initiated by this endpoint. + pub uni: StreamState, +} + +/// Stream occupancy and remaining opening credit for one direction. +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +pub struct StreamState { + /// Streams not yet fully closed by the transport. A bidirectional stream + /// remains open until both halves are closed, including transport retirement. + pub open: u64, + /// Additional stream IDs permitted by the peer's current cumulative limit. + /// + /// Closing a stream does not directly restore this credit: it increases only + /// when the peer grants more. This is not a fixed concurrent capacity. + pub available: u64, +} + /// Connection-level statistics. /// /// Methods return `Option`: `None` means the implementation doesn't track /// this metric, while `Some(0)` means actually zero. pub trait Stats { + /// Locally initiated stream occupancy and remaining peer stream-ID credit. + fn streams(&self) -> Option { + None + } + /// Total bytes sent over the connection, including retransmissions and overhead. fn bytes_sent(&self) -> Option { None diff --git a/rs/moq-quic/src/connection/mod.rs b/rs/moq-quic/src/connection/mod.rs index 8ce51c25626..a12a48d941d 100644 --- a/rs/moq-quic/src/connection/mod.rs +++ b/rs/moq-quic/src/connection/mod.rs @@ -88,7 +88,9 @@ impl ConnectionTag { Self(NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed)) } } -pub use stats::{ConnectionStats, CreditStats, FrameStats, PathStats, UdpStats}; +pub use stats::{ + ConnectionStats, CreditStats, FrameStats, PathStats, StreamState, StreamStats, UdpStats, +}; mod streams; pub(crate) use streams::StreamsState; @@ -1424,6 +1426,11 @@ impl Connection { stats.path.bandwidth_estimate = self.path.congestion.metrics().bandwidth_estimate; stats.path.current_mtu = self.path.mtud.current_mtu(); stats.credit = self.streams.credit_stats(); + stats.streams = if self.state.is_closed() { + StreamStats::default() + } else { + self.streams.stream_stats() + }; stats } diff --git a/rs/moq-quic/src/connection/stats.rs b/rs/moq-quic/src/connection/stats.rs index 1a6dab4ba3b..8daa73cca92 100644 --- a/rs/moq-quic/src/connection/stats.rs +++ b/rs/moq-quic/src/connection/stats.rs @@ -181,6 +181,8 @@ pub struct ConnectionStats { pub path: PathStats, /// Connection-level receive flow control pub credit: CreditStats, + /// Locally initiated stream occupancy and remaining peer stream-ID credit. + pub streams: StreamStats, } /// Connection-level receive flow control, from the receiver's side @@ -193,3 +195,22 @@ pub struct CreditStats { /// advertised pub available: u64, } + +/// Locally initiated transport stream statistics. +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct StreamStats { + /// Locally initiated bidirectional streams. + pub bidi: StreamState, + /// Locally initiated unidirectional streams. + pub uni: StreamState, +} + +/// One direction's stream occupancy and remaining opening credit. +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +pub struct StreamState { + /// Streams not fully retired, including both halves of bidirectional streams. + pub open: u64, + /// Additional stream IDs allowed by the peer's cumulative MAX_STREAMS limit. + /// Closing a stream does not restore this credit until the peer grants more. + pub available: u64, +} diff --git a/rs/moq-quic/src/connection/streams/state.rs b/rs/moq-quic/src/connection/streams/state.rs index f0450c368e6..9e58ed3aa84 100644 --- a/rs/moq-quic/src/connection/streams/state.rs +++ b/rs/moq-quic/src/connection/streams/state.rs @@ -17,7 +17,7 @@ use crate::{ Dir, MAX_STREAM_COUNT, Side, StreamId, TransportError, VarInt, coding::BufMutExt, connection::ConnectionTag, - connection::stats::{CreditStats, FrameStats}, + connection::stats::{CreditStats, FrameStats, StreamState, StreamStats}, frame::{self, FrameStruct, StreamMetaVec}, transport_parameters::TransportParameters, }; @@ -83,6 +83,7 @@ pub(crate) struct StreamsState { pub(super) recv: FxHashMap>, pub(super) free_recv: Vec, pub(super) next: [u64; 2], + local_open: [u64; 2], /// Maximum number of locally-initiated streams that may be opened over the lifetime of the /// connection so far, per direction pub(super) max: [u64; 2], @@ -179,6 +180,7 @@ impl StreamsState { recv: FxHashMap::default(), free_recv: Vec::new(), next: [0, 0], + local_open: [0, 0], max: [0, 0], max_remote: [max_remote_bi.into(), max_remote_uni.into()], sent_max_remote: [max_remote_bi.into(), max_remote_uni.into()], @@ -266,6 +268,7 @@ impl StreamsState { } } self.next[dir as usize] = 0; + self.local_open[dir as usize] = 0; // If 0-RTT was rejected, any flow control frames we sent were lost. if self.flow_control_adjusted { @@ -1019,6 +1022,7 @@ impl StreamsState { pub(super) fn insert_local(&mut self, id: StreamId) { debug_assert_eq!(id.initiator(), self.side); assert!(self.send.insert(id, None).is_none()); + self.local_open[id.dir() as usize] += 1; if id.dir() == Dir::Bi { let recv = self.free_recv.pop(); assert!(self.recv.insert(id, recv).is_none()); @@ -1111,15 +1115,28 @@ impl StreamsState { } } + pub(crate) fn stream_stats(&self) -> StreamStats { + let state = |dir: Dir| StreamState { + open: self.local_open[dir as usize], + available: self.max[dir as usize].saturating_sub(self.next[dir as usize]), + }; + StreamStats { + bidi: state(Dir::Bi), + uni: state(Dir::Uni), + } + } + /// Update counters for removal of a stream pub(super) fn stream_freed(&mut self, id: StreamId, half: StreamHalf) { - if id.initiator() != self.side { - let fully_free = id.dir() == Dir::Uni - || match half { - StreamHalf::Send => !self.recv.contains_key(&id), - StreamHalf::Recv => !self.send.contains_key(&id), - }; - if fully_free { + let fully_free = id.dir() == Dir::Uni + || match half { + StreamHalf::Send => !self.recv.contains_key(&id), + StreamHalf::Recv => !self.send.contains_key(&id), + }; + if fully_free { + if id.initiator() == self.side { + self.local_open[id.dir() as usize] -= 1; + } else { self.allocated_remote_count[id.dir() as usize] -= 1; self.ensure_remote_streams(id.dir()); } @@ -1166,6 +1183,107 @@ mod tests { }; use bytes::Bytes; + #[test] + fn stream_statistics_wait_for_both_halves_and_do_not_recycle_id_credit() { + for side in [Side::Client, Side::Server] { + let mut state = make(side); + state.set_params(&TransportParameters { + initial_max_streams_uni: 1u32.into(), + initial_max_streams_bidi: 1u32.into(), + ..TransportParameters::default() + }); + let conn_state = ConnState::Established; + let mut pending = Retransmits::default(); + for dir in Dir::iter() { + let id = Streams { + state: &mut state, + conn_state: &conn_state, + } + .open(dir, Default::default()) + .unwrap(); + assert_eq!(state.local_open[dir as usize], 1); + let snapshot = state.stream_stats(); + assert_eq!( + match dir { + Dir::Bi => snapshot.bidi, + Dir::Uni => snapshot.uni, + } + .available, + 0 + ); + SendStream { + id, + state: &mut state, + pending: &mut pending, + conn_state: &conn_state, + } + .finish() + .unwrap(); + // FIN is not closure until the peer acknowledges it. + assert_eq!(state.local_open[dir as usize], 1); + state.received_ack_of(frame::StreamMeta { + id, + offsets: 0..0, + fin: true, + }); + if dir == Dir::Bi { + assert_eq!(state.stream_stats().bidi.open, 1); + let _ = state + .received( + frame::Stream { + id, + offset: 0, + fin: true, + data: Bytes::new(), + }, + 0, + ) + .unwrap(); + let mut recv = RecvStream { + id, + state: &mut state, + pending: &mut pending, + }; + let mut chunks = recv.read(true).unwrap(); + assert!(chunks.next(1).unwrap().is_none()); + let _ = chunks.finalize(); + } + assert_eq!(state.local_open[dir as usize], 0); + assert_eq!(state.max[dir as usize] - state.next[dir as usize], 0); + } + } + } + + #[test] + fn rejected_early_streams_reset_occupancy_and_id_credit() { + let mut state = make(Side::Client); + state.max = [1, 1]; + let conn_state = ConnState::Established; + for dir in Dir::iter() { + Streams { + state: &mut state, + conn_state: &conn_state, + } + .open(dir, Default::default()) + .unwrap(); + } + state.zero_rtt_rejected(); + assert_eq!( + state.stream_stats().bidi, + StreamState { + open: 0, + available: 1 + } + ); + assert_eq!( + state.stream_stats().uni, + StreamState { + open: 0, + available: 1 + } + ); + } + fn make(side: Side) -> StreamsState { StreamsState::new( side, diff --git a/rs/moq-quic/src/lib.rs b/rs/moq-quic/src/lib.rs index 7927e9b9fd4..17deca858db 100644 --- a/rs/moq-quic/src/lib.rs +++ b/rs/moq-quic/src/lib.rs @@ -56,7 +56,7 @@ pub use crate::connection::{ Chunk, Chunks, ClosedStream, Connection, ConnectionError, ConnectionStats, Credit, CreditStats, Datagrams, Event, FinishError, FrameStats, PathStats, ReadError, ReadableError, RecvStream, RttEstimator, SendDatagramError, SendGroup, SendGroups, SendOptions, SendStream, - ShouldTransmit, StreamEvent, Streams, UdpStats, WriteError, Written, + ShouldTransmit, StreamEvent, StreamState, StreamStats, Streams, UdpStats, WriteError, Written, }; #[cfg(feature = "qlog")] pub use connection::qlog::QlogStream; diff --git a/rs/moq-tokio/src/quic/web/session.rs b/rs/moq-tokio/src/quic/web/session.rs index b65d732209d..f46ed1bec1d 100644 --- a/rs/moq-tokio/src/quic/web/session.rs +++ b/rs/moq-tokio/src/quic/web/session.rs @@ -950,6 +950,20 @@ fn log_header_error(err: SessionError, direction: &'static str) { pub struct SessionStats(crate::quic::driver::ConnectionStats); impl web_transport_trait::Stats for SessionStats { + fn streams(&self) -> Option { + let streams = self.0.streams; + Some(web_transport_trait::Streams { + bidi: web_transport_trait::StreamState { + open: streams.bidi.open, + available: streams.bidi.available, + }, + uni: web_transport_trait::StreamState { + open: streams.uni.open, + available: streams.uni.available, + }, + }) + } + fn bytes_sent(&self) -> Option { Some(self.0.udp_tx.bytes) } diff --git a/rs/moq-tokio/src/transport/owned.rs b/rs/moq-tokio/src/transport/owned.rs index eec916f342d..6253cf145e1 100644 --- a/rs/moq-tokio/src/transport/owned.rs +++ b/rs/moq-tokio/src/transport/owned.rs @@ -22,6 +22,19 @@ impl moq::Error for Error { struct Stats(S); impl moq::Stats for Stats { + fn streams(&self) -> Option { + self.0.streams().map(|streams| moq::Streams { + bidi: moq::StreamState { + open: streams.bidi.open, + available: streams.bidi.available, + }, + uni: moq::StreamState { + open: streams.uni.open, + available: streams.uni.available, + }, + }) + } + fn bytes_sent(&self) -> Option { self.0.bytes_sent() } diff --git a/rs/moq-uring/src/quic/driver/connection.rs b/rs/moq-uring/src/quic/driver/connection.rs index 8dcb786ef21..ba08b23d7d0 100644 --- a/rs/moq-uring/src/quic/driver/connection.rs +++ b/rs/moq-uring/src/quic/driver/connection.rs @@ -657,6 +657,7 @@ impl web_transport_trait::poll::Session for Connection { fn stats(&self) -> impl web_transport_trait::Stats { let stats = self.shared.conn.borrow().stats(); Stats { + streams: stats.streams, bytes_sent: stats.udp_tx.bytes, bytes_received: stats.udp_rx.bytes, bytes_lost: stats.path.lost_bytes, @@ -678,6 +679,7 @@ impl std::fmt::Debug for Connection { /// A snapshot of moq-quic's counters in [`web_transport_trait::Stats`] /// shape. struct Stats { + streams: moq_quic::StreamStats, bytes_sent: u64, bytes_received: u64, bytes_lost: u64, @@ -690,6 +692,19 @@ struct Stats { } impl web_transport_trait::Stats for Stats { + fn streams(&self) -> Option { + Some(web_transport_trait::Streams { + bidi: web_transport_trait::StreamState { + open: self.streams.bidi.open, + available: self.streams.bidi.available, + }, + uni: web_transport_trait::StreamState { + open: self.streams.uni.open, + available: self.streams.uni.available, + }, + }) + } + fn bytes_sent(&self) -> Option { Some(self.bytes_sent) } diff --git a/rs/moq-uring/src/transport/adapter.rs b/rs/moq-uring/src/transport/adapter.rs index b2e2fa32c1f..61f70b829c9 100644 --- a/rs/moq-uring/src/transport/adapter.rs +++ b/rs/moq-uring/src/transport/adapter.rs @@ -22,6 +22,19 @@ impl moq::Error for Error { struct Stats(S); impl moq::Stats for Stats { + fn streams(&self) -> Option { + self.0.streams().map(|streams| moq::Streams { + bidi: moq::StreamState { + open: streams.bidi.open, + available: streams.bidi.available, + }, + uni: moq::StreamState { + open: streams.uni.open, + available: streams.uni.available, + }, + }) + } + fn bytes_sent(&self) -> Option { self.0.bytes_sent() } @@ -312,6 +325,13 @@ mod tests { impl Grouped for Backend {} struct Sample; impl wt::Stats for Sample { + fn streams(&self) -> Option { + Some(wt::Streams { + bidi: wt::StreamState { open: 3, available: 5 }, + uni: wt::StreamState { open: 7, available: 11 }, + }) + } + fn rtt(&self) -> Option { Some(std::time::Duration::from_millis(7)) } @@ -382,6 +402,13 @@ mod tests { let mut session = Session::new(Backend(state.clone()), moq::Binding::InBand); let mut cx = Context::from_waker(std::task::Waker::noop()); assert_eq!(poll::Session::protocol(&session), Some("moq-lite-06")); + assert_eq!( + poll::Session::stats(&session).streams(), + Some(moq::Streams { + bidi: moq::StreamState { open: 3, available: 5 }, + uni: moq::StreamState { open: 7, available: 11 }, + }) + ); assert_eq!( poll::Session::stats(&session).rtt(), Some(std::time::Duration::from_millis(7)) diff --git a/rs/moq-wasm/src/transport/adapter.rs b/rs/moq-wasm/src/transport/adapter.rs index 7b6a08e2e10..060aa6510dd 100644 --- a/rs/moq-wasm/src/transport/adapter.rs +++ b/rs/moq-wasm/src/transport/adapter.rs @@ -19,6 +19,19 @@ impl moq::Error for Error { struct Stats(S); impl moq::Stats for Stats { + fn streams(&self) -> Option { + self.0.streams().map(|streams| moq::Streams { + bidi: moq::StreamState { + open: streams.bidi.open, + available: streams.bidi.available, + }, + uni: moq::StreamState { + open: streams.uni.open, + available: streams.uni.available, + }, + }) + } + fn bytes_sent(&self) -> Option { self.0.bytes_sent() } @@ -234,6 +247,13 @@ mod tests { } struct Sample; impl wt::Stats for Sample { + fn streams(&self) -> Option { + Some(wt::Streams { + bidi: wt::StreamState { open: 3, available: 5 }, + uni: wt::StreamState { open: 7, available: 11 }, + }) + } + fn rtt(&self) -> Option { Some(std::time::Duration::from_millis(7)) } @@ -304,6 +324,13 @@ mod tests { let mut session = Session::new(Backend(state.clone())); let mut cx = Context::from_waker(std::task::Waker::noop()); assert_eq!(poll::Session::protocol(&session), Some("moq-lite-06")); + assert_eq!( + poll::Session::stats(&session).streams(), + Some(moq::Streams { + bidi: moq::StreamState { open: 3, available: 5 }, + uni: moq::StreamState { open: 7, available: 11 }, + }) + ); assert_eq!( poll::Session::stats(&session).rtt(), Some(std::time::Duration::from_millis(7)) From 154f3dc8b4577a822396f7b9f943cc82a21d6bc8 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 19 Oct 2026 17:29:56 -0700 Subject: [PATCH 3/6] fix(quic): mark the stream stats non_exhaustive like their siblings Co-Authored-By: Claude Opus 5.5 --- rs/moq-quic/src/connection/stats.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rs/moq-quic/src/connection/stats.rs b/rs/moq-quic/src/connection/stats.rs index 8daa73cca92..50143c5cc6a 100644 --- a/rs/moq-quic/src/connection/stats.rs +++ b/rs/moq-quic/src/connection/stats.rs @@ -198,6 +198,7 @@ pub struct CreditStats { /// Locally initiated transport stream statistics. #[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +#[non_exhaustive] pub struct StreamStats { /// Locally initiated bidirectional streams. pub bidi: StreamState, @@ -207,6 +208,7 @@ pub struct StreamStats { /// One direction's stream occupancy and remaining opening credit. #[derive(Debug, Default, Copy, Clone, PartialEq, Eq)] +#[non_exhaustive] pub struct StreamState { /// Streams not fully retired, including both halves of bidirectional streams. pub open: u64, From 3912019030b36fa7bcffcbd327002233f522cd35 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 20 Oct 2026 13:17:04 -0700 Subject: [PATCH 4/6] refactor(transport): report stream counts through the sealed backend hook Drop the web-transport-trait Stats::streams plumbing and its git patch on moq-dev/web-transport#440. Native QUIC sessions in moq-tokio and moq-uring now hand moq-quic's snapshot to moq-net through the crate-private Grouped hook, next to wire(). The FFI and WASM adapters only wrap the browser backend, which has no counts, so they are unchanged. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 27 +++------ Cargo.toml | 4 -- rs/moq-ffi/src/transport/adapter.rs | 27 --------- rs/moq-tokio/src/quic/web/session.rs | 14 ----- rs/moq-tokio/src/transport.rs | 34 ++++++++++- rs/moq-tokio/src/transport/grouped.rs | 16 ++++-- rs/moq-tokio/src/transport/owned.rs | 38 ++++++------- rs/moq-tokio/tests/integration/backend.rs | 2 + rs/moq-uring/src/quic/driver/connection.rs | 15 ----- rs/moq-uring/src/quic/web.rs | 5 ++ rs/moq-uring/src/transport.rs | 12 ++++ rs/moq-uring/src/transport/adapter.rs | 66 +++++++++++----------- rs/moq-wasm/src/transport/adapter.rs | 27 --------- 13 files changed, 122 insertions(+), 165 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87dbc839517..7c703cac3a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5366,7 +5366,7 @@ dependencies = [ "url", "usage-rs", "web-transport-iroh", - "web-transport-proto 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "web-transport-proto", "web-transport-trait", "webpki-roots 1.0.9", "x509-parser", @@ -5421,7 +5421,7 @@ dependencies = [ "tokio", "tracing", "url", - "web-transport-proto 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "web-transport-proto", "web-transport-trait", ] @@ -7529,7 +7529,8 @@ dependencies = [ [[package]] name = "qmux" version = "0.6.3" -source = "git+https://github.com/moq-dev/web-transport?rev=13bd407#13bd407b864e60c5c46c2762e82ca6c001516e51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "542edbed299cac6d624d3964c423c2b2a94b19ffcde4eef5fde09b74c64799e4" dependencies = [ "bytes", "futures", @@ -7540,7 +7541,7 @@ dependencies = [ "tokio-rustls", "tokio-tungstenite 0.30.0", "tracing", - "web-transport-proto 0.6.2 (git+https://github.com/moq-dev/web-transport?rev=13bd407)", + "web-transport-proto", "web-transport-trait", ] @@ -11073,7 +11074,7 @@ dependencies = [ "tokio", "tracing", "url", - "web-transport-proto 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "web-transport-proto", "web-transport-trait", ] @@ -11091,23 +11092,11 @@ dependencies = [ "url", ] -[[package]] -name = "web-transport-proto" -version = "0.6.2" -source = "git+https://github.com/moq-dev/web-transport?rev=13bd407#13bd407b864e60c5c46c2762e82ca6c001516e51" -dependencies = [ - "bytes", - "http", - "sfv", - "thiserror 2.0.21", - "tokio", - "url", -] - [[package]] name = "web-transport-trait" version = "0.5.0" -source = "git+https://github.com/moq-dev/web-transport?rev=13bd407#13bd407b864e60c5c46c2762e82ca6c001516e51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f1e801f997864ab0074afb1c7d3262df46d5d9ad9b78274c47694544db2dba7" dependencies = [ "bytes", ] diff --git a/Cargo.toml b/Cargo.toml index bcbf7f460a9..479044152d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -269,10 +269,6 @@ x509-parser = "0.18" zeroize = { version = "1", features = ["derive"] } [patch.crates-io] -# Stream snapshots require the proposed transport API until its next release. -web-transport-trait = { git = "https://github.com/moq-dev/web-transport", rev = "13bd407" } -qmux = { git = "https://github.com/moq-dev/web-transport", rev = "13bd407" } - # web-transport-iroh depends on kio from crates.io. Without # this, the lock carries a second kio whose pin drifts behind the member, and the # next publish that reaches both fails to resolve a single version (#3551). diff --git a/rs/moq-ffi/src/transport/adapter.rs b/rs/moq-ffi/src/transport/adapter.rs index 060aa6510dd..7b6a08e2e10 100644 --- a/rs/moq-ffi/src/transport/adapter.rs +++ b/rs/moq-ffi/src/transport/adapter.rs @@ -19,19 +19,6 @@ impl moq::Error for Error { struct Stats(S); impl moq::Stats for Stats { - fn streams(&self) -> Option { - self.0.streams().map(|streams| moq::Streams { - bidi: moq::StreamState { - open: streams.bidi.open, - available: streams.bidi.available, - }, - uni: moq::StreamState { - open: streams.uni.open, - available: streams.uni.available, - }, - }) - } - fn bytes_sent(&self) -> Option { self.0.bytes_sent() } @@ -247,13 +234,6 @@ mod tests { } struct Sample; impl wt::Stats for Sample { - fn streams(&self) -> Option { - Some(wt::Streams { - bidi: wt::StreamState { open: 3, available: 5 }, - uni: wt::StreamState { open: 7, available: 11 }, - }) - } - fn rtt(&self) -> Option { Some(std::time::Duration::from_millis(7)) } @@ -324,13 +304,6 @@ mod tests { let mut session = Session::new(Backend(state.clone())); let mut cx = Context::from_waker(std::task::Waker::noop()); assert_eq!(poll::Session::protocol(&session), Some("moq-lite-06")); - assert_eq!( - poll::Session::stats(&session).streams(), - Some(moq::Streams { - bidi: moq::StreamState { open: 3, available: 5 }, - uni: moq::StreamState { open: 7, available: 11 }, - }) - ); assert_eq!( poll::Session::stats(&session).rtt(), Some(std::time::Duration::from_millis(7)) diff --git a/rs/moq-tokio/src/quic/web/session.rs b/rs/moq-tokio/src/quic/web/session.rs index f46ed1bec1d..b65d732209d 100644 --- a/rs/moq-tokio/src/quic/web/session.rs +++ b/rs/moq-tokio/src/quic/web/session.rs @@ -950,20 +950,6 @@ fn log_header_error(err: SessionError, direction: &'static str) { pub struct SessionStats(crate::quic::driver::ConnectionStats); impl web_transport_trait::Stats for SessionStats { - fn streams(&self) -> Option { - let streams = self.0.streams; - Some(web_transport_trait::Streams { - bidi: web_transport_trait::StreamState { - open: streams.bidi.open, - available: streams.bidi.available, - }, - uni: web_transport_trait::StreamState { - open: streams.uni.open, - available: streams.uni.available, - }, - }) - } - fn bytes_sent(&self) -> Option { Some(self.0.udp_tx.bytes) } diff --git a/rs/moq-tokio/src/transport.rs b/rs/moq-tokio/src/transport.rs index 5f60ad295b9..7e9dd8eb982 100644 --- a/rs/moq-tokio/src/transport.rs +++ b/rs/moq-tokio/src/transport.rs @@ -878,6 +878,18 @@ impl Grouped for crate::quic::web::Session { Some(crate::quic::driver::Connection::wire(self)) } + fn streams(&self) -> Option { + let streams = crate::quic::driver::Connection::stats(self).streams; + let state = |s: moq_quic::StreamState| moq_net::transport::StreamState { + open: s.open, + available: s.available, + }; + Some(moq_net::transport::Streams { + bidi: state(streams.bidi), + uni: state(streams.uni), + }) + } + fn send_group(&self, priority: i64) -> Option { Some(Self::send_group(self, priority)) } @@ -1444,7 +1456,14 @@ mod tests { #[derive(Clone)] struct FakeSession; - impl Grouped for FakeSession {} + impl Grouped for FakeSession { + fn streams(&self) -> Option { + Some(moq_net::transport::Streams { + bidi: moq_net::transport::StreamState { open: 3, available: 5 }, + uni: moq_net::transport::StreamState { open: 7, available: 11 }, + }) + } + } impl web_transport_trait::Session for FakeSession { type SendStream = FakeSend; @@ -1486,6 +1505,19 @@ mod tests { } } + #[test] + fn owned_poll_adapter_reports_backend_stream_counts() { + use moq_net::transport::{Stats as _, poll}; + let session = Session::new(FakeSession, moq_net::transport::Binding::Uri); + assert_eq!( + poll::Session::stats(&session).streams(), + Some(moq_net::transport::Streams { + bidi: moq_net::transport::StreamState { open: 3, available: 5 }, + uni: moq_net::transport::StreamState { open: 7, available: 11 }, + }) + ); + } + #[test] fn owned_poll_adapter_forwards_writes_and_resets() { use moq_net::transport::poll; diff --git a/rs/moq-tokio/src/transport/grouped.rs b/rs/moq-tokio/src/transport/grouped.rs index a3b0bfc9f35..2b34e3399cd 100644 --- a/rs/moq-tokio/src/transport/grouped.rs +++ b/rs/moq-tokio/src/transport/grouped.rs @@ -1,4 +1,4 @@ -//! Send-group and wire-counter hooks for the async backends. +//! Send-group, wire-counter and stream-count hooks for the async backends. //! //! The traits are `pub` in this private module, so other crates can neither name nor //! implement them: `pub(crate)` is refused (E0446) because the public adapter's @@ -8,16 +8,22 @@ use moq_net::transport::poll::SendOptions; /// A backend session whose send streams may join send groups, as native QUIC's do. /// -/// The async interface has no groups or wire counters, so moq-net's -/// [`send_group`](moq_net::transport::poll::Session::send_group) and -/// [`wire`](moq_net::transport::poll::Session::wire) reach a backend through this. A -/// backend without either implements it empty. +/// The async interface has no groups, wire counters or stream counts, so moq-net's +/// [`send_group`](moq_net::transport::poll::Session::send_group), +/// [`wire`](moq_net::transport::poll::Session::wire) and +/// [`Stats::streams`](moq_net::transport::Stats::streams) reach a backend through this. +/// A backend without any of them implements it empty. pub trait Grouped: web_transport_trait::Session { /// The wire counters the backend updates as it sends and receives, or `None` when it has none. fn wire(&self) -> Option { None } + /// Locally initiated stream occupancy and remaining peer stream-ID credit, or `None` when the backend doesn't track it. + fn streams(&self) -> Option { + None + } + /// Open a send group at `priority`, or `None` when the backend has none. fn send_group(&self, priority: i64) -> Option<::Group> { let _ = priority; diff --git a/rs/moq-tokio/src/transport/owned.rs b/rs/moq-tokio/src/transport/owned.rs index 6253cf145e1..668b94cc7f4 100644 --- a/rs/moq-tokio/src/transport/owned.rs +++ b/rs/moq-tokio/src/transport/owned.rs @@ -20,44 +20,37 @@ impl moq::Error for Error { } } -struct Stats(S); +struct Stats { + backend: S, + streams: Option, +} impl moq::Stats for Stats { fn streams(&self) -> Option { - self.0.streams().map(|streams| moq::Streams { - bidi: moq::StreamState { - open: streams.bidi.open, - available: streams.bidi.available, - }, - uni: moq::StreamState { - open: streams.uni.open, - available: streams.uni.available, - }, - }) + self.streams } - fn bytes_sent(&self) -> Option { - self.0.bytes_sent() + self.backend.bytes_sent() } fn bytes_received(&self) -> Option { - self.0.bytes_received() + self.backend.bytes_received() } fn bytes_lost(&self) -> Option { - self.0.bytes_lost() + self.backend.bytes_lost() } fn packets_sent(&self) -> Option { - self.0.packets_sent() + self.backend.packets_sent() } fn packets_received(&self) -> Option { - self.0.packets_received() + self.backend.packets_received() } fn packets_lost(&self) -> Option { - self.0.packets_lost() + self.backend.packets_lost() } fn rtt(&self) -> Option { - self.0.rtt() + self.backend.rtt() } fn estimated_send_rate(&self) -> Option { - self.0.estimated_send_rate() + self.backend.estimated_send_rate() } } impl> poll::Session for super::Session { @@ -123,7 +116,10 @@ impl> poll::Session backend::Session::poll_closed(self, cx).map(Error) } fn stats(&self) -> impl moq::Stats { - Stats(backend::Session::stats(self)) + Stats { + backend: backend::Session::stats(self), + streams: super::Grouped::streams(&self.session), + } } fn wire(&self) -> Option { super::Grouped::wire(&self.session) diff --git a/rs/moq-tokio/tests/integration/backend.rs b/rs/moq-tokio/tests/integration/backend.rs index e08488a9572..9333bc77c33 100644 --- a/rs/moq-tokio/tests/integration/backend.rs +++ b/rs/moq-tokio/tests/integration/backend.rs @@ -169,6 +169,8 @@ async fn connect_test(config: ConnectTest<'_>) { assert_eq!(request.authority(), expect_authority.as_deref()); } let (session, _driver) = request.with_publisher(&pub_origin).ok().await?; + // Native QUIC reports its stream counts through moq-net's sampler. + assert!(session.stats().streams.is_some()); let _broadcast = broadcast; let _track = track; diff --git a/rs/moq-uring/src/quic/driver/connection.rs b/rs/moq-uring/src/quic/driver/connection.rs index fff91644fc2..1e08132aa2d 100644 --- a/rs/moq-uring/src/quic/driver/connection.rs +++ b/rs/moq-uring/src/quic/driver/connection.rs @@ -657,7 +657,6 @@ impl web_transport_trait::poll::Session for Connection { fn stats(&self) -> impl web_transport_trait::Stats { let stats = self.shared.conn.borrow().stats(); Stats { - streams: stats.streams, bytes_sent: stats.udp_tx.bytes, bytes_received: stats.udp_rx.bytes, bytes_lost: stats.path.lost_bytes, @@ -679,7 +678,6 @@ impl std::fmt::Debug for Connection { /// A snapshot of moq-quic's counters in [`web_transport_trait::Stats`] /// shape. struct Stats { - streams: moq_quic::StreamStats, bytes_sent: u64, bytes_received: u64, bytes_lost: u64, @@ -692,19 +690,6 @@ struct Stats { } impl web_transport_trait::Stats for Stats { - fn streams(&self) -> Option { - Some(web_transport_trait::Streams { - bidi: web_transport_trait::StreamState { - open: self.streams.bidi.open, - available: self.streams.bidi.available, - }, - uni: web_transport_trait::StreamState { - open: self.streams.uni.open, - available: self.streams.uni.available, - }, - }) - } - fn bytes_sent(&self) -> Option { Some(self.bytes_sent) } diff --git a/rs/moq-uring/src/quic/web.rs b/rs/moq-uring/src/quic/web.rs index e644043da0a..5c8c836ee76 100644 --- a/rs/moq-uring/src/quic/web.rs +++ b/rs/moq-uring/src/quic/web.rs @@ -450,6 +450,11 @@ impl Session { self.conn.wire() } + /// Locally initiated stream occupancy and remaining peer stream-ID credit. + pub(crate) fn streams(&self) -> moq_quic::StreamStats { + self.conn.stats().streams + } + /// Open a send group at `priority`, for streams to join with /// [`SendStream::set_group`]. The HTTP/3 streams stay outside every /// group, so they go first. diff --git a/rs/moq-uring/src/transport.rs b/rs/moq-uring/src/transport.rs index 12efe45010a..78ad3252212 100644 --- a/rs/moq-uring/src/transport.rs +++ b/rs/moq-uring/src/transport.rs @@ -15,6 +15,18 @@ impl Grouped for quic::web::Session { Some(quic::web::Session::wire(self)) } + fn streams(&self) -> Option { + let streams = quic::web::Session::streams(self); + let state = |s: moq_quic::StreamState| moq_net::transport::StreamState { + open: s.open, + available: s.available, + }; + Some(moq_net::transport::Streams { + bidi: state(streams.bidi), + uni: state(streams.uni), + }) + } + fn send_group(&mut self, priority: i64) -> Option { Some(quic::web::Session::send_group(self, priority)) } diff --git a/rs/moq-uring/src/transport/adapter.rs b/rs/moq-uring/src/transport/adapter.rs index 61f70b829c9..2c5d2a4e8fd 100644 --- a/rs/moq-uring/src/transport/adapter.rs +++ b/rs/moq-uring/src/transport/adapter.rs @@ -20,44 +20,37 @@ impl moq::Error for Error { } } -struct Stats(S); +struct Stats { + backend: S, + streams: Option, +} impl moq::Stats for Stats { fn streams(&self) -> Option { - self.0.streams().map(|streams| moq::Streams { - bidi: moq::StreamState { - open: streams.bidi.open, - available: streams.bidi.available, - }, - uni: moq::StreamState { - open: streams.uni.open, - available: streams.uni.available, - }, - }) + self.streams } - fn bytes_sent(&self) -> Option { - self.0.bytes_sent() + self.backend.bytes_sent() } fn bytes_received(&self) -> Option { - self.0.bytes_received() + self.backend.bytes_received() } fn bytes_lost(&self) -> Option { - self.0.bytes_lost() + self.backend.bytes_lost() } fn packets_sent(&self) -> Option { - self.0.packets_sent() + self.backend.packets_sent() } fn packets_received(&self) -> Option { - self.0.packets_received() + self.backend.packets_received() } fn packets_lost(&self) -> Option { - self.0.packets_lost() + self.backend.packets_lost() } fn rtt(&self) -> Option { - self.0.rtt() + self.backend.rtt() } fn estimated_send_rate(&self) -> Option { - self.0.estimated_send_rate() + self.backend.estimated_send_rate() } } /// A backend session whose send streams may join send groups, as native QUIC's do. @@ -66,15 +59,21 @@ impl moq::Stats for Stats { /// through [`GroupedSend`]. The module is private and the trait is not re-exported, so /// other crates can neither name nor implement it. /// -/// The backend interface has no groups or wire counters, so moq-net's -/// [`send_group`](poll::Session::send_group) and [`wire`](poll::Session::wire) reach a -/// backend through this. A backend without either implements it empty. +/// The backend interface has no groups, wire counters or stream counts, so moq-net's +/// [`send_group`](poll::Session::send_group), [`wire`](poll::Session::wire) and +/// [`Stats::streams`](moq::Stats::streams) reach a backend through this. A backend +/// without any of them implements it empty. pub trait Grouped: backend::Session { /// The wire counters the backend updates as it sends and receives, or `None` when it has none. fn wire(&self) -> Option { None } + /// Locally initiated stream occupancy and remaining peer stream-ID credit, or `None` when the backend doesn't track it. + fn streams(&self) -> Option { + None + } + /// Open a send group at `priority`, or `None` when the backend has none. fn send_group(&mut self, priority: i64) -> Option<::Group> { let _ = priority; @@ -183,7 +182,10 @@ impl + Clone + 'static> pol backend::Session::poll_closed(&mut self.0, cx).map(Error) } fn stats(&self) -> impl moq::Stats { - Stats(backend::Session::stats(&self.0)) + Stats { + backend: backend::Session::stats(&self.0), + streams: Grouped::streams(&self.0), + } } fn wire(&self) -> Option { Grouped::wire(&self.0) @@ -322,16 +324,16 @@ mod tests { match *group {} } } - impl Grouped for Backend {} - struct Sample; - impl wt::Stats for Sample { - fn streams(&self) -> Option { - Some(wt::Streams { - bidi: wt::StreamState { open: 3, available: 5 }, - uni: wt::StreamState { open: 7, available: 11 }, + impl Grouped for Backend { + fn streams(&self) -> Option { + Some(moq::Streams { + bidi: moq::StreamState { open: 3, available: 5 }, + uni: moq::StreamState { open: 7, available: 11 }, }) } - + } + struct Sample; + impl wt::Stats for Sample { fn rtt(&self) -> Option { Some(std::time::Duration::from_millis(7)) } diff --git a/rs/moq-wasm/src/transport/adapter.rs b/rs/moq-wasm/src/transport/adapter.rs index 060aa6510dd..7b6a08e2e10 100644 --- a/rs/moq-wasm/src/transport/adapter.rs +++ b/rs/moq-wasm/src/transport/adapter.rs @@ -19,19 +19,6 @@ impl moq::Error for Error { struct Stats(S); impl moq::Stats for Stats { - fn streams(&self) -> Option { - self.0.streams().map(|streams| moq::Streams { - bidi: moq::StreamState { - open: streams.bidi.open, - available: streams.bidi.available, - }, - uni: moq::StreamState { - open: streams.uni.open, - available: streams.uni.available, - }, - }) - } - fn bytes_sent(&self) -> Option { self.0.bytes_sent() } @@ -247,13 +234,6 @@ mod tests { } struct Sample; impl wt::Stats for Sample { - fn streams(&self) -> Option { - Some(wt::Streams { - bidi: wt::StreamState { open: 3, available: 5 }, - uni: wt::StreamState { open: 7, available: 11 }, - }) - } - fn rtt(&self) -> Option { Some(std::time::Duration::from_millis(7)) } @@ -324,13 +304,6 @@ mod tests { let mut session = Session::new(Backend(state.clone())); let mut cx = Context::from_waker(std::task::Waker::noop()); assert_eq!(poll::Session::protocol(&session), Some("moq-lite-06")); - assert_eq!( - poll::Session::stats(&session).streams(), - Some(moq::Streams { - bidi: moq::StreamState { open: 3, available: 5 }, - uni: moq::StreamState { open: 7, available: 11 }, - }) - ); assert_eq!( poll::Session::stats(&session).rtt(), Some(std::time::Duration::from_millis(7)) From 286c8fb8f1f014c6be10d4bf849591a10abbf954 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 20 Oct 2026 17:37:16 -0700 Subject: [PATCH 5/6] docs(quic): list stream occupancy among moq-quic's carried changes Co-Authored-By: Claude Opus 5.5 --- rs/moq-quic/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/rs/moq-quic/README.md b/rs/moq-quic/README.md index 6c055b023b0..11bd6ae563c 100644 --- a/rs/moq-quic/README.md +++ b/rs/moq-quic/README.md @@ -84,6 +84,7 @@ Changes on top of the upstream commit, besides the renames: - **Late stream limits**: peer transport parameters that raise a stream limit after an open was refused emit `StreamEvent::Available`, as `MAX_STREAMS` does. A server accepted before the rest of a multi-packet ClientHello (a post-quantum key share is enough) otherwise leaves a 0.5-RTT `open_uni` parked until the idle timeout. Not offered upstream yet. - **Stream credit on stop**: `RecvStream::stop` on a stream whose final size is already known (finished or reset) frees it and queues `MAX_STREAMS` at once, as reading the reset does, instead of leaving the credit until the next packet arrives. Not offered upstream yet; quinn `main` has the same gap. - **Connection limits** (`Limits`, `Connection::set_limits`, and the drivers' `set_limits`): one validated call changes a live connection's stream limit and windows, refusing values a peer would reject and changing nothing then. moq-tokio and moq-uring re-export the type, so both runtimes check limits the same way. Not offered upstream: it only bundles quinn's existing setters. +- **Stream occupancy** (`ConnectionStats::streams`, `StreamStats`): per direction, `open` counts locally initiated streams until `StreamsState::stream_freed` fully retires them (both halves of a bidi stream; a FIN or reset only once acknowledged), and `available` is the peer's cumulative `MAX_STREAMS` minus the next stream ID. A rejected 0-RTT resets both, and a closed connection reports zeros. A cherry-pick touching `insert_local`, `stream_freed`, or `zero_rtt_rejected` has to keep the count. Not offered upstream: quinn exposes no stream counts. Recheck the BBR3 changes when cherry-picking quinn#2481 updates, or if it merges. From 3e0353e6b2ec45f6d8a60949c5ce19926504616e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 20 Oct 2026 18:16:38 -0700 Subject: [PATCH 6/6] docs(net): note that JS Stats omits Rust's native-only streams field Co-Authored-By: Claude Opus 5.5 --- js/net/src/connection/stats.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/net/src/connection/stats.ts b/js/net/src/connection/stats.ts index a4e03389042..0bc51aa98f2 100644 --- a/js/net/src/connection/stats.ts +++ b/js/net/src/connection/stats.ts @@ -15,7 +15,8 @@ import { Milli } from "@moq/clock"; * Every field is optional. The qmux/WebSocket fallback implements no `getStats()` at * all and reports nothing; see {@link Probe} for what the peer measures. * - * The field names match Rust's `moq_net::session::Stats` but the counters keep each + * The field names match Rust's `moq_net::session::Stats`, except its native-only + * `streams`, which W3C stats cannot report. The counters keep each * stack's own semantics rather than being normalized. Notably W3C excludes * retransmissions and QUIC overhead from the byte counts where native QUIC includes * them, and counts packets where native QUIC counts datagrams.