core: remove duplicates when performing address translation (#1697)

* core: remove duplicates when performing address translation

* core: use filter_map instead of flat_map

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
This commit is contained in:
André Silva
2020-08-24 09:46:54 +01:00
committed by GitHub
parent 0b05b21093
commit b601ed41b1

View File

@ -205,7 +205,15 @@ where
TMuxer: 'a, TMuxer: 'a,
THandler: 'a, THandler: 'a,
{ {
self.listen_addrs().flat_map(move |server| address_translation(server, observed_addr)) let mut addrs: Vec<_> = self.listen_addrs()
.filter_map(move |server| address_translation(server, observed_addr))
.collect();
// remove duplicates
addrs.sort_unstable();
addrs.dedup();
addrs.into_iter()
} }
/// Returns the peer id of the local node. /// Returns the peer id of the local node.