2020-11-29 20:22:40 +00:00
|
|
|
#![warn (clippy::pedantic)]
|
|
|
|
|
2020-11-02 03:34:50 +00:00
|
|
|
use std::{
|
2020-11-29 16:58:56 +00:00
|
|
|
convert::TryFrom,
|
2020-11-02 03:34:50 +00:00
|
|
|
error::Error,
|
2020-11-25 03:09:21 +00:00
|
|
|
path::PathBuf,
|
2020-11-02 18:39:19 +00:00
|
|
|
sync::Arc,
|
2020-11-02 03:34:50 +00:00
|
|
|
};
|
2020-10-30 22:53:03 +00:00
|
|
|
|
2020-12-16 14:57:47 +00:00
|
|
|
use clap::{App, SubCommand};
|
2020-11-06 23:43:52 +00:00
|
|
|
use tracing_subscriber::{
|
|
|
|
fmt,
|
|
|
|
fmt::format::FmtSpan,
|
|
|
|
EnvFilter,
|
|
|
|
};
|
2020-11-06 20:55:55 +00:00
|
|
|
|
2020-11-27 00:20:18 +00:00
|
|
|
use ptth_relay::{
|
2020-11-26 23:30:33 +00:00
|
|
|
Config,
|
2021-04-18 13:28:07 +00:00
|
|
|
Relay,
|
2020-11-27 00:20:18 +00:00
|
|
|
run_relay,
|
2020-11-26 23:30:33 +00:00
|
|
|
};
|
2020-11-02 18:39:19 +00:00
|
|
|
|
2020-10-30 22:53:03 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main () -> Result <(), Box <dyn Error>> {
|
2020-11-06 23:43:52 +00:00
|
|
|
fmt ()
|
|
|
|
.with_env_filter (EnvFilter::from_default_env ())
|
2020-12-20 23:34:55 +00:00
|
|
|
.with_span_events (FmtSpan::CLOSE)
|
2020-11-06 23:43:52 +00:00
|
|
|
.init ()
|
|
|
|
;
|
2020-11-06 20:55:55 +00:00
|
|
|
|
2020-12-16 14:57:47 +00:00
|
|
|
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 (());
|
|
|
|
}
|
|
|
|
|
2020-11-25 03:09:21 +00:00
|
|
|
let config_path = PathBuf::from ("config/ptth_relay.toml");
|
2022-12-16 15:57:38 +00:00
|
|
|
let mut config = Config::from_file (&config_path).await?;
|
|
|
|
config.webhook_url = std::env::var ("WEBHOOK_URL").ok ().or (config.webhook_url);
|
2022-12-16 15:30:38 +00:00
|
|
|
|
2020-11-27 00:03:11 +00:00
|
|
|
let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force ();
|
2020-11-07 02:29:45 +00:00
|
|
|
|
|
|
|
forced_shutdown.wrap_server (
|
2020-11-27 00:20:18 +00:00
|
|
|
run_relay (
|
2021-04-18 13:28:07 +00:00
|
|
|
Arc::new (Relay::try_from (config)?),
|
2021-04-18 01:50:48 +00:00
|
|
|
&PathBuf::new (),
|
2020-11-25 03:09:21 +00:00
|
|
|
shutdown_rx,
|
|
|
|
Some (config_path)
|
2020-11-07 02:29:45 +00:00
|
|
|
)
|
|
|
|
).await??;
|
|
|
|
|
|
|
|
Ok (())
|
2020-10-30 22:53:03 +00:00
|
|
|
}
|