mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
start fixing up main
This commit is contained in:
parent
87ae0aa972
commit
0f6c0d8a56
|
@ -8,7 +8,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
|||
find_package(sodium)
|
||||
|
||||
set(EXE llarpd)
|
||||
set(EXE_SRC daemon/main.c)
|
||||
set(EXE_SRC daemon/main.cpp)
|
||||
|
||||
set(LIBS ${sodium_LIBRARY_RELEASE} pthread stdc++fs jemalloc mbedx509 mbedcrypto mbedtls)
|
||||
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
[router]
|
||||
threads=1
|
||||
contact-file=router-contact.signed
|
||||
|
||||
[netdb]
|
||||
dir=./tmp-nodes
|
||||
|
||||
[iwp-connect]
|
||||
#named-node0=/path/to/routercontact0
|
||||
#named-node1=/path/to/routercontact1
|
||||
|
||||
[iwp-links]
|
||||
lo=1090
|
||||
#lo=eth
|
||||
|
|
|
@ -3,22 +3,78 @@
|
|||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
struct llarp_main {
|
||||
|
||||
static void progress() {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
struct llarp_main
|
||||
{
|
||||
struct llarp_alloc mem;
|
||||
struct llarp_router *router;
|
||||
struct llarp_threadpool *worker;
|
||||
struct llarp_threadpool *thread;
|
||||
struct llarp_logic *logic;
|
||||
struct llarp_config *config;
|
||||
struct llarp_nodedb *nodedb;
|
||||
struct llarp_ev_loop *mainloop;
|
||||
struct llarp_router *router = nullptr;
|
||||
struct llarp_threadpool *worker = nullptr;
|
||||
struct llarp_threadpool *thread = nullptr;
|
||||
struct llarp_logic *logic = nullptr;
|
||||
struct llarp_config *config = nullptr;
|
||||
struct llarp_nodedb *nodedb = nullptr;
|
||||
struct llarp_ev_loop *mainloop = nullptr;
|
||||
char nodedb_dir[256];
|
||||
int exitcode;
|
||||
|
||||
int shutdown()
|
||||
{
|
||||
printf("Shutting down ");
|
||||
|
||||
progress();
|
||||
if(mainloop)
|
||||
llarp_ev_loop_stop(mainloop);
|
||||
|
||||
progress();
|
||||
if(worker)
|
||||
llarp_threadpool_stop(worker);
|
||||
|
||||
progress();
|
||||
|
||||
if(worker)
|
||||
llarp_threadpool_join(worker);
|
||||
|
||||
progress();
|
||||
if (logic)
|
||||
llarp_logic_stop(logic);
|
||||
|
||||
progress();
|
||||
|
||||
if(router)
|
||||
llarp_stop_router(router);
|
||||
|
||||
progress();
|
||||
llarp_free_router(&router);
|
||||
|
||||
progress();
|
||||
llarp_free_config(&config);
|
||||
|
||||
progress();
|
||||
llarp_ev_loop_free(&mainloop);
|
||||
|
||||
progress();
|
||||
llarp_free_threadpool(&worker);
|
||||
|
||||
progress();
|
||||
|
||||
llarp_free_logic(&logic);
|
||||
progress();
|
||||
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
return exitcode;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void iter_main_config(struct llarp_config_iterator *itr, const char *section,
|
||||
const char *key, const char *val) {
|
||||
struct llarp_main *m = (struct llarp_main *)itr->user;
|
||||
llarp_main *m = static_cast<llarp_main *>(itr->user);
|
||||
|
||||
if (!strcmp(section, "router")) {
|
||||
if (!strcmp(key, "threads")) {
|
||||
|
@ -35,78 +91,14 @@ void iter_main_config(struct llarp_config_iterator *itr, const char *section,
|
|||
}
|
||||
}
|
||||
|
||||
static void progress() {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int shutdown_llarp(struct llarp_main *m) {
|
||||
printf("Shutting down ");
|
||||
|
||||
progress();
|
||||
if(m->mainloop)
|
||||
llarp_ev_loop_stop(m->mainloop);
|
||||
|
||||
progress();
|
||||
if(m->worker)
|
||||
llarp_threadpool_stop(m->worker);
|
||||
|
||||
progress();
|
||||
|
||||
if(m->worker)
|
||||
llarp_threadpool_join(m->worker);
|
||||
|
||||
progress();
|
||||
if (m->logic)
|
||||
{
|
||||
llarp_logic_stop(m->logic);
|
||||
}
|
||||
|
||||
progress();
|
||||
if(m->router)
|
||||
llarp_stop_router(m->router);
|
||||
|
||||
progress();
|
||||
llarp_free_router(&m->router);
|
||||
|
||||
progress();
|
||||
llarp_free_config(&m->config);
|
||||
|
||||
progress();
|
||||
llarp_ev_loop_free(&m->mainloop);
|
||||
|
||||
progress();
|
||||
llarp_free_threadpool(&m->worker);
|
||||
|
||||
progress();
|
||||
|
||||
llarp_free_logic(&m->logic);
|
||||
progress();
|
||||
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
return m->exitcode;
|
||||
}
|
||||
|
||||
struct llarp_main llarp = {
|
||||
{0,0,0},
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
{0},
|
||||
1
|
||||
};
|
||||
llarp_main llarp;
|
||||
|
||||
void run_net(void * user)
|
||||
{
|
||||
llarp_ev_loop_run(user);
|
||||
llarp_ev_loop_run(static_cast<llarp_ev_loop*>(user));
|
||||
}
|
||||
|
||||
|
||||
void handle_signal(int sig)
|
||||
{
|
||||
printf("interrupted\n");
|
||||
|
@ -162,8 +154,7 @@ int main(int argc, char *argv[]) {
|
|||
printf("failed to initialize nodedb at %s\n", dir);
|
||||
} else
|
||||
printf("no nodedb defined\n");
|
||||
|
||||
return shutdown_llarp(&llarp);
|
||||
return llarp.shutdown();
|
||||
} else
|
||||
printf("Failed to load config %s\n", conffname);
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
#ifndef LLARP_LOGIC_H
|
||||
#define LLARP_LOGIC_H
|
||||
#include <llarp/mem.h>
|
||||
#include <llarp/threadpool.h>
|
||||
#include <llarp/timer.h>
|
||||
#ifdef __cplusplus
|
||||
|
@ -8,7 +9,7 @@ extern "C" {
|
|||
|
||||
struct llarp_logic;
|
||||
|
||||
struct llarp_logic* llarp_init_logic();
|
||||
struct llarp_logic* llarp_init_logic(struct llarp_alloc * mem);
|
||||
|
||||
void llarp_free_logic(struct llarp_logic** logic);
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
namespace llarp {
|
||||
|
||||
template <typename Config, typename Section>
|
||||
static Section find_section(Config &c, const std::string &name,
|
||||
static const Section & find_section(Config &c, const std::string &name,
|
||||
const Section &fallback) {
|
||||
if (c.sections.find(name) == c.sections.end()) return fallback;
|
||||
return c.sections[name].values;
|
||||
|
@ -20,9 +20,9 @@ bool Config::Load(const char *fname) {
|
|||
auto &top = parser.top();
|
||||
router = find_section(top, "router", section_t{});
|
||||
network = find_section(top, "network", section_t{});
|
||||
connect = find_section(top, "iwp-connect", section_t{});
|
||||
netdb = find_section(top, "netdb", section_t{});
|
||||
iwp_links = find_section(top, "iwp-links", section_t{});
|
||||
dtls_links = find_section(top, "dtls-links", section_t{});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -53,7 +53,7 @@ void llarp_config_iter(struct llarp_config *conf,
|
|||
std::map<std::string, llarp::Config::section_t &> sections = {
|
||||
{"router", conf->impl.router},
|
||||
{"network", conf->impl.network},
|
||||
{"dtls-links", conf->impl.dtls_links},
|
||||
{"iwp-connect", conf->impl.connect},
|
||||
{"iwp-links", conf->impl.iwp_links},
|
||||
{"netdb", conf->impl.netdb}};
|
||||
for (const auto §ion : sections)
|
||||
|
|
|
@ -13,7 +13,7 @@ struct Config {
|
|||
section_t network;
|
||||
section_t netdb;
|
||||
section_t iwp_links;
|
||||
section_t dtls_links;
|
||||
section_t connect;
|
||||
|
||||
bool Load(const char *fname);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue