Skip to content

EPIC 1669 SI-35: Consolidate duplicate UDP types #1966

Closed

Description

@josecelano

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

Activity

  1. self-assigned this
    on Jun 30, 2026
  2. added 2 commits that reference this issue on Jun 30, 2026
  3. added a commit that references this issue on Jul 20, 2026
  4. added a commit that references this issue on Jul 22, 2026
  5. added a commit that references this issue on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Code Cleanup / Refactoringtask

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions