Skip to content

fix(configuration): [#2466] bound announce intervals to what every delivery protocol can encode - #2680

Merged
josecelano merged 9 commits into
torrust:developfrom
josecelano:2466-1978-announce-interval-upper-bound
Oct 28, 2026
Merged

josecelano merged 9 commits into
torrust:developfrom
josecelano:2466-1978-announce-interval-upper-bound

Conversation

@josecelano

Copy link
Copy Markdown
Member

Closes #2466

Summary

A configured core.announce_policy.interval or interval_min above i32::MAX (2147483647 seconds) is now rejected when the configuration is loaded. Before, the tracker started, UDP clients received a clamped 2147483647 and HTTP clients received the configured value, so the two protocols disagreed for the same configuration.

The bound is enforced by a new typed value, AnnounceIntervalInSecs, in primitives, following the value-invariant and constrained-newtype ADRs. It is not a Validator rule. The error names the rejected value and the limit, and the loader adds the key path, for example the interval 2147483648 is above the maximum of 2147483647 seconds that every delivery protocol can encode for key "default.core.announce_policy.interval".

This is a breaking change to the AnnouncePolicy field types, accepted for the 4.0.0 release in the specification.

Changes

  • primitives: new AnnounceIntervalInSecs (wraps u32, new/TryFrom<u32> are fallible, From<u16> is infallible, get(), get_i32(), infallible From to i32 and i64, plain-integer Serialize, bounded Deserialize). AnnouncePolicy::interval and interval_min use it.
  • udp-server: the announce interval is converted to the BEP 15 field without clamping. saturating_wire_i32 stays for the seeder and leecher counts.
  • axum-http-server: converts the typed value with get() for the http-protocol wire type, which keeps its own policy type and does not depend on primitives.
  • configuration, tracker-core, http-core: test and documentation updates; configuration-load tests for both fields and for the boundary value.
  • packages/configuration/docs/migrate-v2-to-v3.md: quick-reference row, a new step 11, and a checklist item.
  • docs/issues/open/2466-1978-announce-interval-upper-bound/: spec decisions 7-11 recorded before implementation, then progress and manual verification evidence.

Validation

  • The configuration-load regression tests were recorded red against the u32 fields and pass after the change.
  • linter all ran on every commit through the pre-commit hook, and the pre-push suite (nightly format, check and docs, workspace packaging, full stable test suite) exited 0.
  • Manual scenarios against a real tracker, recorded in manual-verification-evidence.md: interval = 2147483648 and interval_min = 2147483648 fail at startup with the key, the value and the limit; interval = 2147483647 starts and both UDP and HTTP announces report 2147483647.
  • No temporary local-only patches were used for verification; everything tested is in the branch.

Related to #2245 and #1978.

josecelano and others added 6 commits October 28, 2026 11:05
…he spec

Name the bounded type AnnounceIntervalInSecs, fix its representation,
conversions, constructors and error contract, and tick the merged
specification PR checkpoint.

Co-authored-by: Copilot <[email protected]>
…ed type

Reject an announce interval above i32::MAX seconds, the BEP 15 limit
and the tightest among the supported delivery protocols, when the value
is built or deserialized.

Co-authored-by: Copilot <[email protected]>
…at every delivery protocol can encode

Use AnnounceIntervalInSecs for AnnouncePolicy::interval and
interval_min, so a configuration with a value above i32::MAX fails to
load instead of being clamped on the UDP wire. The UDP announce handler
converts the interval without clamping; saturating_wire_i32 remains for
the seeder and leecher counts. The HTTP handler passes the value to the
http-protocol wire type, which keeps its own policy type.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 11:07

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

This PR enforces a protocol-safe upper bound for configured announce intervals by introducing a bounded AnnounceIntervalInSecs type and updating all protocol handlers/tests/docs so UDP and HTTP behavior stays consistent.

Changes:

  • Add AnnounceIntervalInSecs newtype (bounded to i32::MAX) and migrate AnnouncePolicy::{interval, interval_min} to use it.
  • Update UDP and HTTP servers to convert the typed interval without clamping and adjust contract/integration tests accordingly.
  • Add configuration-load regression tests and migration/spec documentation capturing the new constraint.
File Description
packages/​udp-server/​src/​handlers/​mod.rs Updates clamping helper docs to reflect interval is now bounded at config load.
packages/​udp-server/​src/​handlers/​announce.rs Uses typed interval conversion for UDP wire format and updates related tests.
packages/​tracker-core/​tests/​integration.rs Updates integration test policy literals to the new interval type.
packages/​tracker-core/​src/​announce_handler.rs Updates public docs example to show new interval types.
packages/​primitives/​src/​lib.rs Exposes the new announce-interval module/type from primitives.
packages/​primitives/​src/​announce_interval.rs Introduces bounded AnnounceIntervalInSecs with serde support and unit tests.
packages/​primitives/​src/​announce.rs Migrates AnnouncePolicy fields/defaults to AnnounceIntervalInSecs.
packages/​http-core/​src/​services/​announce.rs Updates tests to construct policies with the new interval type.
packages/​configuration/​src/​v3_0_0/​mod.rs Adds config-load tests ensuring out-of-range intervals are rejected with key/value/limit.
packages/​configuration/​docs/​migrate-v2-to-v3.md Documents the new upper bound and adds a migration checklist item.
packages/​axum-http-server/​tests/​.../​receiving_an_announce_request.rs Updates contract tests to compare HTTP response values using .get().
packages/​axum-http-server/​src/​v1/​handlers/​announce.rs Converts the typed interval to the HTTP protocol field values via .get().
docs/​issues/​open/​.../​manual-verification-evidence.md Updates evidence with red/green regression tests and post-fix scenarios.
docs/​issues/​open/​.../​ISSUE.md Updates spec status/tasks/acceptance criteria progress and branch metadata.

Review effort: Lite

Comment thread packages/udp-server/src/handlers/mod.rs Resolved
@josecelano
josecelano requested a review from da2ce7 October 28, 2026 11:35
@josecelano josecelano self-assigned this Oct 28, 2026
@josecelano

Copy link
Copy Markdown
Member Author

ACK 3d7d183

@josecelano
josecelano merged commit 2025431 into torrust:develop Oct 28, 2026
36 checks passed
josecelano added a commit that referenced this pull request Oct 28, 2026
…ssues/closed

b48ea73 chore(issues): [#2466] archive the closed issue spec to docs/issues/closed (Jose Celano)

Pull request description:

  Related to #2466 and #1978.

  ## Summary

  Archives the specification for issue #2466, which is closed on GitHub, from `docs/issues/open/` to `docs/issues/closed/`, following the `cleanup-completed-issues` skill. The implementation merged in #2680.

  ## Changes

  - Moves `docs/issues/open/2466-1978-announce-interval-upper-bound/` (`ISSUE.md` and `manual-verification-evidence.md`) to `docs/issues/closed/`.
  - Updates the spec frontmatter (`status: done`, `spec-path`, `related-pr: 2680`, `last-updated-utc`), ticks the acceptance criteria and the workflow checkpoints that the recorded evidence supports, adds the related PRs, and appends progress-log entries for the merge and the archive.
  - Leaves the "independent reviewer reports" checkpoint unticked because no `agent-review-reports.md` was recorded.
  - Repairs the live references to the old path: the EPIC #1978 frontmatter and its subissue table row (now `DONE`), and the `related-artifacts` link in the PR #2680 review audit.
  - Keeps one deliberate historical reference to the old path, in the PR #2468 review audit, because it records a command that ran against the path that existed then.

  ## Validation

  - Verified that #2466 is `CLOSED` and that #2680 is merged.
  - Searched the repository for the old path before finishing; only the historical reference above remains.
  - `git diff --cached --check` and the pre-commit hook (including the frontmatter validator and `linter all`) passed, and `validate-audit-record.py` still reports no failures for PR #2680.

  EPIC #1978 stays open: closing it and rechecking its AC4 are left to the maintainer.

ACKs for top commit:
  josecelano:
    ACK b48ea73

Tree-SHA512: 63af0fe9a73af8337238686bb9b012fd8766e9833757d7478af58196dbb80f17c8ca32c00d03777ad2e21ca83e37f05baf6e0ebb4a19b4b44df4b4fa159508c9

@da2ce7 da2ce7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at 3d7d18368d65ac9550f9d79ba0a3cccda7ce9e25 (post-merge). Recomputed from the bytes at the merged head, against the base 09263a46c21b05007d838510a92e3a327a84f783; the PR merged on 2026-10-28 at 13:03:03Z as 2025431d3.

Label: POST_MERGE_FINDINGS — Review was requested on 2026-10-28 at 11:35:16Z. The PR merged before this round ran. The findings below stand at the merged head for a follow-up; no ACK follows a merged PR.

Claims and change: the range contains nine commits and 15 changed files. The bound is 2147483647 seconds: the UDP response stores an I32, while both HTTP encodings use i64 integers after a u32 policy conversion. UDP has no minimum-interval field; applying the same bound to that field is the explicit domain decision. Construction and deserialization enforce the invariant, including shared v2 library use; no Validator rule was added. Both defaults remain 120. Conversion paths and callers in all six affected packages are consistent with the new field types.

Tests: constructor, deserializer and both configuration-load rejection tests distinguish limit+1 from the limit and would fail if the bound check were removed. Acceptance tests protect inclusivity; the UDP test protects both address families and retains counter clamping. Existing HTTP and core assertions retain their behavior after type adaptation. No build or execution result is claimed here.

Records: F1-F3 match the captured source comments, reply IDs and resolved thread states; the two fixing subjects exist uniquely and the Processing Log agrees with the captured reply times and commit times. All eight relative Markdown links resolve. The recorded manual results fit the code paths, but the run evidence omits required sequencing and cleanup evidence (F4). Historical execution and hook success cannot be independently established from source bytes. The evidence timestamp also remains 07:35 after its later reference edit.

Hygiene: every commit has a Conventional subject, scoped issue reference and matching author/committer identity; every per-commit whitespace check is clean. Attribution footer lines occur in all nine commits; no applicable tree rule prohibiting those footers was found. The description's closing-pattern match is the intended issue 2466; commit messages add none. New terminology was compared with the project dictionary; spelling-tool behavior remains for independent verification.

The review bot: review 5681855365 supplied three source comments. For 4399979381, retaining const is consistent with the workspace nursery/warnings policy. For 4399979440, the simpler MAX construction landed, and the supposedly unnecessary variable still supplies the leecher count. For 4399979473, the clarification landed. No source concern needs re-raising.

Findings: F4 (Minor), preserve the required manual-run evidence.

Checked, no finding: private representation, fallible u32 construction, u16 conversion, large-u64 rejection, plain-integer serialization, inclusive boundary, unchanged counter saturation, and the distinction between protocol and domain policy. The later archive PR 2684 carries this spec and evidence forward; PR 2685 archives the parent EPIC. PR 2682 concerns test-module visibility, not interval semantics.

Checks

On the loop's compute hub at the merged head, against the base 09263a46c (receipt server-gates-sojka-477; the PR merged as 2025431d3): pre-commit profile gate exit 0 (96 s); linter markdown, linter cspell, linter lychee exit 0; frontmatter-validator --all: 16 errors / 4 warnings at the merged head and 16 / 4 at the base re-measured, the same 20 diagnostics by path and category; the audit validator over docs/pr-reviews/pr-2680-review/PR-REVIEW.md with the review comments and commit list captured at gate time: ok, 3 rows, 5 log entries, 0 failures; cargo test at the merged head: torrust-tracker-axum-http-server 110 passed, 0 failed (exit 0, 44 s; 110 at the base); torrust-tracker-configuration 132 passed, 0 failed (exit 0, 17 s; 129 at the base); torrust-tracker-http-core 194 passed, 0 failed (exit 0, 34 s; 194 at the base); torrust-tracker-primitives 44 passed, 0 failed (exit 0, 7 s; 34 at the base); torrust-tracker-core 185 passed, 0 failed (exit 0, 43 s; 185 at the base); torrust-tracker-udp-server 252 passed, 0 failed, 1 ignored (exit 0, 38 s; 252 at the base); cargo clippy over torrust-tracker-axum-http-server torrust-tracker-configuration torrust-tracker-http-core torrust-tracker-primitives torrust-tracker-core torrust-tracker-udp-server with all targets and features and -D warnings: exit 0, 0 diagnostics. GitHub checks at this head at posting time: "Publish (Development): completed/skipped; Publish (Release): completed/skipped; Context: completed/success; Package Coverage Regression: completed/success; Package Coverage (torrust-tracker-axum-http-server): completed/success; Package Coverage (torrust-tracker-http-core): completed/success; Package Coverage (torrust-tracker-configuration): completed/success; Package Coverage (torrust-tracker-udp-server): completed/success; Package Coverage (torrust-tracker-core): completed/success; Package Coverage (torrust-tracker-primitives): completed/success; Docker E2E: completed/skipped; Documented Clippy Allows: completed/success; Unit (nightly): completed/success; Shipped Features: completed/success; Unit (stable): completed/success; Layer Boundary Bans: completed/success; Workspace Packaging: completed/success; Test (Docker) (release): completed/success; Generate Coverage Report: completed/success; Discover Package Coverage: completed/success; Build on windows-latest (nightly): completed/success; Build on macos-latest (nightly): completed/success; Build on ubuntu-latest (nightly): completed/success; Build on windows-latest (stable): completed/success; Build on ubuntu-latest (stable): completed/success; Database Compatibility PostgreSQL (14): completed/success; Database Compatibility PostgreSQL (15): completed/success; Database Compatibility PostgreSQL (17): completed/success; Database Compatibility PostgreSQL (16): completed/success; Database Compatibility MySQL (8.0): completed/success; Build on macos-latest (stable): completed/success; Docs Lint: completed/success; Persistence Benchmark SQLite3: completed/success; Database Compatibility MySQL (8.4): completed/success; Persistence Benchmark MySQL: completed/success; Persistence Benchmark PostgreSQL: completed/success". At posting, develop is 968099d93.

{"complete":1,"incomplete":1,"interval":2147483647,"min interval":120,"peers":[{"ip":"127.0.0.1","peer id":[45,113,66,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,49],"port":7001}]}
```

The tracker was stopped afterwards and no listener remained on ports `16971` and `17071`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[Minor][F4] Preserve the sequencing and cleanup evidence for V3

The new V3 record declares that the tracker was stopped and both ports were free, but records neither the stop command nor the port-check command/output. It also gives only the shared 07:25–07:30 window for V1–V3, with no start/end stamps for the dependent startup and announce steps. docs/templates/MANUAL-VERIFICATION-EVIDENCE.md:51-55 explicitly requires those stamps and the command behind every state claim. The listed response values are consistent with the implementation, but cannot establish these additional claims. In a follow-up, append the retained command evidence (or repeat and accurately timestamp the scenario if it was not retained); do not reconstruct historical times. This also carries into the evidence archived by PR 2684.

This branch was previously deployed

1 inactive deployment
coverage — 3d7d1836 Deployed Oct 28, 2026 by josecelano via Generate Coverage Report #2847
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.

Bound announce intervals to what every delivery protocol can encode

3 participants