aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2016-05-22 09:52:03 +0200
committerCory Fields <cory-nospam-@coryfields.com>2016-09-08 12:24:06 -0400
commitfdf69ff21aef8ed8071a757979f4239537f7afba (patch)
tree638189832dc1ea475da4747811cdbbc1d4ce4de5 /src/net.cpp
parent8a593694b1495656411717fbae5d3167576df973 (diff)
downloadbitcoin-fdf69ff21aef8ed8071a757979f4239537f7afba.tar.xz
net: move max/max-outbound to CConnman
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 853c0cdd65..fe4daaaebf 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -63,7 +63,6 @@
namespace {
- const int MAX_OUTBOUND_CONNECTIONS = 8;
const int MAX_FEELER_CONNECTIONS = 1;
}
@@ -79,7 +78,6 @@ CCriticalSection cs_mapLocalHost;
std::map<CNetAddr, LocalServiceInfo> mapLocalHost;
static bool vfLimited[NET_MAX] = {};
static CNode* pnodeLocalHost = NULL;
-int nMaxConnections = DEFAULT_MAX_PEER_CONNECTIONS;
std::string strSubVersion;
limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
@@ -974,7 +972,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
SOCKET hSocket = accept(hListenSocket.socket, (struct sockaddr*)&sockaddr, &len);
CAddress addr;
int nInbound = 0;
- int nMaxInbound = nMaxConnections - (MAX_OUTBOUND_CONNECTIONS + MAX_FEELER_CONNECTIONS);
+ int nMaxInbound = nMaxConnections - (nMaxOutbound + MAX_FEELER_CONNECTIONS);
assert(nMaxInbound > 0);
if (hSocket != INVALID_SOCKET)
@@ -1626,7 +1624,7 @@ void CConnman::ThreadOpenConnections()
}
}
}
- assert(nOutbound <= (MAX_OUTBOUND_CONNECTIONS + MAX_FEELER_CONNECTIONS));
+ assert(nOutbound <= (nMaxOutbound + MAX_FEELER_CONNECTIONS));
// Feeler Connections
//
@@ -1641,7 +1639,7 @@ void CConnman::ThreadOpenConnections()
// * Only make a feeler connection once every few minutes.
//
bool fFeeler = false;
- if (nOutbound >= MAX_OUTBOUND_CONNECTIONS) {
+ if (nOutbound >= nMaxOutbound) {
int64_t nTime = GetTimeMicros(); // The current time right now (in microseconds).
if (nTime > nNextFeeler) {
nNextFeeler = PoissonNextSend(nTime, FEELER_INTERVAL);
@@ -2038,13 +2036,15 @@ CConnman::CConnman()
nSendBufferMaxSize = 0;
nReceiveFloodSize = 0;
semOutbound = NULL;
+ nMaxConnections = 0;
+ nMaxOutbound = 0;
}
-bool StartNode(CConnman& connman, boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServices, ServiceFlags nRelevantServices, std::string& strNodeError)
+bool StartNode(CConnman& connman, boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServices, ServiceFlags nRelevantServices, int nMaxConnectionsIn, int nMaxOutboundIn, std::string& strNodeError)
{
Discover(threadGroup);
- bool ret = connman.Start(threadGroup, scheduler, nLocalServices, nRelevantServices, strNodeError);
+ bool ret = connman.Start(threadGroup, scheduler, nLocalServices, nRelevantServices, nMaxConnectionsIn, nMaxOutboundIn, strNodeError);
return ret;
}
@@ -2054,7 +2054,7 @@ NodeId CConnman::GetNewNodeId()
return nLastNodeId.fetch_add(1, std::memory_order_relaxed);
}
-bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServicesIn, ServiceFlags nRelevantServicesIn, std::string& strNodeError)
+bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, ServiceFlags nLocalServicesIn, ServiceFlags nRelevantServicesIn, int nMaxConnectionsIn, int nMaxOutboundIn, std::string& strNodeError)
{
nTotalBytesRecv = 0;
nTotalBytesSent = 0;
@@ -2065,6 +2065,9 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, Se
nRelevantServices = nRelevantServicesIn;
nMaxOutboundCycleStartTime = 0;
+ nMaxConnections = nMaxConnectionsIn;
+ nMaxOutbound = std::min((nMaxOutboundIn), nMaxConnections);
+
nSendBufferMaxSize = 1000*GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
nReceiveFloodSize = 1000*GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);
@@ -2106,8 +2109,7 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, Se
if (semOutbound == NULL) {
// initialize semaphore
- int nMaxOutbound = std::min((MAX_OUTBOUND_CONNECTIONS + MAX_FEELER_CONNECTIONS), nMaxConnections);
- semOutbound = new CSemaphore(nMaxOutbound);
+ semOutbound = new CSemaphore(std::min((nMaxOutbound + MAX_FEELER_CONNECTIONS), nMaxConnections));
}
if (pnodeLocalHost == NULL) {
@@ -2174,7 +2176,7 @@ instance_of_cnetcleanup;
void CConnman::Stop()
{
if (semOutbound)
- for (int i=0; i<(MAX_OUTBOUND_CONNECTIONS + MAX_FEELER_CONNECTIONS); i++)
+ for (int i=0; i<(nMaxOutbound + MAX_FEELER_CONNECTIONS); i++)
semOutbound->post();
if (fAddressesInitialized)