liminal-server 0.23.1

Standalone server for the liminal messaging bus
Documentation
use super::{Arc, ConnectionControl, ConnectionSupervisor, ServerError};

impl ConnectionSupervisor {
    /// Installs the services registry (SRV-028), once: lifecycle requests
    /// are served from it and its processes' credentials admitted.
    ///
    /// # Errors
    /// [`ServerError::ConfigValidation`] when one is already installed.
    pub fn install_lifecycle(
        &self,
        lifecycle: Arc<crate::services::lifecycle::Lifecycle>,
    ) -> Result<(), ServerError> {
        self.inner
            .runtime
            .lifecycle
            .set(lifecycle)
            .map_err(|_| ServerError::ConfigValidation {
                message: "a services registry was already installed".to_owned(),
            })
    }

    /// Installs the grant-revocation policy (ACCESS-005), once, before the
    /// first connection. From then on every `Connect` must present a pass
    /// whose grant-decision binding the authority admits and must negotiate
    /// the reason-bearing close; a bearer or open-access `Connect` is refused
    /// `revocation_binding_missing`.
    ///
    /// # Errors
    /// [`ServerError::ConfigValidation`] when an authority is already
    /// installed.
    pub fn install_revocation(
        &self,
        authority: Arc<crate::auth_revocation::RevocationAuthority>,
    ) -> Result<(), ServerError> {
        self.inner
            .runtime
            .install_revocation(authority)
            .map_err(|_| ServerError::ConfigValidation {
                message: "a grant-revocation authority was already installed".to_owned(),
            })
    }

    /// Applies one event of the Lys grant-change stream the caller owns and
    /// reads (ACCESS-005 R2, R4), then tells each affected connection once.
    /// The denied state is in force before any connection is told; when a
    /// connection's control cannot be published the refusal is counted by
    /// name and the connection's own ready wake delivers the sweep. Nothing
    /// is retried on a timer.
    ///
    /// # Errors
    /// [`ServerError::ConfigValidation`] when no authority is installed.
    pub fn apply_grant_event(
        &self,
        event: &crate::auth_revocation::GrantFeedEvent,
    ) -> Result<crate::auth_revocation::ApplyOutcome, ServerError> {
        let Some(authority) = self.inner.runtime.revocation() else {
            return Err(ServerError::ConfigValidation {
                message: "no grant-revocation authority is installed".to_owned(),
            });
        };
        let outcome = authority.apply(event);
        let mut told = std::collections::BTreeSet::new();
        for effect in &outcome.effects {
            let pid = effect.pid();
            if !told.insert(pid) {
                continue;
            }
            if !self
                .inner
                .enqueue_control(pid, ConnectionControl::Revocation)
            {
                authority.record_close_publication_refused(pid);
                let woken = self
                    .inner
                    .runtime
                    .ready_waker(pid)
                    .as_ref()
                    .is_some_and(super::wake::ReadyWaker::fire);
                tracing::warn!(
                    connection_pid = pid,
                    woken,
                    "revocation control refused; the connection's ready wake carries the sweep"
                );
            }
        }
        Ok(outcome)
    }
}