Crate grapevine

Crate grapevine 

Source
Expand description

Grapevine - A modern, asynchronous peer-to-peer gossip protocol library.

This library provides an implementation of gossip protocols for distributed systems, supporting epidemic broadcast, anti-entropy, and configurable transport layers.

§Features

  • Async/await: Built on Tokio for efficient asynchronous I/O
  • Flexible transport: TCP by default, QUIC [scheduled for v1.1+]
  • Configurable: Extensive configuration options

§Example

use grapevine::{NodeConfig, Node};
use bytes::Bytes;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = NodeConfig::default();
    let node = Node::new(config).await?;

    node.on_message(|origin, data| {
        println!("Received from {origin}: {data:?}");
    }).await;

    node.start().await?;
    node.broadcast(Bytes::from("Hello, gossip!")).await?;
    node.shutdown().await?;

    Ok(())
}

Re-exports§

pub use core::Message;
pub use core::MessageCodec;
pub use core::MessageId;
pub use core::Payload;
pub use core::Peer;
pub use core::PeerId;
pub use core::PeerInfo;
pub use core::PeerState;
pub use core::RateLimitConfig;
pub use core::RateLimiter;
pub use error::Error;
pub use node::Node;
pub use node::NodeConfig;
pub use node::NodeConfigBuilder;
pub use protocol::AntiEntropy;
pub use protocol::AntiEntropyConfig;
pub use protocol::EpidemicConfig;
pub use protocol::Gossip;
pub use protocol::MessageEntry;
pub use transport::Tcp;
pub use transport::Transport;
pub use transport::TransportConfig;

Modules§

core
Core types for Grapevine protocol.
error
Error types for Grapevine.
node
High-level node API.
protocol
Gossip protocol implementations.
serde_duration
Serde helper for Duration (de)serialization.
transport
Network transport implementations.

Macros§

internal_error
Create internal errors with file/line information.

Type Aliases§

Result
Result type alias for all operations.