From 5fa85acaf78c298c9849507023886c684d510bed Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 6 May 2019 10:54:05 -0400 Subject: [PATCH] rebuild exit paths if they die --- llarp/exit/session.cpp | 5 +++-- llarp/path/path.cpp | 10 ++++++++++ llarp/path/path.hpp | 5 +++++ llarp/path/pathset.hpp | 5 +++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/llarp/exit/session.cpp b/llarp/exit/session.cpp index 65a08f302..e21126119 100644 --- a/llarp/exit/session.cpp +++ b/llarp/exit/session.cpp @@ -26,9 +26,10 @@ namespace llarp { } - void BaseSession::HandlePathDied(path::Path_ptr) + void + BaseSession::HandlePathDied(path::Path_ptr p) { - BuildOne(); + p->Rebuild(); } util::StatusObject diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index 4ece5677c..6d0135b12 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -515,6 +515,16 @@ namespace llarp return obj; } + void + Path::Rebuild() + { + std::vector< RouterContact > newHops; + for(const auto& hop : hops) + newHops.emplace_back(hop.rc); + LogInfo(Name(), " rebuilding on ", HopsString()); + m_PathSet->Build(newHops); + } + void Path::Tick(llarp_time_t now, AbstractRouter* r) { diff --git a/llarp/path/path.hpp b/llarp/path/path.hpp index 4f7a8cbf9..b97cc7a72 100644 --- a/llarp/path/path.hpp +++ b/llarp/path/path.hpp @@ -435,6 +435,11 @@ namespace llarp bool Expired(llarp_time_t now) const override; + /// build a new path on the same set of hops as us + /// regenerates keys + void + Rebuild(); + void Tick(llarp_time_t now, AbstractRouter* r); diff --git a/llarp/path/pathset.hpp b/llarp/path/pathset.hpp index 6bd6e572a..267e04e4b 100644 --- a/llarp/path/pathset.hpp +++ b/llarp/path/pathset.hpp @@ -76,6 +76,11 @@ namespace llarp virtual void BuildOne(PathRole roles = ePathRoleAny) = 0; + /// manual build on these hops + virtual void + Build(const std::vector< RouterContact >& hops, + PathRole roles = ePathRoleAny) = 0; + /// tick owned paths virtual void Tick(llarp_time_t now) = 0;