Feature/topology conversion (#536)

* Removed reputation field from existing topology

* ibid for registration time

* Basic bond to topology conversion

* Made existing tests compilable

* Added owner and stake fields to mix and gateway topology entries

* Moved node conversion to topology crate

* Added mixnet contract field to clients configs

* topology refresher trying to use new validator

* Removed clients depepdency on the old validator client

* Removed mixnode dependency on the old validator client

* Removed gateway dependency on the old validator client

* Removed location field fron mixnode and gateway configs

* Removed incentives address from mixnodes and gateways

* Cargo.lock changes

* Ignoring clippy warnings originating from codegen from JsonSchema

* no longer formating string with a literal
This commit is contained in:
Jędrzej Stuczyński
2021-03-24 10:52:27 +00:00
committed by GitHub
parent ce7dcbc163
commit 9e0bb80163
51 changed files with 792 additions and 814 deletions
+13 -31
View File
@@ -15,7 +15,6 @@ use tokio::runtime::Runtime;
mod listener;
mod metrics;
pub(crate) mod packet_delayforwarder;
mod presence;
// the MixNode will live for whole duration of this program
pub struct MixNode {
@@ -87,23 +86,26 @@ impl MixNode {
packet_sender
}
// TODO: ask DH whether this function still makes sense in ^0.10
async fn check_if_same_ip_node_exists(&mut self) -> Option<String> {
let validator_client_config =
validator_client::Config::new(self.config.get_validator_rest_endpoint());
let validator_client = validator_client::Client::new(validator_client_config);
let topology = match validator_client.get_topology().await {
Ok(topology) => topology,
let validator_client_config = validator_client_rest::Config::new(
self.config.get_validator_rest_endpoint(),
self.config.get_validator_mixnet_contract_address(),
);
let validator_client = validator_client_rest::Client::new(validator_client_config);
let existing_nodes = match validator_client.get_mix_nodes().await {
Ok(nodes) => nodes,
Err(err) => {
error!("failed to grab initial network topology - {}\n Please try to startup again in few minutes", err);
error!("failed to grab initial network mixnodes - {}\n Please try to startup again in few minutes", err);
process::exit(1);
}
};
let existing_mixes_presence = topology.mix_nodes;
existing_mixes_presence
existing_nodes
.iter()
.find(|node| node.mix_host() == self.config.get_announce_address())
.map(|node| node.identity())
.find(|node| node.mix_node.host == self.config.get_announce_address())
.map(|node| node.mix_node.identity_key.clone())
}
async fn wait_for_interrupt(&self) {
@@ -116,17 +118,6 @@ impl MixNode {
println!(
"Received SIGINT - the mixnode will terminate now (threads are not yet nicely stopped, if you see stack traces that's alright)."
);
info!("Trying to unregister with the validator...");
if let Err(err) = presence::unregister_with_validator(
self.config.get_validator_rest_endpoint(),
self.identity_keypair.public_key().to_base58_string(),
)
.await
{
error!("failed to unregister with validator... - {}", err)
} else {
info!("unregistration was successful!")
}
}
pub fn run(&mut self) {
@@ -147,15 +138,6 @@ impl MixNode {
}
}
if let Err(err) = presence::register_with_validator(
&self.config,
self.identity_keypair.public_key().to_base58_string(),
self.sphinx_keypair.public_key().to_base58_string(),
).await {
error!("failed to register with the validator - {}.\nPlease try again in few minutes.", err);
return;
}
let metrics_reporter = self.start_metrics_reporter();
let delay_forwarding_channel = self.start_packet_delay_forwarder(metrics_reporter.clone());
self.start_socket_listener(metrics_reporter, delay_forwarding_channel);
-39
View File
@@ -1,39 +0,0 @@
// Copyright 2020 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::config::Config;
use validator_client::models::mixnode::MixRegistrationInfo;
use validator_client::ValidatorClientError;
// there's no point in keeping the validator client persistently as it might be literally hours or days
// before it's used again
pub(crate) async fn register_with_validator(
mixnode_config: &Config,
identity_key: String,
sphinx_key: String,
) -> Result<(), ValidatorClientError> {
let config = validator_client::Config::new(mixnode_config.get_validator_rest_endpoint());
let validator_client = validator_client::Client::new(config);
let registration_info = MixRegistrationInfo::new(
mixnode_config.get_announce_address(),
identity_key,
sphinx_key,
mixnode_config.get_version().to_string(),
mixnode_config.get_location(),
mixnode_config.get_layer(),
mixnode_config.get_incentives_address(),
);
validator_client.register_mix(registration_info).await
}
pub(crate) async fn unregister_with_validator(
validator_endpoint: String,
identity_key: String,
) -> Result<(), ValidatorClientError> {
let config = validator_client::Config::new(validator_endpoint);
let validator_client = validator_client::Client::new(config);
validator_client.unregister_node(&identity_key).await
}