From 6ccf3a84957c276320d229418f78ac23d58680c1 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 17 Feb 2021 17:43:07 +0100 Subject: Add resilience when peer_addr() fails --- src/conn.rs | 4 ++-- src/netapp.rs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/conn.rs b/src/conn.rs index a4c4f4e..daa0235 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -46,7 +46,7 @@ impl ServerConn { let peer_id = handshake.peer_pk.clone(); let tokio_socket = asyncstd_socket.into_inner(); - let remote_addr = tokio_socket.peer_addr().unwrap(); + let remote_addr = tokio_socket.peer_addr()?; debug!( "Handshake complete (server) with {}@{}", @@ -160,7 +160,7 @@ impl ClientConn { .await?; let tokio_socket = asyncstd_socket.into_inner(); - let remote_addr = tokio_socket.peer_addr().unwrap(); + let remote_addr = tokio_socket.peer_addr()?; debug!( "Handshake complete (client) with {}@{}", diff --git a/src/netapp.rs b/src/netapp.rs index eed0f59..0ddd447 100644 --- a/src/netapp.rs +++ b/src/netapp.rs @@ -210,7 +210,10 @@ impl NetApp { let (socket, _) = listener.accept().await.unwrap(); info!( "Incoming connection from {}, negotiating handshake...", - socket.peer_addr().unwrap() + match socket.peer_addr() { + Ok(x) => format!("{}", x), + Err(e) => format!("", e), + } ); let self2 = self.clone(); tokio::spawn(async move { -- cgit v1.2.3