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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/a1/node-idle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ The native configuration and Node option quests are independently reviewable. Th

## Required

- [Native transport configuration](/quest/a1/node-idle/native-transport-config.md) - typed reusable builder input
- [Node options](/quest/a1/node-idle/options.md) - explicit millisecond options and runtime behavior
11 changes: 0 additions & 11 deletions quest/a1/node-idle/native-transport-config.md

This file was deleted.

4 changes: 0 additions & 4 deletions quest/a1/node-idle/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ Expose explicit millisecond options, validate finite representable values, and d

Keep the default idle timeout and absent keepalive behavior. Test configured expiry, preserved default configuration, disabled behavior, keepalive maintaining an otherwise idle connection and invalid input rejection. Use deterministic configuration/unit coverage where possible; exercise actual Node runtime sessions for the integration behavior. Update generated declarations through the normal generation path, wrapper options and examples in the same PR.

## Required

- [Native transport configuration](/quest/a1/node-idle/native-transport-config.md) - supply options consistently through existing construction paths

## Closes

- [#219](https://github.com/moq-dev/web-transport/issues/219) - the implementation completes this report
25 changes: 25 additions & 0 deletions rs/web-transport-quinn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ Both are spawned on the runtime that [quinn::default_runtime](https://docs.rs/qu
Tokio works out of the box. To run on async-std or smol instead, enable quinn's `runtime-async-std` or `runtime-smol` feature in your own `Cargo.toml`.
Resolving a hostname in `Client::connect` still uses tokio, so outside a tokio runtime connect to an IP address or resolve the name yourself.

## Transport configuration

`ClientBuilder::with_transport_config` and `ServerBuilder::with_transport_config` take an owned `quinn::TransportConfig`. When omitted, the builders use Quinn's defaults: a 30-second maximum idle timeout, no keepalive, and CUBIC congestion control. The transport configuration applies to every client certificate-verification path and to server connections.

```rust,no_run
use std::time::Duration;
use web_transport_quinn::{quinn, ClientBuilder, CongestionControl};

# fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut transport = quinn::TransportConfig::default();
transport.max_idle_timeout(Some(Duration::from_secs(60).try_into()?));
transport.keep_alive_interval(Some(Duration::from_secs(10)));

let client = ClientBuilder::new()
.with_transport_config(transport)
.with_congestion_control(CongestionControl::LowLatency)
.with_system_roots()?;
# Ok(())
# }
```

An explicit `LowLatency` or `Throughput` congestion choice overrides only the configuration's congestion controller, regardless of builder call order. `Default` removes that override and preserves the supplied controller. Calling `with_transport_config` again replaces the supplied configuration; other settings survive the congestion override.

Quinn's `TransportConfig` is not cloneable, so `ClientBuilder` owns it and does not implement `Clone`. Construct a builder for each configuration, then clone the finished `Client` to share its endpoint and settings across connections.

## API
The `web-transport-quinn` API is almost identical to the Quinn API, except that [Connection](https://docs.rs/quinn/latest/quinn/struct.Connection.html) is called [Session](https://docs.rs/web-transport-quinn/latest/web_transport_quinn/struct.Session.html).

Expand Down
163 changes: 158 additions & 5 deletions rs/web-transport-quinn/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{ClientError, Session};
///
/// Different algorithms make different tradeoffs between throughput and latency.
pub enum CongestionControl {
/// Use the default congestion control algorithm (typically CUBIC).
/// Keep the transport configuration's controller (Quinn defaults to CUBIC).
Default,
/// Optimize for throughput (typically CUBIC).
Throughput,
Expand All @@ -44,9 +44,9 @@ pub(crate) fn controller_factory(algorithm: CongestionControl) -> Option<Control
/// drift on which knobs actually get applied.
#[cfg(any(feature = "aws-lc-rs", feature = "ring"))]
pub(crate) fn transport_config(
mut transport: quinn::TransportConfig,
congestion_controller: Option<&ControllerFactory>,
) -> Arc<quinn::TransportConfig> {
let mut transport = quinn::TransportConfig::default();
if let Some(cc) = congestion_controller {
transport.congestion_controller_factory(cc.clone());
}
Expand All @@ -58,9 +58,10 @@ pub(crate) fn transport_config(
/// Construct a WebTransport [Client] using sane defaults.
///
/// This is optional; advanced users may use [Client::new] directly.
#[derive(Clone)]
/// Build a client before cloning it to share its endpoint and configuration.
pub struct ClientBuilder {
provider: crypto::Provider,
transport: quinn::TransportConfig,
congestion_controller: Option<ControllerFactory>,
}

Expand All @@ -70,11 +71,24 @@ impl ClientBuilder {
pub fn new() -> Self {
Self {
provider: crypto::default_provider(),
transport: quinn::TransportConfig::default(),
congestion_controller: None,
}
}

/// Enable the specified congestion controller.
/// Use the supplied QUIC transport configuration instead of Quinn's defaults.
///
/// An explicit [`Self::with_congestion_control`] choice overrides only its
/// congestion controller, regardless of the order these methods are called.
pub fn with_transport_config(mut self, transport: quinn::TransportConfig) -> Self {
self.transport = transport;
self
}

/// Override the transport configuration's congestion controller.
///
/// [`CongestionControl::Default`] preserves the supplied configuration's
/// controller, or Quinn's default when no configuration is supplied.
pub fn with_congestion_control(mut self, algorithm: CongestionControl) -> Self {
self.congestion_controller = controller_factory(algorithm);
self
Expand Down Expand Up @@ -160,7 +174,10 @@ impl ClientBuilder {

let client_config = QuicClientConfig::try_from(crypto).unwrap();
let mut client_config = quinn::ClientConfig::new(Arc::new(client_config));
client_config.transport_config(transport_config(self.congestion_controller.as_ref()));
client_config.transport_config(transport_config(
self.transport,
self.congestion_controller.as_ref(),
));

let client = quinn::Endpoint::client("[::]:0".parse().unwrap()).unwrap();
Ok(Client {
Expand Down Expand Up @@ -390,3 +407,139 @@ impl rustls::client::danger::ServerCertVerifier for NoCertificateVerification {
self.0.signature_verification_algorithms.supported_schemes()
}
}

#[cfg(all(test, any(feature = "aws-lc-rs", feature = "ring")))]
pub(crate) mod tests {
use super::*;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;

pub(crate) fn builder() -> ClientBuilder {
// Avoid a process-wide provider when both features are enabled.
#[cfg(feature = "aws-lc-rs")]
let provider = Arc::new(rustls::crypto::aws_lc_rs::default_provider());
#[cfg(all(feature = "ring", not(feature = "aws-lc-rs")))]
let provider = Arc::new(rustls::crypto::ring::default_provider());

ClientBuilder {
provider,
transport: quinn::TransportConfig::default(),
congestion_controller: None,
}
}

struct CountingController(Arc<AtomicUsize>);

impl quinn::congestion::ControllerFactory for CountingController {
fn build(
self: Arc<Self>,
now: std::time::Instant,
mtu: u16,
) -> Box<dyn quinn::congestion::Controller> {
self.0.fetch_add(1, Ordering::SeqCst);
Arc::new(quinn::congestion::NewRenoConfig::default()).build(now, mtu)
}
}

pub(crate) fn custom_transport() -> (quinn::TransportConfig, Arc<AtomicUsize>) {
let built = Arc::new(AtomicUsize::new(0));
let mut transport = quinn::TransportConfig::default();
transport
.max_idle_timeout(Some(Duration::from_secs(12).try_into().unwrap()))
.keep_alive_interval(Some(Duration::from_secs(3)))
.congestion_controller_factory(Arc::new(CountingController(built.clone())));
(transport, built)
}

pub(crate) fn assert_transport(config: &impl std::fmt::Debug, custom: bool) {
// Quinn exposes these settings only through Debug.
let expected = if custom {
custom_transport().0
} else {
quinn::TransportConfig::default()
};
let expected = format!("{expected:?}");
let config = format!("{config:?}");
assert!(config.contains(&expected), "{config}");
}

fn finish(builder: ClientBuilder, path: u8) -> Client {
match path {
0 => builder.with_system_roots(),
1 => builder.with_server_certificate_hashes(vec![]),
2 => builder.with_server_certificates(vec![]),
3 => builder.dangerous().with_no_certificate_verification(),
_ => unreachable!(),
}
.unwrap()
}

#[tokio::test]
async fn builder_transport_reaches_every_client_config() {
for path in 0..4 {
let client = finish(builder(), path);
assert_transport(&client.config, false);

for transport_first in [false, true] {
for algorithm in [
CongestionControl::Default,
CongestionControl::LowLatency,
CongestionControl::Throughput,
] {
let overridden = !matches!(algorithm, CongestionControl::Default);
let (transport, built) = custom_transport();
let builder = builder();
let builder = if transport_first {
builder
.with_transport_config(transport)
.with_congestion_control(algorithm)
} else {
builder
.with_congestion_control(algorithm)
.with_transport_config(transport)
};
let client = finish(builder, path);
assert_transport(&client.config, true);

// Controller construction happens before any network/TLS result,
// so the system-root path needs no publicly trusted test server.
let connecting = client
.endpoint
.connect_with(
client.config.clone(),
"[::1]:9".parse().unwrap(),
"localhost",
)
.unwrap();
assert_eq!(built.load(Ordering::SeqCst), usize::from(!overridden));
drop(connecting);
client.endpoint.close(0u32.into(), b"done");
}
}
}
}

#[tokio::test]
async fn default_congestion_control_removes_only_the_overlay() {
let (transport, built) = custom_transport();
let client = builder()
.with_transport_config(transport)
.with_congestion_control(CongestionControl::LowLatency)
.with_congestion_control(CongestionControl::Default)
.dangerous()
.with_no_certificate_verification()
.unwrap();
assert_transport(&client.config, true);
let connecting = client
.endpoint
.connect_with(
client.config.clone(),
"[::1]:9".parse().unwrap(),
"localhost",
)
.unwrap();
assert_eq!(built.load(Ordering::SeqCst), 1);
drop(connecting);
client.endpoint.close(0u32.into(), b"done");
}
}
Loading
Loading