Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Clippy Pedantic Warnings and Structure Rename #115

Merged
merged 45 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7eb25a0
refactor: remove internal mod exports
da2ce7 Nov 23, 2022
81c4129
vscode: clippy padantic warnings
da2ce7 Nov 23, 2022
2b88ce5
clippy: auto fix
da2ce7 Nov 23, 2022
f74c933
clippy: fix src/http/response.rs
da2ce7 Nov 23, 2022
a9f760b
clippy: fix src/http/request.rs
da2ce7 Nov 23, 2022
21b6e77
clippy: fix (ignore) src/config.rs
da2ce7 Nov 23, 2022
941e982
clippy: fix src/api/resources/auth_key_resource.rs
da2ce7 Nov 23, 2022
a433c82
clippy: fix src/api/server.rs
da2ce7 Nov 23, 2022
2ba7489
clippy: fix src/protocol/common.rs
da2ce7 Nov 23, 2022
8e3115f
clippy: fix src/config.rs
da2ce7 Nov 23, 2022
87160bd
clippy: fix src/databases/database.rs
da2ce7 Nov 23, 2022
38eabc4
clippy: fix src/databases/mysql.rs
da2ce7 Nov 23, 2022
be6676a
clippy: fix src/databases/sqlite.rs
da2ce7 Nov 23, 2022
b5ce7e9
clippy: fix src/http/filters.rs
da2ce7 Nov 23, 2022
75bef77
clippy: fix src/http/handlers.rs
da2ce7 Nov 23, 2022
208b10e
clippy: fix src/http/server.rs
da2ce7 Nov 23, 2022
577ddb9
clippy: fix src/jobs/http_tracker.rs
da2ce7 Nov 23, 2022
d092580
clippy: fix src/jobs/torrent_cleanup.rs
da2ce7 Nov 23, 2022
9adbfd1
clippy: fix src/logging.rs
da2ce7 Nov 23, 2022
c78404f
clippy: fix src/protocol/clock/mod.rs
da2ce7 Nov 23, 2022
5ea7c0d
clippy: fix src/protocol/clock/time_extent.rs
da2ce7 Nov 23, 2022
d03269a
clippy: fix src/protocol/utils.rs
da2ce7 Nov 23, 2022
efed1bc
clippy: fix src/setup.rs
da2ce7 Nov 24, 2022
58e5909
clippy: fix src/tracker/key.rs
da2ce7 Nov 24, 2022
363b21a
clippy: fix src/tracker/mode.rs
da2ce7 Nov 24, 2022
0f281c3
clippy: fix src/tracker/peer.rs
da2ce7 Nov 24, 2022
3c22323
clippy: fix src/tracker/statistics.rs
da2ce7 Nov 24, 2022
143a11e
refactor: cleanup src/tracker/statistics.rs naming
da2ce7 Nov 24, 2022
81e72da
clippy: fix src/tracker/torrent.rs
da2ce7 Nov 24, 2022
78221b6
clippy: fix src/tracker/mod.rs
da2ce7 Nov 24, 2022
4a34f68
clippy: fix src/udp/connection_cookie.rs
da2ce7 Nov 25, 2022
6e2a342
clippy: fix src/databases/database.rs
da2ce7 Nov 25, 2022
0a7d927
clippy: fix src/jobs/tracker_api.rs
da2ce7 Nov 25, 2022
220f83a
clippy: fix src/udp/handlers.rs
da2ce7 Nov 25, 2022
aa30bb1
clippy: fix src/udp/request.rs
da2ce7 Nov 25, 2022
436a0c1
clippy: fix src/udp/server.rs
da2ce7 Nov 25, 2022
6564c10
clippy: fix src/protocol/crypto.rs
da2ce7 Nov 25, 2022
baba21b
clippy: fix tests/udp.rs
da2ce7 Nov 25, 2022
0d162a1
refactor: correct naming of structs and enums
da2ce7 Nov 28, 2022
ec21df9
rename: Key::Auth to auth::Key
da2ce7 Nov 28, 2022
3645271
refactor: rename inside databases
da2ce7 Nov 28, 2022
32eb44b
refactor: rename inside http
da2ce7 Nov 28, 2022
49a6acb
ci: clippy warning as errors
da2ce7 Nov 23, 2022
01e71bf
clippy: fix src/tracker/peer.rs
da2ce7 Nov 30, 2022
0f075e4
refactor: src/api/resource(s)
da2ce7 Nov 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test_build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets
args: --all-targets -- -D clippy::pedantic
- uses: taiki-e/install-action@cargo-llvm-cov
- uses: taiki-e/install-action@nextest
- name: Run Tests
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
"editor.formatOnSave": true
},
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.checkOnSave.allTargets": true,
"rust-analyzer.checkOnSave.extraArgs": ["--","-W","clippy::pedantic"],
}
1 change: 1 addition & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"bencode",
"binascii",
"Bitflu",
"bools",
"bufs",
"byteorder",
"canonicalize",
Expand Down
2 changes: 1 addition & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod resources;
pub mod resource;
pub mod server;
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ use std::convert::From;

use serde::{Deserialize, Serialize};

use crate::key::AuthKey;
use crate::protocol::clock::DurationSinceUnixEpoch;
use crate::tracker::auth;

#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct AuthKeyResource {
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct AuthKey {
pub key: String,
pub valid_until: Option<u64>,
}

impl From<AuthKeyResource> for AuthKey {
fn from(auth_key_resource: AuthKeyResource) -> Self {
AuthKey {
impl From<AuthKey> for auth::Key {
fn from(auth_key_resource: AuthKey) -> Self {
auth::Key {
key: auth_key_resource.key,
valid_until: auth_key_resource
.valid_until
Expand All @@ -22,9 +22,9 @@ impl From<AuthKeyResource> for AuthKey {
}
}

impl From<AuthKey> for AuthKeyResource {
fn from(auth_key: AuthKey) -> Self {
AuthKeyResource {
impl From<auth::Key> for AuthKey {
fn from(auth_key: auth::Key) -> Self {
AuthKey {
key: auth_key.key,
valid_until: auth_key.valid_until.map(|valid_until| valid_until.as_secs()),
}
Expand All @@ -35,50 +35,50 @@ impl From<AuthKey> for AuthKeyResource {
mod tests {
use std::time::Duration;

use super::AuthKeyResource;
use crate::key::AuthKey;
use crate::protocol::clock::{DefaultClock, TimeNow};
use super::AuthKey;
use crate::protocol::clock::{Current, TimeNow};
use crate::tracker::auth;

#[test]
fn it_should_be_convertible_into_an_auth_key() {
let duration_in_secs = 60;

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

assert_eq!(
AuthKey::from(auth_key_resource),
AuthKey {
auth::Key::from(auth_key_resource),
auth::Key {
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line
valid_until: Some(DefaultClock::add(&Duration::new(duration_in_secs, 0)).unwrap())
valid_until: Some(Current::add(&Duration::new(duration_in_secs, 0)).unwrap())
}
)
);
}

#[test]
fn it_should_be_convertible_from_an_auth_key() {
let duration_in_secs = 60;

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

assert_eq!(
AuthKeyResource::from(auth_key),
AuthKeyResource {
AuthKey::from(auth_key),
AuthKey {
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line
valid_until: Some(duration_in_secs)
}
)
);
}

#[test]
fn it_should_be_convertible_into_json() {
assert_eq!(
serde_json::to_string(&AuthKeyResource {
serde_json::to_string(&AuthKey {
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line
valid_until: Some(60)
})
Expand Down
13 changes: 13 additions & 0 deletions src/api/resource/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! These are the Rest API resources.
//!
//! WIP. Not all endpoints have their resource structs.
//!
//! - [x] `AuthKeys`
//! - [ ] `Torrent`, `ListItem`, `Peer`, `PeerId`
//! - [ ] `StatsResource`
//! - [ ] ...

pub mod auth_key;
pub mod peer;
pub mod stats;
pub mod torrent;
47 changes: 47 additions & 0 deletions src/api/resource/peer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use serde::{Deserialize, Serialize};

use crate::tracker;

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct Peer {
pub peer_id: Id,
pub peer_addr: String,
#[deprecated(since = "2.0.0", note = "please use `updated_milliseconds_ago` instead")]
pub updated: u128,
pub updated_milliseconds_ago: u128,
pub uploaded: i64,
pub downloaded: i64,
pub left: i64,
pub event: String,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct Id {
pub id: Option<String>,
pub client: Option<String>,
}

impl From<tracker::peer::Id> for Id {
fn from(peer_id: tracker::peer::Id) -> Self {
Id {
id: peer_id.get_id(),
client: peer_id.get_client_name().map(std::string::ToString::to_string),
}
}
}

impl From<tracker::peer::Peer> for Peer {
#[allow(deprecated)]
fn from(peer: tracker::peer::Peer) -> Self {
Peer {
peer_id: Id::from(peer.peer_id),
peer_addr: peer.peer_addr.to_string(),
updated: peer.updated.as_millis(),
updated_milliseconds_ago: peer.updated.as_millis(),
uploaded: peer.uploaded.0,
downloaded: peer.downloaded.0,
left: peer.left.0,
event: format!("{:?}", peer.event),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct StatsResource {
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct Stats {
pub torrents: u32,
pub seeders: u32,
pub completed: u32,
Expand Down
21 changes: 21 additions & 0 deletions src/api/resource/torrent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct Torrent {
pub info_hash: String,
pub seeders: u32,
pub completed: u32,
pub leechers: u32,
#[serde(skip_serializing_if = "Option::is_none")]
pub peers: Option<Vec<super::peer::Peer>>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct ListItem {
pub info_hash: String,
pub seeders: u32,
pub completed: u32,
pub leechers: u32,
// todo: this is always None. Remove field from endpoint?
pub peers: Option<Vec<super::peer::Peer>>,
}
11 changes: 0 additions & 11 deletions src/api/resources/mod.rs

This file was deleted.

67 changes: 0 additions & 67 deletions src/api/resources/torrent_resource.rs

This file was deleted.

Loading