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<Vec<u8>>)
pub fn publish(&mut self, topic: impl Into<Topic>, data: impl Into<Vec<u8>>)
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<Vec<u8>>)
pub fn publish_any(&mut self, topic: impl Into<Topic>, data: impl Into<Vec<u8>>)
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<Vec<u8>>
)
pub fn publish_many(
&mut self,
topic: impl IntoIterator<Item = impl Into<Topic>>,
data: impl Into<Vec<u8>>
)
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<Vec<u8>>
)
pub fn publish_many_any(
&mut self,
topic: impl IntoIterator<Item = impl Into<Topic>>,
data: impl Into<Vec<u8>>
)
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 OutEvent = FloodsubEvent
type OutEvent = FloodsubEvent
NetworkBehaviour
and that the swarm will report back.source§fn new_handler(&mut self) -> Self::ConnectionHandler
fn new_handler(&mut self) -> Self::ConnectionHandler
ConnectionHandler
for a connection with a peer. Read moresource§fn inject_connection_established(
&mut self,
id: &PeerId,
_: &ConnectionId,
_: &ConnectedPoint,
_: Option<&Vec<Multiaddr>>,
other_established: usize
)
fn inject_connection_established(
&mut self,
id: &PeerId,
_: &ConnectionId,
_: &ConnectedPoint,
_: Option<&Vec<Multiaddr>>,
other_established: usize
)
source§fn inject_connection_closed(
&mut self,
id: &PeerId,
_: &ConnectionId,
_: &ConnectedPoint,
_: Self::ConnectionHandler,
remaining_established: usize
)
fn inject_connection_closed(
&mut self,
id: &PeerId,
_: &ConnectionId,
_: &ConnectedPoint,
_: Self::ConnectionHandler,
remaining_established: usize
)
source§fn inject_event(
&mut self,
propagation_source: PeerId,
_connection: ConnectionId,
event: InnerMessage
)
fn inject_event(
&mut self,
propagation_source: PeerId,
_connection: ConnectionId,
event: InnerMessage
)
peer_id
.
for the behaviour. Read moresource§fn poll(
&mut self,
_: &mut Context<'_>,
_: &mut impl PollParameters
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>>
fn poll(
&mut self,
_: &mut Context<'_>,
_: &mut impl PollParameters
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>>
source§fn addresses_of_peer(&mut self, _: &PeerId) -> Vec<Multiaddr, Global>
fn addresses_of_peer(&mut self, _: &PeerId) -> Vec<Multiaddr, Global>
source§fn inject_address_change(
&mut self,
_: &PeerId,
_: &ConnectionId,
_old: &ConnectedPoint,
_new: &ConnectedPoint
)
fn inject_address_change(
&mut self,
_: &PeerId,
_: &ConnectionId,
_old: &ConnectedPoint,
_new: &ConnectedPoint
)
ConnectedPoint
of an existing connection has changed.