Skip to content

Commit

Permalink
Merge #941: Simplify CountByIP()
Browse files Browse the repository at this point in the history
10c249f Simplify CountByIP()
  • Loading branch information
UdjinM6 authored and schinzelh committed Aug 12, 2016
1 parent df854a5 commit 27cba53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 30 deletions.
36 changes: 8 additions & 28 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/masternodeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 27cba53

Please sign in to comment.