Skip to content

Commit b1150d5

Browse files
committed
Merge #115: Fix Clippy Pedantic Warnings and Structure Rename
0f075e4 refactor: src/api/resource(s) (Cameron Garnham) 01e71bf clippy: fix src/tracker/peer.rs (Cameron Garnham) 49a6acb ci: clippy warning as errors (Cameron Garnham) 32eb44b refactor: rename inside http (Cameron Garnham) 3645271 refactor: rename inside databases (Cameron Garnham) ec21df9 rename: Key::Auth to auth::Key (Cameron Garnham) 0d162a1 refactor: correct naming of structs and enums (Cameron Garnham) baba21b clippy: fix tests/udp.rs (Cameron Garnham) 6564c10 clippy: fix src/protocol/crypto.rs (Cameron Garnham) 436a0c1 clippy: fix src/udp/server.rs (Cameron Garnham) aa30bb1 clippy: fix src/udp/request.rs (Cameron Garnham) 220f83a clippy: fix src/udp/handlers.rs (Cameron Garnham) 0a7d927 clippy: fix src/jobs/tracker_api.rs (Cameron Garnham) 6e2a342 clippy: fix src/databases/database.rs (Cameron Garnham) 4a34f68 clippy: fix src/udp/connection_cookie.rs (Cameron Garnham) 78221b6 clippy: fix src/tracker/mod.rs (Cameron Garnham) 81e72da clippy: fix src/tracker/torrent.rs (Cameron Garnham) 143a11e refactor: cleanup src/tracker/statistics.rs naming (Cameron Garnham) 3c22323 clippy: fix src/tracker/statistics.rs (Cameron Garnham) 0f281c3 clippy: fix src/tracker/peer.rs (Cameron Garnham) 363b21a clippy: fix src/tracker/mode.rs (Cameron Garnham) 58e5909 clippy: fix src/tracker/key.rs (Cameron Garnham) efed1bc clippy: fix src/setup.rs (Cameron Garnham) d03269a clippy: fix src/protocol/utils.rs (Cameron Garnham) 5ea7c0d clippy: fix src/protocol/clock/time_extent.rs (Cameron Garnham) c78404f clippy: fix src/protocol/clock/mod.rs (Cameron Garnham) 9adbfd1 clippy: fix src/logging.rs (Cameron Garnham) d092580 clippy: fix src/jobs/torrent_cleanup.rs (Cameron Garnham) 577ddb9 clippy: fix src/jobs/http_tracker.rs (Cameron Garnham) 208b10e clippy: fix src/http/server.rs (Cameron Garnham) 75bef77 clippy: fix src/http/handlers.rs (Cameron Garnham) b5ce7e9 clippy: fix src/http/filters.rs (Cameron Garnham) be6676a clippy: fix src/databases/sqlite.rs (Cameron Garnham) 38eabc4 clippy: fix src/databases/mysql.rs (Cameron Garnham) 87160bd clippy: fix src/databases/database.rs (Cameron Garnham) 8e3115f clippy: fix src/config.rs (Cameron Garnham) 2ba7489 clippy: fix src/protocol/common.rs (Cameron Garnham) a433c82 clippy: fix src/api/server.rs (Cameron Garnham) 941e982 clippy: fix src/api/resources/auth_key_resource.rs (Cameron Garnham) 21b6e77 clippy: fix (ignore) src/config.rs (Cameron Garnham) a9f760b clippy: fix src/http/request.rs (Cameron Garnham) f74c933 clippy: fix src/http/response.rs (Cameron Garnham) 2b88ce5 clippy: auto fix (Cameron Garnham) 81c4129 vscode: clippy padantic warnings (Cameron Garnham) 7eb25a0 refactor: remove internal mod exports (Cameron Garnham) Pull request description: Massive Rename of Structs and Fixing of Many Pedantic Clippy Warnings. ACKs for top commit: da2ce7: ACK 0f075e4 Tree-SHA512: 6d1343d889cc5a15da9ab9950497566dd22e9f1cac7e30ee00ecbc8bce65133bc8ab47b9a183edafe3c3bdaf3c922f5d170b69c04644788466017f887a581fbf
2 parents 4d788d2 + 0f075e4 commit b1150d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1772
-1643
lines changed

.github/workflows/test_build_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
uses: actions-rs/cargo@v1
4646
with:
4747
command: clippy
48-
args: --all-targets
48+
args: --all-targets -- -D clippy::pedantic
4949
- uses: taiki-e/install-action@cargo-llvm-cov
5050
- uses: taiki-e/install-action@nextest
5151
- name: Run Tests

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
"editor.formatOnSave": true
44
},
55
"rust-analyzer.checkOnSave.command": "clippy",
6+
"rust-analyzer.checkOnSave.allTargets": true,
7+
"rust-analyzer.checkOnSave.extraArgs": ["--","-W","clippy::pedantic"],
68
}

cSpell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"bencode",
88
"binascii",
99
"Bitflu",
10+
"bools",
1011
"bufs",
1112
"byteorder",
1213
"canonicalize",

src/api/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pub mod resources;
1+
pub mod resource;
22
pub mod server;

src/api/resources/auth_key_resource.rs renamed to src/api/resource/auth_key.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ use std::convert::From;
22

33
use serde::{Deserialize, Serialize};
44

5-
use crate::key::AuthKey;
65
use crate::protocol::clock::DurationSinceUnixEpoch;
6+
use crate::tracker::auth;
77

8-
#[derive(Serialize, Deserialize, Debug, PartialEq)]
9-
pub struct AuthKeyResource {
8+
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
9+
pub struct AuthKey {
1010
pub key: String,
1111
pub valid_until: Option<u64>,
1212
}
1313

14-
impl From<AuthKeyResource> for AuthKey {
15-
fn from(auth_key_resource: AuthKeyResource) -> Self {
16-
AuthKey {
14+
impl From<AuthKey> for auth::Key {
15+
fn from(auth_key_resource: AuthKey) -> Self {
16+
auth::Key {
1717
key: auth_key_resource.key,
1818
valid_until: auth_key_resource
1919
.valid_until
@@ -22,9 +22,9 @@ impl From<AuthKeyResource> for AuthKey {
2222
}
2323
}
2424

25-
impl From<AuthKey> for AuthKeyResource {
26-
fn from(auth_key: AuthKey) -> Self {
27-
AuthKeyResource {
25+
impl From<auth::Key> for AuthKey {
26+
fn from(auth_key: auth::Key) -> Self {
27+
AuthKey {
2828
key: auth_key.key,
2929
valid_until: auth_key.valid_until.map(|valid_until| valid_until.as_secs()),
3030
}
@@ -35,50 +35,50 @@ impl From<AuthKey> for AuthKeyResource {
3535
mod tests {
3636
use std::time::Duration;
3737

38-
use super::AuthKeyResource;
39-
use crate::key::AuthKey;
40-
use crate::protocol::clock::{DefaultClock, TimeNow};
38+
use super::AuthKey;
39+
use crate::protocol::clock::{Current, TimeNow};
40+
use crate::tracker::auth;
4141

4242
#[test]
4343
fn it_should_be_convertible_into_an_auth_key() {
4444
let duration_in_secs = 60;
4545

46-
let auth_key_resource = AuthKeyResource {
46+
let auth_key_resource = AuthKey {
4747
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line
4848
valid_until: Some(duration_in_secs),
4949
};
5050

5151
assert_eq!(
52-
AuthKey::from(auth_key_resource),
53-
AuthKey {
52+
auth::Key::from(auth_key_resource),
53+
auth::Key {
5454
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line
55-
valid_until: Some(DefaultClock::add(&Duration::new(duration_in_secs, 0)).unwrap())
55+
valid_until: Some(Current::add(&Duration::new(duration_in_secs, 0)).unwrap())
5656
}
57-
)
57+
);
5858
}
5959

6060
#[test]
6161
fn it_should_be_convertible_from_an_auth_key() {
6262
let duration_in_secs = 60;
6363

64-
let auth_key = AuthKey {
64+
let auth_key = auth::Key {
6565
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line
66-
valid_until: Some(DefaultClock::add(&Duration::new(duration_in_secs, 0)).unwrap()),
66+
valid_until: Some(Current::add(&Duration::new(duration_in_secs, 0)).unwrap()),
6767
};
6868

6969
assert_eq!(
70-
AuthKeyResource::from(auth_key),
71-
AuthKeyResource {
70+
AuthKey::from(auth_key),
71+
AuthKey {
7272
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line
7373
valid_until: Some(duration_in_secs)
7474
}
75-
)
75+
);
7676
}
7777

7878
#[test]
7979
fn it_should_be_convertible_into_json() {
8080
assert_eq!(
81-
serde_json::to_string(&AuthKeyResource {
81+
serde_json::to_string(&AuthKey {
8282
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line
8383
valid_until: Some(60)
8484
})

src/api/resource/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! These are the Rest API resources.
2+
//!
3+
//! WIP. Not all endpoints have their resource structs.
4+
//!
5+
//! - [x] `AuthKeys`
6+
//! - [ ] `Torrent`, `ListItem`, `Peer`, `PeerId`
7+
//! - [ ] `StatsResource`
8+
//! - [ ] ...
9+
10+
pub mod auth_key;
11+
pub mod peer;
12+
pub mod stats;
13+
pub mod torrent;

src/api/resource/peer.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use crate::tracker;
4+
5+
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
6+
pub struct Peer {
7+
pub peer_id: Id,
8+
pub peer_addr: String,
9+
#[deprecated(since = "2.0.0", note = "please use `updated_milliseconds_ago` instead")]
10+
pub updated: u128,
11+
pub updated_milliseconds_ago: u128,
12+
pub uploaded: i64,
13+
pub downloaded: i64,
14+
pub left: i64,
15+
pub event: String,
16+
}
17+
18+
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
19+
pub struct Id {
20+
pub id: Option<String>,
21+
pub client: Option<String>,
22+
}
23+
24+
impl From<tracker::peer::Id> for Id {
25+
fn from(peer_id: tracker::peer::Id) -> Self {
26+
Id {
27+
id: peer_id.get_id(),
28+
client: peer_id.get_client_name().map(std::string::ToString::to_string),
29+
}
30+
}
31+
}
32+
33+
impl From<tracker::peer::Peer> for Peer {
34+
#[allow(deprecated)]
35+
fn from(peer: tracker::peer::Peer) -> Self {
36+
Peer {
37+
peer_id: Id::from(peer.peer_id),
38+
peer_addr: peer.peer_addr.to_string(),
39+
updated: peer.updated.as_millis(),
40+
updated_milliseconds_ago: peer.updated.as_millis(),
41+
uploaded: peer.uploaded.0,
42+
downloaded: peer.downloaded.0,
43+
left: peer.left.0,
44+
event: format!("{:?}", peer.event),
45+
}
46+
}
47+
}

src/api/resources/stats_resource.rs renamed to src/api/resource/stats.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

3-
#[derive(Serialize, Deserialize, Debug, PartialEq)]
4-
pub struct StatsResource {
3+
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
4+
pub struct Stats {
55
pub torrents: u32,
66
pub seeders: u32,
77
pub completed: u32,

src/api/resource/torrent.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
4+
pub struct Torrent {
5+
pub info_hash: String,
6+
pub seeders: u32,
7+
pub completed: u32,
8+
pub leechers: u32,
9+
#[serde(skip_serializing_if = "Option::is_none")]
10+
pub peers: Option<Vec<super::peer::Peer>>,
11+
}
12+
13+
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
14+
pub struct ListItem {
15+
pub info_hash: String,
16+
pub seeders: u32,
17+
pub completed: u32,
18+
pub leechers: u32,
19+
// todo: this is always None. Remove field from endpoint?
20+
pub peers: Option<Vec<super::peer::Peer>>,
21+
}

src/api/resources/mod.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)