2019-04-21 16:44:27 +00:00
|
|
|
#include <service/hidden_service_address_lookup.hpp>
|
|
|
|
|
|
|
|
#include <dht/messages/findintro.hpp>
|
|
|
|
#include <service/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,
|
|
|
|
uint64_t order,
|
|
|
|
uint64_t tx)
|
2020-01-27 21:30:41 +00:00
|
|
|
: IServiceLookup(p, tx, "HSLookup")
|
|
|
|
, 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))
|
2019-04-21 16:44:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
HiddenServiceAddressLookup::HandleResponse(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;
|
2020-01-27 21:30:41 +00:00
|
|
|
const Address remote(rootkey);
|
2019-04-21 16:44:27 +00:00
|
|
|
LogInfo("found ", results.size(), " for ", remote.ToString());
|
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-04-07 18:38:56 +00:00
|
|
|
if (maybe.has_value())
|
2020-01-27 21:30:41 +00:00
|
|
|
found = maybe.value();
|
2019-04-21 16:44:27 +00:00
|
|
|
}
|
2020-03-02 16:12:29 +00:00
|
|
|
return handle(remote, found, endpoint);
|
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
|