pub struct Builder<Providers>(_);
Expand description

A builder for configuring Server providers

Implementations

Sets the connection ID provider for the Server

Examples

Uses the default connection ID provider with the default configuration.

use s2n_quic::{Server, provider::connection_id};
let server = Server::builder()
    .with_connection_id(connection_id::Default::default())?
    .start()?;

Sets a custom connection ID provider for the server

use s2n_quic::{Server, provider::connection_id};
use rand::prelude::*;
struct MyConnectionIdFormat;

impl connection_id::Generator for MyConnectionIdFormat {
    fn generate(&mut self, _conn_info: &connection_id::ConnectionInfo) -> connection_id::LocalId {
        let mut id = [0u8; 16];
        rand::thread_rng().fill_bytes(&mut id);
        connection_id::LocalId::try_from_bytes(&id[..]).unwrap()
    }
}

impl connection_id::Validator for MyConnectionIdFormat {
    fn validate(&self, _conn_info: &connection_id::ConnectionInfo, packet: &[u8]) -> Option<usize> {
        // this connection id format is always 16 bytes
        Some(16)
    }
}

let server = Server::builder()
    .with_connection_id(MyConnectionIdFormat)?
    .start()?;

Sets the stateless reset token provider for the Server

Examples

Sets a custom stateless reset token provider for the server

use s2n_quic::Server;
let server = Server::builder()
    .with_stateless_reset_token(MyStatelessResetTokenGenerator::new())?
    .start()?;

Sets the limits provider for the Server

Examples

Sets the max idle time, while inheriting the remaining default limits

use s2n_quic::{Server, provider::limits};
let server = Server::builder()
    .with_limits(limits::Default::default())?
    .start()?;

Sets the endpoint limits provider for the Server

Examples

Sets the max inflight handshakes for an endpoint, while inheriting the remaining default limits

use s2n_quic::{Server, provider::endpoint_limits};

let server = Server::builder()
    .with_endpoint_limits(endpoint_limits::Default::default())?
    .start()?;

Sets the event provider for the Server

Examples

Sets a custom event subscriber for the server

use s2n_quic::Server;
let server = Server::builder()
    .with_event(MyEventLogger::new())?
    .start()?;

Sets the token provider for the Server

Examples

Sets a custom token provider for the server

use s2n_quic::Server;
let server = Server::builder()
    .with_address_token(MyTokenProvider::new())?
    .start()?;

Sets the IO provider for the Server

Examples

Starts listening on 127.0.0.1:443

use s2n_quic::Server;
let server = Server::builder()
    .with_io("127.0.0.1:443")?
    .start()?;

Configures a socket with the provided Builder

use s2n_quic::{Server, provider::io::tokio::Builder as IoBuilder};
use std::net::ToSocketAddrs;
let addr = "127.0.0.1:443".to_socket_addrs()?.next().unwrap();

let io = IoBuilder::default()
    .with_receive_address(addr)?
    .build()?;

let server = Server::builder()
    .with_io(io)?
    .start()?;

Sets the TLS provider for the Server

Examples

The default TLS provider and configuration will be used with the path to the private key.

let server = Server::builder()
    .with_tls((Path::new("./certs/cert.pem"), Path::new("./certs/key.pem")))?
    .start()?;

Sets the TLS provider to a TLS server builder

let tls = s2n::tls::Server::builder()
    .with_certificate(Path::new("./certs/cert.pem"), Path::new("./certs/key.pem"))?
    .with_security_policy(s2n::tls::security_policy::S2N_20190802)?;

let server = Server::builder()
    .with_tls(tls)?
    .start()?;

Starts the Server with the configured providers

Examples
let server = Server::builder()
    .with_tls((Path::new("./certs/cert.pem"), Path::new("./certs/key.pem")))?
    .with_io("127.0.0.1:443")?
    .start()?;

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.