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

Overhaul clients #669

Open
14 of 21 tasks
josecelano opened this issue Feb 2, 2024 · 1 comment
Open
14 of 21 tasks

Overhaul clients #669

josecelano opened this issue Feb 2, 2024 · 1 comment
Labels
- Admin - Enjoyable to Install and Setup our Software - Developer - Torrust Improvement Experience Code Cleanup / Refactoring Tidying and Making Neat Continuous Integration Workflows and Automation Enhancement / Feature Request Something New EPIC Contains several subissues good first issue Good for newcomers Help Wanted More Contributions are Appreciated and extra attention is needed. Quality & Assurance Relates to QA, Testing, and CI
Milestone

Comments

@josecelano
Copy link
Member

josecelano commented Feb 2, 2024

This is an epic issue for tracking progress with clients.

NOTES:

  • The list order is the recommended order of implementation.
  • If you want to contribute to one task but there is no issue yet or want more info feel free to ask for more information.

Introduction

I've recently added three new tools to the repo. These three console commands can be used for testing and debugging. Since I started working on this project, I've missed tools that can help developers and sys admins detect and fix trackers' problems. The new three console commands are:

HTTP Tracker Client

This client allows making announce and scrape requests to HTTP trackers.

Announce:

cargo run --bin http_tracker_client announce http://127.0.0.1:7070 9c38422213e30bff212b30c360d26f9a02136422
{
  "complete": 1,
  "incomplete": 0,
  "interval": 120,
  "min interval": 120,
  "peers": []
}

Notice: all parameters except the info_hash are hardcoded. This client is not intended (yet) to be used with a full request from inputs. It's only used for testing so it generates a sample request. It could be changed to accept all parameters as a json object in the future. It depends on this.

You could use any browser for the HTTP Tracker Client, but the main advantage is getting the response in JSON instead of Bencoded format.

Scrape:

cargo run --bin http_tracker_client scrape http://127.0.0.1:7070 9c38422213e30bff212b30c360d26f9a02136422
{
  "9c38422213e30bff212b30c360d26f9a02136422": {
    "complete": 1,
    "downloaded": 0,
    "incomplete": 0
  }
}

UDP Tracker Client

This client allows making announce and scrape requests to UDP trackers.

Announce:

cargo run --bin udp_tracker_client announce http://127.0.0.1:6969 9c38422213e30bff212b30c360d26f9a02136422
{
  "transaction_id": -888840697,
  "announce_interval": 120,
  "leechers": 0,
  "seeders": 1,
  "peers": []
}

Scrape:

cargo run --bin udp_tracker_client scrape http://127.0.0.1:6969 9c38422213e30bff212b30c360d26f9a02136422
{
  "transaction_id": -888840697,
  "torrent_stats": [
    {
      "seeders": 1,
      "completed": 0,
      "leechers": 0
    }
  ]
}

Notice: this is fully implemented as the only parameter for the scrape request is the info_hash.

This client is very convenient because there is no easy way to build and send UDP packets. And some BitTorrent clients don't show you the Tracker response. (https://www.biglybt.com/ does it).

Tracker Checker

You can use this command to test running services on trackers. It can check:

  • UDP trackers: it makes an announce and scrape request.
  • HTP trackers: it makes an announce and scrape request.
  • HTTP endpoints (health check endpoints): it makes a GET request to the provided endpoint and checks that the endpoint returns a 200 HTTP status code.

You can run it for the local dev env with:

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:1313/health_check"]
}' cargo run --bin tracker_checker

or for the live demo with:

TORRUST_CHECKER_CONFIG='{
    "udp_trackers": ["144.126.245.19:6969"],
    "http_trackers": ["https://tracker.torrust-demo.com"],
    "health_checks": ["https://tracker.torrust-demo.com/health_check"]
}' cargo run --bin tracker_checker

Output:

Running checks for trackers ...
UDP trackers ...
✓ - Announce at 144.126.245.19:6969 is OK
✓ - Announce at 144.126.245.19:6969 is OK
HTTP trackers ...
✓ - Announce at https://tracker.torrust-demo.com/ is OK
✓ - Scrape at https://tracker.torrust-demo.com/ is OK
Health checks ...
✓ - Health API at https://tracker.torrust-demo.com/health_check is OK

Considerations

This code is still in beta, some parts were moved from testing code to production code. For example the UdpClient. That means it's not covered by tests. We should add tests while we implement all these new features. I merged as it is because I wanted to use the Checker in the testing workflow (E2E tests). I wanted to enable this feature asap to avoid regressions when we merge PRs, since a lot of the bootstapping of the app is not covered by unit tests.

@josecelano josecelano added Enhancement / Feature Request Something New Code Cleanup / Refactoring Tidying and Making Neat Continuous Integration Workflows and Automation Quality & Assurance Relates to QA, Testing, and CI - Developer - Torrust Improvement Experience - Admin - Enjoyable to Install and Setup our Software good first issue Good for newcomers EPIC Contains several subissues labels Feb 2, 2024
@josecelano josecelano added this to the v3.1.0 milestone Feb 2, 2024
@josecelano josecelano added the Help Wanted More Contributions are Appreciated and extra attention is needed. label Feb 2, 2024
josecelano added a commit that referenced this issue Oct 31, 2024
… struct

7fe648c refactor: replace InfoHash with external extracted crate (Jose Celano)
7d7dba5 feat: add dep bittorrent-primitives (Jose Celano)

Pull request description:

  Relates to:
    - torrust/torrust-index#251
    - torrust/torrust-index#756

  The `InfoHash` type was duplicated here and in the [Index](torrust/torrust-index#251). I've extracted it into a new crate. I'm planning to move the very basic types that we are using in other projects.

  I'm also planning to extract more packages like:

  - UDP tracker client
  - HTTP tracker client
  - Tracker console client (after merging UDP console client, HTTP console client and Tracker checker). See #669

  Some of those new packages also depend on this new [bittorrent-primitives](https://github.com/torrust/bittorrent-primitives) crate.

ACKs for top commit:
  josecelano:
    ACK 7fe648c

Tree-SHA512: 3ab5b2ef8631ae72b792dea6b1c9ab1e64b28f170d4580109872739427f0f50ae753af014d691e41bdffbf3a33da732cba89fd1487b9e219345e74b15599b1b7
@josecelano
Copy link
Member Author

Clients were extracted into a new package, bittorrent-tracker-client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Admin - Enjoyable to Install and Setup our Software - Developer - Torrust Improvement Experience Code Cleanup / Refactoring Tidying and Making Neat Continuous Integration Workflows and Automation Enhancement / Feature Request Something New EPIC Contains several subissues good first issue Good for newcomers Help Wanted More Contributions are Appreciated and extra attention is needed. Quality & Assurance Relates to QA, Testing, and CI
Projects
Status: No status
Development

No branches or pull requests

1 participant