2023-05-24 06:19:15 +00:00
|
|
|
use std::process::ExitCode;
|
|
|
|
|
2023-05-24 04:23:36 +00:00
|
|
|
use config::Node;
|
2023-05-24 06:19:15 +00:00
|
|
|
use log::debug;
|
2023-05-23 02:49:37 +00:00
|
|
|
|
2023-05-24 04:23:36 +00:00
|
|
|
use crate::config::Config;
|
2023-05-23 02:49:37 +00:00
|
|
|
use crate::supervisor::run_tasks;
|
|
|
|
|
|
|
|
mod supervisor;
|
|
|
|
mod linkmap;
|
2023-05-24 04:23:36 +00:00
|
|
|
mod config;
|
2023-05-23 02:49:37 +00:00
|
|
|
|
2023-05-24 04:23:36 +00:00
|
|
|
#[cfg(feature="irc")]
|
2023-05-23 02:49:37 +00:00
|
|
|
mod bridge_irc;
|
2023-06-11 02:35:48 +00:00
|
|
|
#[cfg(feature="irc-sp")]
|
|
|
|
mod bridge_irc_sp;
|
2023-05-24 04:23:36 +00:00
|
|
|
#[cfg(feature="matrix")]
|
2023-05-23 02:49:37 +00:00
|
|
|
mod bridge_matrix;
|
2023-05-24 04:23:36 +00:00
|
|
|
#[cfg(feature="discord")]
|
|
|
|
mod bridge_discord;
|
2023-05-23 02:49:37 +00:00
|
|
|
|
2023-05-24 06:19:15 +00:00
|
|
|
#[cfg(any(
|
|
|
|
not(any(feature="tls-rustls", feature="tls-native")),
|
|
|
|
all(feature="tls-rustls", feature="tls-native"),
|
|
|
|
))]
|
|
|
|
compile_error!(r#"exactly one of "tls-rustls" or "tls-native" must be enabled."#);
|
|
|
|
|
2023-05-23 02:49:37 +00:00
|
|
|
#[tokio::main]
|
2023-05-24 06:19:15 +00:00
|
|
|
async fn main() -> ExitCode {
|
2023-05-23 02:49:37 +00:00
|
|
|
env_logger::init();
|
|
|
|
|
2023-05-24 06:19:15 +00:00
|
|
|
debug!("reading arguments");
|
|
|
|
let mut args = std::env::args();
|
|
|
|
let cmd_name = args.next()
|
|
|
|
.unwrap_or_else(|| env!("CARGO_PKG_NAME").to_owned());
|
|
|
|
|
2023-05-25 21:38:17 +00:00
|
|
|
let Some(conf_filename) = args.next() else {
|
|
|
|
eprintln!("Usage: {cmd_name} <config>");
|
|
|
|
return ExitCode::FAILURE
|
2023-05-24 06:19:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
debug!("reading config file");
|
|
|
|
let conf_str = match std::fs::read_to_string(&conf_filename) {
|
|
|
|
Ok(s) => s,
|
|
|
|
Err(e) => {
|
|
|
|
eprintln!("Failed to read {conf_filename}: {e}");
|
|
|
|
return ExitCode::FAILURE
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
debug!("parsing config");
|
2023-05-24 04:23:36 +00:00
|
|
|
let config: Config = match toml::from_str(&conf_str) {
|
|
|
|
Ok(c) => c,
|
|
|
|
Err(e) => {
|
2023-05-24 06:19:15 +00:00
|
|
|
eprintln!("{e}");
|
|
|
|
return ExitCode::SUCCESS
|
2023-05-24 04:23:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let tasks = config.nodes.into_iter()
|
|
|
|
.map(|(k, t)| (k, Node::into_task(t)))
|
|
|
|
.collect();
|
|
|
|
|
2023-05-24 06:19:15 +00:00
|
|
|
debug!("running tasks");
|
2023-05-23 02:49:37 +00:00
|
|
|
run_tasks(tasks).await;
|
2023-05-24 06:19:15 +00:00
|
|
|
ExitCode::SUCCESS
|
2023-05-23 02:49:37 +00:00
|
|
|
}
|