From 62d73f5370415f910c95a67b3d9f97bc85487bbe Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Tue, 11 Apr 2023 15:09:31 -0400 Subject: net, refactor: pass CNode instead of CNetAddr to GetLocalAddress Access to CNode will be needed in the following commits. --- src/net.cpp | 10 +++++----- src/net.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index a53835f999..ab0d34fc63 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -153,7 +153,7 @@ uint16_t GetListenPort() } // find 'best' local address for a particular peer -bool GetLocal(CService& addr, const CNetAddr *paddrPeer) +bool GetLocal(CService& addr, const CNode& peer) { if (!fListen) return false; @@ -165,7 +165,7 @@ bool GetLocal(CService& addr, const CNetAddr *paddrPeer) for (const auto& entry : mapLocalHost) { int nScore = entry.second.nScore; - int nReachability = entry.first.GetReachabilityFrom(paddrPeer); + int nReachability = entry.first.GetReachabilityFrom(&peer.addr); if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore)) { addr = CService(entry.first, entry.second.nPort); @@ -203,10 +203,10 @@ static std::vector ConvertSeeds(const std::vector &vSeedsIn) // Otherwise, return the unroutable 0.0.0.0 but filled in with // the normal parameters, since the IP may be changed to a useful // one by discovery. -CService GetLocalAddress(const CNetAddr& addrPeer) +CService GetLocalAddress(const CNode& peer) { CService addr; - if (GetLocal(addr, &addrPeer)) { + if (GetLocal(addr, peer)) { return addr; } return CService{CNetAddr(), GetListenPort()}; @@ -229,7 +229,7 @@ bool IsPeerAddrLocalGood(CNode *pnode) std::optional GetLocalAddrForPeer(CNode& node) { - CService addrLocal{GetLocalAddress(node.addr)}; + CService addrLocal{GetLocalAddress(node)}; if (gArgs.GetBoolArg("-addrmantest", false)) { // use IPv4 loopback during addrmantest addrLocal = CService(LookupNumeric("127.0.0.1", GetListenPort())); diff --git a/src/net.h b/src/net.h index 83fe0427d4..e161671853 100644 --- a/src/net.h +++ b/src/net.h @@ -164,8 +164,8 @@ bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE); void RemoveLocal(const CService& addr); bool SeenLocal(const CService& addr); bool IsLocal(const CService& addr); -bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr); -CService GetLocalAddress(const CNetAddr& addrPeer); +bool GetLocal(CService& addr, const CNode& peer); +CService GetLocalAddress(const CNode& peer); CService MaybeFlipIPv6toCJDNS(const CService& service); -- cgit v1.2.3