mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-30 20:24:15 +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 ())
|
||||
{
|
||||
it.second->Print (s);
|
||||
auto state = it.second->GetState ();
|
||||
it->Print (s);
|
||||
auto state = it->GetState ();
|
||||
if (state == i2p::tunnel::eTunnelStateFailed)
|
||||
s << "<span class=failed_tunnel> " << "Failed</span>";
|
||||
else if (state == i2p::tunnel::eTunnelStateExpiring)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
29
Tunnel.cpp
29
Tunnel.cpp
@ -258,14 +258,6 @@ namespace tunnel
|
||||
Tunnels::~Tunnels ()
|
||||
{
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -303,11 +295,11 @@ namespace tunnel
|
||||
size_t minReceived = 0;
|
||||
for (auto it : m_InboundTunnels)
|
||||
{
|
||||
if (!it.second->IsEstablished ()) continue;
|
||||
if (!tunnel || it.second->GetNumReceivedBytes () < minReceived)
|
||||
if (!it->IsEstablished ()) continue;
|
||||
if (!tunnel || it->GetNumReceivedBytes () < minReceived)
|
||||
{
|
||||
tunnel = it.second;
|
||||
minReceived = it.second->GetNumReceivedBytes ();
|
||||
tunnel = it;
|
||||
minReceived = it->GetNumReceivedBytes ();
|
||||
}
|
||||
}
|
||||
return tunnel;
|
||||
@ -615,7 +607,7 @@ namespace tunnel
|
||||
{
|
||||
for (auto it = m_InboundTunnels.begin (); it != m_InboundTunnels.end ();)
|
||||
{
|
||||
auto tunnel = it->second;
|
||||
auto tunnel = *it;
|
||||
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||
{
|
||||
LogPrint (eLogDebug, "Tunnel: tunnel with id ", tunnel->GetTunnelID (), " expired");
|
||||
@ -749,7 +741,7 @@ namespace tunnel
|
||||
{
|
||||
if (m_Tunnels.emplace (newTunnel->GetTunnelID (), newTunnel).second)
|
||||
{
|
||||
m_InboundTunnels[newTunnel->GetTunnelID ()] = newTunnel;
|
||||
m_InboundTunnels.push_back (newTunnel);
|
||||
auto pool = newTunnel->GetTunnelPool ();
|
||||
if (!pool)
|
||||
{
|
||||
@ -793,17 +785,20 @@ namespace tunnel
|
||||
return timeout;
|
||||
}
|
||||
|
||||
size_t Tunnels::CountTransitTunnels() {
|
||||
size_t Tunnels::CountTransitTunnels() const
|
||||
{
|
||||
// TODO: locking
|
||||
return m_TransitTunnels.size();
|
||||
}
|
||||
|
||||
size_t Tunnels::CountInboundTunnels() {
|
||||
size_t Tunnels::CountInboundTunnels() const
|
||||
{
|
||||
// TODO: locking
|
||||
return m_InboundTunnels.size();
|
||||
}
|
||||
|
||||
size_t Tunnels::CountOutboundTunnels() {
|
||||
size_t Tunnels::CountOutboundTunnels() const
|
||||
{
|
||||
// TODO: locking
|
||||
return m_OutboundTunnels.size();
|
||||
}
|
||||
|
9
Tunnel.h
9
Tunnel.h
@ -137,7 +137,6 @@ namespace tunnel
|
||||
void Start ();
|
||||
void Stop ();
|
||||
|
||||
std::shared_ptr<InboundTunnel> GetInboundTunnel (uint32_t tunnelID);
|
||||
std::shared_ptr<InboundTunnel> GetPendingInboundTunnel (uint32_t replyMsgID);
|
||||
std::shared_ptr<OutboundTunnel> GetPendingOutboundTunnel (uint32_t replyMsgID);
|
||||
std::shared_ptr<InboundTunnel> GetNextInboundTunnel ();
|
||||
@ -184,7 +183,7 @@ namespace tunnel
|
||||
std::thread * m_Thread;
|
||||
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<InboundTunnel> > m_InboundTunnels;
|
||||
std::list<std::shared_ptr<InboundTunnel> > m_InboundTunnels;
|
||||
std::list<std::shared_ptr<OutboundTunnel> > m_OutboundTunnels;
|
||||
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
|
||||
@ -203,9 +202,9 @@ namespace tunnel
|
||||
const decltype(m_InboundTunnels)& GetInboundTunnels () const { return m_InboundTunnels; };
|
||||
const decltype(m_TransitTunnels)& GetTransitTunnels () const { return m_TransitTunnels; };
|
||||
|
||||
size_t CountTransitTunnels();
|
||||
size_t CountInboundTunnels();
|
||||
size_t CountOutboundTunnels();
|
||||
size_t CountTransitTunnels() const;
|
||||
size_t CountInboundTunnels() const;
|
||||
size_t CountOutboundTunnels() const;
|
||||
|
||||
int GetQueueSize () { return m_Queue.GetSize (); };
|
||||
int GetTunnelCreationSuccessRate () const // in percents
|
||||
|
Loading…
x
Reference in New Issue
Block a user