lokinet/llarp/service/lookup.hpp
Jeff 21930cf667
LNS (#1342)
* initial relay side lns

* fix typo

* add reserved names and refactor test for dns

* lns name decryption

* all wired up (allegedly)

* refact to use service::EncryptedName for LNS responses to include nonce with ciphertext

* fully rwemove tag_lookup_job

* replace lns cache with DecayingHashTable

* check for lns name validity against the following rules:

* not localhost.loki, loki.loki, or snode.loki

* if it contains no dash then max 32 characters long, not including the .loki tld (and also assuming a leading subdomain has been stripped)

* These are from general DNS requirements, and also enforced in
registrations:

* Must be all [A-Za-z0-9-]. (A-Z will be lower-cased by the RPC call).

* cannot start or end with a -

* max 63 characters long if it does contain a dash

* cannot contain -- in the third and fourth characters unless it starts with xn--

* handle timeout in name lookup job by calling the right handler with std::nullopt
2020-09-17 15:18:08 -04:00

98 lines
2.2 KiB
C++

#ifndef LLARP_SERVICE_LOOKUP_HPP
#define LLARP_SERVICE_LOOKUP_HPP
#include <routing/message.hpp>
#include <service/intro_set.hpp>
#include <path/pathset.hpp>
#include <set>
namespace llarp
{
// forward declare
namespace path
{
struct Path;
}
namespace service
{
struct ILookupHolder;
constexpr size_t MaxConcurrentLookups = size_t(16);
struct IServiceLookup
{
IServiceLookup() = delete;
virtual ~IServiceLookup() = default;
/// handle lookup result for introsets
virtual bool
HandleIntrosetResponse(const std::set<EncryptedIntroSet>&)
{
return false;
}
/// handle lookup result for introsets
virtual bool HandleNameResponse(std::optional<Address>)
{
return false;
}
virtual void
HandleTimeout()
{
HandleIntrosetResponse({});
}
/// determine if this request has timed out
bool
IsTimedOut(llarp_time_t now, llarp_time_t timeout = 20s) const
{
if (now <= m_created)
return false;
return now - m_created > timeout;
}
/// build request message for service lookup
virtual std::shared_ptr<routing::IMessage>
BuildRequestMessage() = 0;
/// build a new request message and send it via a path
virtual bool
SendRequestViaPath(path::Path_ptr p, AbstractRouter* r);
ILookupHolder* m_parent;
uint64_t txid;
const std::string name;
RouterID endpoint;
util::StatusObject
ExtractStatus() const
{
auto now = time_now_ms();
util::StatusObject obj{{"txid", txid},
{"endpoint", endpoint.ToHex()},
{"name", name},
{"timedOut", IsTimedOut(now)},
{"createdAt", m_created.count()}};
return obj;
}
protected:
IServiceLookup(ILookupHolder* parent, uint64_t tx, std::string name);
llarp_time_t m_created;
};
struct ILookupHolder
{
virtual void
PutLookup(IServiceLookup* l, uint64_t txid) = 0;
};
} // namespace service
} // namespace llarp
#endif