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
ConnectionContext into a single canonical definition (likely in udp-core)
- Move
MAX_PACKET_SIZE to udp-protocol and import it in both udp-server and tracker-client
- Remove the unused
PROTOCOL_ID constant from tracker-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-protocol beyond 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
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-pasteThe struct and its entire
implblock are duplicated betweenpackages/udp-core/src/event.rsandpackages/udp-server/src/event.rs. The only difference is field visibility (pubin core, private in server). The impl blocks are identical.🟡
MAX_PACKET_SIZE— same constant, two locationsBoth
packages/udp-server/src/lib.rsandpackages/tracker-client/src/udp/mod.rsdefinepub const MAX_PACKET_SIZE: usize = 1496;. Thetracker-clientalready depends onudp-protocol; this constant could live there and be shared.🟡
PROTOCOL_ID— dead code copypackages/tracker-client/src/udp/mod.rsdefinespub const PROTOCOL_IDwhich is unused — zero references anywhere. It mirrorsPROTOCOL_IDENTIFIERfromudp-protocol. Should be removed.🟢 Intentional duplications (not in scope)
AnnounceEvent,InfoHash, andNumberOfBytesare kept separate per ADR 20260527175600. As part of this issue, each location will gain anadr:comment so future contributors understand the architectural reasoning and do not accidentally re-couple the types.Scope
In Scope
ConnectionContextinto a single canonical definition (likely inudp-core)MAX_PACKET_SIZEtoudp-protocoland import it in bothudp-serverandtracker-clientPROTOCOL_IDconstant fromtracker-clientadr:comments to intentional-duplication locations referencing the ADROut of Scope
AnnounceEvent,InfoHash,NumberOfBytes) — governed by ADRudp-protocolbeyond what's needed for consolidationReferences
docs/issues/drafts/1669-si-35-consolidate-duplicate-udp-types.mddocs/issues/open/1669-overhaul-packages/DECISIONS.mddocs/adrs/20260527175600_keep_protocol_and_domain_types_decoupled.md