From fc56a018e578122b1ad664f24ff47ed1a63aa7be Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Thu, 20 Feb 2020 16:37:39 -0500 Subject: [PATCH 1/6] path builder prints hops, rest print short name --- llarp/path/path.cpp | 14 ++++++++++---- llarp/path/path.hpp | 7 ++++++- llarp/path/pathbuilder.cpp | 7 +++++-- llarp/path/pathset.cpp | 6 +++--- llarp/router/abstractrouter.hpp | 6 ++++++ llarp/router/router.cpp | 12 ++++++++++++ llarp/router/router.hpp | 8 ++++++++ test/path/test_path.cpp | 2 +- 8 files changed, 51 insertions(+), 11 deletions(-) diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index 52b77185f..ca66e03b8 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, const std::string& shortName) + : m_PathSet(parent), _role(startingRoles), m_shortName(shortName) { hops.resize(h.size()); @@ -122,6 +122,12 @@ namespace llarp return hops[0].rc.pubkey; } + 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..d8aae1a6a 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, const std::string& shortName); util::StatusObject ExtractStatus() const; @@ -205,6 +205,9 @@ namespace llarp return _status; } + 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; + + std::string m_shortName; }; } // namespace path } // namespace llarp diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 394e2ae37..2d9f4e7e1 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 = "[" + m_router->ShortName() + "-"; + path_shortName += m_router->PathBuildNumber() + "]"; + auto path = std::make_shared< path::Path >(hops, self.get(), roles, + 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..876fa6e5a 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 + PathBuildNumber() = 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..0afd2d4e7 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::PathBuildNumber() + { + return path_build_count++; + } + void Router::ConnectToRandomRouters(int _want) { diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 05b334b11..195037e40 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 + PathBuildNumber(); + 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]") From 893ef2b874ba7d0e7353aa37ca74941758eb2dff Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Thu, 20 Feb 2020 16:46:07 -0500 Subject: [PATCH 2/6] const-y-ness and move-y-ness --- llarp/path/path.cpp | 4 ++-- llarp/path/path.hpp | 6 +++--- llarp/path/pathbuilder.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index ca66e03b8..4d4b4ea6b 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -23,7 +23,7 @@ namespace llarp namespace path { Path::Path(const std::vector< RouterContact >& h, PathSet* parent, - PathRole startingRoles, const std::string& shortName) + PathRole startingRoles, std::string&& shortName) : m_PathSet(parent), _role(startingRoles), m_shortName(shortName) { @@ -122,7 +122,7 @@ namespace llarp return hops[0].rc.pubkey; } - std::string + const std::string& Path::ShortName() const { return m_shortName; diff --git a/llarp/path/path.hpp b/llarp/path/path.hpp index d8aae1a6a..5ceb2940e 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, const std::string& shortName); + PathRole startingRoles, std::string&& shortName); util::StatusObject ExtractStatus() const; @@ -205,7 +205,7 @@ namespace llarp return _status; } - std::string + const std::string& ShortName() const; std::string @@ -441,7 +441,7 @@ namespace llarp uint64_t m_LastTXRate = 0; uint64_t m_TXRate = 0; - std::string m_shortName; + const std::string m_shortName; }; } // namespace path } // namespace llarp diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 2d9f4e7e1..d33ba9da8 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -443,7 +443,7 @@ namespace llarp std::string path_shortName = "[" + m_router->ShortName() + "-"; path_shortName += m_router->PathBuildNumber() + "]"; auto path = std::make_shared< path::Path >(hops, self.get(), roles, - path_shortName); + std::move(path_shortName)); LogInfo(Name(), " build ", path->ShortName(), ": ", path->HopsString()); path->SetBuildResultHook( [self](Path_ptr p) { self->HandlePathBuilt(p); }); From ad3465ee668da6014e02f2b03c2ebbc22db7ac30 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Thu, 20 Feb 2020 16:53:04 -0500 Subject: [PATCH 3/6] std move better --- llarp/path/path.cpp | 4 ++-- llarp/path/path.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index 4d4b4ea6b..8922d8819 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, std::string&& shortName) - : m_PathSet(parent), _role(startingRoles), m_shortName(shortName) + PathRole startingRoles, std::string& shortName) + : m_PathSet(parent), _role(startingRoles), m_shortName(std::move(shortName)) { hops.resize(h.size()); diff --git a/llarp/path/path.hpp b/llarp/path/path.hpp index 5ceb2940e..2edc240ca 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, std::string&& shortName); + PathRole startingRoles, std::string& shortName); util::StatusObject ExtractStatus() const; From 74d421ac2d271ae9f8cd2b5a5432ad72c09f2e9c Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Thu, 20 Feb 2020 16:57:48 -0500 Subject: [PATCH 4/6] PathBuildNumber -> NextPathBuildNumber because increment side-effect --- llarp/path/pathbuilder.cpp | 2 +- llarp/router/abstractrouter.hpp | 2 +- llarp/router/router.cpp | 2 +- llarp/router/router.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index d33ba9da8..147214da9 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -441,7 +441,7 @@ namespace llarp auto self = GetSelf(); ctx->pathset = self; std::string path_shortName = "[" + m_router->ShortName() + "-"; - path_shortName += m_router->PathBuildNumber() + "]"; + path_shortName += 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()); diff --git a/llarp/router/abstractrouter.hpp b/llarp/router/abstractrouter.hpp index 876fa6e5a..188d3c3b3 100644 --- a/llarp/router/abstractrouter.hpp +++ b/llarp/router/abstractrouter.hpp @@ -249,7 +249,7 @@ namespace llarp HasSessionTo(const RouterID &router) const = 0; virtual uint32_t - PathBuildNumber() = 0; + NextPathBuildNumber() = 0; virtual std::string ShortName() const = 0; diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 0afd2d4e7..86e9e39b3 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -1153,7 +1153,7 @@ namespace llarp } uint32_t - Router::PathBuildNumber() + Router::NextPathBuildNumber() { return path_build_count++; } diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 195037e40..bf3ad2e07 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -481,7 +481,7 @@ namespace llarp ShortName() const; uint32_t - PathBuildNumber(); + NextPathBuildNumber(); void handle_router_ticker(); From 145efaf0bb744a020f3de1d47c19740d8f3e7cd9 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Thu, 20 Feb 2020 17:04:08 -0500 Subject: [PATCH 5/6] should probably build before committing... --- llarp/path/path.cpp | 2 +- llarp/path/path.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index 8922d8819..b648d9f16 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -23,7 +23,7 @@ namespace llarp namespace path { Path::Path(const std::vector< RouterContact >& h, PathSet* parent, - PathRole startingRoles, std::string& shortName) + PathRole startingRoles, std::string shortName) : m_PathSet(parent), _role(startingRoles), m_shortName(std::move(shortName)) { diff --git a/llarp/path/path.hpp b/llarp/path/path.hpp index 2edc240ca..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, std::string& shortName); + PathRole startingRoles, std::string shortName); util::StatusObject ExtractStatus() const; From fae86281e9046af9fc65462f0d713d8ac4f8c324 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Thu, 20 Feb 2020 17:20:17 -0500 Subject: [PATCH 6/6] make path short name look nicer --- llarp/path/pathbuilder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 147214da9..8a5ca2a6a 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -440,8 +440,8 @@ namespace llarp ctx->router = m_router; auto self = GetSelf(); ctx->pathset = self; - std::string path_shortName = "[" + m_router->ShortName() + "-"; - path_shortName += m_router->NextPathBuildNumber() + "]"; + 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());