Merge pull request #656 from nymtech/feature/configurable-verloc-http-ports

Feature/configurable verloc http ports
This commit is contained in:
Bogdan-Ștefan Neacşu
2021-06-28 14:52:54 +03:00
committed by GitHub
23 changed files with 196 additions and 141 deletions
+13 -1
View File
@@ -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(
+24
View File
@@ -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::<u16>())
{
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::<u16>())
{
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));
}
+13 -1
View File
@@ -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(
+41
View File
@@ -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(),
+9 -1
View File
@@ -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 }}
+1 -1
View File
@@ -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;
+13 -11
View File
@@ -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!");