From 44d1425e5c1df3f6f2c9e04730d51821e339df8f Mon Sep 17 00:00:00 2001 From: Davide Gessa Date: Thu, 7 Oct 2021 11:51:01 +0200 Subject: [PATCH] Replace is_global to is_private, maybe fixing #9922 (#9943) * replace is_global to is_private, maybe fixing #9922 * use of ip_network for private_ipv4 filtering * check is_global for both ip4 and ip6 * fix for rustfmt --- substrate/client/network/src/discovery.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/substrate/client/network/src/discovery.rs b/substrate/client/network/src/discovery.rs index 431de50c0f..1ed08cd671 100644 --- a/substrate/client/network/src/discovery.rs +++ b/substrate/client/network/src/discovery.rs @@ -512,14 +512,10 @@ impl NetworkBehaviour for DiscoveryBehaviour { list_to_filter.extend(self.mdns.addresses_of_peer(peer_id)); if !self.allow_private_ipv4 { - list_to_filter.retain(|addr| { - if let Some(Protocol::Ip4(addr)) = addr.iter().next() { - if addr.is_private() { - return false - } - } - - true + list_to_filter.retain(|addr| match addr.iter().next() { + Some(Protocol::Ip4(addr)) if !IpNetwork::from(addr).is_global() => false, + Some(Protocol::Ip6(addr)) if !IpNetwork::from(addr).is_global() => false, + _ => true, }); }