| 1309 | } |
| 1310 | |
| 1311 | void CConnman::DisconnectNodes() |
| 1312 | { |
| 1313 | { |
| 1314 | LOCK(m_nodes_mutex); |
| 1315 | |
| 1316 | if (!fNetworkActive) { |
| 1317 | // Disconnect any connected nodes |
| 1318 | for (CNode* pnode : m_nodes) { |
| 1319 | if (!pnode->fDisconnect) { |
| 1320 | LogPrint(BCLog::NET, "Network not active, dropping peer=%d\n", pnode->GetId()); |
| 1321 | pnode->fDisconnect = true; |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | // Disconnect unused nodes |
| 1327 | std::vector<CNode*> nodes_copy = m_nodes; |
| 1328 | for (CNode* pnode : nodes_copy) |
| 1329 | { |
| 1330 | if (pnode->fDisconnect) |
| 1331 | { |
| 1332 | // remove from m_nodes |
| 1333 | m_nodes.erase(remove(m_nodes.begin(), m_nodes.end(), pnode), m_nodes.end()); |
| 1334 | |
| 1335 | // release outbound grant (if any) |
| 1336 | pnode->grantOutbound.Release(); |
| 1337 | |
| 1338 | // close socket and cleanup |
| 1339 | pnode->CloseSocketDisconnect(); |
| 1340 | |
| 1341 | // hold in disconnected pool until all refs are released |
| 1342 | pnode->Release(); |
| 1343 | m_nodes_disconnected.push_back(pnode); |
| 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | { |
| 1348 | // Delete disconnected nodes |
| 1349 | std::list<CNode*> nodes_disconnected_copy = m_nodes_disconnected; |
| 1350 | for (CNode* pnode : nodes_disconnected_copy) |
| 1351 | { |
| 1352 | // Destroy the object only after other threads have stopped using it. |
| 1353 | if (pnode->GetRefCount() <= 0) { |
| 1354 | m_nodes_disconnected.remove(pnode); |
| 1355 | DeleteNode(pnode); |
| 1356 | } |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | void CConnman::NotifyNumConnectionsChanged() |
| 1362 | { |
nothing calls this directly
no test coverage detected