Grapevine
A modern, asynchronous peer-to-peer gossip protocol library and application.
Features
- Async/await - Built on Tokio for high-performance async I/O
- Authenticated messages - Every message is Ed25519-signed by its origin and verified on receipt
- Epidemic broadcast - Probabilistic message forwarding for efficient network coverage
- Anti-entropy - Periodic synchronization ensures eventual consistency
- Rate limiting - Per-peer token bucket rate limiting prevents DoS attacks
- Highly configurable - Fine-tune gossip parameters for your use case
- Zero unsafe code - Memory safe and thread safe
Installation
As a Library
To use Grapevine in your Rust project:
Or add manually to your Cargo.toml:
[]
= "1.1"
= { = "1", = ["full"] }
= "1"
As a CLI Application
To install the standalone gossip client binary:
Then run:
Quick Start
Basic Example
use ;
use Bytes;
async
Multi-Node Cluster
use ;
async
Configuration
Grapevine is highly configurable. See NodeConfig for all options:
use NodeConfigBuilder;
use Duration;
let config = new
.bind_addr
.gossip_interval
.fanout
.max_peers
.max_message_size
.build?;
Message Authenticity
Each node holds an Ed25519 keypair (its PeerId is the public key), signs every message it originates over a domain-separated encoding of the immutable (origin, sequence, payload), and embeds the public key. Recipients verify the signature and pin each origin address to the key it first presented (trust-on-first-use), so a peer cannot forge a message attributed to a pinned origin. This provides integrity and origin authenticity but not confidentiality; see docs/protocol.md for the full threat model.
Note: QUIC transport and TLS (for confidentiality) are planned for a future release.
Architecture
Grapevine implements a push-based gossip protocol with the following components:
- Message Authenticity: Ed25519 signing and verification of every message, with trust-on-first-use origin pinning
- Epidemic Broadcast: Probabilistic rumor mongering (blind variant; default 70% forward probability)
- Anti-Entropy: Periodic version-vector reconciliation and repair (every 30s) ensures eventual consistency
- Peer Management: Automatic health monitoring with state machine (Connecting => Connected => Stale => Disconnected)
- Rate Limiting: Per-peer token bucket (100 capacity, 50 tokens/sec) prevents DoS attacks
- Message Deduplication: Time-based eviction (5 minute TTL) prevents duplicates
- Graceful Shutdown: Phased shutdown with goodbye notifications to peers
See Architecture Documentation for details.
Testing
# Run all tests
# Run integration tests only
# Run with logging
RUST_LOG=debug
CLI Usage
Grapevine includes a standalone binary for running gossip nodes. For a complete guide on starting nodes, joining networks, broadcasting messages, and more, see the CLI Usage Guide.
Environment Variables
For a straightforward run, first copy .env.example to .env and customize:
# Edit .env with your configuration
CLI Arguments
)
Common Operations
# Start a seed node
# Join the network from another terminal
# Join with multiple bootstrap peers
# Start with custom configuration
# Use environment variables
BIND_HOST=0.0.0.0 BIND_PORT=9000
# Enable debug logging
# Graceful shutdown
# Press Ctrl+C to send goodbye messages and cleanly exit
See docs/client.md for:
- Step-by-step setup instructions
- Multi-node cluster examples
- Network tuning parameters
- Troubleshooting common issues
Examples
See the examples directory:
simple_node.rs- Single node setupmulti_node_cluster.rs- Multi-node clustercustom_config.rs- Custom configuration
Run an example:
RUST_LOG=info
Contributing
Contributions are welcome! Please read our Contributing Guidelines and Code of Conduct.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.