2019-01-22 01:14:02 +00:00
|
|
|
#include <dht/recursiverouterlookup.hpp>
|
|
|
|
|
|
|
|
#include <dht/context.hpp>
|
|
|
|
#include <dht/messages/findrouter.hpp>
|
|
|
|
#include <dht/messages/gotrouter.hpp>
|
2020-01-14 20:48:39 +00:00
|
|
|
|
|
|
|
#include <router/abstractrouter.hpp>
|
|
|
|
#include <router/i_rc_lookup_handler.hpp>
|
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
#include <utility>
|
2019-01-22 01:14:02 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dht
|
|
|
|
{
|
2019-08-02 09:27:27 +00:00
|
|
|
RecursiveRouterLookup::RecursiveRouterLookup(const TXOwner &_whoasked,
|
|
|
|
const RouterID &_target,
|
2019-01-24 01:31:02 +00:00
|
|
|
AbstractContext *ctx,
|
2019-01-22 01:14:02 +00:00
|
|
|
RouterLookupHandler result)
|
2019-08-02 09:27:27 +00:00
|
|
|
: TX< RouterID, RouterContact >(_whoasked, _target, ctx)
|
2019-07-30 23:42:13 +00:00
|
|
|
, resultHandler(std::move(result))
|
2019-01-22 01:14:02 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
peersAsked.insert(ctx->OurKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RecursiveRouterLookup::Validate(const RouterContact &rc) const
|
|
|
|
{
|
2019-05-28 19:45:08 +00:00
|
|
|
if(!rc.Verify(parent->Now()))
|
2019-01-22 01:14:02 +00:00
|
|
|
{
|
|
|
|
llarp::LogWarn("rc from lookup result is invalid");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RecursiveRouterLookup::Start(const TXOwner &peer)
|
|
|
|
{
|
|
|
|
parent->DHTSendTo(peer.node.as_array(),
|
|
|
|
new FindRouterMessage(peer.txid, target));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RecursiveRouterLookup::SendReply()
|
|
|
|
{
|
2019-02-08 13:42:12 +00:00
|
|
|
if(valuesFound.size())
|
|
|
|
{
|
|
|
|
RouterContact found;
|
|
|
|
for(const auto &rc : valuesFound)
|
|
|
|
{
|
2020-01-14 20:48:39 +00:00
|
|
|
if(found.OtherIsNewer(rc)
|
|
|
|
&& parent->GetRouter()->rcLookupHandler().CheckRC(rc))
|
2019-02-08 13:42:12 +00:00
|
|
|
found = rc;
|
|
|
|
}
|
|
|
|
valuesFound.clear();
|
|
|
|
valuesFound.emplace_back(found);
|
|
|
|
}
|
2019-01-22 01:14:02 +00:00
|
|
|
if(resultHandler)
|
|
|
|
{
|
|
|
|
resultHandler(valuesFound);
|
|
|
|
}
|
2020-01-22 22:08:05 +00:00
|
|
|
if(whoasked.node != parent->OurKey())
|
2019-07-19 17:21:20 +00:00
|
|
|
{
|
2019-01-22 01:14:02 +00:00
|
|
|
parent->DHTSendTo(
|
|
|
|
whoasked.node.as_array(),
|
2019-02-23 17:22:34 +00:00
|
|
|
new GotRouterMessage({}, whoasked.txid, valuesFound, false), false);
|
2019-07-19 17:21:20 +00:00
|
|
|
}
|
2019-01-22 01:14:02 +00:00
|
|
|
}
|
|
|
|
} // namespace dht
|
|
|
|
} // namespace llarp
|