Skip to content

Commit

Permalink
fix: get MAX_NODES_PER_BUCKET when respond closest (paradigmxyz#6842)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Feb 28, 2024
1 parent 210d090 commit 0f26cd6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/net/discv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,9 +1378,12 @@ impl Discv4Service {
fn respond_closest(&mut self, target: PeerId, to: SocketAddr) {
let key = kad_key(target);
let expire = self.send_neighbours_expiration();
let all_nodes = self.kbuckets.closest_values(&key).collect::<Vec<_>>();

for nodes in all_nodes.chunks(SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS) {
// get the MAX_NODES_PER_BUCKET closest nodes to the target
let closest_nodes =
self.kbuckets.closest_values(&key).take(MAX_NODES_PER_BUCKET).collect::<Vec<_>>();

for nodes in closest_nodes.chunks(SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS) {
let nodes = nodes.iter().map(|node| node.value.record).collect::<Vec<NodeRecord>>();
trace!(target: "discv4", len = nodes.len(), to=?to,"Sent neighbours packet");
let msg = Message::Neighbours(Neighbours { nodes, expire });
Expand Down

0 comments on commit 0f26cd6

Please sign in to comment.