lokinet/llarp/service/hidden_service_address_lookup.cpp

62 lines
1.6 KiB
C++
Raw Normal View History

#include "hidden_service_address_lookup.hpp"
#include <llarp/dht/messages/findintro.hpp>
#include "endpoint.hpp"
2019-07-30 23:42:13 +00:00
#include <utility>
namespace llarp
{
namespace service
{
HiddenServiceAddressLookup::HiddenServiceAddressLookup(
Endpoint* p,
HandlerFunc h,
const dht::Key_t& l,
const PubKey& k,
const RouterID& ep,
uint64_t order,
uint64_t tx,
llarp_time_t timeout)
: IServiceLookup(p, tx, "HSLookup", timeout)
2020-01-27 21:30:41 +00:00
, rootkey(k)
, relayOrder(order)
2020-01-27 21:30:41 +00:00
, location(l)
, handle(std::move(h))
{
endpoint = ep;
}
bool
HiddenServiceAddressLookup::HandleIntrosetResponse(const std::set<EncryptedIntroSet>& results)
{
std::optional<IntroSet> found;
const Address remote{rootkey};
if (results.size() > 0)
{
2020-01-27 21:30:41 +00:00
EncryptedIntroSet selected;
for (const auto& introset : results)
{
if (selected.OtherIsNewer(introset))
selected = introset;
}
2020-01-27 21:30:41 +00:00
const auto maybe = selected.MaybeDecrypt(rootkey);
if (maybe)
{
LogInfo("found result for ", remote.ToString());
found = *maybe;
}
}
return handle(remote, found, endpoint, TimeLeft(time_now_ms()));
}
std::shared_ptr<routing::IMessage>
HiddenServiceAddressLookup::BuildRequestMessage()
{
auto msg = std::make_shared<routing::DHTMessage>();
msg->M.emplace_back(std::make_unique<dht::FindIntroMessage>(txid, location, relayOrder));
return msg;
}
} // namespace service
} // namespace llarp