Skip to content

Commit a67e137

Browse files
committed
feat: [#1376] add peer info to TcpAnnounce event
1 parent 27c5f9b commit a67e137

4 files changed

Lines changed: 200 additions & 69 deletions

File tree

packages/http-tracker-core/src/event/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@ use std::net::{IpAddr, SocketAddr};
22

33
use torrust_tracker_metrics::label::{LabelSet, LabelValue};
44
use torrust_tracker_metrics::label_name;
5+
use torrust_tracker_primitives::peer::Peer;
56
use torrust_tracker_primitives::service_binding::ServiceBinding;
67

78
pub mod sender;
89

910
/// A HTTP core event.
1011
#[derive(Debug, PartialEq, Eq, Clone)]
1112
pub enum Event {
12-
TcpAnnounce { connection: ConnectionContext },
13-
TcpScrape { connection: ConnectionContext },
13+
TcpAnnounce {
14+
connection: ConnectionContext,
15+
16+
/// The peer that is announcing itself to the tracker.
17+
announced_peer: Peer,
18+
19+
/// The peer that is added to the tracker.
20+
///
21+
/// It might not be the same as the `announced_peer` because the tracker
22+
/// can change the peer's IP address.
23+
added_peer: Peer,
24+
},
25+
TcpScrape {
26+
connection: ConnectionContext,
27+
},
1428
}
1529

1630
#[derive(Debug, PartialEq, Eq, Clone)]

packages/http-tracker-core/src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ pub const HTTP_TRACKER_LOG_TARGET: &str = "HTTP TRACKER";
2020

2121
#[cfg(test)]
2222
pub(crate) mod tests {
23+
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
24+
25+
use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes, PeerId};
2326
use bittorrent_primitives::info_hash::InfoHash;
27+
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch};
2428

2529
/// # Panics
2630
///
@@ -31,4 +35,29 @@ pub(crate) mod tests {
3135
.parse::<InfoHash>()
3236
.expect("String should be a valid info hash")
3337
}
38+
39+
pub fn sample_peer_using_ipv4() -> peer::Peer {
40+
sample_peer()
41+
}
42+
43+
pub fn sample_peer_using_ipv6() -> peer::Peer {
44+
let mut peer = sample_peer();
45+
peer.peer_addr = SocketAddr::new(
46+
IpAddr::V6(Ipv6Addr::new(0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969)),
47+
8080,
48+
);
49+
peer
50+
}
51+
52+
pub fn sample_peer() -> peer::Peer {
53+
peer::Peer {
54+
peer_id: PeerId(*b"-qB00000000000000000"),
55+
peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1)), 8080),
56+
updated: DurationSinceUnixEpoch::new(1_669_397_478_934, 0),
57+
uploaded: NumberOfBytes::new(0),
58+
downloaded: NumberOfBytes::new(0),
59+
left: NumberOfBytes::new(0),
60+
event: AnnounceEvent::Started,
61+
}
62+
}
3463
}

0 commit comments

Comments
 (0)