mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
use same outbound tunnel for streaming as long as possible
This commit is contained in:
parent
a25fe85b4d
commit
dda80703d2
4 changed files with 28 additions and 15 deletions
|
@ -74,23 +74,29 @@ namespace tunnel
|
|||
return v;
|
||||
}
|
||||
|
||||
OutboundTunnel * TunnelPool::GetNextOutboundTunnel ()
|
||||
OutboundTunnel * TunnelPool::GetNextOutboundTunnel (OutboundTunnel * suggested)
|
||||
{
|
||||
return GetNextTunnel (m_OutboundTunnels);
|
||||
return GetNextTunnel (m_OutboundTunnels, suggested);
|
||||
}
|
||||
|
||||
InboundTunnel * TunnelPool::GetNextInboundTunnel ()
|
||||
InboundTunnel * TunnelPool::GetNextInboundTunnel (InboundTunnel * suggested)
|
||||
{
|
||||
return GetNextTunnel (m_InboundTunnels);
|
||||
return GetNextTunnel (m_InboundTunnels, suggested);
|
||||
}
|
||||
|
||||
template<class TTunnels>
|
||||
typename TTunnels::value_type TunnelPool::GetNextTunnel (TTunnels& tunnels)
|
||||
typename TTunnels::value_type TunnelPool::GetNextTunnel (TTunnels& tunnels,
|
||||
typename TTunnels::value_type suggested)
|
||||
{
|
||||
if (tunnels.empty ()) return nullptr;
|
||||
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||
if (suggested && tunnels.count (suggested) > 0 &&
|
||||
ts + TUNNEL_EXPIRATION_THRESHOLD <= suggested->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||
return suggested;
|
||||
for (auto it: tunnels)
|
||||
if (!it->IsFailed ())
|
||||
return it;
|
||||
if (!it->IsFailed () && ts + TUNNEL_EXPIRATION_THRESHOLD <=
|
||||
it->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||
return it;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue