Skip to content

Commit

Permalink
Partially backport Bitcoin PR#9626: Clean up a few CConnman cs_vNodes…
Browse files Browse the repository at this point in the history
…/CNode things (#1591)

* Delete some unused (and broken) functions in CConnman

* Ensure cs_vNodes is held when using the return value from FindNode
  • Loading branch information
OlegGirko authored and UdjinM6 committed Aug 28, 2017
1 parent 4f54550 commit 1051221
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
27 changes: 4 additions & 23 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -2400,26 +2398,9 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& 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;
Expand Down
2 changes: 0 additions & 2 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,8 @@ class CConnman

size_t GetNodeCount(NumConnections num);
void GetNodeStats(std::vector<CNodeStats>& 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;

Expand Down

0 comments on commit 1051221

Please sign in to comment.