pub struct Gossip { /* private fields */ }Expand description
Gossip protocol to broadcast ephemeral messages to all online nodes interested in the same topic.
§Example
// Gossip uses the address book to watch for nodes interested in the same topic.
let gossip = Gossip::builder(address_book, endpoint).spawn().await?;
// Join overlay with given topic.
let handle = gossip.stream([1; 32]).await?;
// Publish a message.
handle.publish(b"Hello, Panda!").await?;
// Subscribe to messages.
let mut rx = handle.subscribe();
tokio::spawn(async move {
while let Some(Ok(_bytes)) = rx.next().await {
// ..
}
});§Ephemeral Messaging
These unreliable “ephemeral” streams are intended to be used for relatively short-lived messages without persistence and catch-up of past state, for example for “Awareness” or “Presence” features. In most cases, messages will only be received if they were published after the subscription was created.
Use LogSync if you wish to receive messages even after being offline for
guaranteed eventual consistency.
§Self-healing overlay
Gossip-based broadcast overlays rely on membership protocols like HyParView which do not heal from network fragmentation caused, for example, by bootstrap nodes going offline.
p2panda-net uses it’s additional, confidential topic discovery layer in
Discovery to automatically heal these partitions. Whenever possible, it
allows nodes a higher chance to connect to every participating node, thereby decentralising the
entrance points into the network.
§Topic Discovery
For gossip to function correctly we need to inform it about discovered nodes who are interested
in the same topic. Check out the Discovery module for more information.
Implementations§
Source§impl Gossip
impl Gossip
pub fn builder(address_book: AddressBook, endpoint: Endpoint) -> Builder
Sourcepub async fn stream(&self, topic: TopicId) -> Result<GossipHandle, GossipError>
pub async fn stream(&self, topic: TopicId) -> Result<GossipHandle, GossipError>
Join gossip overlay for this topic and return a handle to publish messages to it or receive messages from the network.
Sourcepub async fn events(&self) -> Result<Receiver<GossipEvent>, GossipError>
pub async fn events(&self) -> Result<Receiver<GossipEvent>, GossipError>
Subscribe to system events.