mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-06 06:31:22 +00:00
Fix logic error in public key mismatch (#510)
This commit is contained in:
parent
b61d9faece
commit
4fe92f81e8
@ -499,19 +499,21 @@ where
|
|||||||
|
|
||||||
// If in neither, check outgoing reach attempts again as we may have a public
|
// If in neither, check outgoing reach attempts again as we may have a public
|
||||||
// key mismatch.
|
// key mismatch.
|
||||||
let wrong_peer_id = self
|
let expected_peer_id = self
|
||||||
.out_reach_attempts
|
.out_reach_attempts
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_, a)| a.id == reach_id)
|
.find(|(_, a)| a.id == reach_id)
|
||||||
.map(|(p, _)| p.clone());
|
.map(|(p, _)| p.clone());
|
||||||
if let Some(wrong_peer_id) = wrong_peer_id {
|
if let Some(expected_peer_id) = expected_peer_id {
|
||||||
let attempt = self.out_reach_attempts.remove(&wrong_peer_id)
|
let attempt = self.out_reach_attempts.remove(&expected_peer_id)
|
||||||
.expect("wrong_peer_id is a key that is grabbed from out_reach_attempts");
|
.expect("expected_peer_id is a key that is grabbed from out_reach_attempts");
|
||||||
|
|
||||||
let num_remain = attempt.next_attempts.len();
|
let num_remain = attempt.next_attempts.len();
|
||||||
let failed_addr = attempt.cur_attempted.clone();
|
let failed_addr = attempt.cur_attempted.clone();
|
||||||
|
|
||||||
// Note: at the moment, a peer id mismatch can drop a legitimate connection, which is
|
// Since the `peer_id` (the unexpected peer id) is now successfully connected, we have
|
||||||
|
// to drop it from active_nodes.
|
||||||
|
// TODO: at the moment, a peer id mismatch can drop a legitimate connection, which is
|
||||||
// why we have to purge `connected_multiaddresses`.
|
// why we have to purge `connected_multiaddresses`.
|
||||||
// See https://github.com/libp2p/rust-libp2p/issues/502
|
// See https://github.com/libp2p/rust-libp2p/issues/502
|
||||||
self.connected_multiaddresses.remove(&peer_id);
|
self.connected_multiaddresses.remove(&peer_id);
|
||||||
@ -534,13 +536,13 @@ where
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
self.out_reach_attempts.insert(peer_id.clone(), attempt);
|
self.out_reach_attempts.insert(expected_peer_id.clone(), attempt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SwarmEvent::PublicKeyMismatch {
|
return SwarmEvent::PublicKeyMismatch {
|
||||||
remain_addrs_attempt: num_remain,
|
remain_addrs_attempt: num_remain,
|
||||||
expected_peer_id: peer_id,
|
expected_peer_id,
|
||||||
actual_peer_id: wrong_peer_id,
|
actual_peer_id: peer_id,
|
||||||
multiaddr: failed_addr,
|
multiaddr: failed_addr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user