mirror of https://github.com/oxen-io/lokinet
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.
64 lines
1.5 KiB
C++
64 lines
1.5 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(Method_t method, Params params, Response& resp)
|
|
{
|
|
llarp::LogInfo("method: ", method);
|
|
resp.AddMember("result", abyss::json::Value().SetInt(1),
|
|
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);
|
|
while(true)
|
|
{
|
|
llarp::LogInfo("bind to ", a);
|
|
if(serv.ServeAsync(loop, logic, a))
|
|
{
|
|
llarp_ev_loop_run_single_process(loop, threadpool, logic);
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
llarp::LogError("Failed to serve: ", strerror(errno));
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
}
|
|
}
|
|
return 0;
|
|
}
|