From 7c691cf334c05e3110693106c8cec764aabff3dd Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 19 Sep 2019 16:28:12 -0400 Subject: [PATCH] handover should be fixed now --- llarp/service/endpoint.cpp | 13 +++++++++++++ llarp/service/endpoint.hpp | 3 +++ llarp/service/endpoint_util.cpp | 1 + llarp/service/handler.hpp | 3 +++ llarp/service/outbound_context.cpp | 10 +++++----- llarp/service/sendcontext.cpp | 1 + llarp/service/session.cpp | 5 ++--- 7 files changed, 28 insertions(+), 8 deletions(-) diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 585826cc9..00057409d 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -434,6 +434,16 @@ namespace llarp itr->second.lastUsed = Now(); } + void + Endpoint::MarkConvoTagActive(const ConvoTag& tag) + { + auto itr = Sessions().find(tag); + if(itr != Sessions().end()) + { + itr->second.lastUsed = Now(); + } + } + bool Endpoint::LoadKeyFile() { @@ -1048,7 +1058,10 @@ namespace llarp util::Lock lock(&m_state->m_SendQueueMutex); // send outbound traffic for(const auto& item : m_state->m_SendQueue) + { item.second->SendRoutingMessage(*item.first, router); + MarkConvoTagActive(item.first->T.T); + } m_state->m_SendQueue.clear(); } diff --git a/llarp/service/endpoint.hpp b/llarp/service/endpoint.hpp index ebd25e78f..53df3762d 100644 --- a/llarp/service/endpoint.hpp +++ b/llarp/service/endpoint.hpp @@ -317,6 +317,9 @@ namespace llarp void RemoveConvoTag(const ConvoTag& remote) override; + void + MarkConvoTagActive(const ConvoTag& remote) override; + void PutReplyIntroFor(const ConvoTag& remote, const Introduction& intro) override; diff --git a/llarp/service/endpoint_util.cpp b/llarp/service/endpoint_util.cpp index ecf41f45b..6ca81bbe0 100644 --- a/llarp/service/endpoint_util.cpp +++ b/llarp/service/endpoint_util.cpp @@ -96,6 +96,7 @@ namespace llarp itr->second->Tick(now); if(itr->second->Pump(now)) { + LogInfo("marking session as dead T=", itr->first); itr->second->Stop(); deadSessions.emplace(std::move(*itr)); itr = remoteSessions.erase(itr); diff --git a/llarp/service/handler.hpp b/llarp/service/handler.hpp index 9e029e720..3c20aea47 100644 --- a/llarp/service/handler.hpp +++ b/llarp/service/handler.hpp @@ -29,6 +29,9 @@ namespace llarp PutCachedSessionKeyFor(const ConvoTag& remote, const SharedSecret& secret) = 0; + virtual void + MarkConvoTagActive(const ConvoTag& tag) = 0; + virtual void RemoveConvoTag(const ConvoTag& remote) = 0; diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index be32352c1..255220001 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -259,6 +259,10 @@ namespace llarp else ++itr; } + if(currentIntroSet.HasExpiredIntros(now)) + { + UpdateIntroSet(true); + } // send control message if we look too quiet if(lastGoodSend) { @@ -275,7 +279,6 @@ namespace llarp tmp.Randomize(); llarp_buffer_t buf(tmp.data(), tmp.size()); AsyncEncryptAndSendTo(buf, eProtocolControl); - return !m_DataHandler->HasConvoTag(currentConvoTag); } } } @@ -316,10 +319,7 @@ namespace llarp { if(markedBad) return false; - const bool should = - (!(path::Builder::BuildCooldownHit(now) - || path::Builder::NumInStatus(path::ePathBuilding) >= numPaths)) - && path::Builder::ShouldBuildMore(now); + const bool should = path::Builder::BuildCooldownHit(now); if(!ReadyToSend()) { diff --git a/llarp/service/sendcontext.cpp b/llarp/service/sendcontext.cpp index 9571caffa..2bdb638d6 100644 --- a/llarp/service/sendcontext.cpp +++ b/llarp/service/sendcontext.cpp @@ -43,6 +43,7 @@ namespace llarp if(item.second->SendRoutingMessage(*item.first, r)) { lastGoodSend = r->Now(); + m_Endpoint->MarkConvoTagActive(item.first->T.T); } else LogError(m_Endpoint->Name(), " failed to send frame on path"); diff --git a/llarp/service/session.cpp b/llarp/service/session.cpp index 8bce8f7eb..d7c13ce19 100644 --- a/llarp/service/session.cpp +++ b/llarp/service/session.cpp @@ -18,9 +18,8 @@ namespace llarp bool Session::IsExpired(llarp_time_t now, llarp_time_t lifetime) const { - if(now <= lastUsed) - return intro.IsExpired(now); - return now - lastUsed > lifetime || intro.IsExpired(now); + return now > lastUsed + && (now - lastUsed > lifetime || intro.IsExpired(now)); } } // namespace service