PathRequestReceivedEvent implemented

pull/1184/head
Thomas Winget 4 years ago
parent c9a278c0de
commit a9882ad475

@ -13,6 +13,7 @@
#include <util/logging/logger.hpp>
#include <util/meta/memfn.hpp>
#include <util/thread/logic.hpp>
#include <tooling/router_event.hpp>
#include <functional>
#include <nonstd/optional.hpp>
@ -416,6 +417,10 @@ namespace llarp
// TODO: check if we really want to accept it
self->hop->started = now;
auto event = std::make_unique<tooling::PathRequestReceivedEvent>(
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;

@ -132,6 +132,9 @@ namespace llarp
{
if(!ctx->pathset->IsStopped())
{
tooling::RouterEventPtr event = std::make_unique<tooling::PathAttemptEvent>(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<tooling::PathBuildAttemptEvent>(m_router->pubkey(), p->hops);
m_router->NotifyRouterEvent(std::move(event));
m_BuildStats.success++;
}

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

@ -30,6 +30,9 @@ namespace llarp
std::string
ToString() const;
std::string
ShortString() const;
bool
FromString(const std::string& str);

@ -1,8 +1,7 @@
#include <tooling/router_event.hpp>
#include <tooling/router_hive.hpp>
#include <path/path.hpp>
#include <path/transit_hop.hpp>
namespace tooling
{
@ -12,16 +11,16 @@ namespace tooling
{
}
PathBuildAttemptEvent::PathBuildAttemptEvent(const llarp::RouterID& routerID, std::vector<llarp::path::PathHopConfig> hops)
: RouterEvent(routerID, false), hops(hops)
PathAttemptEvent::PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::Path> 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<const llarp::path::TransitHop> 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

@ -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<RouterEvent>;
struct PathBuildAttemptEvent : public RouterEvent
struct PathAttemptEvent : public RouterEvent
{
PathBuildAttemptEvent(const llarp::RouterID& routerID, std::vector<llarp::path::PathHopConfig> hops);
PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::Path> path);
std::string ToString() const override;
std::vector<llarp::path::PathHopConfig> hops;
};
struct PathRequestReceivedEvent : public RouterEvent
{
PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::TransitHop> hop);
std::string ToString() const override;
llarp::RouterID prevHop;
llarp::RouterID nextHop;
bool isEndpoint = false;
};
} // namespace tooling

@ -15,8 +15,13 @@ namespace tooling
.def_readonly("routerID", &RouterEvent::routerID)
.def_readonly("triggered", &RouterEvent::triggered);
py::class_<PathBuildAttemptEvent, RouterEvent>(mod, "PathBuildAttemptEvent")
.def_readonly("hops", &PathBuildAttemptEvent::hops);
py::class_<PathAttemptEvent, RouterEvent>(mod, "PathAttemptEvent")
.def_readonly("hops", &PathAttemptEvent::hops);
py::class_<PathRequestReceivedEvent, RouterEvent>(mod, "PathRequestReceivedEvent")
.def_readonly("prevHop", &PathRequestReceivedEvent::prevHop)
.def_readonly("nextHop", &PathRequestReceivedEvent::nextHop)
.def_readonly("isEndpoint", &PathRequestReceivedEvent::isEndpoint);
}
} // namespace tooling

Loading…
Cancel
Save