1
1
mirror of https://github.com/bitcoin/bitcoin.git synced 2024-05-17 23:56:39 +00:00

net, refactor: pass CNode instead of CNetAddr to GetLocalAddress

Access to CNode will be needed in the following commits.
This commit is contained in:
Martin Zumsande 2023-04-11 15:09:31 -04:00
parent f4a8269dfc
commit 62d73f5370
2 changed files with 7 additions and 7 deletions

View File

@ -153,7 +153,7 @@ uint16_t GetListenPort()
} }
// find 'best' local address for a particular peer // find 'best' local address for a particular peer
bool GetLocal(CService& addr, const CNetAddr *paddrPeer) bool GetLocal(CService& addr, const CNode& peer)
{ {
if (!fListen) if (!fListen)
return false; return false;
@ -165,7 +165,7 @@ bool GetLocal(CService& addr, const CNetAddr *paddrPeer)
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(paddrPeer); 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);
@ -203,10 +203,10 @@ static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn)
// Otherwise, return the unroutable 0.0.0.0 but filled in with // Otherwise, return the unroutable 0.0.0.0 but filled in with
// the normal parameters, since the IP may be changed to a useful // the normal parameters, since the IP may be changed to a useful
// one by discovery. // one by discovery.
CService GetLocalAddress(const CNetAddr& addrPeer) CService GetLocalAddress(const CNode& peer)
{ {
CService addr; CService addr;
if (GetLocal(addr, &addrPeer)) { if (GetLocal(addr, peer)) {
return addr; return addr;
} }
return CService{CNetAddr(), GetListenPort()}; return CService{CNetAddr(), GetListenPort()};
@ -229,7 +229,7 @@ bool IsPeerAddrLocalGood(CNode *pnode)
std::optional<CService> GetLocalAddrForPeer(CNode& node) std::optional<CService> GetLocalAddrForPeer(CNode& node)
{ {
CService addrLocal{GetLocalAddress(node.addr)}; CService addrLocal{GetLocalAddress(node)};
if (gArgs.GetBoolArg("-addrmantest", false)) { if (gArgs.GetBoolArg("-addrmantest", false)) {
// use IPv4 loopback during addrmantest // use IPv4 loopback during addrmantest
addrLocal = CService(LookupNumeric("127.0.0.1", GetListenPort())); addrLocal = CService(LookupNumeric("127.0.0.1", GetListenPort()));

View File

@ -164,8 +164,8 @@ bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
void RemoveLocal(const CService& addr); void RemoveLocal(const CService& addr);
bool SeenLocal(const CService& addr); bool SeenLocal(const CService& addr);
bool IsLocal(const CService& addr); bool IsLocal(const CService& addr);
bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr); bool GetLocal(CService& addr, const CNode& peer);
CService GetLocalAddress(const CNetAddr& addrPeer); CService GetLocalAddress(const CNode& peer);
CService MaybeFlipIPv6toCJDNS(const CService& service); CService MaybeFlipIPv6toCJDNS(const CService& service);