Trait libp2p_core::nodes::handled_node::NodeHandler
source · pub trait NodeHandler {
type InEvent;
type OutEvent;
type Error;
type Substream;
type OutboundOpenInfo;
fn inject_substream(
&mut self,
substream: Self::Substream,
endpoint: NodeHandlerEndpoint<Self::OutboundOpenInfo>
);
fn inject_inbound_closed(&mut self);
fn inject_outbound_closed(&mut self, user_data: Self::OutboundOpenInfo);
fn inject_event(&mut self, event: Self::InEvent);
fn shutdown(&mut self);
fn poll(
&mut self
) -> Poll<NodeHandlerEvent<Self::OutboundOpenInfo, Self::OutEvent>, Self::Error>;
}
Expand description
Handler for the substreams of a node.
Required Associated Types
sourcetype OutEvent
type OutEvent
Custom event that can be produced by the handler and that will be returned by the swarm.
sourcetype OutboundOpenInfo
type OutboundOpenInfo
Information about a substream. Can be sent to the handler through a NodeHandlerEndpoint
,
and will be passed back in inject_substream
or inject_outbound_closed
.
Required Methods
sourcefn inject_substream(
&mut self,
substream: Self::Substream,
endpoint: NodeHandlerEndpoint<Self::OutboundOpenInfo>
)
fn inject_substream(
&mut self,
substream: Self::Substream,
endpoint: NodeHandlerEndpoint<Self::OutboundOpenInfo>
)
Sends a new substream to the handler.
The handler is responsible for upgrading the substream to whatever protocol it wants.
Panic
Implementations are allowed to panic in the case of dialing if the user_data
in
endpoint
doesn’t correspond to what was returned earlier when polling, or is used
multiple times.
sourcefn inject_inbound_closed(&mut self)
fn inject_inbound_closed(&mut self)
Indicates to the handler that the inbound part of the muxer has been closed, and that therefore no more inbound substream will be produced.
sourcefn inject_outbound_closed(&mut self, user_data: Self::OutboundOpenInfo)
fn inject_outbound_closed(&mut self, user_data: Self::OutboundOpenInfo)
Indicates to the handler that an outbound substream failed to open because the outbound part of the muxer has been closed.
Panic
Implementations are allowed to panic if user_data
doesn’t correspond to what was returned
earlier when polling, or is used multiple times.
sourcefn inject_event(&mut self, event: Self::InEvent)
fn inject_event(&mut self, event: Self::InEvent)
Injects an event coming from the outside into the handler.
sourcefn shutdown(&mut self)
fn shutdown(&mut self)
Indicates to the node that it should shut down. After that, it is expected that poll()
returns Ready(NodeHandlerEvent::Shutdown)
as soon as possible.
This method allows an implementation to perform a graceful shutdown of the substreams, and send back various events.
sourcefn poll(
&mut self
) -> Poll<NodeHandlerEvent<Self::OutboundOpenInfo, Self::OutEvent>, Self::Error>
fn poll(
&mut self
) -> Poll<NodeHandlerEvent<Self::OutboundOpenInfo, Self::OutEvent>, Self::Error>
Should behave like Stream::poll()
. Should close if no more event can be produced and the
node should be closed.