lokinet/llarp/rpc/lokid_rpc_client.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

80 lines
1.9 KiB
C++

#pragma once
#include <router_id.hpp>
#include <lokimq/lokimq.h>
#include <lokimq/address.h>
#include <crypto/types.hpp>
#include <dht/key.hpp>
#include <service/name.hpp>
namespace llarp
{
struct AbstractRouter;
namespace rpc
{
using LMQ_ptr = std::shared_ptr<lokimq::LokiMQ>;
/// The LokidRpcClient uses loki-mq to talk to make API requests to lokid.
struct LokidRpcClient : public std::enable_shared_from_this<LokidRpcClient>
{
explicit LokidRpcClient(LMQ_ptr lmq, AbstractRouter* r);
/// Connect to lokid async
void
ConnectAsync(lokimq::address url);
/// blocking request identity key from lokid
/// throws on failure
SecretKey
ObtainIdentityKey();
void
LookupLNSNameHash(
dht::Key_t namehash,
std::function<void(std::optional<service::EncryptedName>)> resultHandler);
private:
/// called when we have connected to lokid via lokimq
void
Connected();
/// do a lmq command on the current connection
void
Command(std::string_view cmd);
void
UpdateServiceNodeList();
template <typename HandlerFunc_t, typename Args_t>
void
Request(std::string_view cmd, HandlerFunc_t func, const Args_t& args)
{
m_lokiMQ->request(*m_Connection, std::move(cmd), std::move(func), args);
}
template <typename HandlerFunc_t>
void
Request(std::string_view cmd, HandlerFunc_t func)
{
m_lokiMQ->request(*m_Connection, std::move(cmd), std::move(func));
}
void
HandleGotServiceNodeList(std::string json);
// Handles request from lokid for peer stats on a specific peer
void
HandleGetPeerStats(lokimq::Message& msg);
std::optional<lokimq::ConnectionID> m_Connection;
LMQ_ptr m_lokiMQ;
std::string m_CurrentBlockHash;
AbstractRouter* const m_Router;
};
} // namespace rpc
} // namespace llarp