|
|
@ -63,7 +63,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
namespace { |
|
|
|
const int MAX_OUTBOUND_CONNECTIONS = 8; |
|
|
|
|
|
|
|
const int MAX_FEELER_CONNECTIONS = 1; |
|
|
|
const int MAX_FEELER_CONNECTIONS = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -79,7 +78,6 @@ CCriticalSection cs_mapLocalHost; |
|
|
|
std::map<CNetAddr, LocalServiceInfo> mapLocalHost; |
|
|
|
std::map<CNetAddr, LocalServiceInfo> mapLocalHost; |
|
|
|
static bool vfLimited[NET_MAX] = {}; |
|
|
|
static bool vfLimited[NET_MAX] = {}; |
|
|
|
static CNode* pnodeLocalHost = NULL; |
|
|
|
static CNode* pnodeLocalHost = NULL; |
|
|
|
int nMaxConnections = DEFAULT_MAX_PEER_CONNECTIONS; |
|
|
|
|
|
|
|
std::string strSubVersion; |
|
|
|
std::string strSubVersion; |
|
|
|
|
|
|
|
|
|
|
|
limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ); |
|
|
|
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); |
|
|
|
SOCKET hSocket = accept(hListenSocket.socket, (struct sockaddr*)&sockaddr, &len); |
|
|
|
CAddress addr; |
|
|
|
CAddress addr; |
|
|
|
int nInbound = 0; |
|
|
|
int nInbound = 0; |
|
|
|
int nMaxInbound = nMaxConnections - (MAX_OUTBOUND_CONNECTIONS + MAX_FEELER_CONNECTIONS); |
|
|
|
int nMaxInbound = nMaxConnections - (nMaxOutbound + MAX_FEELER_CONNECTIONS); |
|
|
|
assert(nMaxInbound > 0); |
|
|
|
assert(nMaxInbound > 0); |
|
|
|
|
|
|
|
|
|
|
|
if (hSocket != INVALID_SOCKET) |
|
|
|
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
|
|
|
|
// Feeler Connections
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -1641,7 +1639,7 @@ void CConnman::ThreadOpenConnections() |
|
|
|
// * Only make a feeler connection once every few minutes.
|
|
|
|
// * Only make a feeler connection once every few minutes.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
bool fFeeler = false; |
|
|
|
bool fFeeler = false; |
|
|
|
if (nOutbound >= MAX_OUTBOUND_CONNECTIONS) { |
|
|
|
if (nOutbound >= nMaxOutbound) { |
|
|
|
int64_t nTime = GetTimeMicros(); // The current time right now (in microseconds).
|
|
|
|
int64_t nTime = GetTimeMicros(); // The current time right now (in microseconds).
|
|
|
|
if (nTime > nNextFeeler) { |
|
|
|
if (nTime > nNextFeeler) { |
|
|
|
nNextFeeler = PoissonNextSend(nTime, FEELER_INTERVAL); |
|
|
|
nNextFeeler = PoissonNextSend(nTime, FEELER_INTERVAL); |
|
|
@ -2038,13 +2036,15 @@ CConnman::CConnman() |
|
|
|
nSendBufferMaxSize = 0; |
|
|
|
nSendBufferMaxSize = 0; |
|
|
|
nReceiveFloodSize = 0; |
|
|
|
nReceiveFloodSize = 0; |
|
|
|
semOutbound = NULL; |
|
|
|
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); |
|
|
|
Discover(threadGroup); |
|
|
|
|
|
|
|
|
|
|
|
bool ret = connman.Start(threadGroup, scheduler, nLocalServices, nRelevantServices, strNodeError); |
|
|
|
bool ret = connman.Start(threadGroup, scheduler, nLocalServices, nRelevantServices, nMaxConnectionsIn, nMaxOutboundIn, strNodeError); |
|
|
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
@ -2054,7 +2054,7 @@ NodeId CConnman::GetNewNodeId() |
|
|
|
return nLastNodeId.fetch_add(1, std::memory_order_relaxed); |
|
|
|
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; |
|
|
|
nTotalBytesRecv = 0; |
|
|
|
nTotalBytesSent = 0; |
|
|
|
nTotalBytesSent = 0; |
|
|
@ -2065,6 +2065,9 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, Se |
|
|
|
nRelevantServices = nRelevantServicesIn; |
|
|
|
nRelevantServices = nRelevantServicesIn; |
|
|
|
nMaxOutboundCycleStartTime = 0; |
|
|
|
nMaxOutboundCycleStartTime = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nMaxConnections = nMaxConnectionsIn; |
|
|
|
|
|
|
|
nMaxOutbound = std::min((nMaxOutboundIn), nMaxConnections); |
|
|
|
|
|
|
|
|
|
|
|
nSendBufferMaxSize = 1000*GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER); |
|
|
|
nSendBufferMaxSize = 1000*GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER); |
|
|
|
nReceiveFloodSize = 1000*GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER); |
|
|
|
nReceiveFloodSize = 1000*GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER); |
|
|
|
|
|
|
|
|
|
|
@ -2106,8 +2109,7 @@ bool CConnman::Start(boost::thread_group& threadGroup, CScheduler& scheduler, Se |
|
|
|
|
|
|
|
|
|
|
|
if (semOutbound == NULL) { |
|
|
|
if (semOutbound == NULL) { |
|
|
|
// initialize semaphore
|
|
|
|
// initialize semaphore
|
|
|
|
int nMaxOutbound = std::min((MAX_OUTBOUND_CONNECTIONS + MAX_FEELER_CONNECTIONS), nMaxConnections); |
|
|
|
semOutbound = new CSemaphore(std::min((nMaxOutbound + MAX_FEELER_CONNECTIONS), nMaxConnections)); |
|
|
|
semOutbound = new CSemaphore(nMaxOutbound); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pnodeLocalHost == NULL) { |
|
|
|
if (pnodeLocalHost == NULL) { |
|
|
@ -2174,7 +2176,7 @@ instance_of_cnetcleanup; |
|
|
|
void CConnman::Stop() |
|
|
|
void CConnman::Stop() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (semOutbound) |
|
|
|
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(); |
|
|
|
semOutbound->post(); |
|
|
|
|
|
|
|
|
|
|
|
if (fAddressesInitialized) |
|
|
|
if (fAddressesInitialized) |
|
|
|