forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
61 lines (50 loc) · 1.5 KB
/
mod.rs
File metadata and controls
61 lines (50 loc) · 1.5 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::net::{IpAddr, SocketAddr};
use torrust_tracker_primitives::service_binding::ServiceBinding;
pub mod sender;
/// A HTTP core event.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Event {
TcpAnnounce { connection: ConnectionContext },
TcpScrape { connection: ConnectionContext },
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct ConnectionContext {
client: ClientConnectionContext,
server: ServerConnectionContext,
}
impl ConnectionContext {
#[must_use]
pub fn new(client_ip_addr: IpAddr, opt_client_port: Option<u16>, server_service_binding: ServiceBinding) -> Self {
Self {
client: ClientConnectionContext {
ip_addr: client_ip_addr,
port: opt_client_port,
},
server: ServerConnectionContext {
service_binding: server_service_binding,
},
}
}
#[must_use]
pub fn client_ip_addr(&self) -> IpAddr {
self.client.ip_addr
}
#[must_use]
pub fn client_port(&self) -> Option<u16> {
self.client.port
}
#[must_use]
pub fn server_socket_addr(&self) -> SocketAddr {
self.server.service_binding.bind_address()
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct ClientConnectionContext {
ip_addr: IpAddr,
/// It's provided if you use the `torrust-axum-http-tracker-server` crate.
port: Option<u16>,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct ServerConnectionContext {
service_binding: ServiceBinding,
}