liminal-server 0.25.4

Standalone server for the liminal messaging bus
Documentation
//! Fixtures enter the configured production bridge start after binding their listeners.
use super as runtime_links;
use crate::ServerError;
use crate::auth_lys::session::LysAdmitter;
use crate::config::ServerConfig;
use crate::link::LinkHost;
use crate::link_bridge::BridgeRegistry;
use crate::server::connection::services::LiminalConnectionServices;
use crate::server::connection::{ConnectionSupervisor, LysInstall};
use crate::services::production::ServiceBindings;
use std::sync::Arc;

/// Owns the configured bridges started by the production path.
pub struct Configured(runtime_links::ConfiguredLinks);
impl Configured {
    /// Observes settled importing answers on the configured bridges.
    #[must_use]
    pub fn observe_answers(&self, count: u64, bound: std::time::Duration) -> bool {
        self.0
            .retry
            .as_ref()
            .is_some_and(|retry| match retry.observe_answers(count, bound) {
                Ok(observed) => observed,
                Err(error) => {
                    tracing::error!(%error, "configured answer observation failed");
                    false
                }
            })
    }
    /// Stops only the first configured bridge.
    /// # Errors
    /// No bridge exists or that bridge failed to stop.
    pub fn finish_first(&self) -> Result<(), ServerError> {
        self.0
            .retry
            .as_ref()
            .ok_or_else(|| crate::ServerError::ListenerAccept {
                message: "configured bridge absent".to_owned(),
            })?
            .finish_first()
    }
    /// Stops all configured bridges before their services are torn down.
    /// # Errors
    /// Any bridge failed to settle or stop.
    pub fn finish(mut self) -> Result<(), ServerError> {
        self.0.finish()
    }
}
/// Installs the fixture's authority through the production supervisor constructor.
/// # Errors
/// Supervisor startup or observation installation failed.
pub fn supervisor(
    config: &ServerConfig,
    services: Arc<LiminalConnectionServices>,
    host: Arc<LinkHost>,
    admitter: Arc<dyn LysAdmitter>,
    bindings: Option<Arc<ServiceBindings>>,
) -> Result<ConnectionSupervisor, ServerError> {
    let observations = Arc::clone(&services);
    let supervisor = ConnectionSupervisor::with_lys_and_fatal_shutdown(
        services,
        None,
        None,
        Some(LysInstall {
            admitter,
            network_id: "network-a".to_owned(),
            link_host: Some(host),
            services: bindings,
            membership: None,
        }),
        config.limits,
        crate::server::ShutdownHandle::new(),
    )?;
    supervisor.install_link_observations_for_tests(&observations)?;
    Ok(supervisor)
}
/// Runs the same prepare and start used after production listeners bind.
/// # Errors
/// The configured carrier or bridge refused to start.
pub fn start(
    config: &ServerConfig,
    services: &Arc<LiminalConnectionServices>,
    host: Arc<LinkHost>,
    admitter: Arc<dyn LysAdmitter>,
    supervisor: &ConnectionSupervisor,
    registry: &BridgeRegistry,
) -> Result<Configured, ServerError> {
    let install = LysInstall {
        admitter,
        network_id: "network-a".to_owned(),
        link_host: Some(host),
        services: None,
        membership: None,
    };
    let mut links = runtime_links::prepare(config, Some(&install), services)?;
    links.start(registry, supervisor)?;
    Ok(Configured(links))
}

/// Runs production preparation without an installed authority.
/// # Errors
/// Configured links require an installed Lys.
pub fn without_lys(
    config: &ServerConfig,
    services: &Arc<LiminalConnectionServices>,
) -> Result<(), ServerError> {
    runtime_links::prepare(config, None, services).map(|_| ())
}