mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
Merge pull request #598 from brain5lug/openssl
copy elimination for ranges #part3
This commit is contained in:
commit
793e80490c
4
SAM.cpp
4
SAM.cpp
@ -686,7 +686,7 @@ namespace client
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_SocketsMutex);
|
||||
for (auto sock : m_Sockets) {
|
||||
for (auto& sock : m_Sockets) {
|
||||
sock->CloseStream();
|
||||
}
|
||||
}
|
||||
@ -719,7 +719,7 @@ namespace client
|
||||
{
|
||||
m_IsRunning = false;
|
||||
m_Acceptor.cancel ();
|
||||
for (auto it: m_Sessions)
|
||||
for (auto& it: m_Sessions)
|
||||
it.second->CloseStreams ();
|
||||
m_Sessions.clear ();
|
||||
m_Service.stop ();
|
||||
|
2
SAM.h
2
SAM.h
@ -154,7 +154,7 @@ namespace client
|
||||
std::list<std::shared_ptr<SAMSocket> > l;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_SocketsMutex);
|
||||
for( auto & sock : m_Sockets ) l.push_back(sock);
|
||||
for(const auto& sock : m_Sockets ) l.push_back(sock);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
22
SSU.cpp
22
SSU.cpp
@ -237,9 +237,8 @@ namespace transport
|
||||
std::map<boost::asio::ip::udp::endpoint, std::shared_ptr<SSUSession> > * sessions)
|
||||
{
|
||||
std::shared_ptr<SSUSession> session;
|
||||
for (auto it1: packets)
|
||||
for (auto& packet: packets)
|
||||
{
|
||||
auto packet = it1;
|
||||
try
|
||||
{
|
||||
if (!session || session->GetRemoteEndpoint () != packet->from) // we received packet for other session than previous
|
||||
@ -431,11 +430,11 @@ namespace transport
|
||||
|
||||
void SSUServer::DeleteAllSessions ()
|
||||
{
|
||||
for (auto it: m_Sessions)
|
||||
for (auto& it: m_Sessions)
|
||||
it.second->Close ();
|
||||
m_Sessions.clear ();
|
||||
|
||||
for (auto it: m_SessionsV6)
|
||||
for (auto& it: m_SessionsV6)
|
||||
it.second->Close ();
|
||||
m_SessionsV6.clear ();
|
||||
}
|
||||
@ -444,7 +443,7 @@ namespace transport
|
||||
std::shared_ptr<SSUSession> SSUServer::GetRandomV4Session (Filter filter) // v4 only
|
||||
{
|
||||
std::vector<std::shared_ptr<SSUSession> > filteredSessions;
|
||||
for (auto s :m_Sessions)
|
||||
for (const auto& s :m_Sessions)
|
||||
if (filter (s.second)) filteredSessions.push_back (s.second);
|
||||
if (filteredSessions.size () > 0)
|
||||
{
|
||||
@ -468,7 +467,7 @@ namespace transport
|
||||
std::shared_ptr<SSUSession> SSUServer::GetRandomV6Session (Filter filter) // v6 only
|
||||
{
|
||||
std::vector<std::shared_ptr<SSUSession> > filteredSessions;
|
||||
for (auto s :m_SessionsV6)
|
||||
for (const auto& s :m_SessionsV6)
|
||||
if (filter (s.second)) filteredSessions.push_back (s.second);
|
||||
if (filteredSessions.size () > 0)
|
||||
{
|
||||
@ -535,7 +534,7 @@ namespace transport
|
||||
std::list<boost::asio::ip::udp::endpoint> newList;
|
||||
size_t numIntroducers = 0;
|
||||
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||
for (auto it :m_Introducers)
|
||||
for (const auto& it : m_Introducers)
|
||||
{
|
||||
auto session = FindSession (it);
|
||||
if (session && ts < session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION)
|
||||
@ -552,11 +551,9 @@ namespace transport
|
||||
{
|
||||
// create new
|
||||
auto introducers = FindIntroducers (SSU_MAX_NUM_INTRODUCERS);
|
||||
if (introducers.size () > 0)
|
||||
for (const auto& it1: introducers)
|
||||
{
|
||||
for (auto it1: introducers)
|
||||
{
|
||||
auto& ep = it1->GetRemoteEndpoint ();
|
||||
const auto& ep = it1->GetRemoteEndpoint ();
|
||||
i2p::data::RouterInfo::Introducer introducer;
|
||||
introducer.iHost = ep.address ();
|
||||
introducer.iPort = ep.port ();
|
||||
@ -569,7 +566,6 @@ namespace transport
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m_Introducers = newList;
|
||||
if (m_Introducers.size () < SSU_MAX_NUM_INTRODUCERS)
|
||||
{
|
||||
@ -637,7 +633,7 @@ namespace transport
|
||||
it = m_PeerTests.erase (it);
|
||||
}
|
||||
else
|
||||
it++;
|
||||
++it;
|
||||
}
|
||||
if (numDeleted > 0)
|
||||
LogPrint (eLogDebug, "SSU: ", numDeleted, " peer tests have been expired");
|
||||
|
@ -444,7 +444,7 @@ namespace transport
|
||||
|
||||
it->second->numResends++;
|
||||
it->second->nextResendTime += it->second->numResends*RESEND_INTERVAL;
|
||||
it++;
|
||||
++it;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -453,7 +453,7 @@ namespace transport
|
||||
}
|
||||
}
|
||||
else
|
||||
it++;
|
||||
++it;
|
||||
}
|
||||
if (numResent < MAX_OUTGOING_WINDOW_SIZE)
|
||||
ScheduleResend ();
|
||||
@ -487,7 +487,7 @@ namespace transport
|
||||
it = m_IncompleteMessages.erase (it);
|
||||
}
|
||||
else
|
||||
it++;
|
||||
++it;
|
||||
}
|
||||
// decay
|
||||
if (m_ReceivedMessages.size () > MAX_NUM_RECEIVED_MESSAGES ||
|
||||
|
@ -907,7 +907,7 @@ namespace transport
|
||||
{
|
||||
if (m_State == eSessionStateEstablished)
|
||||
{
|
||||
for (auto it: msgs)
|
||||
for (const auto& it: msgs)
|
||||
if (it) m_Data.Send (it);
|
||||
}
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ namespace stream
|
||||
if (nacked)
|
||||
{
|
||||
LogPrint (eLogDebug, "Streaming: Packet ", seqn, " NACK");
|
||||
it++;
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -412,7 +412,7 @@ namespace stream
|
||||
}
|
||||
bool isEmpty = m_SentPackets.empty ();
|
||||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||
for (auto it: packets)
|
||||
for (auto& it: packets)
|
||||
{
|
||||
it->sendTime = ts;
|
||||
m_SentPackets.insert (it);
|
||||
@ -762,7 +762,7 @@ namespace stream
|
||||
bool updated = false;
|
||||
if (expired && m_CurrentRemoteLease)
|
||||
{
|
||||
for (auto it: leases)
|
||||
for (const auto& it: leases)
|
||||
if ((it->tunnelGateway == m_CurrentRemoteLease->tunnelGateway) && (it->tunnelID != m_CurrentRemoteLease->tunnelID))
|
||||
{
|
||||
m_CurrentRemoteLease = it;
|
||||
@ -798,7 +798,7 @@ namespace stream
|
||||
|
||||
StreamingDestination::~StreamingDestination ()
|
||||
{
|
||||
for (auto it: m_SavedPackets)
|
||||
for (auto& it: m_SavedPackets)
|
||||
{
|
||||
for (auto it1: it.second) delete it1;
|
||||
it.second.clear ();
|
||||
@ -877,7 +877,7 @@ namespace stream
|
||||
else // follow on packet without SYN
|
||||
{
|
||||
uint32_t receiveStreamID = packet->GetReceiveStreamID ();
|
||||
for (auto it: m_Streams)
|
||||
for (auto& it: m_Streams)
|
||||
if (it.second->GetSendStreamID () == receiveStreamID)
|
||||
{
|
||||
// found
|
||||
@ -944,7 +944,7 @@ namespace stream
|
||||
m_Owner->GetService ().post([acceptor, this](void)
|
||||
{
|
||||
m_Acceptor = acceptor;
|
||||
for (auto it: m_PendingIncomingStreams)
|
||||
for (auto& it: m_PendingIncomingStreams)
|
||||
if (it->GetStatus () == eStreamStatusOpen) // still open?
|
||||
m_Acceptor (it);
|
||||
m_PendingIncomingStreams.clear ();
|
||||
@ -963,7 +963,7 @@ namespace stream
|
||||
if (ecode != boost::asio::error::operation_aborted)
|
||||
{
|
||||
LogPrint (eLogWarning, "Streaming: Pending incoming timeout expired");
|
||||
for (auto it: m_PendingIncomingStreams)
|
||||
for (auto& it: m_PendingIncomingStreams)
|
||||
it->Close ();
|
||||
m_PendingIncomingStreams.clear ();
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ namespace transport
|
||||
m_Thread = new std::thread (std::bind (&Transports::Run, this));
|
||||
// create acceptors
|
||||
auto& addresses = context.GetRouterInfo ().GetAddresses ();
|
||||
for (auto address : addresses)
|
||||
for (const auto& address : addresses)
|
||||
{
|
||||
if (m_NTCPServer == nullptr && enableNTCP)
|
||||
{
|
||||
@ -236,7 +236,7 @@ namespace transport
|
||||
if (ident == i2p::context.GetRouterInfo ().GetIdentHash ())
|
||||
{
|
||||
// we send it to ourself
|
||||
for (auto it: msgs)
|
||||
for (auto& it: msgs)
|
||||
i2p::HandleI2NPMessage (it);
|
||||
return;
|
||||
}
|
||||
@ -266,7 +266,7 @@ namespace transport
|
||||
{
|
||||
if (it->second.delayedMessages.size () < MAX_NUM_DELAYED_MESSAGES)
|
||||
{
|
||||
for (auto it1: msgs)
|
||||
for (auto& it1: msgs)
|
||||
it->second.delayedMessages.push_back (it1);
|
||||
}
|
||||
else
|
||||
@ -636,7 +636,7 @@ namespace transport
|
||||
it = m_Peers.erase (it);
|
||||
}
|
||||
else
|
||||
it++;
|
||||
++it;
|
||||
}
|
||||
UpdateBandwidth (); // TODO: use separate timer(s) for it
|
||||
if (i2p::context.GetStatus () == eRouterStatusTesting) // if still testing, repeat peer test
|
||||
@ -658,7 +658,7 @@ namespace transport
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_FamilyMutex);
|
||||
m_TrustedFamilies.clear();
|
||||
for ( auto fam : families )
|
||||
for ( const auto& fam : families )
|
||||
m_TrustedFamilies.push_back(fam);
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ namespace transport
|
||||
|
||||
void Done ()
|
||||
{
|
||||
for (auto it: sessions)
|
||||
for (auto& it: sessions)
|
||||
it->Done ();
|
||||
}
|
||||
};
|
||||
|
@ -213,7 +213,7 @@ namespace tunnel
|
||||
void CreatePeers (const Peers& peers)
|
||||
{
|
||||
TunnelHopConfig * prev = nullptr;
|
||||
for (auto it: peers)
|
||||
for (const auto& it: peers)
|
||||
{
|
||||
auto hop = new TunnelHopConfig (it);
|
||||
if (prev)
|
||||
|
Loading…
Reference in New Issue
Block a user