Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent concurrent dials #255

Merged
merged 2 commits into from May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions safenode/src/network/cmd.rs
Expand Up @@ -112,21 +112,30 @@ impl SwarmDriver {
peer_addr,
sender,
} => {
if let hash_map::Entry::Vacant(e) = self.pending_dial.entry(peer_id) {
let mut dial_error = None;
if let hash_map::Entry::Vacant(dial_entry) = self.pending_dial.entry(peer_id) {
// immediately write to the pending dial hashmap, as dials can take time,
// if we wait until its done more may be in flight
let _ = dial_entry.insert(sender);
match self
.swarm
.dial(peer_addr.with(Protocol::P2p(peer_id.into())))
{
Ok(()) => {
let _ = e.insert(sender);
}
Ok(()) => {}
Err(e) => {
let _ = sender.send(Err(e.into()));
dial_error = Some(e);
}
}
} else {
let _ = sender.send(Err(Error::AlreadyDialingPeer(peer_id)));
}

// let's inform of our error if we have one
if let Some(error) = dial_error {
if let Some(sender) = self.pending_dial.remove(&peer_id) {
let _ = sender.send(Err(error.into()));
}
}
}

SwarmCmd::GetClosestPeers { xor_name, sender } => {
Expand Down
2 changes: 1 addition & 1 deletion safenode/src/network/event.rs
Expand Up @@ -195,8 +195,8 @@ impl SwarmDriver {
info!("IdentifyEvent: {iden:?}");
match *iden {
libp2p::identify::Event::Received { peer_id, info } => {
info!("Adding peer to routing table, based on received identify info from {peer_id:?}: {info:?}");
if info.agent_version.starts_with(IDENTIFY_AGENT_STR) {
info!("Adding peer to routing table, based on received identify info from {peer_id:?}: {info:?}");
for multiaddr in info.listen_addrs {
let _routing_update = self
.swarm
Expand Down