diff --git a/src/net.cpp b/src/net.cpp --- a/src/net.cpp +++ b/src/net.cpp @@ -129,11 +129,10 @@ const int64_t nOneWeek = 7 * 24 * 60 * 60; std::vector vSeedsOut; vSeedsOut.reserve(vSeedsIn.size()); - for (std::vector::const_iterator i(vSeedsIn.begin()); - i != vSeedsIn.end(); ++i) { + for (const auto &seed_in : vSeedsIn) { struct in6_addr ip; - memcpy(&ip, i->addr, sizeof(ip)); - CAddress addr(CService(ip, i->port), NODE_NETWORK); + memcpy(&ip, seed_in.addr, sizeof(ip)); + CAddress addr(CService(ip, seed_in.port), NODE_NETWORK); addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek; vSeedsOut.push_back(addr); } @@ -282,7 +281,7 @@ CNode *CConnman::FindNode(const CNetAddr &ip) { LOCK(cs_vNodes); for (CNode *pnode : vNodes) { - if ((CNetAddr)pnode->addr == ip) { + if (static_cast(pnode->addr) == ip) { return pnode; } } @@ -292,7 +291,7 @@ CNode *CConnman::FindNode(const CSubNet &subNet) { LOCK(cs_vNodes); for (CNode *pnode : vNodes) { - if (subNet.Match((CNetAddr)pnode->addr)) { + if (subNet.Match(static_cast(pnode->addr))) { return pnode; } } @@ -312,7 +311,7 @@ CNode *CConnman::FindNode(const CService &addr) { LOCK(cs_vNodes); for (CNode *pnode : vNodes) { - if ((CService)pnode->addr == addr) { + if (static_cast(pnode->addr) == addr) { return pnode; } } @@ -321,7 +320,7 @@ bool CConnman::CheckIncomingNonce(uint64_t nonce) { LOCK(cs_vNodes); - for (CNode *pnode : vNodes) { + for (const CNode *pnode : vNodes) { if (!pnode->fSuccessfullyConnected && !pnode->fInbound && pnode->GetLocalNonce() == nonce) return false; @@ -353,7 +352,7 @@ } // Look for an existing connection - CNode *pnode = FindNode((CService)addrConnect); + CNode *pnode = FindNode(static_cast(addrConnect)); if (pnode) { LogPrintf("Failed to open new connection, already connected\n"); return nullptr; @@ -1116,10 +1115,9 @@ // Disconnect from the network group with the most connections NodeId evicted = vEvictionCandidates.front().id; LOCK(cs_vNodes); - for (std::vector::const_iterator it(vNodes.begin()); - it != vNodes.end(); ++it) { - if ((*it)->GetId() == evicted) { - (*it)->fDisconnect = true; + for (CNode *pnode : vNodes) { + if (pnode->GetId() == evicted) { + pnode->fDisconnect = true; return true; } } @@ -1144,7 +1142,7 @@ bool whitelisted = hListenSocket.whitelisted || IsWhitelistedRange(addr); { LOCK(cs_vNodes); - for (CNode *pnode : vNodes) { + for (const CNode *pnode : vNodes) { if (pnode->fInbound) { nInbound++; } @@ -1512,8 +1510,8 @@ (GetTimeMicros() - pnode->nPingUsecStart)); pnode->fDisconnect = true; } else if (!pnode->fSuccessfullyConnected) { - LogPrintf("version handshake timeout from %d\n", - pnode->GetId()); + LogPrint(BCLog::NET, "version handshake timeout from %d\n", + pnode->GetId()); pnode->fDisconnect = true; } } @@ -1538,11 +1536,11 @@ #ifdef USE_UPNP static CThreadInterrupt g_upnp_interrupt; static std::thread g_upnp_thread; -void ThreadMapPort() { +static void ThreadMapPort() { std::string port = strprintf("%u", GetListenPort()); - const char *multicastif = 0; - const char *minissdpdpath = 0; - struct UPNPDev *devlist = 0; + const char *multicastif = nullptr; + const char *minissdpdpath = nullptr; + struct UPNPDev *devlist = nullptr; char lanaddr[64]; #ifndef UPNPDISCOVER_SUCCESS @@ -1619,7 +1617,7 @@ } else { LogPrintf("No valid UPnP IGDs found\n"); freeUPNPDevlist(devlist); - devlist = 0; + devlist = nullptr; if (r != 0) { FreeUPNPUrls(&urls); } @@ -1687,7 +1685,7 @@ LOCK(cs_vNodes); int nRelevant = 0; - for (auto pnode : vNodes) { + for (const CNode *pnode : vNodes) { nRelevant += pnode->fSuccessfullyConnected && !pnode->fFeeler && !pnode->fOneShot && !pnode->m_manual_connection && !pnode->fInbound; @@ -1791,7 +1789,7 @@ int nOutbound = 0; { LOCK(cs_vNodes); - for (CNode *pnode : vNodes) { + for (const CNode *pnode : vNodes) { if (!pnode->fInbound && !pnode->m_manual_connection && !pnode->fFeeler && !pnode->fDisconnect && !pnode->fOneShot && pnode->fSuccessfullyConnected) { @@ -1868,7 +1866,7 @@ std::set> setConnected; { LOCK(cs_vNodes); - for (CNode *pnode : vNodes) { + for (const CNode *pnode : vNodes) { if (!pnode->fInbound && !pnode->m_manual_connection) { // Netgroups for inbound and addnode peers are not excluded // because our goal here is to not use multiple of our @@ -2448,7 +2446,7 @@ } if (clientInterface) { - clientInterface->InitMessage(_("Loading addresses...")); + clientInterface->InitMessage(_("Loading P2P addresses...")); } // Load addresses from peers.dat int64_t nStart = GetTimeMillis(); @@ -2695,9 +2693,8 @@ bool CConnman::AddNode(const std::string &strNode) { LOCK(cs_vAddedNodes); - for (std::vector::const_iterator it = vAddedNodes.begin(); - it != vAddedNodes.end(); ++it) { - if (strNode == *it) { + for (const std::string &it : vAddedNodes) { + if (strNode == it) { return false; } } @@ -2726,9 +2723,8 @@ } int nNum = 0; - for (std::vector::const_iterator it = vNodes.begin(); - it != vNodes.end(); ++it) { - if (flags & ((*it)->fInbound ? CONNECTIONS_IN : CONNECTIONS_OUT)) { + for (const auto &pnode : vNodes) { + if (flags & (pnode->fInbound ? CONNECTIONS_IN : CONNECTIONS_OUT)) { nNum++; } }