From a33f334bc2a7667be682e11a24e8c5ea1863bce0 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sun, 25 Nov 2018 11:58:27 -0500 Subject: [PATCH] better exit path logic --- include/llarp/pathset.hpp | 4 ++++ llarp/exit/session.cpp | 8 ++++++-- llarp/handlers/tun.cpp | 2 +- llarp/pathset.cpp | 12 ++++++++++++ llarp/service/endpoint.cpp | 4 ---- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/include/llarp/pathset.hpp b/include/llarp/pathset.hpp index e1cecca61..055e964b4 100644 --- a/include/llarp/pathset.hpp +++ b/include/llarp/pathset.hpp @@ -60,6 +60,10 @@ namespace llarp void Tick(llarp_time_t now, llarp_router* r); + /// count the number of paths that will exist at this timestamp in future + size_t + NumPathsExistingAt(llarp_time_t futureTime) const; + void RemovePath(Path* path); diff --git a/llarp/exit/session.cpp b/llarp/exit/session.cpp index 2dd5ace1b..1458581ba 100644 --- a/llarp/exit/session.cpp +++ b/llarp/exit/session.cpp @@ -22,8 +22,12 @@ namespace llarp bool BaseSession::ShouldBuildMore(llarp_time_t now) const { - return AvailablePaths(llarp::path::ePathRoleExit) == 0 - || path::Builder::ShouldBuildMore(now); + const size_t expect = (1 + (m_NumPaths / 2)); + if(NumPathsExistingAt(now + (10 * 1000)) < expect) + return true; + if(AvailablePaths(llarp::path::ePathRoleExit) < expect) + return true; + return false; } bool diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index a2ab29575..cf75577cb 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -335,7 +335,7 @@ namespace llarp TunEndpoint::Tick(llarp_time_t now) { // call tun code in endpoint logic in case of network isolation - llarp_logic_queue_job(EndpointLogic(), {this, handleTickTun}); + //llarp_logic_queue_job(EndpointLogic(), {this, handleTickTun}); FlushSend(); Endpoint::Tick(now); } diff --git a/llarp/pathset.cpp b/llarp/pathset.cpp index 8165025e3..8b461dba3 100644 --- a/llarp/pathset.cpp +++ b/llarp/pathset.cpp @@ -41,6 +41,18 @@ namespace llarp return 0; } + size_t + PathSet::NumPathsExistingAt(llarp_time_t futureTime) const + { + size_t num = 0; + for(const auto & item : m_Paths) + { + if(!item.second->Expired(futureTime)) + ++num; + } + return num; + } + void PathSet::Tick(llarp_time_t now, llarp_router* r) { diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 219d75be4..64e67404c 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -131,10 +131,6 @@ namespace llarp { RegenAndPublishIntroSet(now); } - if(m_Exit) - { - m_Exit->Tick(now, m_Router); - } // expire pending tx { std::set< service::IntroSet > empty;