Skip to content

Commit 62d73f5

Browse files
committed
net, refactor: pass CNode instead of CNetAddr to GetLocalAddress
Access to CNode will be needed in the following commits.
1 parent f4a8269 commit 62d73f5

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/net.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ uint16_t GetListenPort()
153153
}
154154

155155
// find 'best' local address for a particular peer
156-
bool GetLocal(CService& addr, const CNetAddr *paddrPeer)
156+
bool GetLocal(CService& addr, const CNode& peer)
157157
{
158158
if (!fListen)
159159
return false;
@@ -165,7 +165,7 @@ bool GetLocal(CService& addr, const CNetAddr *paddrPeer)
165165
for (const auto& entry : mapLocalHost)
166166
{
167167
int nScore = entry.second.nScore;
168-
int nReachability = entry.first.GetReachabilityFrom(paddrPeer);
168+
int nReachability = entry.first.GetReachabilityFrom(&peer.addr);
169169
if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore))
170170
{
171171
addr = CService(entry.first, entry.second.nPort);
@@ -203,10 +203,10 @@ static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn)
203203
// Otherwise, return the unroutable 0.0.0.0 but filled in with
204204
// the normal parameters, since the IP may be changed to a useful
205205
// one by discovery.
206-
CService GetLocalAddress(const CNetAddr& addrPeer)
206+
CService GetLocalAddress(const CNode& peer)
207207
{
208208
CService addr;
209-
if (GetLocal(addr, &addrPeer)) {
209+
if (GetLocal(addr, peer)) {
210210
return addr;
211211
}
212212
return CService{CNetAddr(), GetListenPort()};
@@ -229,7 +229,7 @@ bool IsPeerAddrLocalGood(CNode *pnode)
229229

230230
std::optional<CService> GetLocalAddrForPeer(CNode& node)
231231
{
232-
CService addrLocal{GetLocalAddress(node.addr)};
232+
CService addrLocal{GetLocalAddress(node)};
233233
if (gArgs.GetBoolArg("-addrmantest", false)) {
234234
// use IPv4 loopback during addrmantest
235235
addrLocal = CService(LookupNumeric("127.0.0.1", GetListenPort()));

src/net.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
164164
void RemoveLocal(const CService& addr);
165165
bool SeenLocal(const CService& addr);
166166
bool IsLocal(const CService& addr);
167-
bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
168-
CService GetLocalAddress(const CNetAddr& addrPeer);
167+
bool GetLocal(CService& addr, const CNode& peer);
168+
CService GetLocalAddress(const CNode& peer);
169169
CService MaybeFlipIPv6toCJDNS(const CService& service);
170170

171171

0 commit comments

Comments
 (0)