Expand description
Β§Core Types and Message Structures for EMRP
This module defines all the fundamental data types used throughout the Email-Based Message Routing Protocol. Understanding these types is essential for working with EMRP messages, identities, and configurations.
Β§ποΈ Message Architecture
EMRP uses a layered message architecture designed for flexibility and security:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SimpleMessage β
β Human-readable, easy to work with β
β β’ to: "Alice" β
β β’ from_entity: "Claude" β
β β’ content: "Hello!" β
β β’ message_type: Direct β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β (automatic conversion)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SecureMessage β
β Network-ready with security and routing β
β β’ message_id: uuid β
β β’ to_global_id: "alice@ai-lab.example.com" β
β β’ from_global_id: "claude@anthropic.com" β
β β’ encrypted_content: [encrypted bytes] β
β β’ signature: [digital signature] β
β β’ security_level: Authenticated β
β β’ routing_path: [hop1, hop2, ...] β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Β§π― Entity Types - Whoβs Who in EMRP
EMRP supports different types of communicating entities:
Β§Human
- Purpose: Represents actual human users
- Examples: Researchers, developers, end users
- Capabilities: Typically uses client applications, email interfaces
- Security: Usually requires authentication, may have elevated privileges
Β§AiModel
- Purpose: AI systems, language models, intelligent agents
- Examples: Claude, GPT-4, local AI assistants, specialized ML models
- Capabilities: Automated responses, real-time communication, batch processing
- Security: May have special encryption requirements, rate limiting
Β§Tool
- Purpose: Utility services and specialized tools
- Examples: Image generators, code analyzers, data processors
- Capabilities: Function-specific, often stateless, API-driven
- Security: Often public or semi-public access
Β§Service
- Purpose: Infrastructure and platform services
- Examples: Databases, authentication servers, load balancers
- Capabilities: High reliability, scalability, enterprise features
- Security: Strong authentication, audit logging, access controls
Β§Router
- Purpose: EMRP routing infrastructure
- Examples: Email servers, message relays, protocol gateways
- Capabilities: Message forwarding, protocol translation, caching
- Security: Trusted infrastructure, certificate-based authentication
Β§π Message Types - Communication Patterns
Different message types enable different communication patterns:
Β§Direct
// One-to-one private communication
SimpleMessage {
to: "Alice".to_string(),
from_entity: "Claude".to_string(),
content: "Can you help me with this analysis?".to_string(),
message_type: MessageType::Direct,
metadata: HashMap::new(),
}
- Use Case: Private conversations, specific requests
- Routing: Point-to-point, highest priority
- Security: End-to-end encryption by default
Β§Broadcast
// One-to-many public announcements
SimpleMessage {
to: "AllTeamMembers".to_string(),
from_entity: "ProjectManager".to_string(),
content: "Weekly meeting at 3pm today".to_string(),
message_type: MessageType::Broadcast,
metadata: [("priority", "high")].into(),
}
- Use Case: Announcements, status updates, alerts
- Routing: Fan-out to all subscribers
- Security: Usually public or group-encrypted
Β§Conversation
// Multi-party ongoing discussion
SimpleMessage {
to: "ResearchGroup".to_string(),
from_entity: "Alice".to_string(),
content: "I think we should try a different approach".to_string(),
message_type: MessageType::Conversation,
metadata: [("thread_id", "quantum-research-2024")].into(),
}
- Use Case: Group discussions, collaborative work
- Routing: All participants receive message
- Security: Group-encrypted, shared access
Β§Notification
// System-generated alerts and updates
SimpleMessage {
to: "DevOpsTeam".to_string(),
from_entity: "MonitoringSystem".to_string(),
content: "Server CPU usage exceeded 90% threshold".to_string(),
message_type: MessageType::Notification,
metadata: [
("severity", "warning"),
("server", "web-01.prod"),
("metric", "cpu_usage"),
("value", "92.3")
].into(),
}
- Use Case: Automated alerts, system status, monitoring
- Routing: Priority-based, may have special handling
- Security: Often authenticated but not necessarily encrypted
Β§π Security Levels - Protection Gradients
EMRP provides multiple security levels to balance protection with performance:
Β§Public
- Protection: Minimal - no encryption, optional signatures
- Use Case: Public announcements, status updates, discovery messages
- Performance: Fastest - no crypto overhead
- Example: βBot online and ready for requestsβ
Β§Authenticated
- Protection: Sender verification via digital signatures
- Use Case: Trusted communications where identity matters
- Performance: Fast - only signature overhead
- Example: βCommand acknowledged, processing request #1234β
Β§Encrypted
- Protection: Content encrypted with recipientβs public key
- Use Case: Sensitive information, private conversations
- Performance: Moderate - encryption overhead
- Example: βAPI key for service X is: sk_abc123β¦β
Β§Confidential
- Protection: Encryption + signature + additional metadata protection
- Use Case: Highly sensitive data, regulatory compliance
- Performance: Slower - maximum security overhead
- Example: Personal data, financial information, trade secrets
Β§π Global Identity Structure
Every entity in EMRP has a structured global identity:
GlobalIdentity {
local_name: "Alice".to_string(), // Human-friendly name
global_id: "alice@ai-lab.example.com".to_string(), // Globally unique
entity_type: EntityType::AiModel, // What kind of entity
capabilities: vec![ // What it can do
"real-time-messaging".to_string(),
"file-transfer".to_string(),
"voice-calls".to_string(),
],
public_key: Some(public_key_bytes), // For encryption
display_name: Some("Alice AI Researcher".to_string()), // Pretty name
created_at: Utc::now(), // When registered
}
Β§Identity Resolution Chain
"Alice" β alice@ai-lab.example.com β 192.168.1.100:8080 β [TCP, UDP, Email]
β β β β
Local Global ID Network Address Capabilities
Name (DNS-based) (Dynamic Discovery) (Feature Detection)
Β§π§ Email Configuration
EMRP seamlessly integrates with email infrastructure:
EmailConfig {
smtp: SmtpConfig {
host: "smtp.gmail.com".to_string(),
port: 587,
username: "mybot@gmail.com".to_string(),
password: "app_password".to_string(),
use_tls: true, // Modern security
use_ssl: false, // Legacy security
},
imap: ImapConfig {
host: "imap.gmail.com".to_string(),
port: 993,
username: "mybot@gmail.com".to_string(),
password: "app_password".to_string(),
use_ssl: true, // Secure IMAP
},
}
Β§ποΈ Message Metadata - Extensible Information
All messages can carry arbitrary metadata for extended functionality:
// Example: AI collaboration metadata
let mut metadata = HashMap::new();
metadata.insert("conversation_id".to_string(), "research-session-001".to_string());
metadata.insert("model_version".to_string(), "claude-3.5".to_string());
metadata.insert("temperature".to_string(), "0.7".to_string());
metadata.insert("context_window".to_string(), "200k".to_string());
// Example: File transfer metadata
metadata.insert("file_name".to_string(), "research_data.zip".to_string());
metadata.insert("file_size".to_string(), "15728640".to_string()); // 15MB
metadata.insert("file_hash".to_string(), "sha256:abc123...".to_string());
metadata.insert("compression".to_string(), "gzip".to_string());
// Example: Real-time communication metadata
metadata.insert("urgency".to_string(), "real-time".to_string());
metadata.insert("timeout_ms".to_string(), "5000".to_string());
metadata.insert("retry_count".to_string(), "3".to_string());
metadata.insert("preferred_transport".to_string(), "tcp".to_string());
Β§π Message Lifecycle
Understanding how messages flow through EMRP:
1. Creation
SimpleMessage β user creates with simple fields
2. Identity Resolution
"Alice" β alice@ai-lab.example.com (local name to global ID)
3. Security Processing
SimpleMessage β SecureMessage (encryption, signing)
4. Transport Selection
Network discovery β choose TCP/UDP/Email based on urgency
5. Delivery
Send via chosen transport with automatic retry/fallback
6. Receipt Processing
Decrypt, verify, route to application handler
This type system provides the foundation for EMRPβs flexibility while maintaining strong typing and security throughout the communication process.
StructsΒ§
- Email
Config - Configuration for email providers
- Global
Identity - Global identity for an entity in the network
- Imap
Config - IMAP server configuration
- Secure
Message - Secure message for network transport
- Simple
Message - The simple message format that users interact with
- Smtp
Config - SMTP server configuration
- Stream
Chunk - A chunk of streaming data
- Stream
Metadata - Metadata for a streaming session
EnumsΒ§
- Entity
Type - Types of entities in the global network
- Message
Type - Types of messages in the protocol
- Security
Level - Security levels for different message types
- Stream
Priority - Stream priority levels
- Stream
Type - Types of streaming scenarios