From 98355b6b88ab5cb8f033d1cfb9915876372c25c7 Mon Sep 17 00:00:00 2001 From: Benno Zeeman Date: Mon, 23 Oct 2023 14:39:05 +0200 Subject: [PATCH] keep peers in HashSet instead of SmallVec This prevents us from adding duplicates into the list of peer addresses we have. --- protocols/request-response/src/lib.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 04152f6d0d6..05a1b17e990 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -326,7 +326,7 @@ where /// reachable addresses, if any. connected: HashMap>, /// Externally managed addresses via `add_address` and `remove_address`. - addresses: HashMap>, + addresses: HashMap>, /// Requests that have not yet been sent and are waiting for a connection /// to be established. pending_outbound_requests: HashMap; 10]>>, @@ -441,15 +441,7 @@ where /// Returns true if the address was added, false otherwise (i.e. if the /// address is already in the list). pub fn add_address(&mut self, peer: &PeerId, address: Multiaddr) -> bool { - let addrs = self.addresses.entry(*peer).or_default(); - - // Add only if address is not already in the list. - if addrs.iter().all(|a| *a != address) { - addrs.push(address); - true - } else { - false - } + self.addresses.entry(*peer).or_default().insert(address) } /// Removes an address of a peer previously added via `add_address`.