Security Guarantees
🔒 Cryptographic Protections
- Modern Encryption: ChaCha20-Poly1305 AEAD or TLS 1.2+/1.3 (no legacy ciphers)
- Key Exchange: X25519 ECDH with per-session ephemeral keys
- Forward Secrecy: Session keys never persist, automatic key rotation
- Replay Protection: Nonce tracking (10,000 per session) + timestamp validation (±5s window)
- Authentication: Mutual TLS support, certificate pinning available
🛡️ DoS/Memory Protections
- Decompression Bombs: Pre-validation prevents LZ4/Zstd expansion attacks (16MB hard limit)
- Memory Exhaustion: Maximum packet size 16MB, backpressure prevents unbounded buffering
- Slowloris: Connection timeouts (configurable), automatic dead connection cleanup
- Resource Limits: Bounded channels, connection limits, compression thresholds
- Fuzzing: 3 fuzz targets continuously tested, OOM attacks caught pre-release
🔍 Implementation Safety
- Memory Safe: 100% safe Rust (zero
unsafein protocol core), fuzz-tested - No Panics: All
unwrap()/expect()confined to test code only - Validated Input: All network data validated before processing, fail-fast on invalid packets
- Audit Trail: Structured logging, comprehensive error context for forensics
- Supply Chain:
cargo-deny+cargo-auditin CI, vetted crypto dependencies (RustCrypto/Rustls)
📋 Standards Compliance
- TLS: Enforces TLS 1.2+ minimum (no SSLv3/TLS 1.0/1.1), strong cipher suites only
- Crypto: NIST-approved algorithms (ChaCha20-Poly1305, X25519, SHA-256)
- Best Practices: Certificate validation, no homebrew crypto, constant-time operations
Threat Model: See THREAT_MODEL.md for comprehensive security analysis and attack scenarios.
Features
Security
- Secure handshake + post-handshake encryption using Elliptic Curve Diffie-Hellman (
ECDH) key exchange - TLS transport with client/server implementations and mutual authentication (
mTLS) - Certificate pinning for enhanced security in TLS connections
- Self-signed certificate generation capability for development environments
- Protection against replay attacks using timestamps and nonce verification
Performance & Reliability
- Advanced backpressure mechanism to prevent server overload from slow clients
- Bounded channels with dynamic read pausing to maintain stable memory usage
- Configurable connection timeouts for all network operations with proper error handling
- Heartbeat mechanism with keep-alive ping/pong messages for connection health monitoring
- Automatic detection and cleanup of dead connections
- Client-side timeout handling with reconnection capabilities
- Optimized Release Builds: LTO + single codegen unit for maximum performance
Testing & Quality
- 77+ Test Suite: Unit, integration, edge cases, stress tests, doc tests
- Fuzzing Infrastructure: 3 targets (packet, handshake, compression) with CI smoke tests
- Benchmarking: Criterion-based micro-benchmarks for packet encode/decode, compression, messages
- CI Pipeline: Format, clippy, cross-platform builds (Linux/macOS/Windows), security audits
Core Architecture
- Custom binary packet format with optional compression (
LZ4,Zstd) - Plugin-friendly dispatcher for message routing with zero-copy serialization
- Graceful shutdown support for all server implementations with configurable timeouts
- Modular transport:
TCP,Unix socket,TLS,cluster sync - Comprehensive configuration system with
TOMLfiles and environment variable overrides - Structured logging with flexible log level control via configuration
Compatibility
- Cross-platform support for local transport (Windows, Linux, macOS)
- Windows-compatible alternative for Unix Domain Sockets
- Ready for microservices, databases, daemons, and system protocols
Installation
Add the library to your Cargo.toml:
[]
= "1.0.1"
Quick Start
TCP Server with Backpressure and Structured Logging
use logging;
use ;
use NetworkConfig;
use Dispatcher;
use Result;
use Arc;
use Duration;
use ;
async
TLS Server
async
Client with Timeout Handling
use logging;
use ;
use NetworkConfig;
use Message;
use ProtocolError;
use Duration;
use ;
use timeout;
async
TLS Client
use ;
use Message;
use Result;
use info;
async
Message Types
Built-in messages include:
HandshakeInit/HandshakeAckPing/PongEcho(String)Unknown
You can extend this list with your own enums or handlers.
Benchmarks
Run microbenchmarks (Criterion):
Highlights:
- Packet encode: up to ~1.9 GiB/s, decode up to ~24.5 GiB/s
- LZ4: compress ~1.0 GiB/s, decompress ~18–19 GiB/s @ 1 MiB
- Zstd (level 1): compress ~1.0 GiB/s, decompress ~0.4 GiB/s @ 1 MiB
- Compression threshold: default 512 bytes (configurable) to skip compression on tiny payloads
See detailed results and recommendations in docs/PERFORMANCE.md.
Testing
Full test suite:
Fuzz smoke tests (nightly):
Stress tests:
Production build profile (already configured): LTO, codegen-units=1, opt-level=3, stripped symbols. Run with cargo build --release.
Custom Message Handlers
Register your own handlers with the dispatcher to process different message types:
use Dispatcher;
use Message;
use Result;
use Arc;
use info;
// Create a dispatcher (typically shared between connections)
let dispatcher = new;
// Basic handlers for built-in message types
dispatcher.register;
dispatcher.register;
// Custom message type handler with complex processing
dispatcher.register;
The dispatcher automatically routes incoming messages based on their message_type(). You can register handlers for both built-in message types and your own custom message types.
Running Tests
Runs full unit + integration tests.
Benchmarking
# Run all benchmarks with output
# Run specific benchmark
Performance Metrics
| Metric | Result | Environment |
|---|---|---|
| Roundtrip Latency | <1ms avg | Local transport |
| Throughput | ~5,000 msg/sec | Standard payload |
| TLS Overhead | +2-5ms | With certificate validation |
The library includes comprehensive benchmarking tools that measure:
- Message roundtrip latency (client → server → client)
- Maximum throughput under various conditions
- Backpressure effectiveness during high load
- Connection recovery after network failures
For detailed benchmarking documentation, see the API Reference.
Documentation
- ARCHITECTURE.md - System design, data flow, component details
- THREAT_MODEL.md - Security analysis, attack scenarios, mitigations
- SECURITY.md - Vulnerability disclosure policy
- API Reference - Detailed API documentation
- Performance Guide - Optimization strategies and benchmarks
Project Structure
src/
├── config.rs # Configuration structures and loading
├── core/ # Codec, packet structure
├── protocol/ # Handshake, heartbeat, message types
├── transport/ # TCP, Unix socket, TLS, Cluster
├── service/ # Daemon + client APIs
├── utils/ # Compression, crypto, timers
benches/ # Criterion benchmarks
fuzz/ # Fuzzing targets (cargo-fuzz)
tests/ # Integration and stress tests
Contributing
Contributions welcome! Please:
- Run
cargo fmt && cargo clippy --workspace -- -D warningsbefore committing - Add tests for new features
- Update documentation as needed
- Follow existing code style and patterns
For security issues, see SECURITY.md.