From b273676a6384f80228969bd8fff4f821f01f720f Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 24 Sep 2018 15:50:52 -0400 Subject: [PATCH] more logic for dead sessions to prevent segfault --- include/llarp/service/endpoint.hpp | 4 ++++ llarp/service/endpoint.cpp | 26 ++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/llarp/service/endpoint.hpp b/include/llarp/service/endpoint.hpp index 5543c7515..b7c0e72de 100644 --- a/include/llarp/service/endpoint.hpp +++ b/include/llarp/service/endpoint.hpp @@ -193,6 +193,7 @@ namespace llarp llarp_time_t createdAt; llarp_time_t sendTimeout = 20 * 1000; llarp_time_t connectTimeout = 30 * 1000; + bool markedBad = false; virtual void ShiftIntroduction(){}; @@ -237,6 +238,9 @@ namespace llarp bool MarkCurrentIntroBad(llarp_time_t now); + bool + ShouldBuildMore() const; + /// tick internal state /// return true to mark as dead bool diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 475740677..a81708330 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -225,9 +225,10 @@ namespace llarp { if(itr->second->Tick(now)) { - m_DeadSessions.insert( - std::make_pair(itr->first, std::move(itr->second))); - itr = m_RemoteSessions.erase(itr); + m_DeadSessions + .insert(std::make_pair(itr->first, std::move(itr->second))) + ->second->markedBad = true; + itr = m_RemoteSessions.erase(itr); } else ++itr; @@ -783,6 +784,9 @@ namespace llarp void Endpoint::OutboundContext::HandlePathBuilt(path::Path* p) { + /// don't use it if we are marked bad + if(markedBad) + return; p->SetDataHandler( std::bind(&Endpoint::OutboundContext::HandleHiddenServiceFrame, this, std::placeholders::_1, std::placeholders::_2)); @@ -899,7 +903,9 @@ namespace llarp Endpoint::OutboundContext::OnIntroSetUpdate(const Address& addr, const IntroSet* i) { - if(i) + if(markedBad) + return true; + if(i && currentIntroSet.T < i->T) { currentIntroSet = *i; ShiftIntroduction(); @@ -1008,7 +1014,7 @@ namespace llarp } m_PendingTraffic[remote].emplace(data, t); return true; - } // namespace service + } bool Endpoint::OutboundContext::MarkCurrentIntroBad(llarp_time_t now) @@ -1226,7 +1232,7 @@ namespace llarp void Endpoint::OutboundContext::UpdateIntroSet() { - if(updatingIntroSet) + if(updatingIntroSet || markedBad) return; auto addr = currentIntroSet.A.Addr(); auto path = m_Endpoint->GetEstablishedPathClosestTo(addr.data()); @@ -1309,6 +1315,14 @@ namespace llarp return ++(itr->second.seqno); } + bool + Endpoint::OutboundContext::ShouldBuildMore() const + { + if(markedBad) + return false; + return path::Builder::ShouldBuildMore(); + } + /// send on an established convo tag void Endpoint::SendContext::EncryptAndSendTo(llarp_buffer_t payload,