Skip to content

Commit

Permalink
Fix CActiveMasternodeManager::GetLocalAddress to prefer IPv4 if multi…
Browse files Browse the repository at this point in the history
…ple local addresses are known
  • Loading branch information
UdjinM6 authored and furszy committed Feb 10, 2022
1 parent 0e757ad commit 34363a5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ CActiveDeterministicMasternodeManager* activeMasternodeManager{nullptr};

static bool GetLocalAddress(CService& addrRet)
{
// First try to find whatever local address is specified by externalip option
bool fFound = GetLocal(addrRet) && CActiveDeterministicMasternodeManager::IsValidNetAddr(addrRet);
// First try to find whatever our own local address is known internally.
// Addresses could be specified via 'externalip' or 'bind' option, discovered via UPnP
// or added by TorController. Use some random dummy IPv4 peer to prefer the one
// reachable via IPv4.
CNetAddr addrDummyPeer;
bool fFound{false};
if (LookupHost("8.8.8.8", addrDummyPeer, false)) {
fFound = GetLocal(addrRet, &addrDummyPeer) && CActiveDeterministicMasternodeManager::IsValidNetAddr(addrRet);
}
if (!fFound && Params().IsRegTestNet()) {
if (Lookup("127.0.0.1", addrRet, GetListenPort(), false)) {
fFound = true;
}
}
if(!fFound) {
if (!fFound) {
// If we have some peers, let's try to find our local address from one of them
g_connman->ForEachNodeContinueIf([&fFound, &addrRet](CNode* pnode) {
if (pnode->addr.IsIPv4())
Expand Down

0 comments on commit 34363a5

Please sign in to comment.