forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_tracker.rs
More file actions
36 lines (31 loc) · 1.24 KB
/
Copy pathhttp_tracker.rs
File metadata and controls
36 lines (31 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::net::SocketAddr;
use std::sync::Arc;
use log::{info, warn};
use tokio::task::JoinHandle;
use crate::config::HttpTracker;
use crate::http::server::Http;
use crate::tracker;
/// # Panics
///
/// It would panic if the `config::HttpTracker` struct would contain an inappropriate values.
#[must_use]
pub fn start_job(config: &HttpTracker, tracker: Arc<tracker::Tracker>) -> JoinHandle<()> {
let bind_addr = config.bind_address.parse::<SocketAddr>().unwrap();
let ssl_enabled = config.ssl_enabled;
let ssl_cert_path = config.ssl_cert_path.clone();
let ssl_key_path = config.ssl_key_path.clone();
tokio::spawn(async move {
let http_tracker = Http::new(tracker);
if !ssl_enabled {
info!("Starting HTTP server on: http://{}", bind_addr);
http_tracker.start(bind_addr).await;
} else if ssl_enabled && ssl_cert_path.is_some() && ssl_key_path.is_some() {
info!("Starting HTTPS server on: https://{} (TLS)", bind_addr);
http_tracker
.start_tls(bind_addr, ssl_cert_path.unwrap(), ssl_key_path.unwrap())
.await;
} else {
warn!("Could not start HTTP tracker on: {}, missing SSL Cert or Key!", bind_addr);
}
})
}