2018-10-19 11:41:36 +00:00
|
|
|
#include <llarp/rpc.hpp>
|
|
|
|
#include <libabyss.hpp>
|
|
|
|
|
2018-10-23 11:29:37 +00:00
|
|
|
#include "router.hpp"
|
|
|
|
|
2018-10-19 11:41:36 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace rpc
|
|
|
|
{
|
2018-10-23 11:29:37 +00:00
|
|
|
struct Handler : public ::abyss::http::IRPCHandler
|
2018-10-19 11:41:36 +00:00
|
|
|
{
|
|
|
|
llarp_router* router;
|
2018-10-23 11:29:37 +00:00
|
|
|
Handler(::abyss::http::ConnImpl* conn, llarp_router* r)
|
|
|
|
: ::abyss::http::IRPCHandler(conn), router(r)
|
|
|
|
{
|
|
|
|
}
|
2018-10-19 11:41:36 +00:00
|
|
|
|
2018-10-23 11:29:37 +00:00
|
|
|
~Handler()
|
2018-10-19 11:41:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-10-23 11:29:37 +00:00
|
|
|
HandleJSONRPC(const Method_t& method, const Params& params,
|
|
|
|
Response& response)
|
2018-10-19 11:41:36 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-23 11:29:37 +00:00
|
|
|
struct ReqHandlerImpl : public ::abyss::http::BaseReqHandler
|
|
|
|
{
|
|
|
|
ReqHandlerImpl(llarp_router* r, llarp_time_t reqtimeout)
|
|
|
|
: ::abyss::http::BaseReqHandler(reqtimeout), router(r)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
llarp_router* router;
|
|
|
|
::abyss::http::IRPCHandler*
|
|
|
|
CreateHandler(::abyss::http::ConnImpl* conn) const
|
|
|
|
{
|
|
|
|
return new Handler(conn, router);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ServerImpl
|
|
|
|
{
|
|
|
|
llarp_router* router;
|
|
|
|
ReqHandlerImpl _handler;
|
|
|
|
|
|
|
|
ServerImpl(llarp_router* r) : router(r), _handler(r, 2000)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~ServerImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Start(const std::string& addr)
|
|
|
|
{
|
|
|
|
llarp::Addr bindaddr(addr);
|
|
|
|
return _handler.ServeAsync(router->netloop, router->logic, bindaddr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-19 11:41:36 +00:00
|
|
|
Server::Server(llarp_router* r) : m_Impl(new ServerImpl(r))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Server::~Server()
|
|
|
|
{
|
|
|
|
delete m_Impl;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Server::Start(const std::string& addr)
|
|
|
|
{
|
|
|
|
return m_Impl->Start(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace rpc
|
|
|
|
} // namespace llarp
|