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(
|
|
|
|
Endpoint* p, HandlerFunc h, const dht::Key_t& l, const PubKey& k,
|
2020-02-14 18:06:19 +00:00
|
|
|
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
|
|
|
|
HiddenServiceAddressLookup::HandleResponse(
|
2020-01-27 21:30:41 +00:00
|
|
|
const std::set< EncryptedIntroSet >& results)
|
2019-04-21 16:44:27 +00:00
|
|
|
{
|
2020-02-19 21:58:01 +00:00
|
|
|
nonstd::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());
|
|
|
|
if(results.size() > 0)
|
|
|
|
{
|
2020-01-27 21:30:41 +00:00
|
|
|
EncryptedIntroSet selected;
|
2019-04-21 16:44:27 +00:00
|
|
|
for(const auto& introset : results)
|
|
|
|
{
|
2020-01-27 21:30:41 +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);
|
|
|
|
if(maybe.has_value())
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-04-23 14:28:59 +00:00
|
|
|
std::shared_ptr< routing::IMessage >
|
2019-04-21 16:44:27 +00:00
|
|
|
HiddenServiceAddressLookup::BuildRequestMessage()
|
|
|
|
{
|
2019-04-23 14:28:59 +00:00
|
|
|
auto msg = std::make_shared< routing::DHTMessage >();
|
2020-02-13 22:19:12 +00:00
|
|
|
msg->M.emplace_back(std::make_unique< dht::FindIntroMessage >(
|
2020-02-20 18:18:05 +00:00
|
|
|
txid, location, relayOrder));
|
2019-04-21 16:44:27 +00:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|