Enum libp2p_swarm::SwarmEvent

source ·
pub enum SwarmEvent<TBehaviourOutEvent, THandlerErr> {
    Behaviour(TBehaviourOutEvent),
    ConnectionEstablished {
        peer_id: PeerId,
        connection_id: ConnectionId,
        endpoint: ConnectedPoint,
        num_established: NonZeroU32,
        concurrent_dial_errors: Option<Vec<(Multiaddr, TransportError<Error>)>>,
        established_in: Duration,
    },
    ConnectionClosed {
        peer_id: PeerId,
        connection_id: ConnectionId,
        endpoint: ConnectedPoint,
        num_established: u32,
        cause: Option<ConnectionError<THandlerErr>>,
    },
    IncomingConnection {
        connection_id: ConnectionId,
        local_addr: Multiaddr,
        send_back_addr: Multiaddr,
    },
    IncomingConnectionError {
        connection_id: ConnectionId,
        local_addr: Multiaddr,
        send_back_addr: Multiaddr,
        error: ListenError,
    },
    OutgoingConnectionError {
        connection_id: ConnectionId,
        peer_id: Option<PeerId>,
        error: DialError,
    },
    NewListenAddr {
        listener_id: ListenerId,
        address: Multiaddr,
    },
    ExpiredListenAddr {
        listener_id: ListenerId,
        address: Multiaddr,
    },
    ListenerClosed {
        listener_id: ListenerId,
        addresses: Vec<Multiaddr>,
        reason: Result<(), Error>,
    },
    ListenerError {
        listener_id: ListenerId,
        error: Error,
    },
    Dialing {
        peer_id: Option<PeerId>,
        connection_id: ConnectionId,
    },
}
Expand description

Event generated by the Swarm.

Variants§

§

Behaviour(TBehaviourOutEvent)

Event generated by the NetworkBehaviour.

§

ConnectionEstablished

A connection to the given peer has been opened.

Fields

§peer_id: PeerId

Identity of the peer that we have connected to.

§connection_id: ConnectionId

Identifier of the connection.

§endpoint: ConnectedPoint

Endpoint of the connection that has been opened.

§num_established: NonZeroU32

Number of established connections to this peer, including the one that has just been opened.

§concurrent_dial_errors: Option<Vec<(Multiaddr, TransportError<Error>)>>

Some when the new connection is an outgoing connection. Addresses are dialed concurrently. Contains the addresses and errors of dial attempts that failed before the one successful dial.

§established_in: Duration

How long it took to establish this connection

§

ConnectionClosed

A connection with the given peer has been closed, possibly as a result of an error.

Fields

§peer_id: PeerId

Identity of the peer that we have connected to.

§connection_id: ConnectionId

Identifier of the connection.

§endpoint: ConnectedPoint

Endpoint of the connection that has been closed.

§num_established: u32

Number of other remaining connections to this same peer.

§cause: Option<ConnectionError<THandlerErr>>

Reason for the disconnection, if it was not a successful active close.

§

IncomingConnection

A new connection arrived on a listener and is in the process of protocol negotiation.

A corresponding ConnectionEstablished or IncomingConnectionError event will later be generated for this connection.

Fields

§connection_id: ConnectionId

Identifier of the connection.

§local_addr: Multiaddr

Local connection address. This address has been earlier reported with a NewListenAddr event.

§send_back_addr: Multiaddr

Address used to send back data to the remote.

§

IncomingConnectionError

An error happened on an inbound connection during its initial handshake.

This can include, for example, an error during the handshake of the encryption layer, or the connection unexpectedly closed.

Fields

§connection_id: ConnectionId

Identifier of the connection.

§local_addr: Multiaddr

Local connection address. This address has been earlier reported with a NewListenAddr event.

§send_back_addr: Multiaddr

Address used to send back data to the remote.

§error: ListenError

The error that happened.

§

OutgoingConnectionError

An error happened on an outbound connection.

Fields

§connection_id: ConnectionId

Identifier of the connection.

§peer_id: Option<PeerId>

If known, PeerId of the peer we tried to reach.

§error: DialError

Error that has been encountered.

§

NewListenAddr

One of our listeners has reported a new local listening address.

Fields

§listener_id: ListenerId

The listener that is listening on the new address.

§address: Multiaddr

The new address that is being listened on.

§

ExpiredListenAddr

One of our listeners has reported the expiration of a listening address.

Fields

§listener_id: ListenerId

The listener that is no longer listening on the address.

§address: Multiaddr

The expired address.

§

ListenerClosed

One of the listeners gracefully closed.

Fields

§listener_id: ListenerId

The listener that closed.

§addresses: Vec<Multiaddr>

The addresses that the listener was listening on. These addresses are now considered expired, similar to if a ExpiredListenAddr event has been generated for each of them.

§reason: Result<(), Error>

Reason for the closure. Contains Ok(()) if the stream produced None, or Err if the stream produced an error.

§

ListenerError

One of the listeners reported a non-fatal error.

Fields

§listener_id: ListenerId

The listener that errored.

§error: Error

The listener error.

§

Dialing

A new dialing attempt has been initiated by the NetworkBehaviour implementation.

A ConnectionEstablished event is reported if the dialing attempt succeeds, otherwise a OutgoingConnectionError event is reported.

Fields

§peer_id: Option<PeerId>

Identity of the peer that we are connecting to.

§connection_id: ConnectionId

Identifier of the connection.

Implementations§

source§

impl<TBehaviourOutEvent, THandlerErr> SwarmEvent<TBehaviourOutEvent, THandlerErr>

source

pub fn try_into_behaviour_event(self) -> Result<TBehaviourOutEvent, Self>

Extract the TBehaviourOutEvent from this SwarmEvent in case it is the Behaviour variant, otherwise fail.

Trait Implementations§

source§

impl<TBehaviourOutEvent: Debug, THandlerErr: Debug> Debug for SwarmEvent<TBehaviourOutEvent, THandlerErr>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<TBehaviourOutEvent, THandlerErr> Freeze for SwarmEvent<TBehaviourOutEvent, THandlerErr>
where TBehaviourOutEvent: Freeze, THandlerErr: Freeze,

§

impl<TBehaviourOutEvent, THandlerErr> !RefUnwindSafe for SwarmEvent<TBehaviourOutEvent, THandlerErr>

§

impl<TBehaviourOutEvent, THandlerErr> Send for SwarmEvent<TBehaviourOutEvent, THandlerErr>
where TBehaviourOutEvent: Send, THandlerErr: Send,

§

impl<TBehaviourOutEvent, THandlerErr> Sync for SwarmEvent<TBehaviourOutEvent, THandlerErr>
where TBehaviourOutEvent: Sync, THandlerErr: Sync,

§

impl<TBehaviourOutEvent, THandlerErr> Unpin for SwarmEvent<TBehaviourOutEvent, THandlerErr>
where TBehaviourOutEvent: Unpin, THandlerErr: Unpin,

§

impl<TBehaviourOutEvent, THandlerErr> !UnwindSafe for SwarmEvent<TBehaviourOutEvent, THandlerErr>

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.

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

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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