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 on_connection_handler_event(
&mut self,
propagation_source: PeerId,
_connection_id: ConnectionId,
event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent
)
fn on_connection_handler_event(
&mut self,
propagation_source: PeerId,
_connection_id: ConnectionId,
event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent
)
ConnectionHandler
dedicated to the
peer identified by 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 on_swarm_event(&mut self, event: FromSwarm<'_, Self::ConnectionHandler>)
fn on_swarm_event(&mut self, event: FromSwarm<'_, Self::ConnectionHandler>)
Swarm
.source§fn addresses_of_peer(&mut self, _: &PeerId) -> Vec<Multiaddr, Global>
fn addresses_of_peer(&mut self, _: &PeerId) -> Vec<Multiaddr, Global>
source§fn inject_connection_established(
&mut self,
peer_id: &PeerId,
connection_id: &ConnectionId,
endpoint: &ConnectedPoint,
failed_addresses: Option<&Vec<Multiaddr, Global>>,
other_established: usize
)
fn inject_connection_established(
&mut self,
peer_id: &PeerId,
connection_id: &ConnectionId,
endpoint: &ConnectedPoint,
failed_addresses: Option<&Vec<Multiaddr, Global>>,
other_established: usize
)
FromSwarm::ConnectionEstablished
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.source§fn inject_connection_closed(
&mut self,
peer_id: &PeerId,
connection_id: &ConnectionId,
endpoint: &ConnectedPoint,
handler: <Self::ConnectionHandler as IntoConnectionHandler>::Handler,
remaining_established: usize
)
fn inject_connection_closed(
&mut self,
peer_id: &PeerId,
connection_id: &ConnectionId,
endpoint: &ConnectedPoint,
handler: <Self::ConnectionHandler as IntoConnectionHandler>::Handler,
remaining_established: usize
)
FromSwarm::ConnectionClosed
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.source§fn inject_address_change(
&mut self,
peer_id: &PeerId,
connection_id: &ConnectionId,
old: &ConnectedPoint,
new: &ConnectedPoint
)
fn inject_address_change(
&mut self,
peer_id: &PeerId,
connection_id: &ConnectionId,
old: &ConnectedPoint,
new: &ConnectedPoint
)
FromSwarm::AddressChange
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.ConnectedPoint
of an existing connection has changed.source§fn inject_event(
&mut self,
peer_id: PeerId,
connection: ConnectionId,
event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent
)
fn inject_event(
&mut self,
peer_id: PeerId,
connection: ConnectionId,
event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent
)
NetworkBehaviour::on_connection_handler_event
instead. The default implementation of this inject_*
method delegates to it.peer_id
.
for the behaviour. Read moresource§fn inject_dial_failure(
&mut self,
peer_id: Option<PeerId>,
handler: Self::ConnectionHandler,
error: &DialError
)
fn inject_dial_failure(
&mut self,
peer_id: Option<PeerId>,
handler: Self::ConnectionHandler,
error: &DialError
)
InEvent::DialFailure
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.source§fn inject_listen_failure(
&mut self,
local_addr: &Multiaddr,
send_back_addr: &Multiaddr,
handler: Self::ConnectionHandler
)
fn inject_listen_failure(
&mut self,
local_addr: &Multiaddr,
send_back_addr: &Multiaddr,
handler: Self::ConnectionHandler
)
FromSwarm::ListenFailure
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.source§fn inject_new_listener(&mut self, id: ListenerId)
fn inject_new_listener(&mut self, id: ListenerId)
FromSwarm::NewListener
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.source§fn inject_new_listen_addr(&mut self, id: ListenerId, addr: &Multiaddr)
fn inject_new_listen_addr(&mut self, id: ListenerId, addr: &Multiaddr)
FromSwarm::NewListenAddr
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.source§fn inject_expired_listen_addr(&mut self, id: ListenerId, addr: &Multiaddr)
fn inject_expired_listen_addr(&mut self, id: ListenerId, addr: &Multiaddr)
FromSwarm::ExpiredListenAddr
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.source§fn inject_listener_error(&mut self, id: ListenerId, err: &(dyn Error + 'static))
fn inject_listener_error(&mut self, id: ListenerId, err: &(dyn Error + 'static))
FromSwarm::ListenerError
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.source§fn inject_listener_closed(&mut self, id: ListenerId, reason: Result<(), &Error>)
fn inject_listener_closed(&mut self, id: ListenerId, reason: Result<(), &Error>)
FromSwarm::ListenerClosed
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.source§fn inject_new_external_addr(&mut self, addr: &Multiaddr)
fn inject_new_external_addr(&mut self, addr: &Multiaddr)
FromSwarm::NewExternalAddr
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.source§fn inject_expired_external_addr(&mut self, addr: &Multiaddr)
fn inject_expired_external_addr(&mut self, addr: &Multiaddr)
FromSwarm::ExpiredExternalAddr
in NetworkBehaviour::on_swarm_event
instead. The default implementation of this inject_*
method delegates to it.