use std::path::PathBuf;
use std::time::Duration;
use clap::Parser;
use moblink_rust::relay::create_get_status_closure;
use moblink_rust::relay_service::{RelayService, RelayServiceConfig};
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[arg(long, default_value = "1234")]
password: String,
#[arg(long)]
network_interfaces_to_allow: Vec<String>,
#[arg(long)]
network_interfaces_to_ignore: Vec<String>,
#[arg(long)]
streamer_url: Vec<String>,
#[arg(long)]
interface_name_override: Vec<String>,
#[arg(long)]
runtime_status_file: Option<PathBuf>,
#[arg(long, default_value = "info")]
log_level: String,
#[arg(long)]
no_log_timestamps: bool,
#[arg(long)]
status_executable: Option<String>,
#[arg(long)]
status_file: Option<String>,
#[arg(long, default_value = "moblink-relay-service.json")]
database: PathBuf,
}
fn setup_logging(timestamps: bool, log_level: &str) {
let mut builder = env_logger::builder();
if timestamps {
builder.format_timestamp_millis()
} else {
builder.format_timestamp(None)
}
.parse_filters(log_level)
.init();
}
#[tokio::main]
async fn main() {
let args = Args::parse();
setup_logging(!args.no_log_timestamps, &args.log_level);
let relay_service = RelayService::new(
RelayServiceConfig {
password: args.password,
network_interfaces_to_allow: args.network_interfaces_to_allow,
network_interfaces_to_ignore: args.network_interfaces_to_ignore,
streamer_urls: args.streamer_url,
interface_name_overrides: args.interface_name_override,
runtime_status_file: args.runtime_status_file,
database: args.database,
},
create_get_status_closure(&args.status_executable, &args.status_file),
)
.await;
relay_service.start().await;
loop {
tokio::time::sleep(Duration::from_secs(3600)).await;
}
}