From 2075b92ab55b9c1a97c2229b4c3f8912bc5801ff Mon Sep 17 00:00:00 2001 From: Stanimal Date: Tue, 14 Dec 2021 09:48:00 +0400 Subject: [PATCH] fix: remove noise negotiation for debugging on bad wire mode --- comms/src/connection_manager/listener.rs | 36 ++---------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/comms/src/connection_manager/listener.rs b/comms/src/connection_manager/listener.rs index df5d648543..f261fbd7c1 100644 --- a/comms/src/connection_manager/listener.rs +++ b/comms/src/connection_manager/listener.rs @@ -33,7 +33,6 @@ use std::{ use futures::{future, FutureExt}; use log::*; -use tari_crypto::tari_utilities::hex::Hex; use tari_shutdown::{oneshot_trigger, oneshot_trigger::OneshotTrigger, ShutdownSignal}; use tokio::{ io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}, @@ -286,18 +285,14 @@ where } }, Ok(WireMode::Comms(byte)) => { - // TODO: This call is expensive and only added for the benefit of improved logging and may lead to - // TODO: DoS attacks. Remove later when not needed anymore or make it optional with a config file - // TODO: setting. - let public_key = Self::remote_public_key_from_socket(socket, noise_config).await; warn!( target: LOG_TARGET, - "Peer at address '{}' ({}) sent invalid wire format byte. Expected {:x?} got: {:x?} ", + "Peer at address '{}' sent invalid wire format byte. Expected {:x?} got: {:x?} ", peer_addr, - public_key, config.network_info.network_byte, byte, ); + let _ = socket.shutdown().await; }, Ok(WireMode::Liveness) => { if liveness_session_count.load(Ordering::SeqCst) > 0 && @@ -339,33 +334,6 @@ where self.bounded_executor.spawn(inbound_fut).await; } - async fn remote_public_key_from_socket(socket: TTransport::Output, noise_config: NoiseConfig) -> String { - let noise_socket = time::timeout( - Duration::from_secs(30), - noise_config.upgrade_socket(socket, ConnectionDirection::Inbound), - ) - .await; - - let public_key = match noise_socket { - Ok(Ok(mut noise_socket)) => { - let pk = noise_socket.get_remote_public_key(); - if let Err(err) = noise_socket.shutdown().await { - debug!( - target: LOG_TARGET, - "IO error when closing socket after invalid wire format: {}", err - ); - } - pk - }, - _ => None, - }; - - match public_key { - None => "public key not known".to_string(), - Some(pk) => pk.to_hex(), - } - } - #[allow(clippy::too_many_arguments)] async fn perform_socket_upgrade_procedure( node_identity: Arc,