Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify CountByIP() #941

Merged
merged 1 commit into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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