@@ -135,11 +135,10 @@ static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &vSeedsIn
135
135
const int64_t nOneWeek = 7 *24 *60 *60 ;
136
136
std::vector<CAddress> vSeedsOut;
137
137
vSeedsOut.reserve (vSeedsIn.size ());
138
- for (std::vector<SeedSpec6>::const_iterator i (vSeedsIn.begin ()); i != vSeedsIn.end (); ++i)
139
- {
138
+ for (const auto & seed_in : vSeedsIn) {
140
139
struct in6_addr ip;
141
- memcpy (&ip, i-> addr , sizeof (ip));
142
- CAddress addr (CService (ip, i-> port ), NODE_NETWORK);
140
+ memcpy (&ip, seed_in. addr , sizeof (ip));
141
+ CAddress addr (CService (ip, seed_in. port ), NODE_NETWORK);
143
142
addr.nTime = GetTime () - GetRand (nOneWeek) - nOneWeek;
144
143
vSeedsOut.push_back (addr);
145
144
}
@@ -299,18 +298,22 @@ bool IsReachable(const CNetAddr& addr)
299
298
CNode* CConnman::FindNode (const CNetAddr& ip)
300
299
{
301
300
LOCK (cs_vNodes);
302
- for (CNode* pnode : vNodes)
303
- if ((CNetAddr)pnode->addr == ip)
304
- return (pnode);
301
+ for (CNode* pnode : vNodes) {
302
+ if ((CNetAddr)pnode->addr == ip) {
303
+ return pnode;
304
+ }
305
+ }
305
306
return nullptr ;
306
307
}
307
308
308
309
CNode* CConnman::FindNode (const CSubNet& subNet)
309
310
{
310
311
LOCK (cs_vNodes);
311
- for (CNode* pnode : vNodes)
312
- if (subNet.Match ((CNetAddr)pnode->addr ))
313
- return (pnode);
312
+ for (CNode* pnode : vNodes) {
313
+ if (subNet.Match ((CNetAddr)pnode->addr )) {
314
+ return pnode;
315
+ }
316
+ }
314
317
return nullptr ;
315
318
}
316
319
@@ -319,7 +322,7 @@ CNode* CConnman::FindNode(const std::string& addrName)
319
322
LOCK (cs_vNodes);
320
323
for (CNode* pnode : vNodes) {
321
324
if (pnode->GetAddrName () == addrName) {
322
- return ( pnode) ;
325
+ return pnode;
323
326
}
324
327
}
325
328
return nullptr ;
@@ -328,9 +331,11 @@ CNode* CConnman::FindNode(const std::string& addrName)
328
331
CNode* CConnman::FindNode (const CService& addr)
329
332
{
330
333
LOCK (cs_vNodes);
331
- for (CNode* pnode : vNodes)
332
- if ((CService)pnode->addr == addr)
333
- return (pnode);
334
+ for (CNode* pnode : vNodes) {
335
+ if ((CService)pnode->addr == addr) {
336
+ return pnode;
337
+ }
338
+ }
334
339
return nullptr ;
335
340
}
336
341
@@ -474,10 +479,9 @@ void CConnman::ClearBanned()
474
479
bool CConnman::IsBanned (CNetAddr ip)
475
480
{
476
481
LOCK (cs_setBanned);
477
- for (banmap_t ::iterator it = setBanned.begin (); it != setBanned.end (); it++)
478
- {
479
- CSubNet subNet = (*it).first ;
480
- CBanEntry banEntry = (*it).second ;
482
+ for (const auto & it : setBanned) {
483
+ CSubNet subNet = it.first ;
484
+ CBanEntry banEntry = it.second ;
481
485
482
486
if (subNet.Match (ip) && GetTime () < banEntry.nBanUntil ) {
483
487
return true ;
@@ -952,7 +956,7 @@ bool CConnman::AttemptToEvictConnection()
952
956
{
953
957
LOCK (cs_vNodes);
954
958
955
- for (CNode * node : vNodes) {
959
+ for (const CNode* node : vNodes) {
956
960
if (node->fWhitelisted )
957
961
continue ;
958
962
if (!node->fInbound )
@@ -1030,9 +1034,9 @@ bool CConnman::AttemptToEvictConnection()
1030
1034
// Disconnect from the network group with the most connections
1031
1035
NodeId evicted = vEvictionCandidates.front ().id ;
1032
1036
LOCK (cs_vNodes);
1033
- for (std::vector< CNode*>::const_iterator it (vNodes. begin ()); it != vNodes. end (); ++it ) {
1034
- if ((*it) ->GetId () == evicted) {
1035
- (*it) ->fDisconnect = true ;
1037
+ for ( CNode* pnode : vNodes) {
1038
+ if (pnode ->GetId () == evicted) {
1039
+ pnode ->fDisconnect = true ;
1036
1040
return true ;
1037
1041
}
1038
1042
}
@@ -1056,9 +1060,9 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
1056
1060
bool whitelisted = hListenSocket.whitelisted || IsWhitelistedRange (addr);
1057
1061
{
1058
1062
LOCK (cs_vNodes);
1059
- for (CNode* pnode : vNodes)
1060
- if (pnode->fInbound )
1061
- nInbound++;
1063
+ for (const CNode* pnode : vNodes) {
1064
+ if (pnode->fInbound ) nInbound++;
1065
+ }
1062
1066
}
1063
1067
1064
1068
if (hSocket == INVALID_SOCKET)
@@ -1850,8 +1854,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo()
1850
1854
{
1851
1855
LOCK (cs_vAddedNodes);
1852
1856
ret.reserve (vAddedNodes.size ());
1853
- for (const std::string& strAddNode : vAddedNodes)
1854
- lAddresses.push_back (strAddNode);
1857
+ std::copy (vAddedNodes.cbegin (), vAddedNodes.cend (), std::back_inserter (lAddresses));
1855
1858
}
1856
1859
1857
1860
@@ -2488,9 +2491,8 @@ std::vector<CAddress> CConnman::GetAddresses()
2488
2491
bool CConnman::AddNode (const std::string& strNode)
2489
2492
{
2490
2493
LOCK (cs_vAddedNodes);
2491
- for (std::vector<std::string>::const_iterator it = vAddedNodes.begin (); it != vAddedNodes.end (); ++it) {
2492
- if (strNode == *it)
2493
- return false ;
2494
+ for (const std::string& it : vAddedNodes) {
2495
+ if (strNode == it) return false ;
2494
2496
}
2495
2497
2496
2498
vAddedNodes.push_back (strNode);
@@ -2516,9 +2518,11 @@ size_t CConnman::GetNodeCount(NumConnections flags)
2516
2518
return vNodes.size ();
2517
2519
2518
2520
int nNum = 0 ;
2519
- for (std::vector<CNode*>::const_iterator it = vNodes. begin (); it != vNodes. end (); ++it)
2520
- if (flags & ((*it) ->fInbound ? CONNECTIONS_IN : CONNECTIONS_OUT))
2521
+ for ( const auto & pnode : vNodes) {
2522
+ if (flags & (pnode ->fInbound ? CONNECTIONS_IN : CONNECTIONS_OUT)) {
2521
2523
nNum++;
2524
+ }
2525
+ }
2522
2526
2523
2527
return nNum;
2524
2528
}
@@ -2528,8 +2532,7 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats)
2528
2532
vstats.clear ();
2529
2533
LOCK (cs_vNodes);
2530
2534
vstats.reserve (vNodes.size ());
2531
- for (std::vector<CNode*>::iterator it = vNodes.begin (); it != vNodes.end (); ++it) {
2532
- CNode* pnode = *it;
2535
+ for (CNode* pnode : vNodes) {
2533
2536
vstats.emplace_back ();
2534
2537
pnode->copyStats (vstats.back ());
2535
2538
}
0 commit comments