From 4a908e7e14749775107e5530cab71efcbcf52cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 31 Mar 2021 16:01:06 +0100 Subject: [PATCH] Feature/bonding info on init (#555) * Mixnode bonding info on init * Gateway bonding info on init --- gateway/src/commands/init.rs | 51 ++++++++++++++++++++++++++++++++++++ mixnode/src/commands/init.rs | 44 +++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/gateway/src/commands/init.rs b/gateway/src/commands/init.rs index 6997a7d8b6..eb3de0b6df 100644 --- a/gateway/src/commands/init.rs +++ b/gateway/src/commands/init.rs @@ -94,6 +94,56 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { ) } +fn show_bonding_info(config: &Config) { + fn load_sphinx_keys(pathfinder: &GatewayPathfinder) -> encryption::KeyPair { + let sphinx_keypair: encryption::KeyPair = + pemstore::load_keypair(&pemstore::KeyPairPath::new( + pathfinder.private_encryption_key().to_owned(), + pathfinder.public_encryption_key().to_owned(), + )) + .expect("Failed to read stored sphinx key files"); + println!( + "Public sphinx key: {}\n", + sphinx_keypair.public_key().to_base58_string() + ); + sphinx_keypair + } + + fn load_identity_keys(pathfinder: &GatewayPathfinder) -> 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"); + println!( + "Public identity key: {}\n", + identity_keypair.public_key().to_base58_string() + ); + identity_keypair + } + + let pathfinder = GatewayPathfinder::new_from_config(&config); + let identity_keypair = load_identity_keys(&pathfinder); + let sphinx_keypair = load_sphinx_keys(&pathfinder); + + println!( + "\nTo bond your gateway you will [most likely] need to provide the following: + Identity key: {} + Sphinx key: {} + Mix Host: {} + Clients Host: {} + Location: [physical location of your node's server] + Version: {} + ", + identity_keypair.public_key().to_base58_string(), + sphinx_keypair.public_key().to_base58_string(), + config.get_mix_announce_address(), + config.get_clients_announce_address(), + config.get_version(), + ); +} + pub fn execute(matches: &ArgMatches) { let id = matches.value_of("id").unwrap(); println!("Initialising gateway {}...", id); @@ -144,4 +194,5 @@ pub fn execute(matches: &ArgMatches) { println!("Saved configuration file to {:?}", config_save_location); println!("Gateway configuration completed.\n\n\n"); + show_bonding_info(&config); } diff --git a/mixnode/src/commands/init.rs b/mixnode/src/commands/init.rs index aee518d3b5..fc39f0ca49 100644 --- a/mixnode/src/commands/init.rs +++ b/mixnode/src/commands/init.rs @@ -128,6 +128,48 @@ async fn choose_layer( *layer_with_fewest } +fn show_bonding_info(config: &Config) { + 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 load_sphinx_keys(pathfinder: &MixNodePathfinder) -> encryption::KeyPair { + let sphinx_keypair: encryption::KeyPair = + pemstore::load_keypair(&pemstore::KeyPairPath::new( + pathfinder.private_encryption_key().to_owned(), + pathfinder.public_encryption_key().to_owned(), + )) + .expect("Failed to read stored sphinx key files"); + sphinx_keypair + } + + let pathfinder = MixNodePathfinder::new_from_config(&config); + let identity_keypair = load_identity_keys(&pathfinder); + let sphinx_keypair = load_sphinx_keys(&pathfinder); + + println!( + "\nTo bond your mixnode you will need to provide the following: + Identity key: {} + Sphinx key: {} + Host: {} + Layer: {} + Location: [physical location of your node's server] + Version: {} + ", + identity_keypair.public_key().to_base58_string(), + sphinx_keypair.public_key().to_base58_string(), + config.get_announce_address(), + config.get_layer(), + config.get_version(), + ); +} + pub fn execute(matches: &ArgMatches) { // TODO: this should probably be made implicit by slapping `#[tokio::main]` on our main method // and then removing runtime from mixnode itself in `run` @@ -185,5 +227,7 @@ pub fn execute(matches: &ArgMatches) { .expect("Failed to save the config file"); println!("Saved configuration file to {:?}", config_save_location); println!("Mixnode configuration completed.\n\n\n"); + + show_bonding_info(&config) }) }