From: Matt Corallo Date: Tue, 17 Aug 2021 00:04:34 +0000 (+0000) Subject: Stop printing to stderr in lightning-net-tokio for disconnections X-Git-Tag: v0.0.101~34^2~2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=ecf1d656ef4b48a155797e5825359ba2bb670d19;p=rust-lightning Stop printing to stderr in lightning-net-tokio for disconnections It isn't exactly a critical error situation when we disconnect a socket, so we shouldn't be printing to stderr, entirely bypassing user logging, when it happens. We do still print to stderr if we fail to write the first message to the socket, but this should never happen unless the user has a reasonably-configured system with at least one packet in bytes available for the socket buffer. --- diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 5f5fece0d..d2ee10028 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -141,30 +141,23 @@ impl Connection { PeerDisconnected } let disconnect_type = loop { - macro_rules! shutdown_socket { - ($err: expr, $need_disconnect: expr) => { { - println!("Disconnecting peer due to {}!", $err); - break $need_disconnect; - } } - } - let read_paused = { let us_lock = us.lock().unwrap(); if us_lock.rl_requested_disconnect { - shutdown_socket!("disconnect_socket() call from RL", Disconnect::CloseConnection); + break Disconnect::CloseConnection; } us_lock.read_paused }; tokio::select! { v = write_avail_receiver.recv() => { assert!(v.is_some()); // We can't have dropped the sending end, its in the us Arc! - if let Err(e) = peer_manager.write_buffer_space_avail(&mut our_descriptor) { - shutdown_socket!(e, Disconnect::CloseConnection); + if let Err(_) = peer_manager.write_buffer_space_avail(&mut our_descriptor) { + break Disconnect::CloseConnection; } }, _ = read_wake_receiver.recv() => {}, read = reader.read(&mut buf), if !read_paused => match read { - Ok(0) => shutdown_socket!("Connection closed", Disconnect::PeerDisconnected), + Ok(0) => break Disconnect::PeerDisconnected, Ok(len) => { let read_res = peer_manager.read_event(&mut our_descriptor, &buf[0..len]); let mut us_lock = us.lock().unwrap(); @@ -174,10 +167,10 @@ impl Connection { us_lock.read_paused = true; } }, - Err(e) => shutdown_socket!(e, Disconnect::CloseConnection), + Err(_) => break Disconnect::CloseConnection, } }, - Err(e) => shutdown_socket!(e, Disconnect::PeerDisconnected), + Err(_) => break Disconnect::PeerDisconnected, }, } peer_manager.process_events();