|
|
@ -827,7 +827,6 @@ void ThreadSocketHandler() |
|
|
|
uiInterface.NotifyNumConnectionsChanged(nPrevNodeCount); |
|
|
|
uiInterface.NotifyNumConnectionsChanged(nPrevNodeCount); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Find which sockets have data to receive
|
|
|
|
// Find which sockets have data to receive
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -849,6 +848,7 @@ void ThreadSocketHandler() |
|
|
|
hSocketMax = max(hSocketMax, hListenSocket); |
|
|
|
hSocketMax = max(hSocketMax, hListenSocket); |
|
|
|
have_fds = true; |
|
|
|
have_fds = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vNodes); |
|
|
|
LOCK(cs_vNodes); |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) |
|
|
@ -909,58 +909,59 @@ void ThreadSocketHandler() |
|
|
|
MilliSleep(timeout.tv_usec/1000); |
|
|
|
MilliSleep(timeout.tv_usec/1000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Accept new connections
|
|
|
|
// Accept new connections
|
|
|
|
//
|
|
|
|
//
|
|
|
|
BOOST_FOREACH(SOCKET hListenSocket, vhListenSocket) |
|
|
|
BOOST_FOREACH(SOCKET hListenSocket, vhListenSocket) |
|
|
|
if (hListenSocket != INVALID_SOCKET && FD_ISSET(hListenSocket, &fdsetRecv)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
struct sockaddr_storage sockaddr; |
|
|
|
if (hListenSocket != INVALID_SOCKET && FD_ISSET(hListenSocket, &fdsetRecv)) |
|
|
|
socklen_t len = sizeof(sockaddr); |
|
|
|
|
|
|
|
SOCKET hSocket = accept(hListenSocket, (struct sockaddr*)&sockaddr, &len); |
|
|
|
|
|
|
|
CAddress addr; |
|
|
|
|
|
|
|
int nInbound = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hSocket != INVALID_SOCKET) |
|
|
|
|
|
|
|
if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr)) |
|
|
|
|
|
|
|
LogPrintf("Warning: Unknown socket family\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vNodes); |
|
|
|
struct sockaddr_storage sockaddr; |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) |
|
|
|
socklen_t len = sizeof(sockaddr); |
|
|
|
if (pnode->fInbound) |
|
|
|
SOCKET hSocket = accept(hListenSocket, (struct sockaddr*)&sockaddr, &len); |
|
|
|
nInbound++; |
|
|
|
CAddress addr; |
|
|
|
} |
|
|
|
int nInbound = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hSocket != INVALID_SOCKET) |
|
|
|
|
|
|
|
if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr)) |
|
|
|
|
|
|
|
LogPrintf("Warning: Unknown socket family\n"); |
|
|
|
|
|
|
|
|
|
|
|
if (hSocket == INVALID_SOCKET) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int nErr = WSAGetLastError(); |
|
|
|
|
|
|
|
if (nErr != WSAEWOULDBLOCK) |
|
|
|
|
|
|
|
LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
closesocket(hSocket); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (CNode::IsBanned(addr)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrintf("connection from %s dropped (banned)\n", addr.ToString()); |
|
|
|
|
|
|
|
closesocket(hSocket); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint("net", "accepted connection %s\n", addr.ToString()); |
|
|
|
|
|
|
|
CNode* pnode = new CNode(hSocket, addr, "", true); |
|
|
|
|
|
|
|
pnode->AddRef(); |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK(cs_vNodes); |
|
|
|
LOCK(cs_vNodes); |
|
|
|
vNodes.push_back(pnode); |
|
|
|
BOOST_FOREACH(CNode* pnode, vNodes) |
|
|
|
|
|
|
|
if (pnode->fInbound) |
|
|
|
|
|
|
|
nInbound++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hSocket == INVALID_SOCKET) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int nErr = WSAGetLastError(); |
|
|
|
|
|
|
|
if (nErr != WSAEWOULDBLOCK) |
|
|
|
|
|
|
|
LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
closesocket(hSocket); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (CNode::IsBanned(addr)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrintf("connection from %s dropped (banned)\n", addr.ToString()); |
|
|
|
|
|
|
|
closesocket(hSocket); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint("net", "accepted connection %s\n", addr.ToString()); |
|
|
|
|
|
|
|
CNode* pnode = new CNode(hSocket, addr, "", true); |
|
|
|
|
|
|
|
pnode->AddRef(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LOCK(cs_vNodes); |
|
|
|
|
|
|
|
vNodes.push_back(pnode); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Service each socket
|
|
|
|
// Service each socket
|
|
|
|
//
|
|
|
|
//
|
|
|
|