diff --git a/llarp/dht/explorenetworkjob.cpp b/llarp/dht/explorenetworkjob.cpp index 5da2eb591..86e76521d 100644 --- a/llarp/dht/explorenetworkjob.cpp +++ b/llarp/dht/explorenetworkjob.cpp @@ -6,6 +6,8 @@ #include +#include + 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 diff --git a/llarp/dht/messages/findrouter.cpp b/llarp/dht/messages/findrouter.cpp index f1d9add3a..d6d5e8057 100644 --- a/llarp/dht/messages/findrouter.cpp +++ b/llarp/dht/messages/findrouter.cpp @@ -7,6 +7,8 @@ #include #include +#include + 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, diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 04f47a3be..ae5f22561 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -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; } diff --git a/llarp/tooling/dht_event.hpp b/llarp/tooling/dht_event.hpp index dc5abe0eb..97961cf75 100644 --- a/llarp/tooling/dht_event.hpp +++ b/llarp/tooling/dht_event.hpp @@ -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 diff --git a/pybind/llarp/tooling/router_event.cpp b/pybind/llarp/tooling/router_event.cpp index b3e01bbcb..37eb4155e 100644 --- a/pybind/llarp/tooling/router_event.cpp +++ b/pybind/llarp/tooling/router_event.cpp @@ -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