|
|
@ -1690,8 +1690,8 @@ void ThreadOpenConnections() |
|
|
|
if (GetTime() - nStart > 60) { |
|
|
|
static bool done = false; |
|
|
|
if (!done) { |
|
|
|
LogPrintf("Adding fixed seed nodes.\n"); |
|
|
|
std::vector<CAddress> vFixedSeeds = ConvertSeeds(Params().FixedSeeds()); |
|
|
|
LogPrintf("Adding %d fixed seed nodes.\n", vFixedSeeds.size()); |
|
|
|
BOOST_FOREACH(CAddress fixedSeed, vFixedSeeds) { |
|
|
|
std::vector<CAddress> vFixedSeed; |
|
|
|
vFixedSeed.push_back(fixedSeed); |
|
|
@ -1700,6 +1700,7 @@ void ThreadOpenConnections() |
|
|
|
addrman.Add(vFixedSeed, seedSource); |
|
|
|
} |
|
|
|
done = true; |
|
|
|
LogPrintf("Done adding fixed seed nodes.\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -1720,6 +1721,7 @@ void ThreadOpenConnections() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
LogPrint("net", "Creating %d outbound connections\n", nOutbound); |
|
|
|
assert(nOutbound <= (MAX_OUTBOUND_CONNECTIONS + MAX_FEELER_CONNECTIONS)); |
|
|
|
|
|
|
|
// "Feeler Connections" as per https://eprint.iacr.org/2015/263.pdf
|
|
|
@ -1751,11 +1753,14 @@ void ThreadOpenConnections() |
|
|
|
int64_t nNow = GetTime(); |
|
|
|
int nTries = 0; |
|
|
|
|
|
|
|
LogPrint("net", "Resolving addrman collisions\n"); |
|
|
|
addrman.ResolveCollisions(); |
|
|
|
|
|
|
|
while (true) { |
|
|
|
if (ShutdownRequested()) |
|
|
|
break; |
|
|
|
|
|
|
|
LogPrint("net", "%s: addrman loop nTries=%d\n", __func__, nTries); |
|
|
|
|
|
|
|
CAddrInfo addr = addrman.SelectTriedCollision(); |
|
|
|
|
|
|
@ -1765,17 +1770,22 @@ void ThreadOpenConnections() |
|
|
|
} |
|
|
|
|
|
|
|
// if we selected an invalid address, restart
|
|
|
|
if (!addr.IsValid() || setConnected.count(addr.GetGroup(addrman.m_asmap)) || IsLocal(addr)) |
|
|
|
if (!addr.IsValid() || setConnected.count(addr.GetGroup(addrman.m_asmap)) || IsLocal(addr)) { |
|
|
|
LogPrint("net", "%s: addrman loop address is not valid, or ASN exists or is local, nTries=%d\n", __func__, nTries); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// If we didn't find an appropriate destination after trying 100 addresses fetched from addrman,
|
|
|
|
// stop this loop, and let the outer loop run again (which sleeps, adds seed nodes, recalculates
|
|
|
|
// already-connected network ranges, ...) before trying new addrman addresses.
|
|
|
|
nTries++; |
|
|
|
if (nTries > 100) |
|
|
|
if (nTries > 100) { |
|
|
|
LogPrint("net", "%s: addrman loop too many tries, nTries=%d\n", __func__, nTries); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (!IsReachable(addr)) { |
|
|
|
LogPrint("net", "%s: addrman loop not reachable, nTries=%d\n", __func__, nTries); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
@ -1791,8 +1801,10 @@ void ThreadOpenConnections() |
|
|
|
|
|
|
|
//TODO: why is this a good thing?
|
|
|
|
// do not allow non-default ports, unless after 50 invalid addresses selected already
|
|
|
|
if (addr.GetPort() != Params().GetDefaultPort() && nTries < 50) |
|
|
|
if (addr.GetPort() != Params().GetDefaultPort() && nTries < 50) { |
|
|
|
LogPrint("net", "%s: addrman loop not default port, nTries=%d\n", __func__, nTries); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
addrConnect = addr; |
|
|
|
break; |
|
|
@ -1892,6 +1904,7 @@ void ThreadOpenAddedConnections() |
|
|
|
// if successful, this moves the passed grant to the constructed node
|
|
|
|
bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound, const char *pszDest, bool fOneShot, bool fFeeler) |
|
|
|
{ |
|
|
|
LogPrint("net", "%s: %s feeler=%d oneshot=%d\n", __func__, addrConnect.ToString(), fFeeler, fOneShot); |
|
|
|
// Initiate outbound network connection
|
|
|
|
boost::this_thread::interruption_point(); |
|
|
|
if (!fNetworkActive) { |
|
|
@ -1910,11 +1923,14 @@ bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOu |
|
|
|
} else if (FindNode(std::string(pszDest))) |
|
|
|
return false; |
|
|
|
|
|
|
|
LogPrint("net", "%s: ConnectNode(%s)\n", __func__, addrConnect.ToString()); |
|
|
|
CNode* pnode = ConnectNode(addrConnect, pszDest); |
|
|
|
boost::this_thread::interruption_point(); |
|
|
|
|
|
|
|
if (!pnode) |
|
|
|
if (!pnode) { |
|
|
|
LogPrint("net", "%s: ConnectNode(%s) FAILED\n", __func__, addrConnect.ToString()); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (grantOutbound) |
|
|
|
grantOutbound->MoveTo(pnode->grantOutbound); |
|
|
|
pnode->fNetworkNode = true; |
|
|
|