Checking if any other node is already announcing the same host (#168)
This commit is contained in:
committed by
GitHub
parent
d02e248328
commit
d859a98367
Generated
+2
@@ -1591,6 +1591,7 @@ dependencies = [
|
||||
"sphinx",
|
||||
"tempfile",
|
||||
"tokio 0.2.12",
|
||||
"topology",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1620,6 +1621,7 @@ dependencies = [
|
||||
"sphinx",
|
||||
"tempfile",
|
||||
"tokio 0.2.12",
|
||||
"topology",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -26,6 +26,7 @@ crypto = {path = "../common/crypto"}
|
||||
directory-client = { path = "../common/clients/directory-client" }
|
||||
multi-tcp-client = { path = "../common/clients/multi-tcp-client" }
|
||||
pemstore = {path = "../common/pemstore"}
|
||||
topology = {path = "../common/topology"}
|
||||
|
||||
## will be moved to proper dependencies once released
|
||||
sphinx = { git = "https://github.com/nymtech/sphinx", rev="44d8f2aece5049eaa4fe84b7948758ce82b4b80d" }
|
||||
|
||||
@@ -2,11 +2,13 @@ use crate::config::persistence::pathfinder::MixNodePathfinder;
|
||||
use crate::config::Config;
|
||||
use crate::node::packet_processing::PacketProcessor;
|
||||
use crypto::encryption;
|
||||
use directory_client::presence::Topology;
|
||||
use futures::channel::mpsc;
|
||||
use log::*;
|
||||
use pemstore::pemstore::PemStore;
|
||||
use std::net::SocketAddr;
|
||||
use tokio::runtime::Runtime;
|
||||
use topology::NymTopology;
|
||||
|
||||
mod listener;
|
||||
mod metrics;
|
||||
@@ -97,7 +99,24 @@ impl MixNode {
|
||||
.start(self.runtime.handle())
|
||||
}
|
||||
|
||||
fn check_if_same_ip_node_exists(&self) -> Option<String> {
|
||||
// TODO: once we change to graph topology this here will need to be updated!
|
||||
let topology = Topology::new(self.config.get_presence_directory_server());
|
||||
let existing_mixes_presence = topology.mix_nodes;
|
||||
existing_mixes_presence
|
||||
.iter()
|
||||
.find(|node| node.host == self.config.get_announce_address())
|
||||
.map(|node| node.pub_key.clone())
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
if let Some(duplicate_node_key) = self.check_if_same_ip_node_exists() {
|
||||
error!(
|
||||
"Our announce-host is identical to one of existing nodes! (its key is {:?}",
|
||||
duplicate_node_key
|
||||
);
|
||||
return;
|
||||
}
|
||||
let forwarding_channel = self.start_packet_forwarder();
|
||||
let metrics_reporter = self.start_metrics_reporter();
|
||||
self.start_socket_listener(metrics_reporter, forwarding_channel);
|
||||
|
||||
@@ -29,6 +29,7 @@ config = {path = "../common/config"}
|
||||
directory-client = { path = "../common/clients/directory-client" }
|
||||
pemstore = {path = "../common/pemstore"}
|
||||
sfw-provider-requests = { path = "./sfw-provider-requests" }
|
||||
topology = {path = "../common/topology"}
|
||||
|
||||
# this dependency is due to requiring to know content of loop message. however, mix-client module itself
|
||||
# is going to be removed or renamed at some point as it no longer servers its purpose of sending traffic to mix network
|
||||
|
||||
@@ -3,9 +3,11 @@ use crate::config::Config;
|
||||
use crate::provider::client_handling::ledger::ClientLedger;
|
||||
use crate::provider::storage::ClientStorage;
|
||||
use crypto::encryption;
|
||||
use directory_client::presence::Topology;
|
||||
use log::*;
|
||||
use pemstore::pemstore::PemStore;
|
||||
use tokio::runtime::Runtime;
|
||||
use topology::NymTopology;
|
||||
|
||||
mod client_handling;
|
||||
mod mix_handling;
|
||||
@@ -85,12 +87,33 @@ impl ServiceProvider {
|
||||
);
|
||||
}
|
||||
|
||||
fn check_if_same_ip_provider_exists(&self) -> Option<String> {
|
||||
// TODO: once we change to graph topology this here will need to be updated!
|
||||
let topology = Topology::new(self.config.get_presence_directory_server());
|
||||
let existing_providers_presence = topology.mix_provider_nodes;
|
||||
existing_providers_presence
|
||||
.iter()
|
||||
.find(|node| {
|
||||
node.mixnet_listener == self.config.get_mix_announce_address()
|
||||
|| node.client_listener == self.config.get_clients_announce_address()
|
||||
})
|
||||
.map(|node| node.pub_key.clone())
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
// A possible future optimisation, depending on bottlenecks and resource usage:
|
||||
// considering, presumably, there will be more mix packets received than client requests:
|
||||
// create 2 separate runtimes - one with bigger threadpool dedicated solely for
|
||||
// the mix handling and the other one for the rest of tasks
|
||||
|
||||
if let Some(duplicate_provider_key) = self.check_if_same_ip_provider_exists() {
|
||||
error!(
|
||||
"Our announce-host is identical to one of existing nodes! (its key is {:?}",
|
||||
duplicate_provider_key
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let client_storage = ClientStorage::new(
|
||||
self.config.get_message_retrieval_limit() as usize,
|
||||
self.config.get_stored_messages_filename_length(),
|
||||
|
||||
Reference in New Issue
Block a user