forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfixtures.rs
More file actions
78 lines (67 loc) · 1.97 KB
/
fixtures.rs
File metadata and controls
78 lines (67 loc) · 1.97 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::{IpAddr, Ipv4Addr, SocketAddr};
use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes};
use torrust_tracker::core::peer::{self, Id, Peer};
use torrust_tracker::shared::clock::DurationSinceUnixEpoch;
pub struct PeerBuilder {
peer: Peer,
}
impl PeerBuilder {
#[allow(dead_code)]
pub fn default() -> PeerBuilder {
Self {
peer: default_peer_for_testing(),
}
}
#[allow(dead_code)]
pub fn with_peer_id(mut self, peer_id: &Id) -> Self {
self.peer.peer_id = *peer_id;
self
}
#[allow(dead_code)]
pub fn with_peer_addr(mut self, peer_addr: &SocketAddr) -> Self {
self.peer.peer_addr = *peer_addr;
self
}
#[allow(dead_code)]
pub fn with_bytes_pending_to_download(mut self, left: i64) -> Self {
self.peer.left = NumberOfBytes(left);
self
}
#[allow(dead_code)]
pub fn with_no_bytes_pending_to_download(mut self) -> Self {
self.peer.left = NumberOfBytes(0);
self
}
#[allow(dead_code)]
pub fn build(self) -> Peer {
self.into()
}
#[allow(dead_code)]
pub fn into(self) -> Peer {
self.peer
}
}
#[allow(dead_code)]
fn default_peer_for_testing() -> Peer {
Peer {
peer_id: peer::Id(*b"-qB00000000000000000"),
peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1)), 8080),
updated: DurationSinceUnixEpoch::new(1_669_397_478_934, 0),
uploaded: NumberOfBytes(0),
downloaded: NumberOfBytes(0),
left: NumberOfBytes(0),
event: AnnounceEvent::Started,
}
}
#[allow(dead_code)]
pub fn invalid_info_hashes() -> Vec<String> {
[
"0".to_string(),
"-1".to_string(),
"1.1".to_string(),
"INVALID INFOHASH".to_string(),
"9c38422213e30bff212b30c360d26f9a0213642".to_string(), // 39-char length instead of 40
"9c38422213e30bff212b30c360d26f9a0213642&".to_string(), // Invalid char
]
.to_vec()
}