Struct libp2p_floodsub::Floodsub
source · pub struct Floodsub { /* private fields */ }
Expand description
Network behaviour that handles the floodsub protocol.
Implementations§
source§impl Floodsub
impl Floodsub
sourcepub fn from_config(config: FloodsubConfig) -> Self
pub fn from_config(config: FloodsubConfig) -> Self
Creates a Floodsub
with the given configuration.
sourcepub fn add_node_to_partial_view(&mut self, peer_id: PeerId)
pub fn add_node_to_partial_view(&mut self, peer_id: PeerId)
Add a node to the list of nodes to propagate messages to.
sourcepub fn remove_node_from_partial_view(&mut self, peer_id: &PeerId)
pub fn remove_node_from_partial_view(&mut self, peer_id: &PeerId)
Remove a node from the list of nodes to propagate messages to.
sourcepub fn subscribe(&mut self, topic: Topic) -> bool
pub fn subscribe(&mut self, topic: Topic) -> bool
Subscribes to a topic.
Returns true if the subscription worked. Returns false if we were already subscribed.
sourcepub fn unsubscribe(&mut self, topic: Topic) -> bool
pub fn unsubscribe(&mut self, topic: Topic) -> bool
Unsubscribes from a topic.
Note that this only requires the topic name.
Returns true if we were subscribed to this topic.
sourcepub fn publish(&mut self, topic: impl Into<Topic>, data: impl Into<Bytes>)
pub fn publish(&mut self, topic: impl Into<Topic>, data: impl Into<Bytes>)
Publishes a message to the network, if we’re subscribed to the topic only.
sourcepub fn publish_any(&mut self, topic: impl Into<Topic>, data: impl Into<Bytes>)
pub fn publish_any(&mut self, topic: impl Into<Topic>, data: impl Into<Bytes>)
Publishes a message to the network, even if we’re not subscribed to the topic.
sourcepub fn publish_many(
&mut self,
topic: impl IntoIterator<Item = impl Into<Topic>>,
data: impl Into<Bytes>,
)
pub fn publish_many( &mut self, topic: impl IntoIterator<Item = impl Into<Topic>>, data: impl Into<Bytes>, )
Publishes a message with multiple topics to the network.
Note: Doesn’t do anything if we’re not subscribed to any of the topics.
sourcepub fn publish_many_any(
&mut self,
topic: impl IntoIterator<Item = impl Into<Topic>>,
data: impl Into<Bytes>,
)
pub fn publish_many_any( &mut self, topic: impl IntoIterator<Item = impl Into<Topic>>, data: impl Into<Bytes>, )
Publishes a message with multiple topics to the network, even if we’re not subscribed to any of the topics.
Trait Implementations§
source§impl NetworkBehaviour for Floodsub
impl NetworkBehaviour for Floodsub
§type ConnectionHandler = OneShotHandler<FloodsubProtocol, FloodsubRpc, InnerMessage>
type ConnectionHandler = OneShotHandler<FloodsubProtocol, FloodsubRpc, InnerMessage>
§type ToSwarm = FloodsubEvent
type ToSwarm = FloodsubEvent
NetworkBehaviour
and that the swarm will report back.source§fn handle_established_inbound_connection(
&mut self,
_: ConnectionId,
_: PeerId,
_: &Multiaddr,
_: &Multiaddr,
) -> Result<THandler<Self>, ConnectionDenied>
fn handle_established_inbound_connection( &mut self, _: ConnectionId, _: PeerId, _: &Multiaddr, _: &Multiaddr, ) -> Result<THandler<Self>, ConnectionDenied>
source§fn handle_established_outbound_connection(
&mut self,
_: ConnectionId,
_: PeerId,
_: &Multiaddr,
_: Endpoint,
_: PortUse,
) -> Result<THandler<Self>, ConnectionDenied>
fn handle_established_outbound_connection( &mut self, _: ConnectionId, _: PeerId, _: &Multiaddr, _: Endpoint, _: PortUse, ) -> Result<THandler<Self>, ConnectionDenied>
source§fn on_connection_handler_event(
&mut self,
propagation_source: PeerId,
connection_id: ConnectionId,
event: THandlerOutEvent<Self>,
)
fn on_connection_handler_event( &mut self, propagation_source: PeerId, connection_id: ConnectionId, event: THandlerOutEvent<Self>, )
ConnectionHandler
dedicated to the peer identified by peer_id
. for the behaviour. Read moresource§fn poll(
&mut self,
_: &mut Context<'_>,
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>>
fn poll( &mut self, _: &mut Context<'_>, ) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>>
source§fn on_swarm_event(&mut self, event: FromSwarm<'_>)
fn on_swarm_event(&mut self, event: FromSwarm<'_>)
Swarm
.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>
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>
Auto Trait Implementations§
impl Freeze for Floodsub
impl RefUnwindSafe for Floodsub
impl Send for Floodsub
impl Sync for Floodsub
impl Unpin for Floodsub
impl UnwindSafe for Floodsub
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
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>
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>
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