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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use std::fmt;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct RetriedStatsInfo {
retried_total: usize,
retried_on_current_endpoint: usize,
retried_on_current_ips: usize,
abandoned_endpoints: usize,
abandoned_ips_of_current_endpoint: usize,
switched_to_alternative_endpoints: bool,
}
impl RetriedStatsInfo {
#[inline]
pub fn increase_current_endpoint(&mut self) {
self.retried_total += 1;
self.retried_on_current_endpoint += 1;
self.retried_on_current_ips += 1;
}
#[inline]
pub fn increase_abandoned_endpoints(&mut self) {
self.abandoned_endpoints += 1;
}
#[inline]
pub fn increase_abandoned_ips_of_current_endpoint(&mut self) {
self.abandoned_ips_of_current_endpoint += 1;
}
#[inline]
pub fn switch_to_alternative_endpoints(&mut self) {
self.switched_to_alternative_endpoints = true;
self.switch_endpoint();
}
pub fn switch_endpoint(&mut self) {
self.retried_on_current_endpoint = 0;
self.abandoned_ips_of_current_endpoint = 0;
self.switch_ips();
}
pub fn switch_ips(&mut self) {
self.retried_on_current_ips = 0;
}
#[inline]
pub fn retried_total(&self) -> usize {
self.retried_total
}
#[inline]
pub fn retried_on_current_endpoint(&self) -> usize {
self.retried_on_current_endpoint
}
#[inline]
pub fn retried_on_current_ips(&self) -> usize {
self.retried_on_current_ips
}
#[inline]
pub fn abandoned_endpoints(&self) -> usize {
self.abandoned_endpoints
}
#[inline]
pub fn abandoned_ips_of_current_endpoint(&self) -> usize {
self.abandoned_ips_of_current_endpoint
}
#[inline]
pub fn switched_to_alternative_endpoints(&self) -> bool {
self.switched_to_alternative_endpoints
}
}
impl fmt::Display for RetriedStatsInfo {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{},{},{},{},{},{}",
self.retried_total,
self.retried_on_current_endpoint,
self.retried_on_current_ips,
self.abandoned_endpoints,
self.abandoned_ips_of_current_endpoint,
if self.switched_to_alternative_endpoints {
"a" } else {
"p" }
)
}
}