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;
pub struct Configured(runtime_links::ConfiguredLinks);
impl Configured {
#[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
}
})
}
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()
}
pub fn finish(mut self) -> Result<(), ServerError> {
self.0.finish()
}
}
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)
}
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))
}
pub fn without_lys(
config: &ServerConfig,
services: &Arc<LiminalConnectionServices>,
) -> Result<(), ServerError> {
runtime_links::prepare(config, None, services).map(|_| ())
}