Project: Rust Encrypted Pub/Sub Broker (whispeer)
Project Overview
A Rust-native, lightweight, end-to-end encrypted Pub/Sub broker supporting:
- Multiple transports: TCP and WebSocket
- Compression and encryption engines
- Typed, async-aware publish/subscribe API
- Plugin system for custom behaviors
- Optional per-topic or global engines
This project targets secure messaging, real-time applications, and extensible event-driven systems.
Core Features
- Broker Core
- Topic registry
- Subscriber management
- Publish/subscribe API
- Compression Engine
- Default: zstd
- Optional: other compression methods
- Encryption Engine
- Default: ChaCha20Poly1305 / AES-GCM
- End-to-end encryption per topic
- WebSocket Transport
- Optional TCP/WS transport
- Automatic compression/encryption integration
- Async Support
- Tokio runtime ready
- Async subscribers
- Plugin System
- Logging, persistence, metrics, custom transforms
- Typed Messages
- Support generic message types via
serde::Serialize/Deserialize
- Support generic message types via
Milestones & Tasks
Milestone 1: Core Broker MVP
Goal: Functional in-memory pub/sub with simple API
Tasks:
- Define
Broker,Topic,Subscriberstructs - Implement basic
subscribe(topic, callback) - Implement basic
publish(topic, message) - Add simple synchronous subscribers
- Write tests for publish/subscribe functionality
Milestone 2: Async + Tokio Integration
Goal: Async subscriber support with Tokio
Tasks:
- Make subscription callbacks async
- Support
async moveclosures for subscribers - Ensure thread-safe broker operations using
Arc<Mutex<>>orRwLock - Write async tests for concurrent publish/subscribe
Milestone 3: Compression Engine
Goal: Add transparent compression support Example:
let broker = new.with;
Tasks:
- Integrate
zstdorlz4compression - Automatically compress messages before sending
- Decompress on the subscriber side
- Add tests for compression correctness and performance
- Optional: allow per-topic compression settings
Milestone 4: Encryption Engine
Goal: End-to-end encrypted messaging
Tasks:
- Integrate
chacha20poly1305oraes-gcmencryption - Automatic encryption/decryption for publishers/subscribers
- Support per-topic or global keys
- Write tests to verify message confidentiality
Milestone 5: Plugin System
Goal: Allow extensibility via plugins
Tasks:
- Define
Plugintrait with hooks (on_publish,on_subscribe) - Implement default logging plugin
- Implement example persistence plugin (in-memory, file, or SQLite)
- Implement trait enforcement system for message types
- Write tests for plugin system integration
Milestone 6: WebSocket Transport
Goal: Real-time messaging over WS as plugin
Tasks:
- Implement WebSocket listener using
tokio-tungstenite - Integrate broker with WebSocket transport
- Support both async and sync subscribers over WS
- Ensure compression + encryption works over WS
- Write WebSocket integration tests
Milestone 7: Typed & Generic Messages
Goal: Make broker type-safe with Rust generics
Tasks:
- Support
publish::<T>(topic, data) - Ensure subscribers get correctly typed messages
- Verify
serde::Serialize/Deserializeintegration - Write tests for multiple types
Milestone 8: Stretch Goals / Optional Features
- Topic wildcards (
"chat/*"or"sensor/+/temperature") - Message persistence and replay
- QoS options:
at_least_once,exactly_once - CLI tool to inspect broker status (topics, subscribers)
- Rust-native client library for browser/Node.js via WASM
- Benchmarking and performance optimization
Project Structure (Proposed)
src/
├── broker/
│ ├── mod.rs
│ ├── broker.rs # Broker core
│ ├── topic.rs # Topic registry
│ └── subscriber.rs # Subscriber management
├── transport/
│ ├── mod.rs
│ ├── websocket.rs # WS transport
│ └── tcp.rs # TCP transport (optional)
├── engines/
│ ├── mod.rs
│ ├── compression.rs # Compression engine
│ └── encryption.rs # Encryption engine
├── plugins/
│ ├── mod.rs
│ └── logging.rs
├── types/
│ └── message.rs # Typed messages
└── main.rs
Tech Stack
- Rust 1.70+
- Tokio for async runtime
serdefor typed messagestokio-tungstenitefor WebSocket supportzstdorlz4for compressionchacha20poly1305oraes-gcmfor encryptionrsubfor a high-performance pub/sub message broker base using QUIC and built-in TLS 1.3 encryption.- Whatever else is needed
Simple example
let broker = builder
.with
.with
.with
.with
.build;
// OR
// Only Compression and Encryption
let broker = build_default.build;
// OR
// With WebSocket and defaults
let broker = build_default_with_ws.build;
// OR
// With Persistence and defaults
let broker = build_default_with_persistence.build;
// OR
// With Persistence, WebSocket and defaults
let broker = build_default_with_persistence_ws.build;
// --- Use:
// Sub:
broker.subscribe
broker.
// Pub:
let my_data = MyData
broker.publish
broker.
Example for the message type:
Timeline (Suggested MVP)
| Week | Goal |
|---|---|
| 1-2 | Milestone 1-2: Core broker + async support |
| 3-4 | Milestone 3: Compression |
| 5-6 | Milestone 4: Encryption |
| 7-8 | Milestone 5: WebSocket transport |
| 9 | Milestone 6: Plugins |
| 10 | Milestone 7: Typed messages + cleanup |
| 11+ | Stretch goals, benchmarking, documentation |
Next Steps
- Start with Milestone 1 MVP, purely in-memory pub/sub.
- Make API ergonomic and type-safe.
- Gradually integrate async, compression, encryption, and WS.
- Expand with plugins and advanced features once core stability is proven.