Repository navigation
feat(tracker-client): add unified tracker_client binary - #1777
josecelano merged 6 commits into
Conversation
…and-port approach)
Merge http_tracker_client, udp_tracker_client, and tracker_checker into a single tracker_client binary with explicit protocol subcommands: tracker_client http announce|scrape <url> <infohash> tracker_client udp announce|scrape <url> <infohash> tracker_client check [-- <checker-args>] Implementation approach: progressive copy-and-port. Command handlers are independent copies in console/tracker-client/src/console/clients/unified/. The old binaries are frozen and never called from the new code. Legacy binaries now print a deprecation notice on startup directing users to tracker_client. They will be removed no earlier than ~1 year after tracker_client ships (tracked in torrust#1775). Changes: - Add tracker_client binary entrypoint (bin/tracker_client.rs) - Add unified/{app,http,udp,check}.rs with copied command handlers - Add --format=json (default) / --format=text flag across all subcommands - Port tracker_checker integration tests to tracker_client check -- - Add tracker_client integration tests (help, HTTP error, UDP error) - Add deprecation eprintln! to http_tracker_client, udp_tracker_client, tracker_checker - Update skills and docs to reference tracker_client commands - Update issue spec torrust#1771: all tasks and AC marked DONE with evidence All automated gates pass: linter all, 46 unit tests, 13 integration tests. Manual verification M1-M7 against local tracker all exit 0. Closes torrust#1771
… in progress log
There was a problem hiding this comment.
Pull request overview
This PR introduces a new unified tracker_client CLI binary for the console/tracker-client crate, consolidating HTTP, UDP, and checker workflows under explicit protocol subcommands while leaving the legacy binaries in place with deprecation warnings.
Changes:
- Added a new
tracker_clientbinary withhttp,udp, andchecksubcommands implemented underconsole::clients::unified. - Ported/added integration tests to exercise
tracker_client(includingcheck) and updated docs/skills to reference the unified CLI. - Added startup deprecation warnings to
http_tracker_client,udp_tracker_client, andtracker_checker.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/issues/open/1771-merge-clients-into-unified-tracker-client-cli.md | Marks the issue spec as done; adds implementation strategy and design notes. |
| console/tracker-client/tests/tracker_client.rs | New integration tests for tracker_client help and basic error paths. |
| console/tracker-client/tests/tracker_checker.rs | Ports checker integration tests to tracker_client check -- …. |
| console/tracker-client/tests/tracker_checker/configuration.rs | Updates test harness to use tracker_client check. |
| console/tracker-client/tests/tracker_checker/monitor.rs | Updates monitor test to invoke tracker_client check monitor …. |
| console/tracker-client/src/console/clients/unified/mod.rs | Declares unified module and documents migration intent. |
| console/tracker-client/src/console/clients/unified/app.rs | Defines unified top-level clap app and dispatch to http/udp/check handlers. |
| console/tracker-client/src/console/clients/unified/http.rs | New HTTP announce/scrape handlers + small unit tests. |
| console/tracker-client/src/console/clients/unified/udp.rs | New UDP announce/scrape handlers wired to existing UDP client helpers. |
| console/tracker-client/src/console/clients/unified/check.rs | New check implementation that reuses checker library modules. |
| console/tracker-client/src/console/clients/mod.rs | Exposes the unified module alongside legacy modules. |
| console/tracker-client/src/bin/tracker_client.rs | New unified binary entrypoint and exit/error handling. |
| console/tracker-client/src/bin/http_tracker_client.rs | Adds deprecation warning on startup. |
| console/tracker-client/src/bin/udp_tracker_client.rs | Adds deprecation warning on startup. |
| console/tracker-client/src/bin/tracker_checker.rs | Adds deprecation warning on startup. |
| console/tracker-client/docs/features/json-request-input/README.md | Updates examples/references to the unified CLI naming. |
| .github/skills/dev/testing/public-trackers-for-testing/SKILL.md | Updates examples to use tracker_client http/udp … and new format names. |
| .github/skills/dev/environment-setup/run-tracker-locally/SKILL.md | Updates local testing commands to use tracker_client http/udp …. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #1777 +/- ##
===========================================
- Coverage 79.01% 78.23% -0.79%
===========================================
Files 371 376 +5
Lines 27928 28361 +433
Branches 27928 28361 +433
===========================================
+ Hits 22068 22188 +120
- Misses 5555 5859 +304
- Partials 305 314 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
ACK 3e47c36 |
da2ce7
left a comment
There was a problem hiding this comment.
This is a post-merge review of the change from #1777 as it stands at a94c3ced8 on the default branch.
What still runs: the tracker_client binary (console/tracker-client/src/bin/tracker_client.rs) and its unified module (app, http, udp, check) are now the crate's only command entry point. The three legacy binaries and their deprecation warnings were removed in 4ea7826f8. Since the merge, all output goes through unified/output.rs: the terminal refusal, JSON-only stderr and the panic record came in 36607df28, tracker keys are masked since 5714ddde5, and the checker's URL validation was tightened in 3fd4dd6fb. The HTTP and UDP handlers, the check wrapper and the shared test binary resolver are otherwise much as merged.
[Minor] The UDP subcommand cannot address an IPv6 tracker, or a host name written as host:port, because of parse_socket_addr in console/tracker-client/src/console/clients/unified/udp.rs:167. With udp://[::1]:6969, url.host_str() (line 173) returns [::1] with its brackets. ("[::1]", 6969).to_socket_addrs() (line 205) does not parse a bracketed literal and hands it to the resolver, which fails, so the command exits 2 before it sends anything. [::1]:6969 fails the split(':') length check (line 185). tracker.example.com:6969 and localhost:6969 parse at line 170 as URLs whose scheme is the host name, so host_str() is None and the error is invalid host in URL, although the fallback's own message asks for exactly this host:port form. Only IPv4 literals and udp://<hostname>:<port> work, and any scheme is accepted, so http://host:6969 is sent over UDP. Smallest fix: take the URL branch only when the input starts with udp://, and resolve it with Url::socket_addrs(|| None) as console/tracker-client/src/console/clients/checker/checks/udp.rs:128 already does. Otherwise, pass the whole string to the ToSocketAddrs impl for str, which accepts host:port and [v6]:port.
[Minor] The HTTP subcommand checks its positional input only after parsing, so bad command-line input exits 1 with runtime_failure. The UDP subcommand rejects the same input in the parser with exit 2 and usage_error, and the contract (console/tracker-client/docs/contracts/tracker-cli-io-contract.md:114) gives exit 2 to an invalid command line. For example, tracker_client http announce http://127.0.0.1:7070 nothex exits 1 (unified/http.rs:152), while tracker_client udp scrape udp://127.0.0.1:6969 nothex exits 2. The tests pin both codes: console/tracker-client/tests/tracker_client.rs:44 expects 1 and :63 expects 2. http scrape <url> with no info-hash is also accepted: unified/http.rs:82 sets no minimum, so a scrape goes out with no info_hash at all, whereas udp scrape requires at least one (unified/udp.rs:70). Smallest fix: give tracker_url, info_hash and info_hashes in http::Command clap value parsers (the parse_info_hash at unified/udp.rs:213 fits), add num_args = 1.. on info_hashes, and expect 2 at tests/tracker_client.rs:44. Parser errors already pass through the key masking in AppError::from_clap.
[Minor] console/tracker-client/src/bin/tracker_client.rs:27 renders the anyhow::Error with to_string(), which prints only the outermost context, so every .context(...) on the HTTP and UDP paths hides its cause. tracker_client http scrape http://127.0.0.1:7070 nothex reports only failed to parse infohashes, and the cause, Invalid infohash: nothex, is dropped (unified/http.rs:212). tracker_client http announce tracker.example.com <hash> reports only failed to parse HTTP tracker base URL, without the parse error (unified/http.rs:268). A failed stdout write loses its I/O error (unified/http.rs:201 and :230). Smallest fix: format!("{err:#}"). On these paths the causes are URL parse errors, info-hash conversion errors, JSON and I/O errors, and the client error text, which is already key-masked, so the full chain adds no secret.
[Minor] The HTTP and UDP subcommands report a tracker's refusal through opposite channels and exit codes. On the HTTP side, unified/http.rs:190-199 decodes only full announce bodies, so a BEP 3 failure reason reply, such as a private tracker refusing an unknown key, ends as an unrecognized_response record with exit 1. Yet torrust_tracker_http_protocol::v1::responses::error::Error decodes that reply, and the contract (tracker-cli-io-contract.md:42) keeps that record kind for replies the client cannot decode. A minimal BEP 3 announce reply fails the same way: BEP 3 requires only interval and peers (d8:intervali1800e5:peers0:e), but DeserializedNormal and DeserializedCompact also require complete, incomplete and min interval. On the UDP side, unified/udp.rs:135-138 writes any reply variant to stdout as the result with exit 0, including the tracker's Error reply. So a script that checks the exit status sees a tracker refusal as a failure over HTTP and as a success over UDP. Smallest fix: try the failure reason decoder before the fallback and report it the same way as the UDP error reply, and make the three extension keys optional in the client-side decoders. The contract should also say which exit code a tracker refusal gets from the single-request commands: its rule at line 118 and its example at line 58 disagree on that.
[Nit] unified/udp.rs:18 sends the fixed constant RANDOM_TRANSACTION_ID in every request. Neither the transaction id nor the action of the reply is compared with the request (unified/udp.rs:146-164; console/tracker-client/src/console/clients/udp/checker.rs:154-160 returns whatever arrives), so an announce that receives a scrape or connect reply prints that reply as its result. BEP 15 asks for a random transaction id so that the client can match replies. The socket is connected to the tracker, which limits the exposure. Fix: draw the id at random for each request, and reject a reply whose id or action does not match.
[Nit] tracker_client check --format text monitor udp --url ... ignores --format. unified/check.rs:84-86 calls run_command without the output format, and the monitor summary is always compact, although #1777 described --format as applying to all subcommands. check also collects its results in task-completion order (unified/check.rs:143-145), so the UDP, HTTP and health groups can appear in results in a different order from one invocation to the next. Fix: pass the format to the monitor, and put the groups in a fixed order before rendering.
Checked and found sound: the terminal refusal and the help and version records in unified/app.rs; the diagnostic writer and panic record in unified/output.rs; the key masking on HTTP client errors, body-read errors and parser usage errors; the check configuration precedence and its exit-2 configuration errors; the i64 range checks on the UDP announce counters; the peer-id and non-zero port parsers; the scrape truncation warning; and the binary resolver in tests/common/mod.rs.
Closes #1771
Summary
Merges the three separate tracker client binaries (
http_tracker_client,udp_tracker_client,tracker_checker) into a singletracker_clientbinary with explicit protocol subcommands.Changes
New:
tracker_clientbinaryA single entry point replacing the three legacy binaries:
--format=json(default) /--format=text(pretty-printed JSON) for all subcommandschecker::checks,checker::monitor)Deprecation warnings
Each legacy binary (
http_tracker_client,udp_tracker_client,tracker_checker) now printsa startup warning on stderr directing users to
tracker_client. The old binaries are otherwisefrozen — no new features, no modifications.
Tests
tracker_checkerintegration tests to invoketracker_client check --tracker_clientintegration tests: help output, HTTP error path (exit 1), UDP error path (exit 2)Docs and skills
public-trackers-for-testingandrun-tracker-locallyskillsdocs/features/json-request-input/README.mdDesign decisions
http_tracker_client,udp_tracker_client,tracker_checker#1775unified/module structure: flat files, no per-action nesting — deferred to Remove legacy binaries:http_tracker_client,udp_tracker_client,tracker_checker#1775 cleanupManual verification
All 7 local-tracker scenarios (HTTP announce/scrape, UDP announce/scrape, checker,
--format=text)pass with exit 0. Evidence recorded in the issue spec.
Spec
docs/issues/open/1771-merge-clients-into-unified-tracker-client-cli.md