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>
impl ServerConfigBuilder<WantsBindAddress>
Sourcepub fn with_bind_default(
self,
listening_port: u16,
) -> ServerConfigBuilder<WantsIdentity>
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.
Sourcepub fn with_bind_config(
self,
ip_bind_config: IpBindConfig,
listening_port: u16,
) -> ServerConfigBuilder<WantsIdentity>
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.
Sourcepub fn with_bind_address(
self,
address: SocketAddr,
) -> ServerConfigBuilder<WantsIdentity>
pub fn with_bind_address( self, address: SocketAddr, ) -> ServerConfigBuilder<WantsIdentity>
Sets the binding (local) socket address for the endpoint.
Sourcepub fn with_bind_address_v6(
self,
address: SocketAddrV6,
dual_stack_config: Ipv6DualStackConfig,
) -> ServerConfigBuilder<WantsIdentity>
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.
Sourcepub fn with_bind_socket(
self,
socket: UdpSocket,
) -> ServerConfigBuilder<WantsIdentity>
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>
impl ServerConfigBuilder<WantsIdentity>
Sourcepub fn with_identity(
self,
identity: Identity,
) -> ServerConfigBuilder<WantsTransportConfigServer>
pub fn with_identity( self, identity: Identity, ) -> ServerConfigBuilder<WantsTransportConfigServer>
Sourcepub fn with_custom_tls(
self,
tls_config: TlsServerConfig,
) -> ServerConfigBuilder<WantsTransportConfigServer>
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();Sourcepub fn with_custom_transport(
self,
identity: Identity,
quic_transport_config: QuicTransportConfig,
) -> ServerConfigBuilder<WantsTransportConfigServer>
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 anIdentitythat contains the server’s certificate and private key. This will be used to generate the default TLS configuration.quic_transport_config: A customQuicTransportConfiginstance 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();Sourcepub fn with_custom_tls_and_transport(
self,
tls_config: TlsServerConfig,
quic_transport_config: QuicTransportConfig,
) -> ServerConfigBuilder<WantsTransportConfigServer>
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 customTlsServerConfiginstance that allows you to specify detailed TLS settings, such as ciphersuites, certificate verification, and more. It must support TLS 1.3 (see the documentation ofSelf::with_custom_tls).quic_transport_config: A customQuicTransportConfiginstance that allows you to specify various QUIC transport-layer settings according to your requirements.
Sourcepub fn build_with_quic_config(
self,
quic_config: QuicServerConfig,
) -> ServerConfig
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>
impl ServerConfigBuilder<WantsTransportConfigServer>
Sourcepub fn build(self) -> ServerConfig
pub fn build(self) -> ServerConfig
Completes configuration process.
§Panics
See the documentation of Self::with_custom_tls for the TLS 1.3 requirement.
Sourcepub fn max_idle_timeout(
self,
idle_timeout: Option<Duration>,
) -> Result<Self, InvalidIdleTimeout>
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!
Sourcepub fn keep_alive_interval(self, interval: Option<Duration>) -> Self
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.
Sourcepub fn allow_migration(self, value: bool) -> Self
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.