From 96d1f1496643f47fac765a1852e7e648649d08b3 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 21 Feb 2022 16:57:07 +0100 Subject: [PATCH] Avoid logging full node IDs --- src/client.rs | 7 ++++--- src/endpoint.rs | 2 +- src/netapp.rs | 16 ++++++++++------ src/peering/fullmesh.rs | 22 +++++++++++++--------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/client.rs b/src/client.rs index 27cd1b8..c9dbd02 100644 --- a/src/client.rs +++ b/src/client.rs @@ -79,10 +79,11 @@ impl ClientConn { read.read_exact(&mut their_version_tag[..]).await?; if their_version_tag != netapp.version_tag { let msg = format!( - "Different netapp versions: {:?} (theirs) vs. {:?} (ours)", - their_version_tag, netapp.version_tag + "different version tags: {} (theirs) vs. {} (ours)", + hex::encode(their_version_tag), + hex::encode(netapp.version_tag) ); - error!("{}", msg); + error!("Cannot connect to {}: {}", hex::encode(&peer_id[..8]), msg); return Err(Error::VersionMismatch(msg)); } diff --git a/src/endpoint.rs b/src/endpoint.rs index bb5399c..42e9a98 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -114,7 +114,7 @@ where match conn { None => Err(Error::Message(format!( "Not connected: {}", - hex::encode(target) + hex::encode(&target[..8]) ))), Some(c) => c.call(req, self.path.as_str(), prio).await, } diff --git a/src/netapp.rs b/src/netapp.rs index 1ac5f37..e9efa2e 100644 --- a/src/netapp.rs +++ b/src/netapp.rs @@ -307,7 +307,7 @@ impl NetApp { if let Some(c) = conn { debug!( "Closing connection to {} ({})", - hex::encode(c.peer_id), + hex::encode(&c.peer_id[..8]), c.remote_addr ); c.close(); @@ -334,7 +334,11 @@ impl NetApp { // has an actual IP address and port we can call them back on. // We will know this when they send a Hello message, which is handled below. pub(crate) fn connected_as_server(&self, id: NodeID, conn: Arc) { - info!("Accepted connection from {}", hex::encode(id)); + info!( + "Accepted connection from {} at {}", + hex::encode(&id[..8]), + conn.remote_addr + ); self.server_conns.write().unwrap().insert(id, conn); } @@ -349,7 +353,7 @@ impl NetApp { // We deregister the connection from server_conns and call the // handler registered by on_disconnected pub(crate) fn disconnected_as_server(&self, id: &NodeID, conn: Arc) { - info!("Connection from {} closed", hex::encode(id)); + info!("Connection from {} closed", hex::encode(&id[..8])); let mut conn_list = self.server_conns.write().unwrap(); if let Some(c) = conn_list.get(id) { @@ -372,7 +376,7 @@ impl NetApp { // they know on which port to call us back. (TODO: don't do this if we are // just a simple client and not a full p2p node) pub(crate) fn connected_as_client(&self, id: NodeID, conn: Arc) { - info!("Connection established to {}", hex::encode(id)); + info!("Connection established to {}", hex::encode(&id[..8])); { let old_c_opt = self.client_conns.write().unwrap().insert(id, conn.clone()); @@ -409,7 +413,7 @@ impl NetApp { // The connection is removed from conn_list, and the on_disconnected handler // is called. pub(crate) fn disconnected_as_client(&self, id: &NodeID, conn: Arc) { - info!("Connection to {} closed", hex::encode(id)); + info!("Connection to {} closed", hex::encode(&id[..8])); let mut conn_list = self.client_conns.write().unwrap(); if let Some(c) = conn_list.get(id) { if Arc::ptr_eq(c, &conn) { @@ -429,7 +433,7 @@ impl NetApp { #[async_trait] impl EndpointHandler for NetApp { async fn handle(self: &Arc, msg: &HelloMessage, from: NodeID) { - debug!("Hello from {:?}: {:?}", hex::encode(from), msg); + debug!("Hello from {:?}: {:?}", hex::encode(&from[..8]), msg); if let Some(h) = self.on_connected_handler.load().as_ref() { if let Some(c) = self.server_conns.read().unwrap().get(&from) { let remote_ip = msg.server_addr.unwrap_or_else(|| c.remote_addr.ip()); diff --git a/src/peering/fullmesh.rs b/src/peering/fullmesh.rs index cf10279..a5b2c3a 100644 --- a/src/peering/fullmesh.rs +++ b/src/peering/fullmesh.rs @@ -236,7 +236,7 @@ impl FullMeshPeeringStrategy { let mut to_ping = vec![]; let mut to_retry = vec![]; for (id, info) in known_hosts.list.iter() { - trace!("{}, {:?}", hex::encode(id), info); + trace!("{}, {:?}", hex::encode(&id[..8]), info); match info.state { PeerConnState::Connected => { let must_ping = match info.last_seen { @@ -273,7 +273,7 @@ impl FullMeshPeeringStrategy { if let PeerConnState::Waiting(i, _) = h.state { info!( "Retrying connection to {} at {} ({})", - hex::encode(&id), + hex::encode(&id[..8]), h.addr, i + 1 ); @@ -344,16 +344,16 @@ impl FullMeshPeeringStrategy { debug!( "Sending ping {} to {} at {:?}", ping_id, - hex::encode(id), + hex::encode(&id[..8]), ping_time ); match self.ping_endpoint.call(&id, &ping_msg, PRIO_HIGH).await { - Err(e) => warn!("Error pinging {}: {}", hex::encode(id), e), + Err(e) => warn!("Error pinging {}: {}", hex::encode(&id[..8]), e), Ok(ping_resp) => { let resp_time = Instant::now(); debug!( "Got ping response from {} at {:?}", - hex::encode(id), + hex::encode(&id[..8]), resp_time ); { @@ -409,7 +409,7 @@ impl FullMeshPeeringStrategy { async fn try_connect(self: Arc, id: NodeID, addr: SocketAddr) { let conn_result = self.netapp.clone().try_connect(addr, id).await; if let Err(e) = conn_result { - warn!("Error connecting to {}: {}", hex::encode(id), e); + warn!("Error connecting to {}: {}", hex::encode(&id[..8]), e); let mut known_hosts = self.known_hosts.write().unwrap(); if let Some(host) = known_hosts.list.get_mut(&id) { host.state = match host.state { @@ -438,7 +438,11 @@ impl FullMeshPeeringStrategy { self.update_public_peer_list(&known_hosts); } } else { - info!("Successfully connected to {} at {}", hex::encode(&id), addr); + info!( + "Successfully connected to {} at {}", + hex::encode(&id[..8]), + addr + ); let mut known_hosts = self.known_hosts.write().unwrap(); if let Some(host) = known_hosts.list.get_mut(&id) { host.state = PeerConnState::Connected; @@ -461,7 +465,7 @@ impl FullMeshPeeringStrategy { fn on_disconnected(self: Arc, id: NodeID, is_incoming: bool) { if !is_incoming { - info!("Connection to {} was closed", hex::encode(id)); + info!("Connection to {} was closed", hex::encode(&id[..8])); let mut known_hosts = self.known_hosts.write().unwrap(); if let Some(host) = known_hosts.list.get_mut(&id) { host.state = PeerConnState::Waiting(0, Instant::now()); @@ -493,7 +497,7 @@ impl EndpointHandler for FullMeshPeeringStrategy { id: ping.id, peer_list_hash: self.known_hosts.read().unwrap().hash, }; - debug!("Ping from {}", hex::encode(&from)); + debug!("Ping from {}", hex::encode(&from[..8])); ping_resp } }