mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-09 13:10:25 +00:00
47 lines
1.4 KiB
C++
47 lines
1.4 KiB
C++
#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);
|
|
}
|
|
|
|
std::unique_ptr< routing::IMessage >
|
|
HiddenServiceAddressLookup::BuildRequestMessage()
|
|
{
|
|
auto msg = std::make_unique< routing::DHTMessage >();
|
|
msg->M.emplace_back(
|
|
std::make_unique< dht::FindIntroMessage >(txid, remote, 0));
|
|
return msg;
|
|
}
|
|
|
|
} // namespace service
|
|
} // namespace llarp
|