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
27 lines (25 loc) · 1.01 KB
/
Copy pathpeer_builder.rs
File metadata and controls
27 lines (25 loc) · 1.01 KB
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
27
//! Logic to extract the peer info from the announce request.
use std::net::{IpAddr, SocketAddr};
use super::request::AnnounceWrapper;
use crate::shared::clock::{Current, Time};
use crate::tracker::peer::{Id, Peer};
/// Extracts the [`Peer`] info from the
/// announce request.
///
/// # Arguments
///
/// * `announce_wrapper` - The announce request to extract the peer info from.
/// * `peer_ip` - The real IP address of the peer, not the one in the announce
/// request.
#[must_use]
pub fn from_request(announce_wrapper: &AnnounceWrapper, peer_ip: &IpAddr) -> Peer {
Peer {
peer_id: Id(announce_wrapper.announce_request.peer_id.0),
peer_addr: SocketAddr::new(*peer_ip, announce_wrapper.announce_request.port.0),
updated: Current::now(),
uploaded: announce_wrapper.announce_request.bytes_uploaded,
downloaded: announce_wrapper.announce_request.bytes_downloaded,
left: announce_wrapper.announce_request.bytes_left,
event: announce_wrapper.announce_request.event,
}
}