diff --git a/src/net.cpp b/src/net.cpp index 83440c2497f..e1f3040485e 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -620,6 +620,11 @@ Network CNode::ConnectedThroughNetwork() const return m_inbound_onion ? NET_ONION : addr.GetNetClass(); } +bool CNode::IsConnectedThroughPrivacyNet() const +{ + return m_inbound_onion || addr.IsPrivacyNet(); +} + #undef X #define X(name) stats.name = name void CNode::CopyStats(CNodeStats& stats) diff --git a/src/net.h b/src/net.h index 54c3839fcc9..8cf203b309e 100644 --- a/src/net.h +++ b/src/net.h @@ -506,6 +506,9 @@ public: */ Network ConnectedThroughNetwork() const; + /** Whether this peer connected through a privacy network. */ + [[nodiscard]] bool IsConnectedThroughPrivacyNet() const; + // We selected peer as (compact blocks) high-bandwidth peer (BIP152) std::atomic m_bip152_highbandwidth_to{false}; // Peer selected us as (compact blocks) high-bandwidth peer (BIP152) diff --git a/src/netaddress.h b/src/netaddress.h index 5e67d843e25..428ab87423b 100644 --- a/src/netaddress.h +++ b/src/netaddress.h @@ -188,6 +188,13 @@ public: bool IsInternal() const; bool IsValid() const; + /** + * Whether this object is a privacy network. + * TODO: consider adding IsCJDNS() here when more peers adopt CJDNS, see: + * https://github.com/bitcoin/bitcoin/pull/27411#issuecomment-1497176155 + */ + [[nodiscard]] bool IsPrivacyNet() const { return IsTor() || IsI2P(); } + /** * Check if the current object can be serialized in pre-ADDRv2/BIP155 format. */