Browse Source

Refactor: Bail early in AcceptConnection

0.13
Patrick Strateman 9 years ago
parent
commit
1ef4817614
  1. 21
      src/net.cpp

21
src/net.cpp

@ -801,29 +801,37 @@ static void AcceptConnection(const ListenSocket& hListenSocket) {
int nErr = WSAGetLastError(); int nErr = WSAGetLastError();
if (nErr != WSAEWOULDBLOCK) if (nErr != WSAEWOULDBLOCK)
LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr)); LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr));
return;
} }
else if (!IsSelectableSocket(hSocket))
if (!IsSelectableSocket(hSocket))
{ {
LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToString()); LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToString());
CloseSocket(hSocket); CloseSocket(hSocket);
return;
} }
else if (nInbound >= nMaxInbound)
if (nInbound >= nMaxInbound)
{ {
LogPrint("net", "connection from %s dropped (full)\n", addr.ToString()); LogPrint("net", "connection from %s dropped (full)\n", addr.ToString());
CloseSocket(hSocket); CloseSocket(hSocket);
return;
} }
else if (!whitelisted && (nInbound >= (nMaxInbound - nWhiteConnections)))
if (!whitelisted && (nInbound >= (nMaxInbound - nWhiteConnections)))
{ {
LogPrint("net", "connection from %s dropped (non-whitelisted)\n", addr.ToString()); LogPrint("net", "connection from %s dropped (non-whitelisted)\n", addr.ToString());
CloseSocket(hSocket); CloseSocket(hSocket);
return;
} }
else if (CNode::IsBanned(addr) && !whitelisted)
if (CNode::IsBanned(addr) && !whitelisted)
{ {
LogPrintf("connection from %s dropped (banned)\n", addr.ToString()); LogPrintf("connection from %s dropped (banned)\n", addr.ToString());
CloseSocket(hSocket); CloseSocket(hSocket);
return;
} }
else
{
CNode* pnode = new CNode(hSocket, addr, "", true); CNode* pnode = new CNode(hSocket, addr, "", true);
pnode->AddRef(); pnode->AddRef();
pnode->fWhitelisted = whitelisted; pnode->fWhitelisted = whitelisted;
@ -835,7 +843,6 @@ static void AcceptConnection(const ListenSocket& hListenSocket) {
vNodes.push_back(pnode); vNodes.push_back(pnode);
} }
} }
}
void ThreadSocketHandler() void ThreadSocketHandler()
{ {

Loading…
Cancel
Save