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/libabyss/main.cpp

53 lines
1.3 KiB
C++

#include <libabyss.hpp>
#include <llarp/net.hpp>
#include <sys/signal.h>
struct DemoHandler : public abyss::http::IRPCHandler
{
DemoHandler(abyss::http::ConnImpl* impl) : abyss::http::IRPCHandler(impl)
{
}
bool
HandleJSONRPC(const Method_t& method, const Params& params, Response& resp)
{
resp.SetObject().AddMember("test", "value", resp.GetAllocator());
return true;
}
};
struct DemoServer : public abyss::http::BaseReqHandler
{
DemoServer() : abyss::http::BaseReqHandler(1000)
{
}
abyss::http::IRPCHandler*
CreateHandler(abyss::http::ConnImpl* impl) const
{
return new DemoHandler(impl);
}
};
int
main(int argc, char* argv[])
{
signal(SIGPIPE, SIG_IGN);
llarp_threadpool* threadpool = llarp_init_same_process_threadpool();
llarp_ev_loop* loop = nullptr;
llarp_ev_loop_alloc(&loop);
llarp_logic* logic = llarp_init_single_process_logic(threadpool);
sockaddr_in addr;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons(1222);
addr.sin_family = AF_INET;
DemoServer serv;
llarp::Addr a(addr);
llarp::LogInfo("bind to ", a);
if(serv.ServeAsync(loop, logic, a))
llarp_ev_loop_run_single_process(loop, threadpool, logic);
else
llarp::LogError("Failed to serve: ", strerror(errno));
return 0;
}