From c548cb388c3a784989d467893057f435d126a079 Mon Sep 17 00:00:00 2001 From: boqiu <82121246@qq.com> Date: Wed, 4 Dec 2024 16:12:32 +0800 Subject: [PATCH] refactor log --- node/router/src/libp2p_event_handler.rs | 16 ---------------- node/router/src/service.rs | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/node/router/src/libp2p_event_handler.rs b/node/router/src/libp2p_event_handler.rs index f4412c4..146d1fe 100644 --- a/node/router/src/libp2p_event_handler.rs +++ b/node/router/src/libp2p_event_handler.rs @@ -365,22 +365,6 @@ impl Libp2pEventHandler { self.on_find_chunks(msg).await } PubsubMessage::AnnounceFile(msgs) => { - let maybe_peer = self - .network_globals - .peers - .read() - .peer_info(&source) - .cloned(); - let ip = maybe_peer - .clone() - .map(|info| info.seen_ip_addresses().collect::>()); - let agent = maybe_peer - .clone() - .map(|info| info.client().agent_string.clone()); - let connection = maybe_peer.map(|info| info.connection_status().clone()); - - debug!(batch = %msgs.len(), %source, ?ip, ?agent, ?connection, "Received AnnounceFile pubsub message"); - metrics::LIBP2P_HANDLE_PUBSUB_ANNOUNCE_FILE.mark(1); for msg in msgs { diff --git a/node/router/src/service.rs b/node/router/src/service.rs index 1135bc7..847bcce 100644 --- a/node/router/src/service.rs +++ b/node/router/src/service.rs @@ -14,6 +14,7 @@ use network::{ use pruner::PrunerMessage; use shared_types::timestamp_now; use std::collections::HashMap; +use std::net::IpAddr; use std::sync::Arc; use std::time::Duration; use storage::log_store::Store as LogStore; @@ -235,6 +236,25 @@ impl RouterService { message, .. } => { + if matches!(message, PubsubMessage::AnnounceFile(..)) { + let maybe_peer = self + .network_globals + .peers + .read() + .peer_info(&source) + .cloned(); + + if let Some(peer) = maybe_peer { + let ip = peer.seen_ip_addresses().collect::>(); + let agent = peer.client().agent_string.clone(); + let connection = peer.connection_status().clone(); + let conn_dir = peer.connection_direction().cloned(); + debug!(%source, ?ip, ?agent, ?connection, ?conn_dir, "Received AnnounceFile pubsub message"); + } else { + debug!(%source, "Received AnnounceFile pubsub message, but not found in peer db"); + } + } + let result = self .libp2p_event_handler .on_pubsub_message(propagation_source, source, &id, message)