2020-11-02 03:34:50 +00:00
|
|
|
use std::{
|
|
|
|
error::Error,
|
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-11-02 18:39:19 +00:00
|
|
|
use tokio::sync::oneshot;
|
|
|
|
|
2020-11-06 04:18:47 +00:00
|
|
|
mod load_toml;
|
|
|
|
|
2020-11-02 18:39:19 +00:00
|
|
|
use ptth::relay;
|
|
|
|
use ptth::relay::RelayState;
|
|
|
|
|
2020-10-30 22:53:03 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main () -> Result <(), Box <dyn Error>> {
|
2020-11-06 04:18:47 +00:00
|
|
|
let config_file = load_toml::load ("config/ptth_relay.toml");
|
2020-11-02 03:34:50 +00:00
|
|
|
|
2020-11-02 18:07:34 +00:00
|
|
|
eprintln! ("ptth_relay Git version: {:?}", ptth::git_version::GIT_VERSION);
|
|
|
|
|
2020-11-02 18:39:19 +00:00
|
|
|
let rx = {
|
|
|
|
let (tx, rx) = oneshot::channel::<()> ();
|
|
|
|
|
|
|
|
// I have to put the tx into a Cell here so that if Ctrl-C gets
|
|
|
|
// called multiple times, we won't send multiple shutdowns to the
|
|
|
|
// oneshot channel. (Which would be a compile error)
|
|
|
|
|
|
|
|
let tx = Some (tx);
|
|
|
|
let tx = std::cell::Cell::new (tx);
|
|
|
|
|
|
|
|
ctrlc::set_handler (move ||{
|
|
|
|
let tx = tx.replace (None);
|
|
|
|
|
|
|
|
if let Some (tx) = tx {
|
|
|
|
tx.send (()).unwrap ();
|
|
|
|
}
|
|
|
|
}).expect ("Error setting Ctrl-C handler");
|
|
|
|
|
|
|
|
rx
|
|
|
|
};
|
|
|
|
|
|
|
|
relay::run_relay (
|
|
|
|
Arc::new (RelayState::from (&config_file)),
|
2020-11-06 03:44:32 +00:00
|
|
|
rx
|
2020-11-02 18:39:19 +00:00
|
|
|
).await
|
2020-10-30 22:53:03 +00:00
|
|
|
}
|