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/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ The Required list is ordered by priority. Independent children may proceed concu

## Required

- [Dual-stack bind](/quest/a1/dual-stack-bind.md) - native clients bind by the server's address family
- [Rust crates on rind](/quest/a1/rind/README.md) - no C crypto outside Quiche
- [Binding runtime coverage](/quest/a1/bindings/README.md) - independent language jobs
- [Node idle configuration](/quest/a1/node-idle/README.md) - typed native input and Node options
Expand Down
32 changes: 0 additions & 32 deletions quest/a1/dual-stack-bind.md

This file was deleted.

1 change: 0 additions & 1 deletion quest/a1/native-client-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ Do not add a pretend browser certificate-verification bypass, a browser panic or

## Related

- [Dual-stack bind](/quest/a1/dual-stack-bind.md) - edits the same Quinn client construction
- [Quinn on rind](/quest/a1/rind/quinn.md) - replaces the crypto these builders configure
1 change: 0 additions & 1 deletion quest/a1/rind/quinn.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ Decided with the maintainer on 2026-11-06 (planning interview):
## Related

- [Native client composition](/quest/a1/native-client-config.md) - converts a configured Quinn client into the router
- [Dual-stack bind](/quest/a1/dual-stack-bind.md) - rebuilds the same builders' endpoints
6 changes: 6 additions & 0 deletions rs/web-transport-ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Low-level UniFFI bindings for WebTransport over HTTP/3 (QUIC). Generates Python,

For an ergonomic Python API (async context managers, legacy exception hierarchy), see [`web-transport-rs`](https://pypi.org/project/web-transport-rs/) which wraps this package.

Clients lazily share one socket per destination address family: IPv4 uses
`0.0.0.0:0`, IPv6 uses IPv6-only `[::]:0`, and IPv4-mapped IPv6 uses IPv4.
Socket setup errors are returned by `connect`. `close` and final client drop
close both sockets, including pending connections. Call `close` before awaiting
`wait_closed` to prevent new connections while both sockets drain.

## Building

```bash
Expand Down
20 changes: 6 additions & 14 deletions rs/web-transport-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ impl Default for ClientConfig {
#[derive(uniffi::Object)]
pub struct Client {
inner: web_transport_quinn::Client,
endpoint: quinn::Endpoint,
}

#[uniffi::export]
Expand Down Expand Up @@ -143,15 +142,8 @@ impl Client {
client_config.transport_config(transport.into());

let _guard = RUNTIME.enter();
let endpoint = quinn::Endpoint::client("[::]:0".parse().unwrap())
.or_else(|_| quinn::Endpoint::client("0.0.0.0:0".parse().unwrap()))
.map_err(|e| WebTransportError::Io(format!("failed to create endpoint: {e}")))?;

let client = web_transport_quinn::Client::new(endpoint.clone(), client_config);

Ok(Arc::new(Self {
inner: client,
endpoint,
inner: web_transport_quinn::Client::from(client_config),
}))
}

Expand All @@ -178,15 +170,15 @@ impl Client {
let var_code = quinn::VarInt::from_u64(code)
.map_err(|_| WebTransportError::invalid("code must be < 2^62"))?;
let _guard = RUNTIME.enter();
self.endpoint.close(var_code, reason.as_bytes());
self.inner.close(var_code, reason.as_bytes());
Ok(())
}

/// Wait until all connections have shut down cleanly.
/// Wait for bound endpoints to drain; close first to prevent new connections.
pub async fn wait_closed(&self) {
let endpoint = self.endpoint.clone();
let client = self.inner.clone();
let handle = RUNTIME.spawn(async move {
endpoint.wait_idle().await;
client.wait_idle().await;
});
let _ = handle.await;
}
Expand All @@ -195,7 +187,7 @@ impl Client {
impl Drop for Client {
fn drop(&mut self) {
let _guard = RUNTIME.enter();
self.endpoint.close(quinn::VarInt::from_u32(0), b"");
self.inner.close(quinn::VarInt::from_u32(0), b"");
}
}

Expand Down
80 changes: 80 additions & 0 deletions rs/web-transport-ffi/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,83 @@ fn sha256(cert_der: &[u8]) -> Vec<u8> {
hasher.update(cert_der);
hasher.finalize().to_vec()
}

async fn dual_family_sessions(
client: &Client,
) -> (Vec<ServerSession>, Vec<std::sync::Arc<Server>>) {
let (chain, key) = self_signed_cert();
let mut sessions = Vec::new();
let mut servers = Vec::new();
for bind in ["127.0.0.1:0", "[::1]:0"] {
let server = Server::new(ServerConfig {
certificate_chain: chain.clone(),
private_key: key.clone(),
bind: bind.into(),
congestion_control: CongestionControl::Default,
max_idle_timeout_secs: Some(10.0),
keep_alive_interval_secs: None,
})
.unwrap();
let addr = server.local_addr();
let remote = std::net::SocketAddr::new(addr.host.parse().unwrap(), addr.port);
let (session, peer) = tokio::join!(client.connect(format!("https://{remote}/")), async {
server.accept().await.unwrap().accept().await.unwrap()
},);
sessions.push((session.unwrap(), peer));
servers.push(server);
}
(sessions, servers)
}

type ServerSession = (
std::sync::Arc<crate::session::Session>,
std::sync::Arc<crate::session::Session>,
);

#[tokio::test]
async fn client_close_and_drop_cover_both_families() {
tokio::time::timeout(TIMEOUT, async {
for explicit_close in [true, false] {
let client = Client::new(ClientConfig {
no_cert_verification: true,
..Default::default()
})
.unwrap();
let (sessions, servers) = dual_family_sessions(&client).await;
if explicit_close {
client.close(42, "all sockets".into()).unwrap();
assert!(client
.connect("https://127.0.0.1:443/".into())
.await
.is_err());
assert!(client.connect("https://[::1]:443/".into()).await.is_err());
client.wait_closed().await;
}
drop(client);
for (session, peer) in &sessions {
assert!(session.receive_datagram().await.is_err());
assert!(peer.receive_datagram().await.is_err());
}
for server in servers {
server.close(0, String::new()).unwrap();
server.wait_closed().await;
}
}
})
.await
.expect("client shutdown timed out");
}

#[tokio::test]
async fn closing_unused_client_prevents_first_bind() {
let client = Client::new(ClientConfig::default()).unwrap();
client.close(0, String::new()).unwrap();
client.wait_closed().await;
for url in [
"https://127.0.0.1:443/",
"https://[::1]:443/",
"https://[::ffff:127.0.0.1]:443/",
] {
assert!(client.connect(url.into()).await.is_err());
}
}
1 change: 1 addition & 0 deletions rs/web-transport-noq/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ rustls = { version = "0.23", default-features = false, features = [
"std",
] }
rustls-native-certs = "0.8"
socket2 = "0.6"
thiserror = "2"
tokio = { version = "1", default-features = false, features = [
"io-util",
Expand Down
30 changes: 11 additions & 19 deletions rs/web-transport-noq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,20 @@ Both endpoints can send datagrams below the MTU size (~1.2kb minimum) and they m
They are basically UDP packets, except they are encrypted and congestion controlled.

# Usage
To use web-transport-noq, first you need to create a [noq::Endpoint](https://docs.rs/noq/latest/noq/struct.Endpoint.html); see the documentation and examples for more information.
The only requirement is that the ALPN is set to `web_transport_noq::ALPN` (aka `h3`).

Afterwards, you use [web_transport_noq::accept](https://docs.rs/web-transport-noq/latest/web_transport_noq/fn.accept.html) (as a server) or [web_transport_noq::connect](https://docs.rs/web-transport-noq/latest/web_transport_noq/fn.connect.html) (as a client) to establish a WebTransport session.
This will take over the QUIC connection and perform the boring HTTP/3 handshake for you.
Use `ClientBuilder::new().with_system_roots()?` to build a reusable client,
then call `client.connect(url).await?` to establish a session. Clones share the
client's endpoints. The first connection to each address family binds an
IPv4 `0.0.0.0:0` or IPv6-only `[::]:0` socket. IPv4-mapped IPv6 destinations
use IPv4. Socket setup failures are returned by `connect`, so building a client
does not require IPv6 support or a running async runtime. Both sockets use the
runtime present at construction, or at the first connection if constructed
outside a runtime. Keep that runtime alive while using the client.

See the [examples](examples) or [moq-native](https://github.com/moq-dev/moq-rs/blob/main/moq-native/src/quic.rs) for a full setup.
For an existing `noq::ClientConfig`, `Client::new(endpoint, config)` keeps
the caller's endpoint and address handling. Set its ALPN to `h3`.

```rust
// Create a QUIC client.
let mut endpoint = noq::Endpoint::client("[::]:0".parse()?)?;
endpoint.set_default_client_config(/* ... */);

// Connect to the given URL.
let session = web_transport_noq::connect(&client, Url::parse("https://localhost")?).await?;

// Create a bidirectional stream.
let (mut send, mut recv) = session.open_bi().await?;

// Send a message.
send.write(b"hello").await?;
```
See the [examples](examples) for certificate setup and server construction.

## API
The `web-transport-noq` API is almost identical to the Noq API, except that [Connection](https://docs.rs/noq/latest/noq/struct.Connection.html) is called [Session](https://docs.rs/web-transport-noq/latest/web_transport_noq/struct.Session.html).
Expand Down
Loading
Loading