From 546e69f1afcafeac1195ecb6286595be0d6249a2 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 24 Jan 2020 17:09:59 +0300 Subject: [PATCH] Fix CActiveMasternodeManager::GetLocalAddress to prefer IPv4 if multiple local addresses are known (#3304) * Fix CActiveMasternodeManager::GetLocalAddress to prefer IPv4 if multiple local addresses are known * Make sure LookupHost succeeded --- src/masternode/activemasternode.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/masternode/activemasternode.cpp b/src/masternode/activemasternode.cpp index 356f36c0a8..2e65e529f8 100644 --- a/src/masternode/activemasternode.cpp +++ b/src/masternode/activemasternode.cpp @@ -177,8 +177,15 @@ void CActiveMasternodeManager::UpdatedBlockTip(const CBlockIndex* pindexNew, con bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet) { - // First try to find whatever local address is specified by externalip option - bool fFoundLocal = GetLocal(addrRet) && 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 fFoundLocal{false}; + if (LookupHost("8.8.8.8", addrDummyPeer, false)) { + fFoundLocal = GetLocal(addrRet, &addrDummyPeer) && IsValidNetAddr(addrRet); + } if (!fFoundLocal && Params().NetworkIDString() == CBaseChainParams::REGTEST) { if (Lookup("127.0.0.1", addrRet, GetListenPort(), false)) { fFoundLocal = true;