Avoid logging full node IDs
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Alex 2022-02-21 16:57:07 +01:00
parent 8858c94289
commit 96d1f14966
Signed by: lx
GPG key ID: 0E496D15096376BE
4 changed files with 28 additions and 19 deletions

View file

@ -79,10 +79,11 @@ impl ClientConn {
read.read_exact(&mut their_version_tag[..]).await?; read.read_exact(&mut their_version_tag[..]).await?;
if their_version_tag != netapp.version_tag { if their_version_tag != netapp.version_tag {
let msg = format!( let msg = format!(
"Different netapp versions: {:?} (theirs) vs. {:?} (ours)", "different version tags: {} (theirs) vs. {} (ours)",
their_version_tag, netapp.version_tag 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)); return Err(Error::VersionMismatch(msg));
} }

View file

@ -114,7 +114,7 @@ where
match conn { match conn {
None => Err(Error::Message(format!( None => Err(Error::Message(format!(
"Not connected: {}", "Not connected: {}",
hex::encode(target) hex::encode(&target[..8])
))), ))),
Some(c) => c.call(req, self.path.as_str(), prio).await, Some(c) => c.call(req, self.path.as_str(), prio).await,
} }

View file

@ -307,7 +307,7 @@ impl NetApp {
if let Some(c) = conn { if let Some(c) = conn {
debug!( debug!(
"Closing connection to {} ({})", "Closing connection to {} ({})",
hex::encode(c.peer_id), hex::encode(&c.peer_id[..8]),
c.remote_addr c.remote_addr
); );
c.close(); c.close();
@ -334,7 +334,11 @@ impl NetApp {
// has an actual IP address and port we can call them back on. // 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. // 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<ServerConn>) { pub(crate) fn connected_as_server(&self, id: NodeID, conn: Arc<ServerConn>) {
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); self.server_conns.write().unwrap().insert(id, conn);
} }
@ -349,7 +353,7 @@ impl NetApp {
// We deregister the connection from server_conns and call the // We deregister the connection from server_conns and call the
// handler registered by on_disconnected // handler registered by on_disconnected
pub(crate) fn disconnected_as_server(&self, id: &NodeID, conn: Arc<ServerConn>) { pub(crate) fn disconnected_as_server(&self, id: &NodeID, conn: Arc<ServerConn>) {
info!("Connection from {} closed", hex::encode(id)); info!("Connection from {} closed", hex::encode(&id[..8]));
let mut conn_list = self.server_conns.write().unwrap(); let mut conn_list = self.server_conns.write().unwrap();
if let Some(c) = conn_list.get(id) { 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 // 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) // just a simple client and not a full p2p node)
pub(crate) fn connected_as_client(&self, id: NodeID, conn: Arc<ClientConn>) { pub(crate) fn connected_as_client(&self, id: NodeID, conn: Arc<ClientConn>) {
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()); 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 // The connection is removed from conn_list, and the on_disconnected handler
// is called. // is called.
pub(crate) fn disconnected_as_client(&self, id: &NodeID, conn: Arc<ClientConn>) { pub(crate) fn disconnected_as_client(&self, id: &NodeID, conn: Arc<ClientConn>) {
info!("Connection to {} closed", hex::encode(id)); info!("Connection to {} closed", hex::encode(&id[..8]));
let mut conn_list = self.client_conns.write().unwrap(); let mut conn_list = self.client_conns.write().unwrap();
if let Some(c) = conn_list.get(id) { if let Some(c) = conn_list.get(id) {
if Arc::ptr_eq(c, &conn) { if Arc::ptr_eq(c, &conn) {
@ -429,7 +433,7 @@ impl NetApp {
#[async_trait] #[async_trait]
impl EndpointHandler<HelloMessage> for NetApp { impl EndpointHandler<HelloMessage> for NetApp {
async fn handle(self: &Arc<Self>, msg: &HelloMessage, from: NodeID) { async fn handle(self: &Arc<Self>, 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(h) = self.on_connected_handler.load().as_ref() {
if let Some(c) = self.server_conns.read().unwrap().get(&from) { if let Some(c) = self.server_conns.read().unwrap().get(&from) {
let remote_ip = msg.server_addr.unwrap_or_else(|| c.remote_addr.ip()); let remote_ip = msg.server_addr.unwrap_or_else(|| c.remote_addr.ip());

View file

@ -236,7 +236,7 @@ impl FullMeshPeeringStrategy {
let mut to_ping = vec![]; let mut to_ping = vec![];
let mut to_retry = vec![]; let mut to_retry = vec![];
for (id, info) in known_hosts.list.iter() { for (id, info) in known_hosts.list.iter() {
trace!("{}, {:?}", hex::encode(id), info); trace!("{}, {:?}", hex::encode(&id[..8]), info);
match info.state { match info.state {
PeerConnState::Connected => { PeerConnState::Connected => {
let must_ping = match info.last_seen { let must_ping = match info.last_seen {
@ -273,7 +273,7 @@ impl FullMeshPeeringStrategy {
if let PeerConnState::Waiting(i, _) = h.state { if let PeerConnState::Waiting(i, _) = h.state {
info!( info!(
"Retrying connection to {} at {} ({})", "Retrying connection to {} at {} ({})",
hex::encode(&id), hex::encode(&id[..8]),
h.addr, h.addr,
i + 1 i + 1
); );
@ -344,16 +344,16 @@ impl FullMeshPeeringStrategy {
debug!( debug!(
"Sending ping {} to {} at {:?}", "Sending ping {} to {} at {:?}",
ping_id, ping_id,
hex::encode(id), hex::encode(&id[..8]),
ping_time ping_time
); );
match self.ping_endpoint.call(&id, &ping_msg, PRIO_HIGH).await { 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) => { Ok(ping_resp) => {
let resp_time = Instant::now(); let resp_time = Instant::now();
debug!( debug!(
"Got ping response from {} at {:?}", "Got ping response from {} at {:?}",
hex::encode(id), hex::encode(&id[..8]),
resp_time resp_time
); );
{ {
@ -409,7 +409,7 @@ impl FullMeshPeeringStrategy {
async fn try_connect(self: Arc<Self>, id: NodeID, addr: SocketAddr) { async fn try_connect(self: Arc<Self>, id: NodeID, addr: SocketAddr) {
let conn_result = self.netapp.clone().try_connect(addr, id).await; let conn_result = self.netapp.clone().try_connect(addr, id).await;
if let Err(e) = conn_result { 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(); let mut known_hosts = self.known_hosts.write().unwrap();
if let Some(host) = known_hosts.list.get_mut(&id) { if let Some(host) = known_hosts.list.get_mut(&id) {
host.state = match host.state { host.state = match host.state {
@ -438,7 +438,11 @@ impl FullMeshPeeringStrategy {
self.update_public_peer_list(&known_hosts); self.update_public_peer_list(&known_hosts);
} }
} else { } 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(); let mut known_hosts = self.known_hosts.write().unwrap();
if let Some(host) = known_hosts.list.get_mut(&id) { if let Some(host) = known_hosts.list.get_mut(&id) {
host.state = PeerConnState::Connected; host.state = PeerConnState::Connected;
@ -461,7 +465,7 @@ impl FullMeshPeeringStrategy {
fn on_disconnected(self: Arc<Self>, id: NodeID, is_incoming: bool) { fn on_disconnected(self: Arc<Self>, id: NodeID, is_incoming: bool) {
if !is_incoming { 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(); let mut known_hosts = self.known_hosts.write().unwrap();
if let Some(host) = known_hosts.list.get_mut(&id) { if let Some(host) = known_hosts.list.get_mut(&id) {
host.state = PeerConnState::Waiting(0, Instant::now()); host.state = PeerConnState::Waiting(0, Instant::now());
@ -493,7 +497,7 @@ impl EndpointHandler<PingMessage> for FullMeshPeeringStrategy {
id: ping.id, id: ping.id,
peer_list_hash: self.known_hosts.read().unwrap().hash, peer_list_hash: self.known_hosts.read().unwrap().hash,
}; };
debug!("Ping from {}", hex::encode(&from)); debug!("Ping from {}", hex::encode(&from[..8]));
ping_resp ping_resp
} }
} }