Struct libp2p_gossipsub::Gossipsub[][src]

pub struct Gossipsub { /* fields omitted */ }

Network behaviour that handles the gossipsub protocol.

NOTE: Initialisation requires a MessageAuthenticity and GossipsubConfig instance. If message signing is disabled, the ValidationMode in the config should be adjusted to an appropriate level to accept unsigned messages.

Implementations

impl Gossipsub[src]

pub fn new(privacy: MessageAuthenticity, config: GossipsubConfig) -> Self[src]

Creates a Gossipsub struct given a set of parameters specified via a GossipsubConfig.

pub fn topics(&self) -> impl Iterator<Item = &TopicHash>[src]

Lists the hashes of the topics we are currently subscribed to.

pub fn peers(&self, topic_hash: &TopicHash) -> impl Iterator<Item = &PeerId>[src]

Lists peers for a certain topic hash.

pub fn all_peers(&self) -> impl Iterator<Item = &PeerId>[src]

Lists all peers for any topic.

pub fn subscribe(&mut self, topic: Topic) -> bool[src]

Subscribe to a topic.

Returns true if the subscription worked. Returns false if we were already subscribed.

pub fn unsubscribe(&mut self, topic: Topic) -> bool[src]

Unsubscribes from a topic.

Returns true if we were subscribed to this topic.

pub fn publish(
    &mut self,
    topic: &Topic,
    data: impl Into<Vec<u8>>
) -> Result<(), PublishError>
[src]

Publishes a message to the network.

pub fn publish_many(
    &mut self,
    topics: impl IntoIterator<Item = Topic>,
    data: impl Into<Vec<u8>>
) -> Result<(), PublishError>
[src]

Publishes a message with multiple topics to the network.

pub fn validate_message(
    &mut self,
    message_id: &MessageId,
    propagation_source: &PeerId
) -> bool
[src]

This function should be called when config.validate_messages is true in order to validate and propagate messages. Messages are stored in the [‘Memcache’] and validation is expected to be fast enough that the messages should still exist in the cache.

Calling this function will propagate a message stored in the cache, if it still exists. If the message still exists in the cache, it will be forwarded and this function will return true, otherwise it will return false.

The propagation_source parameter indicates who the message was received by and will not be forwarded back to that peer.

This should only be called once per message.

Trait Implementations

impl Debug for Gossipsub[src]

impl NetworkBehaviour for Gossipsub[src]

type ProtocolsHandler = GossipsubHandler

Handler for all the protocols the network behaviour supports.

type OutEvent = GossipsubEvent

Event generated by the NetworkBehaviour and that the swarm will report back.

Auto Trait Implementations

impl !RefUnwindSafe for Gossipsub

impl Send for Gossipsub

impl Sync for Gossipsub

impl Unpin for Gossipsub

impl !UnwindSafe for Gossipsub

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]