NetworkBehaviourAction

Enum NetworkBehaviourAction 

Source
pub enum NetworkBehaviourAction<TInEvent, TOutEvent> {
    GenerateEvent(TOutEvent),
    DialAddress {
        address: Multiaddr,
    },
    DialPeer {
        peer_id: PeerId,
        condition: DialPeerCondition,
    },
    DisconnectPeer {
        peer_id: PeerId,
    },
    NotifyHandler {
        peer_id: PeerId,
        handler: NotifyHandler,
        event: TInEvent,
    },
    ReportObservedAddr {
        address: Multiaddr,
        score: AddressScore,
    },
}
Expand description

An action that a NetworkBehaviour can trigger in the Swarm in whose context it is executing.

Variants§

§

GenerateEvent(TOutEvent)

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

§

DialAddress

Instructs the swarm to dial the given multiaddress, with no knowledge of the PeerId that may be reached.

Fields

§address: Multiaddr

The address to dial.

§

DialPeer

Instructs the swarm to dial a known PeerId.

The addresses_of_peer method is called to determine which addresses to attempt to reach.

If we were already trying to dial this node, the addresses that are not yet in the queue of addresses to try are added back to this queue.

On success, NetworkBehaviour::inject_connected is invoked. On failure, NetworkBehaviour::inject_dial_failure is invoked.

Fields

§peer_id: PeerId

The peer to try reach.

§condition: DialPeerCondition

The condition for initiating a new dialing attempt.

§

DisconnectPeer

Instructs the swarm to close connection the peer with PeerId. The connection status flag will be update with disconnect timeout

Fields

§peer_id: PeerId

The peer to try reach.

§

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 ProtocolsHandler 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::inject_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 ProtocolsHandler).

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

Implementations§

Source§

impl<TInEvent, TOutEvent> NetworkBehaviourAction<TInEvent, TOutEvent>

Source

pub fn map_in<E>( self, f: impl FnOnce(TInEvent) -> E, ) -> NetworkBehaviourAction<E, TOutEvent>

Map the handler event.

Source

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

Map the event the swarm will return.

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<TInEvent, TOutEvent> UnwindSafe for NetworkBehaviourAction<TInEvent, TOutEvent>
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, 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

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

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

Source§

fn vzip(self) -> V

Source§

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