Add FindRouterSentEvent and FindRouterReceivedEvent to RouterHive

pull/1184/head
Stephen Shelton 4 years ago
parent 84a1d7dbcc
commit 6664202868
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -6,6 +6,8 @@
#include <nodedb.hpp>
#include <tooling/dht_event.hpp>
namespace llarp
{
namespace dht
@ -13,7 +15,14 @@ namespace llarp
void
ExploreNetworkJob::Start(const TXOwner &peer)
{
parent->DHTSendTo(peer.node.as_array(), new FindRouterMessage(peer.txid));
auto msg = new FindRouterMessage(peer.txid);
auto router = parent->GetRouter();
auto ev = std::make_unique< tooling::FindRouterSentEvent >(router->pubkey());
ev->targetKey = msg->targetKey;
router->NotifyRouterEvent(std::move(ev));
parent->DHTSendTo(peer.node.as_array(), msg);
}
void

@ -7,6 +7,8 @@
#include <router/abstractrouter.hpp>
#include <routing/dht_message.hpp>
#include <tooling/dht_event.hpp>
namespace llarp
{
namespace dht
@ -152,6 +154,16 @@ namespace llarp
std::vector< std::unique_ptr< IMessage > > &replies) const
{
auto &dht = *ctx->impl;
auto router = dht.GetRouter();
auto ev = std::make_unique< tooling::FindRouterReceivedEvent >(router->pubkey());
ev->targetKey = targetKey;
ev->iterative = iterative;
ev->exploritory = exploritory;
ev->txid = txid;
ev->version = version;
router->NotifyRouterEvent(std::move(ev));
if(!dht.AllowTransit())
{
llarp::LogWarn("Got DHT lookup from ", From,

@ -782,6 +782,12 @@ namespace llarp
if(path && path->SendRoutingMessage(msg, Router()))
{
auto ev = std::make_unique< tooling::FindRouterSentEvent >(m_router->pubkey());
ev->txid = txid;
ev->targetKey = router;
m_router->NotifyRouterEvent(std::move(ev));
routers.emplace(router, RouterLookupJob(this, handler));
return true;
}

@ -54,4 +54,59 @@ namespace tooling
std::string
ToString() const override;
};
struct FindRouterSentEvent : public RouterEvent
{
llarp::dht::Key_t from;
llarp::RouterID targetKey;
bool iterative = false;
bool exploritory = false;
uint64_t txid = 0;
uint64_t version = 0;
FindRouterSentEvent(const llarp::RouterID& ourRouter)
: RouterEvent("DHT: FindRouterSentEvent", ourRouter, true)
{
}
std::string
ToString() const override
{
return RouterEvent::ToString()
+" from "+ from.ShortHex()
+", targetKey: "+ targetKey.ToString()
+", iterative: "+ std::to_string(iterative)
+", exploritory "+ std::to_string(exploritory)
+", txid "+ std::to_string(txid)
+", version "+ std::to_string(version);
}
};
struct FindRouterReceivedEvent : public RouterEvent
{
llarp::dht::Key_t from;
llarp::RouterID targetKey;
bool iterative = false;
bool exploritory = false;
uint64_t txid = 0;
uint64_t version = 0;
FindRouterReceivedEvent(const llarp::RouterID& ourRouter)
: RouterEvent("DHT: FindRouterReceivedEvent", ourRouter, false)
{
}
std::string
ToString() const override
{
return RouterEvent::ToString()
+" from "+ from.ShortHex()
+", targetKey: "+ targetKey.ToString()
+", iterative: "+ std::to_string(iterative)
+", exploritory "+ std::to_string(exploritory)
+", txid "+ std::to_string(txid)
+", version "+ std::to_string(version);
}
};
} // namespace tooling

@ -67,6 +67,20 @@ namespace tooling
py::class_< RCGossipSentEvent, RouterEvent >(mod, "RCGossipSentEvent")
.def_readonly("rc", &RCGossipSentEvent::rc)
.def("LongString", &RCGossipSentEvent::LongString);
py::class_< FindRouterSentEvent, RouterEvent >(mod, "FindRouterSentEvent")
.def_readonly("from", &FindRouterSentEvent::from)
.def_readonly("iterative", &FindRouterSentEvent::iterative)
.def_readonly("exploritory", &FindRouterSentEvent::exploritory)
.def_readonly("txid", &FindRouterSentEvent::txid)
.def_readonly("version", &FindRouterSentEvent::version);
py::class_< FindRouterReceivedEvent, RouterEvent >(mod, "FindRouterReceivedEvent")
.def_readonly("from", &FindRouterReceivedEvent::from)
.def_readonly("iterative", &FindRouterReceivedEvent::iterative)
.def_readonly("exploritory", &FindRouterReceivedEvent::exploritory)
.def_readonly("txid", &FindRouterReceivedEvent::txid)
.def_readonly("version", &FindRouterReceivedEvent::version);
}
} // namespace tooling

Loading…
Cancel
Save