Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/network monitor file topology #412

Merged
merged 4 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ scripts/run_mix.sh
scripts/start_local_tmux_network.sh
/.floo
/.flooignore
qa-v4-topology.json
qa-v6-topology.json
v4-topology.json
v6-topology.json
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions network-monitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = "2.33.0"
dotenv = "0.15.0"
futures = "0.3"
log = "0.4"
pretty_env_logger = "0.3"
rand = "0.7"
serde = "1.0"
serde_json = "1.0"
tokio = { version = "0.2", features = ["signal", "rt-threaded", "macros"] }

## internal
Expand Down
98 changes: 73 additions & 25 deletions network-monitor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@

use crate::monitor::MixnetReceiver;
use crate::run_info::{TestRunUpdateReceiver, TestRunUpdateSender};
use crate::tested_network::{good_topology, TestedNetwork};
use crate::tested_network::good_topology::parse_topology_file;
use crate::tested_network::TestedNetwork;
use clap::{App, Arg, ArgMatches};
use crypto::asymmetric::{encryption, identity};
use futures::channel::mpsc;
use gateway_client::GatewayClient;
use log::*;
use monitor::{AckSender, MixnetSender, Monitor};
use notifications::Notifier;
use nymsphinx::addressing::clients::Recipient;
use packet_sender::PacketSender;
use rand::rngs::OsRng;
use std::sync::Arc;
use std::time;
use topology::gateway;
use topology::{gateway, NymTopology};

mod chunker;
mod monitor;
Expand All @@ -38,26 +41,65 @@ mod tested_network;
pub(crate) type DefRng = OsRng;
pub(crate) const DEFAULT_RNG: DefRng = OsRng;

// CHANGE THIS TO GET COMPLETE LIST OF WHICH NODE IS WORKING OR BROKEN IN PARTICULAR WAY
// ||
// \/
pub const PRINT_DETAILED_REPORT: bool = false;
// /\
// ||
// CHANGE THIS TO GET COMPLETE LIST OF WHICH NODE IS WORKING OR BROKEN IN PARTICULAR WAY
const V4_TOPOLOGY_ARG: &str = "v4-topology-filepath";
const V6_TOPOLOGY_ARG: &str = "v6-topology-filepath";
const VALIDATOR_ARG: &str = "validator";
const DETAILED_REPORT_ARG: &str = "detailed-report";

fn parse_args<'a>() -> ArgMatches<'a> {
App::new("Nym Network Monitor")
.author("Nymtech")
.arg(
Arg::with_name(V4_TOPOLOGY_ARG)
.help("location of .json file containing IPv4 'good' network topology")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name(V6_TOPOLOGY_ARG)
.help("location of .json file containing IPv6 'good' network topology")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name(VALIDATOR_ARG)
.help("REST endpoint of the validator the monitor will grab nodes to test")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name(DETAILED_REPORT_ARG)
.help("specifies whether a detailed report should be printed after each run"),
)
.get_matches()
}

#[tokio::main]
async fn main() {
println!("Network monitor starting...");
check_if_up_to_date();
dotenv::dotenv().ok();
let matches = parse_args();
let v4_topology_path = matches.value_of(V4_TOPOLOGY_ARG).unwrap();
let v6_topology_path = matches.value_of(V6_TOPOLOGY_ARG).unwrap();

let v4_topology = parse_topology_file(v4_topology_path);
let v6_topology = parse_topology_file(v6_topology_path);

let validator_rest_uri = matches.value_of(VALIDATOR_ARG).unwrap();
let detailed_report = matches.is_present(DETAILED_REPORT_ARG);

check_if_up_to_date(&v4_topology, &v6_topology);
setup_logging();

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

// TODO: THIS MUST BE UPDATED!!
// TODO: THIS MUST BE UPDATED!!
// TODO: THIS MUST BE UPDATED!!
warn!("using v4 gateway for both topologies!");
let gateway = v4_topology.gateways()[0].clone();

// TODO: this might change if it turns out we need both v4 and v6 gateway clients
let gateway = tested_network::v4_gateway();
println!("* gateway: {}", gateway.identity_key.to_base58_string());

// Channels for task communication
Expand Down Expand Up @@ -86,10 +128,11 @@ async fn main() {
Arc::clone(&validator_client),
mixnet_receiver,
test_run_receiver,
detailed_report,
);

let gateway_client = new_gateway_client(gateway, identity_keypair, ack_sender, mixnet_sender);
let tested_network = new_tested_network(gateway_client).await;
let tested_network = new_tested_network(gateway_client, v4_topology, v6_topology).await;

let packet_sender = new_packet_sender(
validator_client,
Expand All @@ -101,9 +144,14 @@ async fn main() {
network_monitor.run(notifier, packet_sender).await;
}

async fn new_tested_network(gateway_client: GatewayClient) -> TestedNetwork {
async fn new_tested_network(
gateway_client: GatewayClient,
good_v4_topology: NymTopology,
good_v6_topology: NymTopology,
) -> TestedNetwork {
// TODO: possibly change that if it turns out we need two clients (v4 and v6)
let mut tested_network = TestedNetwork::new_good(gateway_client);
let mut tested_network =
TestedNetwork::new_good(gateway_client, good_v4_topology, good_v6_topology);
tested_network.start_gateway_client().await;
tested_network
}
Expand Down Expand Up @@ -153,12 +201,14 @@ fn new_notifier(
validator_client: Arc<validator_client::Client>,
mixnet_receiver: MixnetReceiver,
test_run_receiver: TestRunUpdateReceiver,
with_detailed_report: bool,
) -> Notifier {
Notifier::new(
mixnet_receiver,
encryption_keypair,
validator_client,
test_run_receiver,
with_detailed_report,
)
}

Expand All @@ -183,11 +233,10 @@ fn setup_logging() {
.init();
}

fn check_if_up_to_date() {
fn check_if_up_to_date(v4_topology: &NymTopology, v6_topology: &NymTopology) {
let monitor_version = env!("CARGO_PKG_VERSION");
let good_v4_topology = good_topology::new_v4();
for (_, layer_mixes) in good_v4_topology.mixes().into_iter() {
for mix in layer_mixes.into_iter() {
for (_, layer_mixes) in v4_topology.mixes().iter() {
for mix in layer_mixes.iter() {
if !version_checker::is_minor_version_compatible(monitor_version, &*mix.version) {
panic!(
"Our good topology is not compatible with monitor! Mix runs {}, we have {}",
Expand All @@ -197,7 +246,7 @@ fn check_if_up_to_date() {
}
}

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

let good_v6_topology = good_topology::new_v6();
for (_, layer_mixes) in good_v6_topology.mixes().into_iter() {
for mix in layer_mixes.into_iter() {
for (_, layer_mixes) in v6_topology.mixes().iter() {
for mix in layer_mixes.iter() {
if !version_checker::is_minor_version_compatible(monitor_version, &*mix.version) {
panic!(
"Our good topology is not compatible with monitor! Mix runs {}, we have {}",
Expand All @@ -218,7 +266,7 @@ fn check_if_up_to_date() {
}
}

for gateway in good_v6_topology.gateways().into_iter() {
for gateway in v6_topology.gateways().iter() {
if !version_checker::is_minor_version_compatible(monitor_version, &*gateway.version) {
panic!(
"Our good topology is not compatible with monitor! Gateway runs {}, we have {}",
Expand Down
4 changes: 2 additions & 2 deletions network-monitor/src/notifications/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::monitor::NOTIFIER_DELIVERY_TIMEOUT;
use crate::notifications::test_run::TestRun;
use crate::notifications::test_timeout::TestTimeout;
use crate::run_info::{RunInfo, TestRunUpdate, TestRunUpdateReceiver};
use crate::PRINT_DETAILED_REPORT;
use crypto::asymmetric::encryption::KeyPair;
use futures::StreamExt;
use log::*;
Expand Down Expand Up @@ -53,10 +52,11 @@ impl Notifier {
client_encryption_keypair: KeyPair,
validator_client: Arc<validator_client::Client>,
test_run_receiver: TestRunUpdateReceiver,
with_detailed_report: bool,
) -> Notifier {
let message_receiver = MessageReceiver::new();
let mut current_test_run = TestRun::new(0).with_report();
if PRINT_DETAILED_REPORT {
if with_detailed_report {
current_test_run = current_test_run.with_detailed_report();
}
Notifier {
Expand Down
Loading