diff --git a/Cargo.lock b/Cargo.lock index 49fcae7f95..9cc19b1dbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1339,7 +1339,7 @@ dependencies = [ [[package]] name = "nym-client" -version = "0.3.1" +version = "0.3.2" dependencies = [ "addressing", "base64 0.11.0", @@ -1372,7 +1372,7 @@ dependencies = [ [[package]] name = "nym-mixnode" -version = "0.3.1" +version = "0.3.2" dependencies = [ "addressing", "base64 0.11.0", @@ -1388,7 +1388,7 @@ dependencies = [ [[package]] name = "nym-sfw-provider" -version = "0.3.1" +version = "0.3.2" dependencies = [ "base64 0.11.0", "built", diff --git a/common/clients/directory-client/src/presence.rs b/common/clients/directory-client/src/presence.rs index 19a4e5da01..f20ed9f914 100644 --- a/common/clients/directory-client/src/presence.rs +++ b/common/clients/directory-client/src/presence.rs @@ -1,6 +1,9 @@ use crate::requests::presence_topology_get::PresenceTopologyGetRequester; use crate::{Client, Config, DirectoryClient}; use serde::{Deserialize, Serialize}; +use std::convert::TryInto; +use std::io; +use std::net::ToSocketAddrs; use topology::{CocoNode, MixNode, MixProviderNode, NymTopology}; #[derive(Clone, Debug, Deserialize, Serialize)] @@ -44,15 +47,25 @@ pub struct MixNodePresence { pub version: String, } -impl Into for MixNodePresence { - fn into(self) -> topology::MixNode { - topology::MixNode { - host: self.host.parse().unwrap(), +impl TryInto for MixNodePresence { + type Error = io::Error; + + fn try_into(self) -> Result { + let resolved_hostname = self.host.to_socket_addrs()?.next(); + if resolved_hostname.is_none() { + return Err(io::Error::new( + io::ErrorKind::Other, + "no valid socket address", + )); + } + + Ok(topology::MixNode { + host: resolved_hostname.unwrap(), pub_key: self.pub_key, layer: self.layer, last_seen: self.last_seen, version: self.version, - } + }) } } @@ -175,7 +188,10 @@ impl NymTopology for Topology { } fn get_mix_nodes(&self) -> Vec { - self.mix_nodes.iter().map(|x| x.clone().into()).collect() + self.mix_nodes + .iter() + .filter_map(|x| x.clone().try_into().ok()) + .collect() } fn get_mix_provider_nodes(&self) -> Vec { @@ -189,3 +205,40 @@ impl NymTopology for Topology { self.coco_nodes.iter().map(|x| x.clone().into()).collect() } } + +#[cfg(test)] +mod converting_mixnode_presence_into_topology_mixnode { + use super::*; + + #[test] + fn it_returns_error_on_unresolvable_hostname() { + let unresolvable_hostname = "foomp.foomp.foomp:1234"; + + let mix_presence = MixNodePresence { + host: unresolvable_hostname.to_string(), + pub_key: "".to_string(), + layer: 0, + last_seen: 0, + version: "".to_string(), + }; + + let result: Result = mix_presence.try_into(); + assert!(result.is_err()) + } + + #[test] + fn it_returns_resolved_ip_on_resolvable_hostname() { + let resolvable_hostname = "nymtech.net:1234"; + + let mix_presence = MixNodePresence { + host: resolvable_hostname.to_string(), + pub_key: "".to_string(), + layer: 0, + last_seen: 0, + version: "".to_string(), + }; + + let result: Result = mix_presence.try_into(); + assert!(result.is_ok()) + } +} diff --git a/common/healthcheck/src/path_check.rs b/common/healthcheck/src/path_check.rs index c3045b0e98..62b94a86b1 100644 --- a/common/healthcheck/src/path_check.rs +++ b/common/healthcheck/src/path_check.rs @@ -1,6 +1,6 @@ use crypto::identity::{DummyMixIdentityKeyPair, MixnetIdentityKeyPair, MixnetIdentityPublicKey}; use itertools::Itertools; -use log::{debug, error, warn}; +use log::{debug, error, trace, warn}; use mix_client::MixClient; use provider_client::ProviderClient; use sphinx::header::delays::Delay; @@ -131,6 +131,7 @@ impl PathChecker { Ok(messages) => { let mut should_stop = false; for msg in messages.into_iter() { + trace!("received provider response: {:?}", msg); if msg == sfw_provider_requests::DUMMY_MESSAGE_CONTENT { // finish iterating the loop as the messages might not be ordered should_stop = true; @@ -175,9 +176,13 @@ impl PathChecker { if provider_client.is_none() { debug!("we can ignore this path as provider itself is inaccessible"); - self.paths_status + if self + .paths_status .insert(path_identifier, PathStatus::Unhealthy) - .unwrap(); + .is_some() + { + panic!("Overwriting path checks!") + } return; } @@ -193,9 +198,13 @@ impl PathChecker { if first_node_client.is_none() { debug!("we can ignore this path as layer one mix is inaccessible"); - self.paths_status + if self + .paths_status .insert(path_identifier, PathStatus::Unhealthy) - .unwrap(); + .is_some() + { + panic!("Overwriting path checks!") + } return; } diff --git a/mixnode/CHANGELOG.md b/mixnode/CHANGELOG.md index 553a967807..2f41201d97 100644 --- a/mixnode/CHANGELOG.md +++ b/mixnode/CHANGELOG.md @@ -1,5 +1,10 @@ # nym-mixnode Changelog +## 0.3.2 + +* added separate announce address +* allows announcing dns hostname instead of an ip address + ## 0.3.1 * Fixed crash when directory server goes down diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index 32859e847a..8c51ad61e0 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -1,7 +1,7 @@ [package] build = "build.rs" name = "nym-mixnode" -version = "0.3.1" +version = "0.3.2" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" diff --git a/mixnode/src/main.rs b/mixnode/src/main.rs index 6f92d4285c..ee05378043 100644 --- a/mixnode/src/main.rs +++ b/mixnode/src/main.rs @@ -32,6 +32,18 @@ fn main() { .takes_value(true) .required(true), ) + .arg( + Arg::with_name("announce_host") + .long("announce-host") + .help("The host that will be reported to the directory server") + .takes_value(true) + ) + .arg( + Arg::with_name("announce_port") + .long("announce-port") + .help("The port that will be reported to the directory server") + .takes_value(true) + ) .arg( Arg::with_name("directory") .long("directory") diff --git a/mixnode/src/node/mod.rs b/mixnode/src/node/mod.rs index f6e151803d..99f4e9646e 100644 --- a/mixnode/src/node/mod.rs +++ b/mixnode/src/node/mod.rs @@ -19,6 +19,7 @@ mod presence; pub mod runner; pub struct Config { + announce_address: String, directory_server: String, layer: usize, public_key: MontgomeryPoint, diff --git a/mixnode/src/node/presence.rs b/mixnode/src/node/presence.rs index 678d8af880..283a6a3afe 100644 --- a/mixnode/src/node/presence.rs +++ b/mixnode/src/node/presence.rs @@ -17,7 +17,7 @@ impl Notifier { }; let net_client = directory_client::Client::new(config); let presence = MixNodePresence { - host: node_config.socket_address.to_string(), // note: the directory server determines the real incoming IP itself, but uses the socket. Host here is just a placeholder. + host: node_config.announce_address.clone(), pub_key: node_config.public_key_string(), layer: node_config.layer as u64, last_seen: 0, diff --git a/mixnode/src/node/runner.rs b/mixnode/src/node/runner.rs index 8f120cc0a7..a403e02036 100644 --- a/mixnode/src/node/runner.rs +++ b/mixnode/src/node/runner.rs @@ -24,6 +24,10 @@ pub fn start(matches: &ArgMatches) { "Listening for incoming packets on {}", config.socket_address ); + println!( + "Announcing the following socket address: {}", + config.announce_address + ); let mix = MixNode::new(&config); mix.start(config).unwrap(); @@ -51,6 +55,20 @@ fn new_config(matches: &ArgMatches) -> node::Config { .next() .expect("Failed to extract the socket address from the iterator"); + let announce_host = matches.value_of("announce_host").unwrap_or(host); + let announce_port = matches + .value_of("announce_port") + .map(|port| port.parse::().unwrap()) + .unwrap_or(port); + + let _ = (announce_host, announce_port) + .to_socket_addrs() + .expect("Failed to combine announce host and port") + .next() + .expect("Failed to extract the announce socket address from the iterator"); + + let announce_address = format!("{}:{}", announce_host, announce_port); + let (secret_key, public_key) = sphinx::crypto::keygen(); let directory_server = matches @@ -63,6 +81,7 @@ fn new_config(matches: &ArgMatches) -> node::Config { layer, public_key, socket_address, + announce_address, secret_key, } } diff --git a/nym-client/CHANGELOG.md b/nym-client/CHANGELOG.md index 02c638b629..34ed4c2dd2 100644 --- a/nym-client/CHANGELOG.md +++ b/nym-client/CHANGELOG.md @@ -1,5 +1,9 @@ # nym-client Changelog +## 0.3.2 + +* allows receiving topology with dns hostname instead of an ip address + ## 0.3.1 * Version increase for consistency with `nym-mixnode` and `nym-sfw-provider` diff --git a/nym-client/Cargo.toml b/nym-client/Cargo.toml index 4c52dbd0fb..fbf8e54a62 100644 --- a/nym-client/Cargo.toml +++ b/nym-client/Cargo.toml @@ -1,7 +1,7 @@ [package] build = "build.rs" name = "nym-client" -version = "0.3.1" +version = "0.3.2" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" diff --git a/scripts/run_local_network.sh b/scripts/run_local_network.sh index 0bc1b91fc1..fe2f949408 100755 --- a/scripts/run_local_network.sh +++ b/scripts/run_local_network.sh @@ -1,3 +1,5 @@ +#!/bin/bash + #// Copyright 2020 The Nym Mixnet Authors #// #// Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,7 +14,6 @@ #// See the License for the specific language governing permissions and #// limitations under the License. -#!/bin/bash echo "Killing old testnet processes..." diff --git a/sfw-provider/CHANGELOG.md b/sfw-provider/CHANGELOG.md index 6379cbed8a..6da245a539 100644 --- a/sfw-provider/CHANGELOG.md +++ b/sfw-provider/CHANGELOG.md @@ -1,5 +1,9 @@ # nym-sfw-provider Changelog +## 0.3.2 + +* Version increase for consistency with `nym-mixnode` and `nym-client` + ## 0.3.1 * Fixed crash when directory server goes down diff --git a/sfw-provider/Cargo.toml b/sfw-provider/Cargo.toml index 2ab7cc691f..83bf161c9a 100644 --- a/sfw-provider/Cargo.toml +++ b/sfw-provider/Cargo.toml @@ -1,7 +1,7 @@ [package] build = "build.rs" name = "nym-sfw-provider" -version = "0.3.1" +version = "0.3.2" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018"