1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

path builder prints hops, rest print short name

This commit is contained in:
Thomas Winget 2020-02-20 16:37:39 -05:00
parent 0429bafbb3
commit fc56a018e5
8 changed files with 51 additions and 11 deletions

View file

@ -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)
{

View file

@ -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

View file

@ -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(),

View file

@ -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++;
}

View file

@ -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;

View file

@ -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)
{

View file

@ -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;

View file

@ -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]")