diff --git a/Cargo.lock b/Cargo.lock index 12a928b0b..7ef142f74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -186,6 +186,12 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "core-foundation" version = "0.9.1" @@ -217,6 +223,19 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + [[package]] name = "digest" version = "0.8.1" @@ -1281,6 +1300,15 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustls" version = "0.19.1" @@ -1370,6 +1398,12 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" + [[package]] name = "serde" version = "0.8.23" @@ -1705,6 +1739,7 @@ dependencies = [ "byteorder", "chrono", "config", + "derive_more", "env_logger", "external-ip", "fern", diff --git a/Cargo.toml b/Cargo.toml index b7e4738d5..1d1d32149 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,3 +29,4 @@ r2d2 = "0.8.8" rand = "0.8.4" env_logger = "0.9.0" config = "0.11" +derive_more = "0.99" diff --git a/src/config.rs b/src/config.rs index c019dd256..9a7e47e37 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,6 +17,7 @@ pub struct UdpTrackerConfig { #[derive(Serialize, Deserialize)] pub struct HttpTrackerConfig { + pub enabled: bool, pub bind_address: String, pub announce_interval: u32, pub ssl_enabled: bool, @@ -34,6 +35,7 @@ impl HttpTrackerConfig { #[derive(Serialize, Deserialize)] pub struct HttpApiConfig { + pub enabled: bool, pub bind_address: String, pub access_tokens: HashMap, } @@ -124,6 +126,7 @@ impl Configuration { announce_interval: 120, }, http_tracker: Option::from(HttpTrackerConfig { + enabled: false, bind_address: String::from("0.0.0.0:7878"), announce_interval: 120, ssl_enabled: false, @@ -131,6 +134,7 @@ impl Configuration { ssl_key_path: None }), http_api: Option::from(HttpApiConfig { + enabled: true, bind_address: String::from("127.0.0.1:1212"), access_tokens: [(String::from("admin"), String::from("MyAccessToken"))].iter().cloned().collect(), }), diff --git a/src/database.rs b/src/database.rs index ea0926e3d..fbec824a0 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,6 +1,5 @@ use crate::{InfoHash, AUTH_KEY_LENGTH}; use log::debug; -use std::sync::Arc; use r2d2_sqlite::{SqliteConnectionManager, rusqlite}; use r2d2::{Pool}; use r2d2_sqlite::rusqlite::NO_PARAMS; @@ -8,30 +7,25 @@ use crate::key_manager::AuthKey; use std::str::FromStr; pub struct SqliteDatabase { - pool: Arc> + pool: Pool } impl SqliteDatabase { - pub async fn new(db_path: &str) -> Option { + pub fn new(db_path: &str) -> Result { let sqlite_connection_manager = SqliteConnectionManager::file(db_path); - let sqlite_pool = r2d2::Pool::new(sqlite_connection_manager) - .expect("Failed to create r2d2 SQLite connection pool."); - let pool_arc = Arc::new(sqlite_pool); - - match SqliteDatabase::create_database_tables(pool_arc.clone()) { - Ok(_) => { - Some(SqliteDatabase { - pool: pool_arc.clone() - }) - } - Err(_) => { - eprintln!("Could not create database tables."); - None - } - } + let sqlite_pool = r2d2::Pool::new(sqlite_connection_manager).expect("Failed to create r2d2 SQLite connection pool."); + let sqlite_database = SqliteDatabase { + pool: sqlite_pool + }; + + if let Err(error) = SqliteDatabase::create_database_tables(&sqlite_database.pool) { + return Err(error) + }; + + Ok(sqlite_database) } - pub fn create_database_tables(pool: Arc>) -> Result { + pub fn create_database_tables(pool: &Pool) -> Result { let create_whitelist_table = " CREATE TABLE IF NOT EXISTS whitelist ( id integer PRIMARY KEY AUTOINCREMENT, @@ -106,10 +100,10 @@ impl SqliteDatabase { } } - pub async fn get_key_from_keys(&self, key: String) -> Result { + pub async fn get_key_from_keys(&self, key: &str) -> Result { let conn = self.pool.get().unwrap(); let mut stmt = conn.prepare("SELECT key, valid_until FROM keys WHERE key = ?")?; - let mut rows = stmt.query(&[key])?; + let mut rows = stmt.query(&[key.to_string()])?; if let Some(row) = rows.next()? { let key: String = row.get(0).unwrap(); @@ -124,10 +118,10 @@ impl SqliteDatabase { } } - pub async fn add_key_to_keys(&self, auth_key: AuthKey) -> Result { + pub async fn add_key_to_keys(&self, auth_key: &AuthKey) -> Result { let conn = self.pool.get().unwrap(); match conn.execute("INSERT INTO keys (key, valid_until) VALUES (?1, ?2)", - &[auth_key.key, auth_key.valid_until.unwrap().to_string()] + &[auth_key.key.to_string(), auth_key.valid_until.unwrap().to_string()] ) { Ok(updated) => { if updated > 0 { return Ok(updated) } diff --git a/src/http_server.rs b/src/http_server.rs index 420e58723..147a446de 100644 --- a/src/http_server.rs +++ b/src/http_server.rs @@ -10,7 +10,7 @@ use std::str::FromStr; use log::{debug}; use warp::{filters, reply::Reply, Filter}; use warp::http::Response; -use crate::{Configuration, TorrentError, TorrentPeer, TorrentStats}; +use crate::{TorrentError, TorrentPeer, TorrentStats}; use crate::key_manager::AuthKey; use crate::utils::url_encode_bytes; use super::common::*; @@ -133,14 +133,12 @@ impl warp::Reply for HttpErrorResponse { #[derive(Clone)] pub struct HttpServer { - pub config: Arc, - pub tracker: Arc, + tracker: Arc, } impl HttpServer { - pub fn new(config: Arc, tracker: Arc) -> HttpServer { + pub fn new(tracker: Arc) -> HttpServer { HttpServer { - config, tracker } } @@ -312,7 +310,7 @@ impl HttpServer { } }; - let peer = TorrentPeer::from_http_announce_request(&query, remote_addr, self.config.get_ext_ip()); + let peer = TorrentPeer::from_http_announce_request(&query, remote_addr, self.tracker.config.get_ext_ip()); match self.tracker.update_torrent_with_peer_and_get_stats(&info_hash, &peer).await { Err(e) => { @@ -329,7 +327,7 @@ impl HttpServer { // todo: add http announce interval config option // success response - let announce_interval = self.config.http_tracker.as_ref().unwrap().announce_interval; + let announce_interval = self.tracker.config.http_tracker.as_ref().unwrap().announce_interval; HttpServer::send_announce_response(&query, torrent_stats, peers.unwrap(), announce_interval) } } diff --git a/src/key_manager.rs b/src/key_manager.rs index 6a5adfb56..fc6db324f 100644 --- a/src/key_manager.rs +++ b/src/key_manager.rs @@ -1,11 +1,10 @@ use super::common::AUTH_KEY_LENGTH; use crate::utils::current_time; -use crate::database::SqliteDatabase; -use std::sync::Arc; use rand::{thread_rng, Rng}; use rand::distributions::Alphanumeric; use serde::Serialize; use log::debug; +use derive_more::{Display, Error}; #[derive(Serialize, Debug, Eq, PartialEq, Clone)] pub struct AuthKey { @@ -31,18 +30,26 @@ impl AuthKey { } } -pub struct KeyManager { - database: Arc, +#[derive(Debug, Display, PartialEq, Error)] +#[allow(dead_code)] +pub enum Error { + #[display(fmt = "Key is invalid.")] + KeyVerificationError, + #[display(fmt = "Key has expired.")] + KeyExpired } -impl KeyManager { - pub fn new(database: Arc) -> KeyManager { - KeyManager { - database - } +impl From for Error { + fn from(e: r2d2_sqlite::rusqlite::Error) -> Self { + eprintln!("{}", e); + Error::KeyVerificationError } +} - pub async fn generate_auth_key(&self, seconds_valid: u64) -> Result { +pub struct KeyManager; + +impl KeyManager { + pub fn generate_auth_key(&self, seconds_valid: u64) -> AuthKey { let key: String = thread_rng() .sample_iter(&Alphanumeric) .take(AUTH_KEY_LENGTH) @@ -51,40 +58,17 @@ impl KeyManager { debug!("Generated key: {}, valid for: {} seconds", key, seconds_valid); - let auth_key = AuthKey { - key: key.clone(), + AuthKey { + key, valid_until: Some(current_time() + seconds_valid), - }; - - // add key to database - match self.database.add_key_to_keys(auth_key.clone()).await { - Ok(_) => Ok(auth_key), - Err(_) => Err(()) } } - pub async fn remove_auth_key(&self, key: String) -> Result<(), ()> { - match self.database.remove_key_from_keys(key).await { - Ok(_) => Ok(()), - Err(_) => Err(()) - } - } - - pub async fn verify_auth_key(&self, auth_key: &AuthKey) -> bool { + pub async fn verify_auth_key(&self, auth_key: &AuthKey) -> Result<(), Error> { let current_time = current_time(); + if auth_key.valid_until.is_none() { return Err(Error::KeyVerificationError) } + if &auth_key.valid_until.unwrap() < ¤t_time { return Err(Error::KeyExpired) } - match self.database.get_key_from_keys(auth_key.key.to_string()).await { - Ok(auth_key) => { - match auth_key.valid_until { - // should not be possible, valid_until is required - None => false, - Some(valid_until) => valid_until > current_time - } - } - Err(e) => { - debug!{"{:?}", e} - false - } - } + Ok(()) } } diff --git a/src/main.rs b/src/main.rs index 7796298fa..c1c90762d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ use fern; -use log::{info, warn}; +use log::{info}; use std::process::exit; -use torrust_tracker::{webserver, Configuration, TorrentTracker, UDPServer}; -use torrust_tracker::database::SqliteDatabase; +use torrust_tracker::{webserver, Configuration, TorrentTracker, UDPServer, HttpTrackerConfig, UdpTrackerConfig, HttpApiConfig}; use std::sync::Arc; use tokio::task::JoinHandle; use torrust_tracker::http_server::HttpServer; @@ -12,44 +11,39 @@ async fn main() { let config = match Configuration::load_from_file() { Ok(config) => Arc::new(config), Err(error) => { - eprintln!("{}", error); - exit(-1); + panic!("{}", error) } }; setup_logging(&config); - let sqlite_database = match SqliteDatabase::new(&config.db_path).await { - Some(sqlite_database) => { - info!("Verified database tables."); - Arc::new(sqlite_database) - } - None => { - eprintln!("Exiting.."); - exit(-1); - } - }; - // the singleton torrent tracker that gets passed to the HTTP and UDP server - let tracker = Arc::new(TorrentTracker::new(config.clone(), sqlite_database.clone())); + let tracker = Arc::new(TorrentTracker::new(config.clone())); // start torrent cleanup job (periodically removes old peers) let _torrent_cleanup_job = start_torrent_cleanup_job(config.clone(), tracker.clone()).unwrap(); // start HTTP API server - let _api_server = start_api_server(config.clone(), tracker.clone()); - - // start HTTP Tracker server - let _http_server = start_http_tracker_server(config.clone(), tracker.clone()); + if let Some(http_api_config) = &config.http_api { + let _api_server = start_api_server(&http_api_config, tracker.clone()); + }; - // start UDP Tracker server - let udp_server = start_udp_tracker_server(config.clone(), tracker.clone()).await.unwrap(); + // check which tracker to run, UDP (Default) or HTTP + let _tracker_server = if let Some(http_config) = &config.http_tracker { + if http_config.enabled { + start_http_tracker_server(http_config, tracker.clone()) + } else { + start_udp_tracker_server(&config.udp_tracker, tracker.clone()).await + } + } else { + start_udp_tracker_server(&config.udp_tracker, tracker.clone()).await + }; let ctrl_c = tokio::signal::ctrl_c(); tokio::select! { - _ = udp_server => { warn!("UDP Tracker server exited.") }, - _ = ctrl_c => { info!("T3 shutting down..") } + _ = _tracker_server => { panic!("Tracker server exited.") }, + _ = ctrl_c => { info!("Torrust shutting down..") } } } @@ -73,60 +67,52 @@ fn start_torrent_cleanup_job(config: Arc, tracker: Arc, tracker: Arc) -> Option> { - if config.http_api.is_some() { - info!("Starting API server.."); - return Some(tokio::spawn(async move { - let http_cfg = config.http_api.as_ref().unwrap(); - let bind_addr = &http_cfg.bind_address; - let server = webserver::build_server(tracker); - server.bind(bind_addr.parse::().unwrap()).await; - })) - } +fn start_api_server(config: &HttpApiConfig, tracker: Arc) -> JoinHandle<()> { + info!("Starting HTTP API server on: {}", config.bind_address); + let bind_addr = config.bind_address.parse::().unwrap(); - None + tokio::spawn(async move { + let server = webserver::build_server(tracker); + server.bind(bind_addr).await; + }) } -fn start_http_tracker_server(config: Arc, tracker: Arc) -> Option> { - if config.http_tracker.is_some() { - let http_tracker = Arc::new(HttpServer::new(config.clone(), tracker)); - - return Some(tokio::spawn(async move { - let http_tracker_config = config.http_tracker.as_ref().unwrap(); - let bind_addr = http_tracker_config.bind_address.parse::().unwrap(); - println!("{}", bind_addr); - - // run with tls if ssl_enabled and cert and key path are set - if http_tracker_config.is_ssl_enabled() { - info!("Starting HTTP tracker server in TLS mode.."); - warp::serve(HttpServer::routes(http_tracker)) - .tls() - .cert_path(&http_tracker_config.ssl_cert_path.as_ref().unwrap()) - .key_path(&http_tracker_config.ssl_key_path.as_ref().unwrap()) - .run(bind_addr).await; - } else { - info!("Starting HTTP tracker server.."); - warp::serve(HttpServer::routes(http_tracker)) - .run(bind_addr).await; - } - - })) - } - - None +fn start_http_tracker_server(config: &HttpTrackerConfig, tracker: Arc) -> JoinHandle<()> { + info!("Starting HTTP server on: {}", config.bind_address); + let http_tracker = Arc::new(HttpServer::new(tracker)); + let bind_addr = config.bind_address.parse::().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 { + // run with tls if ssl_enabled and cert and key path are set + if ssl_enabled { + info!("SSL enabled."); + warp::serve(HttpServer::routes(http_tracker)) + .tls() + .cert_path(ssl_cert_path.as_ref().unwrap()) + .key_path(ssl_key_path.as_ref().unwrap()) + .run(bind_addr).await; + } else { + warp::serve(HttpServer::routes(http_tracker)) + .run(bind_addr).await; + } + }) } -async fn start_udp_tracker_server(config: Arc, tracker: Arc) -> Option> { - let udp_server = UDPServer::new(config, tracker) - .await - .expect("failed to bind udp socket"); +async fn start_udp_tracker_server(config: &UdpTrackerConfig, tracker: Arc) -> JoinHandle<()> { + info!("Starting UDP server on: {}", config.bind_address); + let udp_server = UDPServer::new(tracker).await.unwrap_or_else(|e| { + panic!("Could not start UDP server: {}", e); + }); info!("Starting UDP tracker server.."); - Some(tokio::spawn(async move { - if let Err(err) = udp_server.accept_packets().await { - eprintln!("error: {}", err); + tokio::spawn(async move { + if let Err(e) = udp_server.accept_packets().await { + panic!("Could not start UDP server: {}", e); } - })) + }) } fn setup_logging(cfg: &Configuration) { diff --git a/src/tracker.rs b/src/tracker.rs index 78a4087a1..eeec1c1aa 100644 --- a/src/tracker.rs +++ b/src/tracker.rs @@ -5,7 +5,7 @@ use tokio::sync::RwLock; use crate::common::{NumberOfBytes, InfoHash}; use super::common::*; use std::net::{SocketAddr, IpAddr}; -use crate::{AnnounceRequest, Configuration}; +use crate::{AnnounceRequest, Configuration, key_manager}; use std::collections::btree_map::Entry; use crate::database::SqliteDatabase; use std::sync::Arc; @@ -247,24 +247,44 @@ pub enum TorrentError { } pub struct TorrentTracker { - torrents: tokio::sync::RwLock>, - database: Arc, pub config: Arc, - pub key_manager: Arc, + torrents: tokio::sync::RwLock>, + database: SqliteDatabase, + key_manager: KeyManager, } impl TorrentTracker { - pub fn new(config: Arc, database: Arc) -> TorrentTracker { - let key_manager = Arc::new(KeyManager::new(database.clone())); + pub fn new(config: Arc) -> TorrentTracker { + let database = SqliteDatabase::new(&config.db_path).unwrap_or_else(|error| { + panic!("Could not create SQLite database. Reason: {}", error) + }); TorrentTracker { + config, torrents: RwLock::new(std::collections::BTreeMap::new()), database, - config, - key_manager, + key_manager: KeyManager {} } } + pub async fn generate_auth_key(&self, seconds_valid: u64) -> Result { + let auth_key = self.key_manager.generate_auth_key(seconds_valid); + + // add key to database + if let Err(error) = self.database.add_key_to_keys(&auth_key).await { return Err(error) } + + Ok(auth_key) + } + + pub async fn remove_auth_key(&self, key: String) -> Result { + self.database.remove_key_from_keys(key).await + } + + pub async fn verify_auth_key(&self, auth_key: &AuthKey) -> Result<(), key_manager::Error> { + let db_key = self.database.get_key_from_keys(&auth_key.key).await?; + self.key_manager.verify_auth_key(&db_key).await + } + pub async fn authenticate_request(&self, info_hash: &InfoHash, key: &Option) -> Result<(), TorrentError> { match self.config.mode { TrackerMode::PublicMode => Ok(()), @@ -278,7 +298,7 @@ impl TorrentTracker { TrackerMode::PrivateMode => { match key { Some(key) => { - if !self.key_manager.verify_auth_key(key).await { + if self.key_manager.verify_auth_key(key).await.is_err() { return Err(TorrentError::PeerKeyNotValid) } @@ -292,7 +312,7 @@ impl TorrentTracker { TrackerMode::PrivateListedMode => { match key { Some(key) => { - if !self.key_manager.verify_auth_key(key).await { + if self.key_manager.verify_auth_key(key).await.is_err() { return Err(TorrentError::PeerKeyNotValid) } @@ -311,19 +331,13 @@ impl TorrentTracker { } /// Adding torrents is not relevant to public trackers. - pub async fn add_torrent_to_whitelist(&self, info_hash: &InfoHash) -> Result<(), ()>{ - match self.database.add_info_hash_to_whitelist(info_hash.clone()).await { - Ok(..) => Ok(()), - Err(..) => Err(()) - } + pub async fn add_torrent_to_whitelist(&self, info_hash: &InfoHash) -> Result { + self.database.add_info_hash_to_whitelist(info_hash.clone()).await } /// Removing torrents is not relevant to public trackers. - pub async fn remove_torrent_from_whitelist(&self, info_hash: &InfoHash) -> Result<(), rusqlite::Error> { - match self.database.remove_info_hash_from_whitelist(info_hash.clone()).await { - Ok(..) => Ok(()), - Err(e) => Err(e) - } + pub async fn remove_torrent_from_whitelist(&self, info_hash: &InfoHash) -> Result { + self.database.remove_info_hash_from_whitelist(info_hash.clone()).await } pub async fn is_info_hash_whitelisted(&self, info_hash: &InfoHash) -> bool { @@ -378,7 +392,7 @@ impl TorrentTracker { } } - pub async fn get_torrents<'a>(&'a self) -> tokio::sync::RwLockReadGuard<'a, BTreeMap> { + pub async fn get_torrents(&self) -> tokio::sync::RwLockReadGuard<'_, BTreeMap> { self.torrents.read().await } diff --git a/src/udp_server.rs b/src/udp_server.rs index 4afe24625..b1b51cb15 100644 --- a/src/udp_server.rs +++ b/src/udp_server.rs @@ -5,7 +5,6 @@ use std::sync::Arc; use std::io::{Cursor}; use tokio::net::UdpSocket; -use crate::config::Configuration; use super::common::*; use crate::response::*; use crate::request::{Request, ConnectRequest, AnnounceRequest, ScrapeRequest}; @@ -16,23 +15,20 @@ use crate::{TorrentPeer, TrackerMode, TorrentError}; pub struct UDPServer { socket: UdpSocket, tracker: Arc, - config: Arc, } impl UDPServer { - pub async fn new(config: Arc, tracker: Arc) -> Result { - let cfg = config.clone(); - let srv = UdpSocket::bind(&cfg.udp_tracker.bind_address).await?; + pub async fn new(tracker: Arc) -> Result { + let srv = UdpSocket::bind(&tracker.config.udp_tracker.bind_address).await?; Ok(UDPServer { socket: srv, tracker, - config: cfg, }) } pub async fn authenticate_announce_request(&self, announce_request: &AnnounceRequest) -> Result<(), TorrentError> { - match self.config.mode { + match self.tracker.config.mode { TrackerMode::PublicMode => Ok(()), TrackerMode::ListedMode => { if !self.tracker.is_info_hash_whitelisted(&announce_request.info_hash).await { @@ -44,7 +40,7 @@ impl UDPServer { TrackerMode::PrivateMode => { match &announce_request.auth_key { Some(auth_key) => { - if !self.tracker.key_manager.verify_auth_key(auth_key).await { + if self.tracker.verify_auth_key(auth_key).await.is_err() { return Err(TorrentError::PeerKeyNotValid) } @@ -58,7 +54,7 @@ impl UDPServer { TrackerMode::PrivateListedMode => { match &announce_request.auth_key { Some(auth_key) => { - if !self.tracker.key_manager.verify_auth_key(auth_key).await { + if self.tracker.verify_auth_key(auth_key).await.is_err() { return Err(TorrentError::PeerKeyNotValid) } @@ -144,7 +140,7 @@ impl UDPServer { } async fn handle_announce(&self, remote_addr: SocketAddr, request: AnnounceRequest) { - let peer = TorrentPeer::from_udp_announce_request(&request, remote_addr, self.config.get_ext_ip()); + let peer = TorrentPeer::from_udp_announce_request(&request, remote_addr, self.tracker.config.get_ext_ip()); match self.tracker.update_torrent_with_peer_and_get_stats(&request.info_hash, &peer).await { Ok(torrent_stats) => { @@ -160,7 +156,7 @@ impl UDPServer { let response = UDPResponse::from(UDPAnnounceResponse { action: Actions::Announce, transaction_id: request.transaction_id, - interval: self.config.udp_tracker.announce_interval, + interval: self.tracker.config.udp_tracker.announce_interval, leechers: torrent_stats.leechers, seeders: torrent_stats.seeders, peers, diff --git a/src/webserver.rs b/src/webserver.rs index eff9e00df..23b174a82 100644 --- a/src/webserver.rs +++ b/src/webserver.rs @@ -6,40 +6,6 @@ use std::sync::Arc; use warp::{filters, reply, reply::Reply, serve, Filter, Server}; use super::common::*; -fn view_root() -> impl Reply { - warp::http::Response::builder() - .header("Content-Type", "text/html; charset=utf-8") - .header("Server", concat!("udpt/", env!("CARGO_PKG_VERSION"), "; https://abda.nl/")) - .body(concat!(r#" - - udpt server - - - -

- This server is running Torrust, a BitTorrent tracker based on the UDP protocol. -

-
- torrust-tracker/"#, env!("CARGO_PKG_VERSION"), r#"
- wiki · issues & PRs · developed by DutchBits -
- - "#)) - .unwrap() -} - #[derive(Deserialize, Debug)] struct TorrentInfoQuery { offset: Option, @@ -98,8 +64,6 @@ fn authenticate(tokens: HashMap) -> impl Filter) -> Server + Clone + Send + Sync + 'static> { - let root = filters::path::end().map(|| view_root()); - // GET /api/torrents?offset=:u32&limit=:u32 // View torrent list let t1 = tracker.clone(); @@ -232,7 +196,7 @@ pub fn build_server(tracker: Arc) -> Server)| { async move { - match tracker.key_manager.generate_auth_key(seconds_valid).await { + match tracker.generate_auth_key(seconds_valid).await { Ok(auth_key) => Ok(warp::reply::json(&auth_key)), Err(..) => Err(warp::reject::custom(ActionStatus::Err { reason: "failed to generate key".into() })) } @@ -252,7 +216,7 @@ pub fn build_server(tracker: Arc) -> Server)| { async move { - match tracker.key_manager.remove_auth_key(key).await { + match tracker.remove_auth_key(key).await { Ok(_) => Ok(warp::reply::json(&ActionStatus::Ok)), Err(_) => Err(warp::reject::custom(ActionStatus::Err { reason: "failed to delete key".into() })) } @@ -269,7 +233,7 @@ pub fn build_server(tracker: Arc) -> Server