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