Repository navigation
Description
Context
Issue #1859 moved TORRENT_PEERS_LIMIT (value: 74) and TrackerPolicy from torrust-tracker-configuration into torrust-tracker-primitives. That was the right first step to break a dependency cycle, but the constant is still a global hardcoded value spread across several packages.
Problem
TORRENT_PEERS_LIMIT is currently used in at least three distinct roles:
-
Cap inside
From<i32/u32> for PeersWanted— enforces a maximum on client-requested peers at parse time:// packages/tracker-core/src/announce_handler.rs impl From<i32> for PeersWanted { fn from(value: i32) -> Self { ... PeersWanted::Only { amount: amount.min(TORRENT_PEERS_LIMIT) } } }
Because this is a
Fromimpl, there is no way to inject a runtime limit — the constant is baked in. -
Default return count in
PeersWanted::limit()— used when the client requestedAsManyAsPossible. -
Query cap in repository
get_peers/get_swarm_peers— used inin_memory.rsandswarm/registry.rsto limit how many peers are returned per query.
The constant living in primitives is better than in configuration, but it is still a global that couples unrelated packages to a single magic number.
Questions to Resolve
- Should
TORRENT_PEERS_LIMITremain a single global constant, or should each package define its own local default? - Should the cap be a runtime configuration option (e.g.,
TrackerPolicy::max_peers_per_announce) instead of a compile-time constant? This would make it tunable per deployment without recompilation. - For the
From<i32> for PeersWantedtrait impl, which cannot accept injected state, is a package-local constant the right answer, or should the trait impl be replaced by a free function / builder that accepts the limit explicitly? - If it becomes a config option, where does it live in the configuration hierarchy, and how do the repository query methods receive it?
Possible Approaches
| Approach | Pros | Cons |
|---|---|---|
Keep global constant in primitives (status quo post-#1859) |
Simple, no API churn | Magic number, not tunable, couples packages |
| Move constant into each consuming package | Removes cross-package coupling | Duplication, value can drift |
Make it a TrackerPolicy field with a default |
Runtime-tunable, operator-visible | Requires plumbing through announce handler and repositories |
Replace From impls with explicit constructors |
Removes implicit global dependency | API change for callers |
Related
- Closes (or follows from) Move
TrackerPolicy,TORRENT_PEERS_LIMIT, andPrivateModefromtorrust-tracker-configurationtotorrust-tracker-primitives#1859 - Parent EPIC: Overhaul: Packages #1669 — Overhaul: Packages
packages/tracker-core/src/announce_handler.rs—PeersWanted,Fromimplspackages/tracker-core/src/torrent/repository/in_memory.rs—get_peers,get_swarm_peerspackages/swarm-coordination-registry/src/swarm/registry.rs— samepackages/axum-http-server/src/lib.rs— doc reference to the constant
Expected Output
A decision (either an ADR or a DECISIONS.md entry under the #1669 EPIC) recording which approach is chosen, followed by the implementation if the decision is to change the current design.
Activity
fix: update stale docs and EPIC follow-up notes after torrust#1859
docs(primitives): add follow-up issue spec #1864 for TORRENT_PEERS_LI…
Merge #1865: refactor(primitives): move TrackerPolicy, TORRENT_PEERS_…
Merge #1877: feat(primitives): replace TORRENT_PEERS_LIMIT with Annou…
chore(issues): archive closed issue specs torrust#1854, torrust#1864 …
Merge #1886: chore(issues): maintain issue specs — archive closed, pr…
feat(primitives): replace TORRENT_PEERS_LIMIT with AnnouncePolicy::ma…
docs(issues): [torrust#1669] sync EPIC spec with current workspace state
docs(issues): [torrust#1669] add Details rows for subissues missing f…
Merge #2441: docs(issues): [#1669] sync EPIC spec with current worksp…