mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-07 07:44:13 +00:00
replace std::map to std::list for inbound tunnels
This commit is contained in:
parent
5d41fe4a35
commit
ef6028e933
@ -610,13 +610,13 @@ namespace util
|
|||||||
|
|
||||||
for (auto it: i2p::tunnel::tunnels.GetInboundTunnels ())
|
for (auto it: i2p::tunnel::tunnels.GetInboundTunnels ())
|
||||||
{
|
{
|
||||||
it.second->Print (s);
|
it->Print (s);
|
||||||
auto state = it.second->GetState ();
|
auto state = it->GetState ();
|
||||||
if (state == i2p::tunnel::eTunnelStateFailed)
|
if (state == i2p::tunnel::eTunnelStateFailed)
|
||||||
s << "<span class=failed_tunnel> " << "Failed</span>";
|
s << "<span class=failed_tunnel> " << "Failed</span>";
|
||||||
else if (state == i2p::tunnel::eTunnelStateExpiring)
|
else if (state == i2p::tunnel::eTunnelStateExpiring)
|
||||||
s << "<span class=expiring_tunnel> " << "Exp</span>";
|
s << "<span class=expiring_tunnel> " << "Exp</span>";
|
||||||
s << " " << (int)it.second->GetNumReceivedBytes () << "<br>\r\n";
|
s << " " << (int)it->GetNumReceivedBytes () << "<br>\r\n";
|
||||||
s << std::endl;
|
s << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
Tunnel.cpp
29
Tunnel.cpp
@ -259,14 +259,6 @@ namespace tunnel
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<InboundTunnel> Tunnels::GetInboundTunnel (uint32_t tunnelID)
|
|
||||||
{
|
|
||||||
auto it = m_InboundTunnels.find(tunnelID);
|
|
||||||
if (it != m_InboundTunnels.end ())
|
|
||||||
return it->second;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<TunnelBase> Tunnels::GetTunnel (uint32_t tunnelID)
|
std::shared_ptr<TunnelBase> Tunnels::GetTunnel (uint32_t tunnelID)
|
||||||
{
|
{
|
||||||
auto it = m_Tunnels.find(tunnelID);
|
auto it = m_Tunnels.find(tunnelID);
|
||||||
@ -303,11 +295,11 @@ namespace tunnel
|
|||||||
size_t minReceived = 0;
|
size_t minReceived = 0;
|
||||||
for (auto it : m_InboundTunnels)
|
for (auto it : m_InboundTunnels)
|
||||||
{
|
{
|
||||||
if (!it.second->IsEstablished ()) continue;
|
if (!it->IsEstablished ()) continue;
|
||||||
if (!tunnel || it.second->GetNumReceivedBytes () < minReceived)
|
if (!tunnel || it->GetNumReceivedBytes () < minReceived)
|
||||||
{
|
{
|
||||||
tunnel = it.second;
|
tunnel = it;
|
||||||
minReceived = it.second->GetNumReceivedBytes ();
|
minReceived = it->GetNumReceivedBytes ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tunnel;
|
return tunnel;
|
||||||
@ -615,7 +607,7 @@ namespace tunnel
|
|||||||
{
|
{
|
||||||
for (auto it = m_InboundTunnels.begin (); it != m_InboundTunnels.end ();)
|
for (auto it = m_InboundTunnels.begin (); it != m_InboundTunnels.end ();)
|
||||||
{
|
{
|
||||||
auto tunnel = it->second;
|
auto tunnel = *it;
|
||||||
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "Tunnel: tunnel with id ", tunnel->GetTunnelID (), " expired");
|
LogPrint (eLogDebug, "Tunnel: tunnel with id ", tunnel->GetTunnelID (), " expired");
|
||||||
@ -749,7 +741,7 @@ namespace tunnel
|
|||||||
{
|
{
|
||||||
if (m_Tunnels.emplace (newTunnel->GetTunnelID (), newTunnel).second)
|
if (m_Tunnels.emplace (newTunnel->GetTunnelID (), newTunnel).second)
|
||||||
{
|
{
|
||||||
m_InboundTunnels[newTunnel->GetTunnelID ()] = newTunnel;
|
m_InboundTunnels.push_back (newTunnel);
|
||||||
auto pool = newTunnel->GetTunnelPool ();
|
auto pool = newTunnel->GetTunnelPool ();
|
||||||
if (!pool)
|
if (!pool)
|
||||||
{
|
{
|
||||||
@ -793,17 +785,20 @@ namespace tunnel
|
|||||||
return timeout;
|
return timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Tunnels::CountTransitTunnels() {
|
size_t Tunnels::CountTransitTunnels() const
|
||||||
|
{
|
||||||
// TODO: locking
|
// TODO: locking
|
||||||
return m_TransitTunnels.size();
|
return m_TransitTunnels.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Tunnels::CountInboundTunnels() {
|
size_t Tunnels::CountInboundTunnels() const
|
||||||
|
{
|
||||||
// TODO: locking
|
// TODO: locking
|
||||||
return m_InboundTunnels.size();
|
return m_InboundTunnels.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Tunnels::CountOutboundTunnels() {
|
size_t Tunnels::CountOutboundTunnels() const
|
||||||
|
{
|
||||||
// TODO: locking
|
// TODO: locking
|
||||||
return m_OutboundTunnels.size();
|
return m_OutboundTunnels.size();
|
||||||
}
|
}
|
||||||
|
9
Tunnel.h
9
Tunnel.h
@ -137,7 +137,6 @@ namespace tunnel
|
|||||||
void Start ();
|
void Start ();
|
||||||
void Stop ();
|
void Stop ();
|
||||||
|
|
||||||
std::shared_ptr<InboundTunnel> GetInboundTunnel (uint32_t tunnelID);
|
|
||||||
std::shared_ptr<InboundTunnel> GetPendingInboundTunnel (uint32_t replyMsgID);
|
std::shared_ptr<InboundTunnel> GetPendingInboundTunnel (uint32_t replyMsgID);
|
||||||
std::shared_ptr<OutboundTunnel> GetPendingOutboundTunnel (uint32_t replyMsgID);
|
std::shared_ptr<OutboundTunnel> GetPendingOutboundTunnel (uint32_t replyMsgID);
|
||||||
std::shared_ptr<InboundTunnel> GetNextInboundTunnel ();
|
std::shared_ptr<InboundTunnel> GetNextInboundTunnel ();
|
||||||
@ -184,7 +183,7 @@ namespace tunnel
|
|||||||
std::thread * m_Thread;
|
std::thread * m_Thread;
|
||||||
std::map<uint32_t, std::shared_ptr<InboundTunnel> > m_PendingInboundTunnels; // by replyMsgID
|
std::map<uint32_t, std::shared_ptr<InboundTunnel> > m_PendingInboundTunnels; // by replyMsgID
|
||||||
std::map<uint32_t, std::shared_ptr<OutboundTunnel> > m_PendingOutboundTunnels; // by replyMsgID
|
std::map<uint32_t, std::shared_ptr<OutboundTunnel> > m_PendingOutboundTunnels; // by replyMsgID
|
||||||
std::map<uint32_t, std::shared_ptr<InboundTunnel> > m_InboundTunnels;
|
std::list<std::shared_ptr<InboundTunnel> > m_InboundTunnels;
|
||||||
std::list<std::shared_ptr<OutboundTunnel> > m_OutboundTunnels;
|
std::list<std::shared_ptr<OutboundTunnel> > m_OutboundTunnels;
|
||||||
std::list<std::shared_ptr<TransitTunnel> > m_TransitTunnels;
|
std::list<std::shared_ptr<TransitTunnel> > m_TransitTunnels;
|
||||||
std::unordered_map<uint32_t, std::shared_ptr<TunnelBase> > m_Tunnels; // tunnelID->tunnel known by this id
|
std::unordered_map<uint32_t, std::shared_ptr<TunnelBase> > m_Tunnels; // tunnelID->tunnel known by this id
|
||||||
@ -203,9 +202,9 @@ namespace tunnel
|
|||||||
const decltype(m_InboundTunnels)& GetInboundTunnels () const { return m_InboundTunnels; };
|
const decltype(m_InboundTunnels)& GetInboundTunnels () const { return m_InboundTunnels; };
|
||||||
const decltype(m_TransitTunnels)& GetTransitTunnels () const { return m_TransitTunnels; };
|
const decltype(m_TransitTunnels)& GetTransitTunnels () const { return m_TransitTunnels; };
|
||||||
|
|
||||||
size_t CountTransitTunnels();
|
size_t CountTransitTunnels() const;
|
||||||
size_t CountInboundTunnels();
|
size_t CountInboundTunnels() const;
|
||||||
size_t CountOutboundTunnels();
|
size_t CountOutboundTunnels() const;
|
||||||
|
|
||||||
int GetQueueSize () { return m_Queue.GetSize (); };
|
int GetQueueSize () { return m_Queue.GetSize (); };
|
||||||
int GetTunnelCreationSuccessRate () const // in percents
|
int GetTunnelCreationSuccessRate () const // in percents
|
||||||
|
Loading…
x
Reference in New Issue
Block a user