Skip to content

Commit a488359

Browse files
committed
refactor: moved and renamed some structs
1 parent 79bb1ed commit a488359

9 files changed

+301
-307
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "torrust-tracker"
3-
version = "1.0.0"
3+
version = "2.0.0"
44
authors = ["Mick van Dijke <mick@dutchbits.nl>", "Naim A. <naim@abda.nl>"]
55
description = "A feature rich UDP based BitTorrent tracker."
66
edition = "2018"

src/http_server.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::utils::url_encode_bytes;
1616
use super::common::*;
1717

1818
#[derive(Deserialize, Debug)]
19-
pub struct HttpAnnounceRequest {
19+
pub struct AnnounceRequest {
2020
pub downloaded: NumberOfBytes,
2121
pub uploaded: NumberOfBytes,
2222
pub key: String,
@@ -28,34 +28,34 @@ pub struct HttpAnnounceRequest {
2828
pub compact: Option<u8>,
2929
}
3030

31-
impl HttpAnnounceRequest {
31+
impl AnnounceRequest {
3232
pub fn is_compact(&self) -> bool {
3333
self.compact.unwrap_or(0) == 1
3434
}
3535
}
3636

3737
#[derive(Deserialize, Debug)]
38-
pub struct HttpScrapeRequest {
38+
pub struct ScrapeRequest {
3939
pub info_hash: String,
4040
}
4141

4242
#[derive(Serialize)]
43-
struct HttpPeer {
43+
struct Peer {
4444
peer_id: String,
4545
ip: IpAddr,
4646
port: u16,
4747
}
4848

4949
#[derive(Serialize)]
50-
struct HttpAnnounceResponse {
50+
struct AnnounceResponse {
5151
interval: u32,
5252
//tracker_id: String,
5353
complete: u32,
5454
incomplete: u32,
55-
peers: Vec<HttpPeer>
55+
peers: Vec<Peer>
5656
}
5757

58-
impl HttpAnnounceResponse {
58+
impl AnnounceResponse {
5959
pub fn write(&self) -> String {
6060
serde_bencode::to_string(&self).unwrap()
6161
}
@@ -103,29 +103,29 @@ impl HttpAnnounceResponse {
103103
}
104104

105105
#[derive(Serialize)]
106-
struct HttpScrapeResponse {
107-
files: HashMap<String, HttpScrapeResponseEntry>
106+
struct ScrapeResponse {
107+
files: HashMap<String, ScrapeResponseEntry>
108108
}
109109

110-
impl HttpScrapeResponse {
110+
impl ScrapeResponse {
111111
pub fn write(&self) -> String {
112112
serde_bencode::to_string(&self).unwrap()
113113
}
114114
}
115115

116116
#[derive(Serialize)]
117-
struct HttpScrapeResponseEntry {
117+
struct ScrapeResponseEntry {
118118
complete: u32,
119119
downloaded: u32,
120120
incomplete: u32,
121121
}
122122

123123
#[derive(Serialize)]
124-
struct HttpErrorResponse {
124+
struct ErrorResponse {
125125
failure_reason: String
126126
}
127127

128-
impl warp::Reply for HttpErrorResponse {
128+
impl warp::Reply for ErrorResponse {
129129
fn into_response(self) -> warp::reply::Response {
130130
Response::new(format!("{}", serde_bencode::to_string(&self).unwrap()).into())
131131
}
@@ -167,7 +167,7 @@ impl HttpServer {
167167
debug!("Request: {}", raw_query);
168168
(remote_addr, key, raw_query, query, hs1.clone())
169169
})
170-
.and_then(move |(remote_addr, key, raw_query, mut query, http_server): (Option<SocketAddr>, Option<String>, String, HttpAnnounceRequest, Arc<HttpServer>)| {
170+
.and_then(move |(remote_addr, key, raw_query, mut query, http_server): (Option<SocketAddr>, Option<String>, String, AnnounceRequest, Arc<HttpServer>)| {
171171
async move {
172172
if remote_addr.is_none() { return HttpServer::send_error("could not get remote address") }
173173

@@ -232,14 +232,14 @@ impl HttpServer {
232232
info_hashes
233233
}
234234

235-
fn send_announce_response(query: &HttpAnnounceRequest, torrent_stats: TorrentStats, peers: Vec<TorrentPeer>, interval: u32) -> Result<warp::reply::Response, Infallible> {
236-
let http_peers: Vec<HttpPeer> = peers.iter().map(|peer| HttpPeer {
235+
fn send_announce_response(query: &AnnounceRequest, torrent_stats: TorrentStats, peers: Vec<TorrentPeer>, interval: u32) -> Result<warp::reply::Response, Infallible> {
236+
let http_peers: Vec<Peer> = peers.iter().map(|peer| Peer {
237237
peer_id: String::from_utf8_lossy(&peer.peer_id.0).to_string(),
238238
ip: peer.peer_addr.ip(),
239239
port: peer.peer_addr.port()
240240
}).collect();
241241

242-
let res = HttpAnnounceResponse {
242+
let res = AnnounceResponse {
243243
interval,
244244
complete: torrent_stats.seeders,
245245
incomplete: torrent_stats.leechers,
@@ -269,7 +269,7 @@ impl HttpServer {
269269
}
270270

271271
fn send_error(msg: &str) -> Result<warp::reply::Response, Infallible> {
272-
Ok(HttpErrorResponse {
272+
Ok(ErrorResponse {
273273
failure_reason: msg.to_string()
274274
}.into_response())
275275
}
@@ -302,7 +302,7 @@ impl HttpServer {
302302
None
303303
}
304304

305-
async fn handle_announce(&self, query: HttpAnnounceRequest, remote_addr: SocketAddr) -> Result<warp::reply::Response, Infallible> {
305+
async fn handle_announce(&self, query: AnnounceRequest, remote_addr: SocketAddr) -> Result<warp::reply::Response, Infallible> {
306306
let info_hash = match InfoHash::from_str(&query.info_hash) {
307307
Ok(v) => v,
308308
Err(_) => {
@@ -334,7 +334,7 @@ impl HttpServer {
334334
}
335335

336336
async fn handle_scrape(&self, info_hashes: Vec<InfoHash>) -> Result<warp::reply::Response, Infallible> {
337-
let mut res = HttpScrapeResponse {
337+
let mut res = ScrapeResponse {
338338
files: HashMap::new()
339339
};
340340
let db = self.tracker.get_torrents().await;
@@ -344,14 +344,14 @@ impl HttpServer {
344344
Some(torrent_info) => {
345345
let (seeders, completed, leechers) = torrent_info.get_stats();
346346

347-
HttpScrapeResponseEntry {
347+
ScrapeResponseEntry {
348348
complete: seeders,
349349
downloaded: completed,
350350
incomplete: leechers
351351
}
352352
}
353353
None => {
354-
HttpScrapeResponseEntry {
354+
ScrapeResponseEntry {
355355
complete: 0,
356356
downloaded: 0,
357357
incomplete: 0

src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
pub mod config;
22
pub mod udp_server;
3+
pub mod http_server;
34
pub mod tracker;
45
pub mod webserver;
56
pub mod common;
67
pub mod response;
7-
pub mod request;
88
pub mod utils;
99
pub mod database;
1010
pub mod key_manager;
11-
pub mod http_server;
1211
pub mod logging;
1312

1413
pub use self::config::*;
1514
pub use self::udp_server::*;
15+
pub use self::http_server::*;
1616
pub use self::tracker::*;
1717
pub use self::webserver::*;
1818
pub use self::common::*;
1919
pub use self::response::*;
20-
pub use self::request::*;

src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use log::{info};
2-
use torrust_tracker::{webserver, Configuration, TorrentTracker, UDPServer, HttpTrackerConfig, UdpTrackerConfig, HttpApiConfig, logging};
2+
use torrust_tracker::{webserver, Configuration, TorrentTracker, UdpServer, HttpTrackerConfig, UdpTrackerConfig, HttpApiConfig, logging};
33
use std::sync::Arc;
44
use tokio::task::JoinHandle;
55
use torrust_tracker::http_server::HttpServer;
@@ -103,7 +103,7 @@ fn start_http_tracker_server(config: &HttpTrackerConfig, tracker: Arc<TorrentTra
103103

104104
async fn start_udp_tracker_server(config: &UdpTrackerConfig, tracker: Arc<TorrentTracker>) -> JoinHandle<()> {
105105
info!("Starting UDP server on: {}", config.bind_address);
106-
let udp_server = UDPServer::new(tracker).await.unwrap_or_else(|e| {
106+
let udp_server = UdpServer::new(tracker).await.unwrap_or_else(|e| {
107107
panic!("Could not start UDP server: {}", e);
108108
});
109109

0 commit comments

Comments
 (0)