Skip to content

Commit

Permalink
Merge #1081: Extract console clients into a new package
Browse files Browse the repository at this point in the history
3398024 fix: tracker checker execution in CI (Jose Celano)
3267bc7 fix: add missing package in deployment workflow (Jose Celano)
e966ae4 refactor!: remove tracker console client from tracker lib client (Jose Celano)
9d81624 feat: extract console clients into a new package (Jose Celano)

Pull request description:

  Extract console clients into a new package. Console clients will be available in a new independent crate `torrust-tracker-client`.

ACKs for top commit:
  josecelano:
    ACK 3398024

Tree-SHA512: 80237020c37614c4022fd8d38729ee7550692f72201a621c7232d275584ce8ebc614d2de4e38e8c458edfcb8277cf231c025a279d5c054fab6d1927cc5137e76
  • Loading branch information
josecelano committed Nov 14, 2024
2 parents 5ce46ed + 3398024 commit 49c0f43
Show file tree
Hide file tree
Showing 37 changed files with 308 additions and 43 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ jobs:
env:
CARGO_REGISTRY_TOKEN: "${{ secrets.TORRUST_UPDATE_CARGO_REGISTRY_TOKEN }}"
run: |
cargo publish -p bittorrent-tracker-client
cargo publish -p torrust-tracker
cargo publish -p torrust-tracker-client
cargo publish -p torrust-tracker-clock
cargo publish -p torrust-tracker-configuration
cargo publish -p torrust-tracker-contrib-bencode
cargo publish -p torrust-tracker-located-error
cargo publish -p torrust-tracker-primitives
cargo publish -p torrust-tracker-clock
cargo publish -p torrust-tracker-configuration
cargo publish -p torrust-tracker-torrent-repository
cargo publish -p torrust-tracker-test-helpers
cargo publish -p torrust-tracker
cargo publish -p torrust-tracker-torrent-repository
32 changes: 25 additions & 7 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ torrust-tracker-test-helpers = { version = "3.0.0-develop", path = "packages/tes

[workspace]
members = [
"console/tracker-client",
"contrib/bencode",
"packages/configuration",
"packages/located-error",
Expand Down
39 changes: 39 additions & 0 deletions console/tracker-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
description = "A collection of console clients to make requests to BitTorrent trackers."
keywords = ["bittorrent", "client", "tracker"]
license = "LGPL-3.0"
name = "torrust-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"
bittorrent-tracker-client = { version = "3.0.0-develop", path = "../../packages/tracker-client" }
clap = { version = "4", features = ["derive", "env"] }
futures = "0"
hex-literal = "0"
hyper = "1"
reqwest = { version = "0", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_bencode = "0"
serde_bytes = "0"
serde_json = { version = "1", features = ["preserve_order"] }
thiserror = "1"
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
torrust-tracker-configuration = { version = "3.0.0-develop", path = "../../packages/configuration" }
tracing = "0"
tracing-subscriber = { version = "0", features = ["json"] }
url = { version = "2", features = ["serde"] }

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

A collection of console clients to make requests to BitTorrent trackers.

> **Disclaimer**: This project is actively under development. We’re currently extracting and refining common functionality from the[Torrust Tracker](https://github.com/torrust/torrust-tracker) to make it available to the BitTorrent community in Rust. While these tools are functional, they are not yet ready for use in production or third-party projects.
There are currently three console clients available:

- UDP Client
- HTTP Client
- Tracker Checker

> **Notice**: [Console apps are planned to be merge into a single tracker client in the short-term](https://github.com/torrust/torrust-tracker/discussions/660).
## UDP Client

`Announce` request:

```text
cargo run --bin udp_tracker_client announce udp://127.0.0.1:6969 9c38422213e30bff212b30c360d26f9a02136422 | jq
```

`Announce` response:

```json
{
"AnnounceIpv4": {
"transaction_id": -888840697,
"announce_interval": 120,
"leechers": 0,
"seeders": 1,
"peers": []
}
}
```

`Scrape` request:

```text
cargo run --bin udp_tracker_client scrape udp://127.0.0.1:6969 9c38422213e30bff212b30c360d26f9a02136422 | jq
```

`Scrape` response:

```json
{
"Scrape": {
"transaction_id": -888840697,
"torrent_stats": [
{
"seeders": 1,
"completed": 0,
"leechers": 0
}
]
}
}
```

## HTTP Client

`Announce` request:

```text
cargo run --bin http_tracker_client announce http://127.0.0.1:7070 9c38422213e30bff212b30c360d26f9a02136422 | jq
```

`Announce` response:

```json
{
"complete": 1,
"incomplete": 0,
"interval": 120,
"min interval": 120,
"peers": []
}
```

`Scrape` request:

```text
cargo run --bin http_tracker_client scrape http://127.0.0.1:7070 9c38422213e30bff212b30c360d26f9a02136422 | jq
```

`Scrape` response:

```json
{
"9c38422213e30bff212b30c360d26f9a02136422": {
"complete": 1,
"downloaded": 1,
"incomplete": 0
}
}
```

## Tracker Checker

The Tracker Checker is a tool to check the health of a list of trackers.

```console
TORRUST_CHECKER_CONFIG='{
"udp_trackers": ["127.0.0.1:6969"],
"http_trackers": ["http://127.0.0.1:7070"],
"health_checks": ["http://127.0.0.1:1212/api/health_check"]
}' cargo run --bin tracker_checker
```

Output:

```json
[
{
"Udp": {
"Ok": {
"remote_addr": "127.0.0.1:6969",
"results": [
[
"Setup",
{
"Ok": null
}
],
[
"Connect",
{
"Ok": null
}
],
[
"Announce",
{
"Ok": null
}
],
[
"Scrape",
{
"Ok": null
}
]
]
}
}
},
{
"Health": {
"Ok": {
"url": "http://127.0.0.1:1212/api/health_check",
"result": {
"Ok": "200 OK"
}
}
}
},
{
"Http": {
"Ok": {
"url": "http://127.0.0.1:7070/",
"results": [
[
"Announce",
{
"Ok": null
}
],
[
"Scrape",
{
"Ok": null
}
]
]
}
}
}
]
```

## 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 console/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 bittorrent_tracker_client::console::clients::http::app;
use torrust_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 bittorrent_tracker_client::console::clients::checker::app;
use torrust_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 bittorrent_tracker_client::console::clients::udp::app;
use torrust_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 @@ -2,13 +2,13 @@ use std::str::FromStr as _;
use std::time::Duration;

use bittorrent_primitives::info_hash::InfoHash;
use bittorrent_tracker_client::http::client::responses::announce::Announce;
use bittorrent_tracker_client::http::client::responses::scrape;
use bittorrent_tracker_client::http::client::{requests, Client};
use serde::Serialize;
use url::Url;

use crate::console::clients::http::Error;
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
Loading

0 comments on commit 49c0f43

Please sign in to comment.