pub struct Builder<Providers>(_);
Expand description
A builder for configuring Server
providers
Implementations
sourceimpl<Providers: ServerProviders> Builder<Providers>
impl<Providers: ServerProviders> Builder<Providers>
sourcepub fn with_connection_id<T, U>(
self,
connection_id: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
pub fn with_connection_id<T, U>(
self,
connection_id: T
) -> Result<Builder<impl ServerProviders>, 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()?;
sourcepub fn with_stateless_reset_token<T, U>(
self,
stateless_reset_token: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
pub fn with_stateless_reset_token<T, U>(
self,
stateless_reset_token: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
sourcepub fn with_limits<T, U>(
self,
limits: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
pub fn with_limits<T, U>(
self,
limits: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
sourcepub fn with_endpoint_limits<T, U>(
self,
endpoint_limits: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
pub fn with_endpoint_limits<T, U>(
self,
endpoint_limits: T
) -> Result<Builder<impl ServerProviders>, 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()?;
sourcepub fn with_event<T, U>(
self,
event: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
pub fn with_event<T, U>(
self,
event: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
sourcepub fn with_address_token<T, U>(
self,
address_token: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
pub fn with_address_token<T, U>(
self,
address_token: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
sourcepub fn with_io<T, U>(
self,
io: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
pub fn with_io<T, U>(
self,
io: T
) -> Result<Builder<impl ServerProviders>, 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()?;
sourcepub fn with_tls<T, U>(
self,
tls: T
) -> Result<Builder<impl ServerProviders>, T::Error> where
T: TryInto,
U: ServerProviders,
Self: With<T::Provider, Output = Builder<U>>,
pub fn with_tls<T, U>(
self,
tls: T
) -> Result<Builder<impl ServerProviders>, 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()?;
Trait Implementations
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more