From a521bc0f54e14fcead1a5a7d6b85bdc51cb65116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 28 Apr 2021 14:11:04 +0100 Subject: [PATCH] Logging adjustment (#585) * Reduced severity of common harmless warnings * Changed the same ip node warning * More explicit error on network address binding failure --- clients/native/src/websocket/listener.rs | 12 ++++++++---- common/client-libs/mixnet-client/src/client.rs | 2 +- .../src/cached_packet_processor/processor.rs | 4 ++-- .../src/node/client_handling/websocket/listener.rs | 11 ++++++++--- .../src/node/mixnet_handling/receiver/listener.rs | 11 ++++++++--- mixnode/src/commands/init.rs | 2 +- mixnode/src/node/listener/mod.rs | 12 +++++++++--- mixnode/src/node/mod.rs | 2 +- 8 files changed, 38 insertions(+), 18 deletions(-) diff --git a/clients/native/src/websocket/listener.rs b/clients/native/src/websocket/listener.rs index 0688d77b51..c8d2230d78 100644 --- a/clients/native/src/websocket/listener.rs +++ b/clients/native/src/websocket/listener.rs @@ -14,7 +14,7 @@ use super::handler::Handler; use log::*; -use std::{net::SocketAddr, sync::Arc}; +use std::{net::SocketAddr, process, sync::Arc}; use tokio::io::AsyncWriteExt; use tokio::runtime; use tokio::{sync::Notify, task::JoinHandle}; @@ -45,9 +45,13 @@ impl Listener { } pub(crate) async fn run(&mut self, handler: Handler) { - let tcp_listener = tokio::net::TcpListener::bind(self.address) - .await - .expect("Failed to start websocket listener"); + let tcp_listener = match tokio::net::TcpListener::bind(self.address).await { + Ok(listener) => listener, + Err(err) => { + error!("Failed to bind to {} - {}. Are you sure nothing else is running on the specified port and your user has sufficient permission to bind to the requested address?", self.address, err); + process::exit(1); + } + }; let notify = Arc::new(Notify::new()); diff --git a/common/client-libs/mixnet-client/src/client.rs b/common/client-libs/mixnet-client/src/client.rs index c9b7003bcf..6d82977a26 100644 --- a/common/client-libs/mixnet-client/src/client.rs +++ b/common/client-libs/mixnet-client/src/client.rs @@ -220,7 +220,7 @@ impl Client { "connection queue is full", )) } else if err.is_disconnected() { - warn!( + debug!( "Connection to {} seems to be dead. attempting to re-establish it...", address ); diff --git a/common/mixnode-common/src/cached_packet_processor/processor.rs b/common/mixnode-common/src/cached_packet_processor/processor.rs index 2958a53843..068c23e7f7 100644 --- a/common/mixnode-common/src/cached_packet_processor/processor.rs +++ b/common/mixnode-common/src/cached_packet_processor/processor.rs @@ -84,7 +84,7 @@ impl CachedPacketProcessor { packet: SphinxPacket, ) -> Result { packet.process(&self.sphinx_key).map_err(|err| { - warn!("Failed to unwrap Sphinx packet: {:?}", err); + debug!("Failed to unwrap Sphinx packet: {:?}", err); MixProcessingError::SphinxProcessingError(err) }) } @@ -98,7 +98,7 @@ impl CachedPacketProcessor { packet .process_with_derived_keys(&keys.0, &keys.1) .map_err(|err| { - warn!("Failed to unwrap Sphinx packet: {:?}", err); + debug!("Failed to unwrap Sphinx packet: {:?}", err); MixProcessingError::SphinxProcessingError(err) }) } diff --git a/gateway/src/node/client_handling/websocket/listener.rs b/gateway/src/node/client_handling/websocket/listener.rs index 492ce9bf08..970263eb5b 100644 --- a/gateway/src/node/client_handling/websocket/listener.rs +++ b/gateway/src/node/client_handling/websocket/listener.rs @@ -8,6 +8,7 @@ use log::*; use mixnet_client::forwarder::MixForwardingSender; use rand::rngs::OsRng; use std::net::SocketAddr; +use std::process; use std::sync::Arc; use tokio::task::JoinHandle; @@ -30,9 +31,13 @@ impl Listener { outbound_mix_sender: MixForwardingSender, ) { info!("Starting websocket listener at {}", self.address); - let tcp_listener = tokio::net::TcpListener::bind(self.address) - .await - .expect("Failed to start websocket listener"); + let tcp_listener = match tokio::net::TcpListener::bind(self.address).await { + Ok(listener) => listener, + Err(err) => { + error!("Failed to bind the websocket to {} - {}. Are you sure nothing else is running on the specified port and your user has sufficient permission to bind to the requested address?", self.address, err); + process::exit(1); + } + }; loop { match tcp_listener.accept().await { diff --git a/gateway/src/node/mixnet_handling/receiver/listener.rs b/gateway/src/node/mixnet_handling/receiver/listener.rs index f0633ea0bf..dd59d72f99 100644 --- a/gateway/src/node/mixnet_handling/receiver/listener.rs +++ b/gateway/src/node/mixnet_handling/receiver/listener.rs @@ -4,6 +4,7 @@ use crate::node::mixnet_handling::receiver::connection_handler::ConnectionHandler; use log::*; use std::net::SocketAddr; +use std::process; use tokio::task::JoinHandle; pub(crate) struct Listener { @@ -18,9 +19,13 @@ impl Listener { pub(crate) async fn run(&mut self, connection_handler: ConnectionHandler) { info!("Starting mixnet listener at {}", self.address); - let tcp_listener = tokio::net::TcpListener::bind(self.address) - .await - .expect("Failed to start mixnet listener"); + let tcp_listener = match tokio::net::TcpListener::bind(self.address).await { + Ok(listener) => listener, + Err(err) => { + error!("Failed to bind to {} - {}. Are you sure nothing else is running on the specified port and your user has sufficient permission to bind to the requested address?", self.address, err); + process::exit(1); + } + }; loop { match tcp_listener.accept().await { diff --git a/mixnode/src/commands/init.rs b/mixnode/src/commands/init.rs index e880e7921d..a9bdba7327 100644 --- a/mixnode/src/commands/init.rs +++ b/mixnode/src/commands/init.rs @@ -107,7 +107,7 @@ async fn choose_layer( for node in mixnodes { if node.mix_node.layer < 1 || node.mix_node.layer > max_layer as u64 { - warn!( + debug!( "one of bonded mixnodes is on invalid layer {}", node.mix_node.layer ); diff --git a/mixnode/src/node/listener/mod.rs b/mixnode/src/node/listener/mod.rs index 60b78797bd..caba660a1a 100644 --- a/mixnode/src/node/listener/mod.rs +++ b/mixnode/src/node/listener/mod.rs @@ -4,6 +4,7 @@ use crate::node::listener::connection_handler::ConnectionHandler; use log::*; use std::net::SocketAddr; +use std::process; use tokio::net::TcpListener; use tokio::task::JoinHandle; @@ -19,9 +20,14 @@ impl Listener { } async fn run(&mut self, connection_handler: ConnectionHandler) { - let listener = TcpListener::bind(self.address) - .await - .expect("Failed to create TCP listener"); + let listener = match TcpListener::bind(self.address).await { + Ok(listener) => listener, + Err(err) => { + error!("Failed to bind to {} - {}. Are you sure nothing else is running on the specified port and your user has sufficient permission to bind to the requested address?", self.address, err); + process::exit(1); + } + }; + loop { match listener.accept().await { Ok((socket, remote_addr)) => { diff --git a/mixnode/src/node/mod.rs b/mixnode/src/node/mod.rs index 921013c0f6..43a6229066 100644 --- a/mixnode/src/node/mod.rs +++ b/mixnode/src/node/mod.rs @@ -128,7 +128,7 @@ impl MixNode { runtime.block_on(async { if let Some(duplicate_node_key) = self.check_if_same_ip_node_exists().await { if duplicate_node_key == self.identity_keypair.public_key().to_base58_string() { - warn!("We seem to have not unregistered after going offline - there's a node with identical identity and announce-host us as registered.") + warn!("You seem to have bonded your mixnode before starting it - that's highly unrecommended as in the future it will result in slashing"); } else { error!( "Our announce-host is identical to an existing node's announce-host! (its key is {:?})",