mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
net: Add most functions needed for vNodes to CConnman
This commit is contained in:
66
src/net.cpp
66
src/net.cpp
@@ -2267,6 +2267,72 @@ bool CConnman::RemoveAddedNode(const std::string& strNode)
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t CConnman::GetNodeCount(NumConnections flags)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
if (flags == CConnman::CONNECTIONS_ALL) // Shortcut if we want total
|
||||
return vNodes.size();
|
||||
|
||||
int nNum = 0;
|
||||
for(std::vector<CNode*>::const_iterator it = vNodes.begin(); it != vNodes.end(); ++it)
|
||||
if (flags & ((*it)->fInbound ? CONNECTIONS_IN : CONNECTIONS_OUT))
|
||||
nNum++;
|
||||
|
||||
return nNum;
|
||||
}
|
||||
|
||||
void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats)
|
||||
{
|
||||
vstats.clear();
|
||||
LOCK(cs_vNodes);
|
||||
vstats.reserve(vNodes.size());
|
||||
for(std::vector<CNode*>::iterator it = vNodes.begin(); it != vNodes.end(); ++it) {
|
||||
CNode* pnode = *it;
|
||||
CNodeStats stats;
|
||||
pnode->copyStats(stats);
|
||||
vstats.push_back(stats);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (CNode* pnode = FindNode(strNode)) {
|
||||
pnode->fDisconnect = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CConnman::DisconnectNode(NodeId id)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
for(CNode* pnode : vNodes) {
|
||||
if (id == pnode->id) {
|
||||
pnode->fDisconnect = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RelayTransaction(const CTransaction& tx)
|
||||
{
|
||||
CInv inv(MSG_TX, tx.GetHash());
|
||||
|
||||
Reference in New Issue
Block a user