diff --git a/clients/native/src/client/config/template.rs b/clients/native/src/client/config/template.rs index 2c8a69444d..99e1b867c8 100644 --- a/clients/native/src/client/config/template.rs +++ b/clients/native/src/client/config/template.rs @@ -16,7 +16,7 @@ pub(crate) fn config_template() -> &'static str { // While using normal toml marshalling would have been way simpler with less overhead, // I think it's useful to have comments attached to the saved config file to explain behaviour of // particular fields. - // Note: any changes to the template must be reflected in the appropriate structs in mod.rs. + // Note: any changes to the template must be reflected in the appropriate structs in verloc. r#" # This is a TOML config file. # For more information, see https://github.com/toml-lang/toml diff --git a/clients/socks5/src/client/config/template.rs b/clients/socks5/src/client/config/template.rs index 614a7f6ed6..791580718a 100644 --- a/clients/socks5/src/client/config/template.rs +++ b/clients/socks5/src/client/config/template.rs @@ -16,7 +16,7 @@ pub(crate) fn config_template() -> &'static str { // While using normal toml marshalling would have been way simpler with less overhead, // I think it's useful to have comments attached to the saved config file to explain behaviour of // particular fields. - // Note: any changes to the template must be reflected in the appropriate structs in mod.rs. + // Note: any changes to the template must be reflected in the appropriate structs in verloc. r#" # This is a TOML config file. # For more information, see https://github.com/toml-lang/toml diff --git a/clients/validator/package.json b/clients/validator/package.json index 630678b4d6..c1cc85eea5 100644 --- a/clients/validator/package.json +++ b/clients/validator/package.json @@ -1,6 +1,6 @@ { "name": "@nymproject/nym-validator-client", - "version": "0.13.0", + "version": "0.14.0", "description": "A TypeScript client for interacting with smart contracts in Nym validators", "repository": "https://github.com/nymtech/nym", "main": "./dist/index.js", diff --git a/clients/validator/src/index.ts b/clients/validator/src/index.ts index 9c52fd3f38..377fa33092 100644 --- a/clients/validator/src/index.ts +++ b/clients/validator/src/index.ts @@ -403,7 +403,7 @@ export default class ValidatorClient { async bondGateway(gateway: Gateway, bond: Coin): Promise { if (this.client instanceof NetClient) { const result = await this.client.executeContract(this.client.clientAddress, this.contractAddress, {bond_gateway: {gateway: gateway}}, "adding gateway", [bond]).catch((err) => this.handleRequestFailure(err)); - console.log(`account ${this.client.clientAddress} added gateway with ${gateway.mix_host}`); + console.log(`account ${this.client.clientAddress} added gateway with ${gateway.host}`); return result; } else { throw new Error("Tried to bond gateway with a query client") diff --git a/clients/validator/src/types.ts b/clients/validator/src/types.ts index e2f5f75a23..201fac8943 100644 --- a/clients/validator/src/types.ts +++ b/clients/validator/src/types.ts @@ -9,6 +9,9 @@ export type MixNodeBond = { // TODO: change name to MixNodeBond export type MixNode = { host: string, + mix_port: number, + verloc_port: number, + http_api_port: number, layer: number, location: string, sphinx_key: string, // TODO: camelCase this later once everything else works @@ -23,8 +26,9 @@ export type GatewayBond = { } export type Gateway = { - mix_host: string, - clients_host: string, + host: string, + mix_port: number, + clients_port: number, location: string, sphinx_key: string, identity_key: string, diff --git a/common/mixnet-contract/src/gateway.rs b/common/mixnet-contract/src/gateway.rs index c474d20a41..3c8d3c0a9a 100644 --- a/common/mixnet-contract/src/gateway.rs +++ b/common/mixnet-contract/src/gateway.rs @@ -19,28 +19,6 @@ pub struct Gateway { pub version: String, } -impl Gateway { - pub fn new( - host: String, - mix_port: u16, - clients_port: u16, - location: String, - sphinx_key: SphinxKey, - identity_key: IdentityKey, - version: String, - ) -> Self { - Gateway { - host, - mix_port, - clients_port, - location, - sphinx_key, - identity_key, - version, - } - } -} - #[derive(Clone, Debug, Deserialize, PartialEq, Serialize, JsonSchema)] pub struct GatewayBond { pub amount: Vec, diff --git a/common/mixnet-contract/src/mixnode.rs b/common/mixnet-contract/src/mixnode.rs index eb7687ad17..8ceb5c26fa 100644 --- a/common/mixnet-contract/src/mixnode.rs +++ b/common/mixnet-contract/src/mixnode.rs @@ -11,6 +11,8 @@ use std::fmt::Display; pub struct MixNode { pub host: String, pub mix_port: u16, + pub verloc_port: u16, + pub http_api_port: u16, pub layer: u64, pub location: String, pub sphinx_key: SphinxKey, @@ -19,28 +21,6 @@ pub struct MixNode { pub version: String, } -impl MixNode { - pub fn new( - host: String, - mix_port: u16, - layer: u64, - location: String, - sphinx_key: SphinxKey, - identity_key: IdentityKey, - version: String, - ) -> Self { - MixNode { - host, - mix_port, - layer, - location, - sphinx_key, - identity_key, - version, - } - } -} - #[derive(Clone, Debug, Deserialize, PartialEq, Serialize, JsonSchema)] pub struct MixNodeBond { // TODO: diff --git a/common/mixnode-common/src/lib.rs b/common/mixnode-common/src/lib.rs index b0eba79f06..a7e8a54485 100644 --- a/common/mixnode-common/src/lib.rs +++ b/common/mixnode-common/src/lib.rs @@ -13,4 +13,4 @@ // limitations under the License. pub mod cached_packet_processor; -pub mod rtt_measurement; +pub mod verloc; diff --git a/common/mixnode-common/src/rtt_measurement/error.rs b/common/mixnode-common/src/verloc/error.rs similarity index 100% rename from common/mixnode-common/src/rtt_measurement/error.rs rename to common/mixnode-common/src/verloc/error.rs diff --git a/common/mixnode-common/src/rtt_measurement/listener.rs b/common/mixnode-common/src/verloc/listener.rs similarity index 98% rename from common/mixnode-common/src/rtt_measurement/listener.rs rename to common/mixnode-common/src/verloc/listener.rs index 00ea7616f0..0b8025dde7 100644 --- a/common/mixnode-common/src/rtt_measurement/listener.rs +++ b/common/mixnode-common/src/verloc/listener.rs @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::rtt_measurement::error::RttError; -use crate::rtt_measurement::packet::{EchoPacket, ReplyPacket}; +use crate::verloc::error::RttError; +use crate::verloc::packet::{EchoPacket, ReplyPacket}; use bytes::{BufMut, BytesMut}; use crypto::asymmetric::identity; use futures::StreamExt; diff --git a/common/mixnode-common/src/rtt_measurement/measurement.rs b/common/mixnode-common/src/verloc/measurement.rs similarity index 100% rename from common/mixnode-common/src/rtt_measurement/measurement.rs rename to common/mixnode-common/src/verloc/measurement.rs diff --git a/common/mixnode-common/src/rtt_measurement/mod.rs b/common/mixnode-common/src/verloc/mod.rs similarity index 89% rename from common/mixnode-common/src/rtt_measurement/mod.rs rename to common/mixnode-common/src/verloc/mod.rs index 2a351eef49..6596f9269c 100644 --- a/common/mixnode-common/src/rtt_measurement/mod.rs +++ b/common/mixnode-common/src/verloc/mod.rs @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::rtt_measurement::listener::PacketListener; -pub use crate::rtt_measurement::measurement::{AtomicVerlocResult, Verloc, VerlocResult}; -use crate::rtt_measurement::sender::{PacketSender, TestedNode}; +use crate::verloc::listener::PacketListener; +pub use crate::verloc::measurement::{AtomicVerlocResult, Verloc, VerlocResult}; +use crate::verloc::sender::{PacketSender, TestedNode}; use crypto::asymmetric::identity; use futures::stream::FuturesUnordered; use futures::StreamExt; use log::*; -use std::net::SocketAddr; +use std::net::{SocketAddr, ToSocketAddrs}; use std::sync::Arc; use std::time::Duration; use tokio::task::JoinHandle; @@ -34,9 +34,9 @@ pub(crate) mod sender; // TODO: MUST BE UPDATED BEFORE ACTUAL RELEASE!! pub const MINIMUM_NODE_VERSION: &str = "0.10.1"; -pub const DEFAULT_MEASUREMENT_PORT: u16 = 1790; // by default all of those are overwritten by config data from mixnodes directly +const DEFAULT_VERLOC_PORT: u16 = 1790; const DEFAULT_PACKETS_PER_NODE: usize = 100; const DEFAULT_PACKET_TIMEOUT: Duration = Duration::from_millis(1500); const DEFAULT_CONNECTION_TIMEOUT: Duration = Duration::from_millis(5000); @@ -50,9 +50,6 @@ pub struct Config { /// Minimum semver version of a node (gateway or mixnode) that is capable of replying to echo packets. minimum_compatible_node_version: version_checker::Version, - /// Port on which all nodes are (supposed to be) listening for the measurement packets. - measurement_port: u16, - /// Socket address of this node on which it will be listening for the measurement packets. listening_address: SocketAddr, @@ -102,10 +99,6 @@ impl ConfigBuilder { self.0.minimum_compatible_node_version = version; self } - pub fn measurement_port(mut self, measurement_port: u16) -> Self { - self.0.measurement_port = measurement_port; - self - } pub fn listening_address(mut self, listening_address: SocketAddr) -> Self { self.0.listening_address = listening_address; self @@ -154,9 +147,6 @@ impl ConfigBuilder { if self.0.mixnet_contract_address.is_empty() { panic!("the mixnet contract address must be set") } - if self.0.measurement_port != self.0.listening_address.port() { - panic!("Tried to create listener on different port than the other machines") - } self.0 } } @@ -165,10 +155,7 @@ impl Default for ConfigBuilder { fn default() -> Self { ConfigBuilder(Config { minimum_compatible_node_version: parse_version(MINIMUM_NODE_VERSION).unwrap(), - measurement_port: DEFAULT_MEASUREMENT_PORT, - listening_address: format!("[::]:{}", DEFAULT_MEASUREMENT_PORT) - .parse() - .unwrap(), + listening_address: format!("[::]:{}", DEFAULT_VERLOC_PORT).parse().unwrap(), packets_per_node: DEFAULT_PACKETS_PER_NODE, packet_timeout: DEFAULT_PACKET_TIMEOUT, connection_timeout: DEFAULT_CONNECTION_TIMEOUT, @@ -182,7 +169,7 @@ impl Default for ConfigBuilder { } } -pub struct RttMeasurer { +pub struct VerlocMeasurer { config: Config, packet_sender: Arc, packet_listener: Arc, @@ -195,14 +182,9 @@ pub struct RttMeasurer { results: AtomicVerlocResult, } -// I really don't like this solution, I think nodes should be explicitly announcing that address... -pub fn replace_port(address: SocketAddr, port: u16) -> SocketAddr { - SocketAddr::new(address.ip(), port) -} - -impl RttMeasurer { +impl VerlocMeasurer { pub fn new(config: Config, identity: Arc) -> Self { - RttMeasurer { + VerlocMeasurer { packet_sender: Arc::new(PacketSender::new( Arc::clone(&identity), config.packets_per_node, @@ -312,11 +294,18 @@ impl RttMeasurer { // try to parse the identity and host let node_identity = identity::PublicKey::from_base58_string(node.mix_node.identity_key).ok()?; - let mix_host = node.mix_node.host.parse().ok()?; - Some(TestedNode::new( - replace_port(mix_host, self.config.measurement_port), - node_identity, - )) + + let verloc_host = (&*node.mix_node.host, node.mix_node.verloc_port) + .to_socket_addrs() + .ok()? + .next()?; + + // TODO: possible problem in the future, this does name resolution and theoretically + // if a lot of nodes maliciously mis-configured themselves, it might take a while to resolve them all + // However, maybe it's not a problem as if they are misconfigured, they will eventually be + // pushed out of the network and on top of that, verloc is done in separate task that runs + // only every few hours. + Some(TestedNode::new(verloc_host, node_identity)) }) .collect::>(); diff --git a/common/mixnode-common/src/rtt_measurement/packet.rs b/common/mixnode-common/src/verloc/packet.rs similarity index 98% rename from common/mixnode-common/src/rtt_measurement/packet.rs rename to common/mixnode-common/src/verloc/packet.rs index d25b12b1b7..d899273694 100644 --- a/common/mixnode-common/src/rtt_measurement/packet.rs +++ b/common/mixnode-common/src/verloc/packet.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::rtt_measurement::error::RttError; +use crate::verloc::error::RttError; use crypto::asymmetric::identity::{self, PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH}; use std::convert::TryInto; diff --git a/common/mixnode-common/src/rtt_measurement/sender.rs b/common/mixnode-common/src/verloc/sender.rs similarity index 97% rename from common/mixnode-common/src/rtt_measurement/sender.rs rename to common/mixnode-common/src/verloc/sender.rs index 4bbefd2dac..2f45d99854 100644 --- a/common/mixnode-common/src/rtt_measurement/sender.rs +++ b/common/mixnode-common/src/verloc/sender.rs @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::rtt_measurement::error::RttError; -use crate::rtt_measurement::measurement::Measurement; -use crate::rtt_measurement::packet::{EchoPacket, ReplyPacket}; +use crate::verloc::error::RttError; +use crate::verloc::measurement::Measurement; +use crate::verloc::packet::{EchoPacket, ReplyPacket}; use crypto::asymmetric::identity; use log::*; use rand::{thread_rng, Rng}; diff --git a/contracts/mixnet/src/support/tests.rs b/contracts/mixnet/src/support/tests.rs index 8b3ee0dc37..c591b768a7 100644 --- a/contracts/mixnet/src/support/tests.rs +++ b/contracts/mixnet/src/support/tests.rs @@ -105,52 +105,57 @@ pub mod helpers { } pub fn mix_node_fixture() -> MixNode { - MixNode::new( - "mix.node.org".to_string(), - 1789, - 1, - "Sweden".to_string(), - "sphinx".to_string(), - "identity".to_string(), - "0.10.0".to_string(), - ) + MixNode { + host: "mix.node.org".to_string(), + mix_port: 1789, + verloc_port: 1790, + http_api_port: 8000, + layer: 1, + location: "Sweden".to_string(), + sphinx_key: "sphinx".to_string(), + identity_key: "identity".to_string(), + version: "0.10.0".to_string(), + } } pub fn mixnode_bond_fixture() -> MixNodeBond { - let mix_node = MixNode::new( - "1.1.1.1".to_string(), - 1789, - 1, - "London".to_string(), - "1234".to_string(), - "aaaa".to_string(), - "0.10.0".to_string(), - ); + let mix_node = MixNode { + host: "1.1.1.1".to_string(), + mix_port: 1789, + verloc_port: 1790, + http_api_port: 8000, + layer: 1, + location: "London".to_string(), + sphinx_key: "1234".to_string(), + identity_key: "aaaa".to_string(), + version: "0.10.0".to_string(), + }; MixNodeBond::new(coins(50, DENOM), Addr::unchecked("foo"), mix_node) } pub fn gateway_fixture() -> Gateway { - Gateway::new( - "1.1.1.1".to_string(), - 1789, - 9000, - "Sweden".to_string(), - "sphinx".to_string(), - "identity".to_string(), - "0.10.0".to_string(), - ) + Gateway { + host: "1.1.1.1".to_string(), + mix_port: 1789, + clients_port: 9000, + location: "Sweden".to_string(), + + sphinx_key: "sphinx".to_string(), + identity_key: "identity".to_string(), + version: "0.10.0".to_string(), + } } pub fn gateway_bond_fixture() -> GatewayBond { - let gateway = Gateway::new( - "1.1.1.1".to_string(), - 1789, - 9000, - "London".to_string(), - "sphinx".to_string(), - "identity".to_string(), - "0.10.0".to_string(), - ); + let gateway = Gateway { + host: "1.1.1.1".to_string(), + mix_port: 1789, + clients_port: 9000, + location: "London".to_string(), + sphinx_key: "sphinx".to_string(), + identity_key: "identity".to_string(), + version: "0.10.0".to_string(), + }; GatewayBond::new(coins(50, DENOM), Addr::unchecked("foo"), gateway) } diff --git a/gateway/src/config/template.rs b/gateway/src/config/template.rs index 2ac303b465..c4522abfdd 100644 --- a/gateway/src/config/template.rs +++ b/gateway/src/config/template.rs @@ -5,7 +5,7 @@ pub(crate) fn config_template() -> &'static str { // While using normal toml marshalling would have been way simpler with less overhead, // I think it's useful to have comments attached to the saved config file to explain behaviour of // particular fields. - // Note: any changes to the template must be reflected in the appropriate structs in mod.rs. + // Note: any changes to the template must be reflected in the appropriate structs in verloc. r#" # This is a TOML config file. # For more information, see https://github.com/toml-lang/toml diff --git a/mixnode/src/commands/init.rs b/mixnode/src/commands/init.rs index 53b13aed16..37a599291b 100644 --- a/mixnode/src/commands/init.rs +++ b/mixnode/src/commands/init.rs @@ -37,7 +37,19 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .arg( Arg::with_name(MIX_PORT_ARG_NAME) .long(MIX_PORT_ARG_NAME) - .help("The port on which the mixnode will be listening") + .help("The port on which the mixnode will be listening for mix packets") + .takes_value(true), + ) + .arg( + Arg::with_name(VERLOC_PORT_ARG_NAME) + .long(VERLOC_PORT_ARG_NAME) + .help("The port on which the mixnode will be listening for verloc packets") + .takes_value(true), + ) + .arg( + Arg::with_name(HTTP_API_PORT_ARG_NAME) + .long(HTTP_API_PORT_ARG_NAME) + .help("The port on which the mixnode will be listening for http requests") .takes_value(true), ) .arg( diff --git a/mixnode/src/commands/mod.rs b/mixnode/src/commands/mod.rs index 0cd690220b..97e49a4d46 100644 --- a/mixnode/src/commands/mod.rs +++ b/mixnode/src/commands/mod.rs @@ -15,6 +15,8 @@ pub(crate) const ID_ARG_NAME: &str = "id"; pub(crate) const HOST_ARG_NAME: &str = "host"; pub(crate) const LAYER_ARG_NAME: &str = "layer"; pub(crate) const MIX_PORT_ARG_NAME: &str = "mix-port"; +pub(crate) const VERLOC_PORT_ARG_NAME: &str = "verloc-port"; +pub(crate) const HTTP_API_PORT_ARG_NAME: &str = "http-api-port"; pub(crate) const VALIDATORS_ARG_NAME: &str = "validators"; pub(crate) const CONTRACT_ARG_NAME: &str = "mixnet-contract"; pub(crate) const ANNOUNCE_HOST_ARG_NAME: &str = "announce-host"; @@ -58,6 +60,28 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Confi config = config.with_mix_port(port.unwrap()); } + if let Some(port) = matches + .value_of(VERLOC_PORT_ARG_NAME) + .map(|port| port.parse::()) + { + if let Err(err) = port { + // if port was overridden, it must be parsable + panic!("Invalid verloc port value provided - {:?}", err); + } + config = config.with_verloc_port(port.unwrap()); + } + + if let Some(port) = matches + .value_of(HTTP_API_PORT_ARG_NAME) + .map(|port| port.parse::()) + { + if let Err(err) = port { + // if port was overridden, it must be parsable + panic!("Invalid http api port value provided - {:?}", err); + } + config = config.with_http_api_port(port.unwrap()); + } + if let Some(raw_validators) = matches.value_of(VALIDATORS_ARG_NAME) { config = config.with_custom_validators(parse_validators(raw_validators)); } diff --git a/mixnode/src/commands/run.rs b/mixnode/src/commands/run.rs index 0d74647a19..c5b3f393c5 100644 --- a/mixnode/src/commands/run.rs +++ b/mixnode/src/commands/run.rs @@ -37,7 +37,19 @@ pub fn command_args<'a, 'b>() -> App<'a, 'b> { .arg( Arg::with_name(MIX_PORT_ARG_NAME) .long(MIX_PORT_ARG_NAME) - .help("The port on which the mixnode will be listening") + .help("The port on which the mixnode will be listening for mix packets") + .takes_value(true), + ) + .arg( + Arg::with_name(VERLOC_PORT_ARG_NAME) + .long(VERLOC_PORT_ARG_NAME) + .help("The port on which the mixnode will be listening for verloc packets") + .takes_value(true), + ) + .arg( + Arg::with_name(HTTP_API_PORT_ARG_NAME) + .long(HTTP_API_PORT_ARG_NAME) + .help("The port on which the mixnode will be listening for http requests") .takes_value(true), ) .arg( diff --git a/mixnode/src/config/mod.rs b/mixnode/src/config/mod.rs index 7b8320ae4f..d41944567b 100644 --- a/mixnode/src/config/mod.rs +++ b/mixnode/src/config/mod.rs @@ -16,6 +16,9 @@ pub(crate) const MISSING_VALUE: &str = "MISSING VALUE"; // 'MIXNODE' const DEFAULT_MIX_LISTENING_PORT: u16 = 1789; +const DEFAULT_VERLOC_LISTENING_PORT: u16 = 1790; +const DEFAULT_HTTP_API_LISTENING_PORT: u16 = 8000; + pub(crate) const DEFAULT_VALIDATOR_REST_ENDPOINTS: &[&str] = &[ "http://testnet-finney-validator.nymtech.net:1317", "http://testnet-finney-validator2.nymtech.net:1317", @@ -64,6 +67,14 @@ fn default_mix_port() -> u16 { DEFAULT_MIX_LISTENING_PORT } +fn default_verloc_port() -> u16 { + DEFAULT_VERLOC_LISTENING_PORT +} + +fn default_http_api_port() -> u16 { + DEFAULT_HTTP_API_LISTENING_PORT +} + // basically a migration helper that deserialises string representation of a maybe socket addr (like "1.1.1.1:1234") // into just the ipaddr (like "1.1.1.1") pub(super) fn de_ipaddr_from_maybe_str_socks_addr<'de, D>( @@ -197,6 +208,16 @@ impl Config { self } + pub fn with_verloc_port(mut self, port: u16) -> Self { + self.mixnode.verloc_port = port; + self + } + + pub fn with_http_api_port(mut self, port: u16) -> Self { + self.mixnode.http_api_port = port; + self + } + pub fn announce_address_from_listening_address(mut self) -> Self { self.mixnode.announce_address = self.mixnode.listening_address.to_string(); self @@ -260,6 +281,14 @@ impl Config { self.mixnode.mix_port } + pub fn get_verloc_port(&self) -> u16 { + self.mixnode.verloc_port + } + + pub fn get_http_api_port(&self) -> u16 { + self.mixnode.http_api_port + } + pub fn get_packet_forwarding_initial_backoff(&self) -> Duration { self.debug.packet_forwarding_initial_backoff } @@ -347,6 +376,16 @@ pub struct MixNode { #[serde(default = "default_mix_port")] mix_port: u16, + /// Port used for listening for verloc traffic. + /// (default: 1790) + #[serde(default = "default_verloc_port")] + verloc_port: u16, + + /// Port used for listening for http requests. + /// (default: 8000) + #[serde(default = "default_http_api_port")] + http_api_port: u16, + /// Path to file containing private identity key. #[serde(default = "missing_string_value")] private_identity_key_file: PathBuf, @@ -405,6 +444,8 @@ impl Default for MixNode { listening_address: bind_all_address(), announce_address: "127.0.0.1".to_string(), mix_port: DEFAULT_MIX_LISTENING_PORT, + verloc_port: DEFAULT_VERLOC_LISTENING_PORT, + http_api_port: DEFAULT_HTTP_API_LISTENING_PORT, private_identity_key_file: Default::default(), public_identity_key_file: Default::default(), private_sphinx_key_file: Default::default(), diff --git a/mixnode/src/config/template.rs b/mixnode/src/config/template.rs index dfaae35eae..2ef91b3f9f 100644 --- a/mixnode/src/config/template.rs +++ b/mixnode/src/config/template.rs @@ -5,7 +5,7 @@ pub(crate) fn config_template() -> &'static str { // While using normal toml marshalling would have been way simpler with less overhead, // I think it's useful to have comments attached to the saved config file to explain behaviour of // particular fields. - // Note: any changes to the template must be reflected in the appropriate structs in mod.rs. + // Note: any changes to the template must be reflected in the appropriate structs in verloc. r#" # This is a TOML config file. # For more information, see https://github.com/toml-lang/toml @@ -48,6 +48,14 @@ announce_address = '{{ mixnode.announce_address }}' # (default: 1789) mix_port = {{ mixnode.mix_port }} +# Port used for listening for verloc traffic. +# (default: 1790) +verloc_port = {{ mixnode.verloc_port }} + +# Port used for listening for http requests. +# (default: 8000) +http_api_port = {{ mixnode.http_api_port }} + # Validator server to which the node will be getting information about the network. validator_rest_urls = [ {{#each mixnode.validator_rest_urls }} diff --git a/mixnode/src/node/http/verloc.rs b/mixnode/src/node/http/verloc.rs index 9d71ee67a3..4a9643aa12 100644 --- a/mixnode/src/node/http/verloc.rs +++ b/mixnode/src/node/http/verloc.rs @@ -1,4 +1,4 @@ -use mixnode_common::rtt_measurement::{AtomicVerlocResult, VerlocResult}; +use mixnode_common::verloc::{AtomicVerlocResult, VerlocResult}; use rocket::State; use rocket_contrib::json::Json; diff --git a/mixnode/src/node/mod.rs b/mixnode/src/node/mod.rs index 3b5ed2219e..94babb9232 100644 --- a/mixnode/src/node/mod.rs +++ b/mixnode/src/node/mod.rs @@ -6,7 +6,7 @@ use crate::node::http::{ description::description, not_found, stats::stats, - verloc::{verloc, VerlocState}, + verloc::{verloc as verlocRoute, VerlocState}, }; use crate::node::listener::connection_handler::packet_processing::PacketProcessor; use crate::node::listener::connection_handler::ConnectionHandler; @@ -16,7 +16,7 @@ use crate::node::node_statistics::NodeStatsWrapper; use crate::node::packet_delayforwarder::{DelayForwarder, PacketDelayForwardSender}; use crypto::asymmetric::{encryption, identity}; use log::{error, info, warn}; -use mixnode_common::rtt_measurement::{self, AtomicVerlocResult, RttMeasurer}; +use mixnode_common::verloc::{self, AtomicVerlocResult, VerlocMeasurer}; use std::net::SocketAddr; use std::process; use std::sync::Arc; @@ -61,8 +61,10 @@ impl MixNode { info!("Starting HTTP API on http://localhost:8000"); let mut config = rocket::config::Config::release_default(); + // bind to the same address as we are using for mixnodes config.address = self.config.get_listening_address(); + config.port = self.config.get_http_api_port(); let verloc_state = VerlocState::new(atomic_verloc_result); let descriptor = self.descriptor.clone(); @@ -70,7 +72,7 @@ impl MixNode { tokio::spawn(async move { rocket::build() .configure(config) - .mount("/", routes![verloc, description, stats]) + .mount("/", routes![verlocRoute, description, stats]) .register("/", catchers![not_found]) .manage(verloc_state) .manage(descriptor) @@ -135,7 +137,7 @@ impl MixNode { packet_sender } - fn start_rtt_measurer(&self) -> AtomicVerlocResult { + fn start_verloc_measurements(&self) -> AtomicVerlocResult { info!("Starting the round-trip-time measurer..."); // this is a sanity check to make sure we didn't mess up with the minimum version at some point @@ -143,7 +145,7 @@ impl MixNode { // if this code exists in the node, it MUST BE compatible let config_version = parse_version(self.config.get_version()).expect("malformed version in the config file"); - let minimum_version = parse_version(rtt_measurement::MINIMUM_NODE_VERSION).unwrap(); + let minimum_version = parse_version(verloc::MINIMUM_NODE_VERSION).unwrap(); if config_version < minimum_version { error!("You seem to have not updated your mixnode configuration file - please run `upgrade` before attempting again"); process::exit(1) @@ -153,10 +155,10 @@ impl MixNode { let listening_address = SocketAddr::new( self.config.get_listening_address(), - rtt_measurement::DEFAULT_MEASUREMENT_PORT, + self.config.get_verloc_port(), ); - let config = rtt_measurement::ConfigBuilder::new() + let config = verloc::ConfigBuilder::new() .listening_address(listening_address) .packets_per_node(self.config.get_measurement_packets_per_node()) .connection_timeout(self.config.get_measurement_connection_timeout()) @@ -169,9 +171,9 @@ impl MixNode { .mixnet_contract_address(self.config.get_validator_mixnet_contract_address()) .build(); - let mut rtt_measurer = RttMeasurer::new(config, Arc::clone(&self.identity_keypair)); - let atomic_verloc_results = rtt_measurer.get_verloc_results_pointer(); - tokio::spawn(async move { rtt_measurer.run().await }); + let mut verloc_measurer = VerlocMeasurer::new(config, Arc::clone(&self.identity_keypair)); + let atomic_verloc_results = verloc_measurer.get_verloc_results_pointer(); + tokio::spawn(async move { verloc_measurer.run().await }); atomic_verloc_results } @@ -233,7 +235,7 @@ impl MixNode { let delay_forwarding_channel = self.start_packet_delay_forwarder(node_stats_update_sender.clone()); self.start_socket_listener(node_stats_update_sender, delay_forwarding_channel); - let atomic_verloc_results= self.start_rtt_measurer(); + let atomic_verloc_results= self.start_verloc_measurements(); self.start_http_api(atomic_verloc_results, node_stats_pointer); info!("Finished nym mixnode startup procedure - it should now be able to receive mix traffic!");