@@ -6,52 +6,25 @@ use crate::statistics::repository::Repository;
66/// This function panics if the IP version does not match the event type.
77pub async fn handle_event ( event : Event , stats_repository : & Repository ) {
88 match event {
9- // UDP4
10- Event :: Udp4Connect { context } => match context. client_socket_addr . ip ( ) {
9+ Event :: UdpConnect { context } => match context. client_socket_addr . ip ( ) {
1110 std:: net:: IpAddr :: V4 ( _) => {
1211 stats_repository. increase_udp4_connections ( ) . await ;
1312 }
14- std:: net:: IpAddr :: V6 ( _) => {
15- panic ! ( "IP Version 6 does not match the event type for connect" ) ;
16- }
17- } ,
18- Event :: Udp4Announce { context } => match context. client_socket_addr . ip ( ) {
19- std:: net:: IpAddr :: V4 ( _) => {
20- stats_repository. increase_udp4_announces ( ) . await ;
21- }
22- std:: net:: IpAddr :: V6 ( _) => {
23- panic ! ( "IP Version 6 does not match the event type for announce" ) ;
24- }
25- } ,
26- Event :: Udp4Scrape { context } => match context. client_socket_addr . ip ( ) {
27- std:: net:: IpAddr :: V4 ( _) => {
28- stats_repository. increase_udp4_scrapes ( ) . await ;
29- }
30- std:: net:: IpAddr :: V6 ( _) => {
31- panic ! ( "IP Version 6 does not match the event type for scrape" ) ;
32- }
33- } ,
34-
35- // UDP6
36- Event :: Udp6Connect { context } => match context. client_socket_addr . ip ( ) {
37- std:: net:: IpAddr :: V4 ( _) => {
38- panic ! ( "IP Version 4 does not match the event type for connect" ) ;
39- }
4013 std:: net:: IpAddr :: V6 ( _) => {
4114 stats_repository. increase_udp6_connections ( ) . await ;
4215 }
4316 } ,
44- Event :: Udp6Announce { context } => match context. client_socket_addr . ip ( ) {
17+ Event :: UdpAnnounce { context } => match context. client_socket_addr . ip ( ) {
4518 std:: net:: IpAddr :: V4 ( _) => {
46- panic ! ( "IP Version 4 does not match the event type for announce" ) ;
19+ stats_repository . increase_udp4_announces ( ) . await ;
4720 }
4821 std:: net:: IpAddr :: V6 ( _) => {
4922 stats_repository. increase_udp6_announces ( ) . await ;
5023 }
5124 } ,
52- Event :: Udp6Scrape { context } => match context. client_socket_addr . ip ( ) {
25+ Event :: UdpScrape { context } => match context. client_socket_addr . ip ( ) {
5326 std:: net:: IpAddr :: V4 ( _) => {
54- panic ! ( "IP Version 4 does not match the event type for scrape" ) ;
27+ stats_repository . increase_udp4_scrapes ( ) . await ;
5528 }
5629 std:: net:: IpAddr :: V6 ( _) => {
5730 stats_repository. increase_udp6_scrapes ( ) . await ;
@@ -75,7 +48,7 @@ mod tests {
7548 let stats_repository = Repository :: new ( ) ;
7649
7750 handle_event (
78- Event :: Udp4Connect {
51+ Event :: UdpConnect {
7952 context : ConnectionContext :: new (
8053 SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 203 , 0 , 113 , 195 ) ) , 8080 ) ,
8154 SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 203 , 0 , 113 , 196 ) ) , 6969 ) ,
@@ -95,7 +68,7 @@ mod tests {
9568 let stats_repository = Repository :: new ( ) ;
9669
9770 handle_event (
98- Event :: Udp4Announce {
71+ Event :: UdpAnnounce {
9972 context : ConnectionContext :: new (
10073 SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 203 , 0 , 113 , 195 ) ) , 8080 ) ,
10174 SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 203 , 0 , 113 , 196 ) ) , 6969 ) ,
@@ -115,7 +88,7 @@ mod tests {
11588 let stats_repository = Repository :: new ( ) ;
11689
11790 handle_event (
118- Event :: Udp4Scrape {
91+ Event :: UdpScrape {
11992 context : ConnectionContext :: new (
12093 SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 203 , 0 , 113 , 195 ) ) , 8080 ) ,
12194 SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 203 , 0 , 113 , 196 ) ) , 6969 ) ,
@@ -135,7 +108,7 @@ mod tests {
135108 let stats_repository = Repository :: new ( ) ;
136109
137110 handle_event (
138- Event :: Udp6Connect {
111+ Event :: UdpConnect {
139112 context : ConnectionContext :: new (
140113 SocketAddr :: new ( IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 203 , 0 , 113 , 195 ) ) , 8080 ) ,
141114 SocketAddr :: new ( IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 203 , 0 , 113 , 196 ) ) , 6969 ) ,
@@ -155,7 +128,7 @@ mod tests {
155128 let stats_repository = Repository :: new ( ) ;
156129
157130 handle_event (
158- Event :: Udp6Announce {
131+ Event :: UdpAnnounce {
159132 context : ConnectionContext :: new (
160133 SocketAddr :: new ( IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 203 , 0 , 113 , 195 ) ) , 8080 ) ,
161134 SocketAddr :: new ( IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 203 , 0 , 113 , 196 ) ) , 6969 ) ,
@@ -175,7 +148,7 @@ mod tests {
175148 let stats_repository = Repository :: new ( ) ;
176149
177150 handle_event (
178- Event :: Udp6Scrape {
151+ Event :: UdpScrape {
179152 context : ConnectionContext :: new (
180153 SocketAddr :: new ( IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 203 , 0 , 113 , 195 ) ) , 8080 ) ,
181154 SocketAddr :: new ( IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 203 , 0 , 113 , 196 ) ) , 6969 ) ,
0 commit comments