Enum libp2p_swarm::behaviour::ToSwarm

source ·
pub enum ToSwarm<TOutEvent, TInEvent> {
    GenerateEvent(TOutEvent),
    Dial {
        opts: DialOpts,
    },
    NotifyHandler {
        peer_id: PeerId,
        handler: NotifyHandler,
        event: TInEvent,
    },
    ReportObservedAddr {
        address: Multiaddr,
        score: AddressScore,
    },
    CloseConnection {
        peer_id: PeerId,
        connection: CloseConnection,
    },
}
Expand description

A command issued from a NetworkBehaviour for the Swarm.

Variants§

§

GenerateEvent(TOutEvent)

Instructs the Swarm to return an event when it is being polled.

§

Dial

Instructs the swarm to start a dial.

On success, NetworkBehaviour::on_swarm_event with ConnectionEstablished is invoked. On failure, NetworkBehaviour::on_swarm_event with DialFailure is invoked.

DialOpts provides access to the ConnectionId via DialOpts::connection_id. This ConnectionId will be used throughout the connection’s lifecycle to associate events with it. This allows a NetworkBehaviour to identify a connection that resulted out of its own dial request.

Fields

§

NotifyHandler

Instructs the Swarm to send an event to the handler dedicated to a connection with a peer.

If the Swarm is connected to the peer, the message is delivered to the ConnectionHandler instance identified by the peer ID and connection ID.

If the specified connection no longer exists, the event is silently dropped.

Typically the connection ID given is the same as the one passed to NetworkBehaviour::on_connection_handler_event, i.e. whenever the behaviour wishes to respond to a request on the same connection (and possibly the same substream, as per the implementation of ConnectionHandler).

Note that even if the peer is currently connected, connections can get closed at any time and thus the event may not reach a handler.

Fields

§peer_id: PeerId

The peer for whom a ConnectionHandler should be notified.

§handler: NotifyHandler

The options w.r.t. which connection handler to notify of the event.

§event: TInEvent

The event to send.

§

ReportObservedAddr

Informs the Swarm about an address observed by a remote for the local node by which the local node is supposedly publicly reachable.

It is advisable to issue ReportObservedAddr actions at a fixed frequency per node. This way address information will be more accurate over time and individual outliers carry less weight.

Fields

§address: Multiaddr

The observed address of the local node.

§score: AddressScore

The score to associate with this observation, i.e. an indicator for the trusworthiness of this address relative to other observed addresses.

§

CloseConnection

Instructs the Swarm to initiate a graceful close of one or all connections with the given peer.

Note: Closing a connection via ToSwarm::CloseConnection does not inform the corresponding ConnectionHandler. Closing a connection via a ConnectionHandler can be done either in a collaborative manner across ConnectionHandlers with ConnectionHandler::connection_keep_alive or directly with ConnectionHandlerEvent::Close.

Fields

§peer_id: PeerId

The peer to disconnect.

§connection: CloseConnection

Whether to close a specific or all connections to the given peer.

Implementations§

source§

impl<TOutEvent, TInEventOld> ToSwarm<TOutEvent, TInEventOld>

source

pub fn map_in<TInEventNew>( self, f: impl FnOnce(TInEventOld) -> TInEventNew, ) -> ToSwarm<TOutEvent, TInEventNew>

Map the handler event.

source§

impl<TOutEvent, THandlerIn> ToSwarm<TOutEvent, THandlerIn>

source

pub fn map_out<E>( self, f: impl FnOnce(TOutEvent) -> E, ) -> ToSwarm<E, THandlerIn>

Map the event the swarm will return.

Trait Implementations§

source§

impl<TOutEvent: Debug, TInEvent: Debug> Debug for ToSwarm<TOutEvent, TInEvent>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<TOutEvent, TInEvent> Freeze for ToSwarm<TOutEvent, TInEvent>
where TOutEvent: Freeze, TInEvent: Freeze,

§

impl<TOutEvent, TInEvent> RefUnwindSafe for ToSwarm<TOutEvent, TInEvent>
where TOutEvent: RefUnwindSafe, TInEvent: RefUnwindSafe,

§

impl<TOutEvent, TInEvent> Send for ToSwarm<TOutEvent, TInEvent>
where TOutEvent: Send, TInEvent: Send,

§

impl<TOutEvent, TInEvent> Sync for ToSwarm<TOutEvent, TInEvent>
where TOutEvent: Sync, TInEvent: Sync,

§

impl<TOutEvent, TInEvent> Unpin for ToSwarm<TOutEvent, TInEvent>
where TOutEvent: Unpin, TInEvent: Unpin,

§

impl<TOutEvent, TInEvent> UnwindSafe for ToSwarm<TOutEvent, TInEvent>
where TOutEvent: UnwindSafe, TInEvent: UnwindSafe,

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