Skip to content

Commit

Permalink
kad: Include peers that are also not connected to the query
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv committed Apr 18, 2024
1 parent 96e827b commit 200a0fd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/protocol/libp2p/kademlia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,14 +743,15 @@ impl Kademlia {

let key = Key::new(record.key.clone());


if let Some(peers) = peers {
// Put the record to the specified peers.
let peers: VecDeque<_> = peers.into_iter().filter_map(|peer| {
if let KBucketEntry::Occupied(entry) = self.routing_table.entry(Key::from(peer)) {
Some(entry.clone())
} else {
None
match self.routing_table.entry(Key::from(peer)) {
// The routing table contains information about the peer address when:
// - Occupied: Established connection
// - Vacant: We'll try to establish the connection later, but the address is known.
KBucketEntry::Occupied(entry) | KBucketEntry::Vacant(entry) => Some(entry.clone()),
_ => None,
}
}).collect();

Expand Down

0 comments on commit 200a0fd

Please sign in to comment.