From f9fb40f590182a39f4149d391e0f98d4a3c3b51c Mon Sep 17 00:00:00 2001 From: jeff Date: Fri, 20 Sep 2019 12:56:19 -0400 Subject: [PATCH] final touches --- llarp/path/pathbuilder.hpp | 6 ++-- llarp/service/endpoint_util.cpp | 1 + llarp/service/outbound_context.cpp | 54 ++++++++++++++++++++++++++---- llarp/service/outbound_context.hpp | 11 ++++++ llarp/service/sendcontext.cpp | 1 - 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/llarp/path/pathbuilder.hpp b/llarp/path/pathbuilder.hpp index 8e35f89d8..6e1a9d78d 100644 --- a/llarp/path/pathbuilder.hpp +++ b/llarp/path/pathbuilder.hpp @@ -113,13 +113,13 @@ namespace llarp virtual const SecretKey& GetTunnelEncryptionSecretKey() const; - void + virtual void HandlePathBuilt(Path_ptr p) override; - void + virtual void HandlePathBuildTimeout(Path_ptr p) override; - void + virtual void HandlePathBuildFailed(Path_ptr p) override; }; diff --git a/llarp/service/endpoint_util.cpp b/llarp/service/endpoint_util.cpp index 6ca81bbe0..25a4a5c46 100644 --- a/llarp/service/endpoint_util.cpp +++ b/llarp/service/endpoint_util.cpp @@ -116,6 +116,7 @@ namespace llarp { if(itr->second.IsExpired(now)) { + LogInfo("Expire session T=", itr->first); itr = sessions.erase(itr); } else diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index 255220001..cc0ff1a5d 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -44,8 +44,6 @@ namespace llarp if(MarkCurrentIntroBad(Now())) { SwapIntros(); - LogInfo(Name(), " switched intros to ", remoteIntro.router, " via ", - remoteIntro.pathID); } UpdateIntroSet(true); } @@ -53,13 +51,13 @@ namespace llarp } OutboundContext::OutboundContext(const IntroSet& introset, Endpoint* parent) - : path::Builder(parent->Router(), 3, path::default_len) + : path::Builder(parent->Router(), 4, path::default_len) , SendContext(introset.A, {}, this, parent) , currentIntroSet(introset) { updatingIntroSet = false; - for(const auto intro : introset.I) + for(const auto& intro : introset.I) { if(intro.expiresAt > m_NextIntro.expiresAt) m_NextIntro = intro; @@ -75,6 +73,7 @@ namespace llarp { if(remoteIntro != m_NextIntro) { + LogInfo(Name(), " swap intro to use ", RouterID(m_NextIntro.router)); remoteIntro = m_NextIntro; m_DataHandler->PutIntroFor(currentConvoTag, remoteIntro); ShiftIntroduction(false); @@ -114,7 +113,10 @@ namespace llarp BuildOneAlignedTo(m_NextIntro.router); } else + { ++m_LookupFails; + LogWarn(Name(), " failed to look up introset, fails=", m_LookupFails); + } return true; } @@ -125,6 +127,32 @@ namespace llarp && GetPathByRouter(remoteIntro.router) != nullptr; } + void + OutboundContext::ShiftIntroRouter(const RouterID r) + { + const auto now = Now(); + Introduction selectedIntro; + for(const auto& intro : currentIntroSet.I) + { + if(intro.expiresAt > selectedIntro.expiresAt && intro.router != r) + { + selectedIntro = intro; + } + } + if(selectedIntro.router.IsZero() || selectedIntro.ExpiresSoon(now)) + return; + LogWarn(Name(), " shfiting intro off of ", r, " to ", + RouterID(selectedIntro.router)); + m_NextIntro = selectedIntro; + } + + void + OutboundContext::HandlePathBuildTimeout(path::Path_ptr p) + { + ShiftIntroRouter(p->Endpoint()); + path::Builder::HandlePathBuildTimeout(p); + } + void OutboundContext::HandlePathBuilt(path::Path_ptr p) { @@ -138,6 +166,10 @@ namespace llarp // we now have a path to the next intro, swap intros if(p->Endpoint() == m_NextIntro.router) SwapIntros(); + else + { + LogInfo(Name(), " built to non aligned router: ", p->Endpoint()); + } } void @@ -241,6 +273,7 @@ namespace llarp // we are probably dead af if(m_LookupFails > 16 || m_BuildFails > 10) return true; + // check for expiration if(remoteIntro.ExpiresSoon(now)) { @@ -296,9 +329,10 @@ namespace llarp { if(m_NextIntro.router.IsZero() || prev.count(m_NextIntro.router)) { - if(!ShiftIntroduction(false)) - return false; + ShiftIntroduction(false); } + if(m_NextIntro.router.IsZero()) + return false; std::set< RouterID > exclude = prev; exclude.insert(m_NextIntro.router); for(const auto& snode : m_Endpoint->SnodeBlacklist()) @@ -337,9 +371,15 @@ namespace llarp bool OutboundContext::MarkCurrentIntroBad(llarp_time_t now) + { + return MarkIntroBad(remoteIntro, now); + } + + bool + OutboundContext::MarkIntroBad(const Introduction& intro, llarp_time_t now) { // insert bad intro - m_BadIntros[remoteIntro] = now; + m_BadIntros[intro] = now; // try shifting intro without rebuild if(ShiftIntroduction(false)) { diff --git a/llarp/service/outbound_context.hpp b/llarp/service/outbound_context.hpp index 1f591540b..0bde2abec 100644 --- a/llarp/service/outbound_context.hpp +++ b/llarp/service/outbound_context.hpp @@ -6,6 +6,7 @@ #include #include +#include namespace llarp { @@ -52,10 +53,17 @@ namespace llarp bool ShiftIntroduction(bool rebuild = true) override; + /// shift the intro off the current router it is using + void + ShiftIntroRouter(const RouterID remote); + /// mark the current remote intro as bad bool MarkCurrentIntroBad(llarp_time_t now) override; + bool + MarkIntroBad(const Introduction& marked, llarp_time_t now); + /// return true if we are ready to send bool ReadyToSend() const; @@ -85,6 +93,9 @@ namespace llarp void HandlePathBuilt(path::Path_ptr path) override; + void + HandlePathBuildTimeout(path::Path_ptr path) override; + bool SelectHop(llarp_nodedb* db, const std::set< RouterID >& prev, RouterContact& cur, size_t hop, path::PathRole roles) override; diff --git a/llarp/service/sendcontext.cpp b/llarp/service/sendcontext.cpp index 2bdb638d6..cb0b4c952 100644 --- a/llarp/service/sendcontext.cpp +++ b/llarp/service/sendcontext.cpp @@ -19,7 +19,6 @@ namespace llarp , m_Endpoint(ep) { createdAt = ep->Now(); - currentConvoTag.Zero(); } bool