Skip to content

Commit

Permalink
net, refactor: pass CNode instead of CNetAddr to GetLocalAddress
Browse files Browse the repository at this point in the history
Access to CNode will be needed in the following commits.
  • Loading branch information
mzumsande committed Jun 5, 2023
1 parent f4a8269 commit 62d73f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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
// 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()};
Expand All @@ -229,7 +229,7 @@ bool IsPeerAddrLocalGood(CNode *pnode)

std::optional<CService> 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()));
Expand Down
4 changes: 2 additions & 2 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down

0 comments on commit 62d73f5

Please sign in to comment.