Tidy nym-mixnode module visibility (#1075)
* mixnode: make command modules private * mixnode: make some node modules private * mixnode: make config structs private * mixnode: restore accidentally moved function
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::commands::*;
|
||||
use crate::config::Config;
|
||||
use crate::node::node_description::NodeDescription;
|
||||
use clap::Args;
|
||||
use colored::Colorize;
|
||||
use config::NymConfig;
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
// Copyright 2020 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::commands::*;
|
||||
use crate::config::persistence::pathfinder::MixNodePathfinder;
|
||||
use crate::config::Config;
|
||||
use crate::node::MixNode;
|
||||
use crate::{commands::override_config, config::persistence::pathfinder::MixNodePathfinder};
|
||||
use clap::Args;
|
||||
use config::NymConfig;
|
||||
use crypto::asymmetric::{encryption, identity};
|
||||
|
||||
use super::OverrideConfig;
|
||||
|
||||
#[derive(Args, Clone)]
|
||||
pub(crate) struct Init {
|
||||
/// Initialise the mixnode
|
||||
|
||||
@@ -3,18 +3,18 @@
|
||||
|
||||
use std::process;
|
||||
|
||||
use crate::config::Config;
|
||||
use clap::{Args, Subcommand};
|
||||
use crate::{config::Config, Cli};
|
||||
use clap::Subcommand;
|
||||
use colored::Colorize;
|
||||
use crypto::bech32_address_validation;
|
||||
use url::Url;
|
||||
|
||||
pub(crate) mod describe;
|
||||
pub(crate) mod init;
|
||||
pub(crate) mod node_details;
|
||||
pub(crate) mod run;
|
||||
pub(crate) mod sign;
|
||||
pub(crate) mod upgrade;
|
||||
mod describe;
|
||||
mod init;
|
||||
mod node_details;
|
||||
mod run;
|
||||
mod sign;
|
||||
mod upgrade;
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub(crate) enum Commands {
|
||||
@@ -49,6 +49,17 @@ struct OverrideConfig {
|
||||
wallet_address: Option<String>,
|
||||
}
|
||||
|
||||
pub(crate) async fn execute(args: Cli) {
|
||||
match &args.command {
|
||||
Commands::Describe(m) => describe::execute(m),
|
||||
Commands::Init(m) => init::execute(m).await,
|
||||
Commands::Run(m) => run::execute(m).await,
|
||||
Commands::Sign(m) => sign::execute(m),
|
||||
Commands::Upgrade(m) => upgrade::execute(m),
|
||||
Commands::NodeDetails(m) => node_details::execute(m),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_validators(raw: &str) -> Vec<Url> {
|
||||
raw.split(',')
|
||||
.map(|raw_validator| {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::commands::*;
|
||||
use crate::config::Config;
|
||||
use crate::node::MixNode;
|
||||
use clap::Args;
|
||||
use config::NymConfig;
|
||||
|
||||
#[derive(Args)]
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// Copyright 2020 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::commands::*;
|
||||
use crate::commands::{override_config, version_check};
|
||||
use crate::config::Config;
|
||||
use crate::node::MixNode;
|
||||
use clap::Args;
|
||||
use config::NymConfig;
|
||||
|
||||
use super::OverrideConfig;
|
||||
|
||||
#[derive(Args, Clone)]
|
||||
pub(crate) struct Run {
|
||||
/// Id of the nym-mixnode we want to run
|
||||
|
||||
@@ -3,14 +3,17 @@
|
||||
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use crate::commands::*;
|
||||
use crate::commands::validate_bech32_address_or_exit;
|
||||
use crate::config::{persistence::pathfinder::MixNodePathfinder, Config};
|
||||
use crate::node::MixNode;
|
||||
use anyhow::{anyhow, Result};
|
||||
use clap::ArgGroup;
|
||||
use clap::{ArgGroup, Args};
|
||||
use config::NymConfig;
|
||||
use crypto::asymmetric::identity;
|
||||
use log::error;
|
||||
|
||||
use super::version_check;
|
||||
|
||||
#[derive(Args, Clone)]
|
||||
#[clap(group(ArgGroup::new("sign").required(true).args(&["address", "text"])))]
|
||||
pub(crate) struct Sign {
|
||||
@@ -49,15 +52,6 @@ impl TryFrom<Sign> for SignedTarget {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_identity_keys(pathfinder: &MixNodePathfinder) -> identity::KeyPair {
|
||||
let identity_keypair: identity::KeyPair = pemstore::load_keypair(&pemstore::KeyPairPath::new(
|
||||
pathfinder.private_identity_key().to_owned(),
|
||||
pathfinder.public_identity_key().to_owned(),
|
||||
))
|
||||
.expect("Failed to read stored identity key files");
|
||||
identity_keypair
|
||||
}
|
||||
|
||||
fn print_signed_address(private_key: &identity::PrivateKey, raw_address: &str) {
|
||||
let trimmed = raw_address.trim();
|
||||
validate_bech32_address_or_exit(trimmed);
|
||||
@@ -109,7 +103,7 @@ pub(crate) fn execute(args: &Sign) {
|
||||
}
|
||||
};
|
||||
let pathfinder = MixNodePathfinder::new_from_config(&config);
|
||||
let identity_keypair = load_identity_keys(&pathfinder);
|
||||
let identity_keypair = MixNode::load_identity_keys(&pathfinder);
|
||||
|
||||
match signed_target {
|
||||
SignedTarget::Text(text) => print_signed_text(identity_keypair.private_key(), &text),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright 2020 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::commands::*;
|
||||
use crate::config::{missing_string_value, Config};
|
||||
use clap::Args;
|
||||
use config::defaults::default_api_endpoints;
|
||||
use config::NymConfig;
|
||||
use std::fmt::Display;
|
||||
|
||||
@@ -312,7 +312,7 @@ impl Config {
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Serialize)]
|
||||
pub struct MixNode {
|
||||
struct MixNode {
|
||||
/// Version of the mixnode for which this configuration was created.
|
||||
#[serde(default = "missing_string_value")]
|
||||
version: String,
|
||||
@@ -410,11 +410,11 @@ impl Default for MixNode {
|
||||
|
||||
#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Logging {}
|
||||
struct Logging {}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Verloc {
|
||||
struct Verloc {
|
||||
/// Specifies number of echo packets sent to each node during a measurement run.
|
||||
packets_per_node: usize,
|
||||
|
||||
@@ -454,7 +454,7 @@ impl Default for Verloc {
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct Debug {
|
||||
struct Debug {
|
||||
/// Delay between each subsequent node statistics being logged to the console
|
||||
#[serde(with = "humantime_serde")]
|
||||
node_stats_logging_delay: Duration,
|
||||
|
||||
+1
-12
@@ -34,18 +34,7 @@ async fn main() {
|
||||
println!("{}", banner());
|
||||
|
||||
let args = Cli::parse();
|
||||
execute(args).await;
|
||||
}
|
||||
|
||||
async fn execute(args: Cli) {
|
||||
match &args.command {
|
||||
commands::Commands::Describe(m) => commands::describe::execute(m),
|
||||
commands::Commands::Init(m) => commands::init::execute(m).await,
|
||||
commands::Commands::Run(m) => commands::run::execute(m).await,
|
||||
commands::Commands::Sign(m) => commands::sign::execute(m),
|
||||
commands::Commands::Upgrade(m) => commands::upgrade::execute(m),
|
||||
commands::Commands::NodeDetails(m) => commands::node_details::execute(m),
|
||||
}
|
||||
commands::execute(args).await;
|
||||
}
|
||||
|
||||
fn banner() -> String {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2020 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::commands::sign::load_identity_keys;
|
||||
use crate::commands::validate_bech32_address_or_exit;
|
||||
use crate::config::persistence::pathfinder::MixNodePathfinder;
|
||||
use crate::config::Config;
|
||||
@@ -28,11 +27,11 @@ use std::process;
|
||||
use std::sync::Arc;
|
||||
use version_checker::parse_version;
|
||||
|
||||
pub(crate) mod http;
|
||||
mod http;
|
||||
mod listener;
|
||||
pub(crate) mod node_description;
|
||||
pub(crate) mod node_statistics;
|
||||
pub(crate) mod packet_delayforwarder;
|
||||
mod node_statistics;
|
||||
mod packet_delayforwarder;
|
||||
|
||||
// the MixNode will live for whole duration of this program
|
||||
pub struct MixNode {
|
||||
@@ -60,7 +59,7 @@ impl MixNode {
|
||||
}
|
||||
|
||||
/// Loads identity keys stored on disk
|
||||
fn load_identity_keys(pathfinder: &MixNodePathfinder) -> identity::KeyPair {
|
||||
pub(crate) fn load_identity_keys(pathfinder: &MixNodePathfinder) -> identity::KeyPair {
|
||||
let identity_keypair: identity::KeyPair =
|
||||
pemstore::load_keypair(&pemstore::KeyPairPath::new(
|
||||
pathfinder.private_identity_key().to_owned(),
|
||||
@@ -85,7 +84,7 @@ impl MixNode {
|
||||
/// Exits if the address isn't valid (which should protect against manual edits).
|
||||
fn generate_owner_signature(&self) -> String {
|
||||
let pathfinder = MixNodePathfinder::new_from_config(&self.config);
|
||||
let identity_keypair = load_identity_keys(&pathfinder);
|
||||
let identity_keypair = Self::load_identity_keys(&pathfinder);
|
||||
let address = self.config.get_wallet_address();
|
||||
validate_bech32_address_or_exit(address);
|
||||
let verification_code = identity_keypair.private_key().sign_text(address);
|
||||
|
||||
Reference in New Issue
Block a user