Merge pull request #1116 from tewinget/short-path-names

path builder prints hops, rest print short name
pull/1120/head
Stephen Shelton 4 years ago committed by GitHub
commit 16be86a5c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,8 +23,8 @@ namespace llarp
namespace path namespace path
{ {
Path::Path(const std::vector< RouterContact >& h, PathSet* parent, Path::Path(const std::vector< RouterContact >& h, PathSet* parent,
PathRole startingRoles) PathRole startingRoles, std::string shortName)
: m_PathSet(parent), _role(startingRoles) : m_PathSet(parent), _role(startingRoles), m_shortName(std::move(shortName))
{ {
hops.resize(h.size()); hops.resize(h.size());
@ -122,6 +122,12 @@ namespace llarp
return hops[0].rc.pubkey; return hops[0].rc.pubkey;
} }
const std::string&
Path::ShortName() const
{
return m_shortName;
}
std::string std::string
Path::HopsString() const Path::HopsString() const
{ {
@ -354,7 +360,7 @@ namespace llarp
std::vector< RouterContact > newHops; std::vector< RouterContact > newHops;
for(const auto& hop : hops) for(const auto& hop : hops)
newHops.emplace_back(hop.rc); newHops.emplace_back(hop.rc);
LogInfo(Name(), " rebuilding on ", HopsString()); LogInfo(Name(), " rebuilding on ", ShortName());
m_PathSet->Build(newHops); m_PathSet->Build(newHops);
} }
@ -639,7 +645,7 @@ namespace llarp
bool bool
Path::HandlePathConfirmMessage(AbstractRouter* r) Path::HandlePathConfirmMessage(AbstractRouter* r)
{ {
LogDebug("Path Build Confirm, path: ", HopsString()); LogDebug("Path Build Confirm, path: ", ShortName());
const auto now = llarp::time_now_ms(); const auto now = llarp::time_now_ms();
if(_status == ePathBuilding) if(_status == ePathBuilding)
{ {

@ -100,7 +100,7 @@ namespace llarp
llarp_time_t buildStarted = 0; llarp_time_t buildStarted = 0;
Path(const std::vector< RouterContact >& routers, PathSet* parent, Path(const std::vector< RouterContact >& routers, PathSet* parent,
PathRole startingRoles); PathRole startingRoles, std::string shortName);
util::StatusObject util::StatusObject
ExtractStatus() const; ExtractStatus() const;
@ -205,6 +205,9 @@ namespace llarp
return _status; return _status;
} }
const std::string&
ShortName() const;
std::string std::string
HopsString() const; HopsString() const;
@ -437,6 +440,8 @@ namespace llarp
uint64_t m_RXRate = 0; uint64_t m_RXRate = 0;
uint64_t m_LastTXRate = 0; uint64_t m_LastTXRate = 0;
uint64_t m_TXRate = 0; uint64_t m_TXRate = 0;
const std::string m_shortName;
}; };
} // namespace path } // namespace path
} // namespace llarp } // namespace llarp

@ -440,8 +440,11 @@ namespace llarp
ctx->router = m_router; ctx->router = m_router;
auto self = GetSelf(); auto self = GetSelf();
ctx->pathset = self; ctx->pathset = self;
auto path = std::make_shared< path::Path >(hops, self.get(), roles); std::string path_shortName = "[path " + m_router->ShortName() + "-";
LogInfo(Name(), " build ", path->HopsString()); 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( path->SetBuildResultHook(
[self](Path_ptr p) { self->HandlePathBuilt(p); }); [self](Path_ptr p) { self->HandlePathBuilt(p); });
ctx->AsyncGenerateKeys(path, m_router->logic(), m_router->threadpool(), ctx->AsyncGenerateKeys(path, m_router->logic(), m_router->threadpool(),

@ -298,21 +298,21 @@ namespace llarp
void void
PathSet::HandlePathBuildTimeout(Path_ptr p) PathSet::HandlePathBuildTimeout(Path_ptr p)
{ {
LogWarn(Name(), " path build ", p->HopsString(), " timed out"); LogWarn(Name(), " path build ", p->ShortName(), " timed out");
m_BuildStats.timeouts++; m_BuildStats.timeouts++;
} }
void void
PathSet::HandlePathBuildFailed(Path_ptr p) PathSet::HandlePathBuildFailed(Path_ptr p)
{ {
LogWarn(Name(), " path build ", p->HopsString(), " failed"); LogWarn(Name(), " path build ", p->ShortName(), " failed");
m_BuildStats.fails++; m_BuildStats.fails++;
} }
void void
PathSet::PathBuildStarted(Path_ptr p) PathSet::PathBuildStarted(Path_ptr p)
{ {
LogInfo(Name(), " path build ", p->HopsString(), " started"); LogInfo(Name(), " path build ", p->ShortName(), " started");
m_BuildStats.attempts++; m_BuildStats.attempts++;
} }

@ -248,6 +248,12 @@ namespace llarp
virtual bool virtual bool
HasSessionTo(const RouterID &router) const = 0; HasSessionTo(const RouterID &router) const = 0;
virtual uint32_t
NextPathBuildNumber() = 0;
virtual std::string
ShortName() const = 0;
virtual util::StatusObject virtual util::StatusObject
ExtractStatus() const = 0; ExtractStatus() const = 0;

@ -1146,6 +1146,18 @@ namespace llarp
return _linkManager.HasSessionTo(remote); 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 void
Router::ConnectToRandomRouters(int _want) Router::ConnectToRandomRouters(int _want)
{ {

@ -477,6 +477,12 @@ namespace llarp
bool bool
HasSessionTo(const RouterID &remote) const override; HasSessionTo(const RouterID &remote) const override;
std::string
ShortName() const;
uint32_t
NextPathBuildNumber();
void void
handle_router_ticker(); handle_router_ticker();
@ -496,6 +502,8 @@ namespace llarp
std::shared_ptr< llarp::KeyManager > m_keyManager; std::shared_ptr< llarp::KeyManager > m_keyManager;
uint32_t path_build_count = 0;
bool bool
ShouldReportStats(llarp_time_t now) const; ShouldReportStats(llarp_time_t now) const;

@ -20,7 +20,7 @@ MakePath(std::vector< char > hops)
std::vector< RC_t > pathHops; std::vector< RC_t > pathHops;
for(const auto& hop : hops) for(const auto& hop : hops)
pathHops.push_back(MakeHop(hop)); 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]") TEST_CASE("UniqueEndpointSet_t has unique endpoints", "[path]")

Loading…
Cancel
Save