2019-04-21 16:44:27 +00:00
|
|
|
#include <service/hidden_service_address_lookup.hpp>
|
|
|
|
|
|
|
|
#include <dht/messages/findintro.hpp>
|
|
|
|
#include <service/endpoint.hpp>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
HiddenServiceAddressLookup::HiddenServiceAddressLookup(Endpoint* p,
|
|
|
|
HandlerFunc h,
|
|
|
|
const Address& addr,
|
|
|
|
uint64_t tx)
|
|
|
|
: IServiceLookup(p, tx, "HSLookup"), remote(addr), handle(h)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HiddenServiceAddressLookup::HandleResponse(
|
|
|
|
const std::set< IntroSet >& results)
|
|
|
|
{
|
|
|
|
LogInfo("found ", results.size(), " for ", remote.ToString());
|
|
|
|
if(results.size() > 0)
|
|
|
|
{
|
|
|
|
IntroSet selected;
|
|
|
|
for(const auto& introset : results)
|
|
|
|
{
|
|
|
|
if(selected.OtherIsNewer(introset) && introset.A.Addr() == remote)
|
|
|
|
selected = introset;
|
|
|
|
}
|
|
|
|
return handle(remote, &selected, endpoint);
|
|
|
|
}
|
|
|
|
return handle(remote, nullptr, endpoint);
|
|
|
|
}
|
|
|
|
|
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 >();
|
2019-04-22 17:38:29 +00:00
|
|
|
msg->M.emplace_back(
|
2019-04-27 11:13:16 +00:00
|
|
|
std::make_unique< dht::FindIntroMessage >(txid, remote, true));
|
2019-04-21 16:44:27 +00:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|