mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
check tunnel status instead fidning it every time
This commit is contained in:
parent
763547f465
commit
192a08b5bf
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
|||
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…
Reference in a new issue