lokinet/llarp/service/hidden_service_address_lookup.cpp
Jason Rhinelander ebd2142114 Don't use std::optional::value() because f u macos
This replaces all use of std::optional's `opt.value()` with `*opt`
because macOS is great and the ghost of Steve Jobs says that actually
supporting std::optional's value() method is not for chumps before macOS
10.14.  So don't use it because Apple is great.

Pretty much all of our use of it actually is done better with operator*
anyway (since operator* doesn't do a check that the optional has a
value).

Also replaced *most* of the `has_value()` calls with direct bool
context, except for one in the config section which looked really
confusing at a glance without a has_value().
2020-05-20 19:18:28 -03:00

57 lines
1.5 KiB
C++

#include <service/hidden_service_address_lookup.hpp>
#include <dht/messages/findintro.hpp>
#include <service/endpoint.hpp>
#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)
: IServiceLookup(p, tx, "HSLookup")
, rootkey(k)
, relayOrder(order)
, location(l)
, handle(std::move(h))
{
}
bool
HiddenServiceAddressLookup::HandleResponse(const std::set<EncryptedIntroSet>& results)
{
std::optional<IntroSet> found;
const Address remote(rootkey);
LogInfo("found ", results.size(), " for ", remote.ToString());
if (results.size() > 0)
{
EncryptedIntroSet selected;
for (const auto& introset : results)
{
if (selected.OtherIsNewer(introset))
selected = introset;
}
const auto maybe = selected.MaybeDecrypt(rootkey);
if (maybe)
found = *maybe;
}
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