From 202dc2ccc26200095702f1bbdff5dbc2850f5c5c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 17 Oct 2026 08:17:34 -0700 Subject: [PATCH 1/6] wip: send options for streams and datagrams, private send domains Co-Authored-By: Claude Opus 5.5 --- rs/moq-ffi/src/transport/adapter.rs | 23 ++- rs/moq-net/src/client.rs | 26 +-- rs/moq-net/src/coding/stream.rs | 4 +- rs/moq-net/src/coding/writer.rs | 5 - rs/moq-net/src/ietf/adapter.rs | 22 +- rs/moq-net/src/ietf/publisher.rs | 66 +++--- rs/moq-net/src/ietf/session.rs | 2 +- rs/moq-net/src/ietf/subscriber.rs | 16 +- rs/moq-net/src/lite/publisher.rs | 42 ++-- rs/moq-net/src/lite/session.rs | 2 +- rs/moq-net/src/lite/subscriber.rs | 4 +- rs/moq-net/src/lite/test_transport.rs | 68 +++--- rs/moq-net/src/server.rs | 9 +- rs/moq-net/src/transport.rs | 107 +++++++--- rs/moq-net/src/transport/memory.rs | 24 ++- rs/moq-net/tests/integration/goaway.rs | 2 +- .../tests/integration/subscribe_tracks.rs | 4 +- rs/moq-net/tests/integration/support/mock.rs | 16 +- rs/moq-quic/benches/receive.rs | 6 +- rs/moq-quic/benches/streams.rs | 2 +- rs/moq-quic/benches/wire.rs | 2 +- rs/moq-quic/src/connection/datagrams.rs | 32 ++- rs/moq-quic/src/connection/mod.rs | 2 +- rs/moq-quic/src/connection/streams/mod.rs | 95 +++++++-- .../src/connection/streams/saturated.rs | 27 ++- .../src/connection/streams/schedule.rs | 2 + rs/moq-quic/src/connection/streams/state.rs | 56 ++--- rs/moq-quic/src/fuzz.rs | 2 +- rs/moq-quic/src/fuzz/connection.rs | 18 +- rs/moq-quic/src/lib.rs | 2 +- rs/moq-quic/src/tests/characterize/limits.rs | 6 +- rs/moq-quic/src/tests/characterize/paths.rs | 6 +- rs/moq-quic/src/tests/characterize/reset.rs | 10 +- .../src/tests/characterize/schedule.rs | 8 +- rs/moq-quic/src/tests/mod.rs | 194 ++++++++++-------- rs/moq-quic/src/tests/reset_stream_at.rs | 46 ++--- rs/moq-quic/src/tests/sim.rs | 2 +- rs/moq-relay/tests/integration/peer_limits.rs | 6 +- rs/moq-tokio/src/quic/driver/connection.rs | 57 +++-- rs/moq-tokio/src/quic/driver/mod.rs | 2 +- rs/moq-tokio/src/quic/driver/send_group.rs | 17 +- rs/moq-tokio/src/quic/driver/tests.rs | 36 ++-- rs/moq-tokio/src/quic/web/connect.rs | 2 +- rs/moq-tokio/src/quic/web/session.rs | 81 ++++---- rs/moq-tokio/src/quic/web/settings.rs | 2 +- rs/moq-tokio/src/transport.rs | 17 +- rs/moq-tokio/src/transport/grouped.rs | 9 +- rs/moq-tokio/src/transport/owned.rs | 33 ++- rs/moq-tokio/tests/integration/stream_code.rs | 4 +- rs/moq-uring/benches/echo_quic.rs | 2 +- rs/moq-uring/src/quic/driver/connection.rs | 20 +- rs/moq-uring/src/quic/driver/group.rs | 15 +- rs/moq-uring/src/quic/driver/mod.rs | 2 +- rs/moq-uring/src/quic/mod.rs | 2 +- rs/moq-uring/src/quic/web.rs | 10 +- rs/moq-uring/src/transport.rs | 9 +- rs/moq-uring/src/transport/adapter.rs | 36 ++-- rs/moq-uring/tests/integration/echo.rs | 2 +- rs/moq-uring/tests/integration/web.rs | 12 +- rs/moq-wasm/src/transport/adapter.rs | 23 ++- 60 files changed, 793 insertions(+), 566 deletions(-) diff --git a/rs/moq-ffi/src/transport/adapter.rs b/rs/moq-ffi/src/transport/adapter.rs index 46a2c8ff250..464f5c483ae 100644 --- a/rs/moq-ffi/src/transport/adapter.rs +++ b/rs/moq-ffi/src/transport/adapter.rs @@ -67,22 +67,22 @@ impl + Clone + 'st .map_err(Error) .map(|res| res.map(|(send, recv)| (SendStream(send), RecvStream(recv)))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>) -> Poll> { + fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, poll::Ungrouped>) -> Poll> { backend::Session::poll_open_uni(&mut self.0, cx) .map_err(Error) - .map(|res| res.map(SendStream)) + .map(|res| res.map(|send| SendStream(send).scheduled(options))) } - fn poll_open_bi(&mut self, cx: &mut Context<'_>) -> Poll, Self::Error>> { + fn poll_open_bi(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, poll::Ungrouped>) -> Poll, Self::Error>> { backend::Session::poll_open_bi(&mut self.0, cx) .map_err(Error) - .map(|res| res.map(|(send, recv)| (SendStream(send), RecvStream(recv)))) + .map(|res| res.map(|(send, recv)| (SendStream(send).scheduled(options), RecvStream(recv)))) } fn send_group(&mut self, _: i64) -> Option { None } - /// The backend cannot rank a datagram against a stream, so the group and order are ignored, - /// and a datagram it has no room for is dropped. - fn send_datagram(&mut self, payload: Bytes, _: Option<&poll::Ungrouped>, _: i64) -> Result<(), Self::Error> { + /// The backend cannot rank a datagram against a stream, so `options` are ignored, and a + /// datagram it has no room for is dropped. + fn send_datagram(&mut self, payload: Bytes, _: poll::SendOptions<'_, poll::Ungrouped>) -> Result<(), Self::Error> { let mut cx = Context::from_waker(std::task::Waker::noop()); match backend::Session::poll_send_datagram(&mut self.0, &mut cx, &payload) { Poll::Ready(res) => res.map_err(Error), @@ -113,6 +113,13 @@ impl + Clone + 'st } /// An outgoing WebTransport stream adapted to moq-net. pub struct SendStream(S); +impl SendStream { + /// Schedule a newly opened stream, which has no group to join. + fn scheduled(mut self, options: poll::SendOptions<'_, poll::Ungrouped>) -> Self { + poll::SendStream::set_priority(&mut self, options.priority); + self + } +} impl poll::SendStream for SendStream { type Error = Error; type Group = poll::Ungrouped; @@ -293,7 +300,7 @@ mod tests { poll::Session::stats(&session).rtt(), Some(std::time::Duration::from_millis(7)) ); - let Poll::Ready(Ok((mut send, mut recv))) = poll::Session::poll_open_bi(&mut session, &mut cx) else { + let Poll::Ready(Ok((mut send, mut recv))) = poll::Session::poll_open_bi(&mut session, &mut cx, Default::default()) else { panic!("open failed") }; let mut buf = Bytes::from_static(b"abcd"); diff --git a/rs/moq-net/src/client.rs b/rs/moq-net/src/client.rs index 00e3d42a6d8..f4c6487f44f 100644 --- a/rs/moq-net/src/client.rs +++ b/rs/moq-net/src/client.rs @@ -612,11 +612,12 @@ mod tests { fn poll_open_bi( &mut self, _cx: &mut Context<'_>, + _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>, ) -> Poll> { Poll::Ready(self.state.control_stream.lock().unwrap().take().ok_or(FakeError)) } - fn poll_open_uni(&mut self, _cx: &mut Context<'_>) -> Poll> { + fn poll_open_uni(&mut self, _cx: &mut Context<'_>, _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>) -> Poll> { Poll::Pending } @@ -624,12 +625,7 @@ mod tests { None } - fn send_datagram( - &mut self, - _: Bytes, - _: Option<&crate::transport::poll::Ungrouped>, - _: i64, - ) -> Result<(), Self::Error> { + fn send_datagram(&mut self, _: Bytes, _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>) -> Result<(), Self::Error> { Ok(()) } @@ -998,8 +994,9 @@ mod tests { fn poll_open_bi( &mut self, cx: &mut Context<'_>, + options: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>, ) -> Poll> { - self.inner.poll_open_bi(cx).map_ok(|(send, recv)| { + self.inner.poll_open_bi(cx, options).map_ok(|(send, recv)| { ( LocalSend { inner: send, @@ -1013,8 +1010,8 @@ mod tests { }) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>) -> Poll> { - self.inner.poll_open_uni(cx).map_ok(|stream| LocalSend { + fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>) -> Poll> { + self.inner.poll_open_uni(cx, options).map_ok(|stream| LocalSend { inner: stream, _local: self._local.clone(), }) @@ -1024,13 +1021,8 @@ mod tests { None } - fn send_datagram( - &mut self, - payload: Bytes, - group: Option<&crate::transport::poll::Ungrouped>, - order: i64, - ) -> Result<(), Self::Error> { - self.inner.send_datagram(payload, group, order) + fn send_datagram(&mut self, payload: Bytes, options: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>) -> Result<(), Self::Error> { + self.inner.send_datagram(payload, options) } fn poll_recv_datagram(&mut self, cx: &mut Context<'_>) -> Poll> { diff --git a/rs/moq-net/src/coding/stream.rs b/rs/moq-net/src/coding/stream.rs index 36aa621ca31..1393d773b4d 100644 --- a/rs/moq-net/src/coding/stream.rs +++ b/rs/moq-net/src/coding/stream.rs @@ -31,7 +31,7 @@ impl Stream { where V: Clone, { - let (send, recv) = ready!(session.poll_open_bi(cx)).map_err(|err| version.transport_error(err))?; + let (send, recv) = ready!(session.poll_open_bi(cx, Default::default())).map_err(|err| version.transport_error(err))?; Poll::Ready(Ok(Self::build(send, recv, version))) } @@ -40,7 +40,7 @@ impl Stream { where V: Clone, { - let (send, recv) = session.open_bi().await.map_err(|err| version.transport_error(err))?; + let (send, recv) = session.open_bi(Default::default()).await.map_err(|err| version.transport_error(err))?; Ok(Self::build(send, recv, version)) } diff --git a/rs/moq-net/src/coding/writer.rs b/rs/moq-net/src/coding/writer.rs index 494bd8588ec..31a7f5d9304 100644 --- a/rs/moq-net/src/coding/writer.rs +++ b/rs/moq-net/src/coding/writer.rs @@ -219,11 +219,6 @@ impl Writer { self.stream.as_mut().unwrap().set_priority(priority); } - /// Move the stream into a send group from its session. - pub fn set_group(&mut self, group: &S::Group) { - self.stream.as_mut().unwrap().set_group(group); - } - /// Cast the writer to a different version, used during version negotiation. pub fn with_version(mut self, version: O) -> Writer { Writer { diff --git a/rs/moq-net/src/ietf/adapter.rs b/rs/moq-net/src/ietf/adapter.rs index 7c7bb3959bb..04841eecff2 100644 --- a/rs/moq-net/src/ietf/adapter.rs +++ b/rs/moq-net/src/ietf/adapter.rs @@ -751,7 +751,10 @@ impl ControlStreamAdapter { /// Open a real (non-virtual) bidi stream, bypassing control stream multiplexing. /// Used for v16 SubscribeNamespace which moved to its own bidi stream. pub async fn open_native_bi(&mut self) -> Result<(AdapterSend, AdapterRecv), crate::Error> { - let (send, recv) = self.inner.open_bi().await.map_err(|_| crate::Error::Closed)?; + let (send, recv) = self.inner + .open_bi(Default::default()) + .await + .map_err(|_| crate::Error::Closed)?; Ok((AdapterSend::Real(send), AdapterRecv::Real(recv))) } @@ -1156,14 +1159,16 @@ impl crate::transport::poll::Session for Con fn poll_open_bi( &mut self, _cx: &mut Context<'_>, + // Rides the control stream, which no group schedules. + _: crate::transport::poll::SendOptions<'_, ::Group>, ) -> Poll> { let (send, recv) = self.shared.open_outgoing(self.version); Poll::Ready(Ok((AdapterSend::Virtual(send), AdapterRecv::Virtual(recv)))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>) -> Poll> { + fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: crate::transport::poll::SendOptions<'_, ::Group>) -> Poll> { self.inner - .poll_open_uni(cx) + .poll_open_uni(cx, options) .map(|r| r.map(AdapterSend::Real).map_err(|_| crate::Error::Closed)) } @@ -1177,14 +1182,9 @@ impl crate::transport::poll::Session for Con self.inner.send_group(priority) } - fn send_datagram( - &mut self, - payload: Bytes, - group: Option<&::Group>, - order: i64, - ) -> Result<(), Self::Error> { + fn send_datagram(&mut self, payload: Bytes, options: crate::transport::poll::SendOptions<'_, ::Group>) -> Result<(), Self::Error> { self.inner - .send_datagram(payload, group, order) + .send_datagram(payload, options) .map_err(|_| crate::Error::Closed) } @@ -1877,7 +1877,7 @@ mod tests { } script.extend_from_slice(then); let mut session = ScriptedSession::new(script); - let (_, recv) = session.open_bi().await.unwrap(); + let (_, recv) = session.open_bi(Default::default()).await.unwrap(); // We are the server, so the client's request IDs are even. let control = Control::new(None, false).with_window(window, false, VERSION); let adapter = ControlStreamAdapter::new(session, control, VERSION); diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index f86cfcb4e6e..cd929e2668d 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -11,7 +11,7 @@ use std::{ time::Duration, }; -use crate::transport::poll::GroupOf; +use crate::transport::poll::{GroupOf, SendOptions}; use crate::transport::poll::SendGroup as _; use crate::{ @@ -1756,8 +1756,10 @@ where FillServe::Unsupported => None, }; + let mut rank = rank; + let options = rank.as_mut().map(Rank::options).unwrap_or_default(); let mut session = self.session.clone(); - let stream = match session.open_uni().await { + let stream = match session.open_uni(options).await { Ok(stream) => stream, Err(err) => { tracing::debug!(err = %Error::from_transport(err), fill = %request_id, "fill stream failed to open"); @@ -2439,8 +2441,13 @@ where }) .await?; - let uni = self.session.open_uni().await.map_err(Error::from_transport)?; - let mut writer = Writer::new(Ranked::new(uni, Some(ranking.rank(start))), self.version); + let mut rank = ranking.rank(start); + let uni = self + .session + .open_uni(rank.options()) + .await + .map_err(Error::from_transport)?; + let mut writer = Writer::new(Ranked::new(uni, Some(rank)), self.version); writer.varint(FetchHeader::TYPE).await?; writer .encode(&FetchHeader { @@ -4044,17 +4051,16 @@ impl TrackServe { /// Send the original terminal on a separate stream when its group already sent FIN, /// ranked as the group it ends. async fn write_end_of_track(&mut self, end: track::Position) -> Result<(), Error> { - let stream = std::future::poll_fn(|cx| self.session.poll_open_uni(cx)) + let mut rank = self.ranking.rank(Location { + group: end.group, + object: end.frame, + }); + let options = rank.options(); + let stream = std::future::poll_fn(|cx| self.session.poll_open_uni(cx, options)) .await .map_err(Error::from_transport)?; self.opened.fetch_add(1, Ordering::Relaxed); - let stream = Ranked::new( - stream, - Some(self.ranking.rank(Location { - group: end.group, - object: end.frame, - })), - ); + let stream = Ranked::new(stream, Some(rank)); let mut writer = Writer::new(stream, self.version); writer.buffer(&ietf::GroupHeader { track_alias: self.request_id.0, @@ -4278,8 +4284,11 @@ impl TrackServe { } // Ranked like a stream carrying the group from its start, so it merges into the // subscription's group order and wins a tie with that group's stream. - let order = crate::priority::in_group(sequence, 0, self.ranking.order); - let _ = self.session.send_datagram(body, self.ranking.group.as_ref(), order); + let options = SendOptions { + group: self.ranking.group.as_ref(), + priority: crate::priority::in_group(sequence, 0, self.ranking.order), + }; + let _ = self.session.send_datagram(body, options); } Ok(()) } @@ -4335,10 +4344,8 @@ struct Ranked { } impl Ranked { - fn new(mut stream: T, mut rank: Option>) -> Self { - if let Some(rank) = &mut rank { - rank.place(&mut stream); - } + /// Wrap a stream opened with its rank's [options](Rank::options). + fn new(stream: T, rank: Option>) -> Self { Self { stream, rank, @@ -4422,14 +4429,17 @@ impl Rank { Self::Queue(Queued::solo(priority)) } - /// Put a newly opened stream in its place. - fn place>(&mut self, stream: &mut T) { + /// Where a newly opened stream goes. + fn options(&mut self) -> SendOptions<'_, G> { match self { - Self::Group { group, order } => { - stream.set_group(group); - stream.set_priority(*order); - } - Self::Queue(queued) => stream.set_priority(queued.handle.send_order().into()), + Self::Group { group, order } => SendOptions { + group: Some(&*group), + priority: *order, + }, + Self::Queue(queued) => SendOptions { + group: None, + priority: queued.handle.send_order().into(), + }, } } @@ -4596,7 +4606,8 @@ impl GroupServe { self.state = GroupState::Done; return Poll::Ready(Err(Error::Old)); } - let stream = match ready!(self.session.poll_open_uni(&mut cx)) { + // The current rank, which already includes anything `moved` saw. + let stream = match ready!(self.session.poll_open_uni(&mut cx, self.rank.options())) { Ok(stream) => stream, Err(err) => { self.state = GroupState::Done; @@ -4604,9 +4615,6 @@ impl GroupServe { } }; self.opened.fetch_add(1, Ordering::Relaxed); - let mut stream = stream; - // The current rank, which already includes anything `moved` saw. - self.rank.place(&mut stream); moved = None; let mut writer = Writer::new(stream, self.version); diff --git a/rs/moq-net/src/ietf/session.rs b/rs/moq-net/src/ietf/session.rs index c04e850beef..b590e184d9e 100644 --- a/rs/moq-net/src/ietf/session.rs +++ b/rs/moq-net/src/ietf/session.rs @@ -783,7 +783,7 @@ async fn run_setup( ) -> Result<(), Error> { let outer_version = crate::Version::Ietf(version); - let send = session.open_uni().await.map_err(Error::from_transport)?; + let send = session.open_uni(Default::default()).await.map_err(Error::from_transport)?; let mut writer: Writer = Writer::new(send, outer_version); let mut parameters = ietf::Parameters::default(); diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index d237a236743..e89499406fe 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -5395,7 +5395,7 @@ mod tests { use crate::lite::test_transport::ScriptedSession; use crate::transport::poll::Session as _; let mut session = ScriptedSession::eof(responses); - let (_, recv) = session.open_bi().await.unwrap(); + let (_, recv) = session.open_bi(Default::default()).await.unwrap(); let mut reader = Reader::new(recv, Version::Draft19); let result = Subscriber::::read_publish_done(&mut reader, Version::Draft19, &AtomicU64::new(0)).await; @@ -5427,7 +5427,7 @@ mod tests { .unwrap(); let mut session = ScriptedSession::new(wire); - let (_, recv) = session.open_bi().await.unwrap(); + let (_, recv) = session.open_bi(Default::default()).await.unwrap(); let mut reader = Reader::new(recv, VERSION); let result = decode_fetch_object(&mut reader, VERSION, true) .now_or_never() @@ -10864,7 +10864,7 @@ mod stitch_tests { session: &ScriptedSession, ) -> Reader<::RecvStream, Version> { let mut session = session.clone(); - let (_, recv) = session.open_bi().await.unwrap(); + let (_, recv) = session.open_bi(Default::default()).await.unwrap(); Reader::new(recv, Version::Draft18) } @@ -10976,7 +10976,7 @@ mod stitch_tests { /// A reader over the next scripted stream, standing in for one the peer opened. async fn stream(&self) -> Reader<::RecvStream, Version> { let mut session = self.session.clone(); - let (_, recv) = session.open_bi().await.unwrap(); + let (_, recv) = session.open_bi(Default::default()).await.unwrap(); Reader::new(recv, VERSION) } } @@ -13210,7 +13210,7 @@ mod stitch_tests { tasks.0.clone(), Default::default(), ); - let (_, recv) = session.open_bi().await.unwrap(); + let (_, recv) = session.open_bi(Default::default()).await.unwrap(); let track = track::Producer::new( std::sync::Arc::new(crate::broadcast::Info::default()), "video", @@ -13759,7 +13759,7 @@ mod joining_fetch_tests { } w.bytes(b"x").unwrap(); let data = ScriptedSession::new(objects); - let (_, recv) = data.clone().open_bi().await.unwrap(); + let (_, recv) = data.clone().open_bi(Default::default()).await.unwrap(); let mut reader = Reader::new(recv, version); let mut receiving = run.subscriber.clone(); let mut fill = Box::pin(receiving.recv_fill(&mut reader)); @@ -13913,7 +13913,7 @@ mod joining_fetch_tests { .unwrap(); objects.push(b'x'); let data = ScriptedSession::new(objects); - let (_, recv) = data.clone().open_bi().await.unwrap(); + let (_, recv) = data.clone().open_bi(Default::default()).await.unwrap(); let mut reader = Reader::new(recv, version); let mut receiving = subscriber.clone(); let mut fill = Box::pin(receiving.recv_group_fetch(&mut reader, slot.clone())); @@ -14261,7 +14261,7 @@ mod joining_fetch_tests { settle().await; // The fetch stream, as the peer would open it. - let (_, recv) = session.clone().open_bi().await.unwrap(); + let (_, recv) = session.clone().open_bi(Default::default()).await.unwrap(); let mut stream = Reader::new(recv, version); subscriber.clone().recv_fill(&mut stream).await.expect("group fetch"); serving.await.expect("run_group_fetch"); diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 292d49d18c8..15748db6cdb 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -17,7 +17,7 @@ use crate::{ lite, priority::{Priority, PriorityHandle, PriorityQueue}, track::Order, - transport::poll::{GroupOf, SendGroup as _}, + transport::poll::{GroupOf, SendGroup as _, SendOptions}, }; use super::Version; @@ -3230,8 +3230,12 @@ impl Subscription { } // The run loop may not have served a group since the last SUBSCRIBE_UPDATE. - let order = crate::priority::in_group(datagram.sequence, 0, self.steer_current().order); - let _ = self.session.send_datagram(body, self.group.as_ref(), order); + let priority = crate::priority::in_group(datagram.sequence, 0, self.steer_current().order); + let options = SendOptions { + group: self.group.as_ref(), + priority, + }; + let _ = self.session.send_datagram(body, options); true } @@ -3832,7 +3836,17 @@ impl GroupServe { return Poll::Ready(Err(Error::Old)); } let mut cx = waiter.context(); - let stream = match ready!(self.ctx.session.poll_open_uni(&mut cx)) { + let options = match &mut self.rank { + Rank::Group(group) => SendOptions { + group: Some(&*group), + priority: crate::priority::in_group(self.sequence, self.frame_start, self.ctx.steer_seen.order), + }, + Rank::Queue(handle) => SendOptions { + group: None, + priority: handle.send_order().into(), + }, + }; + let stream = match ready!(self.ctx.session.poll_open_uni(&mut cx, options)) { Ok(stream) => stream, Err(err) => { self.settle_open(false); @@ -3842,14 +3856,6 @@ impl GroupServe { }; self.settle_open(true); let mut writer = Writer::new(stream, self.ctx.version); - match &mut self.rank { - Rank::Group(group) => { - writer.set_group(group); - let order = self.ctx.steer_seen.order; - writer.set_priority(crate::priority::in_group(self.sequence, self.frame_start, order)); - } - Rank::Queue(handle) => writer.set_priority(handle.send_order().into()), - } let msg = lite::Group { subscribe: self.ctx.id, @@ -6180,7 +6186,7 @@ mod tests { .unwrap(); let mut session = ScriptedSession::new(script); let (send, recv) = futures::future::poll_fn(|cx| { - ::poll_open_bi(&mut session, cx) + ::poll_open_bi(&mut session, cx, Default::default()) }) .await .unwrap(); @@ -6319,7 +6325,7 @@ mod tests { .unwrap(); let mut session = ScriptedSession::new(script); let (_, recv) = futures::future::poll_fn(|cx| { - ::poll_open_bi(&mut session, cx) + ::poll_open_bi(&mut session, cx, Default::default()) }) .await .unwrap(); @@ -6408,7 +6414,7 @@ mod tests { .unwrap(); let mut session = ScriptedSession::new(script); let (send, recv) = futures::future::poll_fn(|cx| { - ::poll_open_bi(&mut session, cx) + ::poll_open_bi(&mut session, cx, Default::default()) }) .await .unwrap(); @@ -6501,7 +6507,7 @@ mod tests { .unwrap(); let mut session = ScriptedSession::new(script); let (send, recv) = futures::future::poll_fn(|cx| { - ::poll_open_bi(&mut session, cx) + ::poll_open_bi(&mut session, cx, Default::default()) }) .await .unwrap(); @@ -6694,7 +6700,7 @@ mod tests { .unwrap(); let mut session = ScriptedSession::new(script); let (send, recv) = futures::future::poll_fn(|cx| { - ::poll_open_bi(&mut session, cx) + ::poll_open_bi(&mut session, cx, Default::default()) }) .await .unwrap(); @@ -6764,7 +6770,7 @@ mod tests { for count in 0..3 { let mut session = ScriptedSession::new(script.clone()); let (send, recv) = futures::future::poll_fn(|cx| { - ::poll_open_bi(&mut session, cx) + ::poll_open_bi(&mut session, cx, Default::default()) }) .await .unwrap(); diff --git a/rs/moq-net/src/lite/session.rs b/rs/moq-net/src/lite/session.rs index 756871b1ac5..9395fa2db90 100644 --- a/rs/moq-net/src/lite/session.rs +++ b/rs/moq-net/src/lite/session.rs @@ -714,7 +714,7 @@ impl SendSetup { loop { match &mut self.state { SendSetupState::Open { session, setup } => { - let stream = ready!(session.poll_open_uni(cx)).map_err(crate::lite::error::from_transport)?; + let stream = ready!(session.poll_open_uni(cx, Default::default())).map_err(crate::lite::error::from_transport)?; let mut writer = Writer::new(stream, self.version); writer.buffer(&super::DataType::Setup)?; writer.buffer(&**setup)?; diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 5f59f20715d..d68c75491fa 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -2202,7 +2202,7 @@ mod tests { }, ); - let (_, recv) = session.open_bi().await.unwrap(); + let (_, recv) = session.open_bi(Default::default()).await.unwrap(); let mut group = GroupRecv::new(subscriber, Reader::new(recv, version)); let res = kio::wait(|waiter| group.poll_serve(waiter)).await; match version { @@ -2270,7 +2270,7 @@ mod tests { }, ); - let (_, recv) = session.open_bi().await.unwrap(); + let (_, recv) = session.open_bi(Default::default()).await.unwrap(); let mut group = GroupRecv::new(subscriber, Reader::new(recv, version)); let res = kio::wait(|waiter| group.poll_serve(waiter)).await; assert!(matches!(res, Err(Error::Duplicate)), "{res:?}"); diff --git a/rs/moq-net/src/lite/test_transport.rs b/rs/moq-net/src/lite/test_transport.rs index 967f72e621a..6fe3091d183 100644 --- a/rs/moq-net/src/lite/test_transport.rs +++ b/rs/moq-net/src/lite/test_transport.rs @@ -135,12 +135,12 @@ impl Log { self.datagram_ranks.lock().unwrap().clone() } - fn record_datagram(&self, payload: bytes::Bytes, group: Option<&SinkGroup>, order: i64) { + fn record_datagram(&self, payload: bytes::Bytes, options: poll::SendOptions<'_, SinkGroup>) { self.datagrams.lock().unwrap().push(payload); self.datagram_ranks .lock() .unwrap() - .push((group.map(|group| group.id), order)); + .push((options.group.map(|group| group.id), options.priority)); } /// The session-level closes, as (code, reason). A list rather than a last-value so @@ -217,6 +217,19 @@ impl poll::SendGroup for SinkGroup { } impl SinkSend { + /// Schedule a stream as it opens, logging only what differs from a fresh stream's + /// ungrouped priority 0, as the setters would. + fn opened(mut self, options: poll::SendOptions<'_, SinkGroup>) -> Self { + use poll::SendStream as _; + if let Some(group) = options.group { + self.set_group(group); + } + if options.group.is_some() || options.priority != 0 { + self.set_priority(options.priority); + } + self + } + pub fn new(log: Log) -> Self { Self { prefix: 0, @@ -445,26 +458,21 @@ impl poll::Session for DeadStreamSession { } } - fn poll_open_bi(&mut self, _cx: &mut Context<'_>) -> Poll, Self::Error>> { + fn poll_open_bi(&mut self, _cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll, Self::Error>> { self.log.bi_opens.fetch_add(1, Ordering::Relaxed); - Poll::Ready(Ok((SinkSend::new(self.log.clone()), DeadRecv(self.reset)))) + Poll::Ready(Ok((SinkSend::new(self.log.clone()).opened(options), DeadRecv(self.reset)))) } - fn poll_open_uni(&mut self, _cx: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(SinkSend::new(self.log.clone()))) + fn poll_open_uni(&mut self, _cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll> { + Poll::Ready(Ok(SinkSend::new(self.log.clone()).opened(options))) } fn send_group(&mut self, _: i64) -> Option { None } - fn send_datagram( - &mut self, - payload: bytes::Bytes, - group: Option<&SinkGroup>, - order: i64, - ) -> Result<(), Self::Error> { - self.log.record_datagram(payload, group, order); + fn send_datagram(&mut self, payload: bytes::Bytes, options: poll::SendOptions<'_, SinkGroup>) -> Result<(), Self::Error> { + self.log.record_datagram(payload, options); Ok(()) } @@ -641,18 +649,18 @@ impl poll::Session for SinkSession { Poll::Ready(Ok((send, PendingRecv))) } - fn poll_open_bi(&mut self, _cx: &mut Context<'_>) -> Poll, Self::Error>> { + fn poll_open_bi(&mut self, _cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll, Self::Error>> { let Some(gate) = self.bi_gate.clone() else { return Poll::Pending; }; self.log.bi_opens.fetch_add(1, Ordering::Relaxed); - let mut send = SinkSend::gated(self.log.clone(), gate); + let mut send = SinkSend::gated(self.log.clone(), gate).opened(options); send.prefix = self.bi_prefix; Poll::Ready(Ok((send, PendingRecv))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>) -> Poll> { + fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll> { if let Some(gate) = &self.uni_open_gate { let waiter = self.uni_open_park.hold(cx); match gate.poll(waiter, |open| (**open).then_some(()).map_or(Poll::Pending, Poll::Ready)) { @@ -665,20 +673,15 @@ impl poll::Session for SinkSession { None => SinkSend::new(self.log.clone()), }; send.unacked_fin = self.unacked_fin; - Poll::Ready(Ok(send)) + Poll::Ready(Ok(send.opened(options))) } fn send_group(&mut self, priority: i64) -> Option { self.groups.then(|| SinkGroup::open(self.log.clone(), priority)) } - fn send_datagram( - &mut self, - payload: bytes::Bytes, - group: Option<&SinkGroup>, - order: i64, - ) -> Result<(), Self::Error> { - self.log.record_datagram(payload, group, order); + fn send_datagram(&mut self, payload: bytes::Bytes, options: poll::SendOptions<'_, SinkGroup>) -> Result<(), Self::Error> { + self.log.record_datagram(payload, options); Ok(()) } @@ -965,7 +968,7 @@ impl poll::Session for ScriptedSession { ))) } - fn poll_open_bi(&mut self, cx: &mut Context<'_>) -> Poll, Self::Error>> { + fn poll_open_bi(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll, Self::Error>> { if let Some(gate) = self.open_gate.clone() { let waiter = self.park.hold(cx); // A closed gate reads as open: the test dropped the producer, so nothing is @@ -983,7 +986,7 @@ impl poll::Session for ScriptedSession { Some(queue) => Arc::new(Mutex::new(queue.lock().unwrap().pop_front().unwrap_or_default())), None => self.script.clone(), }; - let mut send = SinkSend::new(self.log.clone()); + let mut send = SinkSend::new(self.log.clone()).opened(options); send.unacked_fin = self.unacked_fin; Poll::Ready(Ok(( send, @@ -995,21 +998,16 @@ impl poll::Session for ScriptedSession { ))) } - fn poll_open_uni(&mut self, _cx: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(SinkSend::new(self.log.clone()))) + fn poll_open_uni(&mut self, _cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll> { + Poll::Ready(Ok(SinkSend::new(self.log.clone()).opened(options))) } fn send_group(&mut self, _: i64) -> Option { None } - fn send_datagram( - &mut self, - payload: bytes::Bytes, - group: Option<&SinkGroup>, - order: i64, - ) -> Result<(), Self::Error> { - self.log.record_datagram(payload, group, order); + fn send_datagram(&mut self, payload: bytes::Bytes, options: poll::SendOptions<'_, SinkGroup>) -> Result<(), Self::Error> { + self.log.record_datagram(payload, options); Ok(()) } diff --git a/rs/moq-net/src/server.rs b/rs/moq-net/src/server.rs index 50fe8bf01e1..9401827dec0 100644 --- a/rs/moq-net/src/server.rs +++ b/rs/moq-net/src/server.rs @@ -1060,12 +1060,14 @@ mod tests { fn poll_open_bi( &mut self, _cx: &mut std::task::Context<'_>, + _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>, ) -> std::task::Poll> { std::task::Poll::Pending } fn poll_open_uni( &mut self, _cx: &mut std::task::Context<'_>, + _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>, ) -> std::task::Poll> { std::task::Poll::Pending } @@ -1073,12 +1075,7 @@ mod tests { None } - fn send_datagram( - &mut self, - _: Bytes, - _: Option<&crate::transport::poll::Ungrouped>, - _: i64, - ) -> Result<(), Self::Error> { + fn send_datagram(&mut self, _: Bytes, _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>) -> Result<(), Self::Error> { Ok(()) } fn poll_recv_datagram( diff --git a/rs/moq-net/src/transport.rs b/rs/moq-net/src/transport.rs index 8cf1ce6f551..f327e458e54 100644 --- a/rs/moq-net/src/transport.rs +++ b/rs/moq-net/src/transport.rs @@ -163,30 +163,39 @@ pub mod poll { /// Poll for a bidirectional stream created by the peer. fn poll_accept_bi(&mut self, cx: &mut Context<'_>) -> Poll, Self::Error>>; - /// Poll to open a unidirectional stream, which blocks while there are too many - /// concurrent streams. - fn poll_open_uni(&mut self, cx: &mut Context<'_>) -> Poll>; + /// Poll to open a unidirectional stream scheduled by `options`, which blocks while + /// there are too many concurrent streams. + fn poll_open_uni( + &mut self, + cx: &mut Context<'_>, + options: SendOptions<'_, ::Group>, + ) -> Poll>; - /// Poll to open a bidirectional stream, which blocks while there are too many - /// concurrent streams. - fn poll_open_bi(&mut self, cx: &mut Context<'_>) -> Poll, Self::Error>>; + /// Poll to open a bidirectional stream, its sending half scheduled by `options`, which + /// blocks while there are too many concurrent streams. + fn poll_open_bi( + &mut self, + cx: &mut Context<'_>, + options: SendOptions<'_, ::Group>, + ) -> Poll, Self::Error>>; /// Open a send group at `priority`, or `None` when the transport orders streams by /// their own priority alone. /// - /// Streams that [join](SendStream::set_group) a group share bytes with the session's + /// Streams that join a group, through [`SendOptions`] or [`SendStream::set_group`], and + /// datagrams sent in it share bytes with the session's /// other groups: a higher priority group preempts every lower one, and groups of equal /// priority get an equal share of bytes however many streams each has queued. Streams /// outside every group go before all of them. The group is released once its last /// handle is dropped and its streams finish. fn send_group(&mut self, priority: i64) -> Option<::Group>; - /// Send a datagram in `group` at `order`, best-effort. + /// Send a datagram scheduled by `options`, best-effort. /// - /// `order` ranks the datagram among the group's streams like a stream's own - /// [priority](SendStream::set_priority), and a datagram goes ahead of a stream of equal - /// order. Without a group it is ranked among the ungrouped streams. A transport that - /// cannot rank datagrams against streams ignores both. + /// The datagram is ranked among its group's streams by its priority, like a stream's + /// own [priority](SendStream::set_priority), and goes ahead of a stream of equal + /// priority. Without a group it is ranked among the ungrouped streams. A transport that + /// cannot rank datagrams against streams ignores `options`. /// /// Never blocks: a transport with no room drops a queued datagram, the lowest priority /// first where it can tell, exactly as the network is allowed to. @@ -199,8 +208,7 @@ pub mod poll { fn send_datagram( &mut self, payload: Bytes, - group: Option<&::Group>, - order: i64, + options: SendOptions<'_, ::Group>, ) -> Result<(), Self::Error>; /// Poll for a datagram from the network. @@ -247,14 +255,16 @@ pub mod poll { AcceptBi(self) } - /// Open a unidirectional stream, waiting for stream credit if necessary. - fn open_uni(&mut self) -> OpenUni<'_, Self> { - OpenUni(self) + /// Open a unidirectional stream scheduled by `options`, waiting for stream credit if + /// necessary. + fn open_uni<'a>(&'a mut self, options: SendOptions<'a, ::Group>) -> OpenUni<'a, Self> { + OpenUni { session: self, options } } - /// Open a bidirectional stream, waiting for stream credit if necessary. - fn open_bi(&mut self) -> OpenBi<'_, Self> { - OpenBi(self) + /// Open a bidirectional stream, its sending half scheduled by `options`, waiting for + /// stream credit if necessary. + fn open_bi<'a>(&'a mut self, options: SendOptions<'a, ::Group>) -> OpenBi<'a, Self> { + OpenBi { session: self, options } } /// Receive the next datagram from the peer. @@ -292,12 +302,32 @@ pub mod poll { poll_future!( /// A pending [`Session::accept_bi`]. AcceptBi, Session, poll_accept_bi, Result, S::Error>); - poll_future!( + /// One in-flight open, which polls with the same options until it resolves. + macro_rules! open_future { + ($(#[$doc:meta])* $name:ident, $poll:ident, $out:ty) => { + $(#[$doc])* + pub struct $name<'a, S: Session> { + session: &'a mut S, + options: SendOptions<'a, ::Group>, + } + + impl Future for $name<'_, S> { + type Output = $out; + + fn poll(self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + let this = self.get_mut(); + this.session.$poll(cx, this.options) + } + } + }; + } + + open_future!( /// A pending [`Session::open_uni`]. - OpenUni, Session, poll_open_uni, Result); - poll_future!( + OpenUni, poll_open_uni, Result); + open_future!( /// A pending [`Session::open_bi`]. - OpenBi, Session, poll_open_bi, Result, S::Error>); + OpenBi, poll_open_bi, Result, S::Error>); poll_future!( /// A pending [`Session::recv_datagram`]. RecvDatagram, Session, poll_recv_datagram, Result); @@ -338,6 +368,35 @@ pub mod poll { #[cfg(feature = "async")] pub(crate) type GroupOf = <::SendStream as SendStream>::Group; + /// How an outgoing stream or datagram is scheduled, like W3C WebTransport's send options. + /// + /// The default is ungrouped at priority 0. + #[derive(Debug)] + pub struct SendOptions<'a, G> { + /// The send group to join, from [`Session::send_group`], or `None` for the ungrouped + /// streams that go before every group. + pub group: Option<&'a G>, + /// The priority within the group, like [`SendStream::set_priority`]: higher goes first. + pub priority: i64, + } + + impl Default for SendOptions<'_, G> { + fn default() -> Self { + Self { + group: None, + priority: 0, + } + } + } + + impl Clone for SendOptions<'_, G> { + fn clone(&self) -> Self { + *self + } + } + + impl Copy for SendOptions<'_, G> {} + /// A transport's send group, from [`Session::send_group`]. /// /// Clones share the group. diff --git a/rs/moq-net/src/transport/memory.rs b/rs/moq-net/src/transport/memory.rs index e1713331c47..d4c8a305f07 100644 --- a/rs/moq-net/src/transport/memory.rs +++ b/rs/moq-net/src/transport/memory.rs @@ -282,12 +282,16 @@ impl poll::Session for Session { Self::poll_accept(&self.side.incoming().bi, &self.side.conn.close, waiter) } - fn poll_open_uni(&mut self, _cx: &mut Context<'_>) -> Poll> { + fn poll_open_uni(&mut self, _cx: &mut Context<'_>, _: poll::SendOptions<'_, poll::Ungrouped>) -> Poll> { let (send, recv) = self.conn().stream(); Poll::Ready(self.open(&self.side.outgoing().uni, recv).map(|()| send)) } - fn poll_open_bi(&mut self, _cx: &mut Context<'_>) -> Poll> { + fn poll_open_bi( + &mut self, + _cx: &mut Context<'_>, + _: poll::SendOptions<'_, poll::Ungrouped>, + ) -> Poll> { let (send, peer_recv) = self.conn().stream(); let (peer_send, recv) = self.conn().stream(); let opened = self.open(&self.side.outgoing().bi, (peer_send, peer_recv)); @@ -298,7 +302,7 @@ impl poll::Session for Session { None } - fn send_datagram(&mut self, payload: Bytes, _: Option<&poll::Ungrouped>, _: i64) -> Result<(), Error> { + fn send_datagram(&mut self, payload: Bytes, _: poll::SendOptions<'_, poll::Ungrouped>) -> Result<(), Error> { if let Some(err) = closed(&self.conn().close) { return Err(err); } @@ -638,7 +642,7 @@ mod tests { } fn uni(a: &mut Session, b: &mut Session) -> (SendStream, RecvStream) { - let send = ready(a.poll_open_uni(&mut noop())).unwrap(); + let send = ready(a.poll_open_uni(&mut noop(), Default::default())).unwrap(); let recv = ready(b.poll_accept_uni(&mut noop())).unwrap(); (send, recv) } @@ -814,7 +818,7 @@ mod tests { #[test] fn bidi_streams_pair_up() { let (mut a, mut b) = pair(Config::default()); - let (mut a_send, mut a_recv) = ready(a.poll_open_bi(&mut noop())).unwrap(); + let (mut a_send, mut a_recv) = ready(a.poll_open_bi(&mut noop(), Default::default())).unwrap(); let (mut b_send, mut b_recv) = ready(b.poll_accept_bi(&mut noop())).unwrap(); ready(write(&mut a_send, &Bytes::from_static(b"ping"))).unwrap(); @@ -832,7 +836,7 @@ mod tests { assert_eq!(b.protocol(), Some("moq")); let (mut send, mut recv) = uni(&mut a, &mut b); let (mut unfinished, mut unfinished_recv) = uni(&mut a, &mut b); - let late = ready(a.poll_open_uni(&mut noop())).unwrap(); + let late = ready(a.poll_open_uni(&mut noop(), Default::default())).unwrap(); ready(write(&mut send, &Bytes::from_static(b"last"))).unwrap(); send.finish().unwrap(); @@ -842,7 +846,7 @@ mod tests { a.close(4, "bye"); let closed = |err: Error| matches!(err, Error::Session { code: 4, ref reason } if reason == "bye"); assert!(closed(ready(b.poll_closed(&mut noop())))); - assert!(closed(ready(a.poll_open_uni(&mut noop())).err().unwrap())); + assert!(closed(ready(a.poll_open_uni(&mut noop(), Default::default())).err().unwrap())); assert!(closed( ready(write(&mut unfinished, &Bytes::from_static(b"x"))).unwrap_err() )); @@ -877,12 +881,12 @@ mod tests { #[test] fn datagrams() { let (mut a, mut b) = pair(Config::default()); - a.send_datagram(vec![0; MAX_DATAGRAM_SIZE + 1].into(), None, 0).unwrap(); + a.send_datagram(vec![0; MAX_DATAGRAM_SIZE + 1].into(), Default::default()).unwrap(); for _ in 0..DATAGRAM_QUEUE { - a.send_datagram("one".into(), None, 0).unwrap(); + a.send_datagram("one".into(), Default::default()).unwrap(); } // The peer's queue is full, so this one is lost, like the oversized one. - a.send_datagram("two".into(), None, 0).unwrap(); + a.send_datagram("two".into(), Default::default()).unwrap(); for _ in 0..DATAGRAM_QUEUE { assert_eq!(ready(b.poll_recv_datagram(&mut noop())).unwrap(), "one"); } diff --git a/rs/moq-net/tests/integration/goaway.rs b/rs/moq-net/tests/integration/goaway.rs index 55a8de23031..2c44d82b153 100644 --- a/rs/moq-net/tests/integration/goaway.rs +++ b/rs/moq-net/tests/integration/goaway.rs @@ -257,7 +257,7 @@ async fn duplicate_goaway_keeps_first_payload_moq_lite_04() { let mut frame = vec![0x05u8, uri.len() as u8 + 1, uri.len() as u8]; frame.extend_from_slice(uri.as_bytes()); - let (mut send, recv) = session.open_bi().await.map_err(|e| e.to_string()).expect("open_bi"); + let (mut send, recv) = session.open_bi(Default::default()).await.map_err(|e| e.to_string()).expect("open_bi"); let n = send.write(&frame).await.map_err(|e| e.to_string()).expect("write"); assert_eq!(n, frame.len()); send.finish().map_err(|e| e.to_string()).expect("finish"); diff --git a/rs/moq-net/tests/integration/subscribe_tracks.rs b/rs/moq-net/tests/integration/subscribe_tracks.rs index 64e0a247fbc..81b13296528 100644 --- a/rs/moq-net/tests/integration/subscribe_tracks.rs +++ b/rs/moq-net/tests/integration/subscribe_tracks.rs @@ -106,7 +106,7 @@ async fn deliver(setup: &mut Setup, payload: &'static [u8]) { /// Send SUBSCRIBE_TRACKS from the server to the publishing client, returning every byte /// of the reply once the client ends the stream. async fn subscribe_tracks(pair: &MockPair) -> Vec { - let (mut send, mut recv) = pair.server_transport.clone().open_bi().await.expect("open_bi"); + let (mut send, mut recv) = pair.server_transport.clone().open_bi(Default::default()).await.expect("open_bi"); send.write(SUBSCRIBE_TRACKS).await.expect("write"); let mut reply = Vec::new(); @@ -148,7 +148,7 @@ async fn subscribe_tracks_is_refused_per_request() { #[moq_clock::test] async fn subscribe_tracks_before_draft_18_closes_the_session() { let setup = setup("moq-transport-17".parse().unwrap()).await; - let (mut send, _recv) = setup.pair.server_transport.clone().open_bi().await.expect("open_bi"); + let (mut send, _recv) = setup.pair.server_transport.clone().open_bi(Default::default()).await.expect("open_bi"); send.write(SUBSCRIBE_TRACKS).await.expect("write"); moq_clock::timeout(TIMEOUT, setup.pair.client.closed()) diff --git a/rs/moq-net/tests/integration/support/mock.rs b/rs/moq-net/tests/integration/support/mock.rs index 2301a706073..b8cb62db6fb 100644 --- a/rs/moq-net/tests/integration/support/mock.rs +++ b/rs/moq-net/tests/integration/support/mock.rs @@ -553,10 +553,11 @@ impl poll::Session for MockSession { fn poll_open_bi( &mut self, cx: &mut Context<'_>, + options: poll::SendOptions<'_, poll::Ungrouped>, ) -> Poll> { let link = &self.side.out; let mut lines = link.bi.lock().unwrap(); - let (send, recv) = ready!(self.inner.poll_open_bi(cx))?; + let (send, recv) = ready!(self.inner.poll_open_bi(cx, options))?; let held = link.held_bi.lock().unwrap().is_some(); let forward = Arc::new(Line { held, @@ -575,14 +576,14 @@ impl poll::Session for MockSession { Poll::Ready(Ok((send, self.recv(recv, back)))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>) -> Poll> { + fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, poll::Ungrouped>) -> Poll> { if self.side.withheld.load(Ordering::Relaxed) { return Poll::Ready(Err(ready!(self.closer.poll_closed(cx)))); } let link = &self.side.out; let mut lines = link.uni.lock().unwrap(); - let send = ready!(self.inner.poll_open_uni(cx))?; + let send = ready!(self.inner.poll_open_uni(cx, options))?; let line = Arc::new(Line { held: link.held_uni.lock().unwrap().is_some(), split: link.split.lock().unwrap().clone(), @@ -600,16 +601,11 @@ impl poll::Session for MockSession { None } - fn send_datagram( - &mut self, - payload: Bytes, - group: Option<&poll::Ungrouped>, - order: i64, - ) -> Result<(), Self::Error> { + fn send_datagram(&mut self, payload: Bytes, options: poll::SendOptions<'_, poll::Ungrouped>) -> Result<(), Self::Error> { if self.side.lossy.load(Ordering::Relaxed) { return Ok(()); } - self.inner.send_datagram(payload, group, order) + self.inner.send_datagram(payload, options) } fn poll_recv_datagram(&mut self, cx: &mut Context<'_>) -> Poll> { diff --git a/rs/moq-quic/benches/receive.rs b/rs/moq-quic/benches/receive.rs index 1cb84fc1a42..7824992f7ef 100644 --- a/rs/moq-quic/benches/receive.rs +++ b/rs/moq-quic/benches/receive.rs @@ -39,7 +39,7 @@ fn bench_loss(c: &mut Criterion) { let target = pair.server.received.finished + streams as u64; let conn = pair.client(); for _ in 0..streams { - let id = conn.streams().open(Dir::Uni).expect("stream limit"); + let id = conn.streams().open(Dir::Uni, Default::default()).expect("stream limit"); let mut stream = conn.send_stream(id); assert_eq!(stream.write(&data).unwrap(), data.len()); stream.finish().unwrap(); @@ -75,7 +75,7 @@ fn bench_reset(c: &mut Criterion) { let conn = pair.client(); let ids: Vec<_> = (0..streams) .map(|_| { - let id = conn.streams().open(Dir::Uni).expect("stream limit"); + let id = conn.streams().open(Dir::Uni, Default::default()).expect("stream limit"); assert_eq!(conn.send_stream(id).write(&data).unwrap(), bytes); id }) @@ -116,7 +116,7 @@ fn bench_stop(c: &mut Criterion) { let target = pair.server.received.stopped + streams as u64; let conn = pair.client(); for _ in 0..streams { - let id = conn.streams().open(Dir::Uni).expect("stream limit"); + let id = conn.streams().open(Dir::Uni, Default::default()).expect("stream limit"); assert_eq!(conn.send_stream(id).write(&data).unwrap(), bytes); } pair.drive_until(|pair| { diff --git a/rs/moq-quic/benches/streams.rs b/rs/moq-quic/benches/streams.rs index 35fc49536f8..99f06bf6463 100644 --- a/rs/moq-quic/benches/streams.rs +++ b/rs/moq-quic/benches/streams.rs @@ -20,7 +20,7 @@ fn send(pair: &mut Pair, streams: usize, priorities: usize, writes: usize, size: let target = pair.server.received.finished + streams as u64; let conn = pair.client(); for index in 0..streams { - let id = conn.streams().open(Dir::Uni).expect("stream limit"); + let id = conn.streams().open(Dir::Uni, Default::default()).expect("stream limit"); let mut stream = conn.send_stream(id); // `as _` follows the priority type, which a scheduler rewrite widens. stream.set_priority((index % priorities) as _).unwrap(); diff --git a/rs/moq-quic/benches/wire.rs b/rs/moq-quic/benches/wire.rs index a651516fe9f..da0a5b92ea2 100644 --- a/rs/moq-quic/benches/wire.rs +++ b/rs/moq-quic/benches/wire.rs @@ -50,7 +50,7 @@ fn queue(pair: &mut Pair, packets: usize, frames: usize) -> usize { let mut datagrams = conn.datagrams(); let empty = datagrams.send_buffer_space(); for _ in 0..packets * frames { - datagrams.send(data.clone(), None, 0).unwrap(); + datagrams.send(data.clone(), Default::default()).unwrap(); } empty } diff --git a/rs/moq-quic/src/connection/datagrams.rs b/rs/moq-quic/src/connection/datagrams.rs index 6cd3222f727..712e6919a58 100644 --- a/rs/moq-quic/src/connection/datagrams.rs +++ b/rs/moq-quic/src/connection/datagrams.rs @@ -4,7 +4,7 @@ use bytes::Bytes; use thiserror::Error; use tracing::{debug, trace}; -use super::{Connection, SendGroup}; +use super::{Connection, SendOptions}; use crate::{ TransportError, frame::{Datagram, FrameStruct}, @@ -16,28 +16,23 @@ pub struct Datagrams<'a> { } impl Datagrams<'_> { - /// Queue an unreliable, unordered datagram in `group` at `order` + /// Queue an unreliable datagram, scheduled by `options` /// - /// The datagram is scheduled like one of the group's streams at priority `order`: it waits - /// behind higher orders, goes ahead of a stream of equal order, and spends the group's - /// share of bytes. Without a group, it is ordered among the ungrouped streams, which go - /// before every group. + /// The datagram is scheduled like one of its group's streams at its priority: it waits + /// behind higher priorities, goes ahead of a stream of equal priority, and spends the + /// group's share of bytes. Without a group, it is ranked among the ungrouped streams, which + /// go before every group. /// /// Sending never blocks. While queued datagrams overflow /// [`TransportConfig::datagram_send_buffer_size`](crate::TransportConfig::datagram_send_buffer_size), - /// the domain holding the most datagram bytes drops the oldest datagram of its - /// lowest-priority group, and this datagram is dropped instead once it is the one to go. + /// the oldest datagram of the lowest-priority group is dropped, and this datagram is dropped + /// instead once it is the one to go. /// - /// Returns `Err` iff a `len`-byte datagram cannot currently be sent. + /// Returns `Err` iff `data` cannot currently be sent. /// /// # Panics - /// - when `group` was opened on another connection - pub fn send( - &mut self, - data: Bytes, - group: Option<&SendGroup>, - order: i64, - ) -> Result<(), SendDatagramError> { + /// - when `options.group` was opened on another connection + pub fn send(&mut self, data: Bytes, options: SendOptions<'_>) -> Result<(), SendDatagramError> { if self.conn.config.datagram_receive_buffer_size.is_none() { return Err(SendDatagramError::Disabled); } @@ -52,7 +47,7 @@ impl Datagrams<'_> { if !self .conn .streams - .queue_datagram(datagram, group, order, budget) + .queue_datagram(datagram, options, budget) { trace!("dropping outgoing datagram"); } @@ -69,7 +64,7 @@ impl Datagrams<'_> { .drop_oversized_datagrams(max_datagram_size); } - /// Compute the maximum size of datagrams that may passed to `send_datagram` + /// Compute the maximum size of datagrams that may be passed to [`send`](Self::send) /// /// Returns `None` if datagrams are unsupported by the peer or disabled locally. /// @@ -206,6 +201,7 @@ mod tests { /// Errors that can arise when sending a datagram #[derive(Debug, Error, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[non_exhaustive] pub enum SendDatagramError { /// The peer does not support receiving datagrams #[error("datagrams not supported by peer")] diff --git a/rs/moq-quic/src/connection/mod.rs b/rs/moq-quic/src/connection/mod.rs index b2f5fdb6049..1db6b087fc4 100644 --- a/rs/moq-quic/src/connection/mod.rs +++ b/rs/moq-quic/src/connection/mod.rs @@ -94,7 +94,7 @@ mod streams; pub(crate) use streams::StreamsState; pub use streams::{ Checkpoint, Chunks, ClosedStream, Credit, FinishError, ReadError, ReadableError, RecvStream, - SendDomain, SendGroup, SendGroups, SendStream, ShouldTransmit, StreamEvent, Streams, + SendGroup, SendGroups, SendOptions, SendStream, ShouldTransmit, StreamEvent, Streams, WriteError, Written, }; diff --git a/rs/moq-quic/src/connection/streams/mod.rs b/rs/moq-quic/src/connection/streams/mod.rs index 61412154aef..7ff9e35558f 100644 --- a/rs/moq-quic/src/connection/streams/mod.rs +++ b/rs/moq-quic/src/connection/streams/mod.rs @@ -42,10 +42,13 @@ impl<'a> Streams<'a> { Self { state, conn_state } } - /// Open a single stream if possible + /// Open a single stream if possible, its sending half scheduled by `options` /// /// Returns `None` if the streams in the given direction are currently exhausted. - pub fn open(&mut self, dir: Dir) -> Option { + /// + /// # Panics + /// - when `options.group` was opened on another connection + pub fn open(&mut self, dir: Dir, options: SendOptions<'_>) -> Option { if self.conn_state.is_closed() { return None; } @@ -60,6 +63,17 @@ impl<'a> Streams<'a> { let id = StreamId::new(self.state.side, dir, self.state.next[dir as usize] - 1); self.state.insert_local(id); self.state.send_streams += 1; + + // Send state is allocated on first use, so the default schedule needs none. + if options.group.is_some() || options.priority != 0 { + let max_send_data = self.state.max_send_data(id); + let stream = self.state.send.get_mut(&id).unwrap().insert(Send::new(max_send_data)); + stream.priority = options.priority; + let group = options.group.map(|g| g.index(self.state.tag)); + self.state + .pending + .join(id, &mut stream.slot, group, stream.priority); + } Some(id) } @@ -518,25 +532,35 @@ impl Checkpoint { /// Scheduling of outgoing streams between send groups /// -/// A send group shares bytes with the other groups of its domain: a higher priority group -/// preempts every lower one, and groups of equal priority get an equal share of bytes no -/// matter how many streams each has queued. Domains share bytes equally whatever their -/// groups' priorities. Streams outside any group go before all of it. A group's datagrams, +/// A higher priority group preempts every lower one, and groups of equal priority get an +/// equal share of bytes no matter how many streams each has queued. Streams outside any group +/// go before all of it. A group's datagrams, /// from [`Datagrams::send`](crate::Datagrams::send), share its bytes in the same order. pub struct SendGroups<'a> { pub(super) state: &'a mut StreamsState, } impl SendGroups<'_> { - /// Open a send group at `priority` in `domain`, or in the default domain + /// Open a send group at `priority` + pub fn open(&mut self, priority: i64) -> SendGroup { + SendGroup { + index: self.state.pending.open_group(priority, None), + tag: self.state.tag, + } + } + + /// Open a send group at `priority` in `domain` /// /// # Panics /// - when `domain` was opened on another connection - pub fn open(&mut self, priority: i64, domain: Option<&SendDomain>) -> SendGroup { + #[cfg(test)] + pub(crate) fn open_in(&mut self, priority: i64, domain: &SendDomain) -> SendGroup { let tag = self.state.tag; - let domain = domain.map(|d| d.index(tag)); SendGroup { - index: self.state.pending.open_group(priority, domain), + index: self + .state + .pending + .open_group(priority, Some(domain.index(tag))), tag, } } @@ -570,7 +594,8 @@ impl SendGroups<'_> { } /// Open a domain, which gets an equal share of bytes with every other domain - pub fn open_domain(&mut self) -> SendDomain { + #[cfg(test)] + pub(crate) fn open_domain(&mut self) -> SendDomain { SendDomain { index: self.state.pending.open_domain(), tag: self.state.tag, @@ -581,30 +606,30 @@ impl SendGroups<'_> { /// /// # Panics /// - when `domain` was opened on another connection - pub fn close_domain(&mut self, domain: SendDomain) { + #[cfg(test)] + pub(crate) fn close_domain(&mut self, domain: SendDomain) { let index = domain.index(self.state.tag); self.state.pending.close_domain(index); } } impl StreamsState { - /// Queue a datagram in `group` at `order`, within `budget` bytes of queued datagrams. + /// Queue a datagram scheduled by `options`, within `budget` bytes of queued datagrams. /// /// Returns whether it stayed queued rather than being evicted itself. /// /// # Panics - /// - when `group` was opened on another connection + /// - when `options.group` was opened on another connection pub(crate) fn queue_datagram( &mut self, datagram: frame::Datagram, - group: Option<&SendGroup>, - order: i64, + options: SendOptions<'_>, budget: usize, ) -> bool { - let group = group.map(|g| g.index(self.tag)); + let group = options.group.map(|g| g.index(self.tag)); let frame = datagram.size(true); self.pending - .push_datagram(group, order, datagram, frame, budget) + .push_datagram(group, options.priority, datagram, frame, budget) } /// Drop queued datagrams with a payload over `max_payload` bytes, returning whether any was. @@ -628,6 +653,36 @@ impl StreamsState { } } +/// How an outgoing stream or datagram is scheduled, like W3C WebTransport's send options +/// +/// The default is ungrouped at priority 0. Generic so the drivers can carry their own group +/// handle in the same shape. +#[derive(Debug)] +pub struct SendOptions<'a, G = SendGroup> { + /// The send group to join, or `None` for the ungrouped streams that go before every group + pub group: Option<&'a G>, + /// The priority within the group: higher goes first, and a datagram goes ahead of a + /// stream of equal priority + pub priority: i64, +} + +impl Default for SendOptions<'_, G> { + fn default() -> Self { + Self { + group: None, + priority: 0, + } + } +} + +impl Clone for SendOptions<'_, G> { + fn clone(&self) -> Self { + *self + } +} + +impl Copy for SendOptions<'_, G> {} + /// A send group, from [`SendGroups::open`] /// /// Release it with [`SendGroups::close`] on the connection that opened it. @@ -648,13 +703,15 @@ impl SendGroup { /// A domain of send groups, from [`SendGroups::open_domain`] /// /// Release it with [`SendGroups::close_domain`] on the connection that opened it. +#[cfg(test)] #[derive(Debug, PartialEq, Eq)] #[must_use = "a domain lives until it is closed"] -pub struct SendDomain { +pub(crate) struct SendDomain { index: usize, tag: ConnectionTag, } +#[cfg(test)] impl SendDomain { fn index(&self, tag: ConnectionTag) -> usize { assert_eq!(self.tag, tag, "send domain used on another connection"); diff --git a/rs/moq-quic/src/connection/streams/saturated.rs b/rs/moq-quic/src/connection/streams/saturated.rs index 0ae52976672..140d3f916a1 100644 --- a/rs/moq-quic/src/connection/streams/saturated.rs +++ b/rs/moq-quic/src/connection/streams/saturated.rs @@ -7,7 +7,7 @@ use std::collections::HashMap; use bytes::{BufMut, Bytes, BytesMut}; use super::state::StreamsState; -use super::{SendDomain, SendGroup, SendGroups, SendStream, Streams}; +use super::{SendDomain, SendGroup, SendGroups, SendOptions, SendStream, Streams}; use crate::{ Dir, Side, StreamId, VarInt, connection::{State as ConnState, spaces::Retransmits}, @@ -90,7 +90,7 @@ impl Sender { } fn group(&mut self, priority: i64) -> SendGroup { - self.groups().open(priority, None) + self.groups().open(priority) } fn send(&mut self, id: StreamId) -> SendStream<'_> { @@ -108,11 +108,8 @@ impl Sender { state: &mut self.state, conn_state: &self.conn, } - .open(Dir::Uni) + .open(Dir::Uni, SendOptions { group, priority }) .unwrap(); - let mut stream = self.send(id); - stream.set_group(group).unwrap(); - stream.set_priority(priority).unwrap(); self.write(id, bytes); id } @@ -121,8 +118,8 @@ impl Sender { assert_eq!(self.send(id).write(&vec![0; bytes]), Ok(bytes)); } - /// Queue a `bytes` payload datagram in `group` at `order`, returning its tag. - fn datagram(&mut self, group: Option<&SendGroup>, order: i64, bytes: usize) -> u64 { + /// Queue a `bytes` payload datagram in `group` at `priority`, returning its tag. + fn datagram(&mut self, group: Option<&SendGroup>, priority: i64, bytes: usize) -> u64 { let tag = self.tag; self.tag += 1; let mut data = BytesMut::with_capacity(bytes); @@ -133,7 +130,7 @@ impl Sender { }; assert!( self.state - .queue_datagram(datagram, group, order, usize::MAX) + .queue_datagram(datagram, SendOptions { group, priority }, usize::MAX) ); tag } @@ -451,13 +448,13 @@ fn domains_share_bytes_and_confine_priority() { let quiet = sender.groups().open_domain(); let crowded_groups: Vec<_> = (0..10) - .map(|priority| sender.groups().open(priority, Some(&crowded))) + .map(|priority| sender.groups().open_in(priority, &crowded)) .collect(); let crowded_streams: Vec<_> = crowded_groups .iter() .map(|group| sender.open(Some(group), 0, 1_000_000)) .collect(); - let quiet_group = sender.groups().open(-100, Some(&quiet)); + let quiet_group = sender.groups().open_in(-100, &quiet); let quiet_stream = sender.open(Some(&quiet_group), 0, 1_000_000); sender.drain(200); @@ -475,7 +472,7 @@ fn domains_share_bytes_and_confine_priority() { fn the_default_domain_is_one_share() { let mut sender = Sender::new(); let domain = sender.groups().open_domain(); - let inside = sender.groups().open(0, Some(&domain)); + let inside = sender.groups().open_in(0, &domain); let outside: Vec = (0..3).map(|_| sender.group(0)).collect(); let inside = sender.open(Some(&inside), 0, 1_000_000); let outside: Vec<_> = outside @@ -493,7 +490,7 @@ fn the_default_domain_is_one_share() { fn reset_frees_a_released_group() { let mut sender = Sender::new(); let domain: SendDomain = sender.groups().open_domain(); - let group = sender.groups().open(0, Some(&domain)); + let group = sender.groups().open_in(0, &domain); let reset = sender.open(Some(&group), 0, 10_000); let finished = sender.open(Some(&group), 1, 100); sender.send(finished).finish().unwrap(); @@ -676,8 +673,8 @@ fn saturated_datagram_domains_share_bytes() { let mut sender = Sender::new(); let small = sender.groups().open_domain(); let large = sender.groups().open_domain(); - let small = sender.groups().open(0, Some(&small)); - let large = sender.groups().open(9, Some(&large)); + let small = sender.groups().open_in(0, &small); + let large = sender.groups().open_in(9, &large); let small: Vec<_> = (0..2_000) .map(|seq| sender.datagram(Some(&small), seq, 50)) .collect(); diff --git a/rs/moq-quic/src/connection/streams/schedule.rs b/rs/moq-quic/src/connection/streams/schedule.rs index a4c2499e672..1b73fdd08a5 100644 --- a/rs/moq-quic/src/connection/streams/schedule.rs +++ b/rs/moq-quic/src/connection/streams/schedule.rs @@ -291,11 +291,13 @@ impl Schedule { } /// Create a domain, sharing bytes equally with every other domain. + #[cfg(test)] pub(super) fn open_domain(&mut self) -> usize { self.domains.insert(Domain::new()) } /// Release a domain; it is freed once its last group is. + #[cfg(test)] pub(super) fn close_domain(&mut self, domain: usize) { assert_ne!(domain, DEFAULT_DOMAIN, "the default domain is never closed"); self.domains[domain].closed = true; diff --git a/rs/moq-quic/src/connection/streams/state.rs b/rs/moq-quic/src/connection/streams/state.rs index 6c1f57c8d96..e3126bd235c 100644 --- a/rs/moq-quic/src/connection/streams/state.rs +++ b/rs/moq-quic/src/connection/streams/state.rs @@ -1191,7 +1191,7 @@ mod tests { state: &mut server, conn_state: &state, } - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .unwrap(); SendStream { id, @@ -1258,7 +1258,7 @@ mod tests { state: &mut server, conn_state: &state, } - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .unwrap(); SendStream { id, @@ -1616,7 +1616,7 @@ mod tests { state: &mut server, conn_state: &state, } - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .unwrap(); let mut stream = SendStream { @@ -1679,9 +1679,9 @@ mod tests { conn_state: &state, }; - let id_high = streams.open(Dir::Bi).unwrap(); - let id_mid = streams.open(Dir::Bi).unwrap(); - let id_low = streams.open(Dir::Bi).unwrap(); + let id_high = streams.open(Dir::Bi, Default::default()).unwrap(); + let id_mid = streams.open(Dir::Bi, Default::default()).unwrap(); + let id_low = streams.open(Dir::Bi, Default::default()).unwrap(); let mut mid = SendStream { id: id_mid, @@ -1735,8 +1735,8 @@ mod tests { state: &mut server, conn_state: &state, }; - let id_low = streams.open(Dir::Bi).unwrap(); - let id_high = streams.open(Dir::Bi).unwrap(); + let id_low = streams.open(Dir::Bi, Default::default()).unwrap(); + let id_high = streams.open(Dir::Bi, Default::default()).unwrap(); let mut low = SendStream { id: id_low, @@ -1797,8 +1797,8 @@ mod tests { conn_state: &state, }; - let id_high = streams.open(Dir::Bi).unwrap(); - let id_mid = streams.open(Dir::Bi).unwrap(); + let id_high = streams.open(Dir::Bi, Default::default()).unwrap(); + let id_mid = streams.open(Dir::Bi, Default::default()).unwrap(); let mut mid = SendStream { id: id_mid, @@ -1866,9 +1866,9 @@ mod tests { }; // a, b and c all have the same priority - let id_a = streams.open(Dir::Bi).unwrap(); - let id_b = streams.open(Dir::Bi).unwrap(); - let id_c = streams.open(Dir::Bi).unwrap(); + let id_a = streams.open(Dir::Bi, Default::default()).unwrap(); + let id_b = streams.open(Dir::Bi, Default::default()).unwrap(); + let id_c = streams.open(Dir::Bi, Default::default()).unwrap(); let mut stream_a = SendStream { id: id_a, @@ -1948,9 +1948,9 @@ mod tests { }; // a, and b have the same priority, c has higher priority - let id_a = streams.open(Dir::Bi).unwrap(); - let id_b = streams.open(Dir::Bi).unwrap(); - let id_c = streams.open(Dir::Bi).unwrap(); + let id_a = streams.open(Dir::Bi, Default::default()).unwrap(); + let id_b = streams.open(Dir::Bi, Default::default()).unwrap(); + let id_c = streams.open(Dir::Bi, Default::default()).unwrap(); let mut stream_a = SendStream { id: id_a, @@ -2055,7 +2055,7 @@ mod tests { conn_state: &state, }; - let id = streams.open(Dir::Uni).unwrap(); + let id = streams.open(Dir::Uni, Default::default()).unwrap(); let mut stream = SendStream { id, state: &mut server, @@ -2502,7 +2502,7 @@ mod tests { state: &mut server, conn_state: &conn_state, } - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .expect("should be able to open a stream"); let mut stream = SendStream { @@ -2577,7 +2577,7 @@ mod tests { state: &mut server, conn_state: &conn_state, } - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .expect("should be able to open a stream"); let mut stream = SendStream { @@ -2907,7 +2907,7 @@ mod tests { state: &mut server, conn_state: &state, } - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .unwrap(); let mut stream = SendStream { id, @@ -2951,7 +2951,7 @@ mod tests { state: &mut server, conn_state: &state, } - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .unwrap(); let mut stream = SendStream { id, @@ -2980,7 +2980,7 @@ mod tests { state: &mut server, conn_state: &state, } - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .unwrap(); let mut stream = SendStream { id, @@ -3023,7 +3023,7 @@ mod tests { state: &mut server, conn_state: &state, } - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .unwrap(); let mut stream = SendStream { id, @@ -3056,7 +3056,7 @@ mod tests { state: &mut server, conn_state: &state, } - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .unwrap(); let mut stream = SendStream { id, @@ -3097,7 +3097,7 @@ mod tests { state: &mut server, conn_state: &state, } - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .unwrap(); let mut stream = SendStream { id, @@ -3272,8 +3272,8 @@ mod tests { fn send_group_from_another_connection() { let mut a = make(Side::Client); let mut b = make(Side::Client); - let group = crate::SendGroups { state: &mut a }.open(0, None); - let _other = crate::SendGroups { state: &mut b }.open(0, None); + let group = crate::SendGroups { state: &mut a }.open(0); + let _other = crate::SendGroups { state: &mut b }.open(0); crate::SendGroups { state: &mut b }.set_priority(&group, 1); } @@ -3284,7 +3284,7 @@ mod tests { let mut b = make(Side::Client); let domain = crate::SendGroups { state: &mut a }.open_domain(); let _other = crate::SendGroups { state: &mut b }.open_domain(); - let _ = crate::SendGroups { state: &mut b }.open(0, Some(&domain)); + let _ = crate::SendGroups { state: &mut b }.open_in(0, &domain); } /// Another connection holding at least as much credit still refuses it. diff --git a/rs/moq-quic/src/fuzz.rs b/rs/moq-quic/src/fuzz.rs index 2f42de6f67e..cb1b060267c 100644 --- a/rs/moq-quic/src/fuzz.rs +++ b/rs/moq-quic/src/fuzz.rs @@ -180,7 +180,7 @@ pub fn streams(data: &[u8]) -> bool { }; match op { StreamOp::Open => { - Streams::new(&mut state, &conn_state).open(dir); + Streams::new(&mut state, &conn_state).open(dir, Default::default()); } StreamOp::Accept { uni } => { let dir = if uni { Dir::Uni } else { Dir::Bi }; diff --git a/rs/moq-quic/src/fuzz/connection.rs b/rs/moq-quic/src/fuzz/connection.rs index 6c419ad0bc8..db77f7f6b8e 100644 --- a/rs/moq-quic/src/fuzz/connection.rs +++ b/rs/moq-quic/src/fuzz/connection.rs @@ -138,7 +138,7 @@ enum Op { Datagram { who: Who, len: u16, - order: i8, + priority: i8, }, Ping { who: Who, @@ -443,7 +443,7 @@ impl Pair { Op::Open { who, uni } => { let peer = self.peer(who); let dir = dir(uni); - let Some(id) = peer.conn().and_then(|conn| conn.streams().open(dir)) else { + let Some(id) = peer.conn().and_then(|conn| conn.streams().open(dir, Default::default())) else { return; }; peer.send.push(id); @@ -554,7 +554,7 @@ impl Pair { conn.set_send_window(window.into()); } } - Op::Datagram { who, len, order } => { + Op::Datagram { who, len, priority } => { let peer = self.peer(who); let seq = peer.datagrams_sent.len() as u64; let Some(conn) = peer.conn() else { @@ -566,7 +566,15 @@ impl Pair { .chain((0..len).map(|i| datagram_byte(seq, i.into()))) .collect(); let size = data.len(); - if conn.datagrams().send(data, None, order.into()).is_ok() { + if conn + .datagrams() + .send( + data, + crate::SendOptions { + group: None, + priority: priority.into(), + }, + ).is_ok() { peer.datagrams_sent.push(size); } } @@ -820,7 +828,7 @@ pub(super) fn datagrams() -> Vec> { Op::Datagram { who: Who::Server, len: 10, - order: 0, + priority: 0, }, Op::KeyUpdate { who: Who::Client }, Op::Ping { who: Who::Client }, diff --git a/rs/moq-quic/src/lib.rs b/rs/moq-quic/src/lib.rs index 4c30d634a1e..2c9ea501263 100644 --- a/rs/moq-quic/src/lib.rs +++ b/rs/moq-quic/src/lib.rs @@ -55,7 +55,7 @@ mod connection; pub use crate::connection::{ Checkpoint, Chunk, Chunks, ClosedStream, Connection, ConnectionError, ConnectionStats, Credit, CreditStats, Datagrams, Event, FinishError, FrameStats, PathStats, ReadError, ReadableError, - RecvStream, RttEstimator, SendDatagramError, SendDomain, SendGroup, SendGroups, SendStream, + RecvStream, RttEstimator, SendDatagramError, SendGroup, SendGroups, SendOptions, SendStream, ShouldTransmit, StreamEvent, Streams, UdpStats, WriteError, Written, }; #[cfg(feature = "qlog")] diff --git a/rs/moq-quic/src/tests/characterize/limits.rs b/rs/moq-quic/src/tests/characterize/limits.rs index 61f26367b15..506beedd52d 100644 --- a/rs/moq-quic/src/tests/characterize/limits.rs +++ b/rs/moq-quic/src/tests/characterize/limits.rs @@ -4,7 +4,7 @@ use super::*; /// How many more uni streams the client can open right now, opening them all fn openable(pair: &mut Pair, ch: ConnectionHandle) -> Vec { - iter::from_fn(|| pair.client_streams(ch).open(Dir::Uni)).collect() + iter::from_fn(|| pair.client_streams(ch).open(Dir::Uni, Default::default())).collect() } /// Finishes each client stream and has the server read it to the end @@ -75,7 +75,7 @@ fn max_concurrent_streams_lowered() { /// How many bytes a fresh client stream can write, up to `limit` fn writable(pair: &mut Pair, ch: ConnectionHandle, limit: usize) -> usize { - let s = pair.client_streams(ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(ch, s).write(&vec![0; limit]).unwrap_or(0) } @@ -198,7 +198,7 @@ fn zero_rtt_window_raise(dir: Dir) { pair.server.set_server_config(Some(Arc::new(server(NEW)))); let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(dir).unwrap(); + let s = pair.client_streams(client_ch).open(dir, Default::default()).unwrap(); let mut written = pair.client_send(client_ch, s).write(&[0; LEN]).unwrap(); assert_eq!(written, OLD as usize); diff --git a/rs/moq-quic/src/tests/characterize/paths.rs b/rs/moq-quic/src/tests/characterize/paths.rs index 2e0bc284ee2..f5f1e4ee54a 100644 --- a/rs/moq-quic/src/tests/characterize/paths.rs +++ b/rs/moq-quic/src/tests/characterize/paths.rs @@ -155,7 +155,7 @@ fn duplicate_packet_is_discarded() { let _guard = subscribe(); let (mut pair, client_ch, server_ch) = connected(); pair.drive(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive_client(); assert_eq!(pair.server.inbound.len(), 1); @@ -297,7 +297,7 @@ fn zero_rtt_retransmit_after_retry() { let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); @@ -344,7 +344,7 @@ fn path_validation_failure_reverts() { assert_matches!(updates.as_slice(), [.., Event::PathUpdated]); // The connection still works on the old path - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); assert_eq!(pair.server_streams(server_ch).accept(Dir::Uni), Some(s)); diff --git a/rs/moq-quic/src/tests/characterize/reset.rs b/rs/moq-quic/src/tests/characterize/reset.rs index 9128f01c495..31c28bd054e 100644 --- a/rs/moq-quic/src/tests/characterize/reset.rs +++ b/rs/moq-quic/src/tests/characterize/reset.rs @@ -27,7 +27,7 @@ fn open( server_ch: ConnectionHandle, data: &[u8], ) -> StreamId { - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s).write(data).unwrap(); pair.drive(); assert_eq!(pair.server_streams(server_ch).accept(Dir::Uni), Some(s)); @@ -177,11 +177,11 @@ fn reset_returns_stream_credit_once_observed() { let s = open(&mut pair, client_ch, server_ch, b"hello"); pair.client_send(client_ch, s).reset(CODE).unwrap(); pair.drive(); - assert_eq!(pair.client_streams(client_ch).open(Dir::Uni), None); + assert_eq!(pair.client_streams(client_ch).open(Dir::Uni, Default::default()), None); assert_eq!(read_all(&mut pair, server_ch, s).1, ReadError::Reset(CODE)); pair.drive(); - assert!(pair.client_streams(client_ch).open(Dir::Uni).is_some()); + assert!(pair.client_streams(client_ch).open(Dir::Uni, Default::default()).is_some()); } /// The connection window used by `s`'s unread bytes, which fill it @@ -193,7 +193,7 @@ fn blocked() -> (Pair, ConnectionHandle, ConnectionHandle, StreamId) { connected_with(|t| _ = t.receive_window(VarInt::from_u32(WINDOW)), |_| {}); let s = open(&mut pair, client_ch, server_ch, &[0; WINDOW as usize]); // The window is spent, so nothing more can be written - let other = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let other = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!( pair.client_send(client_ch, other).write(b"x"), Err(WriteError::Blocked) @@ -203,7 +203,7 @@ fn blocked() -> (Pair, ConnectionHandle, ConnectionHandle, StreamId) { /// How many bytes a fresh client stream can write fn writable(pair: &mut Pair, ch: ConnectionHandle) -> usize { - let s = pair.client_streams(ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(ch, s) .write(&[0; 2 * WINDOW as usize]) .unwrap_or(0) diff --git a/rs/moq-quic/src/tests/characterize/schedule.rs b/rs/moq-quic/src/tests/characterize/schedule.rs index 1c13c5029a8..7817d8ff84d 100644 --- a/rs/moq-quic/src/tests/characterize/schedule.rs +++ b/rs/moq-quic/src/tests/characterize/schedule.rs @@ -43,7 +43,7 @@ fn assert_golden(pair: &mut Pair, golden: &str) { /// Opens a client uni stream at `priority` and queues `LEN` bytes and a FIN on it fn queue(pair: &mut Pair, ch: ConnectionHandle, priority: i64) -> StreamId { - let s = pair.client_streams(ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(ch, s).set_priority(priority).unwrap(); assert_eq!(pair.client_send(ch, s).write(&[0; LEN]).unwrap(), LEN); pair.client_send(ch, s).finish().unwrap(); @@ -156,12 +156,12 @@ fn datagrams_interleaved() { queue(&mut pair, ch, 0); for _ in 0..3 { pair.client_datagrams(ch) - .send(vec![0; 500].into(), None, 0) + .send(vec![0; 500].into(), Default::default()) .unwrap(); } queue(&mut pair, ch, 0); pair.client_datagrams(ch) - .send(vec![0; 1000].into(), None, 0) + .send(vec![0; 1000].into(), Default::default()) .unwrap(); assert_golden( &mut pair, @@ -183,7 +183,7 @@ fn datagrams_interleaved() { fn retransmit_within_stream() { let _guard = subscribe(); let (mut pair, ch) = idle(true); - let s = pair.client_streams(ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!(pair.client_send(ch, s).write(&[0; 16_000]).unwrap(), 16_000); // Lose the second packet of the first flight diff --git a/rs/moq-quic/src/tests/mod.rs b/rs/moq-quic/src/tests/mod.rs index eb447b86c43..5d77370aeeb 100644 --- a/rs/moq-quic/src/tests/mod.rs +++ b/rs/moq-quic/src/tests/mod.rs @@ -593,7 +593,7 @@ fn finish_stream_simple() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); @@ -637,7 +637,7 @@ fn reset_stream() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); @@ -666,7 +666,7 @@ fn stop_stream() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); @@ -786,7 +786,7 @@ fn congestion() { const TARGET: u64 = 2048; assert!(pair.client_conn_mut(client_ch).congestion_window() > TARGET); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); // Send data without receiving ACKs until the congestion state falls below target while pair.client_conn_mut(client_ch).congestion_window() > TARGET { let n = pair.client_send(client_ch, s).write(&[42; 1024]).unwrap(); @@ -822,7 +822,7 @@ fn full_initial_window() { let mtu = u64::from(INITIAL_MTU); assert_eq!(window % mtu, 0, "window must be exactly fillable"); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let data = vec![42; 2 * window as usize]; assert_eq!( pair.client_send(client_ch, s).write(&data), @@ -871,7 +871,7 @@ fn zero_rtt_happypath() { info!("resuming session"); let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); const MSG: &[u8] = b"Hello, 0-RTT!"; pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); @@ -970,7 +970,7 @@ fn zero_rtt_rejection() { info!("resuming session"); let client_ch = pair.begin_connect(client_config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); const MSG: &[u8] = b"Hello, 0-RTT!"; pair.client_conn_mut(client_ch) .set_send_window(MSG.len() as u64); @@ -991,7 +991,7 @@ fn zero_rtt_rejection() { Some(Event::Connected) ); assert_matches!(pair.server_conn_mut(server_ch).poll(), None); - let s2 = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s2 = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!(s, s2); // The server discarded its 0-RTT keys, so it never decrypted the STREAM frame and has no @@ -1053,7 +1053,7 @@ fn test_zero_rtt_incoming_limit(configure_server: pair.server.handle_incoming = Box::new(|_| IncomingConnectionBehavior::Wait); let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s) .write(&vec![0; CLIENT_WRITES]) .unwrap(); @@ -1419,7 +1419,7 @@ fn late_peer_params_make_streams_available() { pair.server.drive_incoming(pair.time, pair.client.addr); let incoming = pair.server.pop_waiting_incoming(); let server_ch = pair.server.try_accept(incoming, pair.time).unwrap(); - assert_eq!(pair.server_streams(server_ch).open(Dir::Uni), None); + assert_eq!(pair.server_streams(server_ch).open(Dir::Uni, Default::default()), None); pair.drive(); assert!( @@ -1428,7 +1428,7 @@ fn late_peer_params_make_streams_available() { Event::Stream(StreamEvent::Available { dir: Dir::Uni }) )) ); - assert!(pair.server_streams(server_ch).open(Dir::Uni).is_some()); + assert!(pair.server_streams(server_ch).open(Dir::Uni, Default::default()).is_some()); } #[test] @@ -1450,10 +1450,10 @@ fn stream_id_limit() { .get_mut(&client_ch) .unwrap() .streams() - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .expect("couldn't open first stream"); assert_eq!( - pair.client_streams(client_ch).open(Dir::Uni), + pair.client_streams(client_ch).open(Dir::Uni, Default::default()), None, "only one stream is permitted at a time" ); @@ -1467,7 +1467,7 @@ fn stream_id_limit() { Some(Event::Stream(StreamEvent::Finished { id })) if id == s ); assert_eq!( - pair.client_streams(client_ch).open(Dir::Uni), + pair.client_streams(client_ch).open(Dir::Uni, Default::default()), None, "server does not immediately grant additional credit" ); @@ -1505,7 +1505,7 @@ fn stream_id_limit() { .get_mut(&client_ch) .unwrap() .streams() - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .expect("didn't get stream id budget"); pair.client_send(client_ch, s).finish().unwrap(); pair.drive(); @@ -1543,9 +1543,9 @@ fn streams_blocked() { // Use up the only stream slot, then try to open another let s = pair .client_streams(client_ch) - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .expect("first uni stream"); - assert_eq!(pair.client_streams(client_ch).open(Dir::Uni), None); + assert_eq!(pair.client_streams(client_ch).open(Dir::Uni, Default::default()), None); // Send data so the STREAMS_BLOCKED piggybacks on an outgoing packet pair.client_send(client_ch, s).write(b"hi").unwrap(); @@ -1576,7 +1576,7 @@ fn streams_blocked_not_sent_under_limit() { // Default config allows many streams; opening one should not trigger STREAMS_BLOCKED let s = pair .client_streams(client_ch) - .open(Dir::Uni) + .open(Dir::Uni, Default::default()) .expect("open stream"); pair.client_send(client_ch, s).write(b"hi").unwrap(); pair.drive(); @@ -1604,7 +1604,7 @@ fn data_blocked() { let (client_ch, server_ch) = pair.connect(); // Fill the connection-level window, then run into the limit - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!( pair.client_send(client_ch, s) .write(b"0123456789ab") @@ -1682,7 +1682,7 @@ fn stream_data_blocked() { let (client_ch, server_ch) = pair.connect(); // Fill the stream-level window, then run into the limit - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!( pair.client_send(client_ch, s) .write(b"0123456789ab") @@ -1753,7 +1753,7 @@ fn data_blocked_not_sent_under_limit() { let (client_ch, _server_ch) = pair.connect(); // Default windows are far larger than this write, so nothing is blocked - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s).write(b"hi").unwrap(); pair.drive(); @@ -1770,7 +1770,7 @@ fn data_blocked_not_sent_for_local_send_window() { // Running out of our own send window is not the peer's flow control limit pair.client_conn_mut(client_ch).set_send_window(5); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!( pair.client_send(client_ch, s).write(b"0123456789").unwrap(), 5 @@ -1803,7 +1803,7 @@ fn data_blocked_dropped_when_limit_raised() { let mut pair = Pair::new(Default::default(), server); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!( pair.client_send(client_ch, s) .write(b"0123456789ab") @@ -1843,7 +1843,7 @@ fn stream_data_blocked_not_sent_after_reset() { let mut pair = Pair::new(Default::default(), server); let (client_ch, _server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!( pair.client_send(client_ch, s) .write(b"0123456789ab") @@ -1877,7 +1877,7 @@ fn data_blocked_retransmit() { let mut pair = Pair::new(Default::default(), server); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!( pair.client_send(client_ch, s) .write(b"0123456789ab") @@ -1921,7 +1921,7 @@ fn key_update_simple() { .get_mut(&client_ch) .unwrap() .streams() - .open(Dir::Bi) + .open(Dir::Bi, Default::default()) .expect("couldn't open first stream"); const MSG1: &[u8] = b"hello1"; @@ -1978,7 +1978,7 @@ fn key_update_reordered() { .get_mut(&client_ch) .unwrap() .streams() - .open(Dir::Bi) + .open(Dir::Bi, Default::default()) .expect("couldn't open first stream"); const MSG1: &[u8] = b"1"; @@ -2225,7 +2225,7 @@ fn connection_close_while_congestion_blocked() { // Saturate the congestion window with unacknowledged stream data by transmitting from the // client without driving the server, so no ACKs come back and in-flight bytes stay pinned at // the window - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s) .write(&[42; 1024 * 1024]) .unwrap(); @@ -2335,7 +2335,7 @@ fn test_flow_control(config: TransportConfig, window_size: usize) { let msg = vec![0xAB; window_size + 10]; // Stream reset before read - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); info!("writing"); assert_eq!(pair.client_send(client_ch, s).write_limit(), window_size); assert_eq!(pair.client_send(client_ch, s).write(&msg), Ok(window_size)); @@ -2360,7 +2360,7 @@ fn test_flow_control(config: TransportConfig, window_size: usize) { // Happy path info!("writing"); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!(pair.client_send(client_ch, s).write_limit(), window_size); assert_eq!(pair.client_send(client_ch, s).write(&msg), Ok(window_size)); assert_eq!(pair.client_send(client_ch, s).write_limit(), 0); @@ -2456,7 +2456,7 @@ fn stop_opens_bidi() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); assert_eq!(pair.client_streams(client_ch).send_streams(), 0); - let s = pair.client_streams(client_ch).open(Dir::Bi).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Bi, Default::default()).unwrap(); assert_eq!(pair.client_streams(client_ch).send_streams(), 1); const ERROR: VarInt = VarInt(42); pair.client @@ -2500,8 +2500,8 @@ fn implicit_open() { let _guard = subscribe(); let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s1 = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); - let s2 = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s1 = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s2 = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s2).write(b"hello").unwrap(); pair.drive(); assert_matches!( @@ -2669,7 +2669,7 @@ fn finish_stream_flow_control_reordered() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); @@ -2725,7 +2725,7 @@ fn handshake_1rtt_handling() { pair.client.delay_outbound(); // Send some 1-RTT data which will be received first. - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); pair.client_send(client_ch, s).finish().unwrap(); @@ -2765,7 +2765,7 @@ fn stop_before_finish() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); @@ -2787,7 +2787,7 @@ fn stop_during_finish() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); @@ -2814,7 +2814,7 @@ fn congested_tail_loss() { const TARGET: u64 = 2048; assert!(pair.client_conn_mut(client_ch).congestion_window() > TARGET); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); // Send data without receiving ACKs until the congestion state falls below target while pair.client_conn_mut(client_ch).congestion_window() > TARGET { let n = pair.client_send(client_ch, s).write(&[42; 1024]).unwrap(); @@ -2870,7 +2870,7 @@ fn tail_loss_small_segment_size() { info!("Sending datagram batch"); for _ in 0..DGRAM_NUM { pair.client_datagrams(client_ch) - .send(vec![0; DGRAM_LEN].into(), None, 0) + .send(vec![0; DGRAM_LEN].into(), Default::default()) .unwrap(); } @@ -2923,7 +2923,7 @@ fn tail_loss_probe_keeps_ping_when_datagram_does_not_fit() { let datagram_len = pair.client_datagrams(client_ch).max_size().unwrap(); assert!(datagram_len > INITIAL_MTU as usize); pair.client_datagrams(client_ch) - .send(vec![0; datagram_len].into(), None, 0) + .send(vec![0; datagram_len].into(), Default::default()) .unwrap(); pair.drive(); @@ -2970,7 +2970,7 @@ fn tail_loss_respect_max_datagrams() { info!("Sending datagram batch"); for _ in 0..DGRAM_NUM { pair.client_datagrams(client_ch) - .send(vec![0; DGRAM_LEN].into(), None, 0) + .send(vec![0; DGRAM_LEN].into(), Default::default()) .unwrap(); } @@ -2991,7 +2991,7 @@ fn datagram_send_recv() { const DATA: &[u8] = b"whee"; pair.client_datagrams(client_ch) - .send(DATA.into(), None, 0) + .send(DATA.into(), Default::default()) .unwrap(); pair.drive(); assert_matches!( @@ -3010,14 +3010,26 @@ fn first_flight_datagrams(stream: i64, datagram: i64) -> usize { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); let conn = pair.server_conn_mut(server_ch); - let streams = conn.send_groups().open(stream, None); - let datagrams = conn.send_groups().open(datagram, None); - let s = conn.streams().open(Dir::Uni).unwrap(); - conn.send_stream(s).set_group(Some(&streams)).unwrap(); + let streams = conn.send_groups().open(stream); + let datagrams = conn.send_groups().open(datagram); + let s = conn + .streams() + .open( + Dir::Uni, + SendOptions { + group: Some(&streams), + priority: 0, + }, + ) + .unwrap(); conn.send_stream(s).write(&[0; 256 * 1024]).unwrap(); for _ in 0..DATAGRAMS { + let options = SendOptions { + group: Some(&datagrams), + priority: 0, + }; conn.datagrams() - .send(vec![1; 100].into(), Some(&datagrams), 0) + .send(vec![1; 100].into(), options) .unwrap(); } @@ -3076,13 +3088,13 @@ fn datagram_recv_buffer_overflow() { const DATA2: &[u8] = &[0xBC; (PAYLOAD_WINDOW / 3) + 1]; const DATA3: &[u8] = &[0xCD; (PAYLOAD_WINDOW / 3) + 1]; pair.client_datagrams(client_ch) - .send(DATA1.into(), None, 0) + .send(DATA1.into(), Default::default()) .unwrap(); pair.client_datagrams(client_ch) - .send(DATA2.into(), None, 0) + .send(DATA2.into(), Default::default()) .unwrap(); pair.client_datagrams(client_ch) - .send(DATA3.into(), None, 0) + .send(DATA3.into(), Default::default()) .unwrap(); pair.drive(); assert_matches!( @@ -3094,7 +3106,7 @@ fn datagram_recv_buffer_overflow() { assert_matches!(pair.server_datagrams(server_ch).recv(), None); pair.client_datagrams(client_ch) - .send(DATA1.into(), None, 0) + .send(DATA1.into(), Default::default()) .unwrap(); pair.drive(); assert_eq!(pair.server_datagrams(server_ch).recv().unwrap(), DATA1); @@ -3113,12 +3125,12 @@ fn datagram_larger_than_send_buffer_is_too_large() { assert_matches!( pair.client_datagrams(client_ch) - .send(Bytes::from_static(&[0; 2]), None, 0), + .send(Bytes::from_static(&[0; 2]), Default::default()), Err(SendDatagramError::TooLarge) ); assert_matches!( pair.client_datagrams(client_ch) - .send(Bytes::from_static(&[0; 2]), None, 0), + .send(Bytes::from_static(&[0; 2]), Default::default()), Err(SendDatagramError::TooLarge) ); } @@ -3138,7 +3150,7 @@ fn datagram_unsupported() { assert_matches!(pair.server_conn_mut(server_ch).poll(), None); assert_matches!(pair.client_datagrams(client_ch).max_size(), None); - match pair.client_datagrams(client_ch).send(Bytes::new(), None, 0) { + match pair.client_datagrams(client_ch).send(Bytes::new(), Default::default()) { Err(SendDatagramError::UnsupportedByPeer) => {} Err(e) => panic!("unexpected error: {e}"), Ok(_) => panic!("unexpected success"), @@ -3188,7 +3200,7 @@ fn finish_acked() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); @@ -3247,7 +3259,7 @@ fn finish_retransmit() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); @@ -3304,7 +3316,7 @@ fn repeated_request_response() { const REQUEST: &[u8] = b"hello"; const RESPONSE: &[u8] = b"world"; for _ in 0..3 { - let s = pair.client_streams(client_ch).open(Dir::Bi).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Bi, Default::default()).unwrap(); pair.client_send(client_ch, s).write(REQUEST).unwrap(); pair.client_send(client_ch, s).finish().unwrap(); @@ -3818,7 +3830,7 @@ fn blackhole_after_mtu_change_repairs_itself() { // The payload will be sent in a single packet, because the detected MTU was 1444, but it will // be dropped because the link no longer supports that packet size! let payload = vec![42; 1300]; - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s).write(&payload).unwrap(); let out_of_bounds = pair.drive_bounded(); @@ -3866,7 +3878,7 @@ fn packet_splitting_with_default_mtu() { let (client_ch, _) = pair.connect(); pair.drive(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s).write(&payload).unwrap(); pair.client.drive(pair.time, pair.server.addr); @@ -3887,7 +3899,7 @@ fn packet_splitting_not_necessary_after_higher_mtu_discovered() { let (client_ch, _) = pair.connect(); pair.drive(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s).write(&payload).unwrap(); pair.client.drive(pair.time, pair.server.addr); @@ -4428,7 +4440,7 @@ fn pure_sender_voluntarily_acks() { for _ in 0..100 { const MSG: &[u8] = b"hello"; pair.client_datagrams(client_ch) - .send(Bytes::from_static(MSG), None, 0) + .send(Bytes::from_static(MSG), Default::default()) .unwrap(); pair.drive(); assert_eq!(pair.server_datagrams(server_ch).recv().unwrap(), MSG); @@ -4537,7 +4549,7 @@ fn stream_gso() { config.transport = Arc::new(cubic_transport()); let (client_ch, _) = pair.connect_with(config); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let initial_ios = pair.client_conn_mut(client_ch).stats().udp_tx.ios; @@ -4562,7 +4574,7 @@ fn datagram_gso() { // Sending ack-eliciting packet from server let client send ACK, which prevents // sending bundled ACK for a while. pair.server_datagrams(server_ch) - .send(Bytes::new(), None, 0) + .send(Bytes::new(), Default::default()) .unwrap(); pair.drive(); @@ -4576,7 +4588,7 @@ fn datagram_gso() { const DATAGRAMS: usize = 10; for _ in 0..DATAGRAMS { pair.client_datagrams(client_ch) - .send(Bytes::from_static(&[0; DATAGRAM_LEN]), None, 0) + .send(Bytes::from_static(&[0; DATAGRAM_LEN]), Default::default()) .unwrap(); } pair.drive(); @@ -4605,7 +4617,7 @@ fn gso_truncation() { const SIZES: [usize; 3] = [1024, 768, 768]; for len in SIZES { pair.client_datagrams(client_ch) - .send(vec![0; len].into(), None, 0) + .send(vec![0; len].into(), Default::default()) .unwrap(); } pair.drive(); @@ -4670,7 +4682,7 @@ fn min_mtu_does_not_pad_application_data() { let message = Bytes::from_static(b"hello"); pair.client_datagrams(client_ch) - .send(message.clone(), None, 0) + .send(message.clone(), Default::default()) .unwrap(); pair.client.drive(pair.time, pair.server.addr); assert_eq!(pair.client.outbound.len(), 1); @@ -4705,7 +4717,7 @@ fn min_mtu_does_not_pad_zero_rtt_batch_tail() { let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let stream = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let stream = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let data = vec![42; 3_000]; assert_eq!( pair.client_send(client_ch, stream).write(&data), @@ -4770,7 +4782,7 @@ fn min_mtu_limits_application_loss_probes() { let now = pair.time; let client = pair.client_conn_mut(client_ch); client.handle_timeout(now); - let stream = client.streams().open(Dir::Uni).unwrap(); + let stream = client.streams().open(Dir::Uni, Default::default()).unwrap(); client.send_stream(stream).write(&[42; 3000]).unwrap(); let mut buf = Vec::new(); let transmit = client.poll_transmit(now, 1, &mut buf).unwrap(); @@ -4855,10 +4867,10 @@ fn pad_to_mtu() { const LEN_1: usize = 800; const LEN_2: usize = 600; pair.client_datagrams(client_ch) - .send(vec![0; LEN_1].into(), None, 0) + .send(vec![0; LEN_1].into(), Default::default()) .unwrap(); pair.client_datagrams(client_ch) - .send(vec![0; LEN_2].into(), None, 0) + .send(vec![0; LEN_2].into(), Default::default()) .unwrap(); pair.client.drive(pair.time, pair.server.addr); @@ -4914,7 +4926,7 @@ fn large_datagram_with_acks() { let max_size = pair.client_datagrams(client_ch).max_size().unwrap(); let msg = Bytes::from(vec![0; max_size]); pair.client_datagrams(client_ch) - .send(msg.clone(), None, 0) + .send(msg.clone(), Default::default()) .unwrap(); let initial_datagrams = pair.client_conn_mut(client_ch).stats().udp_tx.datagrams; pair.drive(); @@ -4939,7 +4951,7 @@ fn voluntary_ack_with_large_datagrams() { for _ in 0..COUNT { let max_size = pair.client_datagrams(client_ch).max_size().unwrap(); pair.client_datagrams(client_ch) - .send(vec![0; max_size].into(), None, 0) + .send(vec![0; max_size].into(), Default::default()) .unwrap(); pair.drive(); } @@ -4961,7 +4973,7 @@ fn ack_bundled_with_datagrams() { // Send packet from client and then send from server. the packet from server should include ACKs pair.client_datagrams(client_ch) - .send(vec![0; 1].into(), None, 0) + .send(vec![0; 1].into(), Default::default()) .unwrap(); pair.drive_client(); pair.drive_server(); @@ -4971,7 +4983,7 @@ fn ack_bundled_with_datagrams() { pair.server_conn_mut(server_ch).stats().udp_tx.datagrams; pair.server_datagrams(server_ch) - .send(vec![0; 1].into(), None, 0) + .send(vec![0; 1].into(), Default::default()) .unwrap(); pair.drive_server(); @@ -5011,7 +5023,7 @@ fn path_changes_unblock_oversized_datagrams() { let data = Bytes::from(vec![42; old_max]); while pair.server_datagrams(server_ch).send_buffer_space() >= old_max { pair.server_datagrams(server_ch) - .send(data.clone(), None, 0) + .send(data.clone(), Default::default()) .unwrap(); } while pair.server_conn_mut(server_ch).poll().is_some() {} @@ -5051,7 +5063,7 @@ fn path_changes_unblock_oversized_datagrams() { let small = Bytes::from_static(b"small"); pair.server_datagrams(server_ch) - .send(small.clone(), None, 0) + .send(small.clone(), Default::default()) .unwrap(); pair.drive(); assert_eq!(pair.client_datagrams(client_ch).recv(), Some(small)); @@ -5081,7 +5093,7 @@ fn oversized_datagrams_are_dropped() { let data = vec![0; max_size]; while pair.client_datagrams(client_ch).send_buffer_space() >= max_size { pair.client_datagrams(client_ch) - .send(data.clone().into(), None, 0) + .send(data.clone().into(), Default::default()) .unwrap(); } // Set the MTU to a smaller value so the queued datagrams cannot be sent. @@ -5094,7 +5106,7 @@ fn oversized_datagrams_are_dropped() { while sent.is_ok() && pair.client_datagrams(client_ch).send_buffer_space() >= max_size { sent = pair .client_datagrams(client_ch) - .send(data.clone().into(), None, 0); + .send(data.clone().into(), Default::default()); } match sent { Ok(()) => {} @@ -5513,7 +5525,7 @@ fn cwnd_limited_is_not_reported_when_only_pacing_blocks() { let mut pair = Pair::default(); let (client_ch, _) = pair.connect_with(client_cfg); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s) .write(&[42; 64 * 1024]) .unwrap(); @@ -5603,7 +5615,7 @@ fn send_quantum_bounds_the_gso_batch() { let mut pair = Pair::default(); let (client_ch, _) = pair.connect_with(client_cfg); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s) .write(&[42; 64 * 1024]) .unwrap(); @@ -5848,7 +5860,7 @@ fn congestion_callbacks_identify_packets_across_spaces() { pair.drive(); assert!(!pair.client_conn_mut(client_ch).is_handshaking()); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s) .write(&[42; 16 * 1024]) .unwrap(); @@ -5939,7 +5951,7 @@ fn ce_events(log: &PacketLog) -> usize { fn old_ce_marks_report_no_new_congestion() { let _guard = subscribe(); let (mut pair, client_ch, log) = recorded_pair(Default::default()); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s) .write(&[42; 8 * 1024]) .unwrap(); @@ -5970,7 +5982,7 @@ fn invalid_ecn_feedback_reports_no_congestion() { assert!(pair.client_conn_mut(client_ch).using_ecn()); pair.congestion_experienced = true; pair.rewrite_ecn = Some(rewrite); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s) .write(&[42; 16 * 1024]) .unwrap(); @@ -6013,7 +6025,7 @@ fn check_starvation_reported_before_resumed_send(send: impl Fn(&mut Pair, Connec #[test] fn stream_starvation_reported_before_resumed_send() { check_starvation_reported_before_resumed_send(|pair, ch| { - let s = pair.client_streams(ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(ch, s).write(&[42; 1000]).unwrap(); }); } @@ -6022,7 +6034,7 @@ fn stream_starvation_reported_before_resumed_send() { fn datagram_starvation_reported_before_resumed_send() { check_starvation_reported_before_resumed_send(|pair, ch| { pair.client_datagrams(ch) - .send(Bytes::from_static(&[42; 1000]), None, 0) + .send(Bytes::from_static(&[42; 1000]), Default::default()) .unwrap(); }); } @@ -6038,7 +6050,7 @@ fn check_blocked_backlog_is_not_app_limited(factory: PacketRecorderFactory) { pair.drive(); let before = log.lock().unwrap().len(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s) .write(&[42; 64 * 1024]) .unwrap(); @@ -6076,7 +6088,7 @@ fn pacing_blocked_backlog_is_not_app_limited() { fn partial_poll_reports_starvation() { let _guard = subscribe(); let (mut pair, ch, log) = recorded_pair(Default::default()); - let stream = pair.client_streams(ch).open(Dir::Uni).unwrap(); + let stream = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(ch, stream).write(&[42; 1000]).unwrap(); log.lock().unwrap().clear(); let now = pair.time; @@ -6152,7 +6164,7 @@ fn held_credit_spends_connection_window_only() { ); let chs = pair.connect(); let (client_ch, server_ch) = chs; - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let msg = vec![0xAB; 3 * WINDOW]; let (mut sent, mut held) = (0, Credit::default()); @@ -6213,7 +6225,7 @@ fn sender_window_is_not_starvation() { let _guard = subscribe(); let (mut pair, ch, log) = recorded_pair(Default::default()); pair.client_conn_mut(ch).set_send_window(1000); - let stream = pair.client_streams(ch).open(Dir::Uni).unwrap(); + let stream = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!(pair.client_send(ch, stream).write(&[42; 2000]), Ok(1000)); log.lock().unwrap().clear(); pair.drive_client(); @@ -6246,7 +6258,7 @@ fn receiver_credit_is_starvation() { client_cfg.transport = Arc::new(client_transport); let (ch, _) = pair.connect_with(client_cfg); let log = factory.logs.lock().unwrap()[0].clone(); - let stream = pair.client_streams(ch).open(Dir::Uni).unwrap(); + let stream = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!(pair.client_send(ch, stream).write(&[42; 2000]), Ok(1000)); log.lock().unwrap().clear(); pair.drive_client(); @@ -6420,7 +6432,7 @@ fn upload( const CHUNK: [u8; 10_000] = [0; 10_000]; let start = pair.time; - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let mut unsent = total; let mut received = 0; let mut server_stream = None; diff --git a/rs/moq-quic/src/tests/reset_stream_at.rs b/rs/moq-quic/src/tests/reset_stream_at.rs index 4144d3a4974..288030c4c53 100644 --- a/rs/moq-quic/src/tests/reset_stream_at.rs +++ b/rs/moq-quic/src/tests/reset_stream_at.rs @@ -101,7 +101,7 @@ fn stop_sending_abandons_prefix(reset_stream_at: bool) { let (client_ch, server_ch) = pair.connect(); // The server learns of the stream from its first byte - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s).write(&MSG[..1]).unwrap(); pair.drive(); assert_eq!(accept(&mut pair, server_ch), s); @@ -148,7 +148,7 @@ fn delivers_prefix_before_error() { let mut pair = pair(true); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); reset(&mut pair, client_ch, checkpoint).unwrap(); pair.drive(); @@ -174,7 +174,7 @@ fn delivers_unsent_prefix() { let mut pair = pair(true); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s) .write(&MSG[..RELIABLE]) .unwrap(); @@ -195,7 +195,7 @@ fn retransmits_lost_prefix() { let mut pair = pair(true); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); lose_client_packets(&mut pair); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -229,7 +229,7 @@ fn retransmits_lost_reset() { let mut pair = pair(true); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); pair.drive(); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -251,7 +251,7 @@ fn received_reset_after_prefix() { let mut pair = pair(true); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); reset(&mut pair, client_ch, checkpoint).unwrap(); pair.drive(); @@ -282,7 +282,7 @@ fn after_finish() { let (client_ch, server_ch) = pair.connect(); for reliable in [RELIABLE, MSG.len()] { - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let mut checkpoint = write(&mut pair, client_ch, s); if reliable == MSG.len() { checkpoint = pair.client_send(client_ch, s).checkpoint(); @@ -311,7 +311,7 @@ fn flow_control_blocked() { let mut pair = Pair::new(Default::default(), config); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); pair.client_send(client_ch, s) .write(&MSG[..RELIABLE]) .unwrap(); @@ -343,7 +343,7 @@ fn unsupported_holds_reset_until_acked() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -365,7 +365,7 @@ fn unsupported_retransmits_lost_prefix() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); lose_client_packets(&mut pair); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -386,7 +386,7 @@ fn unsupported_resets_at_once_when_acked() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); pair.drive(); assert_eq!(accept(&mut pair, server_ch), s); @@ -412,7 +412,7 @@ fn unsupported_after_finish() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); pair.client_send(client_ch, s).finish().unwrap(); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -445,7 +445,7 @@ fn unsupported_repeated_reset_is_closed() { let mut pair = pair(false); let (client_ch, _) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); let again = pair.client_send(client_ch, s).checkpoint(); lose_client_packets(&mut pair); @@ -464,7 +464,7 @@ fn unsupported_close_while_held() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); lose_client_packets(&mut pair); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -491,10 +491,10 @@ fn unsupported_returns_flow_control() { let mut pair = Pair::new(Default::default(), config); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); reset(&mut pair, client_ch, checkpoint).unwrap(); - let next = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let next = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!( pair.client_send(client_ch, next).write(MSG), Err(WriteError::Blocked) @@ -515,7 +515,7 @@ fn unsupported_allows_zero() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = pair.client_send(client_ch, s).checkpoint(); pair.client_send(client_ch, s).write(MSG).unwrap(); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -534,7 +534,7 @@ fn repeated_reset_is_closed() { let mut pair = pair(true); let (client_ch, _) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); let again = pair.client_send(client_ch, s).checkpoint(); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -573,12 +573,12 @@ fn zero_rtt_rejected_checkpoint_is_closed() { inner.alpn_protocols = vec!["bar".into()]; let client_ch = pair.begin_connect(ClientConfig::new(client_crypto)); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); pair.drive(); assert!(!pair.client_conn_mut(client_ch).accepted_0rtt()); - let reopened = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let reopened = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!(reopened, s); pair.client_send(client_ch, reopened).write(MSG).unwrap(); assert_eq!( @@ -604,9 +604,9 @@ fn checkpoint_from_another_connection() { let mut second = pair(true); let (second_ch, _) = second.connect(); - let s = first.client_streams(first_ch).open(Dir::Uni).unwrap(); + let s = first.client_streams(first_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut first, first_ch, s); - let other = second.client_streams(second_ch).open(Dir::Uni).unwrap(); + let other = second.client_streams(second_ch).open(Dir::Uni, Default::default()).unwrap(); assert_eq!(other, s); second.client_send(second_ch, other).write(MSG).unwrap(); let _ = reset(&mut second, second_ch, checkpoint); @@ -633,7 +633,7 @@ fn zero_rtt() { pair.client.addr = SocketAddr::new(Ipv6Addr::LOCALHOST.into(), pair.next_port()); let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); let checkpoint = write(&mut pair, client_ch, s); reset(&mut pair, client_ch, checkpoint).unwrap(); pair.drive(); diff --git a/rs/moq-quic/src/tests/sim.rs b/rs/moq-quic/src/tests/sim.rs index a551be8e4e2..97cfbf90afc 100644 --- a/rs/moq-quic/src/tests/sim.rs +++ b/rs/moq-quic/src/tests/sim.rs @@ -253,7 +253,7 @@ impl Peer { for (index, sending) in self.sends.iter_mut().enumerate() { let id = match sending.id { Some(id) => id, - None => match conn.streams().open(Dir::Uni) { + None => match conn.streams().open(Dir::Uni, Default::default()) { Some(id) => { assert_eq!(id.index(), index as u64); conn.send_stream(id) diff --git a/rs/moq-relay/tests/integration/peer_limits.rs b/rs/moq-relay/tests/integration/peer_limits.rs index d9ab129570d..1294aeef997 100644 --- a/rs/moq-relay/tests/integration/peer_limits.rs +++ b/rs/moq-relay/tests/integration/peer_limits.rs @@ -72,7 +72,7 @@ async fn probe(port: u16, peer: bool) -> Seen { .expect("handshake"); // SETUP type, then a one-byte message holding zero parameters. - let mut setup = conn.open_uni().await.expect("open"); + let mut setup = conn.open_uni(Default::default()).await.expect("open"); setup.write_all(&[0x01, 0x01, 0x00]).await.expect("write"); setup.finish().expect("finish"); @@ -85,7 +85,7 @@ async fn probe(port: u16, peer: bool) -> Seen { let mut streams = Vec::new(); while streams.len() < PROBE { - let open = conn.open_uni(); + let open = conn.open_uni(Default::default()); let stream = match peer { true => tokio::time::timeout(TIMEOUT, open) .await @@ -253,7 +253,7 @@ async fn cluster_dials_widen_a_plain_client() { let mut streams = Vec::new(); while streams.len() < PROBE { - match conn.open_uni().now_or_never() { + match conn.open_uni(Default::default()).now_or_never() { Some(stream) => streams.push(stream.expect("open")), None => break, } diff --git a/rs/moq-tokio/src/quic/driver/connection.rs b/rs/moq-tokio/src/quic/driver/connection.rs index 8de19c76139..040ab2536d5 100644 --- a/rs/moq-tokio/src/quic/driver/connection.rs +++ b/rs/moq-tokio/src/quic/driver/connection.rs @@ -25,7 +25,9 @@ use tracing::{Instrument, Span, debug_span}; use crate::quic::driver::{ ConnectionEvent, Duration, Instant, VarInt, mutex::Mutex, recv_stream::RecvStream, - runtime::UdpSender, send_group::SendGroup, send_stream::SendStream, udp_transmit, + runtime::UdpSender, + send_group::{self, SendGroup, SendOptions}, + send_stream::SendStream, udp_transmit, }; use moq_quic::{ ConnectionError, ConnectionHandle, ConnectionStats, Dir, EndpointEvent, Side, StreamEvent, @@ -334,26 +336,31 @@ impl Future for ConnectionDriver { pub struct Connection(ConnectionRef); impl Connection { - /// Initiate a new outgoing unidirectional stream. + /// Initiate a new outgoing unidirectional stream, scheduled by `options`. /// /// Streams are cheap and instantaneous to open unless blocked by flow control. As a /// consequence, the peer won't be notified that a stream has been opened until the stream is /// actually used. - pub fn open_uni(&self) -> OpenUni<'_> { + /// + /// # Panics + /// - when `options.group` belongs to another connection + pub fn open_uni<'a>(&'a self, options: SendOptions<'a>) -> OpenUni<'a> { OpenUni { conn: &self.0, + options, notify: self.0.shared.stream_budget_available[Dir::Uni as usize].notified(), } } - /// Open a send group at `priority`, for streams to join with [`SendStream::set_group`]. + /// Open a send group at `priority`, for streams and datagrams to join with [`SendOptions`] + /// or [`SendStream::set_group`]. /// /// [`SendStream::set_group`]: crate::quic::driver::SendStream::set_group pub fn send_group(&self, priority: i64) -> SendGroup { SendGroup::new(self.0.0.clone(), priority) } - /// Initiate a new outgoing bidirectional stream. + /// Initiate a new outgoing bidirectional stream, its sending half scheduled by `options`. /// /// Streams are cheap and instantaneous to open unless blocked by flow control. As a /// consequence, the peer won't be notified that a stream has been opened until the stream is @@ -363,9 +370,13 @@ impl Connection { /// [`open_bi()`]: crate::quic::driver::Connection::open_bi /// [`SendStream`]: crate::quic::driver::SendStream /// [`RecvStream`]: crate::quic::driver::RecvStream - pub fn open_bi(&self) -> OpenBi<'_> { + /// + /// # Panics + /// - when `options.group` belongs to another connection + pub fn open_bi<'a>(&'a self, options: SendOptions<'a>) -> OpenBi<'a> { OpenBi { conn: &self.0, + options, notify: self.0.shared.stream_budget_available[Dir::Bi as usize].notified(), } } @@ -521,21 +532,19 @@ impl Connection { } } - /// Transmit `data` as an unreliable, unordered application datagram in `group` at `order` + /// Transmit `data` as an unreliable application datagram, scheduled by `options` /// /// Application datagrams are a low-level primitive. They may be lost or delivered out of order, /// and `data` must both fit inside a single QUIC packet and be smaller than the maximum /// dictated by the peer. /// - /// The datagram is scheduled like one of the group's streams at priority `order`, or among - /// the ungrouped streams without a group. Sending never blocks: a full buffer drops the - /// oldest datagram of the lowest-priority group, see [`moq_quic::Datagrams::send`]. - pub fn send_datagram( - &self, - data: Bytes, - group: Option<&SendGroup>, - order: i64, - ) -> Result<(), SendDatagramError> { + /// The datagram is scheduled like one of its group's streams at its priority, or among the + /// ungrouped streams without a group. Sending never blocks: a full buffer drops the oldest + /// datagram of the lowest-priority group, see [`moq_quic::Datagrams::send`]. + /// + /// # Panics + /// - when `options.group` belongs to another connection + pub fn send_datagram(&self, data: Bytes, options: SendOptions<'_>) -> Result<(), SendDatagramError> { let conn = &mut *self.0.state.lock("send_datagram"); if let Some(x) = &conn.error { return Err(SendDatagramError::ConnectionLost(x.clone())); @@ -544,7 +553,7 @@ impl Connection { match conn .inner .datagrams() - .send(data, group.map(SendGroup::id), order) + .send(data, send_group::to_quic(options)) { Ok(()) => { conn.wake(); @@ -554,6 +563,7 @@ impl Connection { UnsupportedByPeer => SendDatagramError::UnsupportedByPeer, Disabled => SendDatagramError::Disabled, TooLarge => SendDatagramError::TooLarge, + e => unreachable!("unmapped datagram error: {e}"), }), } } @@ -800,6 +810,7 @@ pin_project! { /// Future produced by [`Connection::open_uni`] pub struct OpenUni<'a> { conn: &'a ConnectionRef, + options: SendOptions<'a>, #[pin] notify: Notified<'a>, } @@ -809,7 +820,7 @@ impl Future for OpenUni<'_> { type Output = Result; fn poll(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll { let this = self.project(); - let (conn, id, is_0rtt) = ready!(poll_open(ctx, this.conn, this.notify, Dir::Uni))?; + let (conn, id, is_0rtt) = ready!(poll_open(ctx, this.conn, *this.options, this.notify, Dir::Uni))?; Poll::Ready(Ok(SendStream::new(conn, id, is_0rtt))) } } @@ -818,6 +829,7 @@ pin_project! { /// Future produced by [`Connection::open_bi`] pub struct OpenBi<'a> { conn: &'a ConnectionRef, + options: SendOptions<'a>, #[pin] notify: Notified<'a>, } @@ -827,7 +839,7 @@ impl Future for OpenBi<'_> { type Output = Result<(SendStream, RecvStream), ConnectionError>; fn poll(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll { let this = self.project(); - let (conn, id, is_0rtt) = ready!(poll_open(ctx, this.conn, this.notify, Dir::Bi))?; + let (conn, id, is_0rtt) = ready!(poll_open(ctx, this.conn, *this.options, this.notify, Dir::Bi))?; Poll::Ready(Ok(( SendStream::new(conn.clone(), id, is_0rtt), @@ -839,13 +851,18 @@ impl Future for OpenBi<'_> { fn poll_open<'a>( ctx: &mut Context<'_>, conn: &'a ConnectionRef, + options: SendOptions<'_>, mut notify: Pin<&mut Notified<'a>>, dir: Dir, ) -> Poll> { let mut state = conn.state.lock("poll_open"); if let Some(e) = &state.error { return Poll::Ready(Err(e.clone())); - } else if let Some(id) = state.inner.streams().open(dir) { + } else if let Some(id) = state + .inner + .streams() + .open(dir, send_group::to_quic(options)) + { let is_0rtt = state.inner.side().is_client() && state.inner.is_handshaking(); drop(state); // Release the lock so clone can take it return Poll::Ready(Ok((conn.clone(), id, is_0rtt))); diff --git a/rs/moq-tokio/src/quic/driver/mod.rs b/rs/moq-tokio/src/quic/driver/mod.rs index a20c51650ff..e875391d395 100644 --- a/rs/moq-tokio/src/quic/driver/mod.rs +++ b/rs/moq-tokio/src/quic/driver/mod.rs @@ -79,7 +79,7 @@ pub use crate::quic::driver::recv_stream::{ #[cfg(test)] pub(crate) use crate::quic::driver::runtime::wrap_udp_socket; pub use crate::quic::driver::runtime::{AsyncUdpSocket, UdpSender}; -pub use crate::quic::driver::send_group::SendGroup; +pub use crate::quic::driver::send_group::{SendGroup, SendOptions}; pub use crate::quic::driver::send_stream::{Checkpoint, SendStream, StoppedError, WriteError}; #[cfg(test)] diff --git a/rs/moq-tokio/src/quic/driver/send_group.rs b/rs/moq-tokio/src/quic/driver/send_group.rs index 9e8adc793ff..5270cdd8de7 100644 --- a/rs/moq-tokio/src/quic/driver/send_group.rs +++ b/rs/moq-tokio/src/quic/driver/send_group.rs @@ -8,14 +8,25 @@ use crate::quic::driver::connection::ConnectionInner; /// the connection's other groups: a higher priority group preempts every lower one, and groups /// of equal priority get an equal share of bytes however many streams each has queued. A /// stream's own priority orders it only against the group's other streams, and a datagram sent -/// in the group is ordered among them by its `order`. Streams and datagrams outside any group go -/// before every group. See [`moq_quic::SendGroups`]. +/// in the group is ordered among them by its priority. Streams and datagrams outside any group +/// go before every group. See [`moq_quic::SendGroups`]. /// /// Clones share one group, released once the last clone is dropped and its streams finish /// and its datagrams are sent. A group does not keep its connection open. #[derive(Debug, Clone)] pub struct SendGroup(Arc); +/// How an outgoing stream or datagram is scheduled: its [`SendGroup`] and priority +pub type SendOptions<'a> = moq_quic::SendOptions<'a, SendGroup>; + +/// The options as the connection knows them. +pub(crate) fn to_quic(options: SendOptions<'_>) -> moq_quic::SendOptions<'_> { + moq_quic::SendOptions { + group: options.group.map(SendGroup::id), + priority: options.priority, + } +} + #[derive(Debug)] struct Inner { conn: Arc, @@ -29,7 +40,7 @@ impl SendGroup { .lock("SendGroup::new") .inner .send_groups() - .open(priority, None); + .open(priority); Self(Arc::new(Inner { conn, group: Some(group), diff --git a/rs/moq-tokio/src/quic/driver/tests.rs b/rs/moq-tokio/src/quic/driver/tests.rs index d7846d30e9f..0625a7fdfdd 100755 --- a/rs/moq-tokio/src/quic/driver/tests.rs +++ b/rs/moq-tokio/src/quic/driver/tests.rs @@ -164,7 +164,7 @@ fn read_after_close() { .expect("endpoint") .await .expect("connection"); - let mut s = new_conn.open_uni().await.unwrap(); + let mut s = new_conn.open_uni(Default::default()).await.unwrap(); s.write_all(MSG).await.unwrap(); s.finish().unwrap(); // Wait for the stream to be closed, one way or another. @@ -709,12 +709,12 @@ async fn zero_rtt() { } }); info!("sending 0.5-RTT"); - let mut s = connection.open_uni().await.expect("open_uni"); + let mut s = connection.open_uni(Default::default()).await.expect("open_uni"); s.write_all(MSG0).await.expect("write"); s.finish().unwrap(); connection.authenticated().await.expect("connected"); info!("sending 1-RTT"); - let mut s = connection.open_uni().await.expect("open_uni"); + let mut s = connection.open_uni(Default::default()).await.expect("open_uni"); s.write_all(MSG1).await.expect("write"); // The peer might close the connection before ACKing let _ = s.finish(); @@ -752,7 +752,7 @@ async fn zero_rtt() { .unwrap_or_else(|_| panic!("missing 0-RTT keys")); // Send something before the handshake can make progress, thereby forcing 0-RTT - let mut stream_0rtt = connection.open_uni().await.expect("0-RTT open uni"); + let mut stream_0rtt = connection.open_uni(Default::default()).await.expect("0-RTT open uni"); info!("sending 0-RTT"); stream_0rtt.write_all(MSG0).await.expect("0-RTT write"); stream_0rtt.finish().unwrap(); @@ -958,7 +958,7 @@ fn run_echo(args: EchoArgs) { for i in 0..args.nr_streams { println!("Opening stream {i}"); - let (mut send, mut recv) = new_conn.open_bi().await.expect("stream open"); + let (mut send, mut recv) = new_conn.open_bi(Default::default()).await.expect("stream open"); let msg = gen_data(args.stream_size, SEED); let send_task = async { @@ -1130,7 +1130,7 @@ async fn rebind_recv() { info!("got conn"); connected_send.notify_one(); write_recv.notified().await; - let mut stream = connection.open_uni().await.unwrap(); + let mut stream = connection.open_uni(Default::default()).await.unwrap(); stream.write_all(MSG).await.unwrap(); stream.finish().unwrap(); // Wait for the stream to be closed, one way or another. @@ -1494,7 +1494,7 @@ async fn remote_address_monitoring() { .unwrap(); // send data from the new socket to trigger migration on the server - let mut stream = client_conn.open_uni().await.unwrap(); + let mut stream = client_conn.open_uni(Default::default()).await.unwrap(); stream.write_all(b"hello").await.unwrap(); stream.finish().unwrap(); }; @@ -1528,13 +1528,13 @@ async fn stream_id_flow_control() { // If `open_uni` doesn't get unblocked when the previous stream is dropped, this will time out. tokio::join!( async { - client.open_uni().await.unwrap(); + client.open_uni(Default::default()).await.unwrap(); }, async { - client.open_uni().await.unwrap(); + client.open_uni(Default::default()).await.unwrap(); }, async { - client.open_uni().await.unwrap(); + client.open_uni(Default::default()).await.unwrap(); }, async { server.accept_uni().await.unwrap(); @@ -1570,9 +1570,9 @@ async fn two_datagram_readers() { x }, async { - server.send_datagram(b"one"[..].into(), None, 0).unwrap(); + server.send_datagram(b"one"[..].into(), Default::default()).unwrap(); done.notified().await; - server.send_datagram(b"two"[..].into(), None, 0).unwrap(); + server.send_datagram(b"two"[..].into(), Default::default()).unwrap(); } ); assert!(*a == *b"one" || *b == *b"one"); @@ -1651,7 +1651,7 @@ async fn stream_stopped() { .unwrap() .await .unwrap(); - let mut stream = conn.open_uni().await.unwrap(); + let mut stream = conn.open_uni(Default::default()).await.unwrap(); let stopped1 = stream.stopped(); let stopped2 = stream.stopped(); let stopped3 = stream.stopped(); @@ -1696,7 +1696,7 @@ async fn stream_stopped_2() { async { endpoint.accept().await.unwrap().await } ) .unwrap(); - let send_stream = conn.open_uni().await.unwrap(); + let send_stream = conn.open_uni(Default::default()).await.unwrap(); let stopped = timeout(Duration::from_millis(100), send_stream.stopped()) .instrument(error_span!("stopped")); tokio::pin!(stopped); @@ -1762,7 +1762,7 @@ async fn stream_drop_removes_blocked_reader() { .unwrap() .await .unwrap(); - let mut stream = conn.open_uni().await.unwrap(); + let mut stream = conn.open_uni(Default::default()).await.unwrap(); // need to send some data to actually start the stream stream.write_all(b"hello").await.unwrap(); @@ -1806,7 +1806,7 @@ async fn recv_stream_cancel_stop_drop() { .unwrap() .await .unwrap(); - let mut send = conn.open_uni().await.unwrap(); + let mut send = conn.open_uni(Default::default()).await.unwrap(); _ = send.write_all(b"hello").await; // Don't drop (finish) the send stream until the read has been // cancelled by the server, ensuring that read_to_end can't complete @@ -1871,7 +1871,7 @@ async fn held_reads_spend_the_connection_window() { async { endpoint.accept().await.unwrap().await } ) .unwrap(); - let mut send = client.open_uni().await.unwrap(); + let mut send = client.open_uni(Default::default()).await.unwrap(); let writer = tokio::spawn(async move { // The receiver walks away before this finishes. let _ = send.write_all(&[7; 4 * WINDOW]).await; @@ -2045,7 +2045,7 @@ async fn unreachable_sends_are_loss_once_established() { let server_conn = server_conn.unwrap(); outage.active.store(true, Ordering::SeqCst); - let mut send = client_conn.open_uni().await.unwrap(); + let mut send = client_conn.open_uni(Default::default()).await.unwrap(); send.write_all(b"hello").await.unwrap(); send.finish().unwrap(); outage.dropped.notified().await; diff --git a/rs/moq-tokio/src/quic/web/connect.rs b/rs/moq-tokio/src/quic/web/connect.rs index d49228d5f44..04888cd5fef 100644 --- a/rs/moq-tokio/src/quic/web/connect.rs +++ b/rs/moq-tokio/src/quic/web/connect.rs @@ -113,7 +113,7 @@ impl Connected { let request = request.into(); // Create a new stream that will be used to send the CONNECT frame. - let (mut send, mut recv) = conn.open_bi().await?; + let (mut send, mut recv) = conn.open_bi(Default::default()).await?; tracing::debug!(?request, "sending CONNECT request"); request.write(&mut send).await?; diff --git a/rs/moq-tokio/src/quic/web/session.rs b/rs/moq-tokio/src/quic/web/session.rs index 3e6f84a0711..d14ed86f191 100644 --- a/rs/moq-tokio/src/quic/web/session.rs +++ b/rs/moq-tokio/src/quic/web/session.rs @@ -13,6 +13,7 @@ use bytes::{Bytes, BytesMut}; use futures::stream::{FuturesUnordered, Stream, StreamExt}; use kio::Waiter; +use crate::quic::driver::SendOptions; use crate::quic::web::fan::Fan; use crate::quic::web::{ ClientError, CloseReason, Connected, RecvStream, SendStream, SessionError, Settings, WebTransportError, @@ -261,40 +262,50 @@ impl Session { } } - /// Open a new unidirectional stream. See [`crate::quic::driver::Connection::open_uni`]. - pub async fn open_uni(&self) -> Result { - let mut send = self.conn.open_uni().await.map_err(|e| self.map_error(e))?; - - // Set the stream priority to max and then write the stream header. + /// Open a new unidirectional stream, its sending half scheduled by `options`. + /// See [`crate::quic::driver::Connection::open_uni`]. + pub async fn open_uni(&self, options: SendOptions<'_>) -> Result { + // Write the stream header ungrouped at the highest priority, before scheduling the stream. // Otherwise the application could write data with lower priority than the header, resulting // in queuing. Also the header is very important for determining the session ID // without reliable reset. - send.set_priority(i64::MAX).ok(); + let header = SendOptions { + group: None, + priority: i64::MAX, + }; + let mut send = self.conn.open_uni(header).await.map_err(|e| self.map_error(e))?; Self::write_full(&mut send, &self.header_uni) .await .map_err(|e| self.map_error(e))?; - // Reset the stream priority back to the default of 0. - send.set_priority(0).ok(); + send.set_priority(options.priority).ok(); + if let Some(group) = options.group { + send.set_group(Some(group)).ok(); + } let header = send.checkpoint(); Ok(SendStream::new(send, self.close.clone(), Some(header))) } - /// Open a new bidirectional stream. See [`crate::quic::driver::Connection::open_bi`]. - pub async fn open_bi(&self) -> Result<(SendStream, RecvStream), SessionError> { - let (mut send, recv) = self.conn.open_bi().await.map_err(|e| self.map_error(e))?; - - // Set the stream priority to max and then write the stream header. + /// Open a new bidirectional stream, its sending half scheduled by `options`. + /// See [`crate::quic::driver::Connection::open_bi`]. + pub async fn open_bi(&self, options: SendOptions<'_>) -> Result<(SendStream, RecvStream), SessionError> { + // Write the stream header ungrouped at the highest priority, before scheduling the stream. // Otherwise the application could write data with lower priority than the header, resulting // in queuing. Also the header is very important for determining the session ID // without reliable reset. - send.set_priority(i64::MAX).ok(); + let header = SendOptions { + group: None, + priority: i64::MAX, + }; + let (mut send, recv) = self.conn.open_bi(header).await.map_err(|e| self.map_error(e))?; Self::write_full(&mut send, &self.header_bi) .await .map_err(|e| self.map_error(e))?; - // Reset the stream priority back to the default of 0. - send.set_priority(0).ok(); + send.set_priority(options.priority).ok(); + if let Some(group) = options.group { + send.set_group(Some(group)).ok(); + } let header = send.checkpoint(); Ok(( SendStream::new(send, self.close.clone(), Some(header)), @@ -326,18 +337,13 @@ impl Session { Ok(datagram) } - /// Sends an application datagram to the remote peer in `group` at `order`. + /// Sends an application datagram to the remote peer, scheduled by `options`. /// /// Datagrams are unreliable and may be dropped or delivered out of order. /// The data must be smaller than [`max_datagram_size`](Self::max_datagram_size). /// See [`Connection::send_datagram`](crate::quic::driver::Connection::send_datagram) for how - /// `group` and `order` schedule it. - pub fn send_datagram( - &self, - data: Bytes, - group: Option<&crate::quic::driver::SendGroup>, - order: i64, - ) -> Result<(), SessionError> { + /// `options` schedule it. + pub fn send_datagram(&self, data: Bytes, options: SendOptions<'_>) -> Result<(), SessionError> { let result = if !self.header_datagram.is_empty() { // Unfortunately, we need to allocate/copy each datagram because of the driver API. // Pls go +1 if you care: https://github.com/quinn-rs/quinn/issues/1724 @@ -347,16 +353,17 @@ impl Session { buf.extend_from_slice(&self.header_datagram); buf.extend_from_slice(&data); - self.conn.send_datagram(buf.into(), group, order) + self.conn.send_datagram(buf.into(), options) } else { - self.conn.send_datagram(data, group, order) + self.conn.send_datagram(data, options) }; result.map_err(|e| self.map_error(e))?; Ok(()) } - /// Open a send group at `priority`, for streams to join with [`SendStream::set_group`]. + /// Open a send group at `priority`, for streams and datagrams to join with [`SendOptions`] + /// or [`SendStream::set_group`]. /// /// See [`crate::quic::driver::SendGroup`]. The HTTP/3 streams stay outside every group, /// so they go first. @@ -991,11 +998,11 @@ impl web_transport_trait::Session for Session { } async fn open_bi(&self) -> Result<(Self::SendStream, Self::RecvStream), Self::Error> { - Self::open_bi(self).await + Self::open_bi(self, SendOptions::default()).await } async fn open_uni(&self) -> Result { - Self::open_uni(self).await + Self::open_uni(self, SendOptions::default()).await } fn close(&self, code: u32, reason: &str) { @@ -1007,7 +1014,7 @@ impl web_transport_trait::Session for Session { } fn send_datagram(&self, data: Bytes) -> Result<(), Self::Error> { - Self::send_datagram(self, data, None, 0) + Self::send_datagram(self, data, SendOptions::default()) } async fn recv_datagram(&self) -> Result { @@ -1233,7 +1240,7 @@ mod tests { let (client, server, _endpoints) = pair().await; // A zero-length reserved frame, so the server sees the stream without a capsule. - let (mut send, _recv) = client.open_bi().await.unwrap(); + let (mut send, _recv) = client.open_bi(Default::default()).await.unwrap(); send.write_all(&[0x21, 0x00]).await.unwrap(); let (_send, recv) = server.accept_bi().await.unwrap(); @@ -1249,7 +1256,7 @@ mod tests { let (client, server, _endpoints) = pair().await; // A DATA frame that promises 5 bytes and carries 1. - let (mut send, _recv) = client.open_bi().await.unwrap(); + let (mut send, _recv) = client.open_bi(Default::default()).await.unwrap(); send.write_all(&[0x00, 0x05, 0x01]).await.unwrap(); send.finish().unwrap(); let (_send, recv) = server.accept_bi().await.unwrap(); @@ -1267,7 +1274,7 @@ mod tests { let (client, server, _endpoints) = pair().await; // The stream type alone, so the reset also cuts off the session ID. - let mut send = client.open_uni().await.unwrap(); + let mut send = client.open_uni(Default::default()).await.unwrap(); send.write_all(&[0x40, 0x54]).await.unwrap(); send.reset(7u32.into()).unwrap(); @@ -1281,7 +1288,7 @@ mod tests { async fn bi_reset_before_header() { let (client, server, _endpoints) = pair().await; - let (mut send, _recv) = client.open_bi().await.unwrap(); + let (mut send, _recv) = client.open_bi(Default::default()).await.unwrap(); send.reset(7u32.into()).unwrap(); let (send, recv) = server.accept_bi().await.unwrap(); @@ -1300,8 +1307,8 @@ mod tests { ); let (client, server) = (client.unwrap(), server.unwrap()); - client.open_uni().await.unwrap().reset(7).unwrap(); - let (mut send, _recv) = client.open_bi().await.unwrap(); + client.open_uni(Default::default()).await.unwrap().reset(7).unwrap(); + let (mut send, _recv) = client.open_bi(Default::default()).await.unwrap(); send.reset(8).unwrap(); let read = async { @@ -1323,7 +1330,7 @@ mod tests { async fn uni_other_session() { let (client, server, _endpoints) = pair().await; - let mut send = client.open_uni().await.unwrap(); + let mut send = client.open_uni(Default::default()).await.unwrap(); send.write_all(&[0x40, 0x54, 0x04]).await.unwrap(); send.finish().unwrap(); diff --git a/rs/moq-tokio/src/quic/web/settings.rs b/rs/moq-tokio/src/quic/web/settings.rs index 034c379ce74..65b69144246 100644 --- a/rs/moq-tokio/src/quic/web/settings.rs +++ b/rs/moq-tokio/src/quic/web/settings.rs @@ -63,7 +63,7 @@ impl Settings { tracing::debug!(?settings, "sending SETTINGS frame"); - let mut send = conn.open_uni().await?; + let mut send = conn.open_uni(Default::default()).await?; settings.write(&mut send).await?; Ok(send) diff --git a/rs/moq-tokio/src/transport.rs b/rs/moq-tokio/src/transport.rs index e908eb41d18..9befc0d04ae 100644 --- a/rs/moq-tokio/src/transport.rs +++ b/rs/moq-tokio/src/transport.rs @@ -337,6 +337,14 @@ impl SendStream { } } + /// Schedule a newly opened stream by its options. + fn schedule(&mut self, options: moq_net::transport::poll::SendOptions<'_, S::Group>) { + self.prioritize(options.priority); + if let Some(group) = options.group { + self.join(group); + } + } + /// Join `group`, deferred like [`prioritize`](Self::prioritize). fn join(&mut self, group: &S::Group) { match self.state.get_mut().unwrap().as_mut() { @@ -866,10 +874,13 @@ impl Grouped for crate::quic::web::Session { fn send_datagram( &self, payload: Bytes, - group: Option<&crate::quic::driver::SendGroup>, - order: i64, + options: moq_net::transport::poll::SendOptions<'_, crate::quic::driver::SendGroup>, ) -> Result<(), Self::Error> { - Self::send_datagram(self, payload, group, order) + let options = crate::quic::driver::SendOptions { + group: options.group, + priority: options.priority, + }; + Self::send_datagram(self, payload, options) } } diff --git a/rs/moq-tokio/src/transport/grouped.rs b/rs/moq-tokio/src/transport/grouped.rs index 42751e5fcbd..cc98c296237 100644 --- a/rs/moq-tokio/src/transport/grouped.rs +++ b/rs/moq-tokio/src/transport/grouped.rs @@ -4,6 +4,8 @@ //! implement them: `pub(crate)` is refused (E0446) because the public adapter's //! `type Group` projects through [`GroupedSend`]. +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, so moq-net's @@ -16,14 +18,13 @@ pub trait Grouped: web_transport_trait::Session { None } - /// Send a datagram in `group` at `order`; a backend without groups ignores both. + /// Send a datagram scheduled by `options`; a backend without groups ignores them. fn send_datagram( &self, payload: bytes::Bytes, - group: Option<&::Group>, - order: i64, + options: SendOptions<'_, ::Group>, ) -> Result<(), Self::Error> { - let _ = (group, order); + let _ = options; web_transport_trait::Session::send_datagram(self, payload) } } diff --git a/rs/moq-tokio/src/transport/owned.rs b/rs/moq-tokio/src/transport/owned.rs index 433022db697..f72fed16451 100644 --- a/rs/moq-tokio/src/transport/owned.rs +++ b/rs/moq-tokio/src/transport/owned.rs @@ -57,11 +57,29 @@ impl> poll::Session fn poll_accept_bi(&mut self, cx: &mut Context<'_>) -> Poll, Self::Error>> { backend::Session::poll_accept_bi(self, cx).map_err(Error) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>) -> Poll> { - backend::Session::poll_open_uni(self, cx).map_err(Error) - } - fn poll_open_bi(&mut self, cx: &mut Context<'_>) -> Poll, Self::Error>> { - backend::Session::poll_open_bi(self, cx).map_err(Error) + fn poll_open_uni( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, ::Group>, + ) -> Poll> { + backend::Session::poll_open_uni(self, cx) + .map_ok(|mut send| { + send.schedule(options); + send + }) + .map_err(Error) + } + fn poll_open_bi( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, ::Group>, + ) -> Poll, Self::Error>> { + backend::Session::poll_open_bi(self, cx) + .map_ok(|(mut send, recv)| { + send.schedule(options); + (send, recv) + }) + .map_err(Error) } fn send_group(&mut self, priority: i64) -> Option<::Group> { self.session.send_group(priority) @@ -69,10 +87,9 @@ impl> poll::Session fn send_datagram( &mut self, payload: Bytes, - group: Option<&::Group>, - order: i64, + options: poll::SendOptions<'_, ::Group>, ) -> Result<(), Self::Error> { - super::Grouped::send_datagram(&self.session, payload, group, order).map_err(Error) + super::Grouped::send_datagram(&self.session, payload, options).map_err(Error) } fn poll_recv_datagram(&mut self, cx: &mut Context<'_>) -> Poll> { backend::Session::poll_recv_datagram(self, cx).map_err(Error) diff --git a/rs/moq-tokio/tests/integration/stream_code.rs b/rs/moq-tokio/tests/integration/stream_code.rs index 508a56db8d1..97953fe78c6 100644 --- a/rs/moq-tokio/tests/integration/stream_code.rs +++ b/rs/moq-tokio/tests/integration/stream_code.rs @@ -91,12 +91,12 @@ async fn refused_code(server: &Server, alpn: &str) -> Option { .expect("handshake"); // SETUP type, then a one-byte message holding zero parameters. - let mut setup = conn.open_uni().await.expect("open"); + let mut setup = conn.open_uni(Default::default()).await.expect("open"); setup.write_all(&[0x01, 0x01, 0x00]).await.expect("write"); setup.finish().expect("finish"); // GROUP type, then a three-byte header: subscribe 7, sequence 0, frame start 0. - let mut send = conn.open_uni().await.expect("open"); + let mut send = conn.open_uni(Default::default()).await.expect("open"); send.write_all(&[0x00, 0x03, 0x07, 0x00, 0x00]).await.expect("write"); tokio::time::timeout(Duration::from_secs(10), send.stopped()) diff --git a/rs/moq-uring/benches/echo_quic.rs b/rs/moq-uring/benches/echo_quic.rs index 8d99a769317..f499edd2b40 100644 --- a/rs/moq-uring/benches/echo_quic.rs +++ b/rs/moq-uring/benches/echo_quic.rs @@ -82,7 +82,7 @@ mod linux { let session = client.connect(request).await.expect("connect"); let payload = vec![0x5a; PAYLOAD]; while let Ok(done) = start_rx.recv() { - let (mut send, mut recv) = session.open_bi().await.expect("open stream"); + let (mut send, mut recv) = session.open_bi(Default::default()).await.expect("open stream"); send.write_all(&payload).await.expect("write"); send.finish().expect("finish"); assert_eq!(recv.read_to_end(PAYLOAD + 1).await.expect("read").len(), PAYLOAD); diff --git a/rs/moq-uring/src/quic/driver/connection.rs b/rs/moq-uring/src/quic/driver/connection.rs index 3f8f063eaae..b561aea10cb 100644 --- a/rs/moq-uring/src/quic/driver/connection.rs +++ b/rs/moq-uring/src/quic/driver/connection.rs @@ -313,17 +313,21 @@ impl Connection { } /// Open a send group at `priority`, for streams to join with - /// [`SendStream::set_group`](super::SendStream::set_group). + /// [`SendStream::set_group`](super::SendStream::set_group) and datagrams with + /// [`SendOptions`](super::SendOptions). pub fn send_group(&self, priority: i64) -> super::SendGroup { super::SendGroup::new(self.shared.clone(), priority) } - /// Send a datagram in `group` at `order`, scheduled like one of the group's streams at - /// priority `order`, or among the ungrouped streams without a group. + /// Send a datagram scheduled by `options`, like one of its group's streams at its priority, + /// or among the ungrouped streams without a group. /// /// Never blocks: a full buffer drops the oldest datagram of the lowest-priority group, /// see [`moq_quic::Datagrams::send`]. - pub fn send_datagram(&self, payload: Bytes, group: Option<&super::SendGroup>, order: i64) -> Result<(), Error> { + /// + /// # Panics + /// - when `options.group` belongs to another connection + pub fn send_datagram(&self, payload: Bytes, options: super::SendOptions<'_>) -> Result<(), Error> { if let Some(err) = self.shared.closed() { return Err(err); } @@ -331,7 +335,7 @@ impl Connection { .conn .borrow_mut() .datagrams() - .send(payload, group.map(super::SendGroup::id), order) + .send(payload, super::group::to_quic(options)) .map_err(|err| Error::Quic(err.to_string()))?; self.shared.kick(); Ok(()) @@ -575,7 +579,7 @@ impl web_transport_trait::poll::Session for Connection { } // The peer's MAX_STREAMS credit is what gates us: `open` hands back // nothing while it is spent. - let opened = self.shared.conn.borrow_mut().streams().open(Dir::Uni); + let opened = self.shared.conn.borrow_mut().streams().open(Dir::Uni, Default::default()); match opened { Some(id) => Poll::Ready(Ok(super::SendStream::new(self.shared.clone(), id))), None => { @@ -594,7 +598,7 @@ impl web_transport_trait::poll::Session for Connection { if let Some(err) = self.shared.closed() { return Poll::Ready(Err(err)); } - let opened = self.shared.conn.borrow_mut().streams().open(Dir::Bi); + let opened = self.shared.conn.borrow_mut().streams().open(Dir::Bi, Default::default()); match opened { Some(id) => Poll::Ready(Ok(( super::SendStream::new(self.shared.clone(), id), @@ -609,7 +613,7 @@ impl web_transport_trait::poll::Session for Connection { } fn poll_send_datagram(&mut self, _: &mut Context<'_>, payload: &[u8]) -> Poll> { - Poll::Ready(Self::send_datagram(self, Bytes::copy_from_slice(payload), None, 0)) + Poll::Ready(Self::send_datagram(self, Bytes::copy_from_slice(payload), Default::default())) } fn poll_recv_datagram(&mut self, cx: &mut Context<'_>) -> Poll> { diff --git a/rs/moq-uring/src/quic/driver/group.rs b/rs/moq-uring/src/quic/driver/group.rs index bbe81976a84..54861086322 100644 --- a/rs/moq-uring/src/quic/driver/group.rs +++ b/rs/moq-uring/src/quic/driver/group.rs @@ -10,7 +10,7 @@ use super::Shared; /// connection's other groups: a higher priority group preempts every lower one, and groups of /// equal priority get an equal share of bytes however many streams each has queued. A stream's /// own priority orders it only against the group's other streams, and a datagram sent in the -/// group is ordered among them by its `order`. Streams and datagrams outside any group go +/// group is ordered among them by its priority. Streams and datagrams outside any group go /// before every group. See [`moq_quic::SendGroups`]. /// /// Clones share one group, released once the last clone is dropped and its streams finish @@ -18,6 +18,17 @@ use super::Shared; #[derive(Clone)] pub struct SendGroup(Rc); +/// How an outgoing datagram is scheduled: its [`SendGroup`] and priority. +pub type SendOptions<'a> = moq_quic::SendOptions<'a, SendGroup>; + +/// The options as the connection knows them. +pub(crate) fn to_quic(options: SendOptions<'_>) -> moq_quic::SendOptions<'_> { + moq_quic::SendOptions { + group: options.group.map(SendGroup::id), + priority: options.priority, + } +} + struct Inner { shared: Shared, group: Option, @@ -25,7 +36,7 @@ struct Inner { impl SendGroup { pub(crate) fn new(shared: Shared, priority: i64) -> Self { - let group = shared.conn.borrow_mut().send_groups().open(priority, None); + let group = shared.conn.borrow_mut().send_groups().open(priority); Self(Rc::new(Inner { shared, group: Some(group), diff --git a/rs/moq-uring/src/quic/driver/mod.rs b/rs/moq-uring/src/quic/driver/mod.rs index cd6d5a77ae0..87f5bccbe8b 100644 --- a/rs/moq-uring/src/quic/driver/mod.rs +++ b/rs/moq-uring/src/quic/driver/mod.rs @@ -16,7 +16,7 @@ mod stream; pub use connection::Connection; pub use endpoint::Endpoint; -pub use group::SendGroup; +pub use group::{SendGroup, SendOptions}; pub use stream::{Credit, RecvStream, SendStream}; pub(crate) use connection::{End, Shared}; diff --git a/rs/moq-uring/src/quic/mod.rs b/rs/moq-uring/src/quic/mod.rs index 32cfb5908be..144eec19bac 100644 --- a/rs/moq-uring/src/quic/mod.rs +++ b/rs/moq-uring/src/quic/mod.rs @@ -30,7 +30,7 @@ pub mod web; mod driver; -pub use driver::{Connection, Credit, RecvStream, SendGroup, SendStream}; +pub use driver::{Connection, Credit, RecvStream, SendGroup, SendOptions, SendStream}; pub use endpoint::Endpoint; /// The QUIC payload size every full datagram in a GSO train uses, and the diff --git a/rs/moq-uring/src/quic/web.rs b/rs/moq-uring/src/quic/web.rs index b688ece4c32..e0c32214772 100644 --- a/rs/moq-uring/src/quic/web.rs +++ b/rs/moq-uring/src/quic/web.rs @@ -452,18 +452,18 @@ impl Session { self.conn.send_group(priority) } - /// Send a datagram in `group` at `order`, scheduled like one of the group's streams. + /// Send a datagram scheduled by `options`, like one of its group's streams. /// /// See [`Connection::send_datagram`]. - pub fn send_datagram(&self, payload: Bytes, group: Option<&super::SendGroup>, order: i64) -> Result<(), Error> { + pub fn send_datagram(&self, payload: Bytes, options: super::SendOptions<'_>) -> Result<(), Error> { let Some(web) = &self.web else { - return self.conn.send_datagram(payload, group, order); + return self.conn.send_datagram(payload, options); }; let mut framed = BytesMut::with_capacity(web.header_datagram.len() + payload.len()); framed.extend_from_slice(&web.header_datagram); framed.extend_from_slice(&payload); self.conn - .send_datagram(framed.freeze(), group, order) + .send_datagram(framed.freeze(), options) .map_err(unmap_err) } @@ -692,7 +692,7 @@ impl web_transport_trait::poll::Session for Session { } fn poll_send_datagram(&mut self, _: &mut Context<'_>, payload: &[u8]) -> Poll> { - Poll::Ready(Self::send_datagram(self, Bytes::copy_from_slice(payload), None, 0)) + Poll::Ready(Self::send_datagram(self, Bytes::copy_from_slice(payload), Default::default())) } fn poll_recv_datagram(&mut self, cx: &mut Context<'_>) -> Poll> { diff --git a/rs/moq-uring/src/transport.rs b/rs/moq-uring/src/transport.rs index b77abb15754..34ea2f3c577 100644 --- a/rs/moq-uring/src/transport.rs +++ b/rs/moq-uring/src/transport.rs @@ -16,10 +16,13 @@ impl Grouped for quic::web::Session { fn send_datagram( &mut self, payload: bytes::Bytes, - group: Option<&quic::SendGroup>, - order: i64, + options: moq_net::transport::poll::SendOptions<'_, quic::SendGroup>, ) -> Result<(), Self::Error> { - quic::web::Session::send_datagram(self, payload, group, order) + let options = quic::SendOptions { + group: options.group, + priority: options.priority, + }; + quic::web::Session::send_datagram(self, payload, options) } } diff --git a/rs/moq-uring/src/transport/adapter.rs b/rs/moq-uring/src/transport/adapter.rs index 0f4ff4dc4ce..e1062ac9e8a 100644 --- a/rs/moq-uring/src/transport/adapter.rs +++ b/rs/moq-uring/src/transport/adapter.rs @@ -63,15 +63,14 @@ pub trait Grouped: backend::Session { None } - /// Send a datagram in `group` at `order`; a backend without groups ignores both and + /// Send a datagram scheduled by `options`; a backend without groups ignores them and /// drops the datagram when it has no room. fn send_datagram( &mut self, payload: Bytes, - group: Option<&::Group>, - order: i64, + options: poll::SendOptions<'_, ::Group>, ) -> Result<(), Self::Error> { - let _ = (group, order); + let _ = options; let mut cx = Context::from_waker(std::task::Waker::noop()); match backend::Session::poll_send_datagram(self, &mut cx, &payload) { Poll::Ready(res) => res, @@ -119,26 +118,21 @@ impl + Clone + 'static> pol .map_err(Error) .map(|res| res.map(|(send, recv)| (SendStream(send), RecvStream(recv)))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>) -> Poll> { + fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, ::Group>) -> Poll> { backend::Session::poll_open_uni(&mut self.0, cx) .map_err(Error) - .map(|res| res.map(SendStream)) + .map(|res| res.map(|send| SendStream(send).scheduled(options))) } - fn poll_open_bi(&mut self, cx: &mut Context<'_>) -> Poll, Self::Error>> { + fn poll_open_bi(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, ::Group>) -> Poll, Self::Error>> { backend::Session::poll_open_bi(&mut self.0, cx) .map_err(Error) - .map(|res| res.map(|(send, recv)| (SendStream(send), RecvStream(recv)))) + .map(|res| res.map(|(send, recv)| (SendStream(send).scheduled(options), RecvStream(recv)))) } fn send_group(&mut self, priority: i64) -> Option<::Group> { Grouped::send_group(&mut self.0, priority) } - fn send_datagram( - &mut self, - payload: Bytes, - group: Option<&::Group>, - order: i64, - ) -> Result<(), Self::Error> { - Grouped::send_datagram(&mut self.0, payload, group, order).map_err(Error) + fn send_datagram(&mut self, payload: Bytes, options: poll::SendOptions<'_, ::Group>) -> Result<(), Self::Error> { + Grouped::send_datagram(&mut self.0, payload, options).map_err(Error) } fn poll_recv_datagram(&mut self, cx: &mut Context<'_>) -> Poll> { backend::Session::poll_recv_datagram(&mut self.0, cx).map_err(Error) @@ -164,6 +158,16 @@ impl + Clone + 'static> pol } /// An outgoing WebTransport stream adapted to moq-net. pub struct SendStream(S); +impl SendStream { + /// Schedule a newly opened stream by its options. + fn scheduled(mut self, options: poll::SendOptions<'_, S::Group>) -> Self { + GroupedSend::set_priority(&mut self.0, options.priority); + if let Some(group) = options.group { + GroupedSend::set_group(&mut self.0, group); + } + self + } +} impl poll::SendStream for SendStream { type Error = Error; type Group = S::Group; @@ -362,7 +366,7 @@ mod tests { poll::Session::stats(&session).rtt(), Some(std::time::Duration::from_millis(7)) ); - let Poll::Ready(Ok((mut send, mut recv))) = poll::Session::poll_open_bi(&mut session, &mut cx) else { + let Poll::Ready(Ok((mut send, mut recv))) = poll::Session::poll_open_bi(&mut session, &mut cx, Default::default()) else { panic!("open failed") }; let mut buf = Bytes::from_static(b"abcd"); diff --git a/rs/moq-uring/tests/integration/echo.rs b/rs/moq-uring/tests/integration/echo.rs index ebf521e3e45..10a99e3464f 100644 --- a/rs/moq-uring/tests/integration/echo.rs +++ b/rs/moq-uring/tests/integration/echo.rs @@ -85,7 +85,7 @@ fn echo_tokio_peer() { url::Url::parse(&format!("https://{addr}/echo")).expect("url"), ); let session = client.connect(request).await.expect("connect"); - let (mut send, mut recv) = session.open_bi().await.expect("open stream"); + let (mut send, mut recv) = session.open_bi(Default::default()).await.expect("open stream"); send.write_all(&payload).await.expect("write"); send.finish().expect("finish"); let echoed = recv.read_to_end(PAYLOAD + 1).await.expect("read"); diff --git a/rs/moq-uring/tests/integration/web.rs b/rs/moq-uring/tests/integration/web.rs index c6aaf4e7783..648a21afa77 100644 --- a/rs/moq-uring/tests/integration/web.rs +++ b/rs/moq-uring/tests/integration/web.rs @@ -128,13 +128,13 @@ fn webtransport_echo_end_to_end() { let client = tokio_client(format!("https://{addr}/echo?token=abc"), |session| { Box::pin(async move { // Bidirectional echo. - let (mut send, mut recv) = session.open_bi().await.expect("open_bi"); + let (mut send, mut recv) = session.open_bi(Default::default()).await.expect("open_bi"); send.write_all(PAYLOAD).await.expect("write"); send.finish().expect("finish"); assert_eq!(read_all(&mut recv).await, PAYLOAD, "bidi echo"); // Unidirectional, both directions. - let mut send = session.open_uni().await.expect("open_uni"); + let mut send = session.open_uni(Default::default()).await.expect("open_uni"); send.write_all(PAYLOAD).await.expect("write"); send.finish().expect("finish"); let mut recv = session.accept_uni().await.expect("accept_uni"); @@ -142,7 +142,7 @@ fn webtransport_echo_end_to_end() { // Datagram echo. session - .send_datagram(PAYLOAD.to_vec().into(), None, 0) + .send_datagram(PAYLOAD.to_vec().into(), Default::default()) .expect("send datagram"); let echoed = session.read_datagram().await.expect("read datagram"); assert_eq!(&echoed[..], PAYLOAD, "datagram echo"); @@ -499,7 +499,7 @@ fn a_dropped_stream_carries_a_webtransport_code() { assert_eq!(&buf[..n], PAYLOAD); // Tell it we have the payload, so the reset below cannot race it. - let mut ack = session.open_uni().await.expect("open_uni"); + let mut ack = session.open_uni(Default::default()).await.expect("open_uni"); ack.write_all(b"ack").await.expect("write"); ack.finish().expect("finish"); @@ -508,7 +508,7 @@ fn a_dropped_stream_carries_a_webtransport_code() { // And the other direction: the server drops the read half of this // one, which must arrive as a WebTransport cancellation too. - let mut send = session.open_uni().await.expect("open_uni"); + let mut send = session.open_uni(Default::default()).await.expect("open_uni"); let err = loop { match send.write_all(PAYLOAD).await { Ok(()) => tokio::task::yield_now().await, @@ -605,7 +605,7 @@ fn a_reset_stream_keeps_its_header() { let err = recv.read_chunk(usize::MAX).await.expect_err("the server reset it"); assert!(matches!(err, moq_tokio::quic::web::ReadError::Reset(7)), "got {err:?}"); - session.open_uni().await.expect("open_uni").reset(8).expect("reset"); + session.open_uni(Default::default()).await.expect("open_uni").reset(8).expect("reset"); session.closed().await; }) }); diff --git a/rs/moq-wasm/src/transport/adapter.rs b/rs/moq-wasm/src/transport/adapter.rs index 46a2c8ff250..464f5c483ae 100644 --- a/rs/moq-wasm/src/transport/adapter.rs +++ b/rs/moq-wasm/src/transport/adapter.rs @@ -67,22 +67,22 @@ impl + Clone + 'st .map_err(Error) .map(|res| res.map(|(send, recv)| (SendStream(send), RecvStream(recv)))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>) -> Poll> { + fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, poll::Ungrouped>) -> Poll> { backend::Session::poll_open_uni(&mut self.0, cx) .map_err(Error) - .map(|res| res.map(SendStream)) + .map(|res| res.map(|send| SendStream(send).scheduled(options))) } - fn poll_open_bi(&mut self, cx: &mut Context<'_>) -> Poll, Self::Error>> { + fn poll_open_bi(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, poll::Ungrouped>) -> Poll, Self::Error>> { backend::Session::poll_open_bi(&mut self.0, cx) .map_err(Error) - .map(|res| res.map(|(send, recv)| (SendStream(send), RecvStream(recv)))) + .map(|res| res.map(|(send, recv)| (SendStream(send).scheduled(options), RecvStream(recv)))) } fn send_group(&mut self, _: i64) -> Option { None } - /// The backend cannot rank a datagram against a stream, so the group and order are ignored, - /// and a datagram it has no room for is dropped. - fn send_datagram(&mut self, payload: Bytes, _: Option<&poll::Ungrouped>, _: i64) -> Result<(), Self::Error> { + /// The backend cannot rank a datagram against a stream, so `options` are ignored, and a + /// datagram it has no room for is dropped. + fn send_datagram(&mut self, payload: Bytes, _: poll::SendOptions<'_, poll::Ungrouped>) -> Result<(), Self::Error> { let mut cx = Context::from_waker(std::task::Waker::noop()); match backend::Session::poll_send_datagram(&mut self.0, &mut cx, &payload) { Poll::Ready(res) => res.map_err(Error), @@ -113,6 +113,13 @@ impl + Clone + 'st } /// An outgoing WebTransport stream adapted to moq-net. pub struct SendStream(S); +impl SendStream { + /// Schedule a newly opened stream, which has no group to join. + fn scheduled(mut self, options: poll::SendOptions<'_, poll::Ungrouped>) -> Self { + poll::SendStream::set_priority(&mut self, options.priority); + self + } +} impl poll::SendStream for SendStream { type Error = Error; type Group = poll::Ungrouped; @@ -293,7 +300,7 @@ mod tests { poll::Session::stats(&session).rtt(), Some(std::time::Duration::from_millis(7)) ); - let Poll::Ready(Ok((mut send, mut recv))) = poll::Session::poll_open_bi(&mut session, &mut cx) else { + let Poll::Ready(Ok((mut send, mut recv))) = poll::Session::poll_open_bi(&mut session, &mut cx, Default::default()) else { panic!("open failed") }; let mut buf = Bytes::from_static(b"abcd"); From a3acda95d147fd597341a81f3b68554207523205 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 17 Oct 2026 08:20:36 -0700 Subject: [PATCH 2/6] style: fmt --- rs/moq-ffi/src/transport/adapter.rs | 16 +- rs/moq-net/src/client.rs | 24 +- rs/moq-net/src/coding/stream.rs | 8 +- rs/moq-net/src/ietf/adapter.rs | 21 +- rs/moq-net/src/ietf/publisher.rs | 2 +- rs/moq-net/src/ietf/session.rs | 5 +- rs/moq-net/src/lite/publisher.rs | 12 +- rs/moq-net/src/lite/session.rs | 3 +- rs/moq-net/src/lite/test_transport.rs | 59 +++- rs/moq-net/src/server.rs | 6 +- rs/moq-net/src/transport.rs | 10 +- rs/moq-net/src/transport/memory.rs | 13 +- rs/moq-net/tests/integration/goaway.rs | 6 +- .../tests/integration/subscribe_tracks.rs | 15 +- rs/moq-net/tests/integration/support/mock.rs | 12 +- rs/moq-quic/benches/receive.rs | 15 +- rs/moq-quic/benches/streams.rs | 5 +- rs/moq-quic/src/connection/datagrams.rs | 6 +- rs/moq-quic/src/connection/streams/mod.rs | 7 +- rs/moq-quic/src/fuzz/connection.rs | 9 +- rs/moq-quic/src/tests/characterize/limits.rs | 10 +- rs/moq-quic/src/tests/characterize/paths.rs | 15 +- rs/moq-quic/src/tests/characterize/reset.rs | 27 +- .../src/tests/characterize/schedule.rs | 10 +- rs/moq-quic/src/tests/mod.rs | 268 ++++++++++++++---- rs/moq-quic/src/tests/reset_stream_at.rs | 115 ++++++-- rs/moq-tokio/src/quic/driver/connection.rs | 29 +- rs/moq-tokio/src/quic/driver/tests.rs | 28 +- rs/moq-uring/src/quic/driver/connection.rs | 20 +- rs/moq-uring/src/quic/web.rs | 10 +- rs/moq-uring/src/transport/adapter.rs | 22 +- rs/moq-uring/tests/integration/web.rs | 7 +- rs/moq-wasm/src/transport/adapter.rs | 16 +- 33 files changed, 664 insertions(+), 167 deletions(-) diff --git a/rs/moq-ffi/src/transport/adapter.rs b/rs/moq-ffi/src/transport/adapter.rs index 464f5c483ae..7b6a08e2e10 100644 --- a/rs/moq-ffi/src/transport/adapter.rs +++ b/rs/moq-ffi/src/transport/adapter.rs @@ -67,12 +67,20 @@ impl + Clone + 'st .map_err(Error) .map(|res| res.map(|(send, recv)| (SendStream(send), RecvStream(recv)))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, poll::Ungrouped>) -> Poll> { + fn poll_open_uni( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, poll::Ungrouped>, + ) -> Poll> { backend::Session::poll_open_uni(&mut self.0, cx) .map_err(Error) .map(|res| res.map(|send| SendStream(send).scheduled(options))) } - fn poll_open_bi(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, poll::Ungrouped>) -> Poll, Self::Error>> { + fn poll_open_bi( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, poll::Ungrouped>, + ) -> Poll, Self::Error>> { backend::Session::poll_open_bi(&mut self.0, cx) .map_err(Error) .map(|res| res.map(|(send, recv)| (SendStream(send).scheduled(options), RecvStream(recv)))) @@ -300,7 +308,9 @@ mod tests { poll::Session::stats(&session).rtt(), Some(std::time::Duration::from_millis(7)) ); - let Poll::Ready(Ok((mut send, mut recv))) = poll::Session::poll_open_bi(&mut session, &mut cx, Default::default()) else { + let Poll::Ready(Ok((mut send, mut recv))) = + poll::Session::poll_open_bi(&mut session, &mut cx, Default::default()) + else { panic!("open failed") }; let mut buf = Bytes::from_static(b"abcd"); diff --git a/rs/moq-net/src/client.rs b/rs/moq-net/src/client.rs index f4c6487f44f..cf8613717f1 100644 --- a/rs/moq-net/src/client.rs +++ b/rs/moq-net/src/client.rs @@ -617,7 +617,11 @@ mod tests { Poll::Ready(self.state.control_stream.lock().unwrap().take().ok_or(FakeError)) } - fn poll_open_uni(&mut self, _cx: &mut Context<'_>, _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>) -> Poll> { + fn poll_open_uni( + &mut self, + _cx: &mut Context<'_>, + _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>, + ) -> Poll> { Poll::Pending } @@ -625,7 +629,11 @@ mod tests { None } - fn send_datagram(&mut self, _: Bytes, _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>) -> Result<(), Self::Error> { + fn send_datagram( + &mut self, + _: Bytes, + _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>, + ) -> Result<(), Self::Error> { Ok(()) } @@ -1010,7 +1018,11 @@ mod tests { }) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>) -> Poll> { + fn poll_open_uni( + &mut self, + cx: &mut Context<'_>, + options: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>, + ) -> Poll> { self.inner.poll_open_uni(cx, options).map_ok(|stream| LocalSend { inner: stream, _local: self._local.clone(), @@ -1021,7 +1033,11 @@ mod tests { None } - fn send_datagram(&mut self, payload: Bytes, options: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>) -> Result<(), Self::Error> { + fn send_datagram( + &mut self, + payload: Bytes, + options: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>, + ) -> Result<(), Self::Error> { self.inner.send_datagram(payload, options) } diff --git a/rs/moq-net/src/coding/stream.rs b/rs/moq-net/src/coding/stream.rs index 1393d773b4d..2eec91c3bb9 100644 --- a/rs/moq-net/src/coding/stream.rs +++ b/rs/moq-net/src/coding/stream.rs @@ -31,7 +31,8 @@ impl Stream { where V: Clone, { - let (send, recv) = ready!(session.poll_open_bi(cx, Default::default())).map_err(|err| version.transport_error(err))?; + let (send, recv) = + ready!(session.poll_open_bi(cx, Default::default())).map_err(|err| version.transport_error(err))?; Poll::Ready(Ok(Self::build(send, recv, version))) } @@ -40,7 +41,10 @@ impl Stream { where V: Clone, { - let (send, recv) = session.open_bi(Default::default()).await.map_err(|err| version.transport_error(err))?; + let (send, recv) = session + .open_bi(Default::default()) + .await + .map_err(|err| version.transport_error(err))?; Ok(Self::build(send, recv, version)) } diff --git a/rs/moq-net/src/ietf/adapter.rs b/rs/moq-net/src/ietf/adapter.rs index 04841eecff2..2b6cbbb03b1 100644 --- a/rs/moq-net/src/ietf/adapter.rs +++ b/rs/moq-net/src/ietf/adapter.rs @@ -751,7 +751,8 @@ impl ControlStreamAdapter { /// Open a real (non-virtual) bidi stream, bypassing control stream multiplexing. /// Used for v16 SubscribeNamespace which moved to its own bidi stream. pub async fn open_native_bi(&mut self) -> Result<(AdapterSend, AdapterRecv), crate::Error> { - let (send, recv) = self.inner + let (send, recv) = self + .inner .open_bi(Default::default()) .await .map_err(|_| crate::Error::Closed)?; @@ -1166,7 +1167,14 @@ impl crate::transport::poll::Session for Con Poll::Ready(Ok((AdapterSend::Virtual(send), AdapterRecv::Virtual(recv)))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: crate::transport::poll::SendOptions<'_, ::Group>) -> Poll> { + fn poll_open_uni( + &mut self, + cx: &mut Context<'_>, + options: crate::transport::poll::SendOptions< + '_, + ::Group, + >, + ) -> Poll> { self.inner .poll_open_uni(cx, options) .map(|r| r.map(AdapterSend::Real).map_err(|_| crate::Error::Closed)) @@ -1182,7 +1190,14 @@ impl crate::transport::poll::Session for Con self.inner.send_group(priority) } - fn send_datagram(&mut self, payload: Bytes, options: crate::transport::poll::SendOptions<'_, ::Group>) -> Result<(), Self::Error> { + fn send_datagram( + &mut self, + payload: Bytes, + options: crate::transport::poll::SendOptions< + '_, + ::Group, + >, + ) -> Result<(), Self::Error> { self.inner .send_datagram(payload, options) .map_err(|_| crate::Error::Closed) diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index cd929e2668d..0e678609445 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -11,8 +11,8 @@ use std::{ time::Duration, }; -use crate::transport::poll::{GroupOf, SendOptions}; use crate::transport::poll::SendGroup as _; +use crate::transport::poll::{GroupOf, SendOptions}; use crate::{ AsPath, DecodeError, Error, Timescale, Timestamp, diff --git a/rs/moq-net/src/ietf/session.rs b/rs/moq-net/src/ietf/session.rs index b590e184d9e..eab4ff70be2 100644 --- a/rs/moq-net/src/ietf/session.rs +++ b/rs/moq-net/src/ietf/session.rs @@ -783,7 +783,10 @@ async fn run_setup( ) -> Result<(), Error> { let outer_version = crate::Version::Ietf(version); - let send = session.open_uni(Default::default()).await.map_err(Error::from_transport)?; + let send = session + .open_uni(Default::default()) + .await + .map_err(Error::from_transport)?; let mut writer: Writer = Writer::new(send, outer_version); let mut parameters = ietf::Parameters::default(); diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 15748db6cdb..e64190fd50d 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -3839,7 +3839,11 @@ impl GroupServe { let options = match &mut self.rank { Rank::Group(group) => SendOptions { group: Some(&*group), - priority: crate::priority::in_group(self.sequence, self.frame_start, self.ctx.steer_seen.order), + priority: crate::priority::in_group( + self.sequence, + self.frame_start, + self.ctx.steer_seen.order, + ), }, Rank::Queue(handle) => SendOptions { group: None, @@ -6325,7 +6329,11 @@ mod tests { .unwrap(); let mut session = ScriptedSession::new(script); let (_, recv) = futures::future::poll_fn(|cx| { - ::poll_open_bi(&mut session, cx, Default::default()) + ::poll_open_bi( + &mut session, + cx, + Default::default(), + ) }) .await .unwrap(); diff --git a/rs/moq-net/src/lite/session.rs b/rs/moq-net/src/lite/session.rs index 9395fa2db90..c58650c9f0e 100644 --- a/rs/moq-net/src/lite/session.rs +++ b/rs/moq-net/src/lite/session.rs @@ -714,7 +714,8 @@ impl SendSetup { loop { match &mut self.state { SendSetupState::Open { session, setup } => { - let stream = ready!(session.poll_open_uni(cx, Default::default())).map_err(crate::lite::error::from_transport)?; + let stream = ready!(session.poll_open_uni(cx, Default::default())) + .map_err(crate::lite::error::from_transport)?; let mut writer = Writer::new(stream, self.version); writer.buffer(&super::DataType::Setup)?; writer.buffer(&**setup)?; diff --git a/rs/moq-net/src/lite/test_transport.rs b/rs/moq-net/src/lite/test_transport.rs index 6fe3091d183..26a04e4b0c9 100644 --- a/rs/moq-net/src/lite/test_transport.rs +++ b/rs/moq-net/src/lite/test_transport.rs @@ -458,12 +458,23 @@ impl poll::Session for DeadStreamSession { } } - fn poll_open_bi(&mut self, _cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll, Self::Error>> { + fn poll_open_bi( + &mut self, + _cx: &mut Context<'_>, + options: poll::SendOptions<'_, SinkGroup>, + ) -> Poll, Self::Error>> { self.log.bi_opens.fetch_add(1, Ordering::Relaxed); - Poll::Ready(Ok((SinkSend::new(self.log.clone()).opened(options), DeadRecv(self.reset)))) + Poll::Ready(Ok(( + SinkSend::new(self.log.clone()).opened(options), + DeadRecv(self.reset), + ))) } - fn poll_open_uni(&mut self, _cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll> { + fn poll_open_uni( + &mut self, + _cx: &mut Context<'_>, + options: poll::SendOptions<'_, SinkGroup>, + ) -> Poll> { Poll::Ready(Ok(SinkSend::new(self.log.clone()).opened(options))) } @@ -471,7 +482,11 @@ impl poll::Session for DeadStreamSession { None } - fn send_datagram(&mut self, payload: bytes::Bytes, options: poll::SendOptions<'_, SinkGroup>) -> Result<(), Self::Error> { + fn send_datagram( + &mut self, + payload: bytes::Bytes, + options: poll::SendOptions<'_, SinkGroup>, + ) -> Result<(), Self::Error> { self.log.record_datagram(payload, options); Ok(()) } @@ -649,7 +664,11 @@ impl poll::Session for SinkSession { Poll::Ready(Ok((send, PendingRecv))) } - fn poll_open_bi(&mut self, _cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll, Self::Error>> { + fn poll_open_bi( + &mut self, + _cx: &mut Context<'_>, + options: poll::SendOptions<'_, SinkGroup>, + ) -> Poll, Self::Error>> { let Some(gate) = self.bi_gate.clone() else { return Poll::Pending; }; @@ -660,7 +679,11 @@ impl poll::Session for SinkSession { Poll::Ready(Ok((send, PendingRecv))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll> { + fn poll_open_uni( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, SinkGroup>, + ) -> Poll> { if let Some(gate) = &self.uni_open_gate { let waiter = self.uni_open_park.hold(cx); match gate.poll(waiter, |open| (**open).then_some(()).map_or(Poll::Pending, Poll::Ready)) { @@ -680,7 +703,11 @@ impl poll::Session for SinkSession { self.groups.then(|| SinkGroup::open(self.log.clone(), priority)) } - fn send_datagram(&mut self, payload: bytes::Bytes, options: poll::SendOptions<'_, SinkGroup>) -> Result<(), Self::Error> { + fn send_datagram( + &mut self, + payload: bytes::Bytes, + options: poll::SendOptions<'_, SinkGroup>, + ) -> Result<(), Self::Error> { self.log.record_datagram(payload, options); Ok(()) } @@ -968,7 +995,11 @@ impl poll::Session for ScriptedSession { ))) } - fn poll_open_bi(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll, Self::Error>> { + fn poll_open_bi( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, SinkGroup>, + ) -> Poll, Self::Error>> { if let Some(gate) = self.open_gate.clone() { let waiter = self.park.hold(cx); // A closed gate reads as open: the test dropped the producer, so nothing is @@ -998,7 +1029,11 @@ impl poll::Session for ScriptedSession { ))) } - fn poll_open_uni(&mut self, _cx: &mut Context<'_>, options: poll::SendOptions<'_, SinkGroup>) -> Poll> { + fn poll_open_uni( + &mut self, + _cx: &mut Context<'_>, + options: poll::SendOptions<'_, SinkGroup>, + ) -> Poll> { Poll::Ready(Ok(SinkSend::new(self.log.clone()).opened(options))) } @@ -1006,7 +1041,11 @@ impl poll::Session for ScriptedSession { None } - fn send_datagram(&mut self, payload: bytes::Bytes, options: poll::SendOptions<'_, SinkGroup>) -> Result<(), Self::Error> { + fn send_datagram( + &mut self, + payload: bytes::Bytes, + options: poll::SendOptions<'_, SinkGroup>, + ) -> Result<(), Self::Error> { self.log.record_datagram(payload, options); Ok(()) } diff --git a/rs/moq-net/src/server.rs b/rs/moq-net/src/server.rs index 9401827dec0..5e3cbe82c87 100644 --- a/rs/moq-net/src/server.rs +++ b/rs/moq-net/src/server.rs @@ -1075,7 +1075,11 @@ mod tests { None } - fn send_datagram(&mut self, _: Bytes, _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>) -> Result<(), Self::Error> { + fn send_datagram( + &mut self, + _: Bytes, + _: crate::transport::poll::SendOptions<'_, crate::transport::poll::Ungrouped>, + ) -> Result<(), Self::Error> { Ok(()) } fn poll_recv_datagram( diff --git a/rs/moq-net/src/transport.rs b/rs/moq-net/src/transport.rs index f327e458e54..067a6a6fa15 100644 --- a/rs/moq-net/src/transport.rs +++ b/rs/moq-net/src/transport.rs @@ -257,13 +257,19 @@ pub mod poll { /// Open a unidirectional stream scheduled by `options`, waiting for stream credit if /// necessary. - fn open_uni<'a>(&'a mut self, options: SendOptions<'a, ::Group>) -> OpenUni<'a, Self> { + fn open_uni<'a>( + &'a mut self, + options: SendOptions<'a, ::Group>, + ) -> OpenUni<'a, Self> { OpenUni { session: self, options } } /// Open a bidirectional stream, its sending half scheduled by `options`, waiting for /// stream credit if necessary. - fn open_bi<'a>(&'a mut self, options: SendOptions<'a, ::Group>) -> OpenBi<'a, Self> { + fn open_bi<'a>( + &'a mut self, + options: SendOptions<'a, ::Group>, + ) -> OpenBi<'a, Self> { OpenBi { session: self, options } } diff --git a/rs/moq-net/src/transport/memory.rs b/rs/moq-net/src/transport/memory.rs index d4c8a305f07..1504eda9921 100644 --- a/rs/moq-net/src/transport/memory.rs +++ b/rs/moq-net/src/transport/memory.rs @@ -282,7 +282,11 @@ impl poll::Session for Session { Self::poll_accept(&self.side.incoming().bi, &self.side.conn.close, waiter) } - fn poll_open_uni(&mut self, _cx: &mut Context<'_>, _: poll::SendOptions<'_, poll::Ungrouped>) -> Poll> { + fn poll_open_uni( + &mut self, + _cx: &mut Context<'_>, + _: poll::SendOptions<'_, poll::Ungrouped>, + ) -> Poll> { let (send, recv) = self.conn().stream(); Poll::Ready(self.open(&self.side.outgoing().uni, recv).map(|()| send)) } @@ -846,7 +850,9 @@ mod tests { a.close(4, "bye"); let closed = |err: Error| matches!(err, Error::Session { code: 4, ref reason } if reason == "bye"); assert!(closed(ready(b.poll_closed(&mut noop())))); - assert!(closed(ready(a.poll_open_uni(&mut noop(), Default::default())).err().unwrap())); + assert!(closed( + ready(a.poll_open_uni(&mut noop(), Default::default())).err().unwrap() + )); assert!(closed( ready(write(&mut unfinished, &Bytes::from_static(b"x"))).unwrap_err() )); @@ -881,7 +887,8 @@ mod tests { #[test] fn datagrams() { let (mut a, mut b) = pair(Config::default()); - a.send_datagram(vec![0; MAX_DATAGRAM_SIZE + 1].into(), Default::default()).unwrap(); + a.send_datagram(vec![0; MAX_DATAGRAM_SIZE + 1].into(), Default::default()) + .unwrap(); for _ in 0..DATAGRAM_QUEUE { a.send_datagram("one".into(), Default::default()).unwrap(); } diff --git a/rs/moq-net/tests/integration/goaway.rs b/rs/moq-net/tests/integration/goaway.rs index 2c44d82b153..5e32619e302 100644 --- a/rs/moq-net/tests/integration/goaway.rs +++ b/rs/moq-net/tests/integration/goaway.rs @@ -257,7 +257,11 @@ async fn duplicate_goaway_keeps_first_payload_moq_lite_04() { let mut frame = vec![0x05u8, uri.len() as u8 + 1, uri.len() as u8]; frame.extend_from_slice(uri.as_bytes()); - let (mut send, recv) = session.open_bi(Default::default()).await.map_err(|e| e.to_string()).expect("open_bi"); + let (mut send, recv) = session + .open_bi(Default::default()) + .await + .map_err(|e| e.to_string()) + .expect("open_bi"); let n = send.write(&frame).await.map_err(|e| e.to_string()).expect("write"); assert_eq!(n, frame.len()); send.finish().map_err(|e| e.to_string()).expect("finish"); diff --git a/rs/moq-net/tests/integration/subscribe_tracks.rs b/rs/moq-net/tests/integration/subscribe_tracks.rs index 81b13296528..c8b19d3a19f 100644 --- a/rs/moq-net/tests/integration/subscribe_tracks.rs +++ b/rs/moq-net/tests/integration/subscribe_tracks.rs @@ -106,7 +106,12 @@ async fn deliver(setup: &mut Setup, payload: &'static [u8]) { /// Send SUBSCRIBE_TRACKS from the server to the publishing client, returning every byte /// of the reply once the client ends the stream. async fn subscribe_tracks(pair: &MockPair) -> Vec { - let (mut send, mut recv) = pair.server_transport.clone().open_bi(Default::default()).await.expect("open_bi"); + let (mut send, mut recv) = pair + .server_transport + .clone() + .open_bi(Default::default()) + .await + .expect("open_bi"); send.write(SUBSCRIBE_TRACKS).await.expect("write"); let mut reply = Vec::new(); @@ -148,7 +153,13 @@ async fn subscribe_tracks_is_refused_per_request() { #[moq_clock::test] async fn subscribe_tracks_before_draft_18_closes_the_session() { let setup = setup("moq-transport-17".parse().unwrap()).await; - let (mut send, _recv) = setup.pair.server_transport.clone().open_bi(Default::default()).await.expect("open_bi"); + let (mut send, _recv) = setup + .pair + .server_transport + .clone() + .open_bi(Default::default()) + .await + .expect("open_bi"); send.write(SUBSCRIBE_TRACKS).await.expect("write"); moq_clock::timeout(TIMEOUT, setup.pair.client.closed()) diff --git a/rs/moq-net/tests/integration/support/mock.rs b/rs/moq-net/tests/integration/support/mock.rs index b8cb62db6fb..224f714b773 100644 --- a/rs/moq-net/tests/integration/support/mock.rs +++ b/rs/moq-net/tests/integration/support/mock.rs @@ -576,7 +576,11 @@ impl poll::Session for MockSession { Poll::Ready(Ok((send, self.recv(recv, back)))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, poll::Ungrouped>) -> Poll> { + fn poll_open_uni( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, poll::Ungrouped>, + ) -> Poll> { if self.side.withheld.load(Ordering::Relaxed) { return Poll::Ready(Err(ready!(self.closer.poll_closed(cx)))); } @@ -601,7 +605,11 @@ impl poll::Session for MockSession { None } - fn send_datagram(&mut self, payload: Bytes, options: poll::SendOptions<'_, poll::Ungrouped>) -> Result<(), Self::Error> { + fn send_datagram( + &mut self, + payload: Bytes, + options: poll::SendOptions<'_, poll::Ungrouped>, + ) -> Result<(), Self::Error> { if self.side.lossy.load(Ordering::Relaxed) { return Ok(()); } diff --git a/rs/moq-quic/benches/receive.rs b/rs/moq-quic/benches/receive.rs index 7824992f7ef..10989778c9c 100644 --- a/rs/moq-quic/benches/receive.rs +++ b/rs/moq-quic/benches/receive.rs @@ -39,7 +39,10 @@ fn bench_loss(c: &mut Criterion) { let target = pair.server.received.finished + streams as u64; let conn = pair.client(); for _ in 0..streams { - let id = conn.streams().open(Dir::Uni, Default::default()).expect("stream limit"); + let id = conn + .streams() + .open(Dir::Uni, Default::default()) + .expect("stream limit"); let mut stream = conn.send_stream(id); assert_eq!(stream.write(&data).unwrap(), data.len()); stream.finish().unwrap(); @@ -75,7 +78,10 @@ fn bench_reset(c: &mut Criterion) { let conn = pair.client(); let ids: Vec<_> = (0..streams) .map(|_| { - let id = conn.streams().open(Dir::Uni, Default::default()).expect("stream limit"); + let id = conn + .streams() + .open(Dir::Uni, Default::default()) + .expect("stream limit"); assert_eq!(conn.send_stream(id).write(&data).unwrap(), bytes); id }) @@ -116,7 +122,10 @@ fn bench_stop(c: &mut Criterion) { let target = pair.server.received.stopped + streams as u64; let conn = pair.client(); for _ in 0..streams { - let id = conn.streams().open(Dir::Uni, Default::default()).expect("stream limit"); + let id = conn + .streams() + .open(Dir::Uni, Default::default()) + .expect("stream limit"); assert_eq!(conn.send_stream(id).write(&data).unwrap(), bytes); } pair.drive_until(|pair| { diff --git a/rs/moq-quic/benches/streams.rs b/rs/moq-quic/benches/streams.rs index 99f06bf6463..db88dd21ed4 100644 --- a/rs/moq-quic/benches/streams.rs +++ b/rs/moq-quic/benches/streams.rs @@ -20,7 +20,10 @@ fn send(pair: &mut Pair, streams: usize, priorities: usize, writes: usize, size: let target = pair.server.received.finished + streams as u64; let conn = pair.client(); for index in 0..streams { - let id = conn.streams().open(Dir::Uni, Default::default()).expect("stream limit"); + let id = conn + .streams() + .open(Dir::Uni, Default::default()) + .expect("stream limit"); let mut stream = conn.send_stream(id); // `as _` follows the priority type, which a scheduler rewrite widens. stream.set_priority((index % priorities) as _).unwrap(); diff --git a/rs/moq-quic/src/connection/datagrams.rs b/rs/moq-quic/src/connection/datagrams.rs index 712e6919a58..374625aa674 100644 --- a/rs/moq-quic/src/connection/datagrams.rs +++ b/rs/moq-quic/src/connection/datagrams.rs @@ -44,11 +44,7 @@ impl Datagrams<'_> { if datagram.data.len() > max || datagram.size(true) > budget { return Err(SendDatagramError::TooLarge); } - if !self - .conn - .streams - .queue_datagram(datagram, options, budget) - { + if !self.conn.streams.queue_datagram(datagram, options, budget) { trace!("dropping outgoing datagram"); } Ok(()) diff --git a/rs/moq-quic/src/connection/streams/mod.rs b/rs/moq-quic/src/connection/streams/mod.rs index 7ff9e35558f..67584fb62c3 100644 --- a/rs/moq-quic/src/connection/streams/mod.rs +++ b/rs/moq-quic/src/connection/streams/mod.rs @@ -67,7 +67,12 @@ impl<'a> Streams<'a> { // Send state is allocated on first use, so the default schedule needs none. if options.group.is_some() || options.priority != 0 { let max_send_data = self.state.max_send_data(id); - let stream = self.state.send.get_mut(&id).unwrap().insert(Send::new(max_send_data)); + let stream = self + .state + .send + .get_mut(&id) + .unwrap() + .insert(Send::new(max_send_data)); stream.priority = options.priority; let group = options.group.map(|g| g.index(self.state.tag)); self.state diff --git a/rs/moq-quic/src/fuzz/connection.rs b/rs/moq-quic/src/fuzz/connection.rs index db77f7f6b8e..3c32dc34e0d 100644 --- a/rs/moq-quic/src/fuzz/connection.rs +++ b/rs/moq-quic/src/fuzz/connection.rs @@ -443,7 +443,10 @@ impl Pair { Op::Open { who, uni } => { let peer = self.peer(who); let dir = dir(uni); - let Some(id) = peer.conn().and_then(|conn| conn.streams().open(dir, Default::default())) else { + let Some(id) = peer + .conn() + .and_then(|conn| conn.streams().open(dir, Default::default())) + else { return; }; peer.send.push(id); @@ -574,7 +577,9 @@ impl Pair { group: None, priority: priority.into(), }, - ).is_ok() { + ) + .is_ok() + { peer.datagrams_sent.push(size); } } diff --git a/rs/moq-quic/src/tests/characterize/limits.rs b/rs/moq-quic/src/tests/characterize/limits.rs index 506beedd52d..4616cb10425 100644 --- a/rs/moq-quic/src/tests/characterize/limits.rs +++ b/rs/moq-quic/src/tests/characterize/limits.rs @@ -75,7 +75,10 @@ fn max_concurrent_streams_lowered() { /// How many bytes a fresh client stream can write, up to `limit` fn writable(pair: &mut Pair, ch: ConnectionHandle, limit: usize) -> usize { - let s = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(ch, s).write(&vec![0; limit]).unwrap_or(0) } @@ -198,7 +201,10 @@ fn zero_rtt_window_raise(dir: Dir) { pair.server.set_server_config(Some(Arc::new(server(NEW)))); let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(dir, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(dir, Default::default()) + .unwrap(); let mut written = pair.client_send(client_ch, s).write(&[0; LEN]).unwrap(); assert_eq!(written, OLD as usize); diff --git a/rs/moq-quic/src/tests/characterize/paths.rs b/rs/moq-quic/src/tests/characterize/paths.rs index f5f1e4ee54a..f8f6283ebb7 100644 --- a/rs/moq-quic/src/tests/characterize/paths.rs +++ b/rs/moq-quic/src/tests/characterize/paths.rs @@ -155,7 +155,10 @@ fn duplicate_packet_is_discarded() { let _guard = subscribe(); let (mut pair, client_ch, server_ch) = connected(); pair.drive(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive_client(); assert_eq!(pair.server.inbound.len(), 1); @@ -297,7 +300,10 @@ fn zero_rtt_retransmit_after_retry() { let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); @@ -344,7 +350,10 @@ fn path_validation_failure_reverts() { assert_matches!(updates.as_slice(), [.., Event::PathUpdated]); // The connection still works on the old path - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); assert_eq!(pair.server_streams(server_ch).accept(Dir::Uni), Some(s)); diff --git a/rs/moq-quic/src/tests/characterize/reset.rs b/rs/moq-quic/src/tests/characterize/reset.rs index 31c28bd054e..230b8495d4a 100644 --- a/rs/moq-quic/src/tests/characterize/reset.rs +++ b/rs/moq-quic/src/tests/characterize/reset.rs @@ -27,7 +27,10 @@ fn open( server_ch: ConnectionHandle, data: &[u8], ) -> StreamId { - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s).write(data).unwrap(); pair.drive(); assert_eq!(pair.server_streams(server_ch).accept(Dir::Uni), Some(s)); @@ -177,11 +180,19 @@ fn reset_returns_stream_credit_once_observed() { let s = open(&mut pair, client_ch, server_ch, b"hello"); pair.client_send(client_ch, s).reset(CODE).unwrap(); pair.drive(); - assert_eq!(pair.client_streams(client_ch).open(Dir::Uni, Default::default()), None); + assert_eq!( + pair.client_streams(client_ch) + .open(Dir::Uni, Default::default()), + None + ); assert_eq!(read_all(&mut pair, server_ch, s).1, ReadError::Reset(CODE)); pair.drive(); - assert!(pair.client_streams(client_ch).open(Dir::Uni, Default::default()).is_some()); + assert!( + pair.client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .is_some() + ); } /// The connection window used by `s`'s unread bytes, which fill it @@ -193,7 +204,10 @@ fn blocked() -> (Pair, ConnectionHandle, ConnectionHandle, StreamId) { connected_with(|t| _ = t.receive_window(VarInt::from_u32(WINDOW)), |_| {}); let s = open(&mut pair, client_ch, server_ch, &[0; WINDOW as usize]); // The window is spent, so nothing more can be written - let other = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let other = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!( pair.client_send(client_ch, other).write(b"x"), Err(WriteError::Blocked) @@ -203,7 +217,10 @@ fn blocked() -> (Pair, ConnectionHandle, ConnectionHandle, StreamId) { /// How many bytes a fresh client stream can write fn writable(pair: &mut Pair, ch: ConnectionHandle) -> usize { - let s = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(ch, s) .write(&[0; 2 * WINDOW as usize]) .unwrap_or(0) diff --git a/rs/moq-quic/src/tests/characterize/schedule.rs b/rs/moq-quic/src/tests/characterize/schedule.rs index 7817d8ff84d..4dcd242601e 100644 --- a/rs/moq-quic/src/tests/characterize/schedule.rs +++ b/rs/moq-quic/src/tests/characterize/schedule.rs @@ -43,7 +43,10 @@ fn assert_golden(pair: &mut Pair, golden: &str) { /// Opens a client uni stream at `priority` and queues `LEN` bytes and a FIN on it fn queue(pair: &mut Pair, ch: ConnectionHandle, priority: i64) -> StreamId { - let s = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(ch, s).set_priority(priority).unwrap(); assert_eq!(pair.client_send(ch, s).write(&[0; LEN]).unwrap(), LEN); pair.client_send(ch, s).finish().unwrap(); @@ -183,7 +186,10 @@ fn datagrams_interleaved() { fn retransmit_within_stream() { let _guard = subscribe(); let (mut pair, ch) = idle(true); - let s = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!(pair.client_send(ch, s).write(&[0; 16_000]).unwrap(), 16_000); // Lose the second packet of the first flight diff --git a/rs/moq-quic/src/tests/mod.rs b/rs/moq-quic/src/tests/mod.rs index 5d77370aeeb..7a5a76d3f94 100644 --- a/rs/moq-quic/src/tests/mod.rs +++ b/rs/moq-quic/src/tests/mod.rs @@ -593,7 +593,10 @@ fn finish_stream_simple() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); @@ -637,7 +640,10 @@ fn reset_stream() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); @@ -666,7 +672,10 @@ fn stop_stream() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); @@ -786,7 +795,10 @@ fn congestion() { const TARGET: u64 = 2048; assert!(pair.client_conn_mut(client_ch).congestion_window() > TARGET); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); // Send data without receiving ACKs until the congestion state falls below target while pair.client_conn_mut(client_ch).congestion_window() > TARGET { let n = pair.client_send(client_ch, s).write(&[42; 1024]).unwrap(); @@ -822,7 +834,10 @@ fn full_initial_window() { let mtu = u64::from(INITIAL_MTU); assert_eq!(window % mtu, 0, "window must be exactly fillable"); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let data = vec![42; 2 * window as usize]; assert_eq!( pair.client_send(client_ch, s).write(&data), @@ -871,7 +886,10 @@ fn zero_rtt_happypath() { info!("resuming session"); let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); const MSG: &[u8] = b"Hello, 0-RTT!"; pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); @@ -970,7 +988,10 @@ fn zero_rtt_rejection() { info!("resuming session"); let client_ch = pair.begin_connect(client_config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); const MSG: &[u8] = b"Hello, 0-RTT!"; pair.client_conn_mut(client_ch) .set_send_window(MSG.len() as u64); @@ -991,7 +1012,10 @@ fn zero_rtt_rejection() { Some(Event::Connected) ); assert_matches!(pair.server_conn_mut(server_ch).poll(), None); - let s2 = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s2 = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!(s, s2); // The server discarded its 0-RTT keys, so it never decrypted the STREAM frame and has no @@ -1053,7 +1077,10 @@ fn test_zero_rtt_incoming_limit(configure_server: pair.server.handle_incoming = Box::new(|_| IncomingConnectionBehavior::Wait); let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s) .write(&vec![0; CLIENT_WRITES]) .unwrap(); @@ -1419,7 +1446,11 @@ fn late_peer_params_make_streams_available() { pair.server.drive_incoming(pair.time, pair.client.addr); let incoming = pair.server.pop_waiting_incoming(); let server_ch = pair.server.try_accept(incoming, pair.time).unwrap(); - assert_eq!(pair.server_streams(server_ch).open(Dir::Uni, Default::default()), None); + assert_eq!( + pair.server_streams(server_ch) + .open(Dir::Uni, Default::default()), + None + ); pair.drive(); assert!( @@ -1428,7 +1459,11 @@ fn late_peer_params_make_streams_available() { Event::Stream(StreamEvent::Available { dir: Dir::Uni }) )) ); - assert!(pair.server_streams(server_ch).open(Dir::Uni, Default::default()).is_some()); + assert!( + pair.server_streams(server_ch) + .open(Dir::Uni, Default::default()) + .is_some() + ); } #[test] @@ -1453,7 +1488,8 @@ fn stream_id_limit() { .open(Dir::Uni, Default::default()) .expect("couldn't open first stream"); assert_eq!( - pair.client_streams(client_ch).open(Dir::Uni, Default::default()), + pair.client_streams(client_ch) + .open(Dir::Uni, Default::default()), None, "only one stream is permitted at a time" ); @@ -1467,7 +1503,8 @@ fn stream_id_limit() { Some(Event::Stream(StreamEvent::Finished { id })) if id == s ); assert_eq!( - pair.client_streams(client_ch).open(Dir::Uni, Default::default()), + pair.client_streams(client_ch) + .open(Dir::Uni, Default::default()), None, "server does not immediately grant additional credit" ); @@ -1545,7 +1582,11 @@ fn streams_blocked() { .client_streams(client_ch) .open(Dir::Uni, Default::default()) .expect("first uni stream"); - assert_eq!(pair.client_streams(client_ch).open(Dir::Uni, Default::default()), None); + assert_eq!( + pair.client_streams(client_ch) + .open(Dir::Uni, Default::default()), + None + ); // Send data so the STREAMS_BLOCKED piggybacks on an outgoing packet pair.client_send(client_ch, s).write(b"hi").unwrap(); @@ -1604,7 +1645,10 @@ fn data_blocked() { let (client_ch, server_ch) = pair.connect(); // Fill the connection-level window, then run into the limit - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!( pair.client_send(client_ch, s) .write(b"0123456789ab") @@ -1682,7 +1726,10 @@ fn stream_data_blocked() { let (client_ch, server_ch) = pair.connect(); // Fill the stream-level window, then run into the limit - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!( pair.client_send(client_ch, s) .write(b"0123456789ab") @@ -1753,7 +1800,10 @@ fn data_blocked_not_sent_under_limit() { let (client_ch, _server_ch) = pair.connect(); // Default windows are far larger than this write, so nothing is blocked - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s).write(b"hi").unwrap(); pair.drive(); @@ -1770,7 +1820,10 @@ fn data_blocked_not_sent_for_local_send_window() { // Running out of our own send window is not the peer's flow control limit pair.client_conn_mut(client_ch).set_send_window(5); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!( pair.client_send(client_ch, s).write(b"0123456789").unwrap(), 5 @@ -1803,7 +1856,10 @@ fn data_blocked_dropped_when_limit_raised() { let mut pair = Pair::new(Default::default(), server); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!( pair.client_send(client_ch, s) .write(b"0123456789ab") @@ -1843,7 +1899,10 @@ fn stream_data_blocked_not_sent_after_reset() { let mut pair = Pair::new(Default::default(), server); let (client_ch, _server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!( pair.client_send(client_ch, s) .write(b"0123456789ab") @@ -1877,7 +1936,10 @@ fn data_blocked_retransmit() { let mut pair = Pair::new(Default::default(), server); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!( pair.client_send(client_ch, s) .write(b"0123456789ab") @@ -2225,7 +2287,10 @@ fn connection_close_while_congestion_blocked() { // Saturate the congestion window with unacknowledged stream data by transmitting from the // client without driving the server, so no ACKs come back and in-flight bytes stay pinned at // the window - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s) .write(&[42; 1024 * 1024]) .unwrap(); @@ -2335,7 +2400,10 @@ fn test_flow_control(config: TransportConfig, window_size: usize) { let msg = vec![0xAB; window_size + 10]; // Stream reset before read - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); info!("writing"); assert_eq!(pair.client_send(client_ch, s).write_limit(), window_size); assert_eq!(pair.client_send(client_ch, s).write(&msg), Ok(window_size)); @@ -2360,7 +2428,10 @@ fn test_flow_control(config: TransportConfig, window_size: usize) { // Happy path info!("writing"); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!(pair.client_send(client_ch, s).write_limit(), window_size); assert_eq!(pair.client_send(client_ch, s).write(&msg), Ok(window_size)); assert_eq!(pair.client_send(client_ch, s).write_limit(), 0); @@ -2456,7 +2527,10 @@ fn stop_opens_bidi() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); assert_eq!(pair.client_streams(client_ch).send_streams(), 0); - let s = pair.client_streams(client_ch).open(Dir::Bi, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Bi, Default::default()) + .unwrap(); assert_eq!(pair.client_streams(client_ch).send_streams(), 1); const ERROR: VarInt = VarInt(42); pair.client @@ -2500,8 +2574,14 @@ fn implicit_open() { let _guard = subscribe(); let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s1 = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); - let s2 = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s1 = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); + let s2 = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s2).write(b"hello").unwrap(); pair.drive(); assert_matches!( @@ -2669,7 +2749,10 @@ fn finish_stream_flow_control_reordered() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); @@ -2725,7 +2808,10 @@ fn handshake_1rtt_handling() { pair.client.delay_outbound(); // Send some 1-RTT data which will be received first. - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); pair.client_send(client_ch, s).finish().unwrap(); @@ -2765,7 +2851,10 @@ fn stop_before_finish() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); @@ -2787,7 +2876,10 @@ fn stop_during_finish() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); pair.drive(); @@ -2814,7 +2906,10 @@ fn congested_tail_loss() { const TARGET: u64 = 2048; assert!(pair.client_conn_mut(client_ch).congestion_window() > TARGET); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); // Send data without receiving ACKs until the congestion state falls below target while pair.client_conn_mut(client_ch).congestion_window() > TARGET { let n = pair.client_send(client_ch, s).write(&[42; 1024]).unwrap(); @@ -3028,9 +3123,7 @@ fn first_flight_datagrams(stream: i64, datagram: i64) -> usize { group: Some(&datagrams), priority: 0, }; - conn.datagrams() - .send(vec![1; 100].into(), options) - .unwrap(); + conn.datagrams().send(vec![1; 100].into(), options).unwrap(); } // One congestion-limited flight. @@ -3150,7 +3243,10 @@ fn datagram_unsupported() { assert_matches!(pair.server_conn_mut(server_ch).poll(), None); assert_matches!(pair.client_datagrams(client_ch).max_size(), None); - match pair.client_datagrams(client_ch).send(Bytes::new(), Default::default()) { + match pair + .client_datagrams(client_ch) + .send(Bytes::new(), Default::default()) + { Err(SendDatagramError::UnsupportedByPeer) => {} Err(e) => panic!("unexpected error: {e}"), Ok(_) => panic!("unexpected success"), @@ -3200,7 +3296,10 @@ fn finish_acked() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); @@ -3259,7 +3358,10 @@ fn finish_retransmit() { let mut pair = Pair::default(); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); const MSG: &[u8] = b"hello"; pair.client_send(client_ch, s).write(MSG).unwrap(); @@ -3316,7 +3418,10 @@ fn repeated_request_response() { const REQUEST: &[u8] = b"hello"; const RESPONSE: &[u8] = b"world"; for _ in 0..3 { - let s = pair.client_streams(client_ch).open(Dir::Bi, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Bi, Default::default()) + .unwrap(); pair.client_send(client_ch, s).write(REQUEST).unwrap(); pair.client_send(client_ch, s).finish().unwrap(); @@ -3830,7 +3935,10 @@ fn blackhole_after_mtu_change_repairs_itself() { // The payload will be sent in a single packet, because the detected MTU was 1444, but it will // be dropped because the link no longer supports that packet size! let payload = vec![42; 1300]; - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s).write(&payload).unwrap(); let out_of_bounds = pair.drive_bounded(); @@ -3878,7 +3986,10 @@ fn packet_splitting_with_default_mtu() { let (client_ch, _) = pair.connect(); pair.drive(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s).write(&payload).unwrap(); pair.client.drive(pair.time, pair.server.addr); @@ -3899,7 +4010,10 @@ fn packet_splitting_not_necessary_after_higher_mtu_discovered() { let (client_ch, _) = pair.connect(); pair.drive(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s).write(&payload).unwrap(); pair.client.drive(pair.time, pair.server.addr); @@ -4549,7 +4663,10 @@ fn stream_gso() { config.transport = Arc::new(cubic_transport()); let (client_ch, _) = pair.connect_with(config); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let initial_ios = pair.client_conn_mut(client_ch).stats().udp_tx.ios; @@ -4717,7 +4834,10 @@ fn min_mtu_does_not_pad_zero_rtt_batch_tail() { let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let stream = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let stream = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let data = vec![42; 3_000]; assert_eq!( pair.client_send(client_ch, stream).write(&data), @@ -5525,7 +5645,10 @@ fn cwnd_limited_is_not_reported_when_only_pacing_blocks() { let mut pair = Pair::default(); let (client_ch, _) = pair.connect_with(client_cfg); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s) .write(&[42; 64 * 1024]) .unwrap(); @@ -5615,7 +5738,10 @@ fn send_quantum_bounds_the_gso_batch() { let mut pair = Pair::default(); let (client_ch, _) = pair.connect_with(client_cfg); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s) .write(&[42; 64 * 1024]) .unwrap(); @@ -5860,7 +5986,10 @@ fn congestion_callbacks_identify_packets_across_spaces() { pair.drive(); assert!(!pair.client_conn_mut(client_ch).is_handshaking()); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s) .write(&[42; 16 * 1024]) .unwrap(); @@ -5951,7 +6080,10 @@ fn ce_events(log: &PacketLog) -> usize { fn old_ce_marks_report_no_new_congestion() { let _guard = subscribe(); let (mut pair, client_ch, log) = recorded_pair(Default::default()); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s) .write(&[42; 8 * 1024]) .unwrap(); @@ -5982,7 +6114,10 @@ fn invalid_ecn_feedback_reports_no_congestion() { assert!(pair.client_conn_mut(client_ch).using_ecn()); pair.congestion_experienced = true; pair.rewrite_ecn = Some(rewrite); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s) .write(&[42; 16 * 1024]) .unwrap(); @@ -6025,7 +6160,10 @@ fn check_starvation_reported_before_resumed_send(send: impl Fn(&mut Pair, Connec #[test] fn stream_starvation_reported_before_resumed_send() { check_starvation_reported_before_resumed_send(|pair, ch| { - let s = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(ch, s).write(&[42; 1000]).unwrap(); }); } @@ -6050,7 +6188,10 @@ fn check_blocked_backlog_is_not_app_limited(factory: PacketRecorderFactory) { pair.drive(); let before = log.lock().unwrap().len(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s) .write(&[42; 64 * 1024]) .unwrap(); @@ -6088,7 +6229,10 @@ fn pacing_blocked_backlog_is_not_app_limited() { fn partial_poll_reports_starvation() { let _guard = subscribe(); let (mut pair, ch, log) = recorded_pair(Default::default()); - let stream = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); + let stream = pair + .client_streams(ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(ch, stream).write(&[42; 1000]).unwrap(); log.lock().unwrap().clear(); let now = pair.time; @@ -6164,7 +6308,10 @@ fn held_credit_spends_connection_window_only() { ); let chs = pair.connect(); let (client_ch, server_ch) = chs; - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let msg = vec![0xAB; 3 * WINDOW]; let (mut sent, mut held) = (0, Credit::default()); @@ -6225,7 +6372,10 @@ fn sender_window_is_not_starvation() { let _guard = subscribe(); let (mut pair, ch, log) = recorded_pair(Default::default()); pair.client_conn_mut(ch).set_send_window(1000); - let stream = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); + let stream = pair + .client_streams(ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!(pair.client_send(ch, stream).write(&[42; 2000]), Ok(1000)); log.lock().unwrap().clear(); pair.drive_client(); @@ -6258,7 +6408,10 @@ fn receiver_credit_is_starvation() { client_cfg.transport = Arc::new(client_transport); let (ch, _) = pair.connect_with(client_cfg); let log = factory.logs.lock().unwrap()[0].clone(); - let stream = pair.client_streams(ch).open(Dir::Uni, Default::default()).unwrap(); + let stream = pair + .client_streams(ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!(pair.client_send(ch, stream).write(&[42; 2000]), Ok(1000)); log.lock().unwrap().clear(); pair.drive_client(); @@ -6432,7 +6585,10 @@ fn upload( const CHUNK: [u8; 10_000] = [0; 10_000]; let start = pair.time; - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let mut unsent = total; let mut received = 0; let mut server_stream = None; diff --git a/rs/moq-quic/src/tests/reset_stream_at.rs b/rs/moq-quic/src/tests/reset_stream_at.rs index 288030c4c53..5db100f3672 100644 --- a/rs/moq-quic/src/tests/reset_stream_at.rs +++ b/rs/moq-quic/src/tests/reset_stream_at.rs @@ -101,7 +101,10 @@ fn stop_sending_abandons_prefix(reset_stream_at: bool) { let (client_ch, server_ch) = pair.connect(); // The server learns of the stream from its first byte - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s).write(&MSG[..1]).unwrap(); pair.drive(); assert_eq!(accept(&mut pair, server_ch), s); @@ -148,7 +151,10 @@ fn delivers_prefix_before_error() { let mut pair = pair(true); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); reset(&mut pair, client_ch, checkpoint).unwrap(); pair.drive(); @@ -174,7 +180,10 @@ fn delivers_unsent_prefix() { let mut pair = pair(true); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s) .write(&MSG[..RELIABLE]) .unwrap(); @@ -195,7 +204,10 @@ fn retransmits_lost_prefix() { let mut pair = pair(true); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); lose_client_packets(&mut pair); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -229,7 +241,10 @@ fn retransmits_lost_reset() { let mut pair = pair(true); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); pair.drive(); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -251,7 +266,10 @@ fn received_reset_after_prefix() { let mut pair = pair(true); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); reset(&mut pair, client_ch, checkpoint).unwrap(); pair.drive(); @@ -282,7 +300,10 @@ fn after_finish() { let (client_ch, server_ch) = pair.connect(); for reliable in [RELIABLE, MSG.len()] { - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let mut checkpoint = write(&mut pair, client_ch, s); if reliable == MSG.len() { checkpoint = pair.client_send(client_ch, s).checkpoint(); @@ -311,7 +332,10 @@ fn flow_control_blocked() { let mut pair = Pair::new(Default::default(), config); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s) .write(&MSG[..RELIABLE]) .unwrap(); @@ -343,7 +367,10 @@ fn unsupported_holds_reset_until_acked() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -365,7 +392,10 @@ fn unsupported_retransmits_lost_prefix() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); lose_client_packets(&mut pair); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -386,7 +416,10 @@ fn unsupported_resets_at_once_when_acked() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); pair.drive(); assert_eq!(accept(&mut pair, server_ch), s); @@ -412,7 +445,10 @@ fn unsupported_after_finish() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); pair.client_send(client_ch, s).finish().unwrap(); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -445,7 +481,10 @@ fn unsupported_repeated_reset_is_closed() { let mut pair = pair(false); let (client_ch, _) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); let again = pair.client_send(client_ch, s).checkpoint(); lose_client_packets(&mut pair); @@ -464,7 +503,10 @@ fn unsupported_close_while_held() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); lose_client_packets(&mut pair); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -491,10 +533,16 @@ fn unsupported_returns_flow_control() { let mut pair = Pair::new(Default::default(), config); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); reset(&mut pair, client_ch, checkpoint).unwrap(); - let next = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let next = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!( pair.client_send(client_ch, next).write(MSG), Err(WriteError::Blocked) @@ -515,7 +563,10 @@ fn unsupported_allows_zero() { let mut pair = pair(false); let (client_ch, server_ch) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = pair.client_send(client_ch, s).checkpoint(); pair.client_send(client_ch, s).write(MSG).unwrap(); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -534,7 +585,10 @@ fn repeated_reset_is_closed() { let mut pair = pair(true); let (client_ch, _) = pair.connect(); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); let again = pair.client_send(client_ch, s).checkpoint(); reset(&mut pair, client_ch, checkpoint).unwrap(); @@ -573,12 +627,18 @@ fn zero_rtt_rejected_checkpoint_is_closed() { inner.alpn_protocols = vec!["bar".into()]; let client_ch = pair.begin_connect(ClientConfig::new(client_crypto)); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); pair.drive(); assert!(!pair.client_conn_mut(client_ch).accepted_0rtt()); - let reopened = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let reopened = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!(reopened, s); pair.client_send(client_ch, reopened).write(MSG).unwrap(); assert_eq!( @@ -604,9 +664,15 @@ fn checkpoint_from_another_connection() { let mut second = pair(true); let (second_ch, _) = second.connect(); - let s = first.client_streams(first_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = first + .client_streams(first_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut first, first_ch, s); - let other = second.client_streams(second_ch).open(Dir::Uni, Default::default()).unwrap(); + let other = second + .client_streams(second_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); assert_eq!(other, s); second.client_send(second_ch, other).write(MSG).unwrap(); let _ = reset(&mut second, second_ch, checkpoint); @@ -633,7 +699,10 @@ fn zero_rtt() { pair.client.addr = SocketAddr::new(Ipv6Addr::LOCALHOST.into(), pair.next_port()); let client_ch = pair.begin_connect(config); assert!(pair.client_conn_mut(client_ch).has_0rtt()); - let s = pair.client_streams(client_ch).open(Dir::Uni, Default::default()).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); let checkpoint = write(&mut pair, client_ch, s); reset(&mut pair, client_ch, checkpoint).unwrap(); pair.drive(); diff --git a/rs/moq-tokio/src/quic/driver/connection.rs b/rs/moq-tokio/src/quic/driver/connection.rs index 040ab2536d5..1f1630c8405 100644 --- a/rs/moq-tokio/src/quic/driver/connection.rs +++ b/rs/moq-tokio/src/quic/driver/connection.rs @@ -24,10 +24,13 @@ use tokio::sync::{ use tracing::{Instrument, Span, debug_span}; use crate::quic::driver::{ - ConnectionEvent, Duration, Instant, VarInt, mutex::Mutex, recv_stream::RecvStream, + ConnectionEvent, Duration, Instant, VarInt, + mutex::Mutex, + recv_stream::RecvStream, runtime::UdpSender, send_group::{self, SendGroup, SendOptions}, - send_stream::SendStream, udp_transmit, + send_stream::SendStream, + udp_transmit, }; use moq_quic::{ ConnectionError, ConnectionHandle, ConnectionStats, Dir, EndpointEvent, Side, StreamEvent, @@ -544,7 +547,11 @@ impl Connection { /// /// # Panics /// - when `options.group` belongs to another connection - pub fn send_datagram(&self, data: Bytes, options: SendOptions<'_>) -> Result<(), SendDatagramError> { + pub fn send_datagram( + &self, + data: Bytes, + options: SendOptions<'_>, + ) -> Result<(), SendDatagramError> { let conn = &mut *self.0.state.lock("send_datagram"); if let Some(x) = &conn.error { return Err(SendDatagramError::ConnectionLost(x.clone())); @@ -820,7 +827,13 @@ impl Future for OpenUni<'_> { type Output = Result; fn poll(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll { let this = self.project(); - let (conn, id, is_0rtt) = ready!(poll_open(ctx, this.conn, *this.options, this.notify, Dir::Uni))?; + let (conn, id, is_0rtt) = ready!(poll_open( + ctx, + this.conn, + *this.options, + this.notify, + Dir::Uni + ))?; Poll::Ready(Ok(SendStream::new(conn, id, is_0rtt))) } } @@ -839,7 +852,13 @@ impl Future for OpenBi<'_> { type Output = Result<(SendStream, RecvStream), ConnectionError>; fn poll(self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll { let this = self.project(); - let (conn, id, is_0rtt) = ready!(poll_open(ctx, this.conn, *this.options, this.notify, Dir::Bi))?; + let (conn, id, is_0rtt) = ready!(poll_open( + ctx, + this.conn, + *this.options, + this.notify, + Dir::Bi + ))?; Poll::Ready(Ok(( SendStream::new(conn.clone(), id, is_0rtt), diff --git a/rs/moq-tokio/src/quic/driver/tests.rs b/rs/moq-tokio/src/quic/driver/tests.rs index 0625a7fdfdd..4b2644bf3e1 100755 --- a/rs/moq-tokio/src/quic/driver/tests.rs +++ b/rs/moq-tokio/src/quic/driver/tests.rs @@ -709,12 +709,18 @@ async fn zero_rtt() { } }); info!("sending 0.5-RTT"); - let mut s = connection.open_uni(Default::default()).await.expect("open_uni"); + let mut s = connection + .open_uni(Default::default()) + .await + .expect("open_uni"); s.write_all(MSG0).await.expect("write"); s.finish().unwrap(); connection.authenticated().await.expect("connected"); info!("sending 1-RTT"); - let mut s = connection.open_uni(Default::default()).await.expect("open_uni"); + let mut s = connection + .open_uni(Default::default()) + .await + .expect("open_uni"); s.write_all(MSG1).await.expect("write"); // The peer might close the connection before ACKing let _ = s.finish(); @@ -752,7 +758,10 @@ async fn zero_rtt() { .unwrap_or_else(|_| panic!("missing 0-RTT keys")); // Send something before the handshake can make progress, thereby forcing 0-RTT - let mut stream_0rtt = connection.open_uni(Default::default()).await.expect("0-RTT open uni"); + let mut stream_0rtt = connection + .open_uni(Default::default()) + .await + .expect("0-RTT open uni"); info!("sending 0-RTT"); stream_0rtt.write_all(MSG0).await.expect("0-RTT write"); stream_0rtt.finish().unwrap(); @@ -958,7 +967,10 @@ fn run_echo(args: EchoArgs) { for i in 0..args.nr_streams { println!("Opening stream {i}"); - let (mut send, mut recv) = new_conn.open_bi(Default::default()).await.expect("stream open"); + let (mut send, mut recv) = new_conn + .open_bi(Default::default()) + .await + .expect("stream open"); let msg = gen_data(args.stream_size, SEED); let send_task = async { @@ -1570,9 +1582,13 @@ async fn two_datagram_readers() { x }, async { - server.send_datagram(b"one"[..].into(), Default::default()).unwrap(); + server + .send_datagram(b"one"[..].into(), Default::default()) + .unwrap(); done.notified().await; - server.send_datagram(b"two"[..].into(), Default::default()).unwrap(); + server + .send_datagram(b"two"[..].into(), Default::default()) + .unwrap(); } ); assert!(*a == *b"one" || *b == *b"one"); diff --git a/rs/moq-uring/src/quic/driver/connection.rs b/rs/moq-uring/src/quic/driver/connection.rs index b561aea10cb..01c58640e72 100644 --- a/rs/moq-uring/src/quic/driver/connection.rs +++ b/rs/moq-uring/src/quic/driver/connection.rs @@ -579,7 +579,12 @@ impl web_transport_trait::poll::Session for Connection { } // The peer's MAX_STREAMS credit is what gates us: `open` hands back // nothing while it is spent. - let opened = self.shared.conn.borrow_mut().streams().open(Dir::Uni, Default::default()); + let opened = self + .shared + .conn + .borrow_mut() + .streams() + .open(Dir::Uni, Default::default()); match opened { Some(id) => Poll::Ready(Ok(super::SendStream::new(self.shared.clone(), id))), None => { @@ -598,7 +603,12 @@ impl web_transport_trait::poll::Session for Connection { if let Some(err) = self.shared.closed() { return Poll::Ready(Err(err)); } - let opened = self.shared.conn.borrow_mut().streams().open(Dir::Bi, Default::default()); + let opened = self + .shared + .conn + .borrow_mut() + .streams() + .open(Dir::Bi, Default::default()); match opened { Some(id) => Poll::Ready(Ok(( super::SendStream::new(self.shared.clone(), id), @@ -613,7 +623,11 @@ impl web_transport_trait::poll::Session for Connection { } fn poll_send_datagram(&mut self, _: &mut Context<'_>, payload: &[u8]) -> Poll> { - Poll::Ready(Self::send_datagram(self, Bytes::copy_from_slice(payload), Default::default())) + Poll::Ready(Self::send_datagram( + self, + Bytes::copy_from_slice(payload), + Default::default(), + )) } fn poll_recv_datagram(&mut self, cx: &mut Context<'_>) -> Poll> { diff --git a/rs/moq-uring/src/quic/web.rs b/rs/moq-uring/src/quic/web.rs index e0c32214772..c0e9d98eb92 100644 --- a/rs/moq-uring/src/quic/web.rs +++ b/rs/moq-uring/src/quic/web.rs @@ -462,9 +462,7 @@ impl Session { let mut framed = BytesMut::with_capacity(web.header_datagram.len() + payload.len()); framed.extend_from_slice(&web.header_datagram); framed.extend_from_slice(&payload); - self.conn - .send_datagram(framed.freeze(), options) - .map_err(unmap_err) + self.conn.send_datagram(framed.freeze(), options).map_err(unmap_err) } /// Wrap a raw-QUIC connection in a session, with no @@ -692,7 +690,11 @@ impl web_transport_trait::poll::Session for Session { } fn poll_send_datagram(&mut self, _: &mut Context<'_>, payload: &[u8]) -> Poll> { - Poll::Ready(Self::send_datagram(self, Bytes::copy_from_slice(payload), Default::default())) + Poll::Ready(Self::send_datagram( + self, + Bytes::copy_from_slice(payload), + Default::default(), + )) } fn poll_recv_datagram(&mut self, cx: &mut Context<'_>) -> Poll> { diff --git a/rs/moq-uring/src/transport/adapter.rs b/rs/moq-uring/src/transport/adapter.rs index e1062ac9e8a..479ccb8b55a 100644 --- a/rs/moq-uring/src/transport/adapter.rs +++ b/rs/moq-uring/src/transport/adapter.rs @@ -118,12 +118,20 @@ impl + Clone + 'static> pol .map_err(Error) .map(|res| res.map(|(send, recv)| (SendStream(send), RecvStream(recv)))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, ::Group>) -> Poll> { + fn poll_open_uni( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, ::Group>, + ) -> Poll> { backend::Session::poll_open_uni(&mut self.0, cx) .map_err(Error) .map(|res| res.map(|send| SendStream(send).scheduled(options))) } - fn poll_open_bi(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, ::Group>) -> Poll, Self::Error>> { + fn poll_open_bi( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, ::Group>, + ) -> Poll, Self::Error>> { backend::Session::poll_open_bi(&mut self.0, cx) .map_err(Error) .map(|res| res.map(|(send, recv)| (SendStream(send).scheduled(options), RecvStream(recv)))) @@ -131,7 +139,11 @@ impl + Clone + 'static> pol fn send_group(&mut self, priority: i64) -> Option<::Group> { Grouped::send_group(&mut self.0, priority) } - fn send_datagram(&mut self, payload: Bytes, options: poll::SendOptions<'_, ::Group>) -> Result<(), Self::Error> { + fn send_datagram( + &mut self, + payload: Bytes, + options: poll::SendOptions<'_, ::Group>, + ) -> Result<(), Self::Error> { Grouped::send_datagram(&mut self.0, payload, options).map_err(Error) } fn poll_recv_datagram(&mut self, cx: &mut Context<'_>) -> Poll> { @@ -366,7 +378,9 @@ mod tests { poll::Session::stats(&session).rtt(), Some(std::time::Duration::from_millis(7)) ); - let Poll::Ready(Ok((mut send, mut recv))) = poll::Session::poll_open_bi(&mut session, &mut cx, Default::default()) else { + let Poll::Ready(Ok((mut send, mut recv))) = + poll::Session::poll_open_bi(&mut session, &mut cx, Default::default()) + else { panic!("open failed") }; let mut buf = Bytes::from_static(b"abcd"); diff --git a/rs/moq-uring/tests/integration/web.rs b/rs/moq-uring/tests/integration/web.rs index 648a21afa77..7d2f59e952f 100644 --- a/rs/moq-uring/tests/integration/web.rs +++ b/rs/moq-uring/tests/integration/web.rs @@ -605,7 +605,12 @@ fn a_reset_stream_keeps_its_header() { let err = recv.read_chunk(usize::MAX).await.expect_err("the server reset it"); assert!(matches!(err, moq_tokio::quic::web::ReadError::Reset(7)), "got {err:?}"); - session.open_uni(Default::default()).await.expect("open_uni").reset(8).expect("reset"); + session + .open_uni(Default::default()) + .await + .expect("open_uni") + .reset(8) + .expect("reset"); session.closed().await; }) }); diff --git a/rs/moq-wasm/src/transport/adapter.rs b/rs/moq-wasm/src/transport/adapter.rs index 464f5c483ae..7b6a08e2e10 100644 --- a/rs/moq-wasm/src/transport/adapter.rs +++ b/rs/moq-wasm/src/transport/adapter.rs @@ -67,12 +67,20 @@ impl + Clone + 'st .map_err(Error) .map(|res| res.map(|(send, recv)| (SendStream(send), RecvStream(recv)))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, poll::Ungrouped>) -> Poll> { + fn poll_open_uni( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, poll::Ungrouped>, + ) -> Poll> { backend::Session::poll_open_uni(&mut self.0, cx) .map_err(Error) .map(|res| res.map(|send| SendStream(send).scheduled(options))) } - fn poll_open_bi(&mut self, cx: &mut Context<'_>, options: poll::SendOptions<'_, poll::Ungrouped>) -> Poll, Self::Error>> { + fn poll_open_bi( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, poll::Ungrouped>, + ) -> Poll, Self::Error>> { backend::Session::poll_open_bi(&mut self.0, cx) .map_err(Error) .map(|res| res.map(|(send, recv)| (SendStream(send).scheduled(options), RecvStream(recv)))) @@ -300,7 +308,9 @@ mod tests { poll::Session::stats(&session).rtt(), Some(std::time::Duration::from_millis(7)) ); - let Poll::Ready(Ok((mut send, mut recv))) = poll::Session::poll_open_bi(&mut session, &mut cx, Default::default()) else { + let Poll::Ready(Ok((mut send, mut recv))) = + poll::Session::poll_open_bi(&mut session, &mut cx, Default::default()) + else { panic!("open failed") }; let mut buf = Bytes::from_static(b"abcd"); From 8a13d2b043f6562fcbef0c233431ca5e6a794bfb Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 17 Oct 2026 08:25:09 -0700 Subject: [PATCH 3/6] wip: docs, changelogs, quest notes, mock priority --- doc/setup/upgrade.md | 29 ++++++++++++++++ quest/m1/track-priority-scope.md | 5 +++ quest/m2/drop-web-transport-trait.md | 19 +++++++++++ rs/moq-net/src/lite/test_transport.rs | 4 +-- rs/moq-net/src/transport/memory.rs | 2 +- rs/moq-net/tests/integration/support/mock.rs | 6 ++-- rs/moq-quic/MIGRATE.md | 35 ++++++++++++++++++++ rs/moq-quic/README.md | 5 +-- rs/moq-tokio/src/transport.rs | 8 +++-- 9 files changed, 104 insertions(+), 9 deletions(-) diff --git a/doc/setup/upgrade.md b/doc/setup/upgrade.md index 806bb5a1fa1..c0c83e38ae3 100644 --- a/doc/setup/upgrade.md +++ b/doc/setup/upgrade.md @@ -467,6 +467,35 @@ These land with the next breaking release, not the 2026-09-23 train. decode time (RTMP, a browser) trails by the delay plus the video's send-ahead: 2 s at the new default, where `--delay 500ms` keeps the 1 s it had. moq-srt egress runs at its SRT latency or 1 s, whichever is longer. +- **Custom transports schedule streams and datagrams by send options.** A + transport handed straight to moq-net implements + `poll::Session::send_group(priority)`, returning its `SendStream::Group`, or + `None` with `poll::Ungrouped` when it has no groups, and + `SendStream::set_group`. `poll_open_uni(cx)` and `poll_open_bi(cx)` take a + `poll::SendOptions { group, priority }` the new stream starts with, as do the + `open_uni` and `open_bi` helpers; `SendOptions::default()` is ungrouped at + priority 0. `poll_send_datagram(cx, payload)` is + `send_datagram(payload, options)`, which never blocks. + `SendStream::set_priority` takes an `i64` instead of a `u8`, higher first. + moq-tokio and moq-uring sessions implement all of it already. +- **moq-relay builds its cluster dials from a template.** `Relay::client()` and + `Cluster::with_client` are removed. Give the cluster + `with_connect(connect, quic)`, plus `with_iroh(endpoint)` for `iroh://` + peers, and build your own `moq_tokio::Client` for other outbound dials. +- **moq-sock binds a shard group in one call.** `shard::Group` (`acquire`, + `member`, `complete`), `shard::Member`, `shard::Claim`, and + `shard::cid_prefix` are gone: `shard::bind(addr, count)` returns the + `Bound` group, and moq-quic's `RandomConnectionIdGenerator::set_shard` + names the shard in each connection id. moq-uring's + `quic::endpoint::CID_LEN` is removed too. +- **`moq` refuses a fixed `--connect-bind` for both `--connect` and a WAN + cluster.** They used to share one client; now `--connect` and + `--cluster-connect` or `--cluster-connect-api` each bind it, so a fixed port + stops startup. Use port 0, or drop `--connect`. +- **`--runtime-pin` defaults to off.** moq-relay's per-core workers no longer + pin to cores unless `--runtime-pin`, `MOQ_RUNTIME_PIN`, or `runtime.pin` is + true, since every process pinned to the same first cores. Set it to keep + pinning a relay that has the machine to itself. ## Wire diff --git a/quest/m1/track-priority-scope.md b/quest/m1/track-priority-scope.md index ea657358e09..9fb29bb5ccc 100644 --- a/quest/m1/track-priority-scope.md +++ b/quest/m1/track-priority-scope.md @@ -79,6 +79,11 @@ Direction to settle in the draft first, then the code: presents send order as unrelated. - A per-session cap on distinct ranks is a scheduling detail; whatever replaces the 255-entry sort must stay O(log n) per group under chat-shaped churn. +- moq-quic already has the fair tier: send domains sharing bytes by deficit + round robin, with groups inside them. They are crate-private (exercised only + by its tests) until this quest gives them a consumer. Exposing them also + gives moq-net's `poll::Session::send_group(priority)` a domain, so land that + in the same trait break and implementers break once. Signed priority, decided with the maintainer: diff --git a/quest/m2/drop-web-transport-trait.md b/quest/m2/drop-web-transport-trait.md index 3c05dd0b474..2ecd247b489 100644 --- a/quest/m2/drop-web-transport-trait.md +++ b/quest/m2/drop-web-transport-trait.md @@ -29,6 +29,25 @@ layer instead of reopening it. - Report the public API impact per crate: deleted generic `Session` adapters, and new impls on concrete session types. +The two native QUIC stacks drifted apart behind the adapters. Align them while +each gets its own impl: + +- moq-tokio's `quic::web::Session` derefs to `quic::driver::Connection`, so it + has two `send_datagram`s with different framing: its own prefixes the + WebTransport session id, the driver's reached through `Deref` does not. + Prefer dropping the `Deref` over documenting the trap. +- The driver stream setters disagree: moq-tokio's `set_priority`/`set_group` + take `&self` and return `Result<(), ClosedStream>`, moq-uring's take + `&mut self` and return nothing. +- The sealed `Grouped::send_group` takes `&self` in moq-tokio and `&mut self` + in moq-uring, and only moq-tokio requires `GroupedSend::Group: Send + Sync`. +- moq-uring's driver opens streams only through `web_transport_trait`, so + `SendOptions` reach a new stream through its setters in both runtimes' + adapters. A native impl can pass them to the open, as moq-tokio's driver + `open_uni`/`open_bi` already accept. +- moq-tokio's `quic::driver` and `quic::web` modules are public but + `#[doc(hidden)]`. Decide whether they are API or should be private. + Notes from related quests: - [qmux on moq-quic](/quest/m2/quic-qmux.md) planned to port qmux's `web-transport-trait` impl. If it lands first, its impl targets moq-net's diff --git a/rs/moq-net/src/lite/test_transport.rs b/rs/moq-net/src/lite/test_transport.rs index 26a04e4b0c9..577f25bdc78 100644 --- a/rs/moq-net/src/lite/test_transport.rs +++ b/rs/moq-net/src/lite/test_transport.rs @@ -43,7 +43,7 @@ pub type Rank = (Option, i64); #[derive(Clone, Default)] pub struct Log { pub datagrams: Arc>>, - /// The send group and order each datagram was sent with, beside [`Self::datagrams`]. + /// The send group and priority each datagram was sent with, beside [`Self::datagrams`]. datagram_ranks: Arc>>, pub writes: Arc>>, pub resets: Arc>>, @@ -130,7 +130,7 @@ impl Log { self.orders.lock().unwrap().clone() } - /// The send group and order of every datagram, as (group, order) in call order. + /// The send group and priority of every datagram, as (group, priority) in call order. pub fn datagram_ranks(&self) -> Vec { self.datagram_ranks.lock().unwrap().clone() } diff --git a/rs/moq-net/src/transport/memory.rs b/rs/moq-net/src/transport/memory.rs index 1504eda9921..db944fd01fd 100644 --- a/rs/moq-net/src/transport/memory.rs +++ b/rs/moq-net/src/transport/memory.rs @@ -13,7 +13,7 @@ //! with a code and drops what it queued. Closing the session keeps queued messages //! readable, and leaves streams as they were, so the peer reads them, then the close. //! -//! Datagrams ignore their send group and order, and are dropped when oversized or when the +//! Datagrams ignore their send options, and are dropped when oversized or when the //! peer's queue is full, as a network would. use std::{ diff --git a/rs/moq-net/tests/integration/support/mock.rs b/rs/moq-net/tests/integration/support/mock.rs index 224f714b773..c6f9590d3ed 100644 --- a/rs/moq-net/tests/integration/support/mock.rs +++ b/rs/moq-net/tests/integration/support/mock.rs @@ -557,7 +557,7 @@ impl poll::Session for MockSession { ) -> Poll> { let link = &self.side.out; let mut lines = link.bi.lock().unwrap(); - let (send, recv) = ready!(self.inner.poll_open_bi(cx, options))?; + let (send, recv) = ready!(self.inner.poll_open_bi(cx, Default::default()))?; let held = link.held_bi.lock().unwrap().is_some(); let forward = Arc::new(Line { held, @@ -571,6 +571,7 @@ impl poll::Session for MockSession { drop(lines); let mut send = self.send(send, forward); + poll::SendStream::set_priority(&mut send, options.priority); send.withhold_fin = Some(self.side.withhold_bidi_fins.clone()); send.first_byte = Some(self.side.bidi_types.clone()); Poll::Ready(Ok((send, self.recv(recv, back)))) @@ -587,7 +588,7 @@ impl poll::Session for MockSession { let link = &self.side.out; let mut lines = link.uni.lock().unwrap(); - let send = ready!(self.inner.poll_open_uni(cx, options))?; + let send = ready!(self.inner.poll_open_uni(cx, Default::default()))?; let line = Arc::new(Line { held: link.held_uni.lock().unwrap().is_some(), split: link.split.lock().unwrap().clone(), @@ -597,6 +598,7 @@ impl poll::Session for MockSession { drop(lines); let mut send = self.send(send, line); + poll::SendStream::set_priority(&mut send, options.priority); send.ack = send.line.held; Poll::Ready(Ok(send)) } diff --git a/rs/moq-quic/MIGRATE.md b/rs/moq-quic/MIGRATE.md index 0bff7f133db..418f63c8ce6 100644 --- a/rs/moq-quic/MIGRATE.md +++ b/rs/moq-quic/MIGRATE.md @@ -2,6 +2,41 @@ ## Unreleased +Each entry is a change from `quinn-proto`. + +### Streams and datagrams take `SendOptions` + +`Streams::open` and `Datagrams::send` take a `SendOptions { group, priority }`, +the send group from `Connection::send_groups` and the priority within it. +`SendOptions::default()` is ungrouped at priority 0, where `open` used to start a stream. +A datagram is scheduled with the streams instead of ahead of them, so `send` loses its +`drop` flag: it never blocks, and a full `datagram_send_buffer_size` drops the oldest +datagram of the lowest-priority group. + +```rust +// Before +let id = conn.streams().open(Dir::Uni).unwrap(); +conn.datagrams().send(data, true)?; + +// After +let id = conn.streams().open(Dir::Uni, SendOptions::default()).unwrap(); +conn.datagrams().send(data, SendOptions { group: Some(&group), priority: 0 })?; +``` + +`SendDatagramError::Blocked` and `Event::DatagramsUnblocked` are gone, since sending +never blocks, and `SendDatagramError` is `#[non_exhaustive]`. + +### `SendStream::set_priority` takes an `i64` + +`set_priority` and `priority` use `i64` instead of `i32`, the range of a send group's +priority. Higher still goes first. + +### `fuzzing` module and `arbitrary` feature removed + +The `cfg(fuzzing)` `fuzzing` module and the `arbitrary` feature are gone. The fuzz +targets run through the hidden `fuzz` module behind the `fuzz` feature; see +[`fuzz/`](fuzz/README.md). + ### `congestion::NewReno` removed `congestion::NewReno` and `congestion::NewRenoConfig` are gone. diff --git a/rs/moq-quic/README.md b/rs/moq-quic/README.md index 8d12d1e703a..f4c0e56a610 100644 --- a/rs/moq-quic/README.md +++ b/rs/moq-quic/README.md @@ -66,8 +66,9 @@ Changes on top of the upstream commit, besides the renames: - `TransportConfig::handshake_idle_timeout` (default 10s, as msquic's `HandshakeIdleTimeoutMs`) governs the idle timer until the handshake completes, and the negotiated idle timeout takes over once established. A 2s idle timeout otherwise expires 3x the initial PTO in, just before the second Initial probe, leaving a client two flights. A server also drops an Initial left waiting for `accept` past it, and a deadline too far out to represent never fires instead of panicking. Also [moq-dev/noq#34](https://github.com/moq-dev/noq/pull/34), whose third change (the handshake idle timeout picks noq's idle-based PTO interval cap) has nothing to apply to here, since quinn's PTO backoff has no such cap. quinn's `handshake_timeout` test in its async layer expects the handshake to end at the idle timeout, so the driver's copy sets both timeouts. - **Instants on [moq-clock](../moq-clock)**: the crate's `Instant` is `moq_clock::Instant`, so one clock steps every timer, tokio's paused clock and the simulator included. qlog stamps events relative to `QlogConfig::start_time` on that clock rather than the streamer's own `std::time::Instant`. -- **Send groups** (`streams/schedule.rs`, `Connection::send_groups`): streams outside every group go first, in quinn's order; groups in one scheduling domain are served strictly by priority, with equal priorities sharing bytes by deficit round robin; domains share bytes the same way. A stream's priority is an `i64` ordering it only within its group. This replaces quinn's single pending-stream heap, so a cherry-pick touching `PendingStreamsQueue` has to be redone against the schedule. moq-tokio's `quic::driver` and moq-uring's driver wrap a group in a shared `SendGroup` handle that closes on drop. -- **Scheduled datagrams** (`Datagrams::send`): a datagram is queued in a send group (or ungrouped) at an `i64` order and scheduled with the group's streams, winning a tie with a stream of equal order and spending the group's byte credit, instead of quinn's datagram-first FIFO in `populate_packet`. Sending never blocks: `datagram_send_buffer_size` is shared, and an overflow evicts the oldest datagram of the lowest-priority group in the domain holding the most datagram bytes. `SendDatagramError::Blocked` and `Event::DatagramsUnblocked` are gone, and a cherry-pick touching the `// DATAGRAM` loop has to be redone against `StreamsState::write_frames`. +- **Send groups** (`streams/schedule.rs`, `Connection::send_groups`): streams outside every group go first, in quinn's order; groups are served strictly by priority, with equal priorities sharing bytes by deficit round robin. A stream's priority is an `i64` ordering it only within its group, and `Streams::open` takes a `SendOptions { group, priority }` to start it there, like W3C WebTransport's send options. The schedule also has scheduling domains that share bytes the same way, crate-private until a consumer needs them. This replaces quinn's single pending-stream heap, so a cherry-pick touching `PendingStreamsQueue` has to be redone against the schedule. moq-tokio's `quic::driver` and moq-uring's driver wrap a group in a shared `SendGroup` handle that closes on drop. +- **Scheduled datagrams** (`Datagrams::send`): a datagram is queued by its `SendOptions`, in a send group (or ungrouped) at an `i64` priority, and scheduled with the group's streams, winning a tie with a stream of equal priority and spending the group's byte credit, instead of quinn's datagram-first FIFO in `populate_packet`. Sending never blocks: `datagram_send_buffer_size` is shared, and an overflow evicts the oldest datagram of the lowest-priority group in the domain holding the most datagram bytes. `SendDatagramError::Blocked` and `Event::DatagramsUnblocked` are gone, and a cherry-pick touching the `// DATAGRAM` loop has to be redone against `StreamsState::write_frames`. +- **Sharded connection IDs** (`RandomConnectionIdGenerator::set_shard`): every CID names shard `index` of a `count`-endpoint group in its first byte, modulo `count`, and sets a marker in its fourth byte, so a `SO_REUSEPORT` steering filter delivers a packet to the endpoint that issued its CID. `validate` refuses a CID without this shard's prefix and marker, so a misrouted packet is dropped instead of answered with a stateless reset. Not offered upstream; it serves moq-sock's per-core sharding. - **`RESET_STREAM_AT`** ([draft-ietf-quic-reliable-stream-reset](https://datatracker.ietf.org/doc/draft-ietf-quic-reliable-stream-reset/)): the `reset_stream_at` transport parameter is always advertised, `Checkpoint::reset` (from `SendStream::checkpoint`) keeps the data written before the checkpoint reliable, holding a plain `RESET_STREAM` until that data is acknowledged when the peer lacks the extension, and a received reset surfaces only once the reliable prefix has been read. Stopping a stream after it was reset no longer credits its unread data twice. - **Fuzzing** runs through the hidden `fuzz` module behind a `fuzz` feature, with one-line shims in [`fuzz/`](fuzz/README.md): upstream's `packet`, `params`, `streamid`, and `streams` targets, plus `frame` and a connection op sequence. Upstream's `cfg(fuzzing)` `fuzzing` module and `arbitrary` feature are gone, so its fuzz patches port by hand. - **Draining endpoint event**: `EndpointEvent::is_draining` fires once per connection when it stops being active, before the drained event, so the driver's `Endpoint::wait_all_draining` can end a shutdown without sitting out every closing period. diff --git a/rs/moq-tokio/src/transport.rs b/rs/moq-tokio/src/transport.rs index 9befc0d04ae..e16bc044155 100644 --- a/rs/moq-tokio/src/transport.rs +++ b/rs/moq-tokio/src/transport.rs @@ -63,8 +63,12 @@ impl std::fmt::Display for Transport { /// plain boxed flavor suffices. type OpBox = futures::future::BoxFuture<'static, T>; -/// Adapts a transport that only implements the async interface -/// ([`web_transport_trait::Session`]) to the poll interface this crate requires. +/// Adapts one of this crate's async backends (qmux, iroh, quic) to the poll interface +/// moq-net requires. +/// +/// Only those backends fit: the bound goes through a sealed trait, so another +/// [`web_transport_trait::Session`] cannot be wrapped. A custom transport implements +/// moq-net's `transport::poll` traits instead. /// /// Each pending session operation is stored as a boxed future built from a clone /// of the underlying session; stream operations temporarily move the stream into From 20a7d0ee6a6c0bb661d6b3845d314550f1158cbe Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 17 Oct 2026 08:44:49 -0700 Subject: [PATCH 4/6] fix(quic): refuse a foreign group before opening --- rs/moq-quic/src/connection/streams/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rs/moq-quic/src/connection/streams/mod.rs b/rs/moq-quic/src/connection/streams/mod.rs index 67584fb62c3..d97adbaae22 100644 --- a/rs/moq-quic/src/connection/streams/mod.rs +++ b/rs/moq-quic/src/connection/streams/mod.rs @@ -49,6 +49,7 @@ impl<'a> Streams<'a> { /// # Panics /// - when `options.group` was opened on another connection pub fn open(&mut self, dir: Dir, options: SendOptions<'_>) -> Option { + let group = options.group.map(|g| g.index(self.state.tag)); if self.conn_state.is_closed() { return None; } @@ -65,7 +66,7 @@ impl<'a> Streams<'a> { self.state.send_streams += 1; // Send state is allocated on first use, so the default schedule needs none. - if options.group.is_some() || options.priority != 0 { + if group.is_some() || options.priority != 0 { let max_send_data = self.state.max_send_data(id); let stream = self .state @@ -74,7 +75,6 @@ impl<'a> Streams<'a> { .unwrap() .insert(Send::new(max_send_data)); stream.priority = options.priority; - let group = options.group.map(|g| g.index(self.state.tag)); self.state .pending .join(id, &mut stream.slot, group, stream.priority); @@ -539,8 +539,8 @@ impl Checkpoint { /// /// A higher priority group preempts every lower one, and groups of equal priority get an /// equal share of bytes no matter how many streams each has queued. Streams outside any group -/// go before all of it. A group's datagrams, -/// from [`Datagrams::send`](crate::Datagrams::send), share its bytes in the same order. +/// go before all of it. A group's datagrams, from [`Datagrams::send`](crate::Datagrams::send), +/// share its bytes in the same order. pub struct SendGroups<'a> { pub(super) state: &'a mut StreamsState, } From f700ead3197974bac305d3e2db82e1f335db2e36 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 17 Oct 2026 12:41:30 -0700 Subject: [PATCH 5/6] fix: port main's new transport callers to send options moq-uring's Local wrapper and a few tests from main still used the positional open and datagram signatures. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/ietf/adapter.rs | 2 +- rs/moq-net/src/lite/subscriber.rs | 2 +- rs/moq-quic/src/tests/mod.rs | 5 ++++- rs/moq-uring/src/transport/local.rs | 29 ++++++++++++++++++++++------- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/rs/moq-net/src/ietf/adapter.rs b/rs/moq-net/src/ietf/adapter.rs index 10495265898..2bf51eac65b 100644 --- a/rs/moq-net/src/ietf/adapter.rs +++ b/rs/moq-net/src/ietf/adapter.rs @@ -1994,7 +1994,7 @@ mod tests { }; let script = encode_raw(ietf::SubscribeUpdate::ID, &Bytes::copy_from_slice(body), version); let mut session = ScriptedSession::new(script.to_vec()); - let (_, recv) = session.open_bi().await.unwrap(); + let (_, recv) = session.open_bi(Default::default()).await.unwrap(); let adapter = ControlStreamAdapter::new(session, Control::new(None, false), version); let log = Log::default(); let writer = Writer::new(SinkSend::new(log.clone()), version); diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 4da0fee709f..bbd31c825d2 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -2313,7 +2313,7 @@ mod tests { }, ); - let (_, recv) = session.open_bi().await.unwrap(); + let (_, recv) = session.open_bi(Default::default()).await.unwrap(); let mut group = GroupRecv::new(subscriber, Reader::new(recv, version)); let res = kio::wait(|waiter| group.poll_serve(waiter)).await; (res, track) diff --git a/rs/moq-quic/src/tests/mod.rs b/rs/moq-quic/src/tests/mod.rs index ca33a9cd606..b0ded60c966 100644 --- a/rs/moq-quic/src/tests/mod.rs +++ b/rs/moq-quic/src/tests/mod.rs @@ -2285,7 +2285,10 @@ fn unreachable_is_loss_once_established() { assert!(!pair.client_conn_mut(client_ch).is_closed()); assert_matches!(pair.client_conn_mut(client_ch).poll(), None); - let s = pair.client_streams(client_ch).open(Dir::Uni).unwrap(); + let s = pair + .client_streams(client_ch) + .open(Dir::Uni, Default::default()) + .unwrap(); pair.client_send(client_ch, s).write(b"hello").unwrap(); pair.drive(); assert_matches!( diff --git a/rs/moq-uring/src/transport/local.rs b/rs/moq-uring/src/transport/local.rs index 9161d0100e1..7c42bcb9b7c 100644 --- a/rs/moq-uring/src/transport/local.rs +++ b/rs/moq-uring/src/transport/local.rs @@ -22,6 +22,14 @@ impl Local { } } +/// Unwrap the send group of `options`, checking the thread. +fn unwrap<'a, G>(options: poll::SendOptions<'a, Local>) -> poll::SendOptions<'a, G> { + poll::SendOptions { + group: options.group.map(|group| &*group.0), + priority: options.priority, + } +} + impl poll::Session for Local { type SendStream = Local; type RecvStream = Local; @@ -37,13 +45,21 @@ impl poll::Session for Local { .map_ok(|(send, recv)| (Local::new(send), Local::new(recv))) } - fn poll_open_uni(&mut self, cx: &mut Context<'_>) -> Poll> { - self.0.poll_open_uni(cx).map_ok(Local::new) + fn poll_open_uni( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, Local<::Group>>, + ) -> Poll> { + self.0.poll_open_uni(cx, unwrap(options)).map_ok(Local::new) } - fn poll_open_bi(&mut self, cx: &mut Context<'_>) -> Poll, Self::Error>> { + fn poll_open_bi( + &mut self, + cx: &mut Context<'_>, + options: poll::SendOptions<'_, Local<::Group>>, + ) -> Poll, Self::Error>> { self.0 - .poll_open_bi(cx) + .poll_open_bi(cx, unwrap(options)) .map_ok(|(send, recv)| (Local::new(send), Local::new(recv))) } @@ -54,10 +70,9 @@ impl poll::Session for Local { fn send_datagram( &mut self, payload: Bytes, - group: Option<&Local<::Group>>, - order: i64, + options: poll::SendOptions<'_, Local<::Group>>, ) -> Result<(), Self::Error> { - self.0.send_datagram(payload, group.map(|group| &*group.0), order) + self.0.send_datagram(payload, unwrap(options)) } fn poll_recv_datagram(&mut self, cx: &mut Context<'_>) -> Poll> { From a5ef707e2b1d14de0a9769da71198ee12cdd6763 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 17 Oct 2026 13:01:24 -0700 Subject: [PATCH 6/6] fix(quic): wrap moq-quic datagram errors instead of panicking moq-quic's SendDatagramError is non_exhaustive, so the tokio driver's wildcard would panic on a new variant. Carry it in one transparent Refused variant, and link the upgrade note to the poll trait docs. Co-Authored-By: Claude Opus 5.5 --- doc/setup/upgrade.md | 18 +++++------ rs/moq-tokio/src/quic/driver/connection.rs | 35 +++++----------------- rs/moq-tokio/src/quic/web/error.rs | 26 ---------------- 3 files changed, 15 insertions(+), 64 deletions(-) diff --git a/doc/setup/upgrade.md b/doc/setup/upgrade.md index 63a6efe1216..bce00e326f9 100644 --- a/doc/setup/upgrade.md +++ b/doc/setup/upgrade.md @@ -468,16 +468,14 @@ These land with the next breaking release, not the 2026-09-23 train. send-ahead: 2 s at the new default, where `--delay 500ms` keeps the 1 s it had. moq-srt egress runs at its SRT latency or 1 s, whichever is longer. - **Custom transports schedule streams and datagrams by send options.** A - transport handed straight to moq-net implements - `poll::Session::send_group(priority)`, returning its `SendStream::Group`, or - `None` with `poll::Ungrouped` when it has no groups, and - `SendStream::set_group`. `poll_open_uni(cx)` and `poll_open_bi(cx)` take a - `poll::SendOptions { group, priority }` the new stream starts with, as do the - `open_uni` and `open_bi` helpers; `SendOptions::default()` is ungrouped at - priority 0. `poll_send_datagram(cx, payload)` is - `send_datagram(payload, options)`, which never blocks. - `SendStream::set_priority` takes an `i64` instead of a `u8`, higher first. - moq-tokio and moq-uring sessions implement all of it already. + transport handed straight to moq-net implements the + [`transport::poll`](https://docs.rs/moq-net/latest/moq_net/transport/poll/index.html) + traits, which now add send groups. Opening a stream takes a + `poll::SendOptions { group, priority }` it starts with, and a datagram is + sent with `send_datagram(payload, options)`, which never blocks. + `SendOptions::default()` is ungrouped at priority 0, and priorities are an + `i64` instead of a `u8`, higher first. moq-tokio and moq-uring sessions + implement all of it already. - **moq-relay builds its cluster dials from a template.** `Relay::client()` and `Cluster::with_client` are removed. Give the cluster `with_connect(connect, quic)`, plus `with_iroh(endpoint)` for `iroh://` diff --git a/rs/moq-tokio/src/quic/driver/connection.rs b/rs/moq-tokio/src/quic/driver/connection.rs index a244c2f11a4..6913eb8382e 100644 --- a/rs/moq-tokio/src/quic/driver/connection.rs +++ b/rs/moq-tokio/src/quic/driver/connection.rs @@ -543,23 +543,11 @@ impl Connection { if let Some(x) = &conn.error { return Err(SendDatagramError::ConnectionLost(x.clone())); } - use moq_quic::SendDatagramError::*; - match conn - .inner + conn.inner .datagrams() - .send(data, send_group::to_quic(options)) - { - Ok(()) => { - conn.wake(); - Ok(()) - } - Err(e) => Err(match e { - UnsupportedByPeer => SendDatagramError::UnsupportedByPeer, - Disabled => SendDatagramError::Disabled, - TooLarge => SendDatagramError::TooLarge, - e => unreachable!("unmapped datagram error: {e}"), - }), - } + .send(data, send_group::to_quic(options))?; + conn.wake(); + Ok(()) } /// Compute the maximum size of datagrams that may be passed to [`send_datagram()`]. @@ -1432,18 +1420,9 @@ fn wake_all_notify(wakers: &mut FxHashMap>) { #[derive(Debug, Error, Clone, Eq, PartialEq)] #[non_exhaustive] pub enum SendDatagramError { - /// The peer does not support receiving datagram frames - #[error("datagrams not supported by peer")] - UnsupportedByPeer, - /// Datagram support is disabled locally - #[error("datagram support disabled")] - Disabled, - /// The datagram is larger than the connection can currently accommodate - /// - /// Indicates that the path MTU minus overhead or the limit advertised by the peer has been - /// exceeded. - #[error("datagram too large")] - TooLarge, + /// The connection refused the datagram. + #[error(transparent)] + Refused(#[from] moq_quic::SendDatagramError), /// The connection was lost #[error("connection lost")] ConnectionLost(#[from] ConnectionError), diff --git a/rs/moq-tokio/src/quic/web/error.rs b/rs/moq-tokio/src/quic/web/error.rs index 57d9eb1916b..1679d8dbe94 100644 --- a/rs/moq-tokio/src/quic/web/error.rs +++ b/rs/moq-tokio/src/quic/web/error.rs @@ -307,32 +307,6 @@ pub enum ServerError { Rustls(#[from] rustls::Error), } -// #[derive(Clone, Error, Debug)] -// pub enum SendDatagramError { -// #[error("Unsupported peer")] -// UnsupportedPeer, - -// #[error("Datagram support Disabled by peer")] -// DatagramSupportDisabled, - -// #[error("Datagram Too large")] -// TooLarge, - -// #[error("Session errorr: {0}")] -// SessionError(#[from] SessionError), -// } - -// impl From for SendDatagramError { -// fn from(value: crate::quic::driver::SendDatagramError) -> Self { -// match value { -// crate::quic::driver::SendDatagramError::UnsupportedByPeer => SendDatagramError::UnsupportedPeer, -// crate::quic::driver::SendDatagramError::Disabled => SendDatagramError::DatagramSupportDisabled, -// crate::quic::driver::SendDatagramError::TooLarge => SendDatagramError::TooLarge, -// crate::quic::driver::SendDatagramError::ConnectionLost(e) => -// SendDatagramError::SessionError(e.into()), } -// } -// } - impl web_transport_trait::Error for SessionError { fn session_error(&self) -> Option<(u32, String)> { if let SessionError::WebTransportError(WebTransportError::Closed(code, reason)) = self {