Updated directory_client reqwest to 0.10 (#226)

* Updated directory_client reqwest to 0.10

* Using consistent syntax
This commit is contained in:
Jędrzej Stuczyński
2020-05-12 12:52:31 +01:00
committed by GitHub
parent f47b7cfb13
commit ff2e24afbc
25 changed files with 759 additions and 480 deletions
+32
View File
@@ -18,6 +18,7 @@ use crate::node::client_handling::websocket;
use crate::node::mixnet_handling::sender::{OutboundMixMessageSender, PacketForwarder};
use crate::node::storage::{inboxes, ClientLedger};
use crypto::encryption;
use directory_client::DirectoryClient;
use log::*;
use std::sync::Arc;
use tokio::runtime::Runtime;
@@ -137,6 +138,26 @@ impl Gateway {
);
}
async fn check_if_same_ip_gateway_exists(&self) -> Option<String> {
let announced_mix_host = self.config.get_mix_announce_address();
let announced_clients_host = self.config.get_clients_announce_address();
let directory_client_cfg =
directory_client::Config::new(self.config.get_presence_directory_server());
let topology = directory_client::Client::new(directory_client_cfg)
.get_topology()
.await
.expect("Failed to retrieve network topology");
let existing_gateways = topology.gateway_nodes;
existing_gateways
.iter()
.find(|node| {
node.mixnet_listener == announced_mix_host
|| node.client_listener == announced_clients_host
})
.map(|node| node.pub_key.clone())
}
// Rather than starting all futures with explicit `&Handle` argument, let's see how it works
// out if we make it implicit using `tokio::spawn` inside Runtime context.
// Basically more or less equivalent of using #[tokio::main] attribute.
@@ -145,6 +166,17 @@ impl Gateway {
let mut runtime = Runtime::new().unwrap();
runtime.block_on(async {
if let Some(duplicate_gateway_key) = self.check_if_same_ip_gateway_exists().await {
error!(
"Our announce-host is identical to an existing node's announce-host! (its key is {:?}",
duplicate_gateway_key
);
return;
}
let mix_forwarding_channel = self.start_packet_forwarder();
let clients_handler_sender = self.start_clients_handler();
+3 -4
View File
@@ -15,7 +15,6 @@
use crate::built_info;
use crate::node::storage::ClientLedger;
use directory_client::presence::gateways::{GatewayClient, GatewayPresence};
use directory_client::requests::presence_gateways_post::PresenceGatewayPoster;
use directory_client::DirectoryClient;
use log::{error, trace};
use std::time::Duration;
@@ -98,8 +97,8 @@ impl Notifier {
}
}
pub(crate) fn notify(&self, presence: GatewayPresence) {
match self.net_client.presence_gateway_post.post(&presence) {
async fn notify(&self, presence: GatewayPresence) {
match self.net_client.post_gateway_presence(presence).await {
Err(err) => error!("failed to send presence - {:?}", err),
Ok(_) => trace!("sent presence information"),
}
@@ -111,7 +110,7 @@ impl Notifier {
// set the deadline in the future
let sending_delay = tokio::time::delay_for(self.sending_delay);
let presence = self.make_presence().await;
self.notify(presence);
self.notify(presence).await;
// wait for however much is left
sending_delay.await;
}