Repository navigation
feat(primitives): replace TORRENT_PEERS_LIMIT with AnnouncePolicy::max_peers_per_announce - #1877
Conversation
…x_peers_per_announce Move the peer-count cap from a global constant to a configurable field on `AnnouncePolicy`. The new `max_peers_per_announce: usize` field (default 74) is serialized via serde and respected by `PeersWanted::limit(max_peers)` at announce time. - Remove `TORRENT_PEERS_LIMIT` from `primitives::policy` - Add `AnnouncePolicy::max_peers_per_announce` (serde default = 74) - Replace `PeersWanted::From<i32/u32>` impls with `from_client_request(i32)` - `PeersWanted::limit()` now takes an explicit `max_peers: usize` argument - `get_torrent_peers` takes `max_peers: usize` instead of using the global - Update all call sites, tests, configuration fixtures, and docs Closes torrust#1864
There was a problem hiding this comment.
Pull request overview
This PR makes the per-announce peer return cap runtime-configurable by moving it from the hardcoded TORRENT_PEERS_LIMIT = 74 constant to a new AnnouncePolicy::max_peers_per_announce config field (default 74). It also refactors PeersWanted so the cap is applied explicitly at announce time (using injected policy), and updates call sites, tests, docs, and the EPIC decision log accordingly.
Changes:
- Replace global
TORRENT_PEERS_LIMITwithAnnouncePolicy::max_peers_per_announce(serde default 74) and plumb it through announce-time limiting. - Refactor
PeersWantedto remove implicitFrom<i32/u32>capping and introducefrom_client_request(i32)+limit(max_peers). - Update repositories/tests/docs to use explicit limits and record the decision as DEC-10.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/udp-tracker-core/src/services/announce.rs | Switch to PeersWanted::from_client_request(...) constructor. |
| packages/udp-server/src/handlers/announce.rs | Update tests for new get_torrent_peers(..., max_peers) signature. |
| packages/tracker-core/tests/integration.rs | Extend AnnouncePolicy test fixture with max_peers_per_announce. |
| packages/tracker-core/src/torrent/repository/in_memory.rs | Remove global cap usage and accept explicit limit/max_peers parameters. |
| packages/tracker-core/src/announce_handler.rs | Inject policy cap at announce time; refactor PeersWanted API + tests. |
| packages/torrent-repository-benchmarking/tests/entry/mod.rs | Replace TORRENT_PEERS_LIMIT usage with a local max-peers constant in tests. |
| packages/swarm-coordination-registry/src/swarm/registry.rs | Update docs/tests to remove dependency on the deleted constant. |
| packages/primitives/src/policy.rs | Remove TORRENT_PEERS_LIMIT from primitives policy module. |
| packages/primitives/src/lib.rs | Stop re-exporting TORRENT_PEERS_LIMIT. |
| packages/primitives/src/announce.rs | Add AnnouncePolicy::max_peers_per_announce with serde default + docs. |
| packages/configuration/src/v2_0_0/mod.rs | Document/config fixture update to include max_peers_per_announce. |
| packages/axum-http-server/tests/server/v1/contract.rs | Update tests for new get_torrent_peers(..., max_peers) signature. |
| packages/axum-http-server/src/lib.rs | Update HTTP tracker docs to reference configurable max peers. |
| docs/issues/open/1864-1669-review-torrent-peers-limit/ISSUE.md | Mark acceptance criteria as completed. |
| docs/issues/open/1669-overhaul-packages/DECISIONS.md | Add DEC-10 describing the design decision and rationale. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- swarm-coordination-registry: fix doc comment on get_peers_peers_excluding to accurately describe the limit parameter (not 'greater of provided or configured max' — simply capped by the limit argument) - axum-http-server: fix rustdoc link to point at the field AnnouncePolicy::max_peers_per_announce rather than the type - torrent-repository-benchmarking: assert against MAX_PEERS constant instead of hardcoded 74 to keep test consistent if the limit changes
|
ACK 388e3d1 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1877 +/- ##
========================================
Coverage 80.83% 80.83%
========================================
Files 368 368
Lines 27580 27575 -5
Branches 27580 27575 -5
========================================
- Hits 22294 22290 -4
Misses 4983 4983
+ Partials 303 302 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Closes #1864 — sub-task of EPIC #1669.
Move the peer-count cap from a global compile-time constant (
TORRENT_PEERS_LIMIT = 74) to a configurable fieldAnnouncePolicy::max_peers_per_announce(default 74, serialized via serde). This makes the limit observable in the configuration file and overridable at runtime without recompilation.Changes
TORRENT_PEERS_LIMITfromprimitives::policyand its re-export fromprimitives::libAnnouncePolicy::max_peers_per_announce: usize(serde default = 74, stored in[core.announce_policy]config section)PeersWantedintracker-core:From<i32>andFrom<u32>impls (were silently applying the global cap at construction time)PeersWanted::from_client_request(i32)—≤0→AsManyAsPossible, positive →Only { amount }PeersWanted::limit()now takes an explicitmax_peers: usizeargument, applied at announce time fromannounce_policy.max_peers_per_announceget_torrent_peers— now takesmax_peers: usizeinstead of using the global constant (old implementation had a bug:max(limit, TORRENT_PEERS_LIMIT)returned more than requested)docs/issues/open/1669-overhaul-packages/DECISIONS.mdConfiguration
The new field appears in
[core.announce_policy]:Existing configs without the field continue to work (serde default = 74).
Testing
cargo test --workspace)