BusServer

Struct BusServer 

Source
pub struct BusServer { /* private fields */ }
Expand description

The IPC bus server.

Implementations§

Source§

impl BusServer

Source

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.

Source

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.

Source

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).

Source

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).

Source

pub async fn unregister(&self, daemon_id: &DaemonId)

Remove a subscriber by daemon ID.

Source

pub async fn publish(&self, frame: &[u8], security_level: SecurityLevel)

Publish an already-encoded frame to all matching subscribers.

Source

pub fn epoch(&self) -> Instant

Return the server’s monotonic epoch for timestamp generation.

Source

pub fn socket_path(&self) -> Option<&Path>

Return the socket path if bound.

Source

pub async fn connection_count(&self) -> usize

Return the number of active connections.

Source

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.

Source

pub async fn registry_mut(&self) -> RwLockWriteGuard<'_, ClearanceRegistry>

Access the clearance registry for mutation (key rotation, revocation).

Source

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.

Source

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).

Source

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.

Trait Implementations§

Source§

impl Default for BusServer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for BusServer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more