1
- use crate :: statistics:: event:: { Event , UdpResponseKind } ;
1
+ use crate :: statistics:: event:: { Event , UdpRequestKind , UdpResponseKind } ;
2
2
use crate :: statistics:: repository:: Repository ;
3
3
4
4
pub async fn handle_event ( event : Event , stats_repository : & Repository ) {
@@ -16,16 +16,15 @@ pub async fn handle_event(event: Event, stats_repository: &Repository) {
16
16
stats_repository. increase_udp4_requests ( ) . await ;
17
17
}
18
18
Event :: Udp4Request { kind } => match kind {
19
- UdpResponseKind :: Connect => {
19
+ UdpRequestKind :: Connect => {
20
20
stats_repository. increase_udp4_connections ( ) . await ;
21
21
}
22
- UdpResponseKind :: Announce => {
22
+ UdpRequestKind :: Announce => {
23
23
stats_repository. increase_udp4_announces ( ) . await ;
24
24
}
25
- UdpResponseKind :: Scrape => {
25
+ UdpRequestKind :: Scrape => {
26
26
stats_repository. increase_udp4_scrapes ( ) . await ;
27
27
}
28
- UdpResponseKind :: Error => { }
29
28
} ,
30
29
Event :: Udp4Response {
31
30
kind,
@@ -34,21 +33,23 @@ pub async fn handle_event(event: Event, stats_repository: &Repository) {
34
33
stats_repository. increase_udp4_responses ( ) . await ;
35
34
36
35
match kind {
37
- UdpResponseKind :: Connect => {
38
- stats_repository
39
- . recalculate_udp_avg_connect_processing_time_ns ( req_processing_time)
40
- . await ;
41
- }
42
- UdpResponseKind :: Announce => {
43
- stats_repository
44
- . recalculate_udp_avg_announce_processing_time_ns ( req_processing_time)
45
- . await ;
46
- }
47
- UdpResponseKind :: Scrape => {
48
- stats_repository
49
- . recalculate_udp_avg_scrape_processing_time_ns ( req_processing_time)
50
- . await ;
51
- }
36
+ UdpResponseKind :: Ok { req_kind } => match req_kind {
37
+ UdpRequestKind :: Connect => {
38
+ stats_repository
39
+ . recalculate_udp_avg_connect_processing_time_ns ( req_processing_time)
40
+ . await ;
41
+ }
42
+ UdpRequestKind :: Announce => {
43
+ stats_repository
44
+ . recalculate_udp_avg_announce_processing_time_ns ( req_processing_time)
45
+ . await ;
46
+ }
47
+ UdpRequestKind :: Scrape => {
48
+ stats_repository
49
+ . recalculate_udp_avg_scrape_processing_time_ns ( req_processing_time)
50
+ . await ;
51
+ }
52
+ } ,
52
53
UdpResponseKind :: Error => { }
53
54
}
54
55
}
@@ -61,16 +62,15 @@ pub async fn handle_event(event: Event, stats_repository: &Repository) {
61
62
stats_repository. increase_udp6_requests ( ) . await ;
62
63
}
63
64
Event :: Udp6Request { kind } => match kind {
64
- UdpResponseKind :: Connect => {
65
+ UdpRequestKind :: Connect => {
65
66
stats_repository. increase_udp6_connections ( ) . await ;
66
67
}
67
- UdpResponseKind :: Announce => {
68
+ UdpRequestKind :: Announce => {
68
69
stats_repository. increase_udp6_announces ( ) . await ;
69
70
}
70
- UdpResponseKind :: Scrape => {
71
+ UdpRequestKind :: Scrape => {
71
72
stats_repository. increase_udp6_scrapes ( ) . await ;
72
73
}
73
- UdpResponseKind :: Error => { }
74
74
} ,
75
75
Event :: Udp6Response {
76
76
kind : _,
@@ -89,7 +89,7 @@ pub async fn handle_event(event: Event, stats_repository: &Repository) {
89
89
#[ cfg( test) ]
90
90
mod tests {
91
91
use crate :: statistics:: event:: handler:: handle_event;
92
- use crate :: statistics:: event:: Event ;
92
+ use crate :: statistics:: event:: { Event , UdpRequestKind } ;
93
93
use crate :: statistics:: repository:: Repository ;
94
94
95
95
#[ tokio:: test]
@@ -148,7 +148,7 @@ mod tests {
148
148
149
149
handle_event (
150
150
Event :: Udp4Request {
151
- kind : crate :: statistics:: event:: UdpResponseKind :: Connect ,
151
+ kind : crate :: statistics:: event:: UdpRequestKind :: Connect ,
152
152
} ,
153
153
& stats_repository,
154
154
)
@@ -165,7 +165,7 @@ mod tests {
165
165
166
166
handle_event (
167
167
Event :: Udp4Request {
168
- kind : crate :: statistics:: event:: UdpResponseKind :: Announce ,
168
+ kind : crate :: statistics:: event:: UdpRequestKind :: Announce ,
169
169
} ,
170
170
& stats_repository,
171
171
)
@@ -182,7 +182,7 @@ mod tests {
182
182
183
183
handle_event (
184
184
Event :: Udp4Request {
185
- kind : crate :: statistics:: event:: UdpResponseKind :: Scrape ,
185
+ kind : crate :: statistics:: event:: UdpRequestKind :: Scrape ,
186
186
} ,
187
187
& stats_repository,
188
188
)
@@ -199,7 +199,9 @@ mod tests {
199
199
200
200
handle_event (
201
201
Event :: Udp4Response {
202
- kind : crate :: statistics:: event:: UdpResponseKind :: Announce ,
202
+ kind : crate :: statistics:: event:: UdpResponseKind :: Ok {
203
+ req_kind : UdpRequestKind :: Announce ,
204
+ } ,
203
205
req_processing_time : std:: time:: Duration :: from_secs ( 1 ) ,
204
206
} ,
205
207
& stats_repository,
@@ -228,7 +230,7 @@ mod tests {
228
230
229
231
handle_event (
230
232
Event :: Udp6Request {
231
- kind : crate :: statistics:: event:: UdpResponseKind :: Connect ,
233
+ kind : crate :: statistics:: event:: UdpRequestKind :: Connect ,
232
234
} ,
233
235
& stats_repository,
234
236
)
@@ -245,7 +247,7 @@ mod tests {
245
247
246
248
handle_event (
247
249
Event :: Udp6Request {
248
- kind : crate :: statistics:: event:: UdpResponseKind :: Announce ,
250
+ kind : crate :: statistics:: event:: UdpRequestKind :: Announce ,
249
251
} ,
250
252
& stats_repository,
251
253
)
@@ -262,7 +264,7 @@ mod tests {
262
264
263
265
handle_event (
264
266
Event :: Udp6Request {
265
- kind : crate :: statistics:: event:: UdpResponseKind :: Scrape ,
267
+ kind : crate :: statistics:: event:: UdpRequestKind :: Scrape ,
266
268
} ,
267
269
& stats_repository,
268
270
)
@@ -279,7 +281,9 @@ mod tests {
279
281
280
282
handle_event (
281
283
Event :: Udp6Response {
282
- kind : crate :: statistics:: event:: UdpResponseKind :: Announce ,
284
+ kind : crate :: statistics:: event:: UdpResponseKind :: Ok {
285
+ req_kind : UdpRequestKind :: Announce ,
286
+ } ,
283
287
req_processing_time : std:: time:: Duration :: from_secs ( 1 ) ,
284
288
} ,
285
289
& stats_repository,
0 commit comments