From 57ebe697b51cb6f28cfbcda0f537de37d284dfa8 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 4 Dec 2018 14:05:05 +0100 Subject: [PATCH] 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 --- core/src/topology/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/topology/mod.rs b/core/src/topology/mod.rs index f6cebb82..a360a5ef 100644 --- a/core/src/topology/mod.rs +++ b/core/src/topology/mod.rs @@ -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.