|
|
@ -164,6 +164,21 @@ namespace tunnel |
|
|
|
uint32_t ind = rand () % (tunnels.size ()/2 + 1), i = 0; |
|
|
|
uint32_t ind = rand () % (tunnels.size ()/2 + 1), i = 0; |
|
|
|
typename TTunnels::value_type tunnel = nullptr; |
|
|
|
typename TTunnels::value_type tunnel = nullptr; |
|
|
|
for (const auto& it: tunnels) |
|
|
|
for (const auto& it: tunnels) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (it->IsEstablished () && it != excluded) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(HasLatencyRequirement() && it->LatencyIsKnown() && !it->LatencyFitsRange(m_MinLatency, m_MaxLatency)) { |
|
|
|
|
|
|
|
i ++; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tunnel = it; |
|
|
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (i > ind && tunnel) break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(HasLatencyRequirement() && !tunnel) { |
|
|
|
|
|
|
|
ind = rand () % (tunnels.size ()/2 + 1), i = 0; |
|
|
|
|
|
|
|
for (const auto& it: tunnels) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (it->IsEstablished () && it != excluded) |
|
|
|
if (it->IsEstablished () && it != excluded) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -172,6 +187,7 @@ namespace tunnel |
|
|
|
} |
|
|
|
} |
|
|
|
if (i > ind && tunnel) break; |
|
|
|
if (i > ind && tunnel) break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (!tunnel && excluded && excluded->IsEstablished ()) tunnel = excluded; |
|
|
|
if (!tunnel && excluded && excluded->IsEstablished ()) tunnel = excluded; |
|
|
|
return tunnel; |
|
|
|
return tunnel; |
|
|
|
} |
|
|
|
} |
|
|
@ -322,7 +338,12 @@ namespace tunnel |
|
|
|
test.first->SetState (eTunnelStateEstablished); |
|
|
|
test.first->SetState (eTunnelStateEstablished); |
|
|
|
if (test.second->GetState () == eTunnelStateTestFailed) |
|
|
|
if (test.second->GetState () == eTunnelStateTestFailed) |
|
|
|
test.second->SetState (eTunnelStateEstablished); |
|
|
|
test.second->SetState (eTunnelStateEstablished); |
|
|
|
LogPrint (eLogDebug, "Tunnels: test of ", msgID, " successful. ", i2p::util::GetMillisecondsSinceEpoch () - timestamp, " milliseconds"); |
|
|
|
uint64_t dlt = i2p::util::GetMillisecondsSinceEpoch () - timestamp; |
|
|
|
|
|
|
|
LogPrint (eLogDebug, "Tunnels: test of ", msgID, " successful. ", dlt, " milliseconds"); |
|
|
|
|
|
|
|
// update latency
|
|
|
|
|
|
|
|
uint64_t latency = dlt / 2; |
|
|
|
|
|
|
|
test.first->AddLatencySample(latency); |
|
|
|
|
|
|
|
test.second->AddLatencySample(latency); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
@ -523,5 +544,37 @@ namespace tunnel |
|
|
|
std::lock_guard<std::mutex> lock(m_CustomPeerSelectorMutex); |
|
|
|
std::lock_guard<std::mutex> lock(m_CustomPeerSelectorMutex); |
|
|
|
return m_CustomPeerSelector != nullptr; |
|
|
|
return m_CustomPeerSelector != nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<InboundTunnel> TunnelPool::GetLowestLatencyInboundTunnel(std::shared_ptr<InboundTunnel> exclude) const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::shared_ptr<InboundTunnel> tun = nullptr; |
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_InboundTunnelsMutex); |
|
|
|
|
|
|
|
uint64_t min = 1000000; |
|
|
|
|
|
|
|
for (const auto & itr : m_InboundTunnels) { |
|
|
|
|
|
|
|
if(!itr->LatencyIsKnown()) continue; |
|
|
|
|
|
|
|
auto l = itr->GetMeanLatency(); |
|
|
|
|
|
|
|
if (l >= min) continue; |
|
|
|
|
|
|
|
tun = itr; |
|
|
|
|
|
|
|
if(tun == exclude) continue; |
|
|
|
|
|
|
|
min = l; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return tun; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<OutboundTunnel> TunnelPool::GetLowestLatencyOutboundTunnel(std::shared_ptr<OutboundTunnel> exclude) const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::shared_ptr<OutboundTunnel> tun = nullptr; |
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_OutboundTunnelsMutex); |
|
|
|
|
|
|
|
uint64_t min = 1000000; |
|
|
|
|
|
|
|
for (const auto & itr : m_OutboundTunnels) { |
|
|
|
|
|
|
|
if(!itr->LatencyIsKnown()) continue; |
|
|
|
|
|
|
|
auto l = itr->GetMeanLatency(); |
|
|
|
|
|
|
|
if (l >= min) continue; |
|
|
|
|
|
|
|
tun = itr; |
|
|
|
|
|
|
|
if(tun == exclude) continue; |
|
|
|
|
|
|
|
min = l; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return tun; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|