Skip to content

Commit

Permalink
Ignore observed external address if it is not global
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Nov 12, 2023
1 parent 0f65f43 commit 65401a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/subspace-networking/src/node_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::protocols::request_response::request_response_factory::{
};
use crate::shared::{Command, CreatedSubscription, NewPeerInfo, PeerDiscovered, Shared};
use crate::utils::rate_limiter::RateLimiterPermit;
use crate::utils::{is_global_address_or_dns, strip_peer_id, PeerAddress};
use crate::utils::{is_global_address, is_global_address_or_dns, strip_peer_id, PeerAddress};
use async_mutex::Mutex as AsyncMutex;
use bytes::Bytes;
use event_listener_primitives::HandlerId;
Expand Down Expand Up @@ -764,7 +764,9 @@ where
kademlia.remove_peer(&peer_id);
}

self.add_observed_external_address(info.observed_addr);
if self.allow_non_global_addresses_in_dht || is_global_address(&info.observed_addr) {
self.add_observed_external_address(info.observed_addr);
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions crates/subspace-networking/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ impl<T> Future for AsyncJoinOnDrop<T> {
}
}

/// This test is successful only for global IP addresses.
pub(crate) fn is_global_address(addr: &Multiaddr) -> bool {
match addr.iter().next() {
Some(Protocol::Ip4(ip)) => ip.is_global(),
Some(Protocol::Ip6(ip)) => ip.is_global(),
_ => false,
}
}

/// This test is successful only for global IP addresses and DNS names.
pub(crate) fn is_global_address_or_dns(addr: &Multiaddr) -> bool {
match addr.iter().next() {
Expand Down

0 comments on commit 65401a4

Please sign in to comment.