From 105122181a2d3b75f688f95636cd80f89243248c Mon Sep 17 00:00:00 2001 From: Oleg Girko Date: Tue, 29 Aug 2017 00:51:56 +0100 Subject: [PATCH] Partially backport Bitcoin PR#9626: Clean up a few CConnman cs_vNodes/CNode things (#1591) * Delete some unused (and broken) functions in CConnman * Ensure cs_vNodes is held when using the return value from FindNode --- src/net.cpp | 27 ++++----------------------- src/net.h | 2 -- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 47e631779..1d54005f5 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -388,6 +388,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo // In that case, drop the connection that was just created, and return the existing CNode instead. // Also store the name we used to connect in that CNode, so that future FindNode() calls to that // name catch this early. + LOCK(cs_vNodes); CNode* pnode = FindNode((CService)addrConnect); if (pnode) { @@ -397,11 +398,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo pnode->AddRef(); pnode->fMasternode = true; } - { - LOCK(cs_vNodes); - if (pnode->addrName.empty()) { - pnode->addrName = std::string(pszDest); - } + if (pnode->addrName.empty()) { + pnode->addrName = std::string(pszDest); } CloseSocket(hSocket); return pnode; @@ -2400,26 +2398,9 @@ void CConnman::GetNodeStats(std::vector& vstats) } } -bool CConnman::DisconnectAddress(const CNetAddr& netAddr) -{ - if (CNode* pnode = FindNode(netAddr)) { - pnode->fDisconnect = true; - return true; - } - return false; -} - -bool CConnman::DisconnectSubnet(const CSubNet& subNet) -{ - if (CNode* pnode = FindNode(subNet)) { - pnode->fDisconnect = true; - return true; - } - return false; -} - bool CConnman::DisconnectNode(const std::string& strNode) { + LOCK(cs_vNodes); if (CNode* pnode = FindNode(strNode)) { pnode->fDisconnect = true; return true; diff --git a/src/net.h b/src/net.h index 193eba6f2..ee8f7a098 100644 --- a/src/net.h +++ b/src/net.h @@ -347,10 +347,8 @@ public: size_t GetNodeCount(NumConnections num); void GetNodeStats(std::vector& vstats); - bool DisconnectAddress(const CNetAddr& addr); bool DisconnectNode(const std::string& node); bool DisconnectNode(NodeId id); - bool DisconnectSubnet(const CSubNet& subnet); unsigned int GetSendBufferSize() const;