lokinet/llarp/service/hidden_service_address_lookup.cpp

55 lines
1.5 KiB
C++
Raw Normal View History

#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>
namespace llarp
{
namespace service
{
HiddenServiceAddressLookup::HiddenServiceAddressLookup(
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)
, relayOrder(order)
2020-01-27 21:30:41 +00:00
, location(l)
, handle(std::move(h))
{
}
bool
HiddenServiceAddressLookup::HandleResponse(
2020-01-27 21:30:41 +00:00
const std::set< EncryptedIntroSet >& results)
{
nonstd::optional< IntroSet > found;
2020-01-27 21:30:41 +00:00
const Address remote(rootkey);
LogInfo("found ", results.size(), " for ", remote.ToString());
if(results.size() > 0)
{
2020-01-27 21:30:41 +00:00
EncryptedIntroSet selected;
for(const auto& introset : results)
{
2020-01-27 21:30:41 +00:00
if(selected.OtherIsNewer(introset))
selected = introset;
}
2020-01-27 21:30:41 +00:00
const auto maybe = selected.MaybeDecrypt(rootkey);
if(maybe.has_value())
found = maybe.value();
}
2020-03-02 16:12:29 +00:00
return handle(remote, found, endpoint);
}
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