Skip to content

Commit

Permalink
Merge #1070: Extract new package bittorrent-tracker-client
Browse files Browse the repository at this point in the history
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
  • Loading branch information
josecelano committed Nov 4, 2024
2 parents 25d9487 + e01995c commit 5ce46ed
Show file tree
Hide file tree
Showing 49 changed files with 368 additions and 96 deletions.
32 changes: 31 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ axum-client-ip = "0"
axum-extra = { version = "0", features = ["query"] }
axum-server = { version = "0", features = ["tls-rustls"] }
bittorrent-primitives = "0.1.0"
bittorrent-tracker-client = { version = "3.0.0-develop", path = "packages/tracker-client" }
camino = { version = "1", features = ["serde", "serde1"] }
chrono = { version = "0", default-features = false, features = ["clock"] }
clap = { version = "4", features = ["derive", "env"] }
Expand All @@ -46,7 +47,6 @@ derive_more = { version = "1", features = ["as_ref", "constructor", "from"] }
figment = "0"
futures = "0"
futures-util = "0"
hex-literal = "0"
http-body = "1"
hyper = "1"
hyper-util = { version = "0", features = ["http1", "http2", "tokio"] }
Expand Down Expand Up @@ -100,6 +100,7 @@ members = [
"packages/primitives",
"packages/test-helpers",
"packages/torrent-repository",
"packages/tracker-client",
]

[profile.dev]
Expand Down
44 changes: 44 additions & 0 deletions packages/tracker-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
description = "A library with the primitive types shared by the Torrust tracker packages."
keywords = ["bittorrent", "client", "tracker"]
license = "LGPL-3.0"
name = "bittorrent-tracker-client"
readme = "README.md"

authors.workspace = true
documentation.workspace = true
edition.workspace = true
homepage.workspace = true
publish.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
anyhow = "1"
aquatic_udp_protocol = "0"
bittorrent-primitives = "0.1.0"
clap = { version = "4", features = ["derive", "env"] }
derive_more = { version = "1", features = ["as_ref", "constructor", "from"] }
futures = "0"
hex-literal = "0"
hyper = "1"
percent-encoding = "2"
reqwest = { version = "0", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_bencode = "0"
serde_bytes = "0"
serde_json = { version = "1", features = ["preserve_order"] }
serde_repr = "0"
thiserror = "1"
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" }
torrust-tracker-located-error = { version = "3.0.0-develop", path = "../located-error" }
torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" }
tracing = "0"
tracing-subscriber = { version = "0", features = ["json"] }
url = { version = "2", features = ["serde"] }
zerocopy = "0.7"

[package.metadata.cargo-machete]
ignored = ["serde_bytes"]
25 changes: 25 additions & 0 deletions packages/tracker-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# BitTorrent Tracker Client

A library an console applications to interact with a BitTorrent tracker.

> **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.
## License

**Copyright (c) 2024 The Torrust Developers.**

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.

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.

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/>.

Some files include explicit copyright notices and/or license notices.

### Legacy Exception

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.

[LGPL_3_0]: ./LICENSE
[MIT_0]: ./docs/licenses/LICENSE-MIT_0
[FSF]: https://www.fsf.org/
14 changes: 14 additions & 0 deletions packages/tracker-client/docs/licenses/LICENSE-MIT_0
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
MIT No Attribution

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Program to make request to HTTP trackers.
use torrust_tracker::console::clients::http::app;
use bittorrent_tracker_client::console::clients::http::app;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Program to check running trackers.
use torrust_tracker::console::clients::checker::app;
use bittorrent_tracker_client::console::clients::checker::app;

#[tokio::main]
async fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Program to make request to UDP trackers.
use torrust_tracker::console::clients::udp::app;
use bittorrent_tracker_client::console::clients::udp::app;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use serde::Serialize;
use url::Url;

use crate::console::clients::http::Error;
use crate::shared::bit_torrent::tracker::http::client::responses::announce::Announce;
use crate::shared::bit_torrent::tracker::http::client::responses::scrape;
use crate::shared::bit_torrent::tracker::http::client::{requests, Client};
use crate::http::client::responses::announce::Announce;
use crate::http::client::responses::scrape;
use crate::http::client::{requests, Client};

#[derive(Debug, Clone, Serialize)]
pub struct Checks {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use clap::{Parser, Subcommand};
use reqwest::Url;
use torrust_tracker_configuration::DEFAULT_TIMEOUT;

use crate::shared::bit_torrent::tracker::http::client::requests::announce::QueryBuilder;
use crate::shared::bit_torrent::tracker::http::client::responses::announce::Announce;
use crate::shared::bit_torrent::tracker::http::client::responses::scrape;
use crate::shared::bit_torrent::tracker::http::client::{requests, Client};
use crate::http::client::requests::announce::QueryBuilder;
use crate::http::client::responses::announce::Announce;
use crate::http::client::responses::scrape;
use crate::http::client::{requests, Client};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ use std::sync::Arc;
use serde::Serialize;
use thiserror::Error;

use crate::shared::bit_torrent::tracker::http::client::responses::scrape::BencodeParseError;
use crate::http::client::responses::scrape::BencodeParseError;

pub mod app;

#[derive(Debug, Clone, Error, Serialize)]
#[serde(into = "String")]
pub enum Error {
#[error("Http request did not receive a response within the timeout: {err:?}")]
HttpClientError {
err: crate::shared::bit_torrent::tracker::http::client::Error,
},
HttpClientError { err: crate::http::client::Error },
#[error("Http failed to get a response at all: {err:?}")]
ResponseError { err: Arc<reqwest::Error> },
#[error("Failed to deserialize the bencoded response data with the error: \"{err:?}\"")]
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use aquatic_udp_protocol::{
use bittorrent_primitives::info_hash::InfoHash as TorrustInfoHash;

use super::Error;
use crate::shared::bit_torrent::tracker::udp::client::UdpTrackerClient;
use crate::udp::client::UdpTrackerClient;

/// A UDP Tracker client to make test requests (checks).
#[derive(Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use aquatic_udp_protocol::Response;
use serde::Serialize;
use thiserror::Error;

use crate::shared::bit_torrent::tracker::udp;
use crate::udp;

pub mod app;
pub mod checker;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/tracker-client/src/console/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//! Console apps.
pub mod clients;
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use std::net::IpAddr;
use std::sync::Arc;
use std::time::Duration;

use derive_more::Display;
use hyper::StatusCode;
use requests::{announce, scrape};
use reqwest::{Response, Url};
use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::core::auth::Key;

#[derive(Debug, Clone, Error)]
pub enum Error {
#[error("Failed to Build a Http Client: {err:?}")]
Expand Down Expand Up @@ -202,3 +202,19 @@ impl Client {
self.base_url.to_string()
}
}

/// A token used for authentication.
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Display, Hash)]
pub struct Key(String);

impl Key {
#[must_use]
pub fn new(value: &str) -> Self {
Self(value.to_owned())
}

#[must_use]
pub fn value(&self) -> &str {
&self.0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use aquatic_udp_protocol::PeerId;
use bittorrent_primitives::info_hash::InfoHash;
use serde_repr::Serialize_repr;

use crate::shared::bit_torrent::tracker::http::{percent_encode_byte_array, ByteArray20};
use crate::http::{percent_encode_byte_array, ByteArray20};

pub struct Query {
pub info_hash: ByteArray20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::str::FromStr;

use bittorrent_primitives::info_hash::InfoHash;

use crate::shared::bit_torrent::tracker::http::{percent_encode_byte_array, ByteArray20};
use crate::http::{percent_encode_byte_array, ByteArray20};

pub struct Query {
pub info_hash: Vec<ByteArray20>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::ser::SerializeMap;
use serde::{Deserialize, Serialize, Serializer};
use serde_bencode::value::Value;

use crate::shared::bit_torrent::tracker::http::{ByteArray20, InfoHash};
use crate::http::{ByteArray20, InfoHash};

#[derive(Debug, PartialEq, Default, Deserialize)]
pub struct Response {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod client;
pub mod url_encoding;

use percent_encoding::NON_ALPHANUMERIC;

Expand Down
Loading

0 comments on commit 5ce46ed

Please sign in to comment.