Skip to content

Commit ca97549

Browse files
authored
Some more documentation. (#42)
* Some more documentation. * More README cleanup.
1 parent 2dcc5f2 commit ca97549

File tree

3 files changed

+59
-15
lines changed

3 files changed

+59
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![discord](https://img.shields.io/discord/1124083992740761730)](https://discord.gg/FCYF3p99mr)
44

55
# WebTransport
6-
WebTransport is a protocol for client-server communication over QUIC.
6+
[WebTransport](https://developer.mozilla.org/en-US/docs/Web/API/WebTransport_API) is a new web API that allows for low-level, bidirectional communication between a client and a server.
77
It's [available in the browser](https://caniuse.com/webtransport) as an alternative to HTTP and WebSockets.
88

99
WebTransport is layered on top of HTTP/3 which is then layered on top of QUIC.

web-transport-quinn/README.md

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,55 @@
66
A wrapper around the Quinn API, abstracting away the annoying HTTP/3 internals.
77
Provides a QUIC-like API but with web support!
88

9-
## Example
9+
## WebTransport
10+
[WebTransport](https://developer.mozilla.org/en-US/docs/Web/API/WebTransport_API) is a new web API that allows for low-level, bidirectional communication between a client and a server.
11+
It's [available in the browser](https://caniuse.com/webtransport) as an alternative to HTTP and WebSockets.
1012

11-
See the example [server](examples/echo-server.rs) and [client](examples/echo-client.rs).
13+
WebTransport is layered on top of HTTP/3 which itself is layered on top of QUIC.
14+
This library hides that detail and exposes only the QUIC API, delegating as much as possible to the underlying QUIC implementation (Quinn).
1215

13-
QUIC requires TLS, which makes the initial setup a bit more involved.
16+
QUIC provides two primary APIs:
1417

15-
- Generate a certificate: `./cert/generate`
16-
- Run the Rust server: `cargo run --example echo-server -- --tls-cert cert/localhost.crt --tls-key cert/localhost.key`
17-
- Run a Web client: `cd web; npm install; npx parcel serve client.html --open`
18+
## Streams
1819

19-
If you get a certificate error with the web client, try deleting `.parcel-cache`.
20+
QUIC streams are ordered, reliable, flow-controlled, and optionally bidirectional.
21+
Both endpoints can create and close streams (including an error code) with no overhead.
22+
You can think of them as TCP connections, but shared over a single QUIC connection.
2023

21-
The Rust client example seems to be broken.
22-
It would be amazing if somebody could fix it: `cargo run --example echo-client -- --tls-cert cert/localhost.crt`
24+
## Datagrams
2325

24-
## Limitations
26+
QUIC datagrams are unordered, unreliable, and not flow-controlled.
27+
Both endpoints can send datagrams below the MTU size (~1.2kb minimum) and they might arrive out of order or not at all.
28+
They are basically UDP packets, except they are encrypted and congestion controlled.
2529

26-
This library doesn't support pooling HTTP/3 or multiple WebTransport sessions.
27-
It's means to be analogous to the QUIC API.
30+
# Usage
31+
To use web-transport-quinn, first you need to create a [quinn::Endpoint](https://docs.rs/quinn/latest/quinn/struct.Endpoint.html); see the documentation and examples for more information.
32+
The only requirement is that the ALPN is set to `web_transport_quinn::ALPN` (aka `h3`).
2833

29-
- If you want to support HTTP/3 on the same host/port, you should use another crate (ex. `h3-webtransport`).
30-
- If you want to support multiple WebTransport sessions over the same QUIC connection... you should just dial a new QUIC connection instead.
34+
Afterwards, you use [web_transport_quinn::accept](https://docs.rs/web-transport-quinn/latest/web_transport_quinn/fn.accept.html) (as a server) or [web_transport_quinn::connect](https://docs.rs/web-transport-quinn/latest/web_transport_quinn/fn.connect.html) (as a client) to establish a WebTransport session.
35+
This will take over the QUIC connection and perform the boring HTTP/3 handshake for you.
36+
37+
See the [examples](examples) or [moq-native](https://github.com/kixelated/moq-rs/blob/main/moq-native/src/quic.rs) for a full setup.
38+
39+
```rust
40+
// Create a QUIC client.
41+
let mut endpoint = quinn::Endpoint::client("[::]:0".parse()?)?;
42+
endpoint.set_default_client_config(/* ... */);
43+
44+
// Connect to the given URL.
45+
let session = web_transport_quinn::connect(&client, &"https://localhost").await?;
46+
47+
// Create a bidirectional stream.
48+
let (mut send, mut recv) = session.open_bi().await?;
49+
50+
// Send a message.
51+
send.write(b"hello").await?;
52+
```
53+
54+
## API
55+
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).
56+
57+
When possible, `Deref` is used to expose the underlying Quinn API.
58+
However some of the API is wrapped or unavailable due to WebTransport limitations.
59+
- Stream IDs are not avaialble.
60+
- Error codes are not full VarInts (62-bits) and significantly smaller.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Example
2+
3+
An example [server](echo-server.rs) and [client](echo-client.rs).
4+
5+
QUIC requires TLS, which makes the initial setup a bit more involved.
6+
7+
- Generate a certificate: `./cert/generate`
8+
- Run the Rust server: `cargo run --example echo-server -- --tls-cert cert/localhost.crt --tls-key cert/localhost.key`
9+
- Run a Web client: `cd web; npm install; npx parcel serve client.html --open`
10+
11+
If you get a certificate error with the web client, try deleting `.parcel-cache`.
12+
13+
The Rust client example seems to be broken.
14+
It would be amazing if somebody could fix it: `cargo run --example echo-client -- --tls-cert cert/localhost.crt`

0 commit comments

Comments
 (0)