Struct s2n_quic::server::Builder

source ·
pub struct Builder<Providers>(/* private fields */);
Expand description

A builder for configuring Server providers

Implementations§

source§

impl<Providers: ServerProviders> Builder<Providers>

source

pub fn with_connection_id<T, U>( self, connection_id: T ) -> Result<Builder<U>, T::Error>
where T: TryInto, U: ServerProviders, Self: With<T::Provider, Output = Builder<U>>,

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()?;
source

pub fn with_stateless_reset_token<T, U>( self, stateless_reset_token: T ) -> Result<Builder<U>, T::Error>
where T: TryInto, U: ServerProviders, Self: With<T::Provider, Output = Builder<U>>,

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()?;
source

pub fn with_limits<T, U>(self, limits: T) -> Result<Builder<U>, T::Error>
where T: TryInto, U: ServerProviders, Self: With<T::Provider, Output = Builder<U>>,

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()?;
source

pub fn with_endpoint_limits<T, U>( self, endpoint_limits: T ) -> Result<Builder<U>, T::Error>
where T: TryInto, U: ServerProviders, Self: With<T::Provider, Output = Builder<U>>,

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()?;
source

pub fn with_event<T, U>(self, event: T) -> Result<Builder<U>, T::Error>
where T: TryInto, U: ServerProviders, Self: With<T::Provider, Output = Builder<U>>,

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()?;
source

pub fn with_address_token<T, U>( self, address_token: T ) -> Result<Builder<U>, T::Error>
where T: TryInto, U: ServerProviders, Self: With<T::Provider, Output = Builder<U>>,

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()?;
source

pub fn with_io<T, U>(self, io: T) -> Result<Builder<U>, T::Error>
where T: TryInto, U: ServerProviders, Self: With<T::Provider, Output = Builder<U>>,

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()?;
source

pub fn with_tls<T, U>(self, tls: T) -> Result<Builder<U>, T::Error>
where T: TryInto, U: ServerProviders, Self: With<T::Provider, Output = Builder<U>>,

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()?;
source

pub fn with_congestion_controller<T, U>( self, congestion_controller: T ) -> Result<Builder<U>, T::Error>
where T: TryInto, U: ServerProviders, Self: With<T::Provider, Output = Builder<U>>,

Sets the congestion controller provider for the Server

source

pub fn start(self) -> Result<Server, StartError>

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§

source§

impl<Providers: Debug> Debug for Builder<Providers>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Builder<DefaultProviders>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<Providers> Freeze for Builder<Providers>
where Providers: Freeze,

§

impl<Providers> RefUnwindSafe for Builder<Providers>
where Providers: RefUnwindSafe,

§

impl<Providers> Send for Builder<Providers>
where Providers: Send,

§

impl<Providers> Sync for Builder<Providers>
where Providers: Sync,

§

impl<Providers> Unpin for Builder<Providers>
where Providers: Unpin,

§

impl<Providers> UnwindSafe for Builder<Providers>
where Providers: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T, U> Upcast<T> for U
where T: UpcastFrom<U>,

source§

fn upcast(self) -> T

source§

impl<T, B> UpcastFrom<Counter<T, B>> for T

source§

fn upcast_from(value: Counter<T, B>) -> T

source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V