forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.rs
More file actions
46 lines (39 loc) · 1.37 KB
/
server.rs
File metadata and controls
46 lines (39 loc) · 1.37 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
37
38
39
40
41
42
43
44
45
46
use std::net::SocketAddr;
use std::sync::Arc;
use crate::http::routes;
use crate::tracker::tracker::TorrentTracker;
/// Server that listens on HTTP, needs a TorrentTracker
#[derive(Clone)]
pub struct HttpServer {
tracker: Arc<TorrentTracker>,
}
impl HttpServer {
pub fn new(tracker: Arc<TorrentTracker>) -> HttpServer {
HttpServer {
tracker
}
}
/// Start the HttpServer
pub fn start(&self, socket_addr: SocketAddr) -> impl warp::Future<Output = ()> {
let (_addr, server) = warp::serve(routes(self.tracker.clone()))
.bind_with_graceful_shutdown(socket_addr, async move {
tokio::signal::ctrl_c()
.await
.expect("Failed to listen to shutdown signal.");
});
server
}
/// Start the HttpServer in TLS mode
pub fn start_tls(&self, socket_addr: SocketAddr, ssl_cert_path: String, ssl_key_path: String) -> impl warp::Future<Output = ()> {
let (_addr, server) = warp::serve(routes(self.tracker.clone()))
.tls()
.cert_path(ssl_cert_path)
.key_path(ssl_key_path)
.bind_with_graceful_shutdown(socket_addr, async move {
tokio::signal::ctrl_c()
.await
.expect("Failed to listen to shutdown signal.");
});
server
}
}