Struct libp2p_kad::handler::KademliaHandler
source · pub struct KademliaHandler<TSubstream, TUserData>where
TSubstream: AsyncRead + AsyncWrite,{ /* private fields */ }
Expand description
Protocol handler that handles Kademlia communications with the remote.
The handler will automatically open a Kademlia substream with the remote for each request we make.
It also handles requests made by the remote.
Implementations
sourceimpl<TSubstream, TUserData> KademliaHandler<TSubstream, TUserData>where
TSubstream: AsyncRead + AsyncWrite,
impl<TSubstream, TUserData> KademliaHandler<TSubstream, TUserData>where
TSubstream: AsyncRead + AsyncWrite,
sourcepub fn dial_only() -> Self
pub fn dial_only() -> Self
Create a KademliaHandler
that only allows sending messages to the remote but denying
incoming connections.
sourcepub fn dial_and_listen() -> Self
pub fn dial_and_listen() -> Self
Create a KademliaHandler
that only allows sending messages but also receive incoming
requests.
The Default
trait implementation wraps around this function.
Trait Implementations
sourceimpl<TSubstream, TUserData> Default for KademliaHandler<TSubstream, TUserData>where
TSubstream: AsyncRead + AsyncWrite,
impl<TSubstream, TUserData> Default for KademliaHandler<TSubstream, TUserData>where
TSubstream: AsyncRead + AsyncWrite,
sourceimpl<TSubstream, TUserData> ProtocolsHandler for KademliaHandler<TSubstream, TUserData>where
TSubstream: AsyncRead + AsyncWrite,
TUserData: Clone,
impl<TSubstream, TUserData> ProtocolsHandler for KademliaHandler<TSubstream, TUserData>where
TSubstream: AsyncRead + AsyncWrite,
TUserData: Clone,
type InEvent = KademliaHandlerIn<TUserData>
type InEvent = KademliaHandlerIn<TUserData>
Custom event that can be received from the outside.
type OutEvent = KademliaHandlerEvent<TUserData>
type OutEvent = KademliaHandlerEvent<TUserData>
Custom event that can be produced by the handler and that will be returned to the outside.
type Substream = TSubstream
type Substream = TSubstream
The type of the substream that contains the raw data.
type InboundProtocol = EitherUpgrade<KademliaProtocolConfig, DeniedUpgrade>
type InboundProtocol = EitherUpgrade<KademliaProtocolConfig, DeniedUpgrade>
The upgrade for the protocol or protocols handled by this handler.
type OutboundProtocol = KademliaProtocolConfig
type OutboundProtocol = KademliaProtocolConfig
The upgrade for the protocol or protocols handled by this handler.
type OutboundOpenInfo = (KadRequestMsg, Option<TUserData>)
type OutboundOpenInfo = (KadRequestMsg, Option<TUserData>)
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
. Read moresourcefn listen_protocol(&self) -> Self::InboundProtocol
fn listen_protocol(&self) -> Self::InboundProtocol
Produces a
ConnectionUpgrade
for the protocol or protocols to accept when listening. Read morefn inject_fully_negotiated_outbound(
&mut self,
protocol: <Self::OutboundProtocol as OutboundUpgrade<TSubstream>>::Output,
(msg, user_data): Self::OutboundOpenInfo
)
sourcefn inject_fully_negotiated_inbound(
&mut self,
protocol: <Self::InboundProtocol as InboundUpgrade<TSubstream>>::Output
)
fn inject_fully_negotiated_inbound(
&mut self,
protocol: <Self::InboundProtocol as InboundUpgrade<TSubstream>>::Output
)
Injects a fully-negotiated substream in the handler. Read more
sourcefn inject_event(&mut self, message: KademliaHandlerIn<TUserData>)
fn inject_event(&mut self, message: KademliaHandlerIn<TUserData>)
Injects an event coming from the outside in the handler.
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 substreams will be produced. Read more
sourcefn inject_dial_upgrade_error(
&mut self,
(_, user_data): Self::OutboundOpenInfo,
error: ProtocolsHandlerUpgrErr<Error>
)
fn inject_dial_upgrade_error(
&mut self,
(_, user_data): Self::OutboundOpenInfo,
error: ProtocolsHandlerUpgrErr<Error>
)
Indicates to the handler that upgrading a substream to the given protocol has failed.
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(None)
as soon as possible. Read moresourcefn poll(
&mut self
) -> Poll<ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>, Error>
fn poll(
&mut self
) -> Poll<ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>, Error>
Should behave like
Stream::poll()
. Should close if no more event can be produced and the
node should be closed. Read moresourcefn map_in_event<TNewIn, TMap>(self, map: TMap) -> MapInEvent<Self, TNewIn, TMap>where
Self: Sized,
TMap: Fn(&TNewIn) -> Option<&Self::InEvent>,
fn map_in_event<TNewIn, TMap>(self, map: TMap) -> MapInEvent<Self, TNewIn, TMap>where
Self: Sized,
TMap: Fn(&TNewIn) -> Option<&Self::InEvent>,
Adds a closure that turns the input event into something else.
sourcefn map_out_event<TMap, TNewOut>(self, map: TMap) -> MapOutEvent<Self, TMap>where
Self: Sized,
TMap: FnMut(Self::OutEvent) -> TNewOut,
fn map_out_event<TMap, TNewOut>(self, map: TMap) -> MapOutEvent<Self, TMap>where
Self: Sized,
TMap: FnMut(Self::OutEvent) -> TNewOut,
Adds a closure that turns the output event into something else.
sourcefn select<TProto2>(self, other: TProto2) -> ProtocolsHandlerSelect<Self, TProto2>where
Self: Sized,
fn select<TProto2>(self, other: TProto2) -> ProtocolsHandlerSelect<Self, TProto2>where
Self: Sized,
Builds an implementation of
ProtocolsHandler
that handles both this protocol and the
other one together. Read moresourcefn into_node_handler_builder(self) -> NodeHandlerWrapperBuilder<Self>where
Self: Sized,
fn into_node_handler_builder(self) -> NodeHandlerWrapperBuilder<Self>where
Self: Sized,
Creates a builder that will allow creating a
NodeHandler
that handles this protocol
exclusively. Read moresourcefn into_node_handler(self) -> NodeHandlerWrapper<Self>where
Self: Sized,
fn into_node_handler(self) -> NodeHandlerWrapper<Self>where
Self: Sized,
Builds an implementation of
NodeHandler
that handles this protocol exclusively. Read moreAuto Trait Implementations
impl<TSubstream, TUserData> !RefUnwindSafe for KademliaHandler<TSubstream, TUserData>
impl<TSubstream, TUserData> Send for KademliaHandler<TSubstream, TUserData>where
TSubstream: Send,
TUserData: Send,
impl<TSubstream, TUserData> Sync for KademliaHandler<TSubstream, TUserData>where
TSubstream: Sync,
TUserData: Sync,
impl<TSubstream, TUserData> Unpin for KademliaHandler<TSubstream, TUserData>where
TSubstream: Unpin,
TUserData: Unpin,
impl<TSubstream, TUserData> !UnwindSafe for KademliaHandler<TSubstream, TUserData>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more