From 0103c5b90fa61b5d159a825fcb5a05ca31d0d1c3 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Wed, 31 Aug 2016 13:17:28 -0400 Subject: [PATCH] net: move MAX_FEELER_CONNECTIONS into connman --- src/init.cpp | 1 + src/net.cpp | 14 +++++--------- src/net.h | 2 ++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 8f7cef20c..a8b2cde36 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1520,6 +1520,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) connOptions.nRelevantServices = nRelevantServices; connOptions.nMaxConnections = nMaxConnections; connOptions.nMaxOutbound = std::min(MAX_OUTBOUND_CONNECTIONS, connOptions.nMaxConnections); + connOptions.nMaxFeeler = 1; connOptions.nBestHeight = chainActive.Height(); connOptions.uiInterface = &uiInterface; connOptions.nSendBufferMaxSize = 1000*GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER); diff --git a/src/net.cpp b/src/net.cpp index 19c14e105..b39ef9f54 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -61,11 +61,6 @@ #endif #endif - -namespace { - const int MAX_FEELER_CONNECTIONS = 1; -} - const static std::string NET_MESSAGE_COMMAND_OTHER = "*other*"; // @@ -971,7 +966,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { SOCKET hSocket = accept(hListenSocket.socket, (struct sockaddr*)&sockaddr, &len); CAddress addr; int nInbound = 0; - int nMaxInbound = nMaxConnections - (nMaxOutbound + MAX_FEELER_CONNECTIONS); + int nMaxInbound = nMaxConnections - (nMaxOutbound + nMaxFeeler); assert(nMaxInbound > 0); if (hSocket != INVALID_SOCKET) @@ -1624,7 +1619,7 @@ void CConnman::ThreadOpenConnections() } } } - assert(nOutbound <= (nMaxOutbound + MAX_FEELER_CONNECTIONS)); + assert(nOutbound <= (nMaxOutbound + nMaxFeeler)); // Feeler Connections // @@ -2060,6 +2055,7 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, st nLocalServices = connOptions.nLocalServices; nMaxConnections = connOptions.nMaxConnections; nMaxOutbound = std::min((connOptions.nMaxOutbound), nMaxConnections); + nMaxFeeler = connOptions.nMaxFeeler; nSendBufferMaxSize = connOptions.nSendBufferMaxSize; nReceiveFloodSize = connOptions.nSendBufferMaxSize; @@ -2106,7 +2102,7 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, st if (semOutbound == NULL) { // initialize semaphore - semOutbound = new CSemaphore(std::min((nMaxOutbound + MAX_FEELER_CONNECTIONS), nMaxConnections)); + semOutbound = new CSemaphore(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections)); } if (pnodeLocalHost == NULL) { @@ -2162,7 +2158,7 @@ void CConnman::Stop() { LogPrintf("%s\n",__func__); if (semOutbound) - for (int i=0; i<(nMaxOutbound + MAX_FEELER_CONNECTIONS); i++) + for (int i=0; i<(nMaxOutbound + nMaxFeeler); i++) semOutbound->post(); if (fAddressesInitialized) diff --git a/src/net.h b/src/net.h index 97604ca56..a48ee02c4 100644 --- a/src/net.h +++ b/src/net.h @@ -115,6 +115,7 @@ public: ServiceFlags nRelevantServices = NODE_NONE; int nMaxConnections = 0; int nMaxOutbound = 0; + int nMaxFeeler = 0; int nBestHeight = 0; CClientUIInterface* uiInterface = nullptr; unsigned int nSendBufferMaxSize = 0; @@ -384,6 +385,7 @@ private: CSemaphore *semOutbound; int nMaxConnections; int nMaxOutbound; + int nMaxFeeler; std::atomic nBestHeight; CClientUIInterface* clientInterface; };