Skip to content

Commit 566eb87

Browse files
authored
Feature/network monitor file topology (#412)
* Network monitor loading 'good' topology from files instead * Update .gitignore * Passing address of validator as an argument * Made detailed report const flag into an argument
1 parent e4c8a6b commit 566eb87

File tree

7 files changed

+106
-273
lines changed

7 files changed

+106
-273
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ scripts/run_mix.sh
1515
scripts/start_local_tmux_network.sh
1616
/.floo
1717
/.flooignore
18+
qa-v4-topology.json
19+
qa-v6-topology.json
20+
v4-topology.json
21+
v6-topology.json

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

network-monitor/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10+
clap = "2.33.0"
11+
dotenv = "0.15.0"
1012
futures = "0.3"
1113
log = "0.4"
1214
pretty_env_logger = "0.3"
1315
rand = "0.7"
1416
serde = "1.0"
17+
serde_json = "1.0"
1518
tokio = { version = "0.2", features = ["signal", "rt-threaded", "macros"] }
1619

1720
## internal

network-monitor/src/main.rs

+73-25
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414

1515
use crate::monitor::MixnetReceiver;
1616
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};
1820
use crypto::asymmetric::{encryption, identity};
1921
use futures::channel::mpsc;
2022
use gateway_client::GatewayClient;
23+
use log::*;
2124
use monitor::{AckSender, MixnetSender, Monitor};
2225
use notifications::Notifier;
2326
use nymsphinx::addressing::clients::Recipient;
2427
use packet_sender::PacketSender;
2528
use rand::rngs::OsRng;
2629
use std::sync::Arc;
2730
use std::time;
28-
use topology::gateway;
31+
use topology::{gateway, NymTopology};
2932

3033
mod chunker;
3134
mod monitor;
@@ -38,26 +41,65 @@ mod tested_network;
3841
pub(crate) type DefRng = OsRng;
3942
pub(crate) const DEFAULT_RNG: DefRng = OsRng;
4043

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+
}
4876

4977
#[tokio::main]
5078
async fn main() {
5179
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);
5392
setup_logging();
5493

55-
// Set up topology
56-
let validator_rest_uri = "https://qa-directory.nymtech.net";
5794
println!("* validator server: {}", validator_rest_uri);
5895

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+
59102
// TODO: this might change if it turns out we need both v4 and v6 gateway clients
60-
let gateway = tested_network::v4_gateway();
61103
println!("* gateway: {}", gateway.identity_key.to_base58_string());
62104

63105
// Channels for task communication
@@ -86,10 +128,11 @@ async fn main() {
86128
Arc::clone(&validator_client),
87129
mixnet_receiver,
88130
test_run_receiver,
131+
detailed_report,
89132
);
90133

91134
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;
93136

94137
let packet_sender = new_packet_sender(
95138
validator_client,
@@ -101,9 +144,14 @@ async fn main() {
101144
network_monitor.run(notifier, packet_sender).await;
102145
}
103146

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 {
105152
// 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);
107155
tested_network.start_gateway_client().await;
108156
tested_network
109157
}
@@ -153,12 +201,14 @@ fn new_notifier(
153201
validator_client: Arc<validator_client::Client>,
154202
mixnet_receiver: MixnetReceiver,
155203
test_run_receiver: TestRunUpdateReceiver,
204+
with_detailed_report: bool,
156205
) -> Notifier {
157206
Notifier::new(
158207
mixnet_receiver,
159208
encryption_keypair,
160209
validator_client,
161210
test_run_receiver,
211+
with_detailed_report,
162212
)
163213
}
164214

@@ -183,11 +233,10 @@ fn setup_logging() {
183233
.init();
184234
}
185235

186-
fn check_if_up_to_date() {
236+
fn check_if_up_to_date(v4_topology: &NymTopology, v6_topology: &NymTopology) {
187237
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() {
191240
if !version_checker::is_minor_version_compatible(monitor_version, &*mix.version) {
192241
panic!(
193242
"Our good topology is not compatible with monitor! Mix runs {}, we have {}",
@@ -197,7 +246,7 @@ fn check_if_up_to_date() {
197246
}
198247
}
199248

200-
for gateway in good_v4_topology.gateways().into_iter() {
249+
for gateway in v4_topology.gateways().iter() {
201250
if !version_checker::is_minor_version_compatible(monitor_version, &*gateway.version) {
202251
panic!(
203252
"Our good topology is not compatible with monitor! Gateway runs {}, we have {}",
@@ -206,9 +255,8 @@ fn check_if_up_to_date() {
206255
}
207256
}
208257

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() {
212260
if !version_checker::is_minor_version_compatible(monitor_version, &*mix.version) {
213261
panic!(
214262
"Our good topology is not compatible with monitor! Mix runs {}, we have {}",
@@ -218,7 +266,7 @@ fn check_if_up_to_date() {
218266
}
219267
}
220268

221-
for gateway in good_v6_topology.gateways().into_iter() {
269+
for gateway in v6_topology.gateways().iter() {
222270
if !version_checker::is_minor_version_compatible(monitor_version, &*gateway.version) {
223271
panic!(
224272
"Our good topology is not compatible with monitor! Gateway runs {}, we have {}",

network-monitor/src/notifications/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use crate::monitor::NOTIFIER_DELIVERY_TIMEOUT;
1717
use crate::notifications::test_run::TestRun;
1818
use crate::notifications::test_timeout::TestTimeout;
1919
use crate::run_info::{RunInfo, TestRunUpdate, TestRunUpdateReceiver};
20-
use crate::PRINT_DETAILED_REPORT;
2120
use crypto::asymmetric::encryption::KeyPair;
2221
use futures::StreamExt;
2322
use log::*;
@@ -53,10 +52,11 @@ impl Notifier {
5352
client_encryption_keypair: KeyPair,
5453
validator_client: Arc<validator_client::Client>,
5554
test_run_receiver: TestRunUpdateReceiver,
55+
with_detailed_report: bool,
5656
) -> Notifier {
5757
let message_receiver = MessageReceiver::new();
5858
let mut current_test_run = TestRun::new(0).with_report();
59-
if PRINT_DETAILED_REPORT {
59+
if with_detailed_report {
6060
current_test_run = current_test_run.with_detailed_report();
6161
}
6262
Notifier {

0 commit comments

Comments
 (0)