#![warn (clippy::pedantic)] use std::{ convert::TryFrom, error::Error, path::PathBuf, sync::Arc, }; use clap::{App, SubCommand}; use tracing::{info}; use tracing_subscriber::{ fmt, fmt::format::FmtSpan, EnvFilter, }; use ptth_relay::{ Config, git_version::read_git_version, RelayState, run_relay, }; #[tokio::main] async fn main () -> Result <(), Box > { fmt () .with_env_filter (EnvFilter::from_default_env ()) .with_span_events (FmtSpan::CLOSE) .init () ; let matches = App::new ("ptth_relay") .author ("Trish") .about ("Relay server for the PTTH backwards HTTP server") .subcommand (SubCommand::with_name ("hash-api-key")) .get_matches (); if matches.subcommand_matches ("hash-api-key").is_some () { use std::io; use ptth_relay::key_validity::BlakeHashWrapper; println! ("Enter key (it will be visible in the terminal)"); let mut key = String::new (); io::stdin ().read_line (&mut key)?; println! ("{}", BlakeHashWrapper::from_key (key.trim_end ().as_bytes ()).encode_base64 ()); return Ok (()); } let config_path = PathBuf::from ("config/ptth_relay.toml"); let config = Config::from_file (&config_path).await?; if let Some (x) = read_git_version ().await { info! ("ptth_relay Git version: {:?}", x); } else { info! ("ptth_relay not built from Git"); } let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force (); forced_shutdown.wrap_server ( run_relay ( Arc::new (RelayState::try_from (config)?), Arc::new (ptth_relay::load_templates (&PathBuf::new ())?), shutdown_rx, Some (config_path) ) ).await??; Ok (()) }