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
78 lines (68 loc) · 1.72 KB
/
Copy pathmod.rs
File metadata and controls
78 lines (68 loc) · 1.72 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use std::net::SocketAddr;
use std::time::Duration;
use torrust_tracker_primitives::service_binding::ServiceBinding;
pub mod sender;
/// A UDP server event.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Event {
UdpRequestReceived {
context: ConnectionContext,
},
UdpRequestAborted {
context: ConnectionContext,
},
UdpRequestBanned {
context: ConnectionContext,
},
UdpRequestAccepted {
context: ConnectionContext,
kind: UdpRequestKind,
},
UdpResponseSent {
context: ConnectionContext,
kind: UdpResponseKind,
req_processing_time: Duration,
},
UdpError {
context: ConnectionContext,
},
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum UdpRequestKind {
Connect,
Announce,
Scrape,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum UdpResponseKind {
Ok {
req_kind: UdpRequestKind,
},
/// There was an error handling the request. The error contains the request
/// kind if the request was parsed successfully.
Error {
opt_req_kind: Option<UdpRequestKind>,
},
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct ConnectionContext {
client_socket_addr: SocketAddr,
server_service_binding: ServiceBinding,
}
impl ConnectionContext {
#[must_use]
pub fn new(client_socket_addr: SocketAddr, server_service_binding: ServiceBinding) -> Self {
Self {
client_socket_addr,
server_service_binding,
}
}
#[must_use]
pub fn client_socket_addr(&self) -> SocketAddr {
self.client_socket_addr
}
#[must_use]
pub fn server_socket_addr(&self) -> SocketAddr {
self.server_service_binding.bind_address()
}
}