跳到主要内容

ValidationTokenConfig

搜索

结构体 ValidationTokenConfig 

源代码
pub struct ValidationTokenConfig { /* private fields */ }
展开描述

对入站连接中校验 token 的发送与处理进行配置

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

§QUIC Token

QUIC 协议定义了一个“地址校验(address validation)”的概念。简单来说,QUIC 连接的一端虽然看起来在从一个特定的远端 UDP 地址接收 QUIC 数据包,但它只有在掌握充分证据证明该地址不是被“伪造”的之后,才会认为该远端地址是“已校验的”。

校验之所以重要,主要是因为 QUIC 的“反放大限制”(anti-amplification limit)。该限制规定:在某个地址被校验之前,QUIC 服务器向该客户端发送的字节数不能超过它从该客户端在同一个地址上收到的字节数的三倍。这一机制是为了削弱攻击者把基于 QUIC 的服务器当作放大攻击中的反射器的可能。

路径可以通过多种方式被校验。对客户端而言,服务器始终被视为已校验。客户端在首次连接或迁移后通常处于未校验状态,但随后会通过若干通常需要一次网络往返即可完成的机制被校验。然而,在某些情况下,先前曾尝试连接某服务器的客户端可能已经获得了一个一次性使用的、经过加密签名的“token”,它可以把这个 token 附加在下一次连接尝试中以被立即校验。

这些 token 有两种来源:

  • 若服务器以 retry 来响应一条入站连接,就会生成一个“retry token”并发送给客户端,客户端会立即用该 token 再次发起连接。retry token 的有效时间很短,例如 15 秒。
  • 若客户端在某条活跃连接内的路径已被校验,服务器可以向客户端发送一个或多个“validation token”,客户端可以将它们保存下来以供后续向同一服务器建立连接时使用。validation token 的有效时长可以远长于 retry token。

validation token 最能发挥作用的场景是同时在使用 0-RTT 数据的场合——尤其是当服务器向客户端发送的 0.5-RTT 数据量已经达到它收到的 0-RTT 数据量三倍以上时。由于连接握手的成功完成本身就意味着客户端地址被隐式地校验,0.5-RTT 数据的发送正是服务器最有可能向一个“本来要等更久才能通过 token 校验”的地址上发送应用数据的主要场景。

这些 token 不要与“stateless reset token”混淆,虽然它们名字相近,但完全是两码事。

实现§

源代码§

impl ValidationTokenConfig

源代码

pub fn lifetime(&mut self, value: Duration) -> &mut ValidationTokenConfig

一个地址校验 token 自签发起被认为有效的持续时间

这里仅指通过 NEW_TOKEN 帧发送的 token,不包括 retry token。

默认为 2 周。

源代码

pub fn log(&mut self, log: Arc<dyn TokenLog>) -> &mut ValidationTokenConfig

设置自定义的 TokenLog

若启用了 bloom feature(默认启用),默认为一个内置的 BloomTokenLog,适用于大多数互联网应用。

若禁用了 bloom feature,则默认为 NoneTokenLog,它会使服务器忽略所有地址校验 token(即源自 NEW_TOKEN 帧的 token;retry token 不受影响)。

源代码

pub fn sent(&mut self, value: u32) -> &mut ValidationTokenConfig

在客户端路径校验通过时发送给它的地址校验 token 数量

这里仅指通过 NEW_TOKEN 帧发送的 token,不包括 retry token。

若启用了 bloom feature(默认启用),默认为 2;否则默认为 0。

trait 实现§

源代码§

impl Clone for ValidationTokenConfig

源代码§

fn clone(&self) -> ValidationTokenConfig

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

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

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

impl Debug for ValidationTokenConfig

源代码§

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

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

impl Default for ValidationTokenConfig

源代码§

fn default() -> ValidationTokenConfig

Returns the “default value” for a type. 更多信息

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