Crate synapse

Source
Expand description

Β§Synapse: Neural Communi/// This means you can send messages using simple, human-readable names, and Synapseation Network

A revolutionary neural communication network for AI entities, distributed systems, and modern applications with federated identity management, dual trust systems, and privacy-respecting discovery.

§🌟 What Makes Synapse Special?

Synapse transforms how entities communicate by providing:

  • 🧠 Neural Identity: Contextual participant discovery with natural language
  • 🌍 Federated Network: Cross-organizational communication and trust
  • ⚑ Intelligent Routing: Multi-speed communication with smart transport selection
  • πŸ”’ Privacy First: Advanced privacy controls with stealth and unlisted modes
  • πŸ€– AI-Native: Designed for AI-to-AI and human-to-AI interaction
  • πŸ›οΈ Dual Trust: Entity-to-entity and blockchain-verified network trust
  • ⛓️ Blockchain Trust: Staking, verification, and decay mechanisms

§🎯 The Neural Identity System

One of Synapse’s most powerful features is its contextual identity system:

Simple Name β†’ Global ID β†’ Network Discovery β†’ Smart Transport Selection
 
"Alice" β†’ alice@ai-lab.example.com β†’ 192.168.1.100:8080 β†’ TCP (real-time)
"Claude" β†’ claude@anthropic.com β†’ [external] β†’ Email (reliable)
"LocalBot" β†’ bot@localhost β†’ 127.0.0.1:9090 β†’ UDP (fast local)

This means you can send messages using simple, human-readable names, and Synapse automatically figures out:

  • Where the recipient is located (email address, IP, domain)
  • How to reach them (direct connection, relay, email)
  • What transport to use (TCP for speed, email for reliability)
  • What security to apply (encryption level, authentication)

Β§πŸ—οΈ Architecture Overview

Synapse operates on multiple intelligent layers:

Β§Layer 1: Message Layer

  • Simple message types: Direct, Broadcast, Conversation, Notification
  • Automatic serialization and security wrapping
  • Metadata handling and routing information

Β§Layer 2: Identity Resolution

  • Local Names: "Alice", "Bob", "MyAI" (human-friendly)
  • Global IDs: "alice@company.com" (globally unique)
  • Network Addresses: IP addresses, ports, service endpoints
  • Capability Discovery: What transports and features each peer supports

Β§Layer 3: Multi-Transport Intelligence

  • Real-time Transports: TCP, UDP, WebSocket for <100ms messaging
  • Local Discovery: mDNS, LAN scanning, Bluetooth for peer finding
  • Email Backbone: SMTP/IMAP for reliable, federated communication
  • NAT Traversal: STUN/TURN/UPnP for firewall penetration

Β§Layer 4: Email Server Integration

  • Full Server Mode: Run your own SMTP/IMAP when externally accessible
  • Relay Mode: Outgoing only when behind firewall/NAT
  • External Provider: Fall back to Gmail, Outlook, etc. when restricted

Β§πŸš€ Quick Start Example

use message_routing_system::*;
 
#[tokio::main]
async fn main() -> Result<()> {
    // Initialize with your identity
    let config = Config::default();
    let router = EnhancedSynapseRouter::new(config, "MyBot@example.com".to_string()).await?;
     
    // Register some contacts (or use auto-discovery)
    router.register_peer("Alice", "alice@ai-lab.example.com").await?;
     
    // Start all services
    router.start().await?;
     
    // Send messages using simple names!
    router.send_message_smart(
        "Alice",                          // Just the name
        "Hello from Synapse!",           // Your message  
        MessageType::Direct,             // Type of communication
        SecurityLevel::Authenticated,    // Security level
        MessageUrgency::Interactive,     // Speed vs reliability preference
    ).await?;
     
    Ok(())
}

Β§πŸŽ›οΈ Advanced Features

Β§Automatic Transport Selection

Synapse intelligently chooses the best transport based on:

  • Message urgency: Real-time vs. reliable delivery
  • Network conditions: Latency, bandwidth, connectivity
  • Security requirements: Encryption levels, authentication
  • Peer capabilities: What transports the recipient supports
// Real-time collaboration (prefers TCP/UDP)
router.send_message_smart(
    "AI-Partner", 
    "Quick question about the algorithm...",
    MessageType::Conversation,
    SecurityLevel::Public,
    MessageUrgency::RealTime,  // <100ms preferred
).await?;

// Reliable file sharing (uses email for guaranteed delivery)
router.send_file_with_urgency(
    "ResearchTeam",
    "important_results.pdf", 
    MessageUrgency::Background,  // Reliability over speed
).await?;

Β§Email Server Capabilities

When your system is externally accessible, EMRP can run a full email server:

let router = EnhancedSynapseRouter::new(config, "bot@mydomain.com".to_string()).await?;
 
if router.is_running_email_server() {
    // You can receive emails directly at bot@mydomain.com
    // Other EMRP systems can send messages to your domain
    // Supports both EMRP messages and standard emails
    println!("πŸƒ Running full email infrastructure");
} else {
    // Falls back to external providers (Gmail, etc.)
    println!("🌐 Using external email services");
}

Β§Security by Design

All messages are automatically secured:

  • πŸ” PGP Encryption: Messages encrypted with recipient’s public key
  • ✍️ Digital Signatures: Verify sender authenticity
  • πŸ›‘οΈ TLS Transport: Encrypted connections for real-time transports
  • πŸ”‘ Automatic Key Management: Keys generated and distributed automatically

Β§πŸ“š Module Overview

  • router_enhanced: Main interface - start here for most use cases
  • identity: Name resolution and identity management
  • transport: Multi-transport layer and intelligent routing
  • email_server: SMTP/IMAP server implementation
  • types: Core message types and data structures
  • crypto: Encryption, signatures, and key management
  • config: Configuration and setup

§🎯 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 worldwide

Β§Enterprise & Distributed Systems

  • Microservice communication with email-based service discovery
  • Cross-organization messaging leveraging existing email infrastructure
  • Reliable async processing with email-based job 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

Β§πŸ”§ Getting Started

  1. Add to Cargo.toml: message_routing_system = "0.1.0"
  2. See examples: cargo run --example email_integration_test
  3. Read the docs: Full API documentation and guides
  4. Join the community: Contribute and get support

The combination of email’s universal reach with modern real-time transports creates a communication system that’s both globally federated and performance-optimized - perfect for the AI-driven future.

Re-exportsΒ§

pub use crypto::CryptoManager;
pub use email::EmailTransport;
pub use transport::Transport;
pub use transport::TransportSelector;
pub use transport::HybridConnection;
pub use transport::TransportMetrics;
pub use transport::NatMethod;
pub use transport::providers::TransportProvider;
pub use transport::providers::ProductionTransportProvider;
pub use transport::providers::TestTransportProvider;
pub use transport::providers::MockTransport;
pub use config::Config;
pub use error::SynapseError;
pub use transport::TransportRoute;
pub use transport::abstraction::MessageUrgency;
pub use router::SynapseRouter;
pub use router_enhanced::EnhancedSynapseRouter;
pub use transport::router::MultiTransportRouter;
pub use synapse::SynapseNode;
pub use synapse::SynapseConfig;
pub use synapse::models::ParticipantProfile;
pub use synapse::models::EntityType;
pub use synapse::models::DiscoverabilityLevel;
pub use synapse::api;
pub use synapse::blockchain;
pub use synapse::models;
pub use synapse::services;
pub use synapse::storage;
pub use types::*;

ModulesΒ§

auth_integration
Synapse Authentication Integration
circuit_breaker
Circuit Breaker Infrastructure for Synapse
config
Configuration management for EMRP
connectivity
Network connectivity enhancements for EMRP
crypto
Cryptographic operations for EMRP
email
Email transport layer for EMRP
email_server
Synapse Email Server Implementation
error
Error types for the Synapse system
headers
Standard email headers for Synapse
identity
Identity Management and Name Resolution
monitoring
Enhanced Metrics and Monitoring System for Synapse
router
Main Synapse router implementation
router_enhanced
Enhanced Synapse Router - Your Gateway to Intelligent Communication
streaming
Real-time streaming support for EMRP
synapse
transport
Multi-transport layer for EMRP
types
Core Types and Message Structures for EMRP

MacrosΒ§

report_error

ConstantsΒ§

PROTOCOL_VERSION
Current protocol version

FunctionsΒ§

init_logging
Initialize the Synapse system with logging (not available on WASM)