Skip to content

Commit 546e69f

Browse files
authored
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
1 parent e4ef7e8 commit 546e69f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/masternode/activemasternode.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,15 @@ void CActiveMasternodeManager::UpdatedBlockTip(const CBlockIndex* pindexNew, con
177177

178178
bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet)
179179
{
180-
// First try to find whatever local address is specified by externalip option
181-
bool fFoundLocal = GetLocal(addrRet) && IsValidNetAddr(addrRet);
180+
// First try to find whatever our own local address is known internally.
181+
// Addresses could be specified via externalip or bind option, discovered via UPnP
182+
// or added by TorController. Use some random dummy IPv4 peer to prefer the one
183+
// reachable via IPv4.
184+
CNetAddr addrDummyPeer;
185+
bool fFoundLocal{false};
186+
if (LookupHost("8.8.8.8", addrDummyPeer, false)) {
187+
fFoundLocal = GetLocal(addrRet, &addrDummyPeer) && IsValidNetAddr(addrRet);
188+
}
182189
if (!fFoundLocal && Params().NetworkIDString() == CBaseChainParams::REGTEST) {
183190
if (Lookup("127.0.0.1", addrRet, GetListenPort(), false)) {
184191
fFoundLocal = true;

0 commit comments

Comments
 (0)