Convert llarp_logic to be a C++ class

This commit is contained in:
Michael 2018-12-10 14:14:55 +00:00
parent 24886ad180
commit 30e9dca2e5
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C
39 changed files with 195 additions and 224 deletions

View File

@ -171,11 +171,11 @@ main(int argc, char *argv[])
// libev version
llarp_ev_loop *netloop = nullptr;
llarp_threadpool *worker = nullptr;
llarp_logic *logic = nullptr;
llarp::Logic *logic = nullptr;
llarp_ev_loop_alloc(&netloop); // set up netio worker
worker = llarp_init_same_process_threadpool();
logic = llarp_init_single_process_logic(worker); // set up logic worker
logic = new llarp::Logic(worker); // set up logic worker
// configure main netloop
struct dnsd_context dnsd;
@ -202,10 +202,8 @@ main(int argc, char *argv[])
else
{
// need this for timer stuff
llarp_threadpool *worker = nullptr;
llarp_logic *logic = nullptr;
worker = llarp_init_same_process_threadpool();
logic = llarp_init_single_process_logic(worker); // set up logic worker
llarp_threadpool *worker = llarp_init_same_process_threadpool();
llarp::Logic *logic = new llarp::Logic(worker);
// configure main netloop
struct dnsd_context dnsd;

View File

@ -19,7 +19,7 @@ namespace llarp
llarp_crypto crypto;
llarp_router *router = nullptr;
llarp_threadpool *worker = nullptr;
llarp_logic *logic = nullptr;
llarp::Logic *logic = nullptr;
llarp_config *config = nullptr;
llarp_nodedb *nodedb = nullptr;
llarp_ev_loop *mainloop = nullptr;

View File

@ -14,7 +14,7 @@ struct dotLokiLookup
/// for timers (MAYBEFIXME? maybe we decouple this, yes pls have a generic
/// passed in)
// we can use DNSc for access to the logic
struct llarp_logic *logic;
llarp::Logic *logic;
/// which ip tracker to use
struct dns_iptracker *ip_tracker;

View File

@ -85,7 +85,7 @@ struct dnsc_context
// where to create the new sockets
struct llarp_udp_io *udp;
/// We will likely need something for timing events (timeouts)
struct llarp_logic *logic;
llarp::Logic *logic;
};
/// async (blocking w/callback) resolve a hostname using generic socks
@ -108,8 +108,7 @@ llarp_host_resolved(dnsc_answer_request *const request);
/// initialize dns subsystem and bind socket
/// returns true on bind success otherwise returns false
bool
llarp_dnsc_init(struct dnsc_context *const dnsc,
struct llarp_logic *const logic,
llarp_dnsc_init(struct dnsc_context *const dnsc, llarp::Logic *const logic,
struct llarp_ev_loop *const netloop,
const llarp::Addr &dnsc_sockaddr);

View File

@ -111,8 +111,7 @@ struct dnsd_context
/// initialize dns subsystem and bind socket
/// returns true on bind success otherwise returns false
bool
llarp_dnsd_init(struct dnsd_context *const dnsd,
struct llarp_logic *const logic,
llarp_dnsd_init(struct dnsd_context *const dnsd, llarp::Logic *const logic,
struct llarp_ev_loop *const netloop,
const llarp::Addr &dnsd_sockaddr,
const llarp::Addr &dnsc_sockaddr);

View File

@ -26,10 +26,14 @@
// forward declare
struct llarp_threadpool;
struct llarp_logic;
struct llarp_ev_loop;
namespace llarp
{
class Logic;
}
/// allocator
void
llarp_ev_loop_alloc(struct llarp_ev_loop **ev);
@ -40,12 +44,12 @@ llarp_ev_loop_free(struct llarp_ev_loop **ev);
/// run main loop
int
llarp_ev_loop_run(struct llarp_ev_loop *ev, struct llarp_logic *logic);
llarp_ev_loop_run(struct llarp_ev_loop *ev, llarp::Logic *logic);
void
llarp_ev_loop_run_single_process(struct llarp_ev_loop *ev,
struct llarp_threadpool *tp,
struct llarp_logic *logic);
llarp::Logic *logic);
/// get the current time on the event loop
llarp_time_t

View File

@ -6,7 +6,7 @@
struct llarp_iwp_args
{
struct llarp_crypto* crypto;
struct llarp_logic* logic;
llarp::Logic* logic;
struct llarp_threadpool* cryptoworker;
struct llarp_router* router;
bool permitInbound;

View File

@ -71,7 +71,7 @@ namespace llarp
TryEstablishTo(const RouterContact& rc);
bool
Start(llarp_logic* l);
Start(llarp::Logic* l);
void
Stop();
@ -139,7 +139,7 @@ namespace llarp
void
PutSession(ILinkSession* s);
llarp_logic* m_Logic = nullptr;
llarp::Logic* m_Logic = nullptr;
llarp_ev_loop* m_Loop = nullptr;
Addr m_ourAddr;
llarp_udp_io m_udp;

View File

@ -4,49 +4,54 @@
#include <llarp/threadpool.h>
#include <llarp/timer.hpp>
struct llarp_logic
namespace llarp
{
struct llarp_threadpool* thread;
struct llarp_timer_context* timer;
};
class Logic
{
private:
struct llarp_threadpool* thread;
struct llarp_timer_context* timer;
struct llarp_logic*
llarp_init_logic();
public:
Logic()
: thread(llarp_init_same_process_threadpool())
, timer(llarp_init_timer())
{
}
/// single threaded mode logic event loop
struct llarp_logic*
llarp_init_single_process_logic(struct llarp_threadpool* tp);
Logic(struct llarp_threadpool* tp) : thread(tp), timer(llarp_init_timer())
{
}
/// single threaded tick
void
llarp_logic_tick(struct llarp_logic* logic, llarp_time_t now);
/// single threaded tick
void
tick(llarp_time_t now);
/// isolated tick
void
llarp_logic_tick_async(struct llarp_logic* logic, llarp_time_t now);
/// isolated tick
void
tick_async(llarp_time_t now);
void
llarp_free_logic(struct llarp_logic** logic);
void
stop_timer();
void
llarp_logic_queue_job(struct llarp_logic* logic, struct llarp_thread_job job);
void
stop();
uint32_t
llarp_logic_call_later(struct llarp_logic* logic, struct llarp_timeout_job job);
void
mainloop();
void
llarp_logic_cancel_call(struct llarp_logic* logic, uint32_t id);
void
queue_job(struct llarp_thread_job job);
void
llarp_logic_remove_call(struct llarp_logic* logic, uint32_t id);
uint32_t
call_later(struct llarp_timeout_job job);
void
llarp_logic_stop_timer(struct llarp_logic* logic);
void
cancel_call(uint32_t id);
void
llarp_logic_stop(struct llarp_logic* logic);
void
llarp_logic_mainloop(struct llarp_logic* logic);
void
remove_call(uint32_t id);
};
} // namespace llarp
#endif

View File

@ -13,6 +13,11 @@
struct llarp_nodedb;
namespace llarp
{
class Logic;
}
/// create an empty nodedb
struct llarp_nodedb *
llarp_nodedb_new(struct llarp_crypto *crypto);
@ -93,8 +98,8 @@ struct llarp_async_verify_rc
void *user;
/// nodedb storage
struct llarp_nodedb *nodedb;
// llarp_logic for llarp_logic_queue_job
struct llarp_logic *logic; // includes a llarp_threadpool
// llarp::Logic for queue_job
llarp::Logic *logic; // includes a llarp_threadpool
// struct llarp_crypto *crypto; // probably don't need this because we have
// it in the nodedb
struct llarp_threadpool *cryptoworker;
@ -128,8 +133,8 @@ struct llarp_async_load_rc
void *user;
/// nodedb storage
struct llarp_nodedb *nodedb;
/// llarp_logic for calling hook
struct llarp_logic *logic;
/// llarp::Logic for calling hook
llarp::Logic *logic;
/// disk worker threadpool
struct llarp_threadpool *diskworker;
/// target pubkey

View File

@ -628,7 +628,7 @@ namespace llarp
llarp_crypto*
Crypto();
llarp_logic*
llarp::Logic*
Logic();
llarp_router*

View File

@ -15,7 +15,7 @@ llarp_findOrCreateIdentity(struct llarp_crypto *crypto, const char *path,
struct llarp_router *
llarp_init_router(struct llarp_threadpool *worker,
struct llarp_ev_loop *netloop, struct llarp_logic *logic);
struct llarp_ev_loop *netloop, llarp::Logic *logic);
void
llarp_free_router(struct llarp_router **router);
bool

View File

@ -47,11 +47,11 @@ namespace llarp
Tick(llarp_time_t now);
/// router's logic
llarp_logic*
llarp::Logic*
RouterLogic();
/// endpoint's logic
llarp_logic*
llarp::Logic*
EndpointLogic();
/// endpoint's net loop for sending data to user
@ -430,7 +430,7 @@ namespace llarp
private:
llarp_router* m_Router;
llarp_threadpool* m_IsolatedWorker = nullptr;
llarp_logic* m_IsolatedLogic = nullptr;
llarp::Logic* m_IsolatedLogic = nullptr;
llarp_ev_loop* m_IsolatedNetLoop = nullptr;
std::string m_Keyfile;
std::string m_Name;

View File

@ -95,7 +95,7 @@ namespace llarp
const byte_t* sharedkey, const Identity& localIdent);
bool
AsyncDecryptAndVerify(llarp_logic* logic, llarp_crypto* c,
AsyncDecryptAndVerify(llarp::Logic* logic, llarp_crypto* c,
const PathID_t& srcpath, llarp_threadpool* worker,
const Identity& localIdent,
IDataHandler* handler) const;

View File

@ -44,7 +44,7 @@ namespace abyss
~BaseReqHandler();
bool
ServeAsync(llarp_ev_loop* loop, llarp_logic* logic,
ServeAsync(llarp_ev_loop* loop, llarp::Logic* logic,
const sockaddr* bindaddr);
void
@ -75,7 +75,7 @@ namespace abyss
OnAccept(struct llarp_tcp_acceptor*, struct llarp_tcp_conn*);
llarp_ev_loop* m_loop;
llarp_logic* m_Logic;
llarp::Logic* m_Logic;
llarp_tcp_acceptor m_acceptor;
std::list< std::unique_ptr< IRPCHandler > > m_Conns;
llarp_time_t m_ReqTimeout;

View File

@ -104,7 +104,7 @@ main(__attribute__((unused)) int argc, __attribute__((unused)) char* argv[])
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);
llarp::Logic* logic = new llarp::Logic(threadpool);
sockaddr_in addr;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons(1222);

View File

@ -337,7 +337,7 @@ namespace abyss
}
bool
BaseReqHandler::ServeAsync(llarp_ev_loop* loop, llarp_logic* logic,
BaseReqHandler::ServeAsync(llarp_ev_loop* loop, llarp::Logic* logic,
const sockaddr* bindaddr)
{
m_loop = loop;

View File

@ -144,10 +144,10 @@ namespace llarp
// ensure netio thread
if(singleThreaded)
{
logic = llarp_init_single_process_logic(worker);
logic = new Logic(worker);
}
else
logic = llarp_init_logic();
logic = new Logic;
router = llarp_init_router(worker, mainloop, logic);
@ -205,7 +205,7 @@ namespace llarp
{
llarp::LogDebug("stopping logic");
if(logic)
llarp_logic_stop(logic);
logic->stop();
llarp::LogDebug("stopping event loop");
if(mainloop)
@ -239,7 +239,7 @@ namespace llarp
llarp_free_router(&router);
llarp::LogDebug("free logic");
llarp_free_logic(&logic);
delete logic;
}
bool
@ -318,7 +318,7 @@ extern "C"
void
llarp_main_abort(struct llarp_main *ptr)
{
llarp_logic_stop_timer(ptr->ctx->router->logic);
ptr->ctx->router->logic->stop_timer();
}
void
@ -443,8 +443,8 @@ extern "C"
{
// llarp::Info("llarp_main_queryDHT - setting up timer");
request->hook = &llarp_main_queryDHT_online;
llarp_logic_call_later(request->ptr->ctx->router->logic,
{1000, request, &llarp_main_checkOnline});
request->ptr->ctx->router->logic->call_later(
{1000, request, &llarp_main_checkOnline});
// llarp_dht_lookup_router(ptr->ctx->router->dht, job);
}

View File

@ -47,7 +47,7 @@ llarp_dht_lookup_router(struct llarp_dht_context *ctx,
// llarp_rc_clear(&job->result);
llarp::LogError("implement me llarp_dht_lookup_router");
/*
llarp_logic_queue_job(ctx->parent->logic,
ctx->parent->logic->queue_job(
{job, &llarp::dht::Context::queue_router_lookup});
*/
}

View File

@ -103,8 +103,7 @@ namespace llarp
return;
Context *ctx = static_cast< Context * >(u);
ctx->Explore(1);
llarp_logic_call_later(ctx->router->logic,
{orig, ctx, &handle_explore_timer});
ctx->router->logic->call_later({orig, ctx, &handle_explore_timer});
}
void
@ -269,8 +268,8 @@ namespace llarp
services = new Bucket< ISNode >(ourKey);
llarp::LogDebug("intialize dht with key ", ourKey);
// start exploring
llarp_logic_call_later(
r->logic,
r->logic->call_later(
{exploreInterval, this, &llarp::dht::Context::handle_explore_timer});
// start cleanup timer
ScheduleCleanupTimer();
@ -279,8 +278,7 @@ namespace llarp
void
Context::ScheduleCleanupTimer()
{
llarp_logic_call_later(router->logic,
{1000, this, &handle_cleaner_timer});
router->logic->call_later({1000, this, &handle_cleaner_timer});
}
void

View File

@ -465,8 +465,8 @@ llarp_dotlokilookup_handler(std::string name,
}
// nslookup on osx is about 5 sec before a retry, 2s on linux
llarp_logic_call_later(request->context->client.logic,
{2000, qr, &llarp_dotlokilookup_checkQuery});
request->context->client.logic->call_later(
{2000, qr, &llarp_dotlokilookup_checkQuery});
response->dontSendResponse = true; // will send it shortly
}

View File

@ -785,8 +785,7 @@ llarp_host_resolved(dnsc_answer_request *const request)
}
bool
llarp_dnsc_init(struct dnsc_context *const dnsc,
struct llarp_logic *const logic,
llarp_dnsc_init(struct dnsc_context *const dnsc, llarp::Logic *const logic,
struct llarp_ev_loop *const netloop,
const llarp::Addr &dnsc_sockaddr)
{

View File

@ -550,8 +550,7 @@ raw_handle_recvfrom(int *sockfd, const struct sockaddr *saddr,
}
bool
llarp_dnsd_init(struct dnsd_context *const dnsd,
struct llarp_logic *const logic,
llarp_dnsd_init(struct dnsd_context *const dnsd, llarp::Logic *const logic,
struct llarp_ev_loop *const netloop,
const llarp::Addr &dnsd_sockaddr,
const llarp::Addr &dnsc_sockaddr)

View File

@ -45,14 +45,14 @@ llarp_ev_loop_free(struct llarp_ev_loop **ev)
}
int
llarp_ev_loop_run(struct llarp_ev_loop *ev, struct llarp_logic *logic)
llarp_ev_loop_run(struct llarp_ev_loop *ev, llarp::Logic *logic)
{
while(ev->running())
{
ev->_now = llarp::time_now_ms();
ev->tick(EV_TICK_INTERVAL);
if(ev->running())
llarp_logic_tick(logic, ev->_now);
logic->tick(ev->_now);
}
return 0;
}
@ -66,7 +66,7 @@ llarp_fd_promise_wait_for_value(struct llarp_fd_promise *p)
void
llarp_ev_loop_run_single_process(struct llarp_ev_loop *ev,
struct llarp_threadpool *tp,
struct llarp_logic *logic)
llarp::Logic *logic)
{
while(ev->running())
{
@ -74,7 +74,7 @@ llarp_ev_loop_run_single_process(struct llarp_ev_loop *ev,
ev->tick(EV_TICK_INTERVAL);
if(ev->running())
{
llarp_logic_tick_async(logic, ev->_now);
logic->tick_async(ev->_now);
llarp_threadpool_tick(tp);
}
}

View File

@ -431,7 +431,7 @@ namespace llarp
TunEndpoint::Tick(llarp_time_t now)
{
// call tun code in endpoint logic in case of network isolation
// llarp_logic_queue_job(EndpointLogic(), {this, handleTickTun});
// EndpointLogic()->queue_job({this, handleTickTun});
FlushSend();
Endpoint::Tick(now);
}
@ -628,7 +628,7 @@ namespace llarp
llarp::LogWarn("packet dropped");
});
if(self->m_UserToNetworkPktQueue.Size())
llarp_logic_queue_job(self->RouterLogic(), {self, &handleNetSend});
self->RouterLogic()->queue_job({self, &handleNetSend});
}
void

View File

@ -137,7 +137,7 @@ namespace llarp
}
bool
ILinkLayer::Start(llarp_logic* l)
ILinkLayer::Start(Logic* l)
{
m_Logic = l;
ScheduleTick(100);
@ -148,7 +148,7 @@ namespace llarp
ILinkLayer::Stop()
{
if(m_Logic && tick_id)
llarp_logic_remove_call(m_Logic, tick_id);
m_Logic->remove_call(tick_id);
{
Lock l(m_AuthedLinksMutex);
auto itr = m_AuthedLinks.begin();
@ -284,8 +284,7 @@ namespace llarp
void
ILinkLayer::ScheduleTick(uint64_t interval)
{
tick_id = llarp_logic_call_later(
m_Logic, {interval, this, &ILinkLayer::on_timer_tick});
tick_id = m_Logic->call_later({interval, this, &ILinkLayer::on_timer_tick});
}
} // namespace llarp

View File

@ -2,110 +2,78 @@
#include <llarp/mem.h>
#include "logger.hpp"
struct llarp_logic*
llarp_init_logic()
namespace llarp
{
llarp_logic* logic = new llarp_logic;
if(logic)
void
Logic::tick(llarp_time_t now)
{
logic->thread = llarp_init_same_process_threadpool();
logic->timer = llarp_init_timer();
llarp_timer_set_time(this->timer, now);
llarp_timer_tick_all(this->timer);
llarp_threadpool_tick(this->thread);
}
return logic;
};
struct llarp_logic*
llarp_init_single_process_logic(struct llarp_threadpool* tp)
{
llarp_logic* logic = new llarp_logic;
if(logic)
void
Logic::tick_async(llarp_time_t now)
{
logic->thread = tp;
logic->timer = llarp_init_timer();
llarp_timer_tick_all_async(this->timer, this->thread, now);
llarp_threadpool_tick(this->thread);
}
return logic;
}
void
llarp_logic_tick(struct llarp_logic* logic, llarp_time_t now)
{
llarp_timer_set_time(logic->timer, now);
llarp_timer_tick_all(logic->timer);
llarp_threadpool_tick(logic->thread);
}
void
llarp_logic_tick_async(struct llarp_logic* logic, llarp_time_t now)
{
llarp_timer_tick_all_async(logic->timer, logic->thread, now);
llarp_threadpool_tick(logic->thread);
}
void
llarp_free_logic(struct llarp_logic** logic)
{
if(*logic)
void
Logic::stop_timer()
{
// llarp_free_timer(&(*logic)->timer);
delete *logic;
llarp_timer_stop(this->timer);
}
*logic = nullptr;
}
void
llarp_logic_stop_timer(struct llarp_logic* logic)
{
if(logic->timer)
llarp_timer_stop(logic->timer);
}
void
llarp_logic_stop(struct llarp_logic* logic)
{
llarp::LogDebug("logic thread stop");
if(logic->thread)
void
Logic::queue_job(struct llarp_thread_job job)
{
llarp_threadpool_stop(logic->thread);
llarp_threadpool_join(logic->thread);
if(job.user && job.work)
llarp_threadpool_queue_job(this->thread, {job.user, job.work});
}
llarp_free_threadpool(&logic->thread);
llarp::LogDebug("logic timer stop");
if(logic->timer)
llarp_timer_stop(logic->timer);
}
void
Logic::stop()
{
llarp::LogDebug("logic thread stop");
if(this->thread)
{
llarp_threadpool_stop(this->thread);
llarp_threadpool_join(this->thread);
}
llarp_free_threadpool(&this->thread);
void
llarp_logic_mainloop(struct llarp_logic* logic)
{
llarp_timer_run(logic->timer, logic->thread);
}
llarp::LogDebug("logic timer stop");
if(this->timer)
llarp_timer_stop(this->timer);
}
void
llarp_logic_queue_job(struct llarp_logic* logic, struct llarp_thread_job job)
{
if(job.user && job.work)
llarp_threadpool_queue_job(logic->thread, {job.user, job.work});
}
void
Logic::mainloop()
{
llarp_timer_run(this->timer, this->thread);
}
uint32_t
llarp_logic_call_later(struct llarp_logic* logic, struct llarp_timeout_job job)
{
llarp_timeout_job j;
j.user = job.user;
j.timeout = job.timeout;
j.handler = job.handler;
return llarp_timer_call_later(logic->timer, j);
}
uint32_t
Logic::call_later(struct llarp_timeout_job job)
{
llarp_timeout_job j;
j.user = job.user;
j.timeout = job.timeout;
j.handler = job.handler;
return llarp_timer_call_later(this->timer, j);
}
void
llarp_logic_cancel_call(struct llarp_logic* logic, uint32_t id)
{
llarp_timer_cancel_job(logic->timer, id);
}
void
Logic::cancel_call(uint32_t id)
{
llarp_timer_cancel_job(this->timer, id);
}
void
llarp_logic_remove_call(struct llarp_logic* logic, uint32_t id)
{
llarp_timer_remove_job(logic->timer, id);
}
void
Logic::remove_call(uint32_t id)
{
llarp_timer_remove_job(this->timer, id);
}
} // namespace llarp

View File

@ -232,8 +232,8 @@ disk_threadworker_setRC(void *user)
static_cast< llarp_async_verify_rc * >(user);
verify_request->valid = verify_request->nodedb->Insert(verify_request->rc);
if(verify_request->logic)
llarp_logic_queue_job(verify_request->logic,
{verify_request, &logic_threadworker_callback});
verify_request->logic->queue_job(
{verify_request, &logic_threadworker_callback});
}
// we run the crypto verify in the crypto threadpool worker
@ -256,8 +256,8 @@ crypto_threadworker_verifyrc(void *user)
// callback to logic thread
if(!verify_request->valid)
llarp::LogWarn("RC is not valid, can't save to disk");
llarp_logic_queue_job(verify_request->logic,
{verify_request, &logic_threadworker_callback});
verify_request->logic->queue_job(
{verify_request, &logic_threadworker_callback});
}
}
@ -279,7 +279,7 @@ nodedb_async_load_rc(void *user)
{
job->nodedb->Get(job->pubkey, job->result);
}
llarp_logic_queue_job(job->logic, {job, &nodedb_inform_load_rc});
job->logic->queue_job({job, &nodedb_inform_load_rc});
}
struct llarp_nodedb *

View File

@ -45,7 +45,7 @@ namespace llarp
return &m_Router->crypto;
}
llarp_logic*
llarp::Logic*
PathContext::Logic()
{
return m_Router->logic;

View File

@ -22,7 +22,7 @@ namespace llarp
size_t idx = 0;
llarp_router* router = nullptr;
llarp_threadpool* worker = nullptr;
llarp_logic* logic = nullptr;
llarp::Logic* logic = nullptr;
llarp_crypto* crypto = nullptr;
LR_CommitMessage LRCM;
@ -102,7 +102,7 @@ namespace llarp
if(isFarthestHop)
{
// farthest hop
llarp_logic_queue_job(ctx->logic, {ctx, &HandleDone});
ctx->logic->queue_job({ctx, &HandleDone});
}
else
{
@ -117,7 +117,7 @@ namespace llarp
/// Generate all keys asynchronously and call hadler when done
void
AsyncGenerateKeys(Path_t* p, llarp_logic* l, llarp_threadpool* pool,
AsyncGenerateKeys(Path_t* p, llarp::Logic* l, llarp_threadpool* pool,
User* u, Handler func)
{
path = p;

View File

@ -303,13 +303,13 @@ namespace llarp
// we are the farthest hop
llarp::LogDebug("We are the farthest hop for ", info);
// send a LRAM down the path
llarp_logic_queue_job(self->context->Logic(), {self, &SendPathConfirm});
self->context->Logic()->queue_job({self, &SendPathConfirm});
}
else
{
// forward upstream
// we are still in the worker thread so post job to logic
llarp_logic_queue_job(self->context->Logic(), {self, &SendLRCM});
self->context->Logic()->queue_job({self, &SendLRCM});
}
}
};

View File

@ -116,7 +116,7 @@ llarp_router_try_connect(struct llarp_router *router,
std::make_unique< TryConnectJob >(remote, link, numretries, router)));
TryConnectJob *job = itr.first->second.get();
// try establishing async
llarp_logic_queue_job(router->logic, {job, &on_try_connecting});
router->logic->queue_job({job, &on_try_connecting});
return true;
}
@ -630,8 +630,7 @@ llarp_router::SendTo(llarp::RouterID remote, const llarp::ILinkMessage *msg,
void
llarp_router::ScheduleTicker(uint64_t ms)
{
ticker_job_id =
llarp_logic_call_later(logic, {ms, this, &handle_router_ticker});
ticker_job_id = logic->call_later({ms, this, &handle_router_ticker});
}
void
@ -1036,7 +1035,7 @@ llarp_router::HasPendingConnectJob(const llarp::RouterID &remote)
struct llarp_router *
llarp_init_router(struct llarp_threadpool *tp, struct llarp_ev_loop *netloop,
struct llarp_logic *logic)
llarp::Logic *logic)
{
llarp_router *router = new llarp_router();
if(router)

View File

@ -70,7 +70,7 @@ struct llarp_router
llarp_ev_loop *netloop;
llarp_threadpool *tp;
llarp_logic *logic;
llarp::Logic *logic;
llarp_crypto crypto;
llarp::path::PathContext paths;
llarp::exit::Context exitContext;

View File

@ -1363,7 +1363,7 @@ namespace llarp
struct AsyncKeyExchange
{
llarp_logic* logic;
llarp::Logic* logic;
llarp_crypto* crypto;
SharedSecret sharedKey;
ServiceInfo remote;
@ -1377,7 +1377,7 @@ namespace llarp
IDataHandler* handler;
ConvoTag tag;
AsyncKeyExchange(llarp_logic* l, llarp_crypto* c, const ServiceInfo& r,
AsyncKeyExchange(llarp::Logic* l, llarp_crypto* c, const ServiceInfo& r,
const Identity& localident,
const PQPubKey& introsetPubKey,
const Introduction& remote, IDataHandler* h,
@ -1437,7 +1437,7 @@ namespace llarp
// encrypt and sign
if(self->frame.EncryptAndSign(self->crypto, self->msg, K,
self->m_LocalIdentity))
llarp_logic_queue_job(self->logic, {self, &Result});
self->logic->queue_job({self, &Result});
else
{
llarp::LogError("failed to encrypt and sign");
@ -1711,13 +1711,13 @@ namespace llarp
}
}
llarp_logic*
llarp::Logic*
Endpoint::RouterLogic()
{
return m_Router->logic;
}
llarp_logic*
llarp::Logic*
Endpoint::EndpointLogic()
{
return m_IsolatedLogic ? m_IsolatedLogic : m_Router->logic;

View File

@ -208,13 +208,13 @@ namespace llarp
struct AsyncFrameDecrypt
{
llarp_crypto* crypto;
llarp_logic* logic;
llarp::Logic* logic;
ProtocolMessage* msg;
const Identity& m_LocalIdentity;
IDataHandler* handler;
const ProtocolFrame frame;
AsyncFrameDecrypt(llarp_logic* l, llarp_crypto* c,
AsyncFrameDecrypt(llarp::Logic* l, llarp_crypto* c,
const Identity& localIdent, IDataHandler* h,
ProtocolMessage* m, const ProtocolFrame& f)
: crypto(c)
@ -286,8 +286,7 @@ namespace llarp
self->handler->PutCachedSessionKeyFor(self->msg->tag, sharedKey);
self->msg->handler = self->handler;
llarp_logic_queue_job(self->logic,
{self->msg, &ProtocolMessage::ProcessAsync});
self->logic->queue_job({self->msg, &ProtocolMessage::ProcessAsync});
delete self;
}
};
@ -306,7 +305,7 @@ namespace llarp
}
bool
ProtocolFrame::AsyncDecryptAndVerify(llarp_logic* logic, llarp_crypto* c,
ProtocolFrame::AsyncDecryptAndVerify(llarp::Logic* logic, llarp_crypto* c,
const PathID_t& srcPath,
llarp_threadpool* worker,
const Identity& localIdent,
@ -349,7 +348,7 @@ namespace llarp
}
msg->srcPath = srcPath;
msg->handler = handler;
llarp_logic_queue_job(logic, {msg, &ProtocolMessage::ProcessAsync});
logic->queue_job({msg, &ProtocolMessage::ProcessAsync});
return true;
}

View File

@ -9,7 +9,7 @@ struct AbyssTestBase : public ::testing::Test
llarp_crypto crypto;
llarp_threadpool* threadpool = nullptr;
llarp_ev_loop* loop = nullptr;
llarp_logic* logic = nullptr;
llarp::Logic* logic = nullptr;
abyss::httpd::BaseReqHandler* server = nullptr;
abyss::http::JSONRPC* client = nullptr;
const std::string method = "test.method";
@ -53,7 +53,7 @@ struct AbyssTestBase : public ::testing::Test
if(server->ServeAsync(loop, logic, a))
{
client->RunAsync(loop, a.ToString());
llarp_logic_call_later(logic, {1000, this, &CancelIt});
logic->call_later({1000, this, &CancelIt});
return;
}
std::this_thread::sleep_for(std::chrono::seconds(1));
@ -65,7 +65,7 @@ struct AbyssTestBase : public ::testing::Test
{
if(server)
server->Close();
llarp_logic_stop(logic);
logic->stop();
llarp_ev_loop_stop(loop);
llarp_threadpool_stop(threadpool);
}
@ -168,7 +168,7 @@ struct AbyssTest : public AbyssTestBase,
void
AsyncFlush()
{
llarp_logic_queue_job(logic, {this, &FlushIt});
logic->queue_job({this, &FlushIt});
}
void

View File

@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.hpp> // for threadpool/llarp_logic
#include "llarp/net.hpp" // for llarp::Addr
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.hpp> // for threadpool/llarp::Logic
#include "llarp/net.hpp" // for llarp::Addr
#include "llarp/dns.hpp"
#include "llarp/dnsc.hpp"
@ -91,7 +91,6 @@ TEST_F(DNSTest, TestCodeDomain)
// test decoders
TEST_F(DNSTest, TestDecodeHdr)
{
dns_msg_header hdr;
ASSERT_TRUE(decode_hdr(&this->buffer_t, &hdr));
// rewind
@ -197,7 +196,8 @@ TEST_F(DNSTest, handleDNSrecvFrom)
llarp::Zero(&buffer, 15);
ssize_t sz = 0;
// hdr->qr decides dnsc (1) or dnsd (0)
llarp_handle_dns_recvfrom((llarp_udp_io *)&udp, &addr, llarp::InitBuffer(buffer, sz));
llarp_handle_dns_recvfrom((llarp_udp_io *)&udp, &addr,
llarp::InitBuffer(buffer, sz));
// llarp_handle_dnsc_recvfrom
// llarp_handle_dnsd_recvfrom
}

View File

@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.hpp> // for threadpool/llarp_logic
#include "llarp/net.hpp" // for llarp::Addr
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.hpp> // for threadpool/llarp::Logic
#include "llarp/net.hpp" // for llarp::Addr
#include "llarp/dnsc.hpp"

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <llarp.h> // for llarp_main_init
#include <llarp/logic.hpp> // for threadpool/llarp_logic
#include <llarp/logic.hpp> // for threadpool/llarp::Logic
#include "llarp/net.hpp" // for llarp::Addr
#include "llarp/dnsd.hpp"