Skip to content

Commit

Permalink
fix(kad): prevent simultaneous dials to peer
Browse files Browse the repository at this point in the history
  • Loading branch information
b-zee committed Jul 20, 2023
1 parent b18c77e commit 2db5b98
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,9 @@ where
}
kbucket::InsertResult::Pending { disconnected } => {
self.queued_events.push_back(ToSwarm::Dial {
opts: DialOpts::peer_id(disconnected.into_preimage()).build(),
opts: DialOpts::peer_id(disconnected.into_preimage())
.condition(dial_opts::PeerCondition::NotDialing)
.build(),
});
RoutingUpdate::Pending
}
Expand Down Expand Up @@ -1306,6 +1308,7 @@ where
if !self.connected_peers.contains(disconnected.preimage()) {
self.queued_events.push_back(ToSwarm::Dial {
opts: DialOpts::peer_id(disconnected.into_preimage())
.condition(dial_opts::PeerCondition::NotDialing)
.build(),
})
}
Expand Down Expand Up @@ -2508,7 +2511,9 @@ where
} else if &peer_id != self.kbuckets.local_key().preimage() {
query.inner.pending_rpcs.push((peer_id, event));
self.queued_events.push_back(ToSwarm::Dial {
opts: DialOpts::peer_id(peer_id).build(),
opts: DialOpts::peer_id(peer_id)
.condition(dial_opts::PeerCondition::NotDialing)
.build(),
});
}
}
Expand Down

0 comments on commit 2db5b98

Please sign in to comment.