From a9882ad4755d6b75c20d72b2dba5e3b4001b253d Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Sat, 29 Feb 2020 19:26:23 -0500 Subject: [PATCH] PathRequestReceivedEvent implemented --- llarp/messages/relay_commit.cpp | 5 +++ llarp/path/pathbuilder.cpp | 6 ++-- llarp/router_id.cpp | 6 ++++ llarp/router_id.hpp | 3 ++ llarp/tooling/router_event.cpp | 52 ++++++++++++++++++++++----- llarp/tooling/router_event.hpp | 19 ++++++++-- pybind/llarp/tooling/router_event.cpp | 9 +++-- 7 files changed, 85 insertions(+), 15 deletions(-) diff --git a/llarp/messages/relay_commit.cpp b/llarp/messages/relay_commit.cpp index 076b1c450..eef8f9a3e 100644 --- a/llarp/messages/relay_commit.cpp +++ b/llarp/messages/relay_commit.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -416,6 +417,10 @@ namespace llarp // TODO: check if we really want to accept it self->hop->started = now; + auto event = std::make_unique( + self->context->Router()->pubkey(), self->hop); + self->context->Router()->NotifyRouterEvent(std::move(event)); + size_t sz = self->frames[0].size(); // shift std::array< EncryptedFrame, 8 > frames; diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 5e0485fba..78849d8ac 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -132,6 +132,9 @@ namespace llarp { if(!ctx->pathset->IsStopped()) { + tooling::RouterEventPtr event = std::make_unique(ctx->router->pubkey(), ctx->path); + ctx->router->NotifyRouterEvent(std::move(event)); + const RouterID remote = ctx->path->Upstream(); const ILinkMessage* msg = &ctx->LRCM; auto sentHandler = [ctx](auto status) { @@ -461,9 +464,6 @@ namespace llarp m_router->routerProfiling().MarkPathSuccess(p.get()); LogInfo(p->Name(), " built latency=", p->intro.latency); - tooling::RouterEventPtr event = std::make_unique(m_router->pubkey(), p->hops); - m_router->NotifyRouterEvent(std::move(event)); - m_BuildStats.success++; } diff --git a/llarp/router_id.cpp b/llarp/router_id.cpp index 81d1534e3..cceda8cbb 100644 --- a/llarp/router_id.cpp +++ b/llarp/router_id.cpp @@ -9,6 +9,12 @@ namespace llarp return std::string(llarp::Base32Encode(*this, stack)) + ".snode"; } + std::string + RouterID::ShortString() const + { + return ToString().substr(0, 8); + } + util::StatusObject RouterID::ExtractStatus() const { diff --git a/llarp/router_id.hpp b/llarp/router_id.hpp index bdc643179..142f79ab3 100644 --- a/llarp/router_id.hpp +++ b/llarp/router_id.hpp @@ -30,6 +30,9 @@ namespace llarp std::string ToString() const; + std::string + ShortString() const; + bool FromString(const std::string& str); diff --git a/llarp/tooling/router_event.cpp b/llarp/tooling/router_event.cpp index 6fa3f3365..8c1f5bfec 100644 --- a/llarp/tooling/router_event.cpp +++ b/llarp/tooling/router_event.cpp @@ -1,8 +1,7 @@ #include -#include - #include +#include namespace tooling { @@ -12,16 +11,16 @@ namespace tooling { } - PathBuildAttemptEvent::PathBuildAttemptEvent(const llarp::RouterID& routerID, std::vector hops) - : RouterEvent(routerID, false), hops(hops) + PathAttemptEvent::PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr path) + : RouterEvent(routerID, false), hops(path->hops) { } std::string - PathBuildAttemptEvent::ToString() const + PathAttemptEvent::ToString() const { - std::string result = "PathBuildAttemptEvent ["; - result += routerID.ToString().substr(0, 8); + std::string result = "PathAttemptEvent ["; + result += routerID.ShortString(); result += "] ---- ["; size_t i = 0; @@ -29,7 +28,7 @@ namespace tooling { i++; - result += hop.rc.pubkey.ToString().substr(0, 8); + result += llarp::RouterID(hop.rc.pubkey).ShortString(); result += "]"; if (i != hops.size()) @@ -41,4 +40,41 @@ namespace tooling return result; } + + PathRequestReceivedEvent::PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr hop) + : RouterEvent(routerID, true) + , prevHop(hop->info.downstream) + , nextHop(hop->info.upstream) + { + isEndpoint = false; + if (routerID == nextHop) + { + isEndpoint = true; + } + } + + std::string + PathRequestReceivedEvent::ToString() const + { + std::string result = "PathRequestReceivedEvent ["; + result += routerID.ShortString(); + result += "] ---- ["; + result += prevHop.ShortString(); + result += "] -> [*"; + result += routerID.ShortString(); + result += "] -> ["; + + if (isEndpoint) + { + result += "nowhere]"; + } + else + { + result += nextHop.ShortString(); + result += "]"; + } + + return result; + } + } // namespace tooling diff --git a/llarp/tooling/router_event.hpp b/llarp/tooling/router_event.hpp index 63d8e0a0c..f4845e602 100644 --- a/llarp/tooling/router_event.hpp +++ b/llarp/tooling/router_event.hpp @@ -11,8 +11,11 @@ namespace llarp namespace path { + struct Path; struct PathHopConfig; + struct TransitHop; + } // namespace llarp::path } // namespace llarp @@ -39,13 +42,25 @@ namespace tooling using RouterEventPtr = std::unique_ptr; - struct PathBuildAttemptEvent : public RouterEvent + struct PathAttemptEvent : public RouterEvent { - PathBuildAttemptEvent(const llarp::RouterID& routerID, std::vector hops); + PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr path); std::string ToString() const override; std::vector hops; }; + struct PathRequestReceivedEvent : public RouterEvent + { + PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr hop); + + std::string ToString() const override; + + llarp::RouterID prevHop; + llarp::RouterID nextHop; + + bool isEndpoint = false; + }; + } // namespace tooling diff --git a/pybind/llarp/tooling/router_event.cpp b/pybind/llarp/tooling/router_event.cpp index 3151d4478..00e38b586 100644 --- a/pybind/llarp/tooling/router_event.cpp +++ b/pybind/llarp/tooling/router_event.cpp @@ -15,8 +15,13 @@ namespace tooling .def_readonly("routerID", &RouterEvent::routerID) .def_readonly("triggered", &RouterEvent::triggered); - py::class_(mod, "PathBuildAttemptEvent") - .def_readonly("hops", &PathBuildAttemptEvent::hops); + py::class_(mod, "PathAttemptEvent") + .def_readonly("hops", &PathAttemptEvent::hops); + + py::class_(mod, "PathRequestReceivedEvent") + .def_readonly("prevHop", &PathRequestReceivedEvent::prevHop) + .def_readonly("nextHop", &PathRequestReceivedEvent::nextHop) + .def_readonly("isEndpoint", &PathRequestReceivedEvent::isEndpoint); } } // namespace tooling