Skip to content

Commit

Permalink
net: more net race fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
theuni committed Feb 9, 2017
1 parent 74b46ed commit d185ca0
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ bool CConnman::AttemptToEvictConnection()
continue;
if (node->fDisconnect)
continue;
LOCK(node->cs_filter);
NodeEvictionCandidate candidate = {node->id, node->nTimeConnected, node->nMinPingUsecTime,
node->nLastBlockTime, node->nLastTXTime,
(node->nServices & nRelevantServices) == nRelevantServices,
Expand Down Expand Up @@ -2160,11 +2161,6 @@ NodeId CConnman::GetNewNodeId()

bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options connOptions)
{
nTotalBytesRecv = 0;
nTotalBytesSent = 0;
nMaxOutboundTotalBytesSentInCycle = 0;
nMaxOutboundCycleStartTime = 0;

nRelevantServices = connOptions.nRelevantServices;
nLocalServices = connOptions.nLocalServices;
nMaxConnections = connOptions.nMaxConnections;
Expand All @@ -2175,9 +2171,18 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c
nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
nReceiveFloodSize = connOptions.nReceiveFloodSize;

nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;

{
LOCK(cs_totalBytesSent);
nTotalBytesSent = 0;
nMaxOutboundTotalBytesSentInCycle = 0;
nMaxOutboundCycleStartTime = 0;
nMaxOutboundLimit = connOptions.nMaxOutboundLimit;
nMaxOutboundTimeframe = connOptions.nMaxOutboundTimeframe;
}
{
LOCK(cs_totalBytesRecv);
nTotalBytesRecv = 0;
}
SetBestHeight(connOptions.nBestHeight);

clientInterface = connOptions.uiInterface;
Expand Down Expand Up @@ -2318,22 +2323,24 @@ void CConnman::Stop()
}

// Close sockets
BOOST_FOREACH(CNode* pnode, vNodes)
if (pnode->hSocket != INVALID_SOCKET)
CloseSocket(pnode->hSocket);
{
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes) {
if (pnode->hSocket != INVALID_SOCKET)
CloseSocket(pnode->hSocket);
DeleteNode(pnode);
}
vNodes.clear();
}
BOOST_FOREACH(ListenSocket& hListenSocket, vhListenSocket)
if (hListenSocket.socket != INVALID_SOCKET)
if (!CloseSocket(hListenSocket.socket))
LogPrintf("CloseSocket(hListenSocket) failed with error %s\n", NetworkErrorString(WSAGetLastError()));

// clean up some globals (to help leak detection)
BOOST_FOREACH(CNode *pnode, vNodes) {
DeleteNode(pnode);
}
BOOST_FOREACH(CNode *pnode, vNodesDisconnected) {
DeleteNode(pnode);
}
vNodes.clear();
vNodesDisconnected.clear();
vhListenSocket.clear();
delete semOutbound;
Expand Down

0 comments on commit d185ca0

Please sign in to comment.