You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/rpc.cpp

81 lines
1.5 KiB
C++

6 years ago
#include <llarp/rpc.hpp>
#include <libabyss.hpp>
#include "router.hpp"
6 years ago
namespace llarp
{
namespace rpc
{
struct Handler : public ::abyss::http::IRPCHandler
6 years ago
{
llarp_router* router;
Handler(::abyss::http::ConnImpl* conn, llarp_router* r)
: ::abyss::http::IRPCHandler(conn), router(r)
{
}
6 years ago
~Handler()
6 years ago
{
}
bool
HandleJSONRPC(Method_t method, Params params, Response& response)
6 years ago
{
return false;
}
};
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);
}
};
6 years ago
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