Crate wtransport

Crate wtransport 

Source
Expand description

WebTransport protocol implementation in pure Rust, async-friendly, and API-simple.

For a quick start with this library, refer to Endpoint.

§About WebTransport

WebTransport is a modern protocol built on QUIC and HTTP/3, providing an alternative to HTTP and WebSocket.

It’s designed for efficient client-server communication with low latency and bi-directional multistream data exchange capabilities, making it suitable for a wide range of applications.

WebTransport guarantees secure and reliable communication by leveraging encryption and authentication to protect your data during transmission.

WebTransport offers two key communication channels: streams and datagrams.

§Streams

WebTransport streams are communication channels that provide ordered and reliable data transfer.

WebTransport streams allow sending multiple sets of data at once within a single session. Each stream operates independently, ensuring that the order and reliability of one stream do not affect the others.

Streams can be: uni-directional or bi-directional.

Order Preserved, Guaranteed Delivery, Flow-Controlled, Secure (All Traffic Encrypted), and Multiple Independent Streams.

§Datagrams

WebTransport datagrams are lightweight and unordered communication channels, prioritizing quick data exchange without guarantees of reliability or sequence.

Unordered, No Guaranteed Delivery, No Flow-Controlled, Secure (All Traffic Encrypted), Independent Messages.

§Examples

Explore operational server and client examples below. The elegantly simple yet potent API empowers you to get started with minimal code.

§Server

use wtransport::Endpoint;
use wtransport::Identity;
use wtransport::ServerConfig;

#[tokio::main]
async fn main() -> Result<()> {
    let config = ServerConfig::builder()
        .with_bind_default(4433)
        .with_identity(Identity::load_pemfiles("cert.pem", "key.pem").await?)
        .build();

    let server = Endpoint::server(config)?;

    loop {
        let incoming_session = server.accept().await;
        let incoming_request = incoming_session.await?;
        let connection = incoming_request.accept().await?;
        // ...
    }
}

See repository server example for the complete code.

§Client

use wtransport::ClientConfig;
use wtransport::Endpoint;

#[tokio::main]
async fn main() -> Result<()> {
    let connection = Endpoint::client(ClientConfig::default())?
        .connect("https://localhost:4433")
        .await?;
    // ...
}

See repository client example for the complete code.

Re-exports§

pub use wtransport_proto as proto;
pub use quinn;

Modules§

config
Client and server configurations.
connection
WebTransport connection.
datagram
Datagrams module.
endpoint
Endpoint module.
error
Errors definitions module.
stream
Interfaces for sending and receiving data.
tls
TLS specific configurations.

Structs§

ClientConfig
Client configuration.
Connection
A WebTransport session connection.
Endpoint
Entrypoint for creating client or server connections.
Identity
Represents an TLS identity consisting of a certificate chain and a private key.
RecvStream
A stream that can only be used to receive data.
SendStream
A stream that can only be used to send data.
ServerConfig
Server configuration.
SessionId
A WebTransport session id.
StreamId
Stream id.
VarInt
Variable-length integer.