Expand description
Router federation for CLASP
This crate enables CLASP routers to connect to each other and share state across network boundaries. Federation links appear as normal client sessions, using the standard CLASP protocol for communication.
§Architecture
Federation works by:
- Each router declares its owned namespace patterns (e.g.,
/site-a/**) - Routers connect to each other and exchange namespace declarations
- Messages matching a peer’s namespace are forwarded via the federation link
- Loop prevention uses an
originfield – messages are never forwarded back to the router they came from
§Modes
- Hub: Central router that accepts leaf connections (star topology)
- Leaf: Edge router that connects to a single hub
- Mesh: Peer-to-peer connections between multiple routers
§Example
use clasp_federation::{FederationManager, FederationConfig, FederationMode};
let config = FederationConfig {
mode: FederationMode::Leaf {
hub_endpoint: "wss://hub.example.com:7330".to_string(),
},
router_id: "site-a".to_string(),
owned_namespaces: vec!["/site-a/**".to_string()],
..Default::default()
};
let manager = FederationManager::new(config);
// Create links for each peer connection...Re-exports§
pub use config::FederationConfig;pub use config::FederationMode;pub use config::PeerInfo;pub use config::PeerState;pub use error::FederationError;pub use error::Result;pub use link::FederationLink;pub use link::LinkEvent;pub use manager::FederationManager;pub use namespace::NamespaceManager;