Browse Source

Merge pull request #598 from brain5lug/openssl

copy elimination for ranges #part3
pull/603/head
orignal 8 years ago committed by GitHub
parent
commit
793e80490c
  1. 4
      SAM.cpp
  2. 2
      SAM.h
  3. 42
      SSU.cpp
  4. 14
      SSUData.cpp
  5. 2
      SSUSession.cpp
  6. 16
      Streaming.cpp
  7. 10
      Transports.cpp
  8. 2
      Transports.h
  9. 2
      TunnelConfig.h

4
SAM.cpp

@ -686,7 +686,7 @@ namespace client
{ {
{ {
std::lock_guard<std::mutex> lock(m_SocketsMutex); std::lock_guard<std::mutex> lock(m_SocketsMutex);
for (auto sock : m_Sockets) { for (auto& sock : m_Sockets) {
sock->CloseStream(); sock->CloseStream();
} }
} }
@ -719,7 +719,7 @@ namespace client
{ {
m_IsRunning = false; m_IsRunning = false;
m_Acceptor.cancel (); m_Acceptor.cancel ();
for (auto it: m_Sessions) for (auto& it: m_Sessions)
it.second->CloseStreams (); it.second->CloseStreams ();
m_Sessions.clear (); m_Sessions.clear ();
m_Service.stop (); m_Service.stop ();

2
SAM.h

@ -154,7 +154,7 @@ namespace client
std::list<std::shared_ptr<SAMSocket> > l; std::list<std::shared_ptr<SAMSocket> > l;
{ {
std::lock_guard<std::mutex> lock(m_SocketsMutex); 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; return l;
} }

42
SSU.cpp

@ -237,9 +237,8 @@ namespace transport
std::map<boost::asio::ip::udp::endpoint, std::shared_ptr<SSUSession> > * sessions) std::map<boost::asio::ip::udp::endpoint, std::shared_ptr<SSUSession> > * sessions)
{ {
std::shared_ptr<SSUSession> session; std::shared_ptr<SSUSession> session;
for (auto it1: packets) for (auto& packet: packets)
{ {
auto packet = it1;
try try
{ {
if (!session || session->GetRemoteEndpoint () != packet->from) // we received packet for other session than previous if (!session || session->GetRemoteEndpoint () != packet->from) // we received packet for other session than previous
@ -431,11 +430,11 @@ namespace transport
void SSUServer::DeleteAllSessions () void SSUServer::DeleteAllSessions ()
{ {
for (auto it: m_Sessions) for (auto& it: m_Sessions)
it.second->Close (); it.second->Close ();
m_Sessions.clear (); m_Sessions.clear ();
for (auto it: m_SessionsV6) for (auto& it: m_SessionsV6)
it.second->Close (); it.second->Close ();
m_SessionsV6.clear (); m_SessionsV6.clear ();
} }
@ -444,7 +443,7 @@ namespace transport
std::shared_ptr<SSUSession> SSUServer::GetRandomV4Session (Filter filter) // v4 only std::shared_ptr<SSUSession> SSUServer::GetRandomV4Session (Filter filter) // v4 only
{ {
std::vector<std::shared_ptr<SSUSession> > filteredSessions; 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 (filter (s.second)) filteredSessions.push_back (s.second);
if (filteredSessions.size () > 0) if (filteredSessions.size () > 0)
{ {
@ -468,7 +467,7 @@ namespace transport
std::shared_ptr<SSUSession> SSUServer::GetRandomV6Session (Filter filter) // v6 only std::shared_ptr<SSUSession> SSUServer::GetRandomV6Session (Filter filter) // v6 only
{ {
std::vector<std::shared_ptr<SSUSession> > filteredSessions; 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 (filter (s.second)) filteredSessions.push_back (s.second);
if (filteredSessions.size () > 0) if (filteredSessions.size () > 0)
{ {
@ -535,7 +534,7 @@ namespace transport
std::list<boost::asio::ip::udp::endpoint> newList; std::list<boost::asio::ip::udp::endpoint> newList;
size_t numIntroducers = 0; size_t numIntroducers = 0;
uint32_t ts = i2p::util::GetSecondsSinceEpoch (); uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
for (auto it :m_Introducers) for (const auto& it : m_Introducers)
{ {
auto session = FindSession (it); auto session = FindSession (it);
if (session && ts < session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION) if (session && ts < session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION)
@ -552,23 +551,20 @@ namespace transport
{ {
// create new // create new
auto introducers = FindIntroducers (SSU_MAX_NUM_INTRODUCERS); auto introducers = FindIntroducers (SSU_MAX_NUM_INTRODUCERS);
if (introducers.size () > 0) for (const auto& it1: introducers)
{ {
for (auto it1: introducers) const auto& ep = it1->GetRemoteEndpoint ();
i2p::data::RouterInfo::Introducer introducer;
introducer.iHost = ep.address ();
introducer.iPort = ep.port ();
introducer.iTag = it1->GetRelayTag ();
introducer.iKey = it1->GetIntroKey ();
if (i2p::context.AddIntroducer (introducer))
{ {
auto& ep = it1->GetRemoteEndpoint (); newList.push_back (ep);
i2p::data::RouterInfo::Introducer introducer; if (newList.size () >= SSU_MAX_NUM_INTRODUCERS) break;
introducer.iHost = ep.address (); }
introducer.iPort = ep.port (); }
introducer.iTag = it1->GetRelayTag ();
introducer.iKey = it1->GetIntroKey ();
if (i2p::context.AddIntroducer (introducer))
{
newList.push_back (ep);
if (newList.size () >= SSU_MAX_NUM_INTRODUCERS) break;
}
}
}
} }
m_Introducers = newList; m_Introducers = newList;
if (m_Introducers.size () < SSU_MAX_NUM_INTRODUCERS) if (m_Introducers.size () < SSU_MAX_NUM_INTRODUCERS)
@ -637,7 +633,7 @@ namespace transport
it = m_PeerTests.erase (it); it = m_PeerTests.erase (it);
} }
else else
it++; ++it;
} }
if (numDeleted > 0) if (numDeleted > 0)
LogPrint (eLogDebug, "SSU: ", numDeleted, " peer tests have been expired"); LogPrint (eLogDebug, "SSU: ", numDeleted, " peer tests have been expired");

14
SSUData.cpp

@ -427,12 +427,12 @@ namespace transport
if (ts >= it->second->nextResendTime) if (ts >= it->second->nextResendTime)
{ {
if (it->second->numResends < MAX_NUM_RESENDS) if (it->second->numResends < MAX_NUM_RESENDS)
{ {
for (auto& f: it->second->fragments) for (auto& f: it->second->fragments)
if (f) if (f)
{ {
try try
{ {
m_Session.Send (f->buf, f->len); // resend m_Session.Send (f->buf, f->len); // resend
numResent++; numResent++;
} }
@ -440,11 +440,11 @@ namespace transport
{ {
LogPrint (eLogWarning, "SSU: Can't resend data fragment ", ec.what ()); LogPrint (eLogWarning, "SSU: Can't resend data fragment ", ec.what ());
} }
} }
it->second->numResends++; it->second->numResends++;
it->second->nextResendTime += it->second->numResends*RESEND_INTERVAL; it->second->nextResendTime += it->second->numResends*RESEND_INTERVAL;
it++; ++it;
} }
else else
{ {
@ -453,7 +453,7 @@ namespace transport
} }
} }
else else
it++; ++it;
} }
if (numResent < MAX_OUTGOING_WINDOW_SIZE) if (numResent < MAX_OUTGOING_WINDOW_SIZE)
ScheduleResend (); ScheduleResend ();
@ -487,7 +487,7 @@ namespace transport
it = m_IncompleteMessages.erase (it); it = m_IncompleteMessages.erase (it);
} }
else else
it++; ++it;
} }
// decay // decay
if (m_ReceivedMessages.size () > MAX_NUM_RECEIVED_MESSAGES || if (m_ReceivedMessages.size () > MAX_NUM_RECEIVED_MESSAGES ||

2
SSUSession.cpp

@ -907,7 +907,7 @@ namespace transport
{ {
if (m_State == eSessionStateEstablished) if (m_State == eSessionStateEstablished)
{ {
for (auto it: msgs) for (const auto& it: msgs)
if (it) m_Data.Send (it); if (it) m_Data.Send (it);
} }
} }

16
Streaming.cpp

@ -247,7 +247,7 @@ namespace stream
} }
int nackCount = packet->GetNACKCount (); int nackCount = packet->GetNACKCount ();
for (auto it = m_SentPackets.begin (); it != m_SentPackets.end ();) for (auto it = m_SentPackets.begin (); it != m_SentPackets.end ();)
{ {
auto seqn = (*it)->GetSeqn (); auto seqn = (*it)->GetSeqn ();
if (seqn <= ackThrough) if (seqn <= ackThrough)
{ {
@ -263,7 +263,7 @@ namespace stream
if (nacked) if (nacked)
{ {
LogPrint (eLogDebug, "Streaming: Packet ", seqn, " NACK"); LogPrint (eLogDebug, "Streaming: Packet ", seqn, " NACK");
it++; ++it;
continue; continue;
} }
} }
@ -412,7 +412,7 @@ namespace stream
} }
bool isEmpty = m_SentPackets.empty (); bool isEmpty = m_SentPackets.empty ();
auto ts = i2p::util::GetMillisecondsSinceEpoch (); auto ts = i2p::util::GetMillisecondsSinceEpoch ();
for (auto it: packets) for (auto& it: packets)
{ {
it->sendTime = ts; it->sendTime = ts;
m_SentPackets.insert (it); m_SentPackets.insert (it);
@ -762,7 +762,7 @@ namespace stream
bool updated = false; bool updated = false;
if (expired && m_CurrentRemoteLease) if (expired && m_CurrentRemoteLease)
{ {
for (auto it: leases) for (const auto& it: leases)
if ((it->tunnelGateway == m_CurrentRemoteLease->tunnelGateway) && (it->tunnelID != m_CurrentRemoteLease->tunnelID)) if ((it->tunnelGateway == m_CurrentRemoteLease->tunnelGateway) && (it->tunnelID != m_CurrentRemoteLease->tunnelID))
{ {
m_CurrentRemoteLease = it; m_CurrentRemoteLease = it;
@ -798,7 +798,7 @@ namespace stream
StreamingDestination::~StreamingDestination () StreamingDestination::~StreamingDestination ()
{ {
for (auto it: m_SavedPackets) for (auto& it: m_SavedPackets)
{ {
for (auto it1: it.second) delete it1; for (auto it1: it.second) delete it1;
it.second.clear (); it.second.clear ();
@ -877,7 +877,7 @@ namespace stream
else // follow on packet without SYN else // follow on packet without SYN
{ {
uint32_t receiveStreamID = packet->GetReceiveStreamID (); uint32_t receiveStreamID = packet->GetReceiveStreamID ();
for (auto it: m_Streams) for (auto& it: m_Streams)
if (it.second->GetSendStreamID () == receiveStreamID) if (it.second->GetSendStreamID () == receiveStreamID)
{ {
// found // found
@ -944,7 +944,7 @@ namespace stream
m_Owner->GetService ().post([acceptor, this](void) m_Owner->GetService ().post([acceptor, this](void)
{ {
m_Acceptor = acceptor; m_Acceptor = acceptor;
for (auto it: m_PendingIncomingStreams) for (auto& it: m_PendingIncomingStreams)
if (it->GetStatus () == eStreamStatusOpen) // still open? if (it->GetStatus () == eStreamStatusOpen) // still open?
m_Acceptor (it); m_Acceptor (it);
m_PendingIncomingStreams.clear (); m_PendingIncomingStreams.clear ();
@ -963,7 +963,7 @@ namespace stream
if (ecode != boost::asio::error::operation_aborted) if (ecode != boost::asio::error::operation_aborted)
{ {
LogPrint (eLogWarning, "Streaming: Pending incoming timeout expired"); LogPrint (eLogWarning, "Streaming: Pending incoming timeout expired");
for (auto it: m_PendingIncomingStreams) for (auto& it: m_PendingIncomingStreams)
it->Close (); it->Close ();
m_PendingIncomingStreams.clear (); m_PendingIncomingStreams.clear ();
} }

10
Transports.cpp

@ -112,7 +112,7 @@ namespace transport
m_Thread = new std::thread (std::bind (&Transports::Run, this)); m_Thread = new std::thread (std::bind (&Transports::Run, this));
// create acceptors // create acceptors
auto& addresses = context.GetRouterInfo ().GetAddresses (); auto& addresses = context.GetRouterInfo ().GetAddresses ();
for (auto address : addresses) for (const auto& address : addresses)
{ {
if (m_NTCPServer == nullptr && enableNTCP) if (m_NTCPServer == nullptr && enableNTCP)
{ {
@ -236,7 +236,7 @@ namespace transport
if (ident == i2p::context.GetRouterInfo ().GetIdentHash ()) if (ident == i2p::context.GetRouterInfo ().GetIdentHash ())
{ {
// we send it to ourself // we send it to ourself
for (auto it: msgs) for (auto& it: msgs)
i2p::HandleI2NPMessage (it); i2p::HandleI2NPMessage (it);
return; return;
} }
@ -266,7 +266,7 @@ namespace transport
{ {
if (it->second.delayedMessages.size () < MAX_NUM_DELAYED_MESSAGES) if (it->second.delayedMessages.size () < MAX_NUM_DELAYED_MESSAGES)
{ {
for (auto it1: msgs) for (auto& it1: msgs)
it->second.delayedMessages.push_back (it1); it->second.delayedMessages.push_back (it1);
} }
else else
@ -636,7 +636,7 @@ namespace transport
it = m_Peers.erase (it); it = m_Peers.erase (it);
} }
else else
it++; ++it;
} }
UpdateBandwidth (); // TODO: use separate timer(s) for it UpdateBandwidth (); // TODO: use separate timer(s) for it
if (i2p::context.GetStatus () == eRouterStatusTesting) // if still testing, repeat peer test 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); std::lock_guard<std::mutex> lock(m_FamilyMutex);
m_TrustedFamilies.clear(); m_TrustedFamilies.clear();
for ( auto fam : families ) for ( const auto& fam : families )
m_TrustedFamilies.push_back(fam); m_TrustedFamilies.push_back(fam);
} }

2
Transports.h

@ -60,7 +60,7 @@ namespace transport
void Done () void Done ()
{ {
for (auto it: sessions) for (auto& it: sessions)
it->Done (); it->Done ();
} }
}; };

2
TunnelConfig.h

@ -213,7 +213,7 @@ namespace tunnel
void CreatePeers (const Peers& peers) void CreatePeers (const Peers& peers)
{ {
TunnelHopConfig * prev = nullptr; TunnelHopConfig * prev = nullptr;
for (auto it: peers) for (const auto& it: peers)
{ {
auto hop = new TunnelHopConfig (it); auto hop = new TunnelHopConfig (it);
if (prev) if (prev)

Loading…
Cancel
Save