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

Handler for all the protocols the network supports.

Event generated by the swarm.

Required Methods

Builds a new ProtocolsHandler.

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

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.

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.

Polls for things that swarm should do.

This API mimics the API of the Stream trait.

Implementors