Skip to content

Commit 0f281c3

Browse files
committed
clippy: fix src/tracker/peer.rs
1 parent 363b21a commit 0f281c3

File tree

5 files changed

+27
-30
lines changed

5 files changed

+27
-30
lines changed

src/http/handlers.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ 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::TorrentPeer;
1716
use crate::tracker::statistics::TrackerStatisticsEvent;
1817
use crate::tracker::torrent::{TorrentError, TorrentStats};
19-
use crate::tracker::TorrentTracker;
18+
use crate::tracker::{peer, TorrentTracker};
2019

2120
/// Authenticate `InfoHash` using optional `AuthKey`
2221
///
@@ -55,7 +54,7 @@ pub async fn handle_announce(
5554
debug!("{:?}", announce_request);
5655

5756
let peer =
58-
TorrentPeer::from_http_announce_request(&announce_request, announce_request.peer_addr, tracker.config.get_ext_ip());
57+
peer::TorrentPeer::from_http_announce_request(&announce_request, announce_request.peer_addr, tracker.config.get_ext_ip());
5958
let torrent_stats = tracker
6059
.update_torrent_with_peer_and_get_stats(&announce_request.info_hash, &peer)
6160
.await;
@@ -143,7 +142,7 @@ pub async fn handle_scrape(
143142
fn send_announce_response(
144143
announce_request: &request::Announce,
145144
torrent_stats: &TorrentStats,
146-
peers: &Vec<TorrentPeer>,
145+
peers: &Vec<peer::TorrentPeer>,
147146
interval: u32,
148147
interval_min: u32,
149148
) -> WebResult<impl Reply> {

src/tracker/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::time::Duration;
1313
use tokio::sync::mpsc::error::SendError;
1414
use tokio::sync::{RwLock, RwLockReadGuard};
1515

16-
use self::peer::TorrentPeer;
1716
use self::statistics::{StatsRepository, TrackerStatistics, TrackerStatisticsEvent, TrackerStatisticsEventSender};
1817
use crate::config::Configuration;
1918
use crate::databases::database;
@@ -195,7 +194,7 @@ impl TorrentTracker {
195194
}
196195

197196
/// Get all torrent peers for a given torrent filtering out the peer with the client address
198-
pub async fn get_torrent_peers(&self, info_hash: &InfoHash, client_addr: &SocketAddr) -> Vec<TorrentPeer> {
197+
pub async fn get_torrent_peers(&self, info_hash: &InfoHash, client_addr: &SocketAddr) -> Vec<peer::TorrentPeer> {
199198
let read_lock = self.torrents.read().await;
200199

201200
match read_lock.get(info_hash) {
@@ -205,7 +204,7 @@ impl TorrentTracker {
205204
}
206205

207206
/// Get all torrent peers for a given torrent
208-
pub async fn get_all_torrent_peers(&self, info_hash: &InfoHash) -> Vec<TorrentPeer> {
207+
pub async fn get_all_torrent_peers(&self, info_hash: &InfoHash) -> Vec<peer::TorrentPeer> {
209208
let read_lock = self.torrents.read().await;
210209

211210
match read_lock.get(info_hash) {
@@ -214,7 +213,7 @@ impl TorrentTracker {
214213
}
215214
}
216215

217-
pub async fn update_torrent_with_peer_and_get_stats(&self, info_hash: &InfoHash, peer: &TorrentPeer) -> TorrentStats {
216+
pub async fn update_torrent_with_peer_and_get_stats(&self, info_hash: &InfoHash, peer: &peer::TorrentPeer) -> TorrentStats {
218217
let mut torrents = self.torrents.write().await;
219218

220219
let torrent_entry = match torrents.entry(*info_hash) {

src/tracker/peer.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ impl TorrentPeer {
6060
AnnounceEvent::None
6161
};
6262

63+
#[allow(clippy::cast_possible_truncation)]
6364
TorrentPeer {
64-
peer_id: announce_request.peer_id,
65+
peer_id: announce_request.peer_id.clone(),
6566
peer_addr,
6667
updated: Current::now(),
67-
uploaded: NumberOfBytes(announce_request.uploaded as i64),
68-
downloaded: NumberOfBytes(announce_request.downloaded as i64),
69-
left: NumberOfBytes(announce_request.left as i64),
68+
uploaded: NumberOfBytes(i128::from(announce_request.uploaded) as i64),
69+
downloaded: NumberOfBytes(i128::from(announce_request.downloaded) as i64),
70+
left: NumberOfBytes(i128::from(announce_request.left) as i64),
7071
event,
7172
}
7273
}

src/tracker/torrent.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use std::time::Duration;
44
use aquatic_udp_protocol::AnnounceEvent;
55
use serde::{Deserialize, Serialize};
66

7-
use super::peer::TorrentPeer;
7+
use super::peer;
88
use crate::protocol::clock::{Current, TimeNow};
99
use crate::protocol::common::{PeerId, MAX_SCRAPE_TORRENTS};
1010

1111
#[derive(Serialize, Deserialize, Clone, Debug)]
1212
pub struct TorrentEntry {
1313
#[serde(skip)]
14-
pub peers: std::collections::BTreeMap<PeerId, TorrentPeer>,
14+
pub peers: std::collections::BTreeMap<PeerId, peer::TorrentPeer>,
1515
pub completed: u32,
1616
}
1717

@@ -25,7 +25,7 @@ impl TorrentEntry {
2525
}
2626

2727
// Update peer and return completed (times torrent has been downloaded)
28-
pub fn update_peer(&mut self, peer: &TorrentPeer) -> bool {
28+
pub fn update_peer(&mut self, peer: &peer::TorrentPeer) -> bool {
2929
let mut did_torrent_stats_change: bool = false;
3030

3131
match peer.event {
@@ -49,7 +49,7 @@ impl TorrentEntry {
4949
}
5050

5151
#[must_use]
52-
pub fn get_peers(&self, client_addr: Option<&SocketAddr>) -> Vec<&TorrentPeer> {
52+
pub fn get_peers(&self, client_addr: Option<&SocketAddr>) -> Vec<&peer::TorrentPeer> {
5353
self.peers
5454
.values()
5555
.filter(|peer| match client_addr {
@@ -118,16 +118,16 @@ mod tests {
118118

119119
use crate::protocol::clock::{Current, DurationSinceUnixEpoch, Stopped, StoppedTime, Time, Working};
120120
use crate::protocol::common::PeerId;
121-
use crate::tracker::peer::TorrentPeer;
121+
use crate::tracker::peer;
122122
use crate::tracker::torrent::TorrentEntry;
123123

124124
struct TorrentPeerBuilder {
125-
peer: TorrentPeer,
125+
peer: peer::TorrentPeer,
126126
}
127127

128128
impl TorrentPeerBuilder {
129129
pub fn default() -> TorrentPeerBuilder {
130-
let default_peer = TorrentPeer {
130+
let default_peer = peer::TorrentPeer {
131131
peer_id: PeerId([0u8; 20]),
132132
peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080),
133133
updated: Current::now(),
@@ -164,14 +164,14 @@ mod tests {
164164
self
165165
}
166166

167-
pub fn into(self) -> TorrentPeer {
167+
pub fn into(self) -> peer::TorrentPeer {
168168
self.peer
169169
}
170170
}
171171

172172
/// A torrent seeder is a peer with 0 bytes left to download which
173173
/// has not announced it has stopped
174-
fn a_torrent_seeder() -> TorrentPeer {
174+
fn a_torrent_seeder() -> peer::TorrentPeer {
175175
TorrentPeerBuilder::default()
176176
.with_number_of_bytes_left(0)
177177
.with_event_completed()
@@ -180,7 +180,7 @@ mod tests {
180180

181181
/// A torrent leecher is a peer that is not a seeder.
182182
/// Leecher: left > 0 OR event = Stopped
183-
fn a_torrent_leecher() -> TorrentPeer {
183+
fn a_torrent_leecher() -> peer::TorrentPeer {
184184
TorrentPeerBuilder::default()
185185
.with_number_of_bytes_left(1)
186186
.with_event_completed()

src/udp/handlers.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ use aquatic_udp_protocol::{
88

99
use super::connection_cookie::{check_connection_cookie, from_connection_id, into_connection_id, make_connection_cookie};
1010
use crate::protocol::common::{InfoHash, MAX_SCRAPE_TORRENTS};
11-
use crate::tracker::peer::TorrentPeer;
1211
use crate::tracker::statistics::TrackerStatisticsEvent;
1312
use crate::tracker::torrent::TorrentError;
14-
use crate::tracker::TorrentTracker;
13+
use crate::tracker::{peer, TorrentTracker};
1514
use crate::udp::errors::ServerError;
1615
use crate::udp::request::AnnounceRequestWrapper;
1716

@@ -106,7 +105,7 @@ pub async fn handle_announce(
106105

107106
authenticate(&wrapped_announce_request.info_hash, tracker.clone()).await?;
108107

109-
let peer = TorrentPeer::from_udp_announce_request(
108+
let peer = peer::TorrentPeer::from_udp_announce_request(
110109
&wrapped_announce_request.announce_request,
111110
remote_addr.ip(),
112111
tracker.config.get_ext_ip(),
@@ -255,9 +254,8 @@ mod tests {
255254
use crate::config::Configuration;
256255
use crate::protocol::clock::{Current, Time};
257256
use crate::protocol::common::PeerId;
258-
use crate::tracker::peer::TorrentPeer;
259257
use crate::tracker::statistics::StatsTracker;
260-
use crate::tracker::{mode, TorrentTracker};
258+
use crate::tracker::{mode, peer, TorrentTracker};
261259

262260
fn default_tracker_config() -> Arc<Configuration> {
263261
Arc::new(Configuration::default())
@@ -304,12 +302,12 @@ mod tests {
304302
}
305303

306304
struct TorrentPeerBuilder {
307-
peer: TorrentPeer,
305+
peer: peer::TorrentPeer,
308306
}
309307

310308
impl TorrentPeerBuilder {
311309
pub fn default() -> TorrentPeerBuilder {
312-
let default_peer = TorrentPeer {
310+
let default_peer = peer::TorrentPeer {
313311
peer_id: PeerId([255u8; 20]),
314312
peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1)), 8080),
315313
updated: Current::now(),
@@ -336,7 +334,7 @@ mod tests {
336334
self
337335
}
338336

339-
pub fn into(self) -> TorrentPeer {
337+
pub fn into(self) -> peer::TorrentPeer {
340338
self.peer
341339
}
342340
}

0 commit comments

Comments
 (0)