pub struct BusServer { /* private fields */ }Expand description
The IPC bus server.
Implementations§
Source§impl BusServer
impl BusServer
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new bus server without a listener (for in-process channel wiring).
Used only for register()/unregister() based in-process testing where
clients are pre-wired via channels rather than socket connections.
Does NOT support socket accept — use bind() for socket-based servers.
Sourcepub fn bind(
path: &Path,
keypair: Keypair,
registry: ClearanceRegistry,
) -> Result<Self>
pub fn bind( path: &Path, keypair: Keypair, registry: ClearanceRegistry, ) -> Result<Self>
Bind a Unix domain socket listener at the given path.
The keypair is the server’s Noise IK static keypair (mandatory),
used to perform encrypted handshakes with connecting clients. Generated
via crate::generate_keypair() and published via
crate::noise::write_bus_keypair().
Creates the parent directory if it does not exist. Removes any stale socket file at the path before binding.
§Errors
Returns an error if directory creation or socket binding fails.
Sourcepub async fn run(&self) -> Result<()>
pub async fn run(&self) -> Result<()>
Run the accept loop. This future never completes unless the listener
encounters a fatal error. Cancel it via tokio::select! with a
shutdown signal.
§Errors
Returns an error if no listener was bound (created via new() instead
of bind()).
§Panics
Panics if called on a BusServer created via bind() whose keypair
was somehow removed (should be unreachable).
Sourcepub async fn register(
&self,
daemon_id: DaemonId,
peer: PeerCredentials,
security_clearance: SecurityLevel,
subscriptions: Vec<SubscriptionFilter>,
tx: Sender<Vec<u8>>,
)
pub async fn register( &self, daemon_id: DaemonId, peer: PeerCredentials, security_clearance: SecurityLevel, subscriptions: Vec<SubscriptionFilter>, tx: Sender<Vec<u8>>, )
Register a subscriber with pre-wired channels (for in-process testing).
Sourcepub async fn unregister(&self, daemon_id: &DaemonId)
pub async fn unregister(&self, daemon_id: &DaemonId)
Remove a subscriber by daemon ID.
Sourcepub async fn publish(&self, frame: &[u8], security_level: SecurityLevel)
pub async fn publish(&self, frame: &[u8], security_level: SecurityLevel)
Publish an already-encoded frame to all matching subscribers.
Sourcepub fn socket_path(&self) -> Option<&Path>
pub fn socket_path(&self) -> Option<&Path>
Return the socket path if bound.
Sourcepub async fn connection_count(&self) -> usize
pub async fn connection_count(&self) -> usize
Return the number of active connections.
Sourcepub async fn send_to(&self, conn_id: u64, frame: &[u8]) -> bool
pub async fn send_to(&self, conn_id: u64, frame: &[u8]) -> bool
Send a frame to a specific connection by ID (unicast).
Returns true if the frame was enqueued, false if the connection
was not found or its channel was full.
Sourcepub async fn registry_mut(&self) -> RwLockWriteGuard<'_, ClearanceRegistry>
pub async fn registry_mut(&self) -> RwLockWriteGuard<'_, ClearanceRegistry>
Access the clearance registry for mutation (key rotation, revocation).
Sourcepub async fn take_pending_request(&self, correlation_id: &Uuid) -> Option<u64>
pub async fn take_pending_request(&self, correlation_id: &Uuid) -> Option<u64>
Look up and remove the originating connection for a correlated response.
When a request arrives via route_frame(), the server records
(msg_id -> sender_conn_id) in pending_requests. This method
retrieves and removes that mapping so the response can be unicast
back to the original requester instead of broadcast.
Sourcepub async fn register_confirmation(
&self,
correlation_id: Uuid,
confirm_tx: Sender<Vec<u8>>,
) -> ConfirmationGuard
pub async fn register_confirmation( &self, correlation_id: Uuid, confirm_tx: Sender<Vec<u8>>, ) -> ConfirmationGuard
Register a confirmation route for confirmed RPC.
When a response with matching correlation_id arrives at route_frame(),
the raw frame is sent to confirm_tx instead of the normal host delivery path.
Returns a ConfirmationGuard that deregisters the route on drop (RAII cleanup).
Sourcepub async fn send_to_named(
&self,
daemon_name: &str,
frame: &[u8],
) -> Result<(), String>
pub async fn send_to_named( &self, daemon_name: &str, frame: &[u8], ) -> Result<(), String>
Send a frame to a named daemon via O(1) lookup.
Resolves daemon_name to a connection ID via name_to_conn, then delegates
to send_to(). Returns Ok(()) on success, Err if the daemon is not
connected or the channel is full.
§Errors
Returns an error string if the daemon is not in name_to_conn (not connected)
or if the connection’s outbound channel is full/closed.