2019-01-22 01:14:02 +00:00
|
|
|
#include <dht/serviceaddresslookup.hpp>
|
|
|
|
|
|
|
|
#include <dht/context.hpp>
|
|
|
|
#include <dht/messages/findintro.hpp>
|
|
|
|
#include <dht/messages/gotintro.hpp>
|
2019-07-30 23:42:13 +00:00
|
|
|
#include <utility>
|
2019-01-22 01:14:02 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace dht
|
|
|
|
{
|
|
|
|
ServiceAddressLookup::ServiceAddressLookup(
|
2020-04-07 18:38:56 +00:00
|
|
|
const TXOwner& asker,
|
|
|
|
const Key_t& addr,
|
|
|
|
AbstractContext* ctx,
|
|
|
|
uint32_t order,
|
|
|
|
service::EncryptedIntroSetLookupHandler handler)
|
|
|
|
: TX<TXOwner, service::EncryptedIntroSet>(asker, asker, ctx)
|
2020-03-01 15:59:19 +00:00
|
|
|
, location(addr)
|
2019-07-30 23:42:13 +00:00
|
|
|
, handleResult(std::move(handler))
|
2020-02-13 22:19:12 +00:00
|
|
|
, relayOrder(order)
|
2019-01-22 01:14:02 +00:00
|
|
|
{
|
|
|
|
peersAsked.insert(ctx->OurKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
ServiceAddressLookup::Validate(const service::EncryptedIntroSet& value) const
|
2019-01-22 01:14:02 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!value.Verify(parent->Now()))
|
2019-01-22 01:14:02 +00:00
|
|
|
{
|
|
|
|
llarp::LogWarn("Got invalid introset from service lookup");
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (value.derivedSigningKey != location)
|
2019-01-22 01:14:02 +00:00
|
|
|
{
|
|
|
|
llarp::LogWarn("got introset with wrong target from service lookup");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
ServiceAddressLookup::Start(const TXOwner& peer)
|
2019-01-22 01:14:02 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
parent->DHTSendTo(
|
|
|
|
peer.node.as_array(), new FindIntroMessage(peer.txid, location, relayOrder));
|
2019-01-22 01:14:02 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 19:43:25 +00:00
|
|
|
void
|
|
|
|
ServiceAddressLookup::SendReply()
|
|
|
|
{
|
2019-02-07 22:48:41 +00:00
|
|
|
// get newest introset
|
2020-04-07 18:38:56 +00:00
|
|
|
if (valuesFound.size())
|
2019-02-07 22:48:41 +00:00
|
|
|
{
|
2020-01-27 21:30:41 +00:00
|
|
|
llarp::service::EncryptedIntroSet found;
|
2020-04-07 18:38:56 +00:00
|
|
|
for (const auto& introset : valuesFound)
|
2019-02-08 19:43:25 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (found.OtherIsNewer(introset))
|
2019-02-07 22:48:41 +00:00
|
|
|
found = introset;
|
2019-02-08 19:43:25 +00:00
|
|
|
}
|
2019-02-07 22:48:41 +00:00
|
|
|
valuesFound.clear();
|
|
|
|
valuesFound.emplace_back(found);
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (handleResult)
|
2019-02-08 19:43:25 +00:00
|
|
|
{
|
|
|
|
handleResult(valuesFound);
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
parent->DHTSendTo(whoasked.node.as_array(), new GotIntroMessage(valuesFound, whoasked.txid));
|
2019-01-22 01:14:02 +00:00
|
|
|
}
|
|
|
|
} // namespace dht
|
|
|
|
} // namespace llarp
|