|
|
@ -147,13 +147,13 @@ namespace tunnel
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<OutboundTunnel> TunnelPool::GetNextOutboundTunnel (std::shared_ptr<OutboundTunnel> excluded) const
|
|
|
|
std::shared_ptr<OutboundTunnel> TunnelPool::GetNextOutboundTunnel (std::shared_ptr<OutboundTunnel> excluded) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
|
|
|
|
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
|
|
|
|
return GetNextTunnel (m_OutboundTunnels, excluded);
|
|
|
|
return GetNextTunnel (m_OutboundTunnels, excluded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<InboundTunnel> TunnelPool::GetNextInboundTunnel (std::shared_ptr<InboundTunnel> excluded) const
|
|
|
|
std::shared_ptr<InboundTunnel> TunnelPool::GetNextInboundTunnel (std::shared_ptr<InboundTunnel> excluded) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
|
|
|
|
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
|
|
|
|
return GetNextTunnel (m_InboundTunnels, excluded);
|
|
|
|
return GetNextTunnel (m_InboundTunnels, excluded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -167,11 +167,27 @@ namespace tunnel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (it->IsEstablished () && it != excluded)
|
|
|
|
if (it->IsEstablished () && it != excluded)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if(HasLatencyRequirement() && it->LatencyIsKnown() && !it->LatencyFitsRange(m_MinLatency, m_MaxLatency)) {
|
|
|
|
|
|
|
|
i ++;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
tunnel = it;
|
|
|
|
tunnel = it;
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i > ind && tunnel) break;
|
|
|
|
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)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tunnel = it;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|