Skip to content

Commit 16b8a79

Browse files
authored
Merge pull request #975 from subspace/dsn-wrong-peer-id
DSN. Handle WrongPeer connection error for libp2p.
2 parents bc50620 + 01c7a39 commit 16b8a79

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

crates/subspace-networking/src/node_runner.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,20 +348,29 @@ where
348348
} => {
349349
debug!("Connection closed with peer {peer_id} [{num_established} from peer]");
350350
}
351-
SwarmEvent::OutgoingConnectionError { peer_id, error } => {
352-
if let DialError::Transport(ref addresses) = error {
351+
SwarmEvent::OutgoingConnectionError { peer_id, error } => match error {
352+
DialError::Transport(ref addresses) => {
353353
for (addr, _) in addresses {
354-
debug!(?error, ?peer_id, %addr, "SwarmEvent::OutgoingConnectionError for peer.");
354+
debug!(?error, ?peer_id, %addr, "SwarmEvent::OutgoingConnectionError (DialError::Transport) for peer.");
355355
if let Some(peer_id) = peer_id {
356356
self.networking_parameters_registry
357357
.remove_known_peer_addresses(peer_id, vec![addr.clone()])
358358
.await;
359359
}
360360
}
361-
} else {
362-
trace!(?error, ?peer_id, "SwarmEvent::OutgoingConnectionError");
363361
}
364-
}
362+
DialError::WrongPeerId { obtained, .. } => {
363+
debug!(?error, ?peer_id, obtained_peer_id=?obtained, "SwarmEvent::WrongPeerId (DialError::WrongPeerId) for peer.");
364+
365+
if let Some(ref peer_id) = peer_id {
366+
let kademlia = &mut self.swarm.behaviour_mut().kademlia;
367+
let _ = kademlia.remove_peer(peer_id);
368+
}
369+
}
370+
_ => {
371+
debug!(?error, ?peer_id, "SwarmEvent::OutgoingConnectionError");
372+
}
373+
},
365374
other => {
366375
trace!("Other swarm event: {:?}", other);
367376
}

0 commit comments

Comments
 (0)