diff options
author | Martin Zumsande <mzumsande@gmail.com> | 2023-04-11 16:10:28 -0400 |
---|---|---|
committer | Martin Zumsande <mzumsande@gmail.com> | 2023-06-05 11:02:47 -0400 |
commit | e4d541c7cfa65da77e80e6786fdcb197ab50d04b (patch) | |
tree | 71de84b3ae920e10dbeb34612aa9a0dfa8ae2d9e /src/netaddress.cpp | |
parent | 62d73f5370415f910c95a67b3d9f97bc85487bbe (diff) |
net, refactor: pass reference for peer address in GetReachabilityFrom
The address of the peer always exists (because addr is a member of
CNode), so it was not possible to pass a nullptr before.
Also remove NET_UNKNOWN, which is unused now.
Diffstat (limited to 'src/netaddress.cpp')
-rw-r--r-- | src/netaddress.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
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) { |