Skip to content

Commit 07f5891

Browse files
jonatackvasild
andcommitted
Add CNetAddr::IsPrivacyNet() and CNode::IsConnectedThroughPrivacyNet()
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
1 parent df48856 commit 07f5891

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/net.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,11 @@ Network CNode::ConnectedThroughNetwork() const
620620
return m_inbound_onion ? NET_ONION : addr.GetNetClass();
621621
}
622622

623+
bool CNode::IsConnectedThroughPrivacyNet() const
624+
{
625+
return m_inbound_onion || addr.IsPrivacyNet();
626+
}
627+
623628
#undef X
624629
#define X(name) stats.name = name
625630
void CNode::CopyStats(CNodeStats& stats)

src/net.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ class CNode
506506
*/
507507
Network ConnectedThroughNetwork() const;
508508

509+
/** Whether this peer connected through a privacy network. */
510+
[[nodiscard]] bool IsConnectedThroughPrivacyNet() const;
511+
509512
// We selected peer as (compact blocks) high-bandwidth peer (BIP152)
510513
std::atomic<bool> m_bip152_highbandwidth_to{false};
511514
// Peer selected us as (compact blocks) high-bandwidth peer (BIP152)

src/netaddress.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ class CNetAddr
188188
bool IsInternal() const;
189189
bool IsValid() const;
190190

191+
/**
192+
* Whether this object is a privacy network.
193+
* TODO: consider adding IsCJDNS() here when more peers adopt CJDNS, see:
194+
* https://github.com/bitcoin/bitcoin/pull/27411#issuecomment-1497176155
195+
*/
196+
[[nodiscard]] bool IsPrivacyNet() const { return IsTor() || IsI2P(); }
197+
191198
/**
192199
* Check if the current object can be serialized in pre-ADDRv2/BIP155 format.
193200
*/

0 commit comments

Comments
 (0)