Skip to content

Commit d051929

Browse files
committed
refactor: replace external ::GetLocal() usage
`GetLocal()` will no longer be exposed through the header in the next commit, replace it with `GetLocalAddress()`
1 parent 481175f commit d051929

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/masternode/node.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,14 @@ bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet)
239239
if (!fFoundLocal) {
240240
bool empty = true;
241241
// If we have some peers, let's try to find our local address from one of them
242-
auto service = m_info.service;
243242
m_connman.ForEachNodeContinueIf(CConnman::AllNodes, [&](CNode* pnode) {
244243
empty = false;
245-
if (pnode->addr.IsIPv4()) fFoundLocal = GetLocal(service, *pnode) && IsValidNetAddr(service);
244+
if (pnode->addr.IsIPv4()) {
245+
if (auto addr = ::GetLocalAddress(*pnode); IsValidNetAddr(addr)) {
246+
addrRet = addr;
247+
fFoundLocal = true;
248+
}
249+
}
246250
return !fFoundLocal;
247251
});
248252
// nothing and no live connections, can't do anything for now
@@ -257,10 +261,10 @@ bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet)
257261

258262
bool CActiveMasternodeManager::IsValidNetAddr(const CService& addrIn)
259263
{
264+
if (!addrIn.IsValid() || !addrIn.IsIPv4()) return false;
260265
// TODO: regtest is fine with any addresses for now,
261266
// should probably be a bit smarter if one day we start to implement tests for this
262-
return !Params().RequireRoutableExternalIP() ||
263-
(addrIn.IsIPv4() && IsReachable(addrIn) && addrIn.IsRoutable());
267+
return !Params().RequireRoutableExternalIP() || (IsReachable(addrIn) && addrIn.IsRoutable());
264268
}
265269

266270
template <template <typename> class EncryptedObj, typename Obj>

0 commit comments

Comments
 (0)