From 27cba53e64a9b3b504e5d487fa1e9770d6b6c0a2 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 12 Aug 2016 09:58:55 +0400 Subject: [PATCH] Merge #941: Simplify CountByIP() 10c249f Simplify CountByIP() --- src/masternodeman.cpp | 36 ++++++++---------------------------- src/masternodeman.h | 5 +++-- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index c208a7b0b94fa..3f3f58615bf23 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -218,38 +218,18 @@ int CMasternodeMan::CountEnabled(int protocolVersion) return i; } -int CMasternodeMan::CountByIP(int nodeType) +int CMasternodeMan::CountByIP(int nNetworkType) { - int nIPv4_nodes = 0; - int nIPv6_nodes = 0; - int nTOR_nodes = 0; + int nNodeCount = 0; - BOOST_FOREACH(CMasternode& mn, vMasternodes) { - if(mn.addr.IsIPv6()){ - nIPv6_nodes++; - } else if(mn.addr.IsTor()){ - nTOR_nodes++; - } - else{ - nIPv4_nodes++; // Must be IPv4 if it isn't IPv6 or TOR + BOOST_FOREACH(CMasternode& mn, vMasternodes) + if( (nNetworkType == NET_IPV4 && mn.addr.IsIPv4()) || + (nNetworkType == NET_TOR && mn.addr.IsTor()) || + (nNetworkType == NET_IPV6 && mn.addr.IsIPv6())) { + nNodeCount++; } - } - - switch(nodeType) - { - case NET_IPV4: - return nIPv4_nodes; - - case NET_IPV6: - return nIPv6_nodes; - - case NET_TOR: - return nTOR_nodes; - - default: - return nIPv4_nodes + nIPv6_nodes + nTOR_nodes; // Default: return all nodes - } + return nNodeCount; } void CMasternodeMan::DsegUpdate(CNode* pnode) diff --git a/src/masternodeman.h b/src/masternodeman.h index 207ef6151b9e9..560403700cc0e 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -85,8 +85,9 @@ class CMasternodeMan void Clear(); int CountEnabled(int protocolVersion = -1); - - int CountByIP(int nodeType); + + /// Count Masternodes by network type - NET_IPV4, NET_IPV6, NET_TOR + int CountByIP(int nNetworkType); void DsegUpdate(CNode* pnode);