A Rust implementation of RatNet, an anonymity network designed for mesh routing and embedded scenarios.
RatNet-rs provides a robust foundation for building anonymous peer-to-peer networks with the following capabilities:
- Anonymous Communication: End-to-end encrypted messaging with no metadata leakage
- Mesh Routing: Resilient message routing through dynamic network topologies
- Store-and-Forward: Reliable message delivery in challenging network conditions
- Pluggable Transports: Support for UDP, TLS, and HTTPS protocols
- Embedded Ready: Designed for resource-constrained environments
- Database Persistence: Optional SQLite storage for message persistence
Build private communication networks where message content and routing information remain confidential.
Create resilient networks that can route around failures and adapt to changing topologies.
Deploy lightweight nodes on resource-constrained devices for secure communication.
Establish communication channels that can operate in challenging network environments.
Add to your Cargo.toml
:
[dependencies]
ratnet = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
Basic usage:
use ratnet::prelude::*;
use ratnet::nodes::MemoryNode;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize component registrations
ratnet::init();
// Create a new node
let node = Arc::new(MemoryNode::new());
// Start the node
node.start().await?;
// Get the node's public key
let node_id = node.id().await?;
println!("Node ID: {}", node_id);
// Add contacts and peers
node.add_contact("friend".to_string(), "ed25519:...".to_string()).await?;
node.add_peer("peer1".to_string(), true, "127.0.0.1:8080".to_string(), None).await?;
Ok(())
}
The repository includes comprehensive examples demonstrating different aspects of RatNet-rs:
# Run basic in-memory node
cargo run --example basic_node
# Run database-backed node with persistence
cargo run --example database_node
# TLS transport example
cargo run --example tls_transport --features tls
# HTTPS transport example
cargo run --example https_transport --features https
# Message chunking demo
cargo run --example chunking_demo
# Filesystem-based node
cargo run --example filesystem_node
RatNet-rs is built around a modular architecture with these core components:
- Node: Main interface for sending/receiving messages, managing contacts, channels, and peers
- Transport: Network layer abstraction (UDP, TLS, HTTPS)
- Router: Message routing logic with channel mapping support
- Policy: Connection management policies (polling, P2P, server modes)
- Registry: Dynamic component registration system
- ✅ Anonymous peer-to-peer messaging
- ✅ Channel-based message routing
- ✅ Ed25519 cryptographic signing and verification
- ✅ Message chunking and reassembly
- ✅ Dynamic component registration
- ✅ In-memory storage (MemoryNode)
- ✅ SQLite database persistence (DatabaseNode)
- ✅ Filesystem-based storage (FilesystemNode)
- ✅ UDP transport with configurable limits
- ✅ TLS transport with certificate management
- ✅ HTTPS transport for web-based communication
- ✅ Comprehensive test suite
- ✅ Example applications
- ✅ Async-first design with Tokio
- ✅ Type-safe error handling
git clone https://github.com/awgh/ratnet-rs.git
cd ratnet-rs
cargo build
# Run all tests
cargo test
# Run specific test categories
cargo test --test database_tests
cargo test --test end_to_end_tests
sqlite
: Enable SQLite database supporttls
: Enable TLS transporthttps
: Enable HTTPS transportp2p
: Enable P2P networking features
- API Documentation
- Examples - Comprehensive usage examples
- Tests - Test implementations for reference
RatNet-rs maintains API compatibility with the original Go implementation while leveraging Rust's type safety and async capabilities:
Feature | Go | Rust Status |
---|---|---|
Memory Node | ✅ | ✅ |
Database Node | ✅ | ✅ |
UDP Transport | ✅ | ✅ |
TLS Transport | ✅ | ✅ |
HTTPS Transport | ✅ | ✅ |
Message Chunking | ✅ | ✅ |
Component Registry | ✅ | ✅ |
GPL-3.0 (same as the original Go implementation)
- Original RatNet (Go)
- RatNet Transports
- Bencrypt - Crypto abstraction layer