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
|
|
|
|
{
|
|
|
|
HiddenServiceAddressLookup::HiddenServiceAddressLookup(Endpoint* p,
|
|
|
|
HandlerFunc h,
|
2020-01-27 21:30:41 +00:00
|
|
|
const dht::Key_t& l,
|
|
|
|
const PubKey& k,
|
2019-04-21 16:44:27 +00:00
|
|
|
uint64_t tx)
|
2020-01-27 21:30:41 +00:00
|
|
|
: IServiceLookup(p, tx, "HSLookup")
|
|
|
|
, rootkey(k)
|
|
|
|
, 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-01-27 21:30:41 +00:00
|
|
|
absl::optional< IntroSet > found;
|
|
|
|
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-01-27 21:30:41 +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-07 19:55:08 +00:00
|
|
|
msg->M.emplace_back(
|
|
|
|
std::make_unique< dht::FindIntroMessage >(txid, location, 2));
|
2019-04-21 16:44:27 +00:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|