Browse Source

Merge pull request #1694 from sipa/fix_netloops

Fix infinite loops in connection logic
0.8
Gregory Maxwell 12 years ago
parent
commit
a159d6caf0
  1. 2
      src/init.cpp
  2. 8
      src/net.cpp

2
src/init.cpp

@ -357,7 +357,7 @@ bool AppInit2() @@ -357,7 +357,7 @@ bool AppInit2()
SoftSetBoolArg("-listen", true);
}
if (mapArgs.count("-connect")) {
if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) {
// when only connecting to trusted nodes, do not seed via DNS, or listen by default
SoftSetBoolArg("-dnsseed", false);
SoftSetBoolArg("-listen", false);

8
src/net.cpp

@ -1391,7 +1391,7 @@ void ThreadOpenConnections2(void* parg) @@ -1391,7 +1391,7 @@ void ThreadOpenConnections2(void* parg)
printf("ThreadOpenConnections started\n");
// Connect to specific addresses
if (mapArgs.count("-connect"))
if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0)
{
for (int64 nLoop = 0;; nLoop++)
{
@ -1407,6 +1407,7 @@ void ThreadOpenConnections2(void* parg) @@ -1407,6 +1407,7 @@ void ThreadOpenConnections2(void* parg)
return;
}
}
Sleep(500);
}
}
@ -1480,7 +1481,12 @@ void ThreadOpenConnections2(void* parg) @@ -1480,7 +1481,12 @@ void ThreadOpenConnections2(void* parg)
if (!addr.IsValid() || setConnected.count(addr.GetGroup()) || IsLocal(addr))
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)
break;
if (IsLimited(addr))
continue;

Loading…
Cancel
Save