Skip to content

Commit

Permalink
Merge pull request #2280 from subspace/extended-kademlia-logging
Browse files Browse the repository at this point in the history
Add Kademlia stats logging for subspace-networking crates.
  • Loading branch information
nazar-pc authored Nov 30, 2023
2 parents 184f45b + 8e587e0 commit 9766c32
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/subspace-networking/src/node_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ where
addresses.clear();
addresses.append(&mut external_addresses);
}

self.log_kademlia_stats();
}

fn handle_random_query_interval(&mut self) {
Expand Down Expand Up @@ -1645,4 +1647,23 @@ where
result_peers.retain(|(peer_id, _)| !bootstrap_nodes.contains(peer_id));
result_peers
}

fn log_kademlia_stats(&mut self) {
let mut peer_counter = 0;
let mut peer_with_no_address_counter = 0;
for kbucket in self.swarm.behaviour_mut().kademlia.kbuckets() {
for entry in kbucket.iter() {
peer_counter += 1;
if entry.node.value.len() == 0 {
peer_with_no_address_counter += 1;
}
}
}

debug!(
peers = %peer_counter,
peers_with_no_address = %peer_with_no_address_counter,
"Kademlia stats"
);
}
}

0 comments on commit 9766c32

Please sign in to comment.