2021-12-11 22:43:41 -05:00
|
|
|
//! Server process
|
2023-01-05 08:47:34 -05:00
|
|
|
use clap::Parser;
|
|
|
|
use nostr_rs_relay::cli::*;
|
2021-12-29 23:13:02 -05:00
|
|
|
use nostr_rs_relay::config;
|
2022-09-06 06:56:04 -04:00
|
|
|
use nostr_rs_relay::server::start_server;
|
2022-09-06 07:12:07 -04:00
|
|
|
use std::sync::mpsc as syncmpsc;
|
|
|
|
use std::sync::mpsc::{Receiver as MpscReceiver, Sender as MpscSender};
|
2022-09-06 06:56:04 -04:00
|
|
|
use std::thread;
|
2022-09-28 08:19:59 -04:00
|
|
|
use tracing::info;
|
2021-12-05 17:53:26 -05:00
|
|
|
|
2022-09-11 13:44:45 -04:00
|
|
|
|
2023-01-05 08:47:34 -05:00
|
|
|
use console_subscriber::ConsoleLayer;
|
2022-01-05 17:41:12 -05:00
|
|
|
|
2023-01-03 08:51:44 -05:00
|
|
|
|
2021-12-05 17:53:26 -05:00
|
|
|
/// Start running a Nostr relay server.
|
2022-09-24 09:39:41 -04:00
|
|
|
fn main() {
|
2022-09-06 07:12:07 -04:00
|
|
|
// configure settings from config.toml
|
|
|
|
// replace default settings with those read from config.toml
|
|
|
|
let mut settings = config::Settings::new();
|
2022-09-11 13:44:45 -04:00
|
|
|
|
2023-01-14 10:47:01 -05:00
|
|
|
// setup tracing
|
2022-09-11 13:44:45 -04:00
|
|
|
if settings.diagnostics.tracing {
|
|
|
|
// enable tracing with tokio-console
|
|
|
|
ConsoleLayer::builder().with_default_env().init();
|
2023-01-14 10:47:01 -05:00
|
|
|
} else {
|
|
|
|
// standard logging
|
|
|
|
tracing_subscriber::fmt::try_init().unwrap();
|
2022-09-11 13:44:45 -04:00
|
|
|
}
|
2023-01-14 10:47:01 -05:00
|
|
|
info!("Starting up from main");
|
|
|
|
|
|
|
|
let args = CLIArgs::parse();
|
|
|
|
|
|
|
|
// get database directory from args
|
2023-01-16 18:21:12 -05:00
|
|
|
let db_dir_arg = args.db;
|
2023-01-14 10:47:01 -05:00
|
|
|
|
2023-01-16 18:21:12 -05:00
|
|
|
// update with database location from args, if provided
|
|
|
|
if let Some(db_dir) = db_dir_arg {
|
2023-01-05 08:47:34 -05:00
|
|
|
settings.database.data_directory = db_dir;
|
2021-12-29 23:13:02 -05:00
|
|
|
}
|
2022-09-06 07:12:07 -04:00
|
|
|
let (_, ctrl_rx): (MpscSender<()>, MpscReceiver<()>) = syncmpsc::channel();
|
2022-09-06 06:56:04 -04:00
|
|
|
// run this in a new thread
|
|
|
|
let handle = thread::spawn(|| {
|
2022-09-06 07:12:07 -04:00
|
|
|
// we should have a 'control plane' channel to monitor and bump the server.
|
|
|
|
// this will let us do stuff like clear the database, shutdown, etc.
|
2022-09-24 20:28:02 -04:00
|
|
|
let _svr = start_server(settings, ctrl_rx);
|
2021-12-05 17:53:26 -05:00
|
|
|
});
|
2022-09-06 06:56:04 -04:00
|
|
|
// block on nostr thread to finish.
|
|
|
|
handle.join().unwrap();
|
2021-12-05 17:53:26 -05:00
|
|
|
}
|