Skip to content

Commit

Permalink
check tunnel status instead fidning it every time
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Jan 28, 2015
1 parent 763547f commit 192a08b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Streaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
16 changes: 6 additions & 10 deletions TunnelPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions TunnelPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
Expand Down

0 comments on commit 192a08b

Please sign in to comment.