Feature/error on noninit (#404)

* More graceful shutdown in case of uninitialised client/node

* Performing version check on binary `run`
This commit is contained in:
Jędrzej Stuczyński
2020-10-30 15:15:18 +00:00
committed by GitHub
parent 72e9fb1bc3
commit 7c65101609
6 changed files with 144 additions and 60 deletions
+36 -3
View File
@@ -18,6 +18,8 @@ use crate::node::MixNode;
use clap::{App, Arg, ArgMatches};
use config::NymConfig;
use crypto::asymmetric::{encryption, identity};
use log::*;
use version_checker::is_minor_version_compatible;
pub fn command_args<'a, 'b>() -> App<'a, 'b> {
App::new("run")
@@ -127,17 +129,48 @@ fn load_sphinx_keys(pathfinder: &MixNodePathfinder) -> encryption::KeyPair {
sphinx_keypair
}
// this only checks compatibility between config the binary. It does not take into consideration
// network version. It might do so in the future.
fn version_check(cfg: &Config) -> bool {
let binary_version = env!("CARGO_PKG_VERSION");
let config_version = cfg.get_version();
if binary_version != config_version {
warn!("The mixnode binary has different version than what is specified in config file! {} and {}", binary_version, config_version);
if is_minor_version_compatible(binary_version, config_version) {
info!("but they are still semver compatible. However, consider running the `upgrade` command");
true
} else {
error!("and they are semver incompatible! - please run the `upgrade` command before attempting `run` again");
false
}
} else {
true
}
}
pub fn execute(matches: &ArgMatches) {
let id = matches.value_of("id").unwrap();
println!("Starting mixnode {}...", id);
let mut config =
Config::load_from_file(matches.value_of("config").map(|path| path.into()), Some(id))
.expect("Failed to load config file");
let mut config = match Config::load_from_file(
matches.value_of("config").map(|path| path.into()),
Some(id),
) {
Ok(cfg) => cfg,
Err(err) => {
error!("Failed to load config for {}. Are you sure you have run `init` before? (Error was: {})", id, err);
return;
}
};
config = override_config(config, matches);
if !version_check(&config) {
error!("failed the local version check");
return;
}
let pathfinder = MixNodePathfinder::new_from_config(&config);
let identity_keypair = load_identity_keys(&pathfinder);
let sphinx_keypair = load_sphinx_keys(&pathfinder);
-24
View File
@@ -21,7 +21,6 @@ use log::*;
use mixnet_client::forwarder::{MixForwardingSender, PacketForwarder};
use std::sync::Arc;
use tokio::runtime::Runtime;
use version_checker::is_minor_version_compatible;
mod listener;
mod metrics;
@@ -126,31 +125,8 @@ impl MixNode {
}
}
// this only checks compatibility between config the binary. It does not take into consideration
// network version. It might do so in the future.
fn version_check(&self) -> bool {
let binary_version = env!("CARGO_PKG_VERSION");
let config_version = self.config.get_version();
if binary_version != config_version {
warn!("The mixnode binary has different version than what is specified in config file! {} and {}", binary_version, config_version);
if is_minor_version_compatible(binary_version, config_version) {
info!("but they are still semver compatible. However, consider running the `upgrade` command");
true
} else {
error!("and they are semver incompatible! - please run the `upgrade` command before attempting `run` again");
false
}
} else {
true
}
}
pub fn run(&mut self) {
info!("Starting nym mixnode");
if !self.version_check() {
error!("failed the local version check");
return;
}
let mut runtime = Runtime::new().unwrap();