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

pub trait NetworkBehaviour<TTopology> {
    type ProtocolsHandler: IntoProtocolsHandler;
    type OutEvent;
    fn new_handler(&mut self) -> Self::ProtocolsHandler;
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<TTopology>
    ) -> Async<NetworkBehaviourAction<<<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InEvent, Self::OutEvent>>; }

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 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<TTopology>
) -> 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...

Implementors

Loading content...