Merge #9626: Clean up a few CConnman cs_vNodes/CNode things

2366180 Do not add to vNodes until fOneShot/fFeeler/fAddNode have been set (Matt Corallo)
3c37dc4 Ensure cs_vNodes is held when using the return value from FindNode (Matt Corallo)
5be0190 Delete some unused (and broken) functions in CConnman (Matt Corallo)
This commit is contained in:
Wladimir J. van der Laan 2017-01-30 12:44:08 +01:00
commit 36966a1c0e
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
2 changed files with 14 additions and 46 deletions

View File

@ -342,8 +342,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
CNode* pnode = FindNode((CService)addrConnect); CNode* pnode = FindNode((CService)addrConnect);
if (pnode) if (pnode)
{ {
pnode->AddRef(); LogPrintf("Failed to open new connection, already connected\n");
return pnode; return NULL;
} }
} }
@ -369,18 +369,16 @@ 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. // 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 // Also store the name we used to connect in that CNode, so that future FindNode() calls to that
// name catch this early. // name catch this early.
LOCK(cs_vNodes);
CNode* pnode = FindNode((CService)addrConnect); CNode* pnode = FindNode((CService)addrConnect);
if (pnode) if (pnode)
{ {
pnode->AddRef(); if (pnode->addrName.empty()) {
{ pnode->addrName = std::string(pszDest);
LOCK(cs_vNodes);
if (pnode->addrName.empty()) {
pnode->addrName = std::string(pszDest);
}
} }
CloseSocket(hSocket); CloseSocket(hSocket);
return pnode; LogPrintf("Failed to open new connection, already connected\n");
return NULL;
} }
} }
@ -393,11 +391,6 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
pnode->nServicesExpected = ServiceFlags(addrConnect.nServices & nRelevantServices); pnode->nServicesExpected = ServiceFlags(addrConnect.nServices & nRelevantServices);
pnode->nTimeConnected = GetSystemTimeInSeconds(); pnode->nTimeConnected = GetSystemTimeInSeconds();
pnode->AddRef(); pnode->AddRef();
GetNodeSignals().InitializeNode(pnode, *this);
{
LOCK(cs_vNodes);
vNodes.push_back(pnode);
}
return pnode; return pnode;
} else if (!proxyConnectionFailed) { } else if (!proxyConnectionFailed) {
@ -1840,6 +1833,12 @@ bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
if (fAddnode) if (fAddnode)
pnode->fAddnode = true; pnode->fAddnode = true;
{
LOCK(cs_vNodes);
vNodes.push_back(pnode);
}
GetNodeSignals().InitializeNode(pnode, *this);
return true; return true;
} }
@ -2371,26 +2370,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) bool CConnman::DisconnectNode(const std::string& strNode)
{ {
LOCK(cs_vNodes);
if (CNode* pnode = FindNode(strNode)) { if (CNode* pnode = FindNode(strNode)) {
pnode->fDisconnect = true; pnode->fDisconnect = true;
return true; return true;
@ -2409,16 +2391,6 @@ bool CConnman::DisconnectNode(NodeId id)
return false; return false;
} }
void CConnman::RelayTransaction(const CTransaction& tx)
{
CInv inv(MSG_TX, tx.GetHash());
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)
{
pnode->PushInventory(inv);
}
}
void CConnman::RecordBytesRecv(uint64_t bytes) void CConnman::RecordBytesRecv(uint64_t bytes)
{ {
LOCK(cs_totalBytesRecv); LOCK(cs_totalBytesRecv);

View File

@ -243,8 +243,6 @@ public:
post(); post();
}; };
void RelayTransaction(const CTransaction& tx);
// Addrman functions // Addrman functions
size_t GetAddressCount() const; size_t GetAddressCount() const;
void SetServices(const CService &addr, ServiceFlags nServices); void SetServices(const CService &addr, ServiceFlags nServices);
@ -286,10 +284,8 @@ public:
size_t GetNodeCount(NumConnections num); size_t GetNodeCount(NumConnections num);
void GetNodeStats(std::vector<CNodeStats>& vstats); void GetNodeStats(std::vector<CNodeStats>& vstats);
bool DisconnectAddress(const CNetAddr& addr);
bool DisconnectNode(const std::string& node); bool DisconnectNode(const std::string& node);
bool DisconnectNode(NodeId id); bool DisconnectNode(NodeId id);
bool DisconnectSubnet(const CSubNet& subnet);
unsigned int GetSendBufferSize() const; unsigned int GetSendBufferSize() const;