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:
Pierre Krieger 2018-12-04 14:05:05 +01:00 committed by GitHub
parent 10d76d64d0
commit 57ebe697b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.