aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Maxwell <greg@xiph.org>2012-08-22 07:15:03 -0700
committerGregory Maxwell <greg@xiph.org>2012-08-22 07:15:03 -0700
commita159d6caf0d905790cda5191af73855725f89c12 (patch)
treee2af0e7c7b184f6162dad884d37339aa8f42c70c /src
parentba1cdb688329c4a66baa0d0cc4cedca756a03d1b (diff)
parentf161a2c2114cd7d950248ce75a91ba1923e9abb1 (diff)
Merge pull request #1694 from sipa/fix_netloops
Fix infinite loops in connection logic
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp2
-rw-r--r--src/net.cpp8
2 files changed, 8 insertions, 2 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 7322b23eac..1a1e31c2f3 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -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);
diff --git a/src/net.cpp b/src/net.cpp
index 1c87eb9685..aaf7883e51 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -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)
return;
}
}
+ Sleep(500);
}
}
@@ -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;