Use existing peer count metrics loop to check for open_nat toggle (#6800)

* implement update_nat_open function in network_behaviour for tracking incoming peers below a given threshold count

* implement update_nat_open function in network_behaviour for tracking incoming peers below a given threshold count

* tidy logic and comments

* move logic to existing metrics loop

* revert change to network_behaviour protocol check

* clippy

* clippy matches! macro

* pull nat_open check outside of peercounting loop

* missing close bracket

* make threshold const
This commit is contained in:
jking-aus
2025-01-15 14:53:40 +11:00
committed by GitHub
parent 587c3e2b8c
commit 4fd8e521a4
2 changed files with 48 additions and 3 deletions

View File

@@ -122,6 +122,24 @@ impl<E: EthSpec> PeerInfo<E> {
self.connection_direction.as_ref()
}
/// Returns true if this is an incoming ipv4 connection.
pub fn is_incoming_ipv4_connection(&self) -> bool {
self.seen_multiaddrs.iter().any(|multiaddr| {
multiaddr
.iter()
.any(|protocol| matches!(protocol, libp2p::core::multiaddr::Protocol::Ip4(_)))
})
}
/// Returns true if this is an incoming ipv6 connection.
pub fn is_incoming_ipv6_connection(&self) -> bool {
self.seen_multiaddrs.iter().any(|multiaddr| {
multiaddr
.iter()
.any(|protocol| matches!(protocol, libp2p::core::multiaddr::Protocol::Ip6(_)))
})
}
/// Returns the sync status of the peer.
pub fn sync_status(&self) -> &SyncStatus {
&self.sync_status