diff --git a/llarp/exit/endpoint.cpp b/llarp/exit/endpoint.cpp index 737c10949..bb9728389 100644 --- a/llarp/exit/endpoint.cpp +++ b/llarp/exit/endpoint.cpp @@ -11,24 +11,24 @@ namespace llarp { Endpoint::Endpoint( const llarp::PubKey& remoteIdent, - const llarp::PathID_t& beginPath, + const llarp::path::HopHandler_ptr& beginPath, bool rewriteIP, huint128_t ip, llarp::handlers::ExitEndpoint* parent) - : createdAt(parent->Now()) - , m_Parent(parent) - , m_remoteSignKey(remoteIdent) - , m_CurrentPath(beginPath) - , m_IP(ip) - , m_RewriteSource(rewriteIP) - , m_Counter(0) + : createdAt{parent->Now()} + , m_Parent{parent} + , m_remoteSignKey{remoteIdent} + , m_CurrentPath{beginPath} + , m_IP{ip} + , m_RewriteSource{rewriteIP} { m_LastActive = parent->Now(); } Endpoint::~Endpoint() { - m_Parent->DelEndpointInfo(m_CurrentPath); + if (m_CurrentPath) + m_Parent->DelEndpointInfo(m_CurrentPath->RXID()); } void @@ -59,7 +59,8 @@ namespace llarp { if (!m_Parent->UpdateEndpointPath(m_remoteSignKey, nextPath)) return false; - m_CurrentPath = nextPath; + const RouterID us{m_Parent->GetRouter()->pubkey()}; + m_CurrentPath = m_Parent->GetRouter()->pathContext().GetByUpstream(us, nextPath); return true; } @@ -98,7 +99,7 @@ namespace llarp if (ExpiresSoon(now, timeout)) return true; auto path = GetCurrentPath(); - if (!path) + if (not path) return true; auto lastPing = path->LastRemoteActivityAt(); if (lastPing == 0s || (now > lastPing && now - lastPing > timeout)) @@ -240,12 +241,5 @@ namespace llarp item.second.clear(); return sent; } - - llarp::path::HopHandler_ptr - Endpoint::GetCurrentPath() const - { - auto router = m_Parent->GetRouter(); - return router->pathContext().GetByUpstream(router->pubkey(), m_CurrentPath); - } } // namespace exit } // namespace llarp diff --git a/llarp/exit/endpoint.hpp b/llarp/exit/endpoint.hpp index 1eb3bd8be..50b1d138b 100644 --- a/llarp/exit/endpoint.hpp +++ b/llarp/exit/endpoint.hpp @@ -2,7 +2,8 @@ #include #include -#include +#include +#include #include #include @@ -23,9 +24,9 @@ namespace llarp { static constexpr size_t MaxUpstreamQueueSize = 256; - Endpoint( + explicit Endpoint( const llarp::PubKey& remoteIdent, - const llarp::PathID_t& beginPath, + const llarp::path::HopHandler_ptr& path, bool rewriteIP, huint128_t ip, llarp::handlers::ExitEndpoint* parent); @@ -75,7 +76,10 @@ namespace llarp UpdateLocalPath(const llarp::PathID_t& nextPath); llarp::path::HopHandler_ptr - GetCurrentPath() const; + GetCurrentPath() const + { + return m_CurrentPath; + } const llarp::PubKey& PubKey() const @@ -83,12 +87,6 @@ namespace llarp return m_remoteSignKey; } - const llarp::PathID_t& - LocalPath() const - { - return m_CurrentPath; - } - uint64_t TxRate() const { @@ -112,7 +110,7 @@ namespace llarp private: llarp::handlers::ExitEndpoint* m_Parent; llarp::PubKey m_remoteSignKey; - llarp::PathID_t m_CurrentPath; + llarp::path::HopHandler_ptr m_CurrentPath; llarp::huint128_t m_IP; uint64_t m_TxRate, m_RxRate; llarp_time_t m_LastActive; diff --git a/llarp/handlers/exit.cpp b/llarp/handlers/exit.cpp index 3741f2246..4bf7bb023 100644 --- a/llarp/handlers/exit.cpp +++ b/llarp/handlers/exit.cpp @@ -66,7 +66,8 @@ namespace llarp auto visit = [&tag](exit::Endpoint* const ep) -> bool { if (not ep) return false; - tag = service::ConvoTag{ep->LocalPath().as_array()}; + if (auto path = ep->GetCurrentPath()) + tag = service::ConvoTag{path->RXID().as_array()}; return true; }; if (VisitEndpointsFor(PubKey{*rid}, visit) and not tag.IsZero()) @@ -789,6 +790,10 @@ namespace llarp { if (wantInternet && !m_PermitExit) return false; + path::HopHandler_ptr handler = + m_Router->pathContext().GetByUpstream(m_Router->pubkey(), path); + if (handler == nullptr) + return false; auto ip = GetIPForIdent(pk); if (GetRouter()->pathContext().TransitHopPreviousIsRouter(path, pk.as_array())) { @@ -797,7 +802,7 @@ namespace llarp m_SNodeKeys.emplace(pk.as_array()); } m_ActiveExits.emplace( - pk, std::make_unique(pk, path, !wantInternet, ip, this)); + pk, std::make_unique(pk, handler, !wantInternet, ip, this)); m_Paths[path] = pk; @@ -823,12 +828,13 @@ namespace llarp auto itr = range.first; while (itr != range.second) { - if (itr->second->LocalPath() == ep->LocalPath()) + if (itr->second->GetCurrentPath() == ep->GetCurrentPath()) { itr = m_ActiveExits.erase(itr); // now ep is gone af return; } + ++itr; } } diff --git a/llarp/path/ihophandler.hpp b/llarp/path/ihophandler.hpp index a77d5c176..7fb7e740d 100644 --- a/llarp/path/ihophandler.hpp +++ b/llarp/path/ihophandler.hpp @@ -30,6 +30,9 @@ namespace llarp virtual ~IHopHandler() = default; + virtual PathID_t + RXID() const = 0; + void DecayFilters(llarp_time_t now); diff --git a/llarp/path/path.hpp b/llarp/path/path.hpp index f8c488832..0d57b372b 100644 --- a/llarp/path/path.hpp +++ b/llarp/path/path.hpp @@ -360,7 +360,7 @@ namespace llarp IsEndpoint(const RouterID& router, const PathID_t& path) const; PathID_t - RXID() const; + RXID() const override; RouterID Upstream() const; diff --git a/llarp/path/transit_hop.hpp b/llarp/path/transit_hop.hpp index 315cf83d8..e71843874 100644 --- a/llarp/path/transit_hop.hpp +++ b/llarp/path/transit_hop.hpp @@ -73,6 +73,12 @@ namespace llarp llarp_proto_version_t version; llarp_time_t m_LastActivity = 0s; + PathID_t + RXID() const override + { + return info.rxID; + } + void Stop();