跳到主要内容

ServerConfig

搜索

结构体 ServerConfig 

源代码
pub struct ServerConfig {
    pub transport: Arc<TransportConfig>,
    pub crypto: Arc<dyn ServerConfig>,
    pub validation_token: ValidationTokenConfig,
    /* private fields */
}
展开描述

控制入站连接的参数

默认值应该适合大多数互联网应用。

字段§

§transport: Arc<TransportConfig>

用于入站连接的传输配置

§crypto: Arc<dyn ServerConfig>

用于入站连接的 TLS 配置

必须设置为仅使用 TLS 1.3。

§validation_token: ValidationTokenConfig

用于发送和处理验证令牌(validation token)的配置

实现§

源代码§

impl ServerConfig

源代码

pub fn new( crypto: Arc<dyn ServerConfig>, token_key: Arc<dyn HandshakeTokenKey>, ) -> ServerConfig

使用指定的握手令牌密钥创建一个默认配置

源代码

pub fn transport_config( &mut self, transport: Arc<TransportConfig>, ) -> &mut ServerConfig

设置自定义的 TransportConfig

源代码

pub fn validation_token_config( &mut self, validation_token: ValidationTokenConfig, ) -> &mut ServerConfig

设置自定义的 ValidationTokenConfig

源代码

pub fn token_key( &mut self, value: Arc<dyn HandshakeTokenKey>, ) -> &mut ServerConfig

用于认证握手令牌中所包含数据的私钥

源代码

pub fn retry_token_lifetime(&mut self, value: Duration) -> &mut ServerConfig

重试令牌在签发后被视为有效的时长

默认为 15 秒。

源代码

pub fn migration(&mut self, value: bool) -> &mut ServerConfig

是否允许客户端迁移到新的地址

可改善在切换网络连接或遭遇 NAT 重绑时客户端的行为。默认开启。

源代码

pub fn preferred_address_v4( &mut self, address: Option<SocketAddrV4>, ) -> &mut ServerConfig

在握手期间将向客户端通告的优先 IPv4 地址

若客户端能到达该地址,便会切换到该地址。

源代码

pub fn preferred_address_v6( &mut self, address: Option<SocketAddrV6>, ) -> &mut ServerConfig

在握手期间将向客户端通告的优先 IPv6 地址

若客户端能到达该地址,便会切换到该地址。

源代码

pub fn max_incoming(&mut self, max_incoming: usize) -> &mut ServerConfig

同时允许存在的 Incoming 数量上限

当服务端收到入站连接尝试时,会创建一个 Incoming;当应用程序接受该连接或以其他方式处理掉它时,Incoming 即消失。达到此上限后,新的入站连接尝试将被立即拒绝。该值越大最坏情况下的内存占用越高,但允许应用程序以更大的延迟处理入站连接尝试。

默认值为 65536。以典型的 1500 字节以太网 MTU 计算,这会把该部分内存占用控制在 100 MiB 以内——在大多数场景下既慷慨又能防止内存耗尽。

源代码

pub fn incoming_buffer_size( &mut self, incoming_buffer_size: u64, ) -> &mut ServerConfig

为每个 Incoming 缓冲的已接收字节数上限

当服务端收到入站连接尝试时,会创建一个 Incoming;当应用程序接受该连接或以其他方式处理掉它时,Incoming 即消失。该上限仅约束此期间内收到的数据包,不包括第一个包。超过此限制的数据包将被丢弃,可能导致 0-RTT 或握手数据需要重传。

默认值为 10 MiB——在大多数情况下,客户端在服务端处理相应 Incoming 之前不会发送这么多 0-RTT 数据。

源代码

pub fn incoming_buffer_size_total( &mut self, incoming_buffer_size_total: u64, ) -> &mut ServerConfig

为所有 Incoming 合计缓冲的已接收字节数上限

当收到一个入站连接尝试时,会创建一个 Incoming,并在该连接被应用层接受或以其他方式处置后消失。该限制仅作用于这段时间内收到的包,且不包括第一个包。超出此限制的包将被丢弃,这可能导致 0-RTT 或握手数据需要重传。

默认值为 100 MiB——在大多数情况下,这一较为宽裕的数值足以防止内存耗尽。

源代码

pub fn time_source( &mut self, time_source: Arc<dyn TimeSource>, ) -> &mut ServerConfig

用于获取当前 SystemTime 的对象

提供此设置是为了在测试或其他需要时能够模拟系统时间。

默认为 StdSystemTime,后者直接调用 SystemTime::now()

源代码§

impl ServerConfig

源代码

pub fn with_single_cert( cert_chain: Vec<CertificateDer<'static>>, key: PrivateKeyDer<'static>, ) -> Result<ServerConfig, Error>

使用给定的证书链创建一个服务器配置,该证书链将向客户端出示

使用一个随机生成的握手令牌密钥。

源代码§

impl ServerConfig

源代码

pub fn with_crypto(crypto: Arc<dyn ServerConfig>) -> ServerConfig

使用给定的 crypto::ServerConfig 创建一个服务器配置

使用一个随机生成的握手令牌密钥。

trait 实现§

源代码§

impl Clone for ServerConfig

源代码§

fn clone(&self) -> ServerConfig

返回值的副本。 更多信息
1.0.0 · 源代码§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 更多信息
源代码§

impl Debug for ServerConfig

源代码§

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

使用给定的格式化器格式化此值。 更多信息

自动 trait 实现§

blanket 实现§

源代码§

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

源代码§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
源代码§

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

源代码§

fn borrow(&self) -> &T

Immutably borrows from an owned value. 更多信息
源代码§

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

源代码§

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

Mutably borrows from an owned value. 更多信息
源代码§

impl<T> CloneToUninit for T
where T: Clone,

源代码§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 更多信息
源代码§

impl<T> From<T> for T

源代码§

fn from(t: T) -> T

原样返回该参数。

源代码§

impl<T> Instrument for T

源代码§

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

Instruments this type with the provided Span, returning an Instrumented wrapper. 更多信息
源代码§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. 更多信息
源代码§

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

源代码§

fn into(self) -> U

调用 U::from(self)

也就是说,此转换行为完全由 From<T> for U 的实现决定。

源代码§

impl<T> ToOwned for T
where T: Clone,

源代码§

type Owned = T

The resulting type after obtaining ownership.
源代码§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. 更多信息
源代码§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 更多信息
源代码§

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

源代码§

type Error = Infallible

The type returned in the event of a conversion error.
源代码§

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

执行转换。
源代码§

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.
源代码§

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

执行转换。
源代码§

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

源代码§

fn vzip(self) -> V

源代码§

impl<T> WithSubscriber for T

源代码§

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

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. 更多信息
源代码§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. 更多信息
源代码§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

源代码§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

源代码§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,