Skip to content

Commit 548659b

Browse files
committed
refactor(http-protocol): merge announce DTO layer into layered module
Moved deserialization types from `announce_deserialization.rs` into `announce/deserialization.rs` - Renamed: `Announce` → `DeserializedNormal`, `Compact` → `DeserializedCompactParsed` - Added `peers6` field to `DeserializedCompact` (IPv6 support per BEP 7) - Replaced `CompactPeer` (IPv4-only struct) with shared `encoding::CompactPeer` enum (IPv4+V6) - Added `CompactPeer::new_from_bytes` supporting both 6-byte IPv4 and 18-byte IPv6 formats - Deleted `announce_deserialization.rs` - Updated all 8 import sites across 6 files - Spec progress: T11 marked DONE - All linters and tests pass
1 parent 3dd9357 commit 548659b

10 files changed

Lines changed: 116 additions & 93 deletions

File tree

console/tracker-client/src/console/clients/checker/checks/http.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use torrust_info_hash::InfoHash;
66
use torrust_tracker_client::http::client::Client;
77
use torrust_tracker_http_protocol::v1::requests::announce::AnnounceBuilder;
88
use torrust_tracker_http_protocol::v1::requests::scrape_builder;
9-
use torrust_tracker_http_protocol::v1::responses::announce_deserialization::Announce;
9+
use torrust_tracker_http_protocol::v1::responses::announce::deserialization::DeserializedNormal;
1010
use torrust_tracker_http_protocol::v1::responses::scrape_deserialization;
1111
use url::Url;
1212

@@ -62,7 +62,7 @@ pub async fn run(http_trackers: Vec<Url>, timeout: Duration) -> Vec<Result<Check
6262
results
6363
}
6464

65-
async fn check_http_announce(url: &Url, timeout: Duration) -> Result<Announce, Error> {
65+
async fn check_http_announce(url: &Url, timeout: Duration) -> Result<DeserializedNormal, Error> {
6666
let info_hash_str = "9c38422213e30bff212b30c360d26f9a02136422".to_string(); // DevSkim: ignore DS173237
6767
let info_hash = InfoHash::from_str(&info_hash_str).expect("a valid info-hash is required");
6868

@@ -75,7 +75,7 @@ async fn check_http_announce(url: &Url, timeout: Duration) -> Result<Announce, E
7575

7676
let response = response.bytes().await.map_err(|e| Error::ResponseError { err: e.into() })?;
7777

78-
let response = serde_bencode::from_bytes::<Announce>(&response).map_err(|e| Error::ParseBencodeError {
78+
let response = serde_bencode::from_bytes::<DeserializedNormal>(&response).map_err(|e| Error::ParseBencodeError {
7979
data: response,
8080
err: e.into(),
8181
})?;

console/tracker-client/src/console/clients/http/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ use torrust_peer_id::PeerId;
8181
use torrust_tracker_client::http::client::Client;
8282
use torrust_tracker_http_protocol::v1::requests::announce::{AnnounceBuilder, Compact, Event};
8383
use torrust_tracker_http_protocol::v1::requests::scrape_builder;
84-
use torrust_tracker_http_protocol::v1::responses::announce_deserialization::{Announce, DeserializedCompact};
84+
use torrust_tracker_http_protocol::v1::responses::announce::deserialization::{DeserializedCompact, DeserializedNormal};
8585
use torrust_tracker_http_protocol::v1::responses::scrape_deserialization;
8686

8787
use crate::DEFAULT_NETWORK_TIMEOUT;
@@ -269,7 +269,7 @@ async fn announce_command(options: AnnounceOptions, timeout: Duration) -> anyhow
269269

270270
let body = response.bytes().await?;
271271

272-
let json = if let Ok(announce_response) = serde_bencode::from_bytes::<Announce>(&body) {
272+
let json = if let Ok(announce_response) = serde_bencode::from_bytes::<DeserializedNormal>(&body) {
273273
serialize_json(&announce_response, options.output_format).context("failed to serialize announce response into JSON")?
274274
} else if let Ok(compact_response) = serde_bencode::from_bytes::<DeserializedCompact>(&body) {
275275
serialize_json(&compact_response, options.output_format)

console/tracker-client/src/console/clients/unified/http.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use torrust_peer_id::PeerId;
1111
use torrust_tracker_client::http::client::Client;
1212
use torrust_tracker_http_protocol::v1::requests::announce::{AnnounceBuilder, Compact, Event};
1313
use torrust_tracker_http_protocol::v1::requests::scrape_builder;
14-
use torrust_tracker_http_protocol::v1::responses::announce_deserialization::{Announce, DeserializedCompact};
14+
use torrust_tracker_http_protocol::v1::responses::announce::deserialization::{DeserializedCompact, DeserializedNormal};
1515
use torrust_tracker_http_protocol::v1::responses::scrape_deserialization;
1616

1717
use super::app::OutputFormat;
@@ -185,7 +185,7 @@ async fn announce_command(options: AnnounceOptions, timeout: Duration) -> anyhow
185185

186186
let body = response.bytes().await?;
187187

188-
let json = if let Ok(announce_response) = serde_bencode::from_bytes::<Announce>(&body) {
188+
let json = if let Ok(announce_response) = serde_bencode::from_bytes::<DeserializedNormal>(&body) {
189189
serialize_json(&announce_response, options.output_format).context("failed to serialize announce response into JSON")?
190190
} else if let Ok(compact_response) = serde_bencode::from_bytes::<DeserializedCompact>(&body) {
191191
serialize_json(&compact_response, options.output_format)

docs/issues/open/1965-1669-si-34-consolidate-duplicate-http-types/ISSUE.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -211,28 +211,28 @@ churn from intermediate refactors.
211211

212212
Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`.
213213

214-
| ID | Status | Task | Notes / Expected Output |
215-
| --- | ------ | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
216-
| T1 | DONE | Survey duplicate types and decide merge strategy | Catalog exact types to move; identify which location has the "best" version |
217-
| T2 | DONE | Add client-side types to `http-protocol` | Move query builders, response deserialization structs, and shared helpers |
218-
| T3 | DONE | Add `http-protocol` dependency to `tracker-client` | Update `Cargo.toml`, verify dependency tree |
219-
| T4 | DONE | Replace duplicate types in `tracker-client` | Delete local copies, update imports to `http-protocol` |
220-
| T5 | DONE | Replace duplicate types in `axum-http-server` tests | Delete local copies, update imports to `http-protocol` |
221-
| T6 | DONE | Run full verification (Iteration 1) | `linter all`, `cargo test --workspace`, pre-commit, pre-push |
222-
| | | **Request-side unification (DD6)** | |
223-
| T7 | DONE | Merge `announce_builder::Query` into `Announce` | See [analysis](./analysis-announce-query-vs-announce.md). Added `peer_addr`, `Display`, `AnnounceBuilder`; removed `announce_builder` module |
224-
| T8 | DONE | Update all call sites for unified `Announce` | ~54 call sites updated across 7 files: contract.rs, client.rs, CLI apps, stats test |
225-
| T9 | DONE | Run full verification after announce request merge | `linter all`, `cargo test --workspace`, `cargo test --doc --workspace` — all passed |
226-
| | | **Response-side restructuring (DD7 + DD8)** | |
227-
| T10 | DONE | Restructure announce responses into layered module | Created `announce/{data,encoding}.rs` with `mod.rs` re-exports. Deleted old `announce.rs`. No call sites needed updating (backward compatible) |
228-
| T11 | TODO | Partial merge of announce DTO layer | Rename `Announce``DeserializedNormal`; rename `Compact``DeserializedCompactParsed`; share `CompactPeer` enum; add `peers6`, add IPv6 |
229-
| T12 | TODO | Restructure scrape responses into layered module | Same pattern: `scrape/{data,encoding,deserialization}.rs` |
230-
| T13 | TODO | Partial merge of scrape DTO layer | Same pattern as announce |
231-
| T14 | TODO | Update all call sites for restructured response types | Update imports in tracker-client, axum-http-server tests, CLI apps |
232-
| T15 | TODO | Run full verification after response restructure | `linter all`, `cargo test --workspace`, pre-commit, pre-push |
233-
| | | **Finalization** | |
234-
| T16 | TODO | Replace duplicate HTTP test client (DD9) | Remove `packages/axum-http-server/tests/server/client.rs`; update tests to use `tracker-client` package |
235-
| T17 | TODO | Create `use-tracker-client` skill | New skill in `.github/skills/usage/use-tracker-client/` with learnings from manual verification |
214+
| ID | Status | Task | Notes / Expected Output |
215+
| --- | ------ | ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
216+
| T1 | DONE | Survey duplicate types and decide merge strategy | Catalog exact types to move; identify which location has the "best" version |
217+
| T2 | DONE | Add client-side types to `http-protocol` | Move query builders, response deserialization structs, and shared helpers |
218+
| T3 | DONE | Add `http-protocol` dependency to `tracker-client` | Update `Cargo.toml`, verify dependency tree |
219+
| T4 | DONE | Replace duplicate types in `tracker-client` | Delete local copies, update imports to `http-protocol` |
220+
| T5 | DONE | Replace duplicate types in `axum-http-server` tests | Delete local copies, update imports to `http-protocol` |
221+
| T6 | DONE | Run full verification (Iteration 1) | `linter all`, `cargo test --workspace`, pre-commit, pre-push |
222+
| | | **Request-side unification (DD6)** | |
223+
| T7 | DONE | Merge `announce_builder::Query` into `Announce` | See [analysis](./analysis-announce-query-vs-announce.md). Added `peer_addr`, `Display`, `AnnounceBuilder`; removed `announce_builder` module |
224+
| T8 | DONE | Update all call sites for unified `Announce` | ~54 call sites updated across 7 files: contract.rs, client.rs, CLI apps, stats test |
225+
| T9 | DONE | Run full verification after announce request merge | `linter all`, `cargo test --workspace`, `cargo test --doc --workspace` — all passed |
226+
| | | **Response-side restructuring (DD7 + DD8)** | |
227+
| T10 | DONE | Restructure announce responses into layered module | Created `announce/{data,encoding}.rs` with `mod.rs` re-exports. Deleted old `announce.rs`. No call sites needed updating (backward compatible) |
228+
| T11 | DONE | Partial merge of announce DTO layer | Moved deserialization types into `announce/deserialization.rs`. Renamed `Announce``DeserializedNormal`, `Compact``DeserializedCompactParsed`. Added `peers6` to `DeserializedCompact`. Replaced `CompactPeer` (IPv4-only struct) with shared `encoding::CompactPeer` enum. Deleted `announce_deserialization.rs`. Updated 8 import sites. |
229+
| T12 | TODO | Restructure scrape responses into layered module | Same pattern: `scrape/{data,encoding,deserialization}.rs` |
230+
| T13 | TODO | Partial merge of scrape DTO layer | Same pattern as announce |
231+
| T14 | TODO | Update all call sites for restructured response types | Update imports in tracker-client, axum-http-server tests, CLI apps |
232+
| T15 | TODO | Run full verification after response restructure | `linter all`, `cargo test --workspace`, pre-commit, pre-push |
233+
| | | **Finalization** | |
234+
| T16 | TODO | Replace duplicate HTTP test client (DD9) | Remove `packages/axum-http-server/tests/server/client.rs`; update tests to use `tracker-client` package |
235+
| T17 | TODO | Create `use-tracker-client` skill | New skill in `.github/skills/usage/use-tracker-client/` with learnings from manual verification |
236236

237237
## Progress Tracking
238238

@@ -259,6 +259,7 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`.
259259
- 2026-07-13 16:00 UTC - Copilot - Response-side analysis: decided to restructure into layered modules (DD7) and partial DTO merge (DD8). New tasks T10-T15 added.
260260
- 2026-07-14 10:00 UTC - Copilot - Implementation (T7-T9) completed: merged `announce_builder::Query` into `Announce`, updated all call sites, all verifications passed.
261261
- 2026-07-14 14:00 UTC - Copilot - Implementation (T10) completed: restructured announce responses into `announce/{data,encoding}.rs` layered module.
262+
- 2026-07-14 15:00 UTC - Copilot - Implementation (T11) completed: partial merge of announce DTO layer into `announce/deserialization.rs`.
262263

263264
## Acceptance Criteria
264265

0 commit comments

Comments
 (0)