14
14
15
15
use crate :: monitor:: MixnetReceiver ;
16
16
use crate :: run_info:: { TestRunUpdateReceiver , TestRunUpdateSender } ;
17
- use crate :: tested_network:: { good_topology, TestedNetwork } ;
17
+ use crate :: tested_network:: good_topology:: parse_topology_file;
18
+ use crate :: tested_network:: TestedNetwork ;
19
+ use clap:: { App , Arg , ArgMatches } ;
18
20
use crypto:: asymmetric:: { encryption, identity} ;
19
21
use futures:: channel:: mpsc;
20
22
use gateway_client:: GatewayClient ;
23
+ use log:: * ;
21
24
use monitor:: { AckSender , MixnetSender , Monitor } ;
22
25
use notifications:: Notifier ;
23
26
use nymsphinx:: addressing:: clients:: Recipient ;
24
27
use packet_sender:: PacketSender ;
25
28
use rand:: rngs:: OsRng ;
26
29
use std:: sync:: Arc ;
27
30
use std:: time;
28
- use topology:: gateway;
31
+ use topology:: { gateway, NymTopology } ;
29
32
30
33
mod chunker;
31
34
mod monitor;
@@ -38,26 +41,65 @@ mod tested_network;
38
41
pub ( crate ) type DefRng = OsRng ;
39
42
pub ( crate ) const DEFAULT_RNG : DefRng = OsRng ;
40
43
41
- // CHANGE THIS TO GET COMPLETE LIST OF WHICH NODE IS WORKING OR BROKEN IN PARTICULAR WAY
42
- // ||
43
- // \/
44
- pub const PRINT_DETAILED_REPORT : bool = false ;
45
- // /\
46
- // ||
47
- // CHANGE THIS TO GET COMPLETE LIST OF WHICH NODE IS WORKING OR BROKEN IN PARTICULAR WAY
44
+ const V4_TOPOLOGY_ARG : & str = "v4-topology-filepath" ;
45
+ const V6_TOPOLOGY_ARG : & str = "v6-topology-filepath" ;
46
+ const VALIDATOR_ARG : & str = "validator" ;
47
+ const DETAILED_REPORT_ARG : & str = "detailed-report" ;
48
+
49
+ fn parse_args < ' a > ( ) -> ArgMatches < ' a > {
50
+ App :: new ( "Nym Network Monitor" )
51
+ . author ( "Nymtech" )
52
+ . arg (
53
+ Arg :: with_name ( V4_TOPOLOGY_ARG )
54
+ . help ( "location of .json file containing IPv4 'good' network topology" )
55
+ . takes_value ( true )
56
+ . required ( true ) ,
57
+ )
58
+ . arg (
59
+ Arg :: with_name ( V6_TOPOLOGY_ARG )
60
+ . help ( "location of .json file containing IPv6 'good' network topology" )
61
+ . takes_value ( true )
62
+ . required ( true ) ,
63
+ )
64
+ . arg (
65
+ Arg :: with_name ( VALIDATOR_ARG )
66
+ . help ( "REST endpoint of the validator the monitor will grab nodes to test" )
67
+ . takes_value ( true )
68
+ . required ( true ) ,
69
+ )
70
+ . arg (
71
+ Arg :: with_name ( DETAILED_REPORT_ARG )
72
+ . help ( "specifies whether a detailed report should be printed after each run" ) ,
73
+ )
74
+ . get_matches ( )
75
+ }
48
76
49
77
#[ tokio:: main]
50
78
async fn main ( ) {
51
79
println ! ( "Network monitor starting..." ) ;
52
- check_if_up_to_date ( ) ;
80
+ dotenv:: dotenv ( ) . ok ( ) ;
81
+ let matches = parse_args ( ) ;
82
+ let v4_topology_path = matches. value_of ( V4_TOPOLOGY_ARG ) . unwrap ( ) ;
83
+ let v6_topology_path = matches. value_of ( V6_TOPOLOGY_ARG ) . unwrap ( ) ;
84
+
85
+ let v4_topology = parse_topology_file ( v4_topology_path) ;
86
+ let v6_topology = parse_topology_file ( v6_topology_path) ;
87
+
88
+ let validator_rest_uri = matches. value_of ( VALIDATOR_ARG ) . unwrap ( ) ;
89
+ let detailed_report = matches. is_present ( DETAILED_REPORT_ARG ) ;
90
+
91
+ check_if_up_to_date ( & v4_topology, & v6_topology) ;
53
92
setup_logging ( ) ;
54
93
55
- // Set up topology
56
- let validator_rest_uri = "https://qa-directory.nymtech.net" ;
57
94
println ! ( "* validator server: {}" , validator_rest_uri) ;
58
95
96
+ // TODO: THIS MUST BE UPDATED!!
97
+ // TODO: THIS MUST BE UPDATED!!
98
+ // TODO: THIS MUST BE UPDATED!!
99
+ warn ! ( "using v4 gateway for both topologies!" ) ;
100
+ let gateway = v4_topology. gateways ( ) [ 0 ] . clone ( ) ;
101
+
59
102
// TODO: this might change if it turns out we need both v4 and v6 gateway clients
60
- let gateway = tested_network:: v4_gateway ( ) ;
61
103
println ! ( "* gateway: {}" , gateway. identity_key. to_base58_string( ) ) ;
62
104
63
105
// Channels for task communication
@@ -86,10 +128,11 @@ async fn main() {
86
128
Arc :: clone ( & validator_client) ,
87
129
mixnet_receiver,
88
130
test_run_receiver,
131
+ detailed_report,
89
132
) ;
90
133
91
134
let gateway_client = new_gateway_client ( gateway, identity_keypair, ack_sender, mixnet_sender) ;
92
- let tested_network = new_tested_network ( gateway_client) . await ;
135
+ let tested_network = new_tested_network ( gateway_client, v4_topology , v6_topology ) . await ;
93
136
94
137
let packet_sender = new_packet_sender (
95
138
validator_client,
@@ -101,9 +144,14 @@ async fn main() {
101
144
network_monitor. run ( notifier, packet_sender) . await ;
102
145
}
103
146
104
- async fn new_tested_network ( gateway_client : GatewayClient ) -> TestedNetwork {
147
+ async fn new_tested_network (
148
+ gateway_client : GatewayClient ,
149
+ good_v4_topology : NymTopology ,
150
+ good_v6_topology : NymTopology ,
151
+ ) -> TestedNetwork {
105
152
// TODO: possibly change that if it turns out we need two clients (v4 and v6)
106
- let mut tested_network = TestedNetwork :: new_good ( gateway_client) ;
153
+ let mut tested_network =
154
+ TestedNetwork :: new_good ( gateway_client, good_v4_topology, good_v6_topology) ;
107
155
tested_network. start_gateway_client ( ) . await ;
108
156
tested_network
109
157
}
@@ -153,12 +201,14 @@ fn new_notifier(
153
201
validator_client : Arc < validator_client:: Client > ,
154
202
mixnet_receiver : MixnetReceiver ,
155
203
test_run_receiver : TestRunUpdateReceiver ,
204
+ with_detailed_report : bool ,
156
205
) -> Notifier {
157
206
Notifier :: new (
158
207
mixnet_receiver,
159
208
encryption_keypair,
160
209
validator_client,
161
210
test_run_receiver,
211
+ with_detailed_report,
162
212
)
163
213
}
164
214
@@ -183,11 +233,10 @@ fn setup_logging() {
183
233
. init ( ) ;
184
234
}
185
235
186
- fn check_if_up_to_date ( ) {
236
+ fn check_if_up_to_date ( v4_topology : & NymTopology , v6_topology : & NymTopology ) {
187
237
let monitor_version = env ! ( "CARGO_PKG_VERSION" ) ;
188
- let good_v4_topology = good_topology:: new_v4 ( ) ;
189
- for ( _, layer_mixes) in good_v4_topology. mixes ( ) . into_iter ( ) {
190
- for mix in layer_mixes. into_iter ( ) {
238
+ for ( _, layer_mixes) in v4_topology. mixes ( ) . iter ( ) {
239
+ for mix in layer_mixes. iter ( ) {
191
240
if !version_checker:: is_minor_version_compatible ( monitor_version, & * mix. version ) {
192
241
panic ! (
193
242
"Our good topology is not compatible with monitor! Mix runs {}, we have {}" ,
@@ -197,7 +246,7 @@ fn check_if_up_to_date() {
197
246
}
198
247
}
199
248
200
- for gateway in good_v4_topology . gateways ( ) . into_iter ( ) {
249
+ for gateway in v4_topology . gateways ( ) . iter ( ) {
201
250
if !version_checker:: is_minor_version_compatible ( monitor_version, & * gateway. version ) {
202
251
panic ! (
203
252
"Our good topology is not compatible with monitor! Gateway runs {}, we have {}" ,
@@ -206,9 +255,8 @@ fn check_if_up_to_date() {
206
255
}
207
256
}
208
257
209
- let good_v6_topology = good_topology:: new_v6 ( ) ;
210
- for ( _, layer_mixes) in good_v6_topology. mixes ( ) . into_iter ( ) {
211
- for mix in layer_mixes. into_iter ( ) {
258
+ for ( _, layer_mixes) in v6_topology. mixes ( ) . iter ( ) {
259
+ for mix in layer_mixes. iter ( ) {
212
260
if !version_checker:: is_minor_version_compatible ( monitor_version, & * mix. version ) {
213
261
panic ! (
214
262
"Our good topology is not compatible with monitor! Mix runs {}, we have {}" ,
@@ -218,7 +266,7 @@ fn check_if_up_to_date() {
218
266
}
219
267
}
220
268
221
- for gateway in good_v6_topology . gateways ( ) . into_iter ( ) {
269
+ for gateway in v6_topology . gateways ( ) . iter ( ) {
222
270
if !version_checker:: is_minor_version_compatible ( monitor_version, & * gateway. version ) {
223
271
panic ! (
224
272
"Our good topology is not compatible with monitor! Gateway runs {}, we have {}" ,
0 commit comments