mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-17 15:25:35 +00:00
273270916e
This commit reflects changes to clang-format rules. Unfortunately, these rule changes create a massive change to the codebase, which causes an apparent rewrite of git history. Git blame's --ignore-rev flag can be used to ignore this commit when attempting to `git blame` some code.
72 lines
1.7 KiB
C++
72 lines
1.7 KiB
C++
#include <dht/recursiverouterlookup.hpp>
|
|
|
|
#include <dht/context.hpp>
|
|
#include <dht/messages/findrouter.hpp>
|
|
#include <dht/messages/gotrouter.hpp>
|
|
|
|
#include <router/abstractrouter.hpp>
|
|
#include <router/i_rc_lookup_handler.hpp>
|
|
|
|
#include <utility>
|
|
|
|
namespace llarp
|
|
{
|
|
namespace dht
|
|
{
|
|
RecursiveRouterLookup::RecursiveRouterLookup(
|
|
const TXOwner& _whoasked,
|
|
const RouterID& _target,
|
|
AbstractContext* ctx,
|
|
RouterLookupHandler result)
|
|
: TX<RouterID, RouterContact>(_whoasked, _target, ctx), resultHandler(std::move(result))
|
|
|
|
{
|
|
peersAsked.insert(ctx->OurKey());
|
|
}
|
|
|
|
bool
|
|
RecursiveRouterLookup::Validate(const RouterContact& rc) const
|
|
{
|
|
if (!rc.Verify(parent->Now()))
|
|
{
|
|
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()
|
|
{
|
|
if (valuesFound.size())
|
|
{
|
|
RouterContact found;
|
|
for (const auto& rc : valuesFound)
|
|
{
|
|
if (found.OtherIsNewer(rc) && parent->GetRouter()->rcLookupHandler().CheckRC(rc))
|
|
found = rc;
|
|
}
|
|
valuesFound.clear();
|
|
valuesFound.emplace_back(found);
|
|
}
|
|
if (resultHandler)
|
|
{
|
|
resultHandler(valuesFound);
|
|
}
|
|
if (whoasked.node != parent->OurKey())
|
|
{
|
|
parent->DHTSendTo(
|
|
whoasked.node.as_array(),
|
|
new GotRouterMessage({}, whoasked.txid, valuesFound, false),
|
|
false);
|
|
}
|
|
}
|
|
} // namespace dht
|
|
} // namespace llarp
|