http_private: add config, launch with cli helpers

This commit is contained in:
Joakim Frostegård 2022-04-02 14:35:40 +02:00
parent 6e97bff93f
commit 088daa72ff
8 changed files with 200 additions and 30 deletions

View file

@ -0,0 +1,41 @@
pub mod config;
mod workers;
use dotenv::dotenv;
pub const APP_NAME: &str = "aquatic_http_private: private HTTP/TLS BitTorrent tracker";
pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn run(config: config::Config) -> anyhow::Result<()> {
dotenv().ok();
let mut handles = Vec::new();
for _ in 0..config.socket_workers {
let config = config.clone();
let handle = ::std::thread::Builder::new()
.name("socket".into())
.spawn(move || workers::socket::run_socket_worker(config))?;
handles.push(handle);
}
for _ in 0..config.request_workers {
let config = config.clone();
let handle = ::std::thread::Builder::new()
.name("request".into())
.spawn(move || workers::request::run_request_worker(config))?;
handles.push(handle);
}
for handle in handles {
handle
.join()
.map_err(|err| anyhow::anyhow!("thread join error: {:?}", err))??;
}
Ok(())
}