Browse Source

mark failed tunnels

pull/48/head
orignal 10 years ago
parent
commit
20369cf6d5
  1. 28
      Tunnel.cpp
  2. 5
      Tunnel.h
  3. 19
      TunnelPool.cpp

28
Tunnel.cpp

@ -14,7 +14,8 @@ namespace i2p
namespace tunnel namespace tunnel
{ {
Tunnel::Tunnel (TunnelConfig * config): m_Config (config), m_Pool (nullptr), m_IsEstablished (false) Tunnel::Tunnel (TunnelConfig * config): m_Config (config), m_Pool (nullptr),
m_IsEstablished (false), m_IsFailed (false)
{ {
} }
@ -225,11 +226,14 @@ namespace tunnel
InboundTunnel * tunnel = nullptr; InboundTunnel * tunnel = nullptr;
size_t minReceived = 0; size_t minReceived = 0;
for (auto it : m_InboundTunnels) for (auto it : m_InboundTunnels)
{
if (it.second->IsFailed ()) continue;
if (!tunnel || it.second->GetNumReceivedBytes () < minReceived) if (!tunnel || it.second->GetNumReceivedBytes () < minReceived)
{ {
tunnel = it.second; tunnel = it.second;
minReceived = it.second->GetNumReceivedBytes (); minReceived = it.second->GetNumReceivedBytes ();
} }
}
return tunnel; return tunnel;
} }
@ -240,7 +244,7 @@ namespace tunnel
for (auto it : m_InboundTunnels) for (auto it : m_InboundTunnels)
{ {
if (i >= num) break; if (i >= num) break;
if (it.second->GetNextIdentHash () != i2p::context.GetRouterInfo ().GetIdentHash ()) if (!it.second->IsFailed () && it.second->GetNextIdentHash () != i2p::context.GetRouterInfo ().GetIdentHash ())
{ {
// exclude one hop tunnels // exclude one hop tunnels
v.push_back (it.second); v.push_back (it.second);
@ -254,23 +258,17 @@ namespace tunnel
{ {
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
uint32_t ind = rnd.GenerateWord32 (0, m_OutboundTunnels.size () - 1), i = 0; uint32_t ind = rnd.GenerateWord32 (0, m_OutboundTunnels.size () - 1), i = 0;
OutboundTunnel * tunnel = nullptr;
for (auto it: m_OutboundTunnels) for (auto it: m_OutboundTunnels)
{ {
if (i >= ind) return it; if (i >= ind) return it;
else i++; if (!it->IsFailed ())
}
return nullptr;
// TODO: implement it base on profiling
/*OutboundTunnel * tunnel = nullptr;
size_t minSent = 0;
for (auto it : m_OutboundTunnels)
if (!tunnel || it->GetNumSentBytes () < minSent)
{ {
tunnel = it; tunnel = it;
minSent = it->GetNumSentBytes (); i++;
} }
return tunnel;*/ }
return tunnel;
} }
TunnelPool * Tunnels::CreateTunnelPool (i2p::data::LocalDestination * localDestination) TunnelPool * Tunnels::CreateTunnelPool (i2p::data::LocalDestination * localDestination)

5
Tunnel.h

@ -37,6 +37,9 @@ namespace tunnel
TunnelConfig * GetTunnelConfig () const { return m_Config; } TunnelConfig * GetTunnelConfig () const { return m_Config; }
bool IsEstablished () const { return m_IsEstablished; }; bool IsEstablished () const { return m_IsEstablished; };
bool IsFailed () const { return m_IsEstablished; };
void SetFailed (bool failed) { m_IsFailed = failed; }
TunnelPool * GetTunnelPool () const { return m_Pool; }; TunnelPool * GetTunnelPool () const { return m_Pool; };
void SetTunnelPool (TunnelPool * pool) { m_Pool = pool; }; void SetTunnelPool (TunnelPool * pool) { m_Pool = pool; };
@ -57,7 +60,7 @@ namespace tunnel
TunnelConfig * m_Config; TunnelConfig * m_Config;
TunnelPool * m_Pool; // pool, tunnel belongs to, or null TunnelPool * m_Pool; // pool, tunnel belongs to, or null
bool m_IsEstablished; bool m_IsEstablished, m_IsFailed;
CryptoPP::ECB_Mode<CryptoPP::AES>::Decryption m_ECBDecryption; CryptoPP::ECB_Mode<CryptoPP::AES>::Decryption m_ECBDecryption;
CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption m_CBCDecryption; CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption m_CBCDecryption;

19
TunnelPool.cpp

@ -31,8 +31,6 @@ namespace tunnel
void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel) void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel)
{ {
m_InboundTunnels.insert (createdTunnel); m_InboundTunnels.insert (createdTunnel);
if (m_LocalDestination)
m_LocalDestination->UpdateLeaseSet ();
} }
void TunnelPool::TunnelExpired (InboundTunnel * expiredTunnel) void TunnelPool::TunnelExpired (InboundTunnel * expiredTunnel)
@ -54,10 +52,10 @@ namespace tunnel
void TunnelPool::TunnelExpired (OutboundTunnel * expiredTunnel) void TunnelPool::TunnelExpired (OutboundTunnel * expiredTunnel)
{ {
if (expiredTunnel) if (expiredTunnel)
{ {
expiredTunnel->SetTunnelPool (nullptr); expiredTunnel->SetTunnelPool (nullptr);
m_OutboundTunnels.erase (expiredTunnel); m_OutboundTunnels.erase (expiredTunnel);
} }
if (expiredTunnel == m_LastOutboundTunnel) if (expiredTunnel == m_LastOutboundTunnel)
m_LastOutboundTunnel = nullptr; m_LastOutboundTunnel = nullptr;
} }
@ -69,8 +67,11 @@ namespace tunnel
for (auto it : m_InboundTunnels) for (auto it : m_InboundTunnels)
{ {
if (i >= num) break; if (i >= num) break;
v.push_back (it); if (!it->IsFailed ())
i++; {
v.push_back (it);
i++;
}
} }
return v; return v;
} }
@ -82,7 +83,7 @@ namespace tunnel
if (m_LastOutboundTunnel && tunnel == m_LastOutboundTunnel) if (m_LastOutboundTunnel && tunnel == m_LastOutboundTunnel)
{ {
for (auto it: m_OutboundTunnels) for (auto it: m_OutboundTunnels)
if (it != m_LastOutboundTunnel) if (it != m_LastOutboundTunnel && !it->IsFailed ())
{ {
tunnel = it; tunnel = it;
break; break;
@ -109,8 +110,8 @@ namespace tunnel
{ {
LogPrint ("Tunnel test ", (int)it.first, " failed"); LogPrint ("Tunnel test ", (int)it.first, " failed");
// both outbound and inbound tunnels considered as invalid // both outbound and inbound tunnels considered as invalid
TunnelExpired (it.second.first); it.second.first->SetFailed (true);
TunnelExpired (it.second.second); it.second.second->SetFailed (true);
} }
m_Tests.clear (); m_Tests.clear ();
auto it1 = m_OutboundTunnels.begin (); auto it1 = m_OutboundTunnels.begin ();

Loading…
Cancel
Save