Browse Source

check tunnel status instead fidning it every time

pull/151/head
orignal 10 years ago
parent
commit
192a08b5bf
  1. 3
      Streaming.cpp
  2. 16
      TunnelPool.cpp
  3. 7
      TunnelPool.h

3
Streaming.cpp

@ -504,7 +504,8 @@ namespace stream @@ -504,7 +504,8 @@ namespace stream
return;
}
}
m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ().GetTunnelPool ()->GetNextOutboundTunnel (m_CurrentOutboundTunnel);
if (!m_CurrentOutboundTunnel || !m_CurrentOutboundTunnel->IsEstablished ())
m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ().GetTunnelPool ()->GetNextOutboundTunnel ();
if (!m_CurrentOutboundTunnel)
{
LogPrint ("No outbound tunnels in the pool");

16
TunnelPool.cpp

@ -101,26 +101,22 @@ namespace tunnel @@ -101,26 +101,22 @@ namespace tunnel
return v;
}
std::shared_ptr<OutboundTunnel> TunnelPool::GetNextOutboundTunnel (std::shared_ptr<OutboundTunnel> suggested) const
std::shared_ptr<OutboundTunnel> TunnelPool::GetNextOutboundTunnel () const
{
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
return GetNextTunnel (m_OutboundTunnels, suggested);
return GetNextTunnel (m_OutboundTunnels);
}
std::shared_ptr<InboundTunnel> TunnelPool::GetNextInboundTunnel (std::shared_ptr<InboundTunnel> suggested) const
std::shared_ptr<InboundTunnel> TunnelPool::GetNextInboundTunnel () const
{
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
return GetNextTunnel (m_InboundTunnels, suggested);
return GetNextTunnel (m_InboundTunnels);
}
template<class TTunnels>
typename TTunnels::value_type TunnelPool::GetNextTunnel (TTunnels& tunnels,
typename TTunnels::value_type suggested) const
typename TTunnels::value_type TunnelPool::GetNextTunnel (TTunnels& tunnels) const
{
if (tunnels.empty ()) return nullptr;
if (suggested && tunnels.count (suggested) > 0 && suggested->IsEstablished ())
return suggested;
if (tunnels.empty ()) return nullptr;
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
uint32_t ind = rnd.GenerateWord32 (0, tunnels.size ()/2), i = 0;
typename TTunnels::value_type tunnel = nullptr;

7
TunnelPool.h

@ -39,8 +39,8 @@ namespace tunnel @@ -39,8 +39,8 @@ namespace tunnel
void TunnelCreated (std::shared_ptr<OutboundTunnel> createdTunnel);
void TunnelExpired (std::shared_ptr<OutboundTunnel> expiredTunnel);
std::vector<std::shared_ptr<InboundTunnel> > GetInboundTunnels (int num) const;
std::shared_ptr<OutboundTunnel> GetNextOutboundTunnel (std::shared_ptr<OutboundTunnel> suggested = nullptr) const;
std::shared_ptr<InboundTunnel> GetNextInboundTunnel (std::shared_ptr<InboundTunnel> suggested = nullptr) const;
std::shared_ptr<OutboundTunnel> GetNextOutboundTunnel () const;
std::shared_ptr<InboundTunnel> GetNextInboundTunnel () const;
void TestTunnels ();
void ProcessGarlicMessage (I2NPMessage * msg);
@ -57,8 +57,7 @@ namespace tunnel @@ -57,8 +57,7 @@ namespace tunnel
void RecreateInboundTunnel (std::shared_ptr<InboundTunnel> tunnel);
void RecreateOutboundTunnel (std::shared_ptr<OutboundTunnel> tunnel);
template<class TTunnels>
typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels,
typename TTunnels::value_type suggested = nullptr) const;
typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels) const;
std::shared_ptr<const i2p::data::RouterInfo> SelectNextHop (std::shared_ptr<const i2p::data::RouterInfo> prevHop) const;
private:

Loading…
Cancel
Save