mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-30 13:12:15 +00:00
Don't add an address to the topology if it is already in (#724)
* Don't add an address to the topology if it is already in * Update core/src/topology/mod.rs Co-Authored-By: tomaka <pierre.krieger1708@gmail.com>
This commit is contained in:
parent
10d76d64d0
commit
57ebe697b5
@ -50,7 +50,10 @@ impl MemoryTopology {
|
||||
/// Adds an address to the topology.
|
||||
#[inline]
|
||||
pub fn add_address(&mut self, peer: PeerId, addr: Multiaddr) {
|
||||
self.list.entry(peer).or_insert_with(|| Vec::new()).push(addr);
|
||||
let addrs = self.list.entry(peer).or_insert_with(|| Vec::new());
|
||||
if addrs.iter().all(|a| a != &addr) {
|
||||
addrs.push(addr);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a list of all the known peers in the topology.
|
||||
|
Loading…
x
Reference in New Issue
Block a user