Skip to content

Create torrust-net-primitives and move ServiceBinding from torrust-tracker-primitives #1797

Closed

Description

@josecelano

Goal

Create a new torrust-net-primitives package containing generic networking primitives (starting
with ServiceBinding) and move ServiceBinding out of torrust-tracker-primitives into this
new crate. torrust-server-lib then depends on torrust-net-primitives instead of
torrust-tracker-primitives, breaking an unnecessary coupling.

Background

The coupling analysis (F-04) found that torrust-server-lib depends on
torrust-tracker-primitives solely to import ServiceBinding — a struct representing a
network address binding (socket address at which a service listens). torrust-server-lib is a
generic server utility library with no tracker-specific concerns; pulling in the entire
torrust-tracker-* primitives crate for one generic networking type is wasteful and semantically
misleading.

ServiceBinding is a very generic concept that can be reused across the Torrust organisation,
not just in the tracker. Creating a dedicated torrust-net-primitives crate makes the type
available to any Torrust project without a torrust-tracker-* dependency.

Both torrust-tracker-primitives (source) and the new torrust-net-primitives (destination)
are intended to be published to crates.io. A #[deprecated] re-export of ServiceBinding will
be kept in torrust-tracker-primitives for external crates.io consumers backwards compatibility,
following the same pattern used for DurationSinceUnixEpoch and AnnouncePolicy.

This issue is a subissue of EPIC #1669 (Overhaul: Packages). Part of SI-05.

Scope

In Scope

  • Create packages/net-primitives/ with a minimal Cargo.toml (name = "torrust-net-primitives",
    publish = true) and src/lib.rs and README.md.
  • Move ServiceBinding (and its module service_binding) from packages/primitives/ to
    packages/net-primitives/.
  • Add torrust-net-primitives to the workspace [members] in Cargo.toml.
  • Update packages/server-lib/Cargo.toml to depend on torrust-net-primitives instead of
    torrust-tracker-primitives.
  • Remove torrust-tracker-primitives dep from packages/server-lib/Cargo.toml (ServiceBinding
    was its only reason).
  • Add a #[deprecated] re-export of ServiceBinding in packages/primitives/src/lib.rs (same
    pattern as DurationSinceUnixEpoch) for external consumer backwards compatibility.
  • Update all workspace files that import ServiceBinding from torrust_tracker_primitives to
    import from torrust_net_primitives.
  • Verify the workspace builds and all tests pass.

Out of Scope

  • Moving other types from torrust-tracker-primitives into torrust-net-primitives.
  • Publishing torrust-net-primitives to crates.io (handled in the release cycle).
  • Removing the #[deprecated] re-export from torrust-tracker-primitives for external consumers
    (requires crates.io semver bump, deferred).

Implementation Plan

ID Status Task
T1 TODO Locate all usage sites of ServiceBinding in the workspace
T2 TODO Create packages/net-primitives/Cargo.toml, src/lib.rs, and README.md
T3 TODO Add packages/net-primitives to workspace [members] in root Cargo.toml
T4 TODO Move service_binding module to packages/net-primitives/src/
T5 TODO Replace service_binding module in packages/primitives/src/ with a #[deprecated] re-export
T6 TODO Update packages/server-lib/Cargo.toml: replace torrust-tracker-primitives dep with torrust-net-primitives
T7 TODO Update all other workspace files importing ServiceBinding from torrust_tracker_primitives to torrust_net_primitives
T8 TODO Run cargo build --workspace and cargo test --workspace
T9 TODO Run linter all

Acceptance Criteria

  • packages/net-primitives/ exists and is a member of the workspace.
  • torrust-net-primitives exports ServiceBinding publicly.
  • packages/primitives/src/ no longer defines ServiceBinding (only re-exports it via #[deprecated] from torrust_net_primitives).
  • packages/server-lib/Cargo.toml does not list torrust-tracker-primitives as a dependency (replaced by torrust-net-primitives).
  • No workspace file imports ServiceBinding from torrust_tracker_primitives directly.
  • cargo build --workspace succeeds with zero errors.
  • cargo test --workspace passes with zero failures.
  • linter all exits with code 0.

Local Spec

docs/issues/open/ (will be moved from drafts/ once this issue number is assigned).

Activity

  1. self-assigned this
    on May 19, 2026
  2. added 4 commits that reference this issue on May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions