Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
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
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 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 },

Check warning on line 14 in packages/tracker-client/src/console/clients/http/mod.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L14 was not covered by tests
#[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
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
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::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 @@
self.base_url.to_string()
}
}

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

Check warning on line 208 in packages/tracker-client/src/http/client/mod.rs

View check run for this annotation

Codecov / codecov/patch

packages/tracker-client/src/http/client/mod.rs#L207-L208

Added lines #L207 - L208 were not covered by tests

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

Check warning on line 214 in packages/tracker-client/src/http/client/mod.rs

View check run for this annotation

Codecov / codecov/patch

packages/tracker-client/src/http/client/mod.rs#L212-L214

Added lines #L212 - L214 were not covered by tests

#[must_use]
pub fn value(&self) -> &str {
&self.0
}

Check warning on line 219 in packages/tracker-client/src/http/client/mod.rs

View check run for this annotation

Codecov / codecov/patch

packages/tracker-client/src/http/client/mod.rs#L217-L219

Added lines #L217 - L219 were not covered by tests
}
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
Loading