lokinet/llarp/dht/explorenetworkjob.cpp

44 lines
1.1 KiB
C++
Raw Permalink Normal View History

#include "explorenetworkjob.hpp"
2019-01-22 01:14:02 +00:00
#include "context.hpp"
#include <llarp/dht/messages/findrouter.hpp>
#include <llarp/router/abstractrouter.hpp>
2019-01-22 01:14:02 +00:00
#include <llarp/nodedb.hpp>
#include <llarp/tooling/dht_event.hpp>
2019-01-22 01:14:02 +00:00
namespace llarp
{
namespace dht
{
void
ExploreNetworkJob::Start(const TXOwner& peer)
2019-01-22 01:14:02 +00:00
{
auto msg = new FindRouterMessage(peer.txid);
auto router = parent->GetRouter();
if (router)
{
router->NotifyRouterEvent<tooling::FindRouterSentEvent>(router->pubkey(), *msg);
}
parent->DHTSendTo(peer.node.as_array(), msg);
2019-01-22 01:14:02 +00:00
}
void
ExploreNetworkJob::SendReply()
{
2019-07-17 12:25:51 +00:00
llarp::LogDebug("got ", valuesFound.size(), " routers from exploration");
2019-01-22 23:50:26 +00:00
auto router = parent->GetRouter();
for (const auto& pk : valuesFound)
2019-01-22 01:14:02 +00:00
{
// lookup router
if (router and router->nodedb()->Has(pk))
continue;
2019-01-22 01:14:02 +00:00
parent->LookupRouter(
pk, [router, pk](const auto& res) { router->HandleDHTLookupForExplore(pk, res); });
2019-01-22 01:14:02 +00:00
}
}
} // namespace dht
} // namespace llarp