2020-05-18 16:06:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/router_id.hpp>
|
2020-05-18 16:06:52 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
#include <oxenmq/oxenmq.h>
|
|
|
|
#include <oxenmq/address.h>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/crypto/types.hpp>
|
|
|
|
#include <llarp/dht/key.hpp>
|
|
|
|
#include <llarp/service/name.hpp>
|
2020-05-18 16:06:52 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2020-05-19 18:53:03 +00:00
|
|
|
struct AbstractRouter;
|
|
|
|
|
2020-05-18 16:06:52 +00:00
|
|
|
namespace rpc
|
|
|
|
{
|
2021-02-03 18:12:21 +00:00
|
|
|
using LMQ_ptr = std::shared_ptr<oxenmq::OxenMQ>;
|
2020-05-19 18:53:03 +00:00
|
|
|
|
2020-05-18 16:06:52 +00:00
|
|
|
/// The LokidRpcClient uses loki-mq to talk to make API requests to lokid.
|
2020-05-19 18:53:03 +00:00
|
|
|
struct LokidRpcClient : public std::enable_shared_from_this<LokidRpcClient>
|
2020-05-21 14:09:45 +00:00
|
|
|
{
|
2020-05-18 16:06:52 +00:00
|
|
|
explicit LokidRpcClient(LMQ_ptr lmq, AbstractRouter* r);
|
2020-05-18 16:06:52 +00:00
|
|
|
|
2020-05-19 18:53:03 +00:00
|
|
|
/// Connect to lokid async
|
2020-05-18 16:06:52 +00:00
|
|
|
void
|
2021-02-03 18:12:21 +00:00
|
|
|
ConnectAsync(oxenmq::address url);
|
2020-05-18 16:06:52 +00:00
|
|
|
|
2020-05-20 11:41:42 +00:00
|
|
|
/// blocking request identity key from lokid
|
2020-06-30 16:02:29 +00:00
|
|
|
/// throws on failure
|
|
|
|
SecretKey
|
2020-05-20 11:41:42 +00:00
|
|
|
ObtainIdentityKey();
|
|
|
|
|
2020-09-17 19:18:08 +00:00
|
|
|
void
|
|
|
|
LookupLNSNameHash(
|
|
|
|
dht::Key_t namehash,
|
|
|
|
std::function<void(std::optional<service::EncryptedName>)> resultHandler);
|
|
|
|
|
2020-05-18 16:06:52 +00:00
|
|
|
private:
|
2020-05-19 18:53:03 +00:00
|
|
|
/// 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);
|
|
|
|
|
2020-05-20 11:41:42 +00:00
|
|
|
void
|
|
|
|
UpdateServiceNodeList();
|
|
|
|
|
2020-05-19 18:53:03 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-05-20 11:41:42 +00:00
|
|
|
template <typename HandlerFunc_t>
|
|
|
|
void
|
|
|
|
Request(std::string_view cmd, HandlerFunc_t func)
|
|
|
|
{
|
|
|
|
m_lokiMQ->request(*m_Connection, std::move(cmd), std::move(func));
|
|
|
|
}
|
|
|
|
|
2020-05-19 18:53:03 +00:00
|
|
|
void
|
|
|
|
HandleGotServiceNodeList(std::string json);
|
|
|
|
|
2020-07-16 22:48:26 +00:00
|
|
|
// Handles request from lokid for peer stats on a specific peer
|
|
|
|
void
|
2021-02-03 18:12:21 +00:00
|
|
|
HandleGetPeerStats(oxenmq::Message& msg);
|
2020-07-16 22:48:26 +00:00
|
|
|
|
2021-02-03 18:12:21 +00:00
|
|
|
std::optional<oxenmq::ConnectionID> m_Connection;
|
2020-05-19 18:53:03 +00:00
|
|
|
LMQ_ptr m_lokiMQ;
|
|
|
|
std::string m_CurrentBlockHash;
|
|
|
|
|
|
|
|
AbstractRouter* const m_Router;
|
2020-05-18 16:06:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace rpc
|
|
|
|
} // namespace llarp
|