aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/net.cpp2
-rw-r--r--src/netaddress.cpp16
-rw-r--r--src/netaddress.h2
-rw-r--r--src/test/fuzz/netaddress.cpp2
4 files changed, 9 insertions, 13 deletions
diff --git a/src/net.cpp b/src/net.cpp
index ab0d34fc63..9379f5be78 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -165,7 +165,7 @@ bool GetLocal(CService& addr, const CNode& peer)
for (const auto& entry : mapLocalHost)
{
int nScore = entry.second.nScore;
- int nReachability = entry.first.GetReachabilityFrom(&peer.addr);
+ int nReachability = entry.first.GetReachabilityFrom(peer.addr);
if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore))
{
addr = CService(entry.first, entry.second.nPort);
diff --git a/src/netaddress.cpp b/src/netaddress.cpp
index 85ae8fab36..4758f24680 100644
--- a/src/netaddress.cpp
+++ b/src/netaddress.cpp
@@ -723,19 +723,16 @@ std::vector<unsigned char> CNetAddr::GetAddrBytes() const
// private extensions to enum Network, only returned by GetExtNetwork,
// and only used in GetReachabilityFrom
-static const int NET_UNKNOWN = NET_MAX + 0;
-static const int NET_TEREDO = NET_MAX + 1;
-int static GetExtNetwork(const CNetAddr *addr)
+static const int NET_TEREDO = NET_MAX;
+int static GetExtNetwork(const CNetAddr& addr)
{
- if (addr == nullptr)
- return NET_UNKNOWN;
- if (addr->IsRFC4380())
+ if (addr.IsRFC4380())
return NET_TEREDO;
- return addr->GetNetwork();
+ return addr.GetNetwork();
}
/** Calculates a metric for how reachable (*this) is from a given partner */
-int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const
+int CNetAddr::GetReachabilityFrom(const CNetAddr& paddrPartner) const
{
enum Reachability {
REACH_UNREACHABLE,
@@ -750,7 +747,7 @@ int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const
if (!IsRoutable() || IsInternal())
return REACH_UNREACHABLE;
- int ourNet = GetExtNetwork(this);
+ int ourNet = GetExtNetwork(*this);
int theirNet = GetExtNetwork(paddrPartner);
bool fTunnel = IsRFC3964() || IsRFC6052() || IsRFC6145();
@@ -790,7 +787,6 @@ int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const
case NET_IPV6: return REACH_IPV6_WEAK;
case NET_IPV4: return REACH_IPV4;
}
- case NET_UNKNOWN:
case NET_UNROUTABLE:
default:
switch(ourNet) {
diff --git a/src/netaddress.h b/src/netaddress.h
index 3d15b0b123..36dc886406 100644
--- a/src/netaddress.h
+++ b/src/netaddress.h
@@ -203,7 +203,7 @@ public:
bool HasLinkedIPv4() const;
std::vector<unsigned char> GetAddrBytes() const;
- int GetReachabilityFrom(const CNetAddr* paddrPartner = nullptr) const;
+ int GetReachabilityFrom(const CNetAddr& paddrPartner) const;
explicit CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
bool GetIn6Addr(struct in6_addr* pipv6Addr) const;
diff --git a/src/test/fuzz/netaddress.cpp b/src/test/fuzz/netaddress.cpp
index 049ae02f4d..5141d3362d 100644
--- a/src/test/fuzz/netaddress.cpp
+++ b/src/test/fuzz/netaddress.cpp
@@ -84,7 +84,7 @@ FUZZ_TARGET(netaddress)
(void)CServiceHash(0, 0)(service);
const CNetAddr other_net_addr = ConsumeNetAddr(fuzzed_data_provider);
- (void)net_addr.GetReachabilityFrom(&other_net_addr);
+ (void)net_addr.GetReachabilityFrom(other_net_addr);
(void)sub_net.Match(other_net_addr);
const CService other_service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};