From fb4265747c9eb022d80c6f2988e574c689130348 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Fri, 14 Jul 2023 10:48:30 -0600 Subject: [PATCH] Add and use CNetAddr::HasCJDNSPrefix() helper --- src/net.cpp | 2 +- src/netaddress.cpp | 3 +-- src/netaddress.h | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 654e0ac9fd..d76874b233 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -275,7 +275,7 @@ std::optional GetLocalAddrForPeer(CNode& node) CService MaybeFlipIPv6toCJDNS(const CService& service) { CService ret{service}; - if (ret.m_net == NET_IPV6 && ret.m_addr[0] == 0xfc && IsReachable(NET_CJDNS)) { + if (ret.m_net == NET_IPV6 && ret.HasCJDNSPrefix() && IsReachable(NET_CJDNS)) { ret.m_net = NET_CJDNS; } return ret; diff --git a/src/netaddress.cpp b/src/netaddress.cpp index 4758f24680..8196a6a48c 100644 --- a/src/netaddress.cpp +++ b/src/netaddress.cpp @@ -450,8 +450,7 @@ bool CNetAddr::IsValid() const return false; } - // CJDNS addresses always start with 0xfc - if (IsCJDNS() && (m_addr[0] != 0xFC)) { + if (IsCJDNS() && !HasCJDNSPrefix()) { return false; } diff --git a/src/netaddress.h b/src/netaddress.h index 36dc886406..5e67d843e2 100644 --- a/src/netaddress.h +++ b/src/netaddress.h @@ -182,6 +182,7 @@ public: bool IsTor() const; bool IsI2P() const; bool IsCJDNS() const; + [[nodiscard]] bool HasCJDNSPrefix() const { return m_addr[0] == 0xfc; } bool IsLocal() const; bool IsRoutable() const; bool IsInternal() const;