forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpeer_builder.rs
More file actions
26 lines (23 loc) · 887 Bytes
/
peer_builder.rs
File metadata and controls
26 lines (23 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//! Logic to extract the peer info from the announce request.
use std::net::{IpAddr, SocketAddr};
use torrust_tracker_clock::clock::Time;
use torrust_tracker_primitives::peer;
use crate::CurrentClock;
/// Extracts the [`peer::Peer`] info from the
/// announce request.
///
/// # Arguments
///
/// * `peer_ip` - The real IP address of the peer, not the one in the announce request.
#[must_use]
pub fn from_request(announce_request: &aquatic_udp_protocol::AnnounceRequest, peer_ip: &IpAddr) -> peer::Peer {
peer::Peer {
peer_id: announce_request.peer_id,
peer_addr: SocketAddr::new(*peer_ip, announce_request.port.0.into()),
updated: CurrentClock::now(),
uploaded: announce_request.bytes_uploaded,
downloaded: announce_request.bytes_downloaded,
left: announce_request.bytes_left,
event: announce_request.event.into(),
}
}