mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 15:32:34 +02:00
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.
This commit is contained in:
parent
62d73f5370
commit
e4d541c7cf
@ -165,7 +165,7 @@ bool GetLocal(CService& addr, const CNode& peer)
|
|||||||
for (const auto& entry : mapLocalHost)
|
for (const auto& entry : mapLocalHost)
|
||||||
{
|
{
|
||||||
int nScore = entry.second.nScore;
|
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))
|
if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore))
|
||||||
{
|
{
|
||||||
addr = CService(entry.first, entry.second.nPort);
|
addr = CService(entry.first, entry.second.nPort);
|
||||||
|
@ -723,19 +723,16 @@ std::vector<unsigned char> CNetAddr::GetAddrBytes() const
|
|||||||
|
|
||||||
// private extensions to enum Network, only returned by GetExtNetwork,
|
// private extensions to enum Network, only returned by GetExtNetwork,
|
||||||
// and only used in GetReachabilityFrom
|
// and only used in GetReachabilityFrom
|
||||||
static const int NET_UNKNOWN = NET_MAX + 0;
|
static const int NET_TEREDO = NET_MAX;
|
||||||
static const int NET_TEREDO = NET_MAX + 1;
|
int static GetExtNetwork(const CNetAddr& addr)
|
||||||
int static GetExtNetwork(const CNetAddr *addr)
|
|
||||||
{
|
{
|
||||||
if (addr == nullptr)
|
if (addr.IsRFC4380())
|
||||||
return NET_UNKNOWN;
|
|
||||||
if (addr->IsRFC4380())
|
|
||||||
return NET_TEREDO;
|
return NET_TEREDO;
|
||||||
return addr->GetNetwork();
|
return addr.GetNetwork();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Calculates a metric for how reachable (*this) is from a given partner */
|
/** 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 {
|
enum Reachability {
|
||||||
REACH_UNREACHABLE,
|
REACH_UNREACHABLE,
|
||||||
@ -750,7 +747,7 @@ int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const
|
|||||||
if (!IsRoutable() || IsInternal())
|
if (!IsRoutable() || IsInternal())
|
||||||
return REACH_UNREACHABLE;
|
return REACH_UNREACHABLE;
|
||||||
|
|
||||||
int ourNet = GetExtNetwork(this);
|
int ourNet = GetExtNetwork(*this);
|
||||||
int theirNet = GetExtNetwork(paddrPartner);
|
int theirNet = GetExtNetwork(paddrPartner);
|
||||||
bool fTunnel = IsRFC3964() || IsRFC6052() || IsRFC6145();
|
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_IPV6: return REACH_IPV6_WEAK;
|
||||||
case NET_IPV4: return REACH_IPV4;
|
case NET_IPV4: return REACH_IPV4;
|
||||||
}
|
}
|
||||||
case NET_UNKNOWN:
|
|
||||||
case NET_UNROUTABLE:
|
case NET_UNROUTABLE:
|
||||||
default:
|
default:
|
||||||
switch(ourNet) {
|
switch(ourNet) {
|
||||||
|
@ -203,7 +203,7 @@ public:
|
|||||||
bool HasLinkedIPv4() const;
|
bool HasLinkedIPv4() const;
|
||||||
|
|
||||||
std::vector<unsigned char> GetAddrBytes() 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);
|
explicit CNetAddr(const struct in6_addr& pipv6Addr, const uint32_t scope = 0);
|
||||||
bool GetIn6Addr(struct in6_addr* pipv6Addr) const;
|
bool GetIn6Addr(struct in6_addr* pipv6Addr) const;
|
||||||
|
@ -84,7 +84,7 @@ FUZZ_TARGET(netaddress)
|
|||||||
(void)CServiceHash(0, 0)(service);
|
(void)CServiceHash(0, 0)(service);
|
||||||
|
|
||||||
const CNetAddr other_net_addr = ConsumeNetAddr(fuzzed_data_provider);
|
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);
|
(void)sub_net.Match(other_net_addr);
|
||||||
|
|
||||||
const CService other_service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
|
const CService other_service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
|
||||||
|
Loading…
Reference in New Issue
Block a user