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
) -> Result<THandler<Self>, ConnectionDenied>
fn handle_established_outbound_connection( &mut self, _: ConnectionId, _: PeerId, _: &Multiaddr, _: Endpoint ) -> 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
.