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/error on noninit #404

Merged
merged 2 commits into from
Oct 30, 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
39 changes: 36 additions & 3 deletions clients/native/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::client::NymClient;
use crate::commands::override_config;
use clap::{App, Arg, ArgMatches};
use config::NymConfig;
use log::*;
use version_checker::is_minor_version_compatible;

pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
App::new("run")
Expand Down Expand Up @@ -66,14 +68,45 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
)
}

// 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_base().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();

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;
}

NymClient::new(config).run_forever();
}
39 changes: 36 additions & 3 deletions clients/socks5/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::client::NymClient;
use crate::commands::override_config;
use clap::{App, Arg, ArgMatches};
use config::NymConfig;
use log::*;
use version_checker::is_minor_version_compatible;

pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
App::new("run")
Expand Down Expand Up @@ -67,14 +69,45 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
)
}

// 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_base().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();

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;
}

NymClient::new(config).run_forever();
}
39 changes: 36 additions & 3 deletions gateway/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::node::Gateway;
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>() -> clap::App<'a, 'b> {
App::new("run")
Expand Down Expand Up @@ -152,17 +154,48 @@ fn load_identity_keys(pathfinder: &GatewayPathfinder) -> identity::KeyPair {
identity_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 gateway {}...", 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 = GatewayPathfinder::new_from_config(&config);
let sphinx_keypair = load_sphinx_keys(&pathfinder);
let identity = load_identity_keys(&pathfinder);
Expand Down
24 changes: 0 additions & 24 deletions gateway/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use log::*;
use mixnet_client::forwarder::{MixForwardingSender, PacketForwarder};
use std::sync::Arc;
use tokio::runtime::Runtime;
use version_checker::is_minor_version_compatible;

pub(crate) mod client_handling;
pub(crate) mod mixnet_handling;
Expand Down Expand Up @@ -165,34 +164,11 @@ impl Gateway {
.map(|node| node.identity())
}

// 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
}
}

// Rather than starting all futures with explicit `&Handle` argument, let's see how it works
// out if we make it implicit using `tokio::spawn` inside Runtime context.
// Basically more or less equivalent of using #[tokio::main] attribute.
pub fn run(&mut self) {
info!("Starting nym gateway!");
if !self.version_check() {
error!("failed the local version check");
return;
}

let mut runtime = Runtime::new().unwrap();

Expand Down
39 changes: 36 additions & 3 deletions mixnode/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 0 additions & 24 deletions mixnode/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,31 +126,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();

Expand Down