Skip to content

Commit 78221b6

Browse files
committed
clippy: fix src/tracker/mod.rs
1 parent 81e72da commit 78221b6

File tree

16 files changed

+133
-96
lines changed

16 files changed

+133
-96
lines changed

src/api/server.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::resources::auth_key_resource::AuthKeyResource;
1111
use super::resources::stats_resource::StatsResource;
1212
use super::resources::torrent_resource::{TorrentListItemResource, TorrentPeerResource, TorrentResource};
1313
use crate::protocol::common::InfoHash;
14-
use crate::tracker::TorrentTracker;
14+
use crate::tracker;
1515

1616
#[derive(Deserialize, Debug)]
1717
struct TorrentInfoQuery {
@@ -60,7 +60,7 @@ fn authenticate(tokens: HashMap<String, String>) -> impl Filter<Extract = (), Er
6060
}
6161

6262
#[allow(clippy::too_many_lines)]
63-
pub fn start(socket_addr: SocketAddr, tracker: &Arc<TorrentTracker>) -> impl warp::Future<Output = ()> {
63+
pub fn start(socket_addr: SocketAddr, tracker: &Arc<tracker::Tracker>) -> impl warp::Future<Output = ()> {
6464
// GET /api/torrents?offset=:u32&limit=:u32
6565
// View torrent list
6666
let api_torrents = tracker.clone();
@@ -72,7 +72,7 @@ pub fn start(socket_addr: SocketAddr, tracker: &Arc<TorrentTracker>) -> impl war
7272
let tracker = api_torrents.clone();
7373
(limits, tracker)
7474
})
75-
.and_then(|(limits, tracker): (TorrentInfoQuery, Arc<TorrentTracker>)| async move {
75+
.and_then(|(limits, tracker): (TorrentInfoQuery, Arc<tracker::Tracker>)| async move {
7676
let offset = limits.offset.unwrap_or(0);
7777
let limit = min(limits.limit.unwrap_or(1000), 4000);
7878

@@ -103,7 +103,7 @@ pub fn start(socket_addr: SocketAddr, tracker: &Arc<TorrentTracker>) -> impl war
103103
.and(filters::path::path("stats"))
104104
.and(filters::path::end())
105105
.map(move || api_stats.clone())
106-
.and_then(|tracker: Arc<TorrentTracker>| async move {
106+
.and_then(|tracker: Arc<tracker::Tracker>| async move {
107107
let mut results = StatsResource {
108108
torrents: 0,
109109
seeders: 0,
@@ -165,7 +165,7 @@ pub fn start(socket_addr: SocketAddr, tracker: &Arc<TorrentTracker>) -> impl war
165165
let tracker = t2.clone();
166166
(info_hash, tracker)
167167
})
168-
.and_then(|(info_hash, tracker): (InfoHash, Arc<TorrentTracker>)| async move {
168+
.and_then(|(info_hash, tracker): (InfoHash, Arc<tracker::Tracker>)| async move {
169169
let db = tracker.get_torrents().await;
170170
let torrent_entry_option = db.get(&info_hash);
171171

@@ -201,7 +201,7 @@ pub fn start(socket_addr: SocketAddr, tracker: &Arc<TorrentTracker>) -> impl war
201201
let tracker = t3.clone();
202202
(info_hash, tracker)
203203
})
204-
.and_then(|(info_hash, tracker): (InfoHash, Arc<TorrentTracker>)| async move {
204+
.and_then(|(info_hash, tracker): (InfoHash, Arc<tracker::Tracker>)| async move {
205205
match tracker.remove_torrent_from_whitelist(&info_hash).await {
206206
Ok(_) => Ok(warp::reply::json(&ActionStatus::Ok)),
207207
Err(_) => Err(warp::reject::custom(ActionStatus::Err {
@@ -221,7 +221,7 @@ pub fn start(socket_addr: SocketAddr, tracker: &Arc<TorrentTracker>) -> impl war
221221
let tracker = t4.clone();
222222
(info_hash, tracker)
223223
})
224-
.and_then(|(info_hash, tracker): (InfoHash, Arc<TorrentTracker>)| async move {
224+
.and_then(|(info_hash, tracker): (InfoHash, Arc<tracker::Tracker>)| async move {
225225
match tracker.add_torrent_to_whitelist(&info_hash).await {
226226
Ok(..) => Ok(warp::reply::json(&ActionStatus::Ok)),
227227
Err(..) => Err(warp::reject::custom(ActionStatus::Err {
@@ -241,7 +241,7 @@ pub fn start(socket_addr: SocketAddr, tracker: &Arc<TorrentTracker>) -> impl war
241241
let tracker = t5.clone();
242242
(seconds_valid, tracker)
243243
})
244-
.and_then(|(seconds_valid, tracker): (u64, Arc<TorrentTracker>)| async move {
244+
.and_then(|(seconds_valid, tracker): (u64, Arc<tracker::Tracker>)| async move {
245245
match tracker.generate_auth_key(Duration::from_secs(seconds_valid)).await {
246246
Ok(auth_key) => Ok(warp::reply::json(&AuthKeyResource::from(auth_key))),
247247
Err(..) => Err(warp::reject::custom(ActionStatus::Err {
@@ -261,7 +261,7 @@ pub fn start(socket_addr: SocketAddr, tracker: &Arc<TorrentTracker>) -> impl war
261261
let tracker = t6.clone();
262262
(key, tracker)
263263
})
264-
.and_then(|(key, tracker): (String, Arc<TorrentTracker>)| async move {
264+
.and_then(|(key, tracker): (String, Arc<tracker::Tracker>)| async move {
265265
match tracker.remove_auth_key(&key).await {
266266
Ok(_) => Ok(warp::reply::json(&ActionStatus::Ok)),
267267
Err(_) => Err(warp::reject::custom(ActionStatus::Err {
@@ -278,7 +278,7 @@ pub fn start(socket_addr: SocketAddr, tracker: &Arc<TorrentTracker>) -> impl war
278278
.and(filters::path::path("reload"))
279279
.and(filters::path::end())
280280
.map(move || t7.clone())
281-
.and_then(|tracker: Arc<TorrentTracker>| async move {
281+
.and_then(|tracker: Arc<tracker::Tracker>| async move {
282282
match tracker.load_whitelist().await {
283283
Ok(_) => Ok(warp::reply::json(&ActionStatus::Ok)),
284284
Err(_) => Err(warp::reject::custom(ActionStatus::Err {
@@ -295,7 +295,7 @@ pub fn start(socket_addr: SocketAddr, tracker: &Arc<TorrentTracker>) -> impl war
295295
.and(filters::path::path("reload"))
296296
.and(filters::path::end())
297297
.map(move || t8.clone())
298-
.and_then(|tracker: Arc<TorrentTracker>| async move {
298+
.and_then(|tracker: Arc<tracker::Tracker>| async move {
299299
match tracker.load_keys().await {
300300
Ok(_) => Ok(warp::reply::json(&ActionStatus::Ok)),
301301
Err(_) => Err(warp::reject::custom(ActionStatus::Err {

src/http/filters.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use super::errors::ServerError;
99
use super::request::{Announce, AnnounceRequestQuery, Scrape};
1010
use super::WebResult;
1111
use crate::protocol::common::{InfoHash, PeerId, MAX_SCRAPE_TORRENTS};
12+
use crate::tracker;
1213
use crate::tracker::key::Auth;
13-
use crate::tracker::TorrentTracker;
1414

15-
/// Pass Arc<TorrentTracker> along
15+
/// Pass Arc<tracker::TorrentTracker> along
1616
#[must_use]
17-
pub fn with_tracker(tracker: Arc<TorrentTracker>) -> impl Filter<Extract = (Arc<TorrentTracker>,), Error = Infallible> + Clone {
17+
pub fn with_tracker(
18+
tracker: Arc<tracker::Tracker>,
19+
) -> impl Filter<Extract = (Arc<tracker::Tracker>,), Error = Infallible> + Clone {
1820
warp::any().map(move || tracker.clone())
1921
}
2022

@@ -30,7 +32,7 @@ pub fn with_peer_id() -> impl Filter<Extract = (PeerId,), Error = Rejection> + C
3032
warp::filters::query::raw().and_then(|q| async move { peer_id(&q) })
3133
}
3234

33-
/// Pass Arc<TorrentTracker> along
35+
/// Pass Arc<tracker::TorrentTracker> along
3436
#[must_use]
3537
pub fn with_auth_key() -> impl Filter<Extract = (Option<Auth>,), Error = Infallible> + Clone {
3638
warp::path::param::<String>()

src/http/handlers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use super::{request, WebResult};
1313
use crate::http::response::Error;
1414
use crate::protocol::common::InfoHash;
1515
use crate::tracker::key::Auth;
16-
use crate::tracker::{peer, statistics, torrent, TorrentTracker};
16+
use crate::tracker::{self, peer, statistics, torrent};
1717

1818
/// Authenticate `InfoHash` using optional `AuthKey`
1919
///
@@ -23,7 +23,7 @@ use crate::tracker::{peer, statistics, torrent, TorrentTracker};
2323
pub async fn authenticate(
2424
info_hash: &InfoHash,
2525
auth_key: &Option<Auth>,
26-
tracker: Arc<TorrentTracker>,
26+
tracker: Arc<tracker::Tracker>,
2727
) -> Result<(), ServerError> {
2828
tracker.authenticate_request(info_hash, auth_key).await.map_err(|e| match e {
2929
torrent::Error::TorrentNotWhitelisted => ServerError::TorrentNotWhitelisted,
@@ -43,7 +43,7 @@ pub async fn authenticate(
4343
pub async fn handle_announce(
4444
announce_request: request::Announce,
4545
auth_key: Option<Auth>,
46-
tracker: Arc<TorrentTracker>,
46+
tracker: Arc<tracker::Tracker>,
4747
) -> WebResult<impl Reply> {
4848
authenticate(&announce_request.info_hash, &auth_key, tracker.clone())
4949
.await
@@ -89,7 +89,7 @@ pub async fn handle_announce(
8989
pub async fn handle_scrape(
9090
scrape_request: request::Scrape,
9191
auth_key: Option<Auth>,
92-
tracker: Arc<TorrentTracker>,
92+
tracker: Arc<tracker::Tracker>,
9393
) -> WebResult<impl Reply> {
9494
let mut files: HashMap<InfoHash, ScrapeResponseEntry> = HashMap::new();
9595
let db = tracker.get_torrents().await;

src/http/routes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ use warp::{Filter, Rejection};
55

66
use super::filters::{with_announce_request, with_auth_key, with_scrape_request, with_tracker};
77
use super::handlers::{handle_announce, handle_scrape, send_error};
8-
use crate::tracker::TorrentTracker;
8+
use crate::tracker;
99

1010
/// All routes
1111
#[must_use]
12-
pub fn routes(tracker: Arc<TorrentTracker>) -> impl Filter<Extract = impl warp::Reply, Error = Infallible> + Clone {
12+
pub fn routes(tracker: Arc<tracker::Tracker>) -> impl Filter<Extract = impl warp::Reply, Error = Infallible> + Clone {
1313
announce(tracker.clone())
1414
.or(scrape(tracker))
1515
.recover(|q| async move { send_error(&q) })
1616
}
1717

1818
/// GET /announce or /announce/<key>
19-
fn announce(tracker: Arc<TorrentTracker>) -> impl Filter<Extract = impl warp::Reply, Error = Rejection> + Clone {
19+
fn announce(tracker: Arc<tracker::Tracker>) -> impl Filter<Extract = impl warp::Reply, Error = Rejection> + Clone {
2020
warp::path::path("announce")
2121
.and(warp::filters::method::get())
2222
.and(with_announce_request(tracker.config.on_reverse_proxy))
@@ -26,7 +26,7 @@ fn announce(tracker: Arc<TorrentTracker>) -> impl Filter<Extract = impl warp::Re
2626
}
2727

2828
/// GET /scrape/<key>
29-
fn scrape(tracker: Arc<TorrentTracker>) -> impl Filter<Extract = impl warp::Reply, Error = Rejection> + Clone {
29+
fn scrape(tracker: Arc<tracker::Tracker>) -> impl Filter<Extract = impl warp::Reply, Error = Rejection> + Clone {
3030
warp::path::path("scrape")
3131
.and(warp::filters::method::get())
3232
.and(with_scrape_request(tracker.config.on_reverse_proxy))

src/http/server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ use std::net::SocketAddr;
22
use std::sync::Arc;
33

44
use super::routes;
5-
use crate::tracker::TorrentTracker;
5+
use crate::tracker;
66

7-
/// Server that listens on HTTP, needs a `TorrentTracker`
7+
/// Server that listens on HTTP, needs a `tracker::TorrentTracker`
88
#[derive(Clone)]
99
pub struct Http {
10-
tracker: Arc<TorrentTracker>,
10+
tracker: Arc<tracker::Tracker>,
1111
}
1212

1313
impl Http {
1414
#[must_use]
15-
pub fn new(tracker: Arc<TorrentTracker>) -> Http {
15+
pub fn new(tracker: Arc<tracker::Tracker>) -> Http {
1616
Http { tracker }
1717
}
1818

src/jobs/http_tracker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use tokio::task::JoinHandle;
66

77
use crate::config::HttpTracker;
88
use crate::http::server::Http;
9-
use crate::tracker::TorrentTracker;
9+
use crate::tracker;
1010

1111
/// # Panics
1212
///
1313
/// It would panic if the `config::HttpTracker` struct would contain an inappropriate values.
1414
#[must_use]
15-
pub fn start_job(config: &HttpTracker, tracker: Arc<TorrentTracker>) -> JoinHandle<()> {
15+
pub fn start_job(config: &HttpTracker, tracker: Arc<tracker::Tracker>) -> JoinHandle<()> {
1616
let bind_addr = config.bind_address.parse::<SocketAddr>().unwrap();
1717
let ssl_enabled = config.ssl_enabled;
1818
let ssl_cert_path = config.ssl_cert_path.clone();

src/jobs/torrent_cleanup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use log::info;
55
use tokio::task::JoinHandle;
66

77
use crate::config::Configuration;
8-
use crate::tracker::TorrentTracker;
8+
use crate::tracker;
99

1010
#[must_use]
11-
pub fn start_job(config: &Configuration, tracker: &Arc<TorrentTracker>) -> JoinHandle<()> {
11+
pub fn start_job(config: &Configuration, tracker: &Arc<tracker::Tracker>) -> JoinHandle<()> {
1212
let weak_tracker = std::sync::Arc::downgrade(tracker);
1313
let interval = config.inactive_peer_cleanup_interval;
1414

src/jobs/tracker_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use tokio::task::JoinHandle;
66

77
use crate::api::server;
88
use crate::config::Configuration;
9-
use crate::tracker::TorrentTracker;
9+
use crate::tracker;
1010

1111
#[derive(Debug)]
1212
pub struct ApiServerJobStarted();
1313

14-
pub async fn start_job(config: &Configuration, tracker: Arc<TorrentTracker>) -> JoinHandle<()> {
14+
pub async fn start_job(config: &Configuration, tracker: Arc<tracker::Tracker>) -> JoinHandle<()> {
1515
let bind_addr = config
1616
.http_api
1717
.bind_address

src/jobs/udp_tracker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use log::{error, info, warn};
44
use tokio::task::JoinHandle;
55

66
use crate::config::UdpTracker;
7-
use crate::tracker::TorrentTracker;
7+
use crate::tracker;
88
use crate::udp::server::UdpServer;
99

1010
#[must_use]
11-
pub fn start_job(config: &UdpTracker, tracker: Arc<TorrentTracker>) -> JoinHandle<()> {
11+
pub fn start_job(config: &UdpTracker, tracker: Arc<tracker::Tracker>) -> JoinHandle<()> {
1212
let bind_addr = config.bind_address.clone();
1313

1414
tokio::spawn(async move {

src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::sync::Arc;
33
use log::info;
44
use torrust_tracker::config::Configuration;
55
use torrust_tracker::stats::setup_statistics;
6-
use torrust_tracker::tracker::TorrentTracker;
7-
use torrust_tracker::{ephemeral_instance_keys, logging, setup, static_time};
6+
use torrust_tracker::{ephemeral_instance_keys, logging, setup, static_time, tracker};
87

98
#[tokio::main]
109
async fn main() {
@@ -28,7 +27,7 @@ async fn main() {
2827
let (stats_event_sender, stats_repository) = setup_statistics(config.tracker_usage_statistics);
2928

3029
// Initialize Torrust tracker
31-
let tracker = match TorrentTracker::new(config.clone(), stats_event_sender, stats_repository) {
30+
let tracker = match tracker::Tracker::new(&config.clone(), stats_event_sender, stats_repository) {
3231
Ok(tracker) => Arc::new(tracker),
3332
Err(error) => {
3433
panic!("{}", error)

0 commit comments

Comments
 (0)