Struct libp2p_floodsub::Floodsub
source · pub struct Floodsub<TSubstream> { /* private fields */ }
Expand description
Network behaviour that automatically identifies nodes periodically, and returns information about them.
Implementations
sourceimpl<TSubstream> Floodsub<TSubstream>
impl<TSubstream> Floodsub<TSubstream>
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: impl AsRef<TopicHash>) -> bool
pub fn unsubscribe(&mut self, topic: impl AsRef<TopicHash>) -> bool
Unsubscribes from a topic.
Note that this only requires a TopicHash
and not a full Topic
.
Returns true if we were subscribed to this topic.
sourcepub fn publish(&mut self, topic: impl Into<TopicHash>, data: impl Into<Vec<u8>>)
pub fn publish(&mut self, topic: impl Into<TopicHash>, data: impl Into<Vec<u8>>)
Publishes a message to the network.
Note: Doesn’t do anything if we’re not subscribed to the topic.
sourcepub fn publish_many(
&mut self,
topic: impl IntoIterator<Item = impl Into<TopicHash>>,
data: impl Into<Vec<u8>>
)
pub fn publish_many(
&mut self,
topic: impl IntoIterator<Item = impl Into<TopicHash>>,
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.
Trait Implementations
sourceimpl<TSubstream, TTopology> NetworkBehaviour<TTopology> for Floodsub<TSubstream>where
TSubstream: AsyncRead + AsyncWrite,
impl<TSubstream, TTopology> NetworkBehaviour<TTopology> for Floodsub<TSubstream>where
TSubstream: AsyncRead + AsyncWrite,
type ProtocolsHandler = FloodsubHandler<TSubstream>
type ProtocolsHandler = FloodsubHandler<TSubstream>
Handler for all the protocols the network supports.
type OutEvent = FloodsubEvent
type OutEvent = FloodsubEvent
Event generated by the swarm.
sourcefn new_handler(&mut self) -> Self::ProtocolsHandler
fn new_handler(&mut self) -> Self::ProtocolsHandler
Builds a new
ProtocolsHandler
.sourcefn inject_connected(&mut self, id: PeerId, _: ConnectedPoint)
fn inject_connected(&mut self, id: PeerId, _: ConnectedPoint)
Indicates the behaviour that we connected to the node with the given peer id through the
given endpoint. Read more
sourcefn inject_disconnected(&mut self, id: &PeerId, _: ConnectedPoint)
fn inject_disconnected(&mut self, id: &PeerId, _: ConnectedPoint)
Indicates the behaviour that we disconnected from the node with the given peer id. The
endpoint is the one we used to be connected to. Read more
sourcefn inject_node_event(&mut self, propagation_source: PeerId, event: FloodsubRpc)
fn inject_node_event(&mut self, propagation_source: PeerId, event: FloodsubRpc)
Indicates the behaviour that the node with the given peer id has generated an event for
us. Read more
sourcefn poll(
&mut self,
_: &mut PollParameters<'_, TTopology>
) -> Async<NetworkBehaviourAction<<Self::ProtocolsHandler as ProtocolsHandler>::InEvent, Self::OutEvent>>
fn poll(
&mut self,
_: &mut PollParameters<'_, TTopology>
) -> Async<NetworkBehaviourAction<<Self::ProtocolsHandler as ProtocolsHandler>::InEvent, Self::OutEvent>>
Polls for things that swarm should do. Read more
Auto Trait Implementations
impl<TSubstream> RefUnwindSafe for Floodsub<TSubstream>where
TSubstream: RefUnwindSafe,
impl<TSubstream> Send for Floodsub<TSubstream>where
TSubstream: Send,
impl<TSubstream> Sync for Floodsub<TSubstream>where
TSubstream: Sync,
impl<TSubstream> Unpin for Floodsub<TSubstream>where
TSubstream: Unpin,
impl<TSubstream> UnwindSafe for Floodsub<TSubstream>where
TSubstream: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more