mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
net: move max/max-outbound to CConnman
This commit is contained in:
24
src/net.cpp
24
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)
|
||||
|
||||
Reference in New Issue
Block a user