diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index 88c491cdd..fc546e62a 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -41,7 +41,8 @@ namespace llarp r->netloop()) , m_NetworkToUserPktQueue(nickname + "_recvq", r->netloop(), r->netloop()) - , m_Resolver(std::make_shared(r->netloop(), r->logic(), r->netloop(), r->logic(), this)) + , m_Resolver(std::make_shared< dns::Proxy >( + r->netloop(), r->logic(), r->netloop(), r->logic(), this)) { #ifdef ANDROID tunif.get_fd_promise = &get_tun_fd_promise; diff --git a/llarp/path/path.hpp b/llarp/path/path.hpp index 95464ac05..ad1684936 100644 --- a/llarp/path/path.hpp +++ b/llarp/path/path.hpp @@ -42,7 +42,7 @@ namespace llarp /// default path lifetime in ms constexpr llarp_time_t default_lifetime = 10 * 60 * 1000; /// after this many ms a path build times out - constexpr llarp_time_t build_timeout = 15000; + constexpr llarp_time_t build_timeout = 30000; /// measure latency every this interval ms constexpr llarp_time_t latency_interval = 5000; diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index f531b0ac4..ada02d128 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -332,61 +332,33 @@ namespace llarp OutboundContext::MarkCurrentIntroBad(llarp_time_t now) { // insert bad intro - m_BadIntros[remoteIntro] = now; - // unconditional shift - bool shiftedRouter = false; - bool shiftedIntro = false; - // try same router - for(const auto& intro : currentIntroSet.I) + m_BadIntros[m_NextIntro] = now; + // try shifting intro without rebuild + if(ShiftIntroduction(false)) { - if(intro.ExpiresSoon(now)) - continue; - if(router->routerProfiling().IsBadForPath(intro.router)) - continue; - auto itr = m_BadIntros.find(intro); - if(itr == m_BadIntros.end() && intro.router == m_NextIntro.router) - { - if(intro.expiresAt > m_NextIntro.expiresAt) - { - shiftedIntro = true; - m_NextIntro = intro; - break; - } - } - } - if(!shiftedIntro) - { - // try any router - for(const auto& intro : currentIntroSet.I) - { - if(intro.ExpiresSoon(now)) - continue; - auto itr = m_BadIntros.find(intro); - if(itr == m_BadIntros.end()) - { - // TODO: this should always be true but idk if it really is - if(intro.expiresAt > m_NextIntro.expiresAt) - { - shiftedRouter = m_NextIntro.router != intro.router; - shiftedIntro = true; - m_NextIntro = intro; - break; - } - } - } - } - if(shiftedRouter) - { - lastShift = now; + // we shifted + // check if we have a path to the next intro router + if(GetNewestPathByRouter(m_NextIntro.router)) + return true; + // we don't have a path build one if we aren't building too fast if(!BuildCooldownHit(now)) BuildOneAlignedTo(m_NextIntro.router); + return true; } - else if(!shiftedIntro) + else { - LogInfo(Name(), " updating introset"); - UpdateIntroSet(true); + // we didn't shift check if we should update introset + if(now - lastShift >= MIN_SHIFT_INTERVAL + || currentIntroSet.HasExpiredIntros(now) + || currentIntroSet.IsExpired(now)) + { + // update introset + LogInfo(Name(), " updating introset"); + UpdateIntroSet(true); + return true; + } + return false; } - return shiftedIntro; } bool @@ -409,37 +381,40 @@ namespace llarp { if(intro.expiresAt > m_NextIntro.expiresAt) { + success = true; m_NextIntro = intro; return true; } } } - /// pick newer intro not on same router - for(const auto& intro : currentIntroSet.I) + if(!success) { - if(m_Endpoint->m_SnodeBlacklist.count(intro.router)) - continue; - m_Endpoint->EnsureRouterIsKnown(intro.router); - if(intro.ExpiresSoon(now)) - continue; - if(m_BadIntros.find(intro) == m_BadIntros.end() && m_NextIntro != intro) + /// pick newer intro not on same router + for(const auto& intro : currentIntroSet.I) { - if(intro.expiresAt > m_NextIntro.expiresAt) + if(m_Endpoint->m_SnodeBlacklist.count(intro.router)) + continue; + m_Endpoint->EnsureRouterIsKnown(intro.router); + if(intro.ExpiresSoon(now)) + continue; + if(m_BadIntros.find(intro) == m_BadIntros.end() + && m_NextIntro != intro) { - shifted = intro.router != m_NextIntro.router; - m_NextIntro = intro; - success = true; + if(intro.expiresAt > m_NextIntro.expiresAt) + { + shifted = intro.router != m_NextIntro.router; + m_NextIntro = intro; + success = true; + } } } } if(m_NextIntro.router.IsZero()) return false; if(shifted) - { lastShift = now; - if(rebuild && !BuildCooldownHit(Now())) - BuildOneAlignedTo(m_NextIntro.router); - } + if(rebuild && !BuildCooldownHit(Now())) + BuildOneAlignedTo(m_NextIntro.router); return success; } @@ -496,7 +471,9 @@ namespace llarp // check if we have a path to this router num = 0; ForEachPath([&](const path::Path_ptr& p) { - if(p->Endpoint() == m_NextIntro.router) + // don't count timed out paths + if(p->Status() != path::ePathTimeout + && p->Endpoint() == m_NextIntro.router) ++num; }); // build a path if one isn't already pending build or established