aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlangerhans <[email protected]>2014-12-20 18:05:06 +0100
committerlangerhans <[email protected]>2014-12-20 18:11:15 +0100
commit93d0ddad73e05c318a980284bf601158a3ef0d02 (patch)
tree2bbae1c875cfa6fb6f9c844ddba28156ec65a66a /src
parentMerge pull request #753 from langerhans/1.8.1-dev-blocknotify (diff)
downloaddiscoin-93d0ddad73e05c318a980284bf601158a3ef0d02.tar.xz
discoin-93d0ddad73e05c318a980284bf601158a3ef0d02.zip
Introduce -maxoutconnections= to set the maximum number of outbound connections
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp3
-rw-r--r--src/net.cpp9
-rw-r--r--src/net.h1
3 files changed, 8 insertions, 5 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 8223e3282..1737bb069 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -230,6 +230,7 @@ std::string HelpMessage(HelpMessageMode hmm)
strUsage += " -externalip=<ip> " + _("Specify your own public address") + "\n";
strUsage += " -listen " + _("Accept connections from outside (default: 1 if no -proxy or -connect)") + "\n";
strUsage += " -maxconnections=<n> " + _("Maintain at most <n> connections to peers (default: 125)") + "\n";
+ strUsage += " -maxoutconnections=<n> " + _("Maintain at most <n> outbound connections to peers (default: 8)") + "\n";
strUsage += " -maxreceivebuffer=<n> " + _("Maximum per-connection receive buffer, <n>*1000 bytes (default: 5000)") + "\n";
strUsage += " -maxsendbuffer=<n> " + _("Maximum per-connection send buffer, <n>*1000 bytes (default: 1000)") + "\n";
strUsage += " -onion=<ip:port> " + _("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: -proxy)") + "\n";
@@ -535,6 +536,8 @@ bool AppInit2(boost::thread_group& threadGroup)
if (nFD - MIN_CORE_FILEDESCRIPTORS < nMaxConnections)
nMaxConnections = nFD - MIN_CORE_FILEDESCRIPTORS;
+ nMaxOutboundConnections = GetArg("-maxoutconnections", 8);
+ nMaxOutboundConnections = std::min(std::max(nMaxOutboundConnections, 2), nMaxConnections);
// ********************************************************* Step 3: parameter-to-internal-flags
fDebug = !mapMultiArgs["-debug"].empty();
diff --git a/src/net.cpp b/src/net.cpp
index 425989b3b..f337447ff 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -39,8 +39,6 @@
using namespace std;
using namespace boost;
-static const int MAX_OUTBOUND_CONNECTIONS = 8;
-
bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);
@@ -59,6 +57,7 @@ uint64_t nLocalHostNonce = 0;
static std::vector<SOCKET> vhListenSocket;
CAddrMan addrman;
int nMaxConnections = 125;
+int nMaxOutboundConnections = 8;
vector<CNode*> vNodes;
CCriticalSection cs_vNodes;
@@ -916,7 +915,7 @@ void ThreadSocketHandler()
if (nErr != WSAEWOULDBLOCK)
LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr));
}
- else if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS)
+ else if (nInbound >= nMaxConnections - nMaxOutboundConnections)
{
closesocket(hSocket);
}
@@ -1709,7 +1708,7 @@ void StartNode(boost::thread_group& threadGroup)
{
if (semOutbound == NULL) {
// initialize semaphore
- int nMaxOutbound = min(MAX_OUTBOUND_CONNECTIONS, nMaxConnections);
+ int nMaxOutbound = min(nMaxOutboundConnections, nMaxConnections);
semOutbound = new CSemaphore(nMaxOutbound);
}
@@ -1753,7 +1752,7 @@ bool StopNode()
LogPrintf("StopNode()\n");
MapPort(false);
if (semOutbound)
- for (int i=0; i<MAX_OUTBOUND_CONNECTIONS; i++)
+ for (int i=0; i<nMaxOutboundConnections; i++)
semOutbound->post();
MilliSleep(50);
DumpAddresses();
diff --git a/src/net.h b/src/net.h
index cb07156bd..5862129fa 100644
--- a/src/net.h
+++ b/src/net.h
@@ -104,6 +104,7 @@ extern uint64_t nLocalServices;
extern uint64_t nLocalHostNonce;
extern CAddrMan addrman;
extern int nMaxConnections;
+extern int nMaxOutboundConnections;
extern std::vector<CNode*> vNodes;
extern CCriticalSection cs_vNodes;