Repository navigation
Description
Parent EPIC: #1669 — Overhaul: Packages
EPIC spec:docs/issues/open/1669-overhaul-packages/EPIC.md
Goal
Eliminate duplicate type definitions and constants in the UDP tracker packages by consolidating them into their canonical locations.
Background
A workspace-wide audit of UDP-related packages found that the UDP layer is significantly cleaner than the HTTP layer — the core protocol types are defined exclusively in packages/udp-protocol/src/ and imported everywhere else. This is the correct architecture.
However, three duplications were found:
🔴 ConnectionContext — full copy-paste
The struct and its entire impl block are duplicated between packages/udp-core/src/event.rs and packages/udp-server/src/event.rs. The only difference is field visibility (pub in core, private in server). The impl blocks are identical.
🟡 MAX_PACKET_SIZE — same constant, two locations
Both packages/udp-server/src/lib.rs and packages/tracker-client/src/udp/mod.rs define pub const MAX_PACKET_SIZE: usize = 1496;. The tracker-client already depends on udp-protocol; this constant could live there and be shared.
🟡 PROTOCOL_ID — dead code copy
packages/tracker-client/src/udp/mod.rs defines pub const PROTOCOL_ID which is unused — zero references anywhere. It mirrors PROTOCOL_IDENTIFIER from udp-protocol. Should be removed.
🟢 Intentional duplications (not in scope)
AnnounceEvent, InfoHash, and NumberOfBytes are kept separate per ADR 20260527175600. As part of this issue, each location will gain an adr: comment so future contributors understand the architectural reasoning and do not accidentally re-couple the types.
Scope
In Scope
- Consolidate
ConnectionContextinto a single canonical definition (likely inudp-core) - Move
MAX_PACKET_SIZEtoudp-protocoland import it in bothudp-serverandtracker-client - Remove the unused
PROTOCOL_IDconstant fromtracker-client - Add
adr:comments to intentional-duplication locations referencing the ADR - Verify all tests pass and no functionality regresses
Out of Scope
- Merging protocol-level types (
AnnounceEvent,InfoHash,NumberOfBytes) — governed by ADR - Changing the public API of
udp-protocolbeyond what's needed for consolidation - Refactoring the UDP server architecture
References
- Spec:
docs/issues/drafts/1669-si-35-consolidate-duplicate-udp-types.md - Parent EPIC: #1669
- Decisions log:
docs/issues/open/1669-overhaul-packages/DECISIONS.md - Related ADR:
docs/adrs/20260527175600_keep_protocol_and_domain_types_decoupled.md
Activity
docs(issues): add issue specs for #1964, #1965 (SI-34), and #1966 (SI…
Merge #1967: docs(issues): add issue specs for #1964, #1965 (SI-34), …
refactor(udp-core, udp-server, udp-protocol, tracker-client): consoli…
Merge torrust#1991: refactor(udp-core, udp-server, udp-protocol, trac…
Merge #2021: chore(issues): archive closed specs and enforce dual-for…
Merge #2441: docs(issues): [#1669] sync EPIC spec with current worksp…