diff --git a/AddressBook.cpp b/AddressBook.cpp index cd15d68d..6fdde4eb 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -173,7 +173,7 @@ namespace client return 0; } - for (auto it: addresses) { + for (const auto& it: addresses) { f << it.first << "," << it.second.ToBase32 () << std::endl; num++; } @@ -252,7 +252,7 @@ namespace client } LogPrint (eLogError, "Addressbook: subscription download timeout"); m_IsDownloading = false; - } + } if (m_Storage) { m_Storage->Save (m_Addresses); @@ -260,7 +260,7 @@ namespace client m_Storage = nullptr; } m_DefaultSubscription = nullptr; - for (auto it: m_Subscriptions) + for (auto& it: m_Subscriptions) delete it; m_Subscriptions.clear (); } @@ -418,7 +418,7 @@ namespace client { std::map localAddresses; m_Storage->LoadLocal (localAddresses); - for (auto it: localAddresses) + for (const auto& it: localAddresses) { auto dot = it.first.find ('.'); if (dot != std::string::npos) diff --git a/BOB.cpp b/BOB.cpp index caf766af..8ffffba6 100644 --- a/BOB.cpp +++ b/BOB.cpp @@ -536,8 +536,8 @@ namespace client void BOBCommandSession::ListCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: list"); - auto& destinations = m_Owner.GetDestinations (); - for (auto it: destinations) + const auto& destinations = m_Owner.GetDestinations (); + for (const auto& it: destinations) SendData (it.first.c_str ()); SendReplyOK ("Listing done"); } @@ -619,7 +619,7 @@ namespace client BOBCommandChannel::~BOBCommandChannel () { Stop (); - for (auto it: m_Destinations) + for (const auto& it: m_Destinations) delete it.second; } @@ -633,7 +633,7 @@ namespace client void BOBCommandChannel::Stop () { m_IsRunning = false; - for (auto it: m_Destinations) + for (auto& it: m_Destinations) it.second->Stop (); m_Acceptor.cancel (); m_Service.stop (); diff --git a/ClientContext.cpp b/ClientContext.cpp index 2bc13969..aa18ecdf 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -194,7 +194,7 @@ namespace client LogPrint(eLogInfo, "Clients: stopping AddressBook"); m_AddressBook.Stop (); - for (auto it: m_Destinations) + for (auto& it: m_Destinations) it.second->Stop (); m_Destinations.clear (); m_SharedLocalDestination = nullptr; diff --git a/Destination.cpp b/Destination.cpp index 2df14a9f..b1ab2a6c 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -103,7 +103,7 @@ namespace client { if (m_IsRunning) Stop (); - for (auto it: m_LeaseSetRequests) + for (auto& it: m_LeaseSetRequests) if (it.second->requestComplete) it.second->requestComplete (nullptr); m_LeaseSetRequests.clear (); if (m_Pool) @@ -635,7 +635,7 @@ namespace client it = m_RemoteLeaseSets.erase (it); } else - it++; + ++it; } } @@ -663,7 +663,7 @@ namespace client { m_StreamingDestination = std::make_shared (GetSharedFromThis ()); // TODO: m_StreamingDestination->Start (); - for (auto it: m_StreamingDestinationsByPorts) + for (auto& it: m_StreamingDestinationsByPorts) it.second->Start (); return true; } @@ -677,7 +677,7 @@ namespace client { m_StreamingDestination->Stop (); m_StreamingDestination = nullptr; - for (auto it: m_StreamingDestinationsByPorts) + for (auto& it: m_StreamingDestinationsByPorts) it.second->Stop (); if (m_DatagramDestination) { diff --git a/Garlic.cpp b/Garlic.cpp index d48e9d94..c3c0e045 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -111,7 +111,7 @@ namespace garlic it = m_UnconfirmedTagsMsgs.erase (it); } else - it++; + ++it; } } @@ -123,7 +123,7 @@ namespace garlic if (ts >= it->creationTime + OUTGOING_TAGS_EXPIRATION_TIMEOUT) it = m_SessionTags.erase (it); else - it++; + ++it; } CleanupUnconfirmedTags (); return !m_SessionTags.empty () || !m_UnconfirmedTagsMsgs.empty (); @@ -144,7 +144,7 @@ namespace garlic ret = true; } else - it++; + ++it; } return ret; } @@ -615,7 +615,7 @@ namespace garlic it = m_Tags.erase (it); } else - it++; + ++it; } if (numExpiredTags > 0) LogPrint (eLogDebug, "Garlic: ", numExpiredTags, " tags expired for ", GetIdentHash().ToBase64 ()); @@ -631,7 +631,7 @@ namespace garlic it = m_Sessions.erase (it); } else - it++; + ++it; } } @@ -643,26 +643,26 @@ namespace garlic void GarlicDestination::DeliveryStatusSent (GarlicRoutingSessionPtr session, uint32_t msgID) { m_DeliveryStatusSessions[msgID] = session; - } + } void GarlicDestination::HandleDeliveryStatusMessage (std::shared_ptr msg) { uint32_t msgID = bufbe32toh (msg->GetPayload ()); { auto it = m_DeliveryStatusSessions.find (msgID); - if (it != m_DeliveryStatusSessions.end ()) + if (it != m_DeliveryStatusSessions.end ()) { it->second->MessageConfirmed (msgID); m_DeliveryStatusSessions.erase (it); LogPrint (eLogDebug, "Garlic: message ", msgID, " acknowledged"); - } + } } } void GarlicDestination::SetLeaseSetUpdated () { - std::unique_lock l(m_SessionsMutex); - for (auto it: m_Sessions) + std::unique_lock l(m_SessionsMutex); + for (auto& it: m_Sessions) it.second->SetLeaseSetUpdated (); } diff --git a/HTTP.cpp b/HTTP.cpp index 4a0286a7..08615e5b 100644 --- a/HTTP.cpp +++ b/HTTP.cpp @@ -160,7 +160,7 @@ namespace http { strsplit(query, tokens, '&'); params.clear(); - for (auto it : tokens) { + for (const auto& it : tokens) { std::size_t eq = it.find ('='); if (eq != std::string::npos) { auto e = std::pair(it.substr(0, eq), it.substr(eq + 1)); diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index b35c3b4a..60b6bc33 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -105,7 +105,7 @@ namespace proxy { ss << "

" << description << "

\r\n"; std::string content = ss.str(); SendProxyError(content); - } + } void HTTPReqHandler::HostNotFound(std::string & host) { std::stringstream ss; @@ -113,13 +113,13 @@ namespace proxy { << "

Remote host not found in router's addressbook

\r\n" << "

You may try to find this host on jumpservices below:

\r\n" << "
    \r\n"; - for (auto & js : jumpservices) { + for (const auto& js : jumpservices) { ss << "
  • " << js.first << "
  • \r\n"; } ss << "
\r\n"; std::string content = ss.str(); SendProxyError(content); - } + } void HTTPReqHandler::SendProxyError(std::string & content) { @@ -164,7 +164,7 @@ namespace proxy { req.del_header("Forwarded"); /* drop proxy-disclosing headers */ std::vector toErase; - for (auto it : req.headers) { + for (const auto& it : req.headers) { if (it.first.compare(0, 12, "X-Forwarded-") == 0) { toErase.push_back(it.first); } else if (it.first.compare(0, 6, "Proxy-") == 0) { @@ -173,7 +173,7 @@ namespace proxy { /* allow */ } } - for (auto header : toErase) { + for (const auto& header : toErase) { req.headers.erase(header); } /* replace headers */ diff --git a/HTTPServer.cpp b/HTTPServer.cpp index a811ad45..8ca35100 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -210,7 +210,7 @@ namespace http { s << "Router Family: " << i2p::context.GetRouterInfo().GetProperty("family") << "
\r\n"; s << "Router Caps: " << i2p::context.GetRouterInfo().GetProperty("caps") << "
\r\n"; s << "Our external address:" << "
\r\n" ; - for (auto address : i2p::context.GetRouterInfo().GetAddresses()) + for (const auto& address : i2p::context.GetRouterInfo().GetAddresses()) { switch (address->transportStyle) { @@ -283,7 +283,7 @@ namespace http { } s << "
\r\n"; s << "Tags
Incoming: " << dest->GetNumIncomingTags () << "
Outgoing:
" << std::endl; - for (auto it: dest->GetSessions ()) + for (const auto& it: dest->GetSessions ()) { s << i2p::client::context.GetAddressBook ().ToAddress(it.first) << " "; s << it.second->GetNumOutgoingTags () << "
" << std::endl; @@ -314,7 +314,7 @@ namespace http { s << "Status"; s << ""; - for (auto it: dest->GetAllStreams ()) + for (const auto& it: dest->GetAllStreams ()) { s << ""; s << "" << it->GetSendStreamID () << ""; @@ -432,7 +432,7 @@ namespace http { void ShowTransitTunnels (std::stringstream& s) { s << "Transit tunnels:
\r\n
\r\n"; - for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ()) + for (const auto& it: i2p::tunnel::tunnels.GetTransitTunnels ()) { if (std::dynamic_pointer_cast(it)) s << it->GetTunnelID () << " ⇒ "; @@ -451,7 +451,7 @@ namespace http { if (ntcpServer) { s << "NTCP
\r\n"; - for (auto it: ntcpServer->GetNTCPSessions ()) + for (const auto& it: ntcpServer->GetNTCPSessions ()) { if (it.second && it.second->IsEstablished ()) { @@ -469,7 +469,7 @@ namespace http { if (ssuServer) { s << "
\r\nSSU
\r\n"; - for (auto it: ssuServer->GetSessions ()) + for (const auto& it: ssuServer->GetSessions ()) { auto endpoint = it.second->GetRemoteEndpoint (); if (it.second->IsOutgoing ()) s << " ⇒ "; @@ -481,7 +481,7 @@ namespace http { s << "
\r\n" << std::endl; } s << "
\r\nSSU6
\r\n"; - for (auto it: ssuServer->GetSessionsV6 ()) + for (const auto& it: ssuServer->GetSessionsV6 ()) { auto endpoint = it.second->GetRemoteEndpoint (); if (it.second->IsOutgoing ()) s << " ⇒ "; @@ -526,7 +526,7 @@ namespace http { s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "
\r\n"; s << "
\r\n"; s << "Streams:
\r\n"; - for (auto it: session->ListSockets()) + for (const auto& it: session->ListSockets()) { switch (it->GetSocketType ()) { diff --git a/I2CP.cpp b/I2CP.cpp index 0867d719..0352cd15 100644 --- a/I2CP.cpp +++ b/I2CP.cpp @@ -659,7 +659,7 @@ namespace client { m_IsRunning = false; m_Acceptor.cancel (); - for (auto it: m_Sessions) + for (auto& it: m_Sessions) it.second->Stop (); m_Sessions.clear (); m_Service.stop (); diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 92ab8281..cbd4c3fc 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -202,7 +202,7 @@ namespace i2p len += 32; buf[len] = routers.size (); len++; - for (auto it: routers) + for (const auto& it: routers) { memcpy (buf + len, it, 32); len += 32; diff --git a/I2PControl.cpp b/I2PControl.cpp index a55871a3..3e2e3997 100644 --- a/I2PControl.cpp +++ b/I2PControl.cpp @@ -358,7 +358,7 @@ namespace client void I2PControlService::RouterInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results) { - for (auto it = params.begin (); it != params.end (); it++) + for (auto it = params.begin (); it != params.end (); ++it) { LogPrint (eLogDebug, "I2PControl: RouterInfo request: ", it->first); auto it1 = m_RouterInfoHandlers.find (it->first); @@ -434,7 +434,7 @@ namespace client void I2PControlService::RouterManagerHandler (const boost::property_tree::ptree& params, std::ostringstream& results) { - for (auto it = params.begin (); it != params.end (); it++) + for (auto it = params.begin (); it != params.end (); ++it) { if (it != params.begin ()) results << ","; LogPrint (eLogDebug, "I2PControl: RouterManager request: ", it->first); @@ -483,7 +483,7 @@ namespace client // network setting void I2PControlService::NetworkSettingHandler (const boost::property_tree::ptree& params, std::ostringstream& results) { - for (auto it = params.begin (); it != params.end (); it++) + for (auto it = params.begin (); it != params.end (); ++it) { if (it != params.begin ()) results << ","; LogPrint (eLogDebug, "I2PControl: NetworkSetting request: ", it->first); diff --git a/LeaseSet.cpp b/LeaseSet.cpp index fafe14b7..89cad0df 100644 --- a/LeaseSet.cpp +++ b/LeaseSet.cpp @@ -64,10 +64,10 @@ namespace data return; } - // reset existing leases + // reset existing leases if (m_StoreLeases) - for (auto it: m_Leases) - it->isUpdated = false; + for (auto& it: m_Leases) + it->isUpdated = false; else m_Leases.clear (); @@ -123,7 +123,7 @@ namespace data m_Leases.erase (it++); } else - it++; + ++it; } } @@ -167,7 +167,7 @@ namespace data { auto ts = i2p::util::GetMillisecondsSinceEpoch (); std::vector > leases; - for (auto it: m_Leases) + for (const auto& it: m_Leases) { auto endDate = it->endDate; if (withThreshold) @@ -183,7 +183,7 @@ namespace data bool LeaseSet::HasExpiredLeases () const { auto ts = i2p::util::GetMillisecondsSinceEpoch (); - for (auto it: m_Leases) + for (const auto& it: m_Leases) if (ts >= it->endDate) return true; return false; } diff --git a/NetDb.cpp b/NetDb.cpp index 6ef5df7f..dc018326 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -51,7 +51,7 @@ namespace data { if (m_IsRunning) { - for (auto it: m_RouterInfos) + for (auto& it: m_RouterInfos) it.second->SaveProfile (); DeleteObsoleteProfiles (); m_RouterInfos.clear (); @@ -339,7 +339,7 @@ namespace data m_LastLoad = i2p::util::GetSecondsSinceEpoch(); std::vector files; m_Storage.Traverse(files); - for (auto path : files) + for (const auto& path : files) LoadRouterInfo(path); LogPrint (eLogInfo, "NetDb: ", m_RouterInfos.size(), " routers loaded (", m_Floodfills.size (), " floodfils)"); @@ -357,7 +357,7 @@ namespace data expirationTimeout = i2p::context.IsFloodfill () ? NETDB_FLOODFILL_EXPIRATION_TIMEOUT*1000LL : NETDB_MIN_EXPIRATION_TIMEOUT*1000LL + (NETDB_MAX_EXPIRATION_TIMEOUT - NETDB_MIN_EXPIRATION_TIMEOUT)*1000LL*NETDB_MIN_ROUTERS/total; - for (auto it: m_RouterInfos) + for (auto& it: m_RouterInfos) { std::string ident = it.second->GetIdentHashBase64(); std::string path = m_Storage.Path(ident); @@ -405,7 +405,7 @@ namespace data it = m_RouterInfos.erase (it); continue; } - it++; + ++it; } } // clean up expired floodfiils @@ -415,7 +415,7 @@ namespace data if ((*it)->IsUnreachable ()) it = m_Floodfills.erase (it); else - it++; + ++it; } } } @@ -901,7 +901,7 @@ namespace data { uint32_t i = 0; std::unique_lock l(m_RouterInfosMutex); - for (auto it: m_RouterInfos) + for (const auto& it: m_RouterInfos) { if (i >= ind) { @@ -933,7 +933,7 @@ namespace data else minMetric.SetMax (); std::unique_lock l(m_FloodfillsMutex); - for (auto it: m_Floodfills) + for (const auto& it: m_Floodfills) { if (!it->IsUnreachable ()) { @@ -964,7 +964,7 @@ namespace data if (closeThanUsOnly) ourMetric = destKey ^ i2p::context.GetIdentHash (); { std::unique_lock l(m_FloodfillsMutex); - for (auto it: m_Floodfills) + for (const auto& it: m_Floodfills) { if (!it->IsUnreachable ()) { @@ -983,11 +983,11 @@ namespace data std::vector res; size_t i = 0; - for (auto it: sorted) + for (const auto& it: sorted) { if (i < num) { - auto& ident = it.r->GetIdentHash (); + const auto& ident = it.r->GetIdentHash (); if (!excluded.count (ident)) { res.push_back (ident); @@ -1016,7 +1016,7 @@ namespace data IdentHash destKey = CreateRoutingKey (destination); minMetric.SetMax (); // must be called from NetDb thread only - for (auto it: m_RouterInfos) + for (const auto& it: m_RouterInfos) { if (!it.second->IsFloodfill ()) { @@ -1042,7 +1042,7 @@ namespace data it = m_LeaseSets.erase (it); } else - it++; + ++it; } } @@ -1054,7 +1054,7 @@ namespace data if (ts > it->second.second + 180) // 3 minutes it = m_LookupResponses.erase (it); else - it++; + ++it; } } } diff --git a/NetDbRequests.cpp b/NetDbRequests.cpp index e1ea2872..c3966597 100644 --- a/NetDbRequests.cpp +++ b/NetDbRequests.cpp @@ -141,7 +141,7 @@ namespace data if (done) it = m_RequestedDestinations.erase (it); else - it++; + ++it; } } } diff --git a/Profiling.cpp b/Profiling.cpp index be675502..890a2620 100644 --- a/Profiling.cpp +++ b/Profiling.cpp @@ -167,7 +167,7 @@ namespace data std::vector files; m_ProfilesStorage.Traverse(files); - for (auto path: files) { + for (const auto& path: files) { if (stat(path.c_str(), &st) != 0) { LogPrint(eLogWarning, "Profiling: Can't stat(): ", path); continue; diff --git a/Queue.h b/Queue.h index b47a19c8..39d139b9 100644 --- a/Queue.h +++ b/Queue.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace i2p { @@ -20,7 +21,7 @@ namespace util void Put (Element e) { std::unique_lock l(m_QueueMutex); - m_Queue.push (e); + m_Queue.push (std::move(e)); m_NonEmpty.notify_one (); } @@ -29,7 +30,7 @@ namespace util if (!vec.empty ()) { std::unique_lock l(m_QueueMutex); - for (auto it: vec) + for (const auto& it: vec) m_Queue.push (it); m_NonEmpty.notify_one (); } diff --git a/Tunnel.h b/Tunnel.h index 0d35b682..5bc8b195 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -224,7 +224,7 @@ namespace tunnel std::list> m_Pools; std::shared_ptr m_ExploratoryPool; i2p::util::Queue > m_Queue; - + // some stats int m_NumSuccesiveTunnelCreations, m_NumFailedTunnelCreations;