aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2016-04-16 18:30:03 -0400
committerCory Fields <cory-nospam-@coryfields.com>2016-09-08 12:12:58 -0400
commitc0569c7fa1e25599b3f1d6a16b15ec23052021da (patch)
tree608dc14407c8f28de2d6480910a13883dc47cefe /src/net.cpp
parent8ae2dac1c65349e4620422a43b7fa9d49af52c11 (diff)
downloadbitcoin-c0569c7fa1e25599b3f1d6a16b15ec23052021da.tar.xz
net: Add most functions needed for vNodes to CConnman
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 8ca6df0f9b..e1cfc565d6 100644
--- a/src/net.cpp
+++ b/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());