Struct Endpoint

Source
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

Source

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).

Source

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

Get the local address the underlying socket is bound to.

Source

pub fn open_connections(&self) -> usize

Get the number of connections (≈sessions) that are currently open.

Source

pub fn stats(&self) -> EndpointStats

Get QUIC activity stats.

Source

pub async fn connect(&self, addrs: impl ToSocketAddrs) -> Result<Session, Error>

Connect to a peer.

Source

pub async fn accept(&self) -> Option<Result<Session, Error>>

Accept an incoming session.

Source

pub fn key(&self) -> Arc<KeyPair>

Key used by this endpoint.

Source

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.

Trait Implementations§

Source§

impl Clone for Endpoint

Source§

fn clone(&self) -> Endpoint

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Endpoint

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

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

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T