fix: get MAX_NODES_PER_BUCKET when respond closest (#6842)

This commit is contained in:
Matthias Seitz
2024-02-28 15:18:24 +01:00
committed by GitHub
parent 210d09023d
commit 0f26cd6df3

View File

@ -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 });