2018-10-19 11:41:36 +00:00
|
|
|
#ifndef LLARP_RPC_HPP
|
|
|
|
#define LLARP_RPC_HPP
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/time.hpp>
|
2020-05-06 20:38:44 +00:00
|
|
|
#include <net/ip_address.hpp>
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2018-11-01 12:47:14 +00:00
|
|
|
#include <functional>
|
2019-02-11 14:43:48 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2018-10-19 11:41:36 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2019-01-14 21:46:07 +00:00
|
|
|
struct PubKey;
|
2019-02-11 19:45:42 +00:00
|
|
|
struct AbstractRouter;
|
2018-12-10 16:26:46 +00:00
|
|
|
|
2018-10-19 11:41:36 +00:00
|
|
|
namespace rpc
|
|
|
|
{
|
|
|
|
struct ServerImpl;
|
|
|
|
|
2018-11-01 12:47:14 +00:00
|
|
|
/// jsonrpc server
|
2018-10-19 11:41:36 +00:00
|
|
|
struct Server
|
|
|
|
{
|
2019-02-11 19:45:42 +00:00
|
|
|
Server(AbstractRouter* r);
|
2018-10-19 11:41:36 +00:00
|
|
|
~Server();
|
|
|
|
|
|
|
|
bool
|
2020-05-06 20:38:44 +00:00
|
|
|
Start(const IpAddress& bindaddr);
|
2018-10-19 11:41:36 +00:00
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
/// stop and close
|
|
|
|
void
|
|
|
|
Stop();
|
|
|
|
|
2018-10-19 11:41:36 +00:00
|
|
|
private:
|
2020-04-07 18:38:56 +00:00
|
|
|
std::unique_ptr<ServerImpl> m_Impl;
|
2018-10-19 11:41:36 +00:00
|
|
|
};
|
|
|
|
|
2018-11-01 12:47:14 +00:00
|
|
|
struct CallerImpl;
|
|
|
|
|
|
|
|
/// jsonrpc caller
|
|
|
|
struct Caller
|
|
|
|
{
|
2019-02-11 19:45:42 +00:00
|
|
|
Caller(AbstractRouter* r);
|
2018-11-01 12:47:14 +00:00
|
|
|
~Caller();
|
|
|
|
|
2019-01-28 13:04:45 +00:00
|
|
|
/// set http basic auth for use with remote rpc endpoint
|
|
|
|
void
|
2019-03-13 20:01:10 +00:00
|
|
|
SetAuth(const std::string& user, const std::string& password);
|
2019-01-28 13:04:45 +00:00
|
|
|
|
2018-11-01 12:47:14 +00:00
|
|
|
/// start with jsonrpc endpoint address
|
|
|
|
bool
|
2020-05-06 20:38:44 +00:00
|
|
|
Start(const IpAddress& remote);
|
2018-11-01 12:47:14 +00:00
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
/// stop and close
|
|
|
|
void
|
|
|
|
Stop();
|
|
|
|
|
2018-11-21 17:46:33 +00:00
|
|
|
/// do per second tick
|
2018-11-01 12:47:14 +00:00
|
|
|
void
|
2018-11-21 17:46:33 +00:00
|
|
|
Tick(llarp_time_t now);
|
2018-11-01 12:47:14 +00:00
|
|
|
|
|
|
|
private:
|
2020-04-07 18:38:56 +00:00
|
|
|
std::unique_ptr<CallerImpl> m_Impl;
|
2018-11-01 12:47:14 +00:00
|
|
|
};
|
|
|
|
|
2018-10-19 11:41:36 +00:00
|
|
|
} // namespace rpc
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|