From e907d2ae19f9dc33bad5d52b5833fec5ddc891d0 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 18 Feb 2020 11:00:45 -0500 Subject: [PATCH] handover fixes --- llarp/service/endpoint.cpp | 21 +++++++++++++++++---- llarp/service/endpoint.hpp | 13 ++++++------- llarp/service/endpoint_state.hpp | 2 ++ llarp/service/endpoint_types.hpp | 3 +++ llarp/service/handler.hpp | 7 +++++++ llarp/service/outbound_context.cpp | 5 +---- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index a414ef058..daed6d8c1 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -947,6 +947,18 @@ namespace llarp return true; } + void + Endpoint::MarkAddressOutbound(const Address& addr) + { + m_state->m_OutboundSessions.insert(addr); + } + + bool + Endpoint::WantsOutboundSession(const Address& addr) const + { + return m_state->m_OutboundSessions.count(addr) > 0; + } + bool Endpoint::EnsurePathToService(const Address remote, PathEnsureHook hook, ABSL_ATTRIBUTE_UNUSED llarp_time_t timeoutMS) @@ -954,6 +966,8 @@ namespace llarp static constexpr size_t NumParalellLookups = 2; LogInfo(Name(), " Ensure Path to ", remote.ToString()); + MarkAddressOutbound(remote); + auto& sessions = m_state->m_RemoteSessions; { @@ -1193,8 +1207,7 @@ namespace llarp } } } - - // outbound converstation + else { auto& sessions = m_state->m_RemoteSessions; auto range = sessions.equal_range(remote); @@ -1208,8 +1221,8 @@ namespace llarp } ++itr; } - // if there is an outbound context - if(range.first != sessions.end()) + // if we want to make an outbound session + if(WantsOutboundSession(remote)) { // add pending traffic auto& traffic = m_state->m_PendingTraffic; diff --git a/llarp/service/endpoint.hpp b/llarp/service/endpoint.hpp index e86168e6f..82a0a78cd 100644 --- a/llarp/service/endpoint.hpp +++ b/llarp/service/endpoint.hpp @@ -197,11 +197,6 @@ namespace llarp bool HasPendingPathToService(const Address& remote) const; - /// return false if we don't have a path to the service - /// return true if we did and we removed it - bool - ForgetPathToService(const Address& remote); - bool HandleDataMessage(path::Path_ptr path, const PathID_t from, std::shared_ptr< ProtocolMessage > msg) override; @@ -253,8 +248,6 @@ namespace llarp bool SendTo(const ConvoTag tag, const llarp_buffer_t& pkt, ProtocolType t); - ; - bool HandleDataDrop(path::Path_ptr p, const PathID_t& dst, uint64_t s); @@ -263,6 +256,12 @@ namespace llarp using PendingBufferQueue = std::deque< PendingBuffer >; + bool + WantsOutboundSession(const Address&) const override; + + void + MarkAddressOutbound(const Address&) override; + bool ShouldBundleRC() const override; diff --git a/llarp/service/endpoint_state.hpp b/llarp/service/endpoint_state.hpp index d01b274ac..59f214f62 100644 --- a/llarp/service/endpoint_state.hpp +++ b/llarp/service/endpoint_state.hpp @@ -95,6 +95,8 @@ namespace llarp /// conversations ConvoMap m_Sessions; + OutboundSessions_t m_OutboundSessions; + std::unordered_map< Tag, CachedTagResult, Tag::Hash > m_PrefetchedTags; bool diff --git a/llarp/service/endpoint_types.hpp b/llarp/service/endpoint_types.hpp index e635c2118..0cb850ea4 100644 --- a/llarp/service/endpoint_types.hpp +++ b/llarp/service/endpoint_types.hpp @@ -54,6 +54,9 @@ namespace llarp using ConvoMap = std::unordered_map< ConvoTag, Session, ConvoTag::Hash >; + /// set of outbound addresses to maintain to + using OutboundSessions_t = std::unordered_set< Address, Address::Hash >; + using PathEnsureHook = std::function< void(Address, OutboundContext*) >; } // namespace service diff --git a/llarp/service/handler.hpp b/llarp/service/handler.hpp index 9fabb6b95..1b5a11a57 100644 --- a/llarp/service/handler.hpp +++ b/llarp/service/handler.hpp @@ -72,6 +72,13 @@ namespace llarp virtual bool HasInboundConvo(const Address& addr) const = 0; + /// do we want a session outbound to addr + virtual bool + WantsOutboundSession(const Address& addr) const = 0; + + virtual void + MarkAddressOutbound(const Address& addr) = 0; + virtual void QueueRecvData(RecvDataEvent ev) = 0; }; diff --git a/llarp/service/outbound_context.cpp b/llarp/service/outbound_context.cpp index ec3dfd909..b10762c03 100644 --- a/llarp/service/outbound_context.cpp +++ b/llarp/service/outbound_context.cpp @@ -278,6 +278,7 @@ namespace llarp // check for expiration if(remoteIntro.ExpiresSoon(now)) { + UpdateIntroSet(); // shift intro if it expires "soon" if(ShiftIntroduction()) SwapIntros(); // swap intros if we shifted @@ -293,10 +294,6 @@ namespace llarp else ++itr; } - if(currentIntroSet.HasExpiredIntros(now)) - { - UpdateIntroSet(); - } // send control message if we look too quiet if(lastGoodSend) {