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
This commit is contained in:
Davide Gessa
2021-10-07 11:51:01 +02:00
committed by GitHub
parent e6ff531d0b
commit 44d1425e5c
+4 -8
View File
@@ -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,
});
}