Skip to main content

Crate clasp_federation

Crate clasp_federation 

Source
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:

  1. Each router declares its owned namespace patterns (e.g., /site-a/**)
  2. Routers connect to each other and exchange namespace declarations
  3. Messages matching a peer’s namespace are forwarded via the federation link
  4. Loop prevention uses an origin field – 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::LinkEvent;
pub use manager::FederationManager;
pub use namespace::NamespaceManager;

Modules§

config
Federation configuration types
error
Federation error types
link
Federation link – manages a connection to a peer router
manager
Federation manager – orchestrates federation links
namespace
Namespace management for federation