Skip to content

Enrich HTTP core Event::TcpAnnounce event - #1472

Merged
josecelano merged 8 commits into
torrust:developfrom
josecelano:1376-add-announced-peer-to-http-core-announce-event
Apr 22, 2025
Merged

josecelano merged 8 commits into
torrust:developfrom
josecelano:1376-add-announced-peer-to-http-core-announce-event

Conversation

@josecelano

@josecelano josecelano commented Apr 22, 2025 •

Copy link
Copy Markdown
Member

Added info_hash and announcement (peer announce request data):

pub enum Event {
    TcpAnnounce {
        connection: ConnectionContext,
        info_hash: InfoHash,
        announcement: PeerAnnouncement,
    },
    TcpScrape {
        connection: ConnectionContext,
    },
}

@josecelano josecelano self-assigned this Apr 22, 2025
@josecelano josecelano added Enhancement / Feature Request Something New - Developer - Torrust Improvement Experience labels Apr 22, 2025
@josecelano josecelano linked an issue Apr 22, 2025 that may be closed by this pull request
@josecelano
josecelano marked this pull request as draft April 22, 2025 11:01
@josecelano
josecelano requested a review from da2ce7 April 22, 2025 11:01
@josecelano
josecelano force-pushed the 1376-add-announced-peer-to-http-core-announce-event branch from f4116a2 to a67e137 Compare April 22, 2025 11:02
@codecov

codecov Bot commented Apr 22, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.44444% with 8 lines in your changes missing coverage. Please review.

Project coverage is 84.51%. Comparing base (27c5f9b) to head (a422e4e).
Report is 9 commits behind head on develop.

Files with missing lines Patch % Lines
packages/http-tracker-core/src/event/mod.rs 90.74% 5 Missing ⚠️
...ackages/http-tracker-core/src/services/announce.rs 98.85% 0 Missing and 1 partial ⚠️
packages/http-tracker-core/src/services/mod.rs 94.44% 1 Missing ⚠️
packages/http-tracker-core/src/services/scrape.rs 94.73% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1472      +/-   ##
===========================================
+ Coverage    84.49%   84.51%   +0.02%     
===========================================
  Files          254      255       +1     
  Lines        19337    19437     +100     
  Branches     19337    19437     +100     
===========================================
+ Hits         16338    16427      +89     
- Misses        2716     2726      +10     
- Partials       283      284       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This test has been added becuase this code was not working:

```rust
let mut announced_peer = peer_copy;
announced_peer.peer_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);

let mut added_peer = peer;
added_peer.peer_addr = SocketAddr::new(
    IpAddr::V6(Ipv6Addr::new(0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969)),
    8080,
);

let mut http_stats_event_sender_mock = MockHttpStatsEventSender::new();
http_stats_event_sender_mock
    .expect_send_event()
    .with(eq(Event::TcpAnnounce {
        connection: ConnectionContext::new(
            IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
            Some(8080),
            server_service_binding,
        ),
        announced_peer: peer,
        added_peer: peer,
    }))
    .times(1)
    .returning(|_| Box::pin(future::ready(Some(Ok(1)))));
```

using the same events:

Event sent:

TcpAnnounce { connection: ConnectionContext { client: ClientConnectionContext { ip_addr: 127.0.0.1, port: Some(8080) }, server: ServerConnectionContext { service_binding: ServiceBinding { protocol: HTTP, bind_address: 127.0.0.1:7070 } } }, announced_peer: Peer { peer_id: PeerId([45, 113, 66, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48]), peer_addr: 127.0.0.1:8080, updated: 1745316858.487824645s, uploaded: NumberOfBytes(I64(0)), downloaded: NumberOfBytes(I64(0)), left: NumberOfBytes(I64(0)), event: Started }, added_peer: Peer { peer_id: PeerId([45, 113, 66, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48]), peer_addr: [6969:6969:6969:6969:6969:6969:6969:6969]:8080, updated: 1745316858.487824645s, uploaded: NumberOfBytes(I64(0)), downloaded: NumberOfBytes(I64(0)), left: NumberOfBytes(I64(0)), event: Started } }

Event expected in the mock:

TcpAnnounce { connection: ConnectionContext { client: ClientConnectionContext { ip_addr: 127.0.0.1, port: Some(8080) }, server: ServerConnectionContext { service_binding: ServiceBinding { protocol: HTTP, bind_address: 127.0.0.1:7070 } } }, announced_peer: Peer { peer_id: PeerId([45, 113, 66, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48]), peer_addr: 127.0.0.1:8080, updated: 1745316858.487824645s, uploaded: NumberOfBytes(I64(0)), downloaded: NumberOfBytes(I64(0)), left: NumberOfBytes(I64(0)), event: Started }, added_peer: Peer { peer_id: PeerId([45, 113, 66, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48]), peer_addr: [6969:6969:6969:6969:6969:6969:6969:6969]:8080, updated: 1745316858.487824645s, uploaded: NumberOfBytes(I64(0)), downloaded: NumberOfBytes(I64(0)), left: NumberOfBytes(I64(0)), event: Started } }

That's one of the reasons why the expectation was changed. The other
reason is the only relevant part for the peer in the test is the updated peer
address.
@josecelano
josecelano marked this pull request as ready for review April 22, 2025 11:32
@josecelano josecelano changed the title Add announced Peer and added Peer to HTTP core TcpAnnounce event Add announced and added Peer to HTTP core TcpAnnounce event Apr 22, 2025
@josecelano
josecelano marked this pull request as draft April 22, 2025 15:06
…he peer IP may change

before adding the peer to the swarm, and the original remote client ip is already included in the `ConnectionCotext`.
@josecelano

Copy link
Copy Markdown
Member Author

ACK a422e4e

@josecelano
josecelano marked this pull request as ready for review April 22, 2025 16:21
@josecelano josecelano changed the title Add announced and added Peer to HTTP core TcpAnnounce event Enrich HTTP core Event::TcpAnnounce event Apr 22, 2025
@josecelano
josecelano merged commit c4dc5e3 into torrust:develop Apr 22, 2025
@da2ce7

da2ce7 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Post-merge note: this pull request requested a review from this account and was closed without one at its final head. A post-merge review will not be done: Only 112 of the 282 executable lines it added remain on the default branch, at their own paths or in the files those paths were later renamed to; the rest has since been rewritten or removed.

This branch was previously deployed

1 inactive deployment
coverage — a422e4ee Deployed Apr 22, 2025 by josecelano
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

- Developer - Torrust Improvement Experience Enhancement / Feature Request Something New

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overhaul stats: Add announced Peer to HTTP core announce event

2 participants