Skip to content

Commit 5ce46ed

Browse files
committed
Merge torrust#1070: Extract new package bittorrent-tracker-client
e01995c fix: tracker checker execution in CI (Jose Celano) a5822cd fix: cargo machete errors (Jose Celano) 31ac6cf refactor: use extracted bittorrent-tracker-client (Jose Celano) 093e8c9 feat: extract new package bittorrent-tracker-client (Jose Celano) Pull request description: This will allow other projects to reuse the tracker lib and console clients. ### Subtasks - [x] Extract the new package. - [x] Use the new package in the main app. ACKs for top commit: josecelano: ACK e01995c Tree-SHA512: eca269f9192d154a5f84c87b281017bf2312ccfcafcab12dbf7c3657d734faf946029ae2b997035bfb56f74c3086bd84d40251831585321fab2a3fc2a9a84a97
2 parents 25d9487 + e01995c commit 5ce46ed

Some content is hidden

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

49 files changed

+368
-96
lines changed

Cargo.lock

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

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ axum-client-ip = "0"
3737
axum-extra = { version = "0", features = ["query"] }
3838
axum-server = { version = "0", features = ["tls-rustls"] }
3939
bittorrent-primitives = "0.1.0"
40+
bittorrent-tracker-client = { version = "3.0.0-develop", path = "packages/tracker-client" }
4041
camino = { version = "1", features = ["serde", "serde1"] }
4142
chrono = { version = "0", default-features = false, features = ["clock"] }
4243
clap = { version = "4", features = ["derive", "env"] }
@@ -46,7 +47,6 @@ derive_more = { version = "1", features = ["as_ref", "constructor", "from"] }
4647
figment = "0"
4748
futures = "0"
4849
futures-util = "0"
49-
hex-literal = "0"
5050
http-body = "1"
5151
hyper = "1"
5252
hyper-util = { version = "0", features = ["http1", "http2", "tokio"] }
@@ -100,6 +100,7 @@ members = [
100100
"packages/primitives",
101101
"packages/test-helpers",
102102
"packages/torrent-repository",
103+
"packages/tracker-client",
103104
]
104105

105106
[profile.dev]

packages/tracker-client/Cargo.toml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[package]
2+
description = "A library with the primitive types shared by the Torrust tracker packages."
3+
keywords = ["bittorrent", "client", "tracker"]
4+
license = "LGPL-3.0"
5+
name = "bittorrent-tracker-client"
6+
readme = "README.md"
7+
8+
authors.workspace = true
9+
documentation.workspace = true
10+
edition.workspace = true
11+
homepage.workspace = true
12+
publish.workspace = true
13+
repository.workspace = true
14+
rust-version.workspace = true
15+
version.workspace = true
16+
17+
[dependencies]
18+
anyhow = "1"
19+
aquatic_udp_protocol = "0"
20+
bittorrent-primitives = "0.1.0"
21+
clap = { version = "4", features = ["derive", "env"] }
22+
derive_more = { version = "1", features = ["as_ref", "constructor", "from"] }
23+
futures = "0"
24+
hex-literal = "0"
25+
hyper = "1"
26+
percent-encoding = "2"
27+
reqwest = { version = "0", features = ["json"] }
28+
serde = { version = "1", features = ["derive"] }
29+
serde_bencode = "0"
30+
serde_bytes = "0"
31+
serde_json = { version = "1", features = ["preserve_order"] }
32+
serde_repr = "0"
33+
thiserror = "1"
34+
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
35+
torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" }
36+
torrust-tracker-located-error = { version = "3.0.0-develop", path = "../located-error" }
37+
torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" }
38+
tracing = "0"
39+
tracing-subscriber = { version = "0", features = ["json"] }
40+
url = { version = "2", features = ["serde"] }
41+
zerocopy = "0.7"
42+
43+
[package.metadata.cargo-machete]
44+
ignored = ["serde_bytes"]

packages/tracker-client/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# BitTorrent Tracker Client
2+
3+
A library an console applications to interact with a BitTorrent tracker.
4+
5+
> **Disclaimer**: This project is actively under development. We’re currently extracting and refining common types from the ][Torrust Tracker](https://github.com/torrust/torrust-tracker) to make them available to the BitTorrent community in Rust. While these types are functional, they are not yet ready for use in production or third-party projects.
6+
7+
## License
8+
9+
**Copyright (c) 2024 The Torrust Developers.**
10+
11+
This program is free software: you can redistribute it and/or modify it under the terms of the [GNU Lesser General Public License][LGPL_3_0] as published by the [Free Software Foundation][FSF], version 3.
12+
13+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [GNU Lesser General Public License][LGPL_3_0] for more details.
14+
15+
You should have received a copy of the *GNU Lesser General Public License* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
Some files include explicit copyright notices and/or license notices.
18+
19+
### Legacy Exception
20+
21+
For prosperity, versions of Torrust BitTorrent Tracker Client that are older than five years are automatically granted the [MIT-0][MIT_0] license in addition to the existing [LGPL-3.0-only][LGPL_3_0] license.
22+
23+
[LGPL_3_0]: ./LICENSE
24+
[MIT_0]: ./docs/licenses/LICENSE-MIT_0
25+
[FSF]: https://www.fsf.org/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
MIT No Attribution
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
software and associated documentation files (the "Software"), to deal in the Software
5+
without restriction, including without limitation the rights to use, copy, modify,
6+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
permit persons to whom the Software is furnished to do so.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
10+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
11+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
12+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
13+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
14+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

src/bin/http_tracker_client.rs packages/tracker-client/src/bin/http_tracker_client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Program to make request to HTTP trackers.
2-
use torrust_tracker::console::clients::http::app;
2+
use bittorrent_tracker_client::console::clients::http::app;
33

44
#[tokio::main]
55
async fn main() -> anyhow::Result<()> {

src/bin/tracker_checker.rs packages/tracker-client/src/bin/tracker_checker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Program to check running trackers.
2-
use torrust_tracker::console::clients::checker::app;
2+
use bittorrent_tracker_client::console::clients::checker::app;
33

44
#[tokio::main]
55
async fn main() {

src/bin/udp_tracker_client.rs packages/tracker-client/src/bin/udp_tracker_client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Program to make request to UDP trackers.
2-
use torrust_tracker::console::clients::udp::app;
2+
use bittorrent_tracker_client::console::clients::udp::app;
33

44
#[tokio::main]
55
async fn main() -> anyhow::Result<()> {

src/console/clients/checker/checks/http.rs packages/tracker-client/src/console/clients/checker/checks/http.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use serde::Serialize;
66
use url::Url;
77

88
use crate::console::clients::http::Error;
9-
use crate::shared::bit_torrent::tracker::http::client::responses::announce::Announce;
10-
use crate::shared::bit_torrent::tracker::http::client::responses::scrape;
11-
use crate::shared::bit_torrent::tracker::http::client::{requests, Client};
9+
use crate::http::client::responses::announce::Announce;
10+
use crate::http::client::responses::scrape;
11+
use crate::http::client::{requests, Client};
1212

1313
#[derive(Debug, Clone, Serialize)]
1414
pub struct Checks {

src/console/clients/http/app.rs packages/tracker-client/src/console/clients/http/app.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ use clap::{Parser, Subcommand};
2222
use reqwest::Url;
2323
use torrust_tracker_configuration::DEFAULT_TIMEOUT;
2424

25-
use crate::shared::bit_torrent::tracker::http::client::requests::announce::QueryBuilder;
26-
use crate::shared::bit_torrent::tracker::http::client::responses::announce::Announce;
27-
use crate::shared::bit_torrent::tracker::http::client::responses::scrape;
28-
use crate::shared::bit_torrent::tracker::http::client::{requests, Client};
25+
use crate::http::client::requests::announce::QueryBuilder;
26+
use crate::http::client::responses::announce::Announce;
27+
use crate::http::client::responses::scrape;
28+
use crate::http::client::{requests, Client};
2929

3030
#[derive(Parser, Debug)]
3131
#[command(author, version, about, long_about = None)]

src/console/clients/http/mod.rs packages/tracker-client/src/console/clients/http/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ use std::sync::Arc;
33
use serde::Serialize;
44
use thiserror::Error;
55

6-
use crate::shared::bit_torrent::tracker::http::client::responses::scrape::BencodeParseError;
6+
use crate::http::client::responses::scrape::BencodeParseError;
77

88
pub mod app;
99

1010
#[derive(Debug, Clone, Error, Serialize)]
1111
#[serde(into = "String")]
1212
pub enum Error {
1313
#[error("Http request did not receive a response within the timeout: {err:?}")]
14-
HttpClientError {
15-
err: crate::shared::bit_torrent::tracker::http::client::Error,
16-
},
14+
HttpClientError { err: crate::http::client::Error },
1715
#[error("Http failed to get a response at all: {err:?}")]
1816
ResponseError { err: Arc<reqwest::Error> },
1917
#[error("Failed to deserialize the bencoded response data with the error: \"{err:?}\"")]
File renamed without changes.

src/console/clients/udp/checker.rs packages/tracker-client/src/console/clients/udp/checker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use aquatic_udp_protocol::{
1010
use bittorrent_primitives::info_hash::InfoHash as TorrustInfoHash;
1111

1212
use super::Error;
13-
use crate::shared::bit_torrent::tracker::udp::client::UdpTrackerClient;
13+
use crate::udp::client::UdpTrackerClient;
1414

1515
/// A UDP Tracker client to make test requests (checks).
1616
#[derive(Debug)]

src/console/clients/udp/mod.rs packages/tracker-client/src/console/clients/udp/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use aquatic_udp_protocol::Response;
44
use serde::Serialize;
55
use thiserror::Error;
66

7-
use crate::shared::bit_torrent::tracker::udp;
7+
use crate::udp;
88

99
pub mod app;
1010
pub mod checker;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//! Console apps.
2+
pub mod clients;

src/shared/bit_torrent/tracker/http/client/mod.rs packages/tracker-client/src/http/client/mod.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use std::net::IpAddr;
55
use std::sync::Arc;
66
use std::time::Duration;
77

8+
use derive_more::Display;
89
use hyper::StatusCode;
910
use requests::{announce, scrape};
1011
use reqwest::{Response, Url};
12+
use serde::{Deserialize, Serialize};
1113
use thiserror::Error;
1214

13-
use crate::core::auth::Key;
14-
1515
#[derive(Debug, Clone, Error)]
1616
pub enum Error {
1717
#[error("Failed to Build a Http Client: {err:?}")]
@@ -202,3 +202,19 @@ impl Client {
202202
self.base_url.to_string()
203203
}
204204
}
205+
206+
/// A token used for authentication.
207+
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Display, Hash)]
208+
pub struct Key(String);
209+
210+
impl Key {
211+
#[must_use]
212+
pub fn new(value: &str) -> Self {
213+
Self(value.to_owned())
214+
}
215+
216+
#[must_use]
217+
pub fn value(&self) -> &str {
218+
&self.0
219+
}
220+
}

src/shared/bit_torrent/tracker/http/client/requests/announce.rs packages/tracker-client/src/http/client/requests/announce.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use aquatic_udp_protocol::PeerId;
66
use bittorrent_primitives::info_hash::InfoHash;
77
use serde_repr::Serialize_repr;
88

9-
use crate::shared::bit_torrent::tracker::http::{percent_encode_byte_array, ByteArray20};
9+
use crate::http::{percent_encode_byte_array, ByteArray20};
1010

1111
pub struct Query {
1212
pub info_hash: ByteArray20,

src/shared/bit_torrent/tracker/http/client/requests/scrape.rs packages/tracker-client/src/http/client/requests/scrape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::str::FromStr;
44

55
use bittorrent_primitives::info_hash::InfoHash;
66

7-
use crate::shared::bit_torrent::tracker::http::{percent_encode_byte_array, ByteArray20};
7+
use crate::http::{percent_encode_byte_array, ByteArray20};
88

99
pub struct Query {
1010
pub info_hash: Vec<ByteArray20>,

src/shared/bit_torrent/tracker/http/client/responses/scrape.rs packages/tracker-client/src/http/client/responses/scrape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::ser::SerializeMap;
66
use serde::{Deserialize, Serialize, Serializer};
77
use serde_bencode::value::Value;
88

9-
use crate::shared::bit_torrent::tracker::http::{ByteArray20, InfoHash};
9+
use crate::http::{ByteArray20, InfoHash};
1010

1111
#[derive(Debug, PartialEq, Default, Deserialize)]
1212
pub struct Response {

src/shared/bit_torrent/tracker/http/mod.rs packages/tracker-client/src/http/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod client;
2+
pub mod url_encoding;
23

34
use percent_encoding::NON_ALPHANUMERIC;
45

0 commit comments

Comments
 (0)