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
This commit is contained in:
UdjinM6 2020-01-24 17:09:59 +03:00 committed by GitHub
parent e4ef7e8d09
commit 546e69f1af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -177,8 +177,15 @@ void CActiveMasternodeManager::UpdatedBlockTip(const CBlockIndex* pindexNew, con
bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet) bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet)
{ {
// First try to find whatever local address is specified by externalip option // First try to find whatever our own local address is known internally.
bool fFoundLocal = GetLocal(addrRet) && IsValidNetAddr(addrRet); // 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 (!fFoundLocal && Params().NetworkIDString() == CBaseChainParams::REGTEST) {
if (Lookup("127.0.0.1", addrRet, GetListenPort(), false)) { if (Lookup("127.0.0.1", addrRet, GetListenPort(), false)) {
fFoundLocal = true; fFoundLocal = true;