pub struct Behaviour<P>where
P: Protocol,{ /* private fields */ }Implementations§
Source§impl<P> Behaviour<P>where
P: Protocol,
Public API.
impl<P> Behaviour<P>where
P: Protocol,
Public API.
Sourcepub fn new(config: Config, protocol: P) -> Behaviour<P>
pub fn new(config: Config, protocol: P) -> Behaviour<P>
Creates a new Behaviour from the given configuration and protocol.
Sourcepub fn connections(&self) -> &ConnectionsService
pub fn connections(&self) -> &ConnectionsService
Get a reference to the connections service.
Sourcepub fn subscriptions(&self) -> &BTreeSet<TopicHash>
pub fn subscriptions(&self) -> &BTreeSet<TopicHash>
Get local node topic subscriptions.
Sourcepub fn peer_subscriptions(
&self,
peer_id: &PeerId,
) -> Option<&BTreeSet<TopicHash>>
pub fn peer_subscriptions( &self, peer_id: &PeerId, ) -> Option<&BTreeSet<TopicHash>>
Get peer topic subscriptions.
Sourcepub fn subscribe(&mut self, sub: impl Into<Subscription>) -> Result<bool, Error>
pub fn subscribe(&mut self, sub: impl Into<Subscription>) -> Result<bool, Error>
Subscribe to topic.
Returns Ok(true) if the subscription was successful, Ok(false) if we were already
subscribed to the topic.
impl<P> Behaviour<P>where
P: Protocol,
This impl block contains no items.
Internal API.
Trait Implementations§
Source§impl<P> NetworkBehaviour for Behaviour<P>where
P: Protocol + 'static,
impl<P> NetworkBehaviour for Behaviour<P>where
P: Protocol + 'static,
Source§type ConnectionHandler = Handler<<P as Protocol>::Upgrade>
type ConnectionHandler = Handler<<P as Protocol>::Upgrade>
Handler for all the protocols the network behaviour supports.
Source§type ToSwarm = Event
type ToSwarm = Event
Event generated by the
NetworkBehaviour and that the swarm will report back.Source§fn handle_established_inbound_connection(
&mut self,
connection_id: ConnectionId,
peer_id: PeerId,
local_addr: &Multiaddr,
remote_addr: &Multiaddr,
) -> Result<<Behaviour<P> as NetworkBehaviour>::ConnectionHandler, ConnectionDenied>
fn handle_established_inbound_connection( &mut self, connection_id: ConnectionId, peer_id: PeerId, local_addr: &Multiaddr, remote_addr: &Multiaddr, ) -> Result<<Behaviour<P> as NetworkBehaviour>::ConnectionHandler, ConnectionDenied>
Callback that is invoked for every established inbound connection. Read more
Source§fn handle_established_outbound_connection(
&mut self,
connection_id: ConnectionId,
peer_id: PeerId,
remote_addr: &Multiaddr,
_role_override: Endpoint,
) -> Result<<Behaviour<P> as NetworkBehaviour>::ConnectionHandler, ConnectionDenied>
fn handle_established_outbound_connection( &mut self, connection_id: ConnectionId, peer_id: PeerId, remote_addr: &Multiaddr, _role_override: Endpoint, ) -> Result<<Behaviour<P> as NetworkBehaviour>::ConnectionHandler, ConnectionDenied>
Callback that is invoked for every established outbound connection. Read more
Source§fn on_swarm_event(
&mut self,
event: FromSwarm<'_, <Behaviour<P> as NetworkBehaviour>::ConnectionHandler>,
)
fn on_swarm_event( &mut self, event: FromSwarm<'_, <Behaviour<P> as NetworkBehaviour>::ConnectionHandler>, )
Informs the behaviour about an event from the
Swarm.Source§fn on_connection_handler_event(
&mut self,
peer_id: PeerId,
_connection_id: ConnectionId,
event: <<Behaviour<P> as NetworkBehaviour>::ConnectionHandler as ConnectionHandler>::ToBehaviour,
)
fn on_connection_handler_event( &mut self, peer_id: PeerId, _connection_id: ConnectionId, event: <<Behaviour<P> as NetworkBehaviour>::ConnectionHandler as ConnectionHandler>::ToBehaviour, )
Informs the behaviour about an event generated by the
ConnectionHandler
dedicated to the peer identified by peer_id. for the behaviour. Read moreSource§fn poll(
&mut self,
cx: &mut Context<'_>,
_params: &mut impl PollParameters,
) -> Poll<ToSwarm<<Behaviour<P> as NetworkBehaviour>::ToSwarm, <<Behaviour<P> as NetworkBehaviour>::ConnectionHandler as ConnectionHandler>::FromBehaviour>>
fn poll( &mut self, cx: &mut Context<'_>, _params: &mut impl PollParameters, ) -> Poll<ToSwarm<<Behaviour<P> as NetworkBehaviour>::ToSwarm, <<Behaviour<P> as NetworkBehaviour>::ConnectionHandler as ConnectionHandler>::FromBehaviour>>
Polls for things that swarm should do. Read more
Source§fn handle_pending_inbound_connection(
&mut self,
_connection_id: ConnectionId,
_local_addr: &Multiaddr,
_remote_addr: &Multiaddr,
) -> Result<(), ConnectionDenied>
fn handle_pending_inbound_connection( &mut self, _connection_id: ConnectionId, _local_addr: &Multiaddr, _remote_addr: &Multiaddr, ) -> Result<(), ConnectionDenied>
Callback that is invoked for every new inbound connection. Read more
Source§fn handle_pending_outbound_connection(
&mut self,
_connection_id: ConnectionId,
_maybe_peer: Option<PeerId>,
_addresses: &[Multiaddr],
_effective_role: Endpoint,
) -> Result<Vec<Multiaddr>, ConnectionDenied>
fn handle_pending_outbound_connection( &mut self, _connection_id: ConnectionId, _maybe_peer: Option<PeerId>, _addresses: &[Multiaddr], _effective_role: Endpoint, ) -> Result<Vec<Multiaddr>, ConnectionDenied>
Callback that is invoked for every outbound connection attempt. Read more
Auto Trait Implementations§
impl<P> Freeze for Behaviour<P>
impl<P> !RefUnwindSafe for Behaviour<P>
impl<P> !Send for Behaviour<P>
impl<P> !Sync for Behaviour<P>
impl<P> Unpin for Behaviour<P>
impl<P> !UnwindSafe for Behaviour<P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more