跳到主要内容

Endpoint

搜索

结构体 Endpoint 

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

一个 QUIC 端点。

一个端点对应一个 UDP 套接字,可以承载多个连接,并且对于不同连接可以同时充当客户端和服务器。

可以通过克隆来获得指向同一端点的另一个句柄。

实现§

源代码§

impl Endpoint

源代码

pub fn client(addr: SocketAddr) -> Result<Self>

辅助函数,用于构造一个仅用于出站连接的端点

注意,addr 是要绑定的本地地址,通常应当是通配地址,例如 0.0.0.0:0[::]:0,分别允许通过操作系统分配的端口与任意可达的 IPv4 或 IPv6 地址通信。

如果提供的是 IPv6 地址,则会尝试让该套接字支持双栈,以便同时与 IPv4 和 IPv6 地址通信。因此,使用 [::]:0 调用 Endpoint::client 是一个合理的默认值,可最大化与其他地址建立连接的能力。例如:

quinn::Endpoint::client((std::net::Ipv6Addr::UNSPECIFIED, 0).into());

某些环境可能不允许创建双栈套接字,此时 IPv6 客户端只能连接到 IPv6 服务器。IPv4 客户端永远不会启用双栈。

源代码

pub fn stats(&self) -> EndpointStats

返回该 Endpoint 的相关统计信息

源代码

pub fn server(config: ServerConfig, addr: SocketAddr) -> Result<Self>

辅助函数,用于构造一个既支持入站又支持出站连接的端点

双栈套接字在各个平台上的默认行为并不一致。例如,在 Windows 上,绑定到 IPv6 通配地址的套接字默认无法与 IPv4 地址通信。可移植的应用应绑定一个与它希望通信的地址族相匹配的地址。

源代码

pub fn new( config: EndpointConfig, server_config: Option<ServerConfig>, socket: UdpSocket, runtime: Arc<dyn Runtime>, ) -> Result<Self>

使用任意配置和套接字构造一个端点

源代码

pub fn new_with_abstract_socket( config: EndpointConfig, server_config: Option<ServerConfig>, socket: Arc<dyn AsyncUdpSocket>, runtime: Arc<dyn Runtime>, ) -> Result<Self>

使用任意配置与预先构造的抽象套接字构造一个端点

socket 附带一些额外的状态(例如用于旁路通信的 side channel),且这些状态需要共享所有权时,本方法非常有用。

源代码

pub fn accept(&self) -> Accept<'_>

获取来自客户端的下一个入站连接尝试

产生一系列 Incoming,若端点已被 close 则返回 NoneIncoming 可以被 await 以获得最终的 Connection,也可以用于例如过滤连接尝试、强制地址校验,或转换为一个中间的 Connecting future(进而可以用于发送 0.5-RTT 数据等)。

源代码

pub fn set_default_client_config(&mut self, config: ClientConfig)

设置 connect 所使用的客户端配置

源代码

pub fn connect( &self, addr: SocketAddr, server_name: &str, ) -> Result<Connecting, ConnectError>

连接到一个远程端点

server_name 必须能被服务器出示的证书所覆盖。这可以防止拥有针对其他服务器有效证书的攻击者拦截该连接。

可能由于配置错误而立即失败,也可能在未来由于连接无法建立而失败。

源代码

pub fn connect_with( &self, config: ClientConfig, addr: SocketAddr, server_name: &str, ) -> Result<Connecting, ConnectError>

使用自定义配置连接到一个远程端点。

详细信息请参阅 connect()

源代码

pub fn rebind(&self, socket: UdpSocket) -> Result<()>

切换到一个新的 UDP 套接字

详细信息请参阅 Endpoint::rebind_abstract()

源代码

pub fn rebind_abstract(&self, socket: Arc<dyn AsyncUdpSocket>) -> Result<()>

切换到一个新的 UDP 套接字

允许端点的地址被实时更新,影响所有活跃连接。从新地址无法到达的入站连接以及与服务器之间的连接将会丢失。

出错时,旧的 UDP 套接字会被保留。

源代码

pub fn set_server_config(&self, server_config: Option<ServerConfig>)

替换服务器配置,仅影响后续的入站连接

典型用途包括:在不中断现有连接的情况下刷新 TLS 证书。

源代码

pub fn local_addr(&self) -> Result<SocketAddr>

获取底层套接字所绑定到的本地 SocketAddr

源代码

pub fn open_connections(&self) -> usize

获取当前处于打开状态的连接数量

源代码

pub fn close(&self, error_code: VarInt, reason: &[u8])

立即关闭本端点的所有连接,并停止接受新的连接。

详细信息请参阅 Connection::close()

源代码

pub async fn wait_idle(&self)

等待端点上的所有连接被干净地关闭

在退出前等待该条件可以保证诚实地通知对端最近的连接关闭事件;而立刻退出则可能迫使对端不得不等完整个空闲超时时段。

该方法不会主动关闭现有连接,也不会使新的入站连接被拒绝。如果有这些需求,请考虑调用 close()

trait 实现§

源代码§

impl Clone for Endpoint

源代码§

fn clone(&self) -> Endpoint

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

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

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

impl Debug for Endpoint

源代码§

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

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

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

获得所有权后的类型。
源代码§

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

转换出错时返回的类型。
源代码§

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

转换出错时返回的类型。
源代码§

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,