From 550fc3c439a825c06f96dfb58befe111a96c6ff3 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 14 Feb 2019 08:49:07 -0500 Subject: [PATCH] Revert "tweaking handover logic" This reverts commit 50bfe5d8100539cad3ac4a71964c964b8d0c63fe. --- llarp/service/Intro.cpp | 1 - llarp/service/IntroSet.cpp | 13 ------- llarp/service/IntroSet.hpp | 4 --- llarp/service/endpoint.cpp | 72 +++++++++++++++++++++++++++----------- 4 files changed, 52 insertions(+), 38 deletions(-) diff --git a/llarp/service/Intro.cpp b/llarp/service/Intro.cpp index 8a7b2fde8..6304c6ce2 100644 --- a/llarp/service/Intro.cpp +++ b/llarp/service/Intro.cpp @@ -12,7 +12,6 @@ namespace llarp Introduction::ExtractStatus() const { util::StatusObject obj{{"router", router.ToHex()}, - {"path", pathID.ToHex()}, {"expiresAt", expiresAt}, {"latency", latency}, {"version", uint64_t(version)}}; diff --git a/llarp/service/IntroSet.cpp b/llarp/service/IntroSet.cpp index ff383e537..4f4a95f39 100644 --- a/llarp/service/IntroSet.cpp +++ b/llarp/service/IntroSet.cpp @@ -64,19 +64,6 @@ namespace llarp return read; } - bool - IntroSet::GetNewestIntroOnRouter(const RouterID& router, - Introduction& intro) const - { - intro.Clear(); - for(const auto& i : I) - { - if(intro.router == router && intro.expiresAt < i.expiresAt) - intro = i; - } - return intro.expiresAt > 0; - } - bool IntroSet::BEncode(llarp_buffer_t* buf) const { diff --git a/llarp/service/IntroSet.hpp b/llarp/service/IntroSet.hpp index 772d392b2..a8c9ae53d 100644 --- a/llarp/service/IntroSet.hpp +++ b/llarp/service/IntroSet.hpp @@ -144,10 +144,6 @@ namespace llarp llarp_time_t GetNewestIntroExpiration() const; - bool - GetNewestIntroOnRouter(const RouterID& router, - Introduction& result) const; - bool HasExpiredIntros(llarp_time_t now) const; diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 384273e22..268b055e6 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -1121,6 +1121,29 @@ namespace llarp Endpoint::OutboundContext::SwapIntros() { remoteIntro = m_NextIntro; + // prepare next intro + auto now = Now(); + for(const auto& intro : currentIntroSet.I) + { + if(intro.ExpiresSoon(now)) + continue; + if(m_BadIntros.find(intro) == m_BadIntros.end() + && remoteIntro.router == intro.router) + { + m_NextIntro = intro; + return; + } + } + for(const auto& intro : currentIntroSet.I) + { + if(intro.ExpiresSoon(now)) + continue; + if(m_BadIntros.find(intro) == m_BadIntros.end()) + { + m_NextIntro = intro; + return; + } + } } bool @@ -1152,6 +1175,8 @@ namespace llarp } if(GetPathByRouter(m_NextIntro.router) == nullptr) BuildOneAlignedTo(m_NextIntro.router); + else + SwapIntros(); } return true; } @@ -1383,6 +1408,10 @@ namespace llarp lastShift = now; BuildOneAlignedTo(m_NextIntro.router); } + else if(shiftedIntro) + { + SwapIntros(); + } else { llarp::LogInfo(Name(), " updating introset"); @@ -1399,16 +1428,18 @@ namespace llarp if(now - lastShift < MIN_SHIFT_INTERVAL) return false; bool shifted = false; - Introduction newIntro; - if(currentIntroSet.GetNewestIntroOnRouter(remoteIntro.router, newIntro)) + // to find a intro on the same router as before + for(const auto& intro : currentIntroSet.I) { - if(m_NextIntro != newIntro) + if(intro.ExpiresSoon(now)) + continue; + if(m_BadIntros.find(intro) == m_BadIntros.end() + && remoteIntro.router == intro.router) { - m_NextIntro = newIntro; + m_NextIntro = intro; return true; } } - for(const auto& intro : currentIntroSet.I) { m_Endpoint->EnsureRouterIsKnown(intro.router); @@ -1416,7 +1447,10 @@ namespace llarp continue; if(m_BadIntros.find(intro) == m_BadIntros.end() && m_NextIntro != intro) { - shifted = intro.router != m_NextIntro.router; + shifted = intro.router != m_NextIntro.router + || (now < intro.expiresAt + && intro.expiresAt - now + > 10 * 1000); // TODO: hardcoded value m_NextIntro = intro; success = true; break; @@ -1426,7 +1460,6 @@ namespace llarp { lastShift = now; BuildOneAlignedTo(m_NextIntro.router); - SwapIntros(); } return success; } @@ -1438,7 +1471,10 @@ namespace llarp auto now = m_Endpoint->Now(); if(remoteIntro.ExpiresSoon(now)) { - llarp::LogWarn("no good path yet, your message may drop"); + if(!MarkCurrentIntroBad(now)) + { + llarp::LogWarn("no good path yet, your message may drop"); + } } if(sequenceNo) { @@ -1672,6 +1708,13 @@ namespace llarp bool Endpoint::OutboundContext::Tick(llarp_time_t now) { + // check for expiration + if(remoteIntro.ExpiresSoon(now)) + { + // shift intro if it expires "soon" + ShiftIntroduction(); + } + // swap if we can if(remoteIntro != m_NextIntro) { if(GetPathByRouter(m_NextIntro.router) != nullptr) @@ -1681,16 +1724,9 @@ namespace llarp llarp::LogInfo(Name(), "swapped intro"); } } - else if(remoteIntro.ExpiresSoon(now)) - { - // shift intro if it expires "soon" - ShiftIntroduction(); - } - // lookup router in intro if set and unknown if(!remoteIntro.router.IsZero()) m_Endpoint->EnsureRouterIsKnown(remoteIntro.router); - // expire bad intros auto itr = m_BadIntros.begin(); while(itr != m_BadIntros.end()) @@ -1703,11 +1739,6 @@ namespace llarp // send control message if we look too quiet if(now - lastGoodSend > (sendTimeout / 2)) { - // build path - if(GetPathByRouter(remoteIntro.router) == nullptr) - { - BuildOneAlignedTo(remoteIntro.router); - } Encrypted< 64 > tmp; tmp.Randomize(); llarp_buffer_t buf(tmp.data(), tmp.size()); @@ -1805,6 +1836,7 @@ namespace llarp { llarp::LogError("cannot encrypt and send: no path for intro ", remoteIntro); + return; }