Files
hakorune/src/transport/mod.rs
Moe Charm 2fc6ce3aa6 feat: Unified registry and major code cleanup by ChatGPT5
- Unified Box Registry: Replaced 600+ line match statement with clean factory pattern
- Code cleanup: Removed unused imports, variables, and dead code
- Import fixes: Fixed RangeBox, NullBox, MapBox imports
- Transport Debug: Added Debug trait implementation for Transport interface
- WASM build: Successfully tested with wasm_playground preset ready for integration
- Performance: Build time stable, WASM package generated successfully (1.89MB)

This commit represents a major architectural improvement with the unified registry
system now fully operational, reducing code duplication and improving maintainability.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-21 14:28:24 +09:00

54 lines
1.5 KiB
Rust

/*! 🚀 Transport Module - Communication Layer Abstraction
*
* This module defines the Transport trait and implementations for different
* communication methods (InProcess, WebSocket, WebRTC, etc.)
*/
pub mod inprocess;
use crate::boxes::IntentBox;
/// Envelope containing message with metadata
#[derive(Debug, Clone)]
pub struct IntentEnvelope {
pub from: String,
pub to: String,
pub intent: IntentBox,
pub timestamp: std::time::Instant,
}
/// Options for sending messages
#[derive(Debug, Clone, Default)]
pub struct SendOpts {
pub timeout_ms: Option<u64>,
pub priority: Option<u8>,
}
/// Transport errors
#[derive(Debug, Clone)]
pub enum TransportError {
NodeNotFound(String),
NetworkError(String),
Timeout(String),
SerializationError(String),
}
/// Abstract transport trait for different communication methods
pub trait Transport: Send + Sync + std::fmt::Debug {
/// Get the node ID of this transport
fn node_id(&self) -> &str;
/// Send a message to a specific node
fn send(&self, to: &str, intent: IntentBox, opts: SendOpts) -> Result<(), TransportError>;
/// Register a callback for receiving messages
fn on_receive(&mut self, callback: Box<dyn Fn(IntentEnvelope) + Send + Sync>);
/// Check if a node is reachable
fn is_reachable(&self, node_id: &str) -> bool;
/// Get transport type identifier
fn transport_type(&self) -> &'static str;
}
pub use inprocess::InProcessTransport;