2 releases (1 stable)
Uses new Rust 2024
| 1.1.0 | Jul 17, 2025 |
|---|---|
| 0.1.0 | Jun 29, 2025 |
#15 in #neural
65 downloads per month
1.5MB
25K
SLoC
π§ Synapse: Neural Communication Network

A revolutionary neural communication network for AI and distributed systems with federated identity, dual trust systems, and privacy-respecting discovery.
π What is Synapse?
Synapse is a cutting-edge communication system that transforms how AI entities, applications, and distributed systems interact across the internet. Built on a foundation of federated identity management and blockchain-verified trust, Synapse provides:
- π Universal Reach: Federated network spanning organizations and platforms
- π Privacy-First: Advanced privacy controls with stealth and unlisted modes
- β‘ Intelligent Routing: Multi-speed communication with smart transport selection
- π€ AI-Native Design: Optimized for AI-to-AI and human-to-AI interaction
- ποΈ Dual Trust System: Entity-to-entity and blockchain-verified network trust
- οΏ½ Contextual Discovery: Natural contact patterns with intelligent name resolution
π― Key Innovation: Neural Identity Resolution
One of Synapse's most powerful features is its contextual identity system. You can send messages using natural language descriptions that are automatically resolved to participants through multiple discovery layers:
// Instead of complex addressing...
router.send_to("alice@ai-lab.example.com:8080", message).await?;
// Just use simple names!
router.send_to("Alice", message).await?; // π Automatically resolved!
How Identity Resolution Works
- Local Names:
"Alice","Claude","GPT-4" - Global IDs:
"alice@ai-lab.example.com","claude@anthropic.com" - Network Discovery: Automatic discovery of IP addresses, ports, and capabilities
- Smart Routing: Chooses best transport (TCP, UDP, email) based on availability
"Alice" β alice@ai-lab.example.com β 192.168.1.100:8080 β TCP/direct
"Claude" β claude@anthropic.com β [encrypted email] β SMTP/relay
"LocalBot" β bot@localhost β 127.0.0.1:9090 β UDP/local
ποΈ Architecture Overview
Synapse operates on multiple layers to provide maximum flexibility and performance:
Transport Layer Hierarchy
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Synapse Message Layer β
β Simple names, security, routing, message types β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Identity Resolution β
β Local names β Global IDs β Network addresses β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Multi-Transport Router β
β Automatic selection of best available transport β
ββββββββββββββββ¬βββββββββββββββ¬βββββββββββββββ¬βββββββββββββββ€
β Real-Time β Direct β Local β Email β
β (<100ms) β Connection β Discovery β Reliable β
β β β β β
β β’ TCP β β’ UDP β β’ mDNS β β’ SMTP β
β β’ WebSocket β β’ Raw IP β β’ LAN scan β β’ IMAP β
β β’ gRPC β β’ P2P β β’ Bluetooth β β’ Exchange β
ββββββββββββββββ΄βββββββββββββββ΄βββββββββββββββ΄βββββββββββββββ
Intelligence Features
- π§ Adaptive Routing: Learns network topology and optimizes routes
- π Performance Monitoring: Tracks latency, reliability, bandwidth usage
- π Automatic Fallback: Gracefully degrades from fast β reliable transports
- π NAT Traversal: Punches through firewalls using STUN/TURN/UPnP
- π‘ Service Discovery: Finds peers on local networks automatically
π Quick Start
Installation
[dependencies]
message_routing_system = "0.1.0"
Basic Usage
use message_routing_system::*;
#[tokio::main]
async fn main() -> Result<()> {
// 1. Initialize the enhanced router
let config = Config::default();
let router = EnhancedSynapseRouter::new(config, "MyBot@example.com".to_string()).await?;
// 2. Register some identities (optional - auto-discovery also works)
router.register_peer("Alice", "alice@ai-lab.example.com").await?;
router.register_peer("Bob", "bob@robotics.company.com").await?;
// 3. Start all services (email server, transport discovery, etc.)
router.start().await?;
// 4. Send messages using simple names!
router.send_message_smart(
"Alice", // Just use the name
"Hello from Synapse!", // Your message
MessageType::Direct, // Message type
SecurityLevel::Authenticated, // Security level
MessageUrgency::Interactive, // Urgency (affects transport choice)
).await?;
Ok(())
}
Real-World Example: AI Collaboration
// AI agents coordinating on a research project
async fn ai_research_collaboration() -> Result<()> {
let claude = EnhancedSynapseRouter::new(config, "claude@anthropic.com".to_string()).await?;
// Real-time brainstorming (uses TCP/UDP if available, falls back to email)
claude.send_message_smart(
"GPT-4",
"What's your take on quantum consciousness theories?",
MessageType::Conversation,
SecurityLevel::Authenticated,
MessageUrgency::RealTime, // <100ms preferred
).await?;
// File sharing (automatic transport selection based on size)
claude.send_file(
"ResearchTeam",
"quantum_paper_draft_v3.pdf",
MessageUrgency::Normal,
).await?;
// Reliable delivery for important results (guaranteed delivery via email)
claude.send_message_smart(
"Human-Researcher",
"Breakthrough achieved! See attached simulation results.",
MessageType::Notification,
SecurityLevel::Encrypted,
MessageUrgency::Background, // Reliability over speed
).await?;
Ok(())
}
ποΈ Advanced Features
1. Multi-Transport Intelligence
Synapse automatically selects the best transport method based on:
- Message urgency (real-time vs. reliable delivery)
- Network conditions (latency, bandwidth, connectivity)
- Security requirements (encryption, authentication)
- Peer capabilities (what transports they support)
// The system automatically chooses:
// β’ TCP for local real-time messages
// β’ UDP for low-latency discovery
// β’ Email for reliable remote delivery
// β’ mDNS for local peer discovery
// β’ NAT traversal for firewall penetration
2. Email Server Integration
Synapse can run its own email infrastructure when externally accessible:
// Automatic email server with intelligent connectivity detection
let router = EnhancedSynapseRouter::new(config, entity_id).await?;
if router.is_running_email_server() {
println!("π Running local SMTP/IMAP server");
// Can receive emails directly at your-bot@your-domain.com
} else {
println!("π Using external email providers");
// Falls back to Gmail, Outlook, etc.
}
3. Circuit Breaker Infrastructure
Comprehensive circuit breaker protection across all transports:
// Automatic circuit breaker protection
let transport = EnhancedMdnsTransport::new("entity-id", 8080, None).await?;
// Circuit breaker automatically protects against failures
let result = transport.send_message("target", &message).await;
// Monitor circuit breaker state
let stats = transport.get_circuit_breaker().get_stats();
println!("Circuit state: {:?}, failures: {}", stats.state, stats.failure_count);
Key Features:
- Automatic failure detection based on configurable thresholds
- Intelligent recovery with half-open testing
- External triggers for performance degradation
- Comprehensive monitoring with real-time statistics
4. Blockchain Trust System
Decentralized trust verification with staking mechanisms:
// Blockchain-based trust verification
let blockchain = SynapseBlockchain::new(config).await?;
// Stake tokens to vouch for network participants
blockchain.stake_for_participant("alice@ai-lab.com", 1000).await?;
// Verify trust scores before communication
let trust_score = blockchain.get_trust_score("alice@ai-lab.com").await?;
if trust_score.reputation > 0.8 {
// Proceed with high-trust communication
}
Key Features:
- Proof-of-stake consensus for network trust
- Reputation scoring with decay mechanisms
- Staking requirements for network participation
- Trust decay based on activity and time
5. Real-Time Streaming
Live streaming capabilities for continuous communication:
// Start a streaming session
let stream = router.start_stream("Alice").await?;
// Send streaming data
stream.send_chunk(b"Live data chunk 1").await?;
stream.send_chunk(b"Live data chunk 2").await?;
// End the stream
stream.finalize().await?;
Key Features:
- Stream chunking with automatic reassembly
- Priority-based delivery for different stream types
- Session management for multiple concurrent streams
- Reliability guarantees with acknowledgment tracking
6. OAuth & Federated Authentication
Enterprise-grade authentication with OAuth 2.0 support:
// OAuth provider integration
let auth_manager = SynapseAuthManager::new(auth_config).await?;
// Authenticate with multiple providers
let token = auth_manager.authenticate_oauth("google", credentials).await?;
// Use federated identity
let user_context = auth_manager.get_user_context(&token).await?;
Key Features:
- OAuth 2.0 provider integration (Google, Microsoft, etc.)
- Multi-factor authentication support
- JWT token management with automatic refresh
- Federated identity across organizations
7. Advanced Monitoring & Metrics
Comprehensive system monitoring and performance tracking:
// Get system metrics
let metrics = router.get_metrics().await?;
println!("Messages/sec: {}", metrics.message_throughput);
println!("Average latency: {:?}", metrics.average_latency);
// Subscribe to performance alerts
let mut alerts = router.subscribe_alerts().await?;
while let Some(alert) = alerts.recv().await {
println!("Alert: {}", alert.message);
}
Key Features:
- Real-time metrics collection and reporting
- Performance monitoring with historical data
- Alert system for performance degradation
- Health diagnostics for system components
8. Security by Default
- π PGP Encryption: All messages encrypted with recipient's public key
- βοΈ Digital Signatures: Verify sender authenticity
- π‘οΈ TLS Transport: Encrypted connections for real-time transports
- π Key Management: Automatic key generation and distribution
- πͺ Access Control: Domain-based and user-based permissions
9. Federation & Interoperability
// Your Synapse system automatically interoperates with:
// β’ Other Synapse systems
// β’ Standard email servers
// β’ Existing AI communication platforms
// β’ Legacy enterprise messaging systems
π Documentation
Core Concepts
- Complete Architecture: System architecture and design
- Transport Layer: Multi-transport architecture
- Security Model: Encryption and authentication
- Email Integration: SMTP/IMAP server capabilities
- Configuration: Setup and customization
API Reference
- Enhanced Router: Main interface
- Message Types: Communication patterns
- Streaming API: Real-time streaming support
- WebRTC Transport: Browser-based communication
- Trust System: Blockchain-based trust verification
Examples
- Basic Messaging: Simple send/receive
- AI Collaboration: Multi-agent scenarios
- File Transfer: Large data exchange
- Real-time Chat: Interactive communication
- Email Server: Server functionality
- Integration Test: System validation
π οΈ Use Cases
AI & Machine Learning
- Multi-agent AI systems coordinating in real-time
- AI-human collaboration with natural addressing
- Federated learning with secure model sharing
- Research collaboration between AI entities
Enterprise & Business
- Microservice communication with email-based service discovery
- Cross-organization messaging leveraging existing email infrastructure
- Reliable async processing with email-based queuing
- Legacy system integration through email gateways
IoT & Edge Computing
- Device-to-cloud communication using email when internet is limited
- Peer-to-peer IoT networks with automatic discovery
- Edge AI coordination across distributed deployments
- Resilient communication in unstable network conditions
π€ Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
git clone https://github.com/ai-dev-team/message-routing-system
cd message-routing-system
cargo build
cargo test
cargo run --example email_integration_test
Project Structure
src/
βββ lib.rs # Main library with overview
βββ types.rs # Core types and message definitions
βββ identity.rs # Name resolution and identity management
βββ router.rs # Basic message routing
βββ router_enhanced.rs # Multi-transport enhanced router
βββ email_server/ # SMTP/IMAP server implementation
βββ transport/ # Multi-transport layer
βββ crypto.rs # Encryption and signatures
βββ config.rs # Configuration management
examples/ # Comprehensive examples
docs/ # Detailed documentation
tests/ # Integration tests
οΏ½ Documentation and Resources
π Core Documentation
- Developer Guide - Comprehensive development guide with step-by-step tutorials
- API Reference - Complete API documentation with examples
- Configuration Guide - All configuration options and settings
- Troubleshooting Guide - Common issues and solutions
- New Features - Latest features and capabilities in v1.0.0
ποΈ Architecture and Design
- Complete Architecture - System architecture and design
- Deployment Guide - Production deployment instructions
- Advanced Monitoring - Monitoring and observability
- Security Audit - Security analysis and trust system
π§ͺ Specialized Features
- LLM Discovery Guide - AI agent discovery and communication
- Identity Resolution - Name resolution troubleshooting
- Unknown Name Handling - Handling unknown entities
- Circuit Breaker System - Fault tolerance patterns
- Blockchain Trust System - Trust verification system
- OAuth Authentication - Authentication integration
- WASM Support - WebAssembly and browser support
π Examples and Tutorials
- Examples Directory - Working examples for different use cases
- Hello World Example - Simplest Synapse application
- AI Assistant Example - Multi-AI agent communication
π§ Technical References
- Generated API Docs: Run
cargo doc --openfor complete API reference - Production Readiness Report - Production deployment guide
- Transport Status Report - Multi-transport implementation details
π Project Status
- Renaming Progress - Current renaming status and next steps
- New Features - Latest features and capabilities added in v1.0.0
- API Reference - Complete API documentation with examples
- Developer Guide - Development tutorials and best practices
οΏ½π License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
π Acknowledgments
Built with modern Rust async technology and inspired by the universal reach of email infrastructure. Special thanks to the email protocol designers who created the foundation that enables global communication.
"Making AI communication as universal as email, as fast as the internet allows, and as secure as modern cryptography enables."
Dependencies
~10β44MB
~653K SLoC