Skip to main content

PeerState

Enum PeerState 

Source
enum PeerState {
    None,
    Connected(CancellationToken),
    Reconnect(Peer),
    Replace(Connection),
}
Expand description

The states of a peer.

When a party is created there exists no peer yet. After a connection has been accepted or a connect attempt succeeded, a peer task is created and the state transitions to Connected. The cancellation token is used if the peer task should stop in order to replace the peer’s connection. When cancelled the next connection is stored in Replace and once the peer task finishes and returns the peer, its connection is set and a new peer task (with the same peer object) is spawned and the state transitions to Connected again.

The Reconnect state is entered if the peer itself errors and its task finishes. We keep the peer here until we have a new connection to resume. Once a connect or accept task finishes we set the connection and spawn a new peer task again.

Variants§

§

None

Initial state.

§

Connected(CancellationToken)

A peer task is running.

The cancellation token can be used to interrupt the peer. The task will end and the peer object is returned.

§

Reconnect(Peer)

A peer has errored and wants a fresh connection.

We store the peer here until a new connection is available.

§

Replace(Connection)

The server wants to replace a peer’s connection.

Only entered from Connected after the server has cancelled the peer task. While waiting for the task to return the peer object we park the connection here.

Implementations§

Source§

impl PeerState

Source

fn take(&mut self) -> Self

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> Same for T

Source§

type Output = T

Should always be Self
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.
§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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