From addd8d473c215def6aff61d675c11cbaac9a5b22 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 25 Apr 2023 16:51:41 +0200 Subject: [PATCH] chore: improve incoming connection traces (#2393) --- crates/net/network/src/manager.rs | 2 +- crates/net/network/src/session/mod.rs | 9 +++++++++ crates/net/network/src/swarm.rs | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/net/network/src/manager.rs b/crates/net/network/src/manager.rs index b630f28cdb..166cbbe7ad 100644 --- a/crates/net/network/src/manager.rs +++ b/crates/net/network/src/manager.rs @@ -658,7 +658,7 @@ where ?total_active, "Session established" ); - debug!(target: "net", peer_enode=%NodeRecord::new(remote_addr, peer_id), "Established peer enode"); + debug!(target: "net", kind=%direction, peer_enode=%NodeRecord::new(remote_addr, peer_id), "Established peer enode"); if direction.is_incoming() { this.swarm diff --git a/crates/net/network/src/session/mod.rs b/crates/net/network/src/session/mod.rs index 3337ae34c5..213dae70bd 100644 --- a/crates/net/network/src/session/mod.rs +++ b/crates/net/network/src/session/mod.rs @@ -693,6 +693,15 @@ impl Direction { } } +impl std::fmt::Display for Direction { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Direction::Incoming => write!(f, "incoming"), + Direction::Outgoing(_) => write!(f, "outgoing"), + } + } +} + /// The error thrown when the max configured limit has been reached and no more connections are /// accepted. #[derive(Debug, Clone, thiserror::Error)] diff --git a/crates/net/network/src/swarm.rs b/crates/net/network/src/swarm.rs index 9472ab0db3..32d635bdad 100644 --- a/crates/net/network/src/swarm.rs +++ b/crates/net/network/src/swarm.rs @@ -221,6 +221,7 @@ where match self.sessions.on_incoming(stream, remote_addr) { Ok(session_id) => { + trace!(target: "net", ?remote_addr, "Incoming connection"); return Some(SwarmEvent::IncomingTcpConnection { session_id, remote_addr }) } Err(err) => {