Repository navigation
Description
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 minimalCargo.toml(name = "torrust-net-primitives",
publish = true) andsrc/lib.rsandREADME.md. - Move
ServiceBinding(and its moduleservice_binding) frompackages/primitives/to
packages/net-primitives/. - Add
torrust-net-primitivesto the workspace[members]inCargo.toml. - Update
packages/server-lib/Cargo.tomlto depend ontorrust-net-primitivesinstead of
torrust-tracker-primitives. - Remove
torrust-tracker-primitivesdep frompackages/server-lib/Cargo.toml(ServiceBinding
was its only reason). - Add a
#[deprecated]re-export ofServiceBindinginpackages/primitives/src/lib.rs(same
pattern asDurationSinceUnixEpoch) for external consumer backwards compatibility. - Update all workspace files that import
ServiceBindingfromtorrust_tracker_primitivesto
import fromtorrust_net_primitives. - Verify the workspace builds and all tests pass.
Out of Scope
- Moving other types from
torrust-tracker-primitivesintotorrust-net-primitives. - Publishing
torrust-net-primitivesto crates.io (handled in the release cycle). - Removing the
#[deprecated]re-export fromtorrust-tracker-primitivesfor 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-primitivesexportsServiceBindingpublicly. -
packages/primitives/src/no longer definesServiceBinding(only re-exports it via#[deprecated]fromtorrust_net_primitives). -
packages/server-lib/Cargo.tomldoes not listtorrust-tracker-primitivesas a dependency (replaced bytorrust-net-primitives). - No workspace file imports
ServiceBindingfromtorrust_tracker_primitivesdirectly. -
cargo build --workspacesucceeds with zero errors. -
cargo test --workspacepasses with zero failures. -
linter allexits with code0.
Local Spec
docs/issues/open/ (will be moved from drafts/ once this issue number is assigned).
Activity
docs(issues): update spec torrust#1797 with related PR torrust#1799
docs(issues): add issue specification for #1797
feat(primitives): create torrust-net-primitives and move ServiceBindi…
docs(issues): regenerate workspace coupling report after #1797
Merge torrust#1799: feat(primitives): create torrust-net-primitives a…
chore(issues): archive closed issue specs #1790, #1793, #1795, #1797, #…
Merge #1812: chore(issues): archive closed issue specs to docs/issues…
Merge #1831: docs(1669): refresh EPIC planning and open SI-11/SI-12 s…