Skip to content

Commit

Permalink
Refactor: Bail early in AcceptConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
pstratem authored and Fuzzbawls committed Jun 23, 2020
1 parent 411766d commit fcb732b
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,24 +912,36 @@ static void AcceptConnection(const ListenSocket& hListenSocket) {
int nErr = WSAGetLastError();
if (nErr != WSAEWOULDBLOCK)
LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr));
} else if (!IsSelectableSocket(hSocket)) {
return;
}

if (!IsSelectableSocket(hSocket)) {
LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToString());
CloseSocket(hSocket);
} else if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS) {
return;
}

if (nInbound >= nMaxConnections - MAX_OUTBOUND_CONNECTIONS) {
LogPrint(BCLog::NET, "connection from %s dropped (full)\n", addr.ToString());
CloseSocket(hSocket);
} else if (CNode::IsBanned(addr) && !whitelisted) {
return;
}

if (CNode::IsBanned(addr) && !whitelisted) {
LogPrintf("connection from %s dropped (banned)\n", addr.ToString());
CloseSocket(hSocket);
} else {
CNode* pnode = new CNode(hSocket, addr, "", true);
pnode->AddRef();
pnode->fWhitelisted = whitelisted;
return;
}

{
LOCK(cs_vNodes);
vNodes.push_back(pnode);
}
CNode* pnode = new CNode(hSocket, addr, "", true);
pnode->AddRef();
pnode->fWhitelisted = whitelisted;

LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToString());

{
LOCK(cs_vNodes);
vNodes.push_back(pnode);
}
}

Expand Down

0 comments on commit fcb732b

Please sign in to comment.