pub struct Endpoint { /* private fields */ }Expand description
The main entrypoint to create connections to, and accept connections from other Mushi peers.
Generally, an application will have a single endpoint instance. This results in more optimal network behaviour, and as a single endpoint can have sessions to any number of peers, and each session supports many concurrent datagrams and streams, there’s little need (outside of testing) for multiple endpoints.
Before creating an endpoint, ensure that a default rustls::crypto::CryptoProvider has been
installed, preferably using install_crypto_provider().
Implementations§
Source§impl Endpoint
impl Endpoint
Sourcepub fn new(
bind_to: impl ToSocketAddrs,
key: EndpointKey,
allower: Arc<dyn AllowConnection>,
cc: Option<Arc<dyn ControllerFactory + Send + Sync + 'static>>,
) -> Result<Self, Error>
pub fn new( bind_to: impl ToSocketAddrs, key: EndpointKey, allower: Arc<dyn AllowConnection>, cc: Option<Arc<dyn ControllerFactory + Send + Sync + 'static>>, ) -> Result<Self, Error>
Create and setup a Mushi peer.
You must provide a local or unspecified address to bind the endpoint to. In most cases,
"[::]:0" suffices: this binds to all IP interfaces and selects a random port. Use
Endpoint::local_addr() to discover the randomly-assigned port.
If bind_to resolves to multiple socket addresses, the first that succeeds creation of the
socket will be used.
allower is the trust policy for remote peers: incoming (client certificate) and outgoing
(server certificate) peers will have their public key extracted and checked by the
AllowConnection implementation.
cc is the congestion control strategy for the QUIC state machine. You can select
different strategies from quinn::congestion or elsewhere to optimise for throughput or
latency, or you can use None to select the default strategy (Cubic, aka RFC 8312).
Sourcepub fn local_addr(&self) -> Result<SocketAddr, Error>
pub fn local_addr(&self) -> Result<SocketAddr, Error>
Get the local address the underlying socket is bound to.
Sourcepub fn open_connections(&self) -> usize
pub fn open_connections(&self) -> usize
Get the number of connections (≈sessions) that are currently open.
Sourcepub fn stats(&self) -> EndpointStats
pub fn stats(&self) -> EndpointStats
Get QUIC activity stats.
Sourcepub async fn connect(&self, addrs: impl ToSocketAddrs) -> Result<Session, Error>
pub async fn connect(&self, addrs: impl ToSocketAddrs) -> Result<Session, Error>
Connect to a peer.
Sourcepub async fn wait_idle(&self)
pub async fn wait_idle(&self)
Wait for all sessions on the endpoint to be cleanly shut down.
Waiting for this condition before exiting ensures that a good-faith effort is made to notify peers of recent session closes, whereas exiting immediately could force them to wait out the idle timeout period.
Does not proactively close existing sessions or cause incoming sessions to be
rejected. Consider calling Session::close() if that is desired.