refactor log

This commit is contained in:
boqiu 2024-12-04 16:12:32 +08:00
parent 5b3946c363
commit c548cb388c
2 changed files with 20 additions and 16 deletions

View File

@ -365,22 +365,6 @@ impl Libp2pEventHandler {
self.on_find_chunks(msg).await self.on_find_chunks(msg).await
} }
PubsubMessage::AnnounceFile(msgs) => { 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::<Vec<IpAddr>>());
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); metrics::LIBP2P_HANDLE_PUBSUB_ANNOUNCE_FILE.mark(1);
for msg in msgs { for msg in msgs {

View File

@ -14,6 +14,7 @@ use network::{
use pruner::PrunerMessage; use pruner::PrunerMessage;
use shared_types::timestamp_now; use shared_types::timestamp_now;
use std::collections::HashMap; use std::collections::HashMap;
use std::net::IpAddr;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use storage::log_store::Store as LogStore; use storage::log_store::Store as LogStore;
@ -235,6 +236,25 @@ impl RouterService {
message, 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::<Vec<IpAddr>>();
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 let result = self
.libp2p_event_handler .libp2p_event_handler
.on_pubsub_message(propagation_source, source, &id, message) .on_pubsub_message(propagation_source, source, &id, message)