diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index 52b77185f..b648d9f16 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -23,8 +23,8 @@ namespace llarp namespace path { Path::Path(const std::vector< RouterContact >& h, PathSet* parent, - PathRole startingRoles) - : m_PathSet(parent), _role(startingRoles) + PathRole startingRoles, std::string shortName) + : m_PathSet(parent), _role(startingRoles), m_shortName(std::move(shortName)) { hops.resize(h.size()); @@ -122,6 +122,12 @@ namespace llarp return hops[0].rc.pubkey; } + const std::string& + Path::ShortName() const + { + return m_shortName; + } + std::string Path::HopsString() const { @@ -354,7 +360,7 @@ namespace llarp std::vector< RouterContact > newHops; for(const auto& hop : hops) newHops.emplace_back(hop.rc); - LogInfo(Name(), " rebuilding on ", HopsString()); + LogInfo(Name(), " rebuilding on ", ShortName()); m_PathSet->Build(newHops); } @@ -639,7 +645,7 @@ namespace llarp bool Path::HandlePathConfirmMessage(AbstractRouter* r) { - LogDebug("Path Build Confirm, path: ", HopsString()); + LogDebug("Path Build Confirm, path: ", ShortName()); const auto now = llarp::time_now_ms(); if(_status == ePathBuilding) { diff --git a/llarp/path/path.hpp b/llarp/path/path.hpp index c6a426dbb..68b9c74c5 100644 --- a/llarp/path/path.hpp +++ b/llarp/path/path.hpp @@ -100,7 +100,7 @@ namespace llarp llarp_time_t buildStarted = 0; Path(const std::vector< RouterContact >& routers, PathSet* parent, - PathRole startingRoles); + PathRole startingRoles, std::string shortName); util::StatusObject ExtractStatus() const; @@ -205,6 +205,9 @@ namespace llarp return _status; } + const std::string& + ShortName() const; + std::string HopsString() const; @@ -437,6 +440,8 @@ namespace llarp uint64_t m_RXRate = 0; uint64_t m_LastTXRate = 0; uint64_t m_TXRate = 0; + + const std::string m_shortName; }; } // namespace path } // namespace llarp diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 394e2ae37..8a5ca2a6a 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -440,8 +440,11 @@ namespace llarp ctx->router = m_router; auto self = GetSelf(); ctx->pathset = self; - auto path = std::make_shared< path::Path >(hops, self.get(), roles); - LogInfo(Name(), " build ", path->HopsString()); + std::string path_shortName = "[path " + m_router->ShortName() + "-"; + path_shortName = path_shortName + std::to_string(m_router->NextPathBuildNumber()) + "]"; + auto path = std::make_shared< path::Path >(hops, self.get(), roles, + std::move(path_shortName)); + LogInfo(Name(), " build ", path->ShortName(), ": ", path->HopsString()); path->SetBuildResultHook( [self](Path_ptr p) { self->HandlePathBuilt(p); }); ctx->AsyncGenerateKeys(path, m_router->logic(), m_router->threadpool(), diff --git a/llarp/path/pathset.cpp b/llarp/path/pathset.cpp index 9ec17ee86..3bc8a5366 100644 --- a/llarp/path/pathset.cpp +++ b/llarp/path/pathset.cpp @@ -298,21 +298,21 @@ namespace llarp void PathSet::HandlePathBuildTimeout(Path_ptr p) { - LogWarn(Name(), " path build ", p->HopsString(), " timed out"); + LogWarn(Name(), " path build ", p->ShortName(), " timed out"); m_BuildStats.timeouts++; } void PathSet::HandlePathBuildFailed(Path_ptr p) { - LogWarn(Name(), " path build ", p->HopsString(), " failed"); + LogWarn(Name(), " path build ", p->ShortName(), " failed"); m_BuildStats.fails++; } void PathSet::PathBuildStarted(Path_ptr p) { - LogInfo(Name(), " path build ", p->HopsString(), " started"); + LogInfo(Name(), " path build ", p->ShortName(), " started"); m_BuildStats.attempts++; } diff --git a/llarp/router/abstractrouter.hpp b/llarp/router/abstractrouter.hpp index 255560200..188d3c3b3 100644 --- a/llarp/router/abstractrouter.hpp +++ b/llarp/router/abstractrouter.hpp @@ -248,6 +248,12 @@ namespace llarp virtual bool HasSessionTo(const RouterID &router) const = 0; + virtual uint32_t + NextPathBuildNumber() = 0; + + virtual std::string + ShortName() const = 0; + virtual util::StatusObject ExtractStatus() const = 0; diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 3af07c3b2..86e9e39b3 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -1146,6 +1146,18 @@ namespace llarp return _linkManager.HasSessionTo(remote); } + std::string + Router::ShortName() const + { + return RouterID(pubkey()).ToString().substr(0, 8); + } + + uint32_t + Router::NextPathBuildNumber() + { + return path_build_count++; + } + void Router::ConnectToRandomRouters(int _want) { diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 05b334b11..bf3ad2e07 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -477,6 +477,12 @@ namespace llarp bool HasSessionTo(const RouterID &remote) const override; + std::string + ShortName() const; + + uint32_t + NextPathBuildNumber(); + void handle_router_ticker(); @@ -496,6 +502,8 @@ namespace llarp std::shared_ptr< llarp::KeyManager > m_keyManager; + uint32_t path_build_count = 0; + bool ShouldReportStats(llarp_time_t now) const; diff --git a/test/path/test_path.cpp b/test/path/test_path.cpp index 8630a563f..309af48f5 100644 --- a/test/path/test_path.cpp +++ b/test/path/test_path.cpp @@ -20,7 +20,7 @@ MakePath(std::vector< char > hops) std::vector< RC_t > pathHops; for(const auto& hop : hops) pathHops.push_back(MakeHop(hop)); - return std::make_shared< Path_t >(pathHops, nullptr, 0); + return std::make_shared< Path_t >(pathHops, nullptr, 0, "test"); } TEST_CASE("UniqueEndpointSet_t has unique endpoints", "[path]")