Skip to content

feat(torrent): name Ketch to private trackers and keep their refusal text - #560

Merged
linroid merged 2 commits into
mainfrom
feat/torrent-client-identity
Oct 16, 2026
Merged

linroid merged 2 commits into
mainfrom
feat/torrent-client-identity

Conversation

@linroid

@linroid linroid commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Summary

Private trackers allow clients by peer-ID prefix, so they refused Ketch's 20 random bytes. Users never saw why, because the tracker's own reason was replaced by a generic error. This is item 4 under "Fix first" in the 2026-10-16 torrent review.

  • Peer ID (BEP 20): -KE, then four version characters from KetchApi.VERSION, then twelve random letters and digits. For example, 0.9.1 gives -KE0910-, and a pre-release or dev build ends in Z. I didn't use KT: Transmission, libtorrent, BiglyBT and the theory.org list all assign it to KTorrent. One engine now uses one ID for the v1 swarm, v2 and hybrid connections, magnet metadata peers (which used to pick a fresh random ID on every connection) and trackers. The new TorrentClient object holds the ID, the v name and the User-Agent.

  • BEP 10: every extension handshake now sends v (Ketch <version>) and yourip. This covers the v1 swarm, v2 and hybrid connections, and metadata lookups.

  • User-Agent: tracker announces and scrapes now set User-Agent: Ketch/<version> explicitly, so an HttpEngine the caller supplies cannot change it. The default engine already sent this. Web seeds keep the engine's default.

  • Tracker text: an HTTP failure reason or a UDP error (BEP 15 action 3) now raises TrackerFailureException(reason). The reason is kept in TrackerStatus.failureReason, and a warning message in TrackerStatus.warning. Both pass through trackerMessage() first, which:

    • removes control and formatting characters (bidi overrides, zero-width spaces)
    • reduces URLs to scheme://host:port
    • masks, as ***, the announce URL's credentials and any path or query part that could be a passkey, plus any other run of 16 or more letters and digits that mixes both
    • cuts the text to 200 characters

    Each reason is logged at warn the first time it appears and at debug while it repeats.

  • Docs: added "How Ketch identifies itself" to docs/torrent.md, a tracker-messages rule and a log example to docs/logging.md, and an AGENTS.md entry.

Not in this PR

Feeding peers' yourip into isOwnAddress is a follow-up. yourip comes from untrusted peers, so it needs a tally of distinct voters across the v1 swarms and the v2 sessions, which is more than a small change. For now Ketch only sends yourip.

Tests

  • TorrentClientTest: the version encoding of the prefix, the ID format, and that IDs are unique.
  • PeerExtensionsTest: v and yourip for IPv4, IPv4-mapped and IPv6 peers, none for a hostname, and the same keys in the metadata fetcher's handshake.
  • TrackerMessageTest:
    • An HTTP refusal quotes the passkey and the full passkey URL. The test checks the reason comes back as Unregistered passkey *** at https://tracker.example:443 and that the request sent the User-Agent.
    • A UDP error that contains the passkey is masked the same way.
    • Control characters, user info, path secrets, long tokens and the length cap are handled.
    • warning message is kept.
    • TrackerStatus keeps the reason and clears it after the next answer.
  • TrackerOnlyMagnetTest: tracker announces and the magnet metadata peer see the same -KE peer ID, and the peer gets v and yourip.
  • KotlinTorrentEngineRoutingTest: the v1 swarm answers with the prefixed ID.
  • ./gradlew :library:torrent:jvmTest passes: 1295 tests, 0 failures. :library:torrent:compileTestKotlinIosSimulatorArm64 compiles.

…text

Private trackers allow clients by peer-ID prefix, so they refused Ketch's
20 random bytes, and the reason they gave was replaced by a generic error.

- Peer ID (BEP 20): -KE plus four version characters from KetchApi.VERSION
  and twelve random letters and digits (KT is KTorrent's). The engine uses
  one ID for the v1 swarm, v2 and hybrid connections, magnet metadata peers
  and trackers.
- BEP 10 handshakes send v ("Ketch <version>") and yourip.
- Tracker announces and scrapes send User-Agent: Ketch/<version> whatever
  engine the source was given.
- An HTTP failure reason or UDP error becomes TrackerFailureException.reason
  and TrackerStatus.failureReason, a warning message TrackerStatus.warning,
  both cleaned by trackerMessage(): control and formatting characters
  removed, URLs reduced to scheme://host:port, possible passkeys masked,
  200 characters at most. Each is logged at warn when it changes.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T08:49:01.771232Z 0b97832 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 16, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b97832cbb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ker text

A URL in a tracker's message ends at characters a passkey may hold, such as a
comma, so cutting URLs first left most of such a passkey unmasked.
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 1 929 files  +10   1 957 suites  +10   25m 4s ⏱️ +32s
12 980 tests +30  12 733 ✅ +30  247 💤 ±0  0 ❌ ±0 
15 575 runs  +50  15 328 ✅ +50  247 💤 ±0  0 ❌ ±0 

Results for commit bc849bd. ± Comparison against base commit f9ff4a9.

@linroid
linroid merged commit 57d87d4 into main Oct 16, 2026
14 checks passed
@linroid
linroid deleted the feat/torrent-client-identity branch October 16, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant