pub trait ConnectionHandler {
type InEvent;
type OutEvent;
type Error;
type Substream;
type OutboundOpenInfo;
// Required methods
fn inject_substream(
&mut self,
substream: Self::Substream,
endpoint: SubstreamEndpoint<Self::OutboundOpenInfo>,
);
fn inject_event(&mut self, event: Self::InEvent);
fn inject_address_change(&mut self, new_address: &Multiaddr);
fn poll(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<ConnectionHandlerEvent<Self::OutboundOpenInfo, Self::OutEvent>, Self::Error>>;
}
Expand description
The interface of a connection handler.
Each handler is responsible for a single connection.
Required Associated Types§
Sourcetype InEvent
type InEvent
The inbound type of events used to notify the handler through the Network
.
See also EstablishedConnection::notify_handler
and ConnectionHandler::inject_event
.
Sourcetype OutEvent
type OutEvent
The outbound type of events that the handler emits to the Network
through ConnectionHandler::poll
.
See also NetworkEvent::ConnectionEvent
.
Sourcetype OutboundOpenInfo
type OutboundOpenInfo
Information about a substream. Can be sent to the handler through a SubstreamEndpoint
,
and will be passed back in inject_substream
or inject_outbound_closed
.
Required Methods§
Sourcefn inject_substream(
&mut self,
substream: Self::Substream,
endpoint: SubstreamEndpoint<Self::OutboundOpenInfo>,
)
fn inject_substream( &mut self, substream: Self::Substream, endpoint: SubstreamEndpoint<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_event(&mut self, event: Self::InEvent)
fn inject_event(&mut self, event: Self::InEvent)
Notifies the handler of an event.
Sourcefn inject_address_change(&mut self, new_address: &Multiaddr)
fn inject_address_change(&mut self, new_address: &Multiaddr)
Notifies the handler of a change in the address of the remote.
Sourcefn poll(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<ConnectionHandlerEvent<Self::OutboundOpenInfo, Self::OutEvent>, Self::Error>>
fn poll( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<ConnectionHandlerEvent<Self::OutboundOpenInfo, Self::OutEvent>, Self::Error>>
Polls the handler for events.
Returning an error will close the connection to the remote.