]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Stop printing to stderr in lightning-net-tokio for disconnections
authorMatt Corallo <git@bluematt.me>
Tue, 17 Aug 2021 00:04:34 +0000 (00:04 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 17 Aug 2021 21:03:14 +0000 (21:03 +0000)
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.

lightning-net-tokio/src/lib.rs

index 5f5fece0d2ed34e447e2905f9f3bd6d3f42ce102..d2ee100281eed222fd0a172ab227606318e8aaca 100644 (file)
@@ -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();