[][src]Trait libp2p_core::swarm::NetworkBehaviour

pub trait NetworkBehaviour {
    type ProtocolsHandler: IntoProtocolsHandler;
    type OutEvent;
    fn new_handler(&mut self) -> Self::ProtocolsHandler;
fn addresses_of_peer(&mut self, peer_id: &PeerId) -> Vec<Multiaddr>;
fn inject_connected(&mut self, peer_id: PeerId, endpoint: ConnectedPoint);
fn inject_disconnected(
        &mut self,
        peer_id: &PeerId,
        endpoint: ConnectedPoint
    );
fn inject_node_event(
        &mut self,
        peer_id: PeerId,
        event: <<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent
    );
fn poll(
        &mut self,
        topology: &mut PollParameters
    ) -> Async<NetworkBehaviourAction<<<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InEvent, Self::OutEvent>>; fn inject_replaced(
        &mut self,
        peer_id: PeerId,
        closed_endpoint: ConnectedPoint,
        new_endpoint: ConnectedPoint
    ) { ... }
fn inject_dial_failure(
        &mut self,
        _peer_id: Option<&PeerId>,
        _addr: &Multiaddr,
        _error: &dyn Error
    ) { ... } }

A behaviour for the network. Allows customizing the swarm.

This trait has been designed to be composable. Multiple implementations can be combined into one that handles all the behaviours at once.

Associated Types

type ProtocolsHandler: IntoProtocolsHandler

Handler for all the protocols the network supports.

type OutEvent

Event generated by the swarm.

Loading content...

Required methods

fn new_handler(&mut self) -> Self::ProtocolsHandler

Builds a new ProtocolsHandler.

fn addresses_of_peer(&mut self, peer_id: &PeerId) -> Vec<Multiaddr>

Addresses that this behaviour is aware of for this specific peer, and that may allow reaching the peer.

fn inject_connected(&mut self, peer_id: PeerId, endpoint: ConnectedPoint)

Indicates the behaviour that we connected to the node with the given peer id through the given endpoint.

fn inject_disconnected(&mut self, peer_id: &PeerId, endpoint: ConnectedPoint)

Indicates the behaviour that we disconnected from the node with the given peer id. The endpoint is the one we used to be connected to.

fn inject_node_event(
    &mut self,
    peer_id: PeerId,
    event: <<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent
)

Indicates the behaviour that the node with the given peer id has generated an event for us.

Note: This method is only called for events generated by the protocols handler.

fn poll(
    &mut self,
    topology: &mut PollParameters
) -> Async<NetworkBehaviourAction<<<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InEvent, Self::OutEvent>>

Polls for things that swarm should do.

This API mimics the API of the Stream trait.

Loading content...

Provided methods

fn inject_replaced(
    &mut self,
    peer_id: PeerId,
    closed_endpoint: ConnectedPoint,
    new_endpoint: ConnectedPoint
)

Indicates the behaviour that we replace the connection from the node with another.

fn inject_dial_failure(
    &mut self,
    _peer_id: Option<&PeerId>,
    _addr: &Multiaddr,
    _error: &dyn Error
)

Indicates to the behaviour that we tried to reach a node, but failed.

Loading content...

Implementors

Loading content...