[−][src]Trait libp2p_core::swarm::NetworkBehaviour
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.
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
)
&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>>
&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.