Skip to content

Commit 27cba53

Browse files
UdjinM6schinzelh
authored andcommitted
Merge bitcoin#941: Simplify CountByIP()
10c249f Simplify CountByIP()
1 parent df854a5 commit 27cba53

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

src/masternodeman.cpp

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -218,38 +218,18 @@ int CMasternodeMan::CountEnabled(int protocolVersion)
218218
return i;
219219
}
220220

221-
int CMasternodeMan::CountByIP(int nodeType)
221+
int CMasternodeMan::CountByIP(int nNetworkType)
222222
{
223-
int nIPv4_nodes = 0;
224-
int nIPv6_nodes = 0;
225-
int nTOR_nodes = 0;
223+
int nNodeCount = 0;
226224

227-
BOOST_FOREACH(CMasternode& mn, vMasternodes) {
228-
if(mn.addr.IsIPv6()){
229-
nIPv6_nodes++;
230-
} else if(mn.addr.IsTor()){
231-
nTOR_nodes++;
232-
}
233-
else{
234-
nIPv4_nodes++; // Must be IPv4 if it isn't IPv6 or TOR
225+
BOOST_FOREACH(CMasternode& mn, vMasternodes)
226+
if( (nNetworkType == NET_IPV4 && mn.addr.IsIPv4()) ||
227+
(nNetworkType == NET_TOR && mn.addr.IsTor()) ||
228+
(nNetworkType == NET_IPV6 && mn.addr.IsIPv6())) {
229+
nNodeCount++;
235230
}
236-
}
237-
238-
switch(nodeType)
239-
{
240-
case NET_IPV4:
241-
return nIPv4_nodes;
242-
243-
case NET_IPV6:
244-
return nIPv6_nodes;
245-
246-
case NET_TOR:
247-
return nTOR_nodes;
248-
249-
default:
250-
return nIPv4_nodes + nIPv6_nodes + nTOR_nodes; // Default: return all nodes
251-
}
252231

232+
return nNodeCount;
253233
}
254234

255235
void CMasternodeMan::DsegUpdate(CNode* pnode)

src/masternodeman.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ class CMasternodeMan
8585
void Clear();
8686

8787
int CountEnabled(int protocolVersion = -1);
88-
89-
int CountByIP(int nodeType);
88+
89+
/// Count Masternodes by network type - NET_IPV4, NET_IPV6, NET_TOR
90+
int CountByIP(int nNetworkType);
9091

9192
void DsegUpdate(CNode* pnode);
9293

0 commit comments

Comments
 (0)