Trait libp2p_core::swarm::NetworkBehaviour
source · pub trait NetworkBehaviour<TTopology> {
type ProtocolsHandler: ProtocolsHandler;
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 ProtocolsHandler>::OutEvent
);
fn poll(
&mut self,
topology: &mut PollParameters<'_, TTopology>
) -> Async<NetworkBehaviourAction<<Self::ProtocolsHandler as ProtocolsHandler>::InEvent, Self::OutEvent>>;
}
Expand description
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.
Required Associated Types
sourcetype ProtocolsHandler: ProtocolsHandler
type ProtocolsHandler: ProtocolsHandler
Handler for all the protocols the network supports.
Required Methods
sourcefn new_handler(&mut self) -> Self::ProtocolsHandler
fn new_handler(&mut self) -> Self::ProtocolsHandler
Builds a new ProtocolsHandler
.
sourcefn inject_connected(&mut self, peer_id: PeerId, endpoint: ConnectedPoint)
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.
sourcefn inject_disconnected(&mut self, peer_id: &PeerId, endpoint: ConnectedPoint)
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.
sourcefn inject_node_event(
&mut self,
peer_id: PeerId,
event: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent
)
fn inject_node_event(
&mut self,
peer_id: PeerId,
event: <Self::ProtocolsHandler 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.
sourcefn poll(
&mut self,
topology: &mut PollParameters<'_, TTopology>
) -> Async<NetworkBehaviourAction<<Self::ProtocolsHandler as ProtocolsHandler>::InEvent, Self::OutEvent>>
fn poll(
&mut self,
topology: &mut PollParameters<'_, TTopology>
) -> Async<NetworkBehaviourAction<<Self::ProtocolsHandler as ProtocolsHandler>::InEvent, Self::OutEvent>>
Polls for things that swarm should do.
This API mimics the API of the Stream
trait.