Set maxconnections default to 125

This commit is contained in:
Gavin Andresen 2011-02-16 14:43:04 -05:00
parent 9cbae55a6e
commit 5a3e82f9f5

20
net.cpp
View File

@ -688,25 +688,18 @@ void ThreadSocketHandler2(void* parg)
socklen_t len = sizeof(sockaddr); socklen_t len = sizeof(sockaddr);
SOCKET hSocket = accept(hListenSocket, (struct sockaddr*)&sockaddr, &len); SOCKET hSocket = accept(hListenSocket, (struct sockaddr*)&sockaddr, &len);
CAddress addr(sockaddr); CAddress addr(sockaddr);
bool fLimitConnections = false;
int nInbound = 0; int nInbound = 0;
if (mapArgs.count("-maxconnections")) CRITICAL_BLOCK(cs_vNodes)
fLimitConnections = true; foreach(CNode* pnode, vNodes)
if (pnode->fInbound)
if (fLimitConnections) nInbound++;
{
CRITICAL_BLOCK(cs_vNodes)
foreach(CNode* pnode, vNodes)
if (pnode->fInbound)
nInbound++;
}
if (hSocket == INVALID_SOCKET) if (hSocket == INVALID_SOCKET)
{ {
if (WSAGetLastError() != WSAEWOULDBLOCK) if (WSAGetLastError() != WSAEWOULDBLOCK)
printf("socket error accept failed: %d\n", WSAGetLastError()); printf("socket error accept failed: %d\n", WSAGetLastError());
} }
else if (fLimitConnections && nInbound >= atoi(mapArgs["-maxconnections"]) - MAX_OUTBOUND_CONNECTIONS) else if (nInbound >= GetArg("-maxconnections", 125) - MAX_OUTBOUND_CONNECTIONS)
{ {
closesocket(hSocket); closesocket(hSocket);
} }
@ -988,8 +981,7 @@ void ThreadOpenConnections2(void* parg)
if (!pnode->fInbound) if (!pnode->fInbound)
nOutbound++; nOutbound++;
int nMaxOutboundConnections = MAX_OUTBOUND_CONNECTIONS; int nMaxOutboundConnections = MAX_OUTBOUND_CONNECTIONS;
if (mapArgs.count("-maxconnections")) nMaxOutboundConnections = min(nMaxOutboundConnections, (int)GetArg("-maxconnections", 125));
nMaxOutboundConnections = min(nMaxOutboundConnections, atoi(mapArgs["-maxconnections"]));
if (nOutbound < nMaxOutboundConnections) if (nOutbound < nMaxOutboundConnections)
break; break;
Sleep(2000); Sleep(2000);