From b29ec20ad46d5d4ce03aaa36bbc6e1d5be7748e7 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 26 Jul 2019 12:19:08 -0400 Subject: [PATCH] try deferred resolve for exit handler --- llarp/handlers/exit.cpp | 26 ++++++++++++++++++++++---- llarp/handlers/exit.hpp | 5 +++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/llarp/handlers/exit.cpp b/llarp/handlers/exit.cpp index c371cacf7..137659fd0 100644 --- a/llarp/handlers/exit.cpp +++ b/llarp/handlers/exit.cpp @@ -171,10 +171,20 @@ namespace llarp } else if(m_SNodeKeys.find(pubKey) == m_SNodeKeys.end()) { - // we do not have it mapped - // map it - ip = ObtainServiceNodeIP(r); - msg.AddINReply(ip, isV6); + // we do not have it mapped, async obtain it + ObtainSNodeSession( + r, [&](std::shared_ptr< exit::BaseSession > session) { + if(session && session->IsReady()) + { + msg.AddINReply(m_KeyToIP[pubKey], isV6); + } + else + { + msg.AddNXReply(); + } + reply(msg); + }); + return; } else { @@ -196,6 +206,14 @@ namespace llarp return true; } + void + ExitEndpoint::ObtainSNodeSession(const RouterID &router, + exit::SessionReadyFunc obtainCb) + { + ObtainServiceNodeIP(router); + m_SNodeSessions[router]->AddReadyHook(obtainCb); + } + llarp_time_t ExitEndpoint::Now() const { diff --git a/llarp/handlers/exit.hpp b/llarp/handlers/exit.hpp index e96409468..d8d6abbab 100644 --- a/llarp/handlers/exit.hpp +++ b/llarp/handlers/exit.hpp @@ -120,6 +120,11 @@ namespace llarp huint128_t ObtainServiceNodeIP(const RouterID& router); + /// async obtain snode session and call callback when it's ready to send + void + ObtainSNodeSession(const RouterID& router, + exit::SessionReadyFunc obtainCb); + bool QueueSNodePacket(const llarp_buffer_t& buf, huint128_t from);