mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-03 23:15:52 +00:00
7caa87862e
All #ifndef guards on headers have been removed, I think, in favor of #pragma once Headers are now included as `#include "filename"` if the included file resides in the same directory as the file including it, or any subdirectory therein. Otherwise they are included as `#include <project/top/dir/relative/path/filename>` The above does not include system/os headers.
80 lines
2.0 KiB
C++
80 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <llarp/router_id.hpp>
|
|
|
|
#include <oxenmq/oxenmq.h>
|
|
#include <oxenmq/address.h>
|
|
#include <llarp/crypto/types.hpp>
|
|
#include <llarp/dht/key.hpp>
|
|
#include <llarp/service/name.hpp>
|
|
|
|
namespace llarp
|
|
{
|
|
struct AbstractRouter;
|
|
|
|
namespace rpc
|
|
{
|
|
using LMQ_ptr = std::shared_ptr<oxenmq::OxenMQ>;
|
|
|
|
/// 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(oxenmq::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(oxenmq::Message& msg);
|
|
|
|
std::optional<oxenmq::ConnectionID> m_Connection;
|
|
LMQ_ptr m_lokiMQ;
|
|
std::string m_CurrentBlockHash;
|
|
|
|
AbstractRouter* const m_Router;
|
|
};
|
|
|
|
} // namespace rpc
|
|
} // namespace llarp
|