Feature/very minor refactoring (#188)

* log statement for forwarding traffic

* Mixnode logging intent to forward packet

* Presence logging level decrease + making things less public

* Default adjustments + human readable equivalents in comments

* Do not immediately refresh topology on start
This commit is contained in:
Jędrzej Stuczyński
2020-04-17 18:59:22 +01:00
committed by GitHub
parent 8f4dff0074
commit fda308694e
6 changed files with 22 additions and 19 deletions
@@ -91,6 +91,7 @@ impl Client {
message: Vec<u8>,
wait_for_response: bool,
) -> io::Result<()> {
trace!("Sending packet to {:?}", address);
if !self.connections_managers.contains_key(&address) {
debug!(
"There is no existing connection to {:?} - it will be established now",
+2
View File
@@ -14,6 +14,7 @@
use futures::channel::mpsc;
use futures::StreamExt;
use log::*;
use std::net::SocketAddr;
use std::time::Duration;
use tokio::runtime::Handle;
@@ -50,6 +51,7 @@ impl PacketForwarder {
let sender_channel = self.conn_tx.clone();
handle.spawn(async move {
while let Some((address, packet)) = self.conn_rx.next().await {
trace!("Going to forward packet to {:?}", address);
// as a mix node we don't care about responses, we just want to fire packets
// as quickly as possible
self.tcp_client.send(address, packet, false).await.unwrap(); // if we're not waiting for response, we MUST get an Ok
+6 -6
View File
@@ -16,12 +16,12 @@ use crate::built_info;
use directory_client::presence::mixnodes::MixNodePresence;
use directory_client::requests::presence_mixnodes_post::PresenceMixNodesPoster;
use directory_client::DirectoryClient;
use log::{debug, error};
use log::{error, trace};
use std::time::Duration;
use tokio::runtime::Handle;
use tokio::task::JoinHandle;
pub struct NotifierConfig {
pub(crate) struct NotifierConfig {
location: String,
directory_server: String,
announce_host: String,
@@ -31,7 +31,7 @@ pub struct NotifierConfig {
}
impl NotifierConfig {
pub fn new(
pub(crate) fn new(
location: String,
directory_server: String,
announce_host: String,
@@ -50,14 +50,14 @@ impl NotifierConfig {
}
}
pub struct Notifier {
pub(crate) struct Notifier {
net_client: directory_client::Client,
presence: MixNodePresence,
sending_delay: Duration,
}
impl Notifier {
pub fn new(config: NotifierConfig) -> Notifier {
pub(crate) fn new(config: NotifierConfig) -> Notifier {
let directory_client_cfg = directory_client::Config {
base_url: config.directory_server,
};
@@ -80,7 +80,7 @@ impl Notifier {
fn notify(&self) {
match self.net_client.presence_mix_nodes_post.post(&self.presence) {
Err(err) => error!("failed to send presence - {:?}", err),
Ok(_) => debug!("sent presence information"),
Ok(_) => trace!("sent presence information"),
}
}
+1 -1
View File
@@ -232,8 +232,8 @@ impl<T: 'static + NymTopology> TopologyRefresher<T> {
pub(crate) fn start(mut self, handle: &Handle) -> JoinHandle<()> {
handle.spawn(async move {
loop {
self.refresh().await;
tokio::time::delay_for(self.refresh_rate).await;
self.refresh().await;
}
})
}
+6 -6
View File
@@ -26,12 +26,12 @@ const DEFAULT_LISTENING_PORT: u16 = 9001;
// 'DEBUG'
// where applicable, the below are defined in milliseconds
const DEFAULT_LOOP_COVER_STREAM_AVERAGE_DELAY: u64 = 1000;
const DEFAULT_MESSAGE_STREAM_AVERAGE_DELAY: u64 = 500;
const DEFAULT_AVERAGE_PACKET_DELAY: u64 = 200;
const DEFAULT_FETCH_MESSAGES_DELAY: u64 = 1000;
const DEFAULT_TOPOLOGY_REFRESH_RATE: u64 = 10_000;
const DEFAULT_TOPOLOGY_RESOLUTION_TIMEOUT: u64 = 5_000;
const DEFAULT_LOOP_COVER_STREAM_AVERAGE_DELAY: u64 = 1000; // 1s
const DEFAULT_MESSAGE_STREAM_AVERAGE_DELAY: u64 = 500; // 0.5s
const DEFAULT_AVERAGE_PACKET_DELAY: u64 = 200; // 0.2s
const DEFAULT_FETCH_MESSAGES_DELAY: u64 = 1000; // 1s
const DEFAULT_TOPOLOGY_REFRESH_RATE: u64 = 30_000; // 30s
const DEFAULT_TOPOLOGY_RESOLUTION_TIMEOUT: u64 = 5_000; // 5s
const DEFAULT_PACKET_FORWARDING_INITIAL_BACKOFF: u64 = 10_000; // 10s
const DEFAULT_PACKET_FORWARDING_MAXIMUM_BACKOFF: u64 = 300_000; // 5min
const DEFAULT_INITIAL_CONNECTION_TIMEOUT: u64 = 1_500; // 1.5s
+6 -6
View File
@@ -17,12 +17,12 @@ use crate::provider::ClientLedger;
use directory_client::presence::providers::MixProviderPresence;
use directory_client::requests::presence_providers_post::PresenceMixProviderPoster;
use directory_client::DirectoryClient;
use log::{debug, error};
use log::{error, trace};
use std::time::Duration;
use tokio::runtime::Handle;
use tokio::task::JoinHandle;
pub struct NotifierConfig {
pub(crate) struct NotifierConfig {
location: String,
directory_server: String,
mix_announce_host: String,
@@ -32,7 +32,7 @@ pub struct NotifierConfig {
}
impl NotifierConfig {
pub fn new(
pub(crate) fn new(
location: String,
directory_server: String,
mix_announce_host: String,
@@ -51,7 +51,7 @@ impl NotifierConfig {
}
}
pub struct Notifier {
pub(crate) struct Notifier {
location: String,
net_client: directory_client::Client,
client_ledger: ClientLedger,
@@ -91,10 +91,10 @@ impl Notifier {
}
}
pub fn notify(&self, presence: MixProviderPresence) {
pub(crate) fn notify(&self, presence: MixProviderPresence) {
match self.net_client.presence_providers_post.post(&presence) {
Err(err) => error!("failed to send presence - {:?}", err),
Ok(_) => debug!("sent presence information"),
Ok(_) => trace!("sent presence information"),
}
}