Grapevine
A modern, asynchronous peer-to-peer gossip protocol library and application.
Features
- Async/await - Built on Tokio for high-performance async I/O
- 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.0"
= { = "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?;
Feature Flags
crypto- Enable message signing and verification (deferred tov1.1)
Note: QUIC transport support is planned for v1.1+
Architecture
Grapevine implements a push-based gossip protocol with the following components:
- Epidemic Broadcast: Probabilistic message forwarding (default 70% probability, max 5 forwards)
- Anti-Entropy: Periodic digest exchange 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.