From 07f589158835151a7613e4b2a508c0dd61a18fd7 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Wed, 19 Jul 2023 11:11:06 -0600 Subject: [PATCH] Add CNetAddr::IsPrivacyNet() and CNode::IsConnectedThroughPrivacyNet() Co-authored-by: Vasil Dimov --- src/net.cpp | 5 +++++ src/net.h | 3 +++ src/netaddress.h | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/src/net.cpp b/src/net.cpp index 83440c2497..e1f3040485 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 54c3839fcc..8cf203b309 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 5e67d843e2..428ab87423 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. */