ServerConfigBuilder

Struct ServerConfigBuilder 

Source
pub struct ServerConfigBuilder<State>(/* private fields */);
Expand description

Server builder configuration.

The builder might have different state at compile time.

§Examples:

let config = ServerConfig::builder()
    .with_bind_default(4433)
    .with_identity(Identity::load_pemfiles("cert.pem", "key.pem").await?);

Implementations§

Source§

impl ServerConfigBuilder<WantsBindAddress>

Source

pub fn with_bind_default( self, listening_port: u16, ) -> ServerConfigBuilder<WantsIdentity>

Configures for accepting incoming connections binding ANY IP (allowing IP dual-stack).

listening_port is the port where the server will accept incoming connections.

This is equivalent to: Self::with_bind_config with IpBindConfig::InAddrAnyDual.

Source

pub fn with_bind_config( self, ip_bind_config: IpBindConfig, listening_port: u16, ) -> ServerConfigBuilder<WantsIdentity>

Sets the binding (local) socket address with a specific IpBindConfig.

listening_port is the port where the server will accept incoming connections.

Source

pub fn with_bind_address( self, address: SocketAddr, ) -> ServerConfigBuilder<WantsIdentity>

Sets the binding (local) socket address for the endpoint.

Source

pub fn with_bind_address_v6( self, address: SocketAddrV6, dual_stack_config: Ipv6DualStackConfig, ) -> ServerConfigBuilder<WantsIdentity>

Sets the binding (local) socket address for the endpoint with Ipv6 address.

dual_stack_config allows/denies dual stack port binding.

Source

pub fn with_bind_socket( self, socket: UdpSocket, ) -> ServerConfigBuilder<WantsIdentity>

Configures the server to bind to a pre-existing UdpSocket.

This allows the server to use an already created socket, which may be beneficial for scenarios where socket reuse or specific socket configuration is needed.

Source§

impl ServerConfigBuilder<WantsIdentity>

Source

pub fn with_identity( self, identity: Identity, ) -> ServerConfigBuilder<WantsTransportConfigServer>

Configures TLS with safe defaults and a TLS Identity.

§Example
use wtransport::Identity;
use wtransport::ServerConfig;

let identity = Identity::load_pemfiles("cert.pem", "key.pem").await?;

let server_config = ServerConfig::builder()
    .with_bind_default(4433)
    .with_identity(identity)
    .build();
Source

pub fn with_custom_tls( self, tls_config: TlsServerConfig, ) -> ServerConfigBuilder<WantsTransportConfigServer>

Allows for manual configuration of a custom TLS setup using a provided rustls::ServerConfig, which must support rustls::CipherSuite::TLS13_AES_128_GCM_SHA256. A suitable configuration can be obtained using the ring crypto provider with a set of versions containing rustls::version::TLS13.

This method is provided for advanced users who need fine-grained control over the TLS configuration. It allows you to pass a preconfigured rustls::ServerConfig instance to customize the TLS settings according to your specific requirements.

Generally, it is recommended to use the with_identity method to configure TLS with safe defaults and an TLS Identity.

§Example
use wtransport::tls::rustls;
use wtransport::ServerConfig;

// Create a custom rustls::ServerConfig with specific TLS settings
let custom_tls_config = rustls::ServerConfig::builder();
// Customize TLS settings here...

// Create a ServerConfigBuilder with the custom TLS configuration
let server_config = ServerConfig::builder()
    .with_bind_default(4433)
    .with_custom_tls(custom_tls_config)
    .build();
Source

pub fn with_custom_transport( self, identity: Identity, quic_transport_config: QuicTransportConfig, ) -> ServerConfigBuilder<WantsTransportConfigServer>

Configures the server with a custom QUIC transport configuration and a default TLS setup using the provided Identity.

This method is useful for scenarios where you need to customize the transport settings while relying on a default TLS configuration built from an Identity. It gives you control over the transport layer while maintaining safe and standard TLS settings.

See: with_identity for a simpler configuration option that does not require custom transport settings.

§Parameters
  • identity: A reference to an Identity that contains the server’s certificate and private key. This will be used to generate the default TLS configuration.
  • quic_transport_config: A custom QuicTransportConfig instance that allows you to specify various QUIC transport-layer settings according to your requirements.
§Example
use wtransport::config::QuicTransportConfig;
use wtransport::Identity;
use wtransport::ServerConfig;

// Generate a server identity (self signed certificate and private key)
let identity = Identity::self_signed(["localhost", "127.0.0.1", "::1"]).unwrap();

// Create a custom QuicTransportConfig with specific settings
let mut custom_transport_config = QuicTransportConfig::default();
custom_transport_config.datagram_send_buffer_size(1024);

// Create a ServerConfigBuilder with the custom transport configuration and default TLS settings
let server_config = ServerConfig::builder()
    .with_bind_default(4433)
    .with_custom_transport(identity, custom_transport_config)
    .build();
Source

pub fn with_custom_tls_and_transport( self, tls_config: TlsServerConfig, quic_transport_config: QuicTransportConfig, ) -> ServerConfigBuilder<WantsTransportConfigServer>

Configures the server with both a custom TLS configuration and a custom QUIC transport configuration.

This method is designed for advanced users who require full control over both the TLS and transport settings. It allows you to pass a preconfigured TlsServerConfig and a custom QuicTransportConfig to fine-tune both layers of the server configuration.

§Parameters
  • tls_config: A custom TlsServerConfig instance that allows you to specify detailed TLS settings, such as ciphersuites, certificate verification, and more. It must support TLS 1.3 (see the documentation of Self::with_custom_tls).
  • quic_transport_config: A custom QuicTransportConfig instance that allows you to specify various QUIC transport-layer settings according to your requirements.
Source

pub fn build_with_quic_config( self, quic_config: QuicServerConfig, ) -> ServerConfig

Directly builds ServerConfig skipping TLS and transport configuration.

Both TLS and transport configuration is given by quic_config.

Source§

impl ServerConfigBuilder<WantsTransportConfigServer>

Source

pub fn build(self) -> ServerConfig

Completes configuration process.

§Panics

See the documentation of Self::with_custom_tls for the TLS 1.3 requirement.

Source

pub fn max_idle_timeout( self, idle_timeout: Option<Duration>, ) -> Result<Self, InvalidIdleTimeout>

Maximum duration of inactivity to accept before timing out the connection.

The true idle timeout is the minimum of this and the peer’s own max idle timeout. None represents an infinite timeout.

WARNING: If a peer or its network path malfunctions or acts maliciously, an infinite idle timeout can result in permanently hung futures!

Source

pub fn keep_alive_interval(self, interval: Option<Duration>) -> Self

Period of inactivity before sending a keep-alive packet

Keep-alive packets prevent an inactive but otherwise healthy connection from timing out.

None to disable, which is the default. Only one side of any given connection needs keep-alive enabled for the connection to be preserved. Must be set lower than the max_idle_timeout of both peers to be effective.

Source

pub fn allow_migration(self, value: bool) -> Self

Whether to allow clients to migrate to new addresses.

Improves behavior for clients that move between different internet connections or suffer NAT rebinding. Enabled by default.

Trait Implementations§

Source§

impl Default for ServerConfigBuilder<WantsBindAddress>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<State> Freeze for ServerConfigBuilder<State>
where State: Freeze,

§

impl<State> RefUnwindSafe for ServerConfigBuilder<State>
where State: RefUnwindSafe,

§

impl<State> Send for ServerConfigBuilder<State>
where State: Send,

§

impl<State> Sync for ServerConfigBuilder<State>
where State: Sync,

§

impl<State> Unpin for ServerConfigBuilder<State>
where State: Unpin,

§

impl<State> UnwindSafe for ServerConfigBuilder<State>
where State: 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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more