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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ objc2-screen-capture-kit = "0.3.2"
object_store = { version = "0.14", default-features = false }
percent-encoding = "2"
pollster = "1.0"
qmux = { version = "0.6", default-features = false }
qmux = { version = "0.6.3", default-features = false }
rand = "0.10.1"
# default-features off so each consumer picks its own TLS backend and body
# features; nothing here wants the default native-tls stack.
Expand Down
13 changes: 13 additions & 0 deletions rs/moq-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ pub mod watch;
#[cfg(feature = "websocket")]
pub mod websocket;

/// Session settings for every qmux transport (WebSocket, `tcp://`, `tls://`, `unix://`).
///
/// moq-lite holds a stream open per subscription, so a qmux session grants the same
/// stream count as QUIC rather than qmux's default of 100, past which a peer's opens
/// wait on credit forever.
#[cfg(any(feature = "websocket", feature = "tcp"))]
fn qmux_config() -> qmux::Config {
let mut config = qmux::Config::default();
config.max_streams_bidi = quic::DEFAULT_MAX_STREAMS;
config.max_streams_uni = quic::DEFAULT_MAX_STREAMS;
config
}

// Enumerated rather than globbed, so the root surface is a deliberate list and a
// new `pub` item in these modules doesn't silently join it.
pub use client::Client;
Expand Down
43 changes: 40 additions & 3 deletions rs/moq-tokio/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ pub(crate) async fn connect_tls(
crate::tls::server_name(&name)?;
let client = qmux::tls::Client::new(std::sync::Arc::new(tls.build()?))
.with_protocols(protocols.iter().map(|&alpn| (alpn, &[WIRE_VERSION][..])))
.require_protocol();
.require_protocol()
.with_session_config(crate::qmux_config());

tracing::debug!(peer = %crate::connect::Endpoint(&url), "connecting via TLS over TCP");
let candidates = crate::resolve::Candidates::resolve(host, port, resolution_delay);
Expand Down Expand Up @@ -221,6 +222,7 @@ async fn connect_addrs(
async move {
qmux::tcp::Config::new(WIRE_VERSION)
.protocols(protocols.iter().map(String::as_str))
.session_config(crate::qmux_config())
.connect(addr)
.await
.map_err(|err| Error::Connect(crate::error::message(err)))
Expand Down Expand Up @@ -253,7 +255,7 @@ impl Listener {
/// Serve TLS with `config`, whose ALPN list already names each
/// `qmux-01.<protocol>` pair to accept.
pub(crate) fn with_tls(mut self, config: std::sync::Arc<rustls::ServerConfig>) -> Self {
self.tls = Some(qmux::tls::Server::new(config));
self.tls = Some(qmux::tls::Server::new(config).with_session_config(crate::qmux_config()));
self
}

Expand Down Expand Up @@ -310,7 +312,9 @@ impl Listener {
) -> impl Future<Output = Result<(qmux::Session, net::SocketAddr)>> + use<> {
let (stream, addr) = self.accept_socket().await;
tracing::debug!(%addr, "accepted TCP connection");
let config = qmux::tcp::Config::new(WIRE_VERSION).protocols(self.protocols.iter().map(String::as_str));
let config = qmux::tcp::Config::new(WIRE_VERSION)
.protocols(self.protocols.iter().map(String::as_str))
.session_config(crate::qmux_config());
let tls = self.tls.clone();
async move {
let session = match tls {
Expand Down Expand Up @@ -459,6 +463,39 @@ mod tests {
accept.await.expect("accept task panicked");
}

/// moq-lite holds a stream open per subscription, so each end of a session must
/// let its peer hold far more than qmux's default of 100 open at once.
#[tokio::test]
async fn sessions_grant_a_thousand_open_streams() {
use futures::FutureExt as _;

let listener = Listener::bind("127.0.0.1:0".parse().unwrap())
.await
.expect("bind listener")
.with_protocols(["moq-test"]);
let addr = listener.local_addr().expect("local addr");
let accept = tokio::spawn(async move { listener.accept().await.expect("listener gone").expect("accept") });
let candidates = crate::resolve::Candidates::fixed([addr]);
let client = connect_addrs(candidates, &["moq-test"], Duration::ZERO)
.await
.expect("connect failed");
let server = accept.await.expect("accept task panicked");

// Both handshakes are done, so each end knows its peer's grant, and an open
// with credit left completes without waiting.
for (end, session) in [("client", &client), ("server", &server)] {
let mut held = Vec::new();
for opened in 0..1_000 {
let bi = session.open_bi().now_or_never();
let uni = session.open_uni().now_or_never();
let (Some(bi), Some(uni)) = (bi, uni) else {
panic!("{end} stalled on stream credit after opening {opened} stream pairs");
};
held.push((bi.expect("open bi"), uni.expect("open uni")));
}
}
}

#[tokio::test]
async fn connect_addrs_rejects_empty() {
let candidates = crate::resolve::Candidates::fixed([]);
Expand Down
5 changes: 4 additions & 1 deletion rs/moq-tokio/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ pub(crate) async fn connect(url: Url, protocols: &[&str]) -> Result<qmux::Sessio
tracing::debug!(peer = %crate::connect::Endpoint(&url), "connecting via Unix socket");
qmux::uds::Config::new(WIRE_VERSION)
.protocols(protocols.iter().copied())
.session_config(crate::qmux_config())
.connect(path)
.await
.map_err(|err| Error::Connect(crate::error::message(err)))
Expand Down Expand Up @@ -354,7 +355,9 @@ impl Listener {
/// Accept a socket and return its independently driven qmux handshake.
pub(crate) async fn accept_pending(&self) -> impl Future<Output = Result<(qmux::Session, PeerCred)>> + use<> {
let stream = self.accept_socket().await;
let config = qmux::uds::Config::new(WIRE_VERSION).protocols(self.protocols.iter().map(String::as_str));
let config = qmux::uds::Config::new(WIRE_VERSION)
.protocols(self.protocols.iter().map(String::as_str))
.session_config(crate::qmux_config());
async move {
let cred = stream.peer_cred()?;
let cred = PeerCred {
Expand Down
13 changes: 10 additions & 3 deletions rs/moq-tokio/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ where
.and_then(|timeout| tokio::time::Instant::now().checked_add(timeout));
// A vanished peer sends no FIN. Ping and timeout bound the same stale-session
// lifetime that QUIC's idle timeout bounds on the native path.
let mut upgraded = qmux::ws::Upgraded::new(socket).with_keep_alive(qmux::ws::KeepAlive::default());
let mut upgraded = qmux::ws::Upgraded::new(socket)
.with_keep_alive(qmux::ws::KeepAlive::default())
.with_session_config(crate::qmux_config());
if let Some(stats) = &options.socket_stats {
upgraded = upgraded.with_socket_stats(stats.clone());
}
Expand Down Expand Up @@ -455,6 +457,7 @@ pub(crate) async fn connect(
.with_protocols(alpns.iter().map(|&a| (a, qmux_versions_for(a))))
.with_connector(connector)
.with_keep_alive(qmux::ws::KeepAlive::default()) // 5s ping / 30s deadline; TCP backs off retransmits too far for QUIC's 10s
.with_session_config(crate::qmux_config())
.connect(url.as_str())
.await
.map_err(Error::connect)?
Expand Down Expand Up @@ -513,7 +516,9 @@ async fn connect_tls_override(
.headers()
.get(http::header::SEC_WEBSOCKET_PROTOCOL)
.and_then(|value| value.to_str().ok());
let upgraded = qmux::ws::Upgraded::new(websocket).with_keep_alive(qmux::ws::KeepAlive::default());
let upgraded = qmux::ws::Upgraded::new(websocket)
.with_keep_alive(qmux::ws::KeepAlive::default())
.with_session_config(crate::qmux_config());
Ok(match negotiated {
Some(protocol) => upgraded.with_alpn(protocol).connect(),
None => upgraded.connect(),
Expand Down Expand Up @@ -719,7 +724,9 @@ impl Listener {
.unwrap()
.take()
.expect("successful upgrade selected a protocol");
let upgraded = qmux::ws::Upgraded::new(websocket).with_keep_alive(qmux::ws::KeepAlive::default());
let upgraded = qmux::ws::Upgraded::new(websocket)
.with_keep_alive(qmux::ws::KeepAlive::default())
.with_session_config(crate::qmux_config());
let session = match &protocol {
Some(protocol) => upgraded.with_alpn(protocol).accept(),
None => upgraded.accept(),
Expand Down
Loading