2022-03-10 20:52:34 +01:00
|
|
|
#![warn(unused_imports, unused_import_braces)]
|
2021-10-28 01:10:35 +02:00
|
|
|
#![warn(missing_debug_implementations)]
|
2021-12-06 21:53:42 +01:00
|
|
|
#![warn(missing_docs)]
|
|
|
|
#![warn(missing_crate_level_docs)]
|
2021-10-28 00:32:25 +02:00
|
|
|
|
2021-10-28 01:10:35 +02:00
|
|
|
//! Diflouroborane
|
|
|
|
//!
|
2022-03-08 16:41:38 +01:00
|
|
|
//! This is the capnp component of the FabAccess project.
|
2021-10-28 01:10:35 +02:00
|
|
|
//! The entry point of bffhd can be found in [bin/bffhd/main.rs](../bin/bffhd/main.rs)
|
2021-10-27 23:20:35 +02:00
|
|
|
|
2022-03-11 22:13:54 +01:00
|
|
|
pub mod config;
|
|
|
|
|
2021-10-28 01:10:35 +02:00
|
|
|
/// Internal Databases build on top of LMDB, a mmap()'ed B-tree DB optimized for reads
|
2021-10-27 23:20:35 +02:00
|
|
|
pub mod db;
|
2021-11-26 02:25:48 +01:00
|
|
|
|
2021-10-28 01:10:35 +02:00
|
|
|
/// Shared error type
|
2021-10-27 23:20:35 +02:00
|
|
|
pub mod error;
|
2021-11-26 02:25:48 +01:00
|
|
|
|
2021-11-26 21:01:43 +01:00
|
|
|
pub mod users;
|
2022-03-08 18:52:49 +01:00
|
|
|
pub mod authentication;
|
2022-03-10 20:52:34 +01:00
|
|
|
pub mod authorization;
|
2021-11-26 21:01:43 +01:00
|
|
|
|
2021-10-28 01:10:35 +02:00
|
|
|
/// Resources
|
2021-11-26 02:25:48 +01:00
|
|
|
pub mod resources;
|
|
|
|
|
2021-12-15 23:42:16 +01:00
|
|
|
pub mod actors;
|
|
|
|
|
|
|
|
pub mod initiators;
|
|
|
|
|
|
|
|
pub mod sensors;
|
|
|
|
|
2022-03-08 16:41:38 +01:00
|
|
|
pub mod capnp;
|
2021-11-26 21:01:43 +01:00
|
|
|
|
2022-03-11 22:13:54 +01:00
|
|
|
pub mod utils;
|
|
|
|
|
|
|
|
mod tls;
|
|
|
|
mod keylog;
|
|
|
|
mod logging;
|
2022-03-11 23:00:02 +01:00
|
|
|
mod audit;
|
2022-03-11 22:13:54 +01:00
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::BufReader;
|
|
|
|
use std::path::Path;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use anyhow::Context;
|
|
|
|
use futures_rustls::TlsAcceptor;
|
2022-03-11 22:43:50 +01:00
|
|
|
use futures_util::StreamExt;
|
2022-03-11 22:13:54 +01:00
|
|
|
use rustls::{Certificate, KeyLogFile, PrivateKey, ServerConfig};
|
|
|
|
use rustls::server::NoClientAuth;
|
|
|
|
use signal_hook::consts::signal::*;
|
|
|
|
use executor::pool::Executor;
|
|
|
|
use crate::capnp::APIServer;
|
|
|
|
use crate::config::{Config, TlsListen};
|
|
|
|
use crate::tls::TlsConfig;
|
|
|
|
|
|
|
|
pub struct Diflouroborane {
|
|
|
|
executor: Executor<'static>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Diflouroborane {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
let executor = Executor::new();
|
|
|
|
|
|
|
|
Self { executor }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn log_version_number(&self) {
|
|
|
|
const RELEASE_STRING: &'static str = env!("BFFHD_RELEASE_STRING");
|
|
|
|
tracing::info!(version=RELEASE_STRING, "Starting");
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn setup(&mut self, config: &Config) -> anyhow::Result<()> {
|
|
|
|
logging::init(&config);
|
|
|
|
|
|
|
|
let span = tracing::info_span!("setup");
|
|
|
|
let _guard = span.enter();
|
|
|
|
|
|
|
|
self.log_version_number();
|
|
|
|
|
2022-03-11 22:43:50 +01:00
|
|
|
let mut signals = signal_hook_async_std::Signals::new(&[
|
2022-03-11 22:13:54 +01:00
|
|
|
SIGINT,
|
|
|
|
SIGQUIT,
|
|
|
|
SIGTERM,
|
|
|
|
]).context("Failed to construct signal handler")?;
|
|
|
|
|
|
|
|
let tlsconfig = TlsConfig::new(config.tlskeylog.as_ref(), !config.is_quiet())?;
|
|
|
|
let acceptor = tlsconfig.make_tls_acceptor(&config.tlsconfig)?;
|
|
|
|
|
2022-03-11 22:43:50 +01:00
|
|
|
let mut apiserver = self.executor.run(APIServer::bind(self.executor.clone(), &config.listens, acceptor))?;
|
2022-03-11 22:13:54 +01:00
|
|
|
|
2022-03-11 22:43:50 +01:00
|
|
|
let (mut tx, rx) = async_oneshot::oneshot();
|
|
|
|
|
|
|
|
self.executor.spawn(apiserver.handle_until(rx));
|
|
|
|
|
|
|
|
let f = async {
|
|
|
|
let mut sig = None;
|
|
|
|
while {
|
|
|
|
sig = signals.next().await;
|
|
|
|
sig.is_none()
|
|
|
|
} {}
|
|
|
|
tracing::info!(signal = %sig.unwrap(), "Received signal");
|
|
|
|
tx.send(());
|
|
|
|
};
|
|
|
|
|
|
|
|
self.executor.run(f);
|
2022-03-11 22:13:54 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|