Saorsa Core
Core P2P networking library for Saorsa platform with DHT, QUIC transport, dual-stack endpoints (IPv6+IPv4), and four-word endpoint encoding.
Guides
- Contributor guide: see AGENTS.md
- Architecture overview: see ARCHITECTURE.md
Features
- P2P NAT Traversal: True peer-to-peer messaging with automatic NAT traversal (ant-quic 0.10.0+)
- DHT (Distributed Hash Table): Advanced DHT implementation with RSPS (Root-Scoped Provider Summaries)
- Placement System: Intelligent shard placement with EigenTrust integration and Byzantine fault tolerance
- QUIC Transport: High-performance networking with ant-quic
- Four-Word Endpoints: Human‑readable network endpoints via
four-word-networking(IPv4 encodes to 4 words; IPv6 word count decided by the crate); decode requires an explicit port (no defaults). - Post-Quantum Cryptography: Future-ready cryptographic algorithms
- WebRTC over QUIC: Advanced WebRTC-QUIC bridge for real-time media streaming with adaptive quality
- Media Processing: Image and audio processing with blurhash and symphonia
- Geographic Routing: Location-aware networking
- Identity Management: Post-quantum ML-DSA-65 signatures (NIST Level 3). No PoW; identities hold only required keys (no embedded word address).
- Secure Storage: Database persistence with deadpool-sqlite + rusqlite
- Monitoring: Prometheus metrics integration
Quick Start
Add this to your Cargo.toml:
[]
= "0.5.0"
Basic DHT Node
use ;
use tokio;
async
P2P NAT Traversal
saorsa-core v0.5.0+ includes full P2P NAT traversal support, enabling direct peer-to-peer connections:
use ;
use FourWordAddress;
async
NAT Traversal Modes:
- P2P Node (default): Both send and receive path validations for symmetric P2P connections
- Client Only: Outgoing connections only, minimal resource usage
- Disabled: No NAT traversal for private networks
Configuration Examples:
// Default P2P mode with concurrency limit of 10
let config = default;
// High-traffic P2P node
let config = p2p_node;
// Lightweight client
let config = client_only;
// Private network (no NAT traversal)
let config = no_nat_traversal;
Four-Word Endpoints
- Endpoints are encoded/decoded using the
four-word-networkingcrate's adaptive API. - IPv4 → 4 words; IPv6 → word count is crate‑defined; decoding requires a port (no implicit defaults).
- Four‑words are reserved strictly for network endpoints; user identities in messaging are separate handles.
Architecture
Core Components
- Network Layer: QUIC-based P2P networking with automatic NAT traversal (ant-quic 0.10.0+)
- DHT: Kademlia-based DHT with RSPS optimization
- Placement System: Intelligent shard placement with weighted selection algorithms
- Identity: Post‑quantum cryptographic identities with ML‑DSA‑65 signatures (no PoW; no embedded four‑word address)
- Storage: Local and distributed content storage with audit and repair
- Geographic Routing: Location-aware message routing
Cryptographic Architecture
Saorsa Core implements a pure post-quantum cryptographic approach for maximum security:
- Post‑quantum signatures: ML‑DSA‑65 (FIPS 204) for quantum‑resistant digital signatures (~128‑bit quantum security)
- PQC Encryption: ChaCha20-Poly1305 with quantum-resistant key derivation
- Key Exchange: ML-KEM-768 (FIPS 203) for quantum-resistant key encapsulation (~128-bit quantum security)
- Hashing: BLAKE3 for fast, secure content addressing
- Transport Security: QUIC with TLS 1.3 and PQC cipher suites
- No Legacy Support: Pure PQC implementation with no classical cryptographic fallbacks
Recent Changes
- Removed all Proof‑of‑Work (PoW) usage (identity, adaptive, placement/DHT, error types, CLI).
- Adopted
four-word-networkingadaptive API; four‑words reserved for endpoints only. - Implemented dual‑stack listeners (IPv6 + IPv4) and Happy Eyeballs dialing.
- Introduced
UserHandlefor messaging identities; migrated mentions, presence, participants, search, reactions, and read/delivered receipts to use it.
Data Flow
Application
↓
Network API
↓
Placement Engine → DHT + Geographic Routing
↓ ↓
↓ Audit & Repair
↓ ↓
QUIC Transport (ant-quic)
↓
Internet
Placement System
Saorsa Core includes an advanced placement system for optimal distribution of erasure-coded shards across the network:
use ;
async
Key Features
- EigenTrust Integration: Uses reputation scores for node selection
- Weighted Selection: Balances trust, performance, capacity, and diversity
- Byzantine Fault Tolerance: Configurable f-out-of-3f+1 security model
- Geographic Diversity: Ensures shards are distributed across regions
- Continuous Monitoring: Audit system with automatic repair
- DHT Record Types: Efficient ≤512B records with cryptographic validation
- Hysteresis Control: Prevents repair storms with smart cooldown
Configuration
use NetworkConfig;
let config = NetworkConfig ;
Feature Flags
default- Metrics and Prometheus integrationmetrics- Prometheus metrics and monitoringmocks- Test/dummy helpers for development (off by default)h2_greedy- Hyperbolic greedy routing helpers in APItest-utils- Test utilities including mock DHT for integration tests
Note: DHT, ant-quic QUIC transport, and post-quantum cryptography are always enabled. Four-word networking is a core feature.
Performance
Saorsa Core is designed for high performance:
- Concurrent Operations: Tokio-based async runtime
- Memory Efficiency: Zero-copy operations where possible
- Network Optimization: QUIC with congestion control
- Caching: Multi-level caching with Q-learning optimization
Benchmarks
Run benchmarks with:
Key benchmarks:
- DHT operations: ~10,000 ops/sec
- Storage throughput: ~100 MB/sec
- Geographic routing: <10ms latency
- Placement decisions: <1s for 8-node selection
- Shard repair: Automatic with <1h detection
- Cryptographic operations: Hardware-accelerated
Security
- Post-Quantum Signatures: ML-DSA-65 (FIPS 204) for quantum-resistant digital signatures (~128-bit quantum security)
- PQC Encryption: ChaCha20-Poly1305 with quantum-resistant key derivation
- Key Exchange: ML-KEM-768 (FIPS 203) for quantum-resistant key encapsulation (~128-bit quantum security)
- BLAKE3 Hashing: Fast and secure content addressing
- QUIC Encryption: Transport-level encryption with PQC support
- Pure PQC: No classical cryptographic algorithms - quantum-resistant from the ground up
- Secure Memory: Platform-specific memory protection
WebRTC over QUIC Integration
Saorsa Core provides a unique WebRTC-over-QUIC bridge that combines the real-time capabilities of WebRTC with the performance and reliability of QUIC transport. This allows for high-quality media streaming with improved NAT traversal and congestion control.
Key Features
- Seamless Integration: Bridge WebRTC media streams over ant-quic transport
- Adaptive Quality: Automatic bandwidth and quality adaptation based on network conditions
- Multiple Stream Types: Support for audio, video, screen sharing, and data channels
- QoS Management: Intelligent Quality of Service with stream prioritization
- Jitter Buffering: Built-in jitter buffers for smooth media playback
- Performance Monitoring: Real-time statistics and performance metrics
Basic WebRTC-QUIC Bridge Setup
use ;
use P2PNetworkNode;
use Arc;
async
Media Streaming Example
use RtpPacket;
// Create and send RTP packets
async
Quality of Service (QoS) Configuration
use QosParameters;
// Configure QoS for different stream types
let audio_qos = QosParameters ;
let video_qos = QosParameters ;
manager.set_qos_params.await;
manager.set_qos_params.await;
Bandwidth Adaptation
// Check for bandwidth adaptation recommendations
if let Some = manager.check_bandwidth_adaptation.await
// Check transmission capacity
let can_send_hd = manager.can_transmit.await; // 1.5KB HD frame
if !can_send_hd
Performance Monitoring
// Get peer statistics
if let Some = bridge.get_peer_stats.await
// Get stream-specific statistics
let stream_stats = manager.get_all_stats.await;
for in stream_stats
Advanced Features
Multi-Stream Management
// Configure multiple streams for comprehensive communication
bridge.add_stream.await?;
bridge.add_stream.await?;
bridge.add_stream.await?;
bridge.add_stream.await?;
Custom Bridge Configuration
use BridgeConfig;
let config = BridgeConfig ;
let bridge = new_with_config.await?;
Error Handling and Reconnection
// Robust error handling
match bridge.send_rtp_packet.await
Use Cases
- Voice Calls: Low-latency audio streaming with Opus codec
- Video Conferencing: Adaptive video quality with H.264/VP8 codecs
- Screen Sharing: High-quality desktop streaming
- File Transfer: Reliable data channel communication
- Gaming: Real-time game state synchronization
- IoT Streaming: Sensor data and telemetry transmission
Media Processing
Built-in media processing capabilities:
- Images: JPEG, PNG, WebP, GIF support with blurhash
- Audio: Full codec support via symphonia
- Streaming: Real-time media streaming over WebRTC
Database Integration
SQLite-based persistence with migrations:
use Database;
let db = open.await?;
db.store_message.await?;
Geographic Features
Location-aware networking:
- Geographic distance calculations
- Location-based routing
- Regional content distribution
- Privacy-preserving location services
Development
Building
# Standard build
# With all features
# Feature-specific build
Testing
# Unit tests
# Integration tests
# Property-based tests
Linting
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
Code Style
- Follow Rust 2024 idioms
- Use
cargo fmtfor formatting - Ensure
cargo clippypasses - Add documentation for public APIs
- Include tests for all new features
License
This project is dual-licensed:
- AGPL-3.0: Open source license for open source projects
- Commercial: Commercial license for proprietary projects
For commercial licensing, contact: saorsalabs@gmail.com
Dependencies
Core Dependencies
tokio- Async runtimefutures- Future utilitiesserde- Serializationanyhow- Error handlingtracing- Logging
Networking
ant-quic(0.10.0+) - QUIC transport with P2P NAT traversalfour-word-networking- Human-readable addressesrustls- TLS support
Cryptography
saorsa-pqc- Post-quantum cryptography (ML-DSA, ML-KEM, ChaCha20-Poly1305)blake3- Hashingrand- Random number generation
Storage & Database
sqlx- Database operationslru- LRU cachingreed-solomon-erasure- Error correction
Media & WebRTC
webrtc- WebRTC implementationimage- Image processingsymphonia- Audio codecsrodio- Audio playback
See Cargo.toml for complete dependency list.
Changelog
See CHANGELOG.md for version history.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: saorsalabs@gmail.com
Saorsa Labs Limited - Building the decentralized future