Rip out most of C API

pull/1314/head
Stephen Shelton 4 years ago
parent 4501dd8e0b
commit b5d6a73ffd
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -47,16 +47,16 @@ extern "C" LONG FAR PASCAL
win32_signal_handler(EXCEPTION_POINTERS*);
#endif
struct llarp_main* ctx = 0;
std::shared_ptr<llarp::Context> ctx;
std::promise<int> exit_code;
void
handle_signal(int sig)
{
if (ctx)
{
llarp_main_signal(ctx, sig);
}
// TODO: handle this without C API
(void)sig;
LogError("FIXME: handle signal");
abort();
}
#ifdef _WIN32
@ -86,26 +86,43 @@ handle_signal_win32(DWORD fdwCtrlType)
/// this sets up, configures and runs the main context
static void
run_main_context(std::string conffname, llarp_main_runtime_opts opts)
run_main_context(const fs::path confFile, const llarp::RuntimeOptions& opts)
{
// this is important, can downgrade from Info though
llarp::LogDebug("Running from: ", fs::current_path().string());
llarp::LogInfo("Using config file: ", conffname);
ctx = llarp_main_init(conffname.c_str(), opts.isRelay);
int code = 1;
if (ctx)
try
{
// this is important, can downgrade from Info though
llarp::LogDebug("Running from: ", fs::current_path().string());
llarp::LogInfo("Using config file: ", confFile);
llarp::Config conf;
conf.Load(confFile, opts.isRouter, confFile.parent_path());
ctx = std::shared_ptr<llarp::Context>();
ctx->Configure(opts.isRouter, {});
signal(SIGINT, handle_signal);
signal(SIGTERM, handle_signal);
#ifndef _WIN32
signal(SIGHUP, handle_signal);
#endif
code = llarp_main_setup(ctx, opts.isRelay);
ctx->Setup(opts.isRouter);
llarp::util::SetThreadName("llarp-mainloop");
if (code == 0)
code = llarp_main_run(ctx, opts);
auto result = ctx->Run(opts);
exit_code.set_value(result);
}
catch (std::exception& e)
{
llarp::LogError("Fatal: caught exception while running: ", e.what());
exit_code.set_value(1);
}
catch (...)
{
llarp::LogError("Fatal: caught non-standard exception while running");
exit_code.set_value(2);
}
exit_code.set_value(code);
}
int
@ -116,12 +133,7 @@ main(int argc, char* argv[])
{
return result;
}
llarp_main_runtime_opts opts;
const char* singleThreadVar = getenv("LLARP_SHADOW");
if (singleThreadVar && std::string(singleThreadVar) == "1")
{
opts.singleThreaded = true;
}
llarp::RuntimeOptions opts;
#ifdef _WIN32
if (startWinsock())
@ -149,7 +161,7 @@ main(int argc, char* argv[])
bool genconfigOnly = false;
bool overwrite = false;
std::string conffname;
fs::path configFile;
try
{
auto result = options.parse(argc, argv);
@ -174,7 +186,7 @@ main(int argc, char* argv[])
if (result.count("version"))
{
std::cout << llarp_version() << std::endl;
std::cout << llarp::VERSION_FULL << std::endl;
return 0;
}
@ -188,9 +200,9 @@ main(int argc, char* argv[])
opts.background = true;
}
if (result.count("relay") > 0)
if (result.count("router") > 0)
{
opts.isRelay = true;
opts.isRouter = true;
}
if (result.count("force") > 0)
@ -203,7 +215,7 @@ main(int argc, char* argv[])
auto arg = result["config"].as<std::string>();
if (!arg.empty())
{
conffname = arg;
configFile = arg;
}
}
}
@ -214,22 +226,21 @@ main(int argc, char* argv[])
return 1;
}
if (!conffname.empty())
if (!configFile.empty())
{
// when we have an explicit filepath
fs::path fname = fs::path(conffname);
fs::path basedir = fname.parent_path();
fs::path basedir = configFile.parent_path();
if (genconfigOnly)
{
llarp::ensureConfig(basedir, fname, overwrite, opts.isRelay);
llarp::ensureConfig(basedir, configFile, overwrite, opts.isRouter);
}
else
{
std::error_code ec;
if (!fs::exists(fname, ec))
if (!fs::exists(configFile, ec))
{
llarp::LogError("Config file not found ", conffname);
llarp::LogError("Config file not found ", configFile);
return 1;
}
@ -240,8 +251,8 @@ main(int argc, char* argv[])
else
{
llarp::ensureConfig(
llarp::GetDefaultDataDir(), llarp::GetDefaultConfigPath(), overwrite, opts.isRelay);
conffname = llarp::GetDefaultConfigPath().string();
llarp::GetDefaultDataDir(), llarp::GetDefaultConfigPath(), overwrite, opts.isRouter);
configFile = llarp::GetDefaultConfigPath();
}
if (genconfigOnly)
@ -249,45 +260,38 @@ main(int argc, char* argv[])
return 0;
}
std::thread main_thread{std::bind(&run_main_context, conffname, opts)};
std::thread main_thread{std::bind(&run_main_context, configFile, opts)};
auto ftr = exit_code.get_future();
do
{
// do periodic non lokinet related tasks here
if (ctx != nullptr)
if (ctx and ctx->IsUp() and not ctx->LooksAlive())
{
auto ctx_pp = llarp::Context::Get(ctx);
if (ctx_pp != nullptr)
for (const auto& wtf : {"you have been visited by the mascott of the "
"deadlocked router.",
"⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠄⠄⠄⠄",
"⠄⠄⠄⠄⠄⢀⣀⣀⡀⠄⠄⠄⡠⢲⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠄⠄",
"⠄⠄⠄⠔⣈⣀⠄⢔⡒⠳⡴⠊⠄⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⣿⣿⣧⠄⠄",
"⠄⢜⡴⢑⠖⠊⢐⣤⠞⣩⡇⠄⠄⠄⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠄⠝⠛⠋⠐",
"⢸⠏⣷⠈⠄⣱⠃⠄⢠⠃⠐⡀⠄⠄⠄⠄⠙⠻⢿⣿⣿⣿⣿⣿⣿⣿⡿⠛⠸⠄⠄⠄⠄",
"⠈⣅⠞⢁⣿⢸⠘⡄⡆⠄⠄⠈⠢⡀⠄⠄⠄⠄⠄⠄⠉⠙⠛⠛⠛⠉⠉⡀⠄⠡⢀⠄⣀",
"⠄⠙⡎⣹⢸⠄⠆⢘⠁⠄⠄⠄⢸⠈⠢⢄⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠃⠄⠄⠄⠄⠄",
"⠄⠄⠑⢿⠈⢆⠘⢼⠄⠄⠄⠄⠸⢐⢾⠄⡘⡏⠲⠆⠠⣤⢤⢤⡤⠄⣖⡇⠄⠄⠄⠄⠄",
"⣴⣶⣿⣿⣣⣈⣢⣸⠄⠄⠄⠄⡾⣷⣾⣮⣤⡏⠁⠘⠊⢠⣷⣾⡛⡟⠈⠄⠄⠄⠄⠄⠄",
"⣿⣿⣿⣿⣿⠉⠒⢽⠄⠄⠄⠄⡇⣿⣟⣿⡇⠄⠄⠄⠄⢸⣻⡿⡇⡇⠄⠄⠄⠄⠄⠄⠄",
"⠻⣿⣿⣿⣿⣄⠰⢼⠄⠄⠄⡄⠁⢻⣍⣯⠃⠄⠄⠄⠄⠈⢿⣻⠃⠈⡆⡄⠄⠄⠄⠄⠄",
"⠄⠙⠿⠿⠛⣿⣶⣤⡇⠄⠄⢣⠄⠄⠈⠄⢠⠂⠄⠁⠄⡀⠄⠄⣀⠔⢁⠃⠄⠄⠄⠄⠄",
"⠄⠄⠄⠄⠄⣿⣿⣿⣿⣾⠢⣖⣶⣦⣤⣤⣬⣤⣤⣤⣴⣶⣶⡏⠠⢃⠌⠄⠄⠄⠄⠄⠄",
"⠄⠄⠄⠄⠄⠿⠿⠟⠛⡹⠉⠛⠛⠿⠿⣿⣿⣿⣿⣿⡿⠂⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄",
"⠠⠤⠤⠄⠄⣀⠄⠄⠄⠑⠠⣤⣀⣀⣀⡘⣿⠿⠙⠻⡍⢀⡈⠂⠄⠄⠄⠄⠄⠄⠄⠄⠄",
"⠄⠄⠄⠄⠄⠄⠑⠠⣠⣴⣾⣿⣿⣿⣿⣿⣿⣇⠉⠄⠻⣿⣷⣄⡀⠄⠄⠄⠄⠄⠄⠄⠄",
"file a bug report now or be cursed with this "
"annoying image in your syslog for all time."})
{
if (ctx_pp->IsUp() and not ctx_pp->LooksAlive())
{
for (const auto& wtf : {"you have been visited by the mascott of the "
"deadlocked router.",
"⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠄⠄⠄⠄",
"⠄⠄⠄⠄⠄⢀⣀⣀⡀⠄⠄⠄⡠⢲⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠄⠄",
"⠄⠄⠄⠔⣈⣀⠄⢔⡒⠳⡴⠊⠄⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⣿⣿⣧⠄⠄",
"⠄⢜⡴⢑⠖⠊⢐⣤⠞⣩⡇⠄⠄⠄⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠄⠝⠛⠋⠐",
"⢸⠏⣷⠈⠄⣱⠃⠄⢠⠃⠐⡀⠄⠄⠄⠄⠙⠻⢿⣿⣿⣿⣿⣿⣿⣿⡿⠛⠸⠄⠄⠄⠄",
"⠈⣅⠞⢁⣿⢸⠘⡄⡆⠄⠄⠈⠢⡀⠄⠄⠄⠄⠄⠄⠉⠙⠛⠛⠛⠉⠉⡀⠄⠡⢀⠄⣀",
"⠄⠙⡎⣹⢸⠄⠆⢘⠁⠄⠄⠄⢸⠈⠢⢄⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠃⠄⠄⠄⠄⠄",
"⠄⠄⠑⢿⠈⢆⠘⢼⠄⠄⠄⠄⠸⢐⢾⠄⡘⡏⠲⠆⠠⣤⢤⢤⡤⠄⣖⡇⠄⠄⠄⠄⠄",
"⣴⣶⣿⣿⣣⣈⣢⣸⠄⠄⠄⠄⡾⣷⣾⣮⣤⡏⠁⠘⠊⢠⣷⣾⡛⡟⠈⠄⠄⠄⠄⠄⠄",
"⣿⣿⣿⣿⣿⠉⠒⢽⠄⠄⠄⠄⡇⣿⣟⣿⡇⠄⠄⠄⠄⢸⣻⡿⡇⡇⠄⠄⠄⠄⠄⠄⠄",
"⠻⣿⣿⣿⣿⣄⠰⢼⠄⠄⠄⡄⠁⢻⣍⣯⠃⠄⠄⠄⠄⠈⢿⣻⠃⠈⡆⡄⠄⠄⠄⠄⠄",
"⠄⠙⠿⠿⠛⣿⣶⣤⡇⠄⠄⢣⠄⠄⠈⠄⢠⠂⠄⠁⠄⡀⠄⠄⣀⠔⢁⠃⠄⠄⠄⠄⠄",
"⠄⠄⠄⠄⠄⣿⣿⣿⣿⣾⠢⣖⣶⣦⣤⣤⣬⣤⣤⣤⣴⣶⣶⡏⠠⢃⠌⠄⠄⠄⠄⠄⠄",
"⠄⠄⠄⠄⠄⠿⠿⠟⠛⡹⠉⠛⠛⠿⠿⣿⣿⣿⣿⣿⡿⠂⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄",
"⠠⠤⠤⠄⠄⣀⠄⠄⠄⠑⠠⣤⣀⣀⣀⡘⣿⠿⠙⠻⡍⢀⡈⠂⠄⠄⠄⠄⠄⠄⠄⠄⠄",
"⠄⠄⠄⠄⠄⠄⠑⠠⣠⣴⣾⣿⣿⣿⣿⣿⣿⣇⠉⠄⠻⣿⣷⣄⡀⠄⠄⠄⠄⠄⠄⠄⠄",
"file a bug report now or be cursed with this "
"annoying image in your syslog for all time."})
{
LogError(wtf);
llarp::LogContext::Instance().ImmediateFlush();
}
std::abort();
}
LogError(wtf);
llarp::LogContext::Instance().ImmediateFlush();
}
std::abort();
}
} while (ftr.wait_for(std::chrono::seconds(1)) != std::future_status::ready);
@ -300,7 +304,7 @@ main(int argc, char* argv[])
#endif
if (ctx)
{
llarp_main_free(ctx);
ctx.reset();
}
return code;
}

@ -8,38 +8,6 @@ extern "C"
{
#endif
/// ensure configuration exists
/// populate with defaults
/// return if this succeeded
/// if overwrite is true then overwrite old config file
/// if basedir is not nullptr then use basedir as an absolute
/// base path for all files in config
bool
llarp_ensure_config(const char*, const char*, bool overwrite, bool asrouter);
/// llarp application context for C api
struct llarp_main;
/// runtime options for main context from cli
struct llarp_main_runtime_opts
{
bool background = false;
bool debug = false;
bool singleThreaded = false;
bool isRelay = false;
};
/// llarp_application config
struct llarp_config;
/// get default config for current platform
struct llarp_config*
llarp_default_config();
/// free previously allocated configuration
void
llarp_config_free(struct llarp_config*);
/// packet writer to send packets to lokinet internals
struct llarp_vpn_writer_pipe;
/// packet reader to recv packets from lokinet internals
@ -112,10 +80,7 @@ extern "C"
void
llarp_vpn_io_close_async(struct llarp_vpn_io* io);
/// get the default endpoint's name for injection
const char*
llarp_main_get_default_endpoint_name(struct llarp_main* m);
/*
/// give main context a vpn io for mobile when it is reader to do io with
/// associated info tries to give the vpn io to endpoint with name epName a
/// deferred call to llarp_vpn_io.injected is queued unconditionally
@ -134,89 +99,7 @@ extern "C"
{
return llarp_main_inject_vpn_by_name(m, llarp_main_get_default_endpoint_name(m), io, info);
}
/// load config from file by name
/// allocates new config and puts it into c
/// return false on failure
bool
llarp_config_load_file(const char* fname, struct llarp_config** c, bool isRelay);
/// make a main context from configuration
/// copies config contents
struct llarp_main*
llarp_main_init_from_config(struct llarp_config* conf, bool isRelay);
/// initialize application context and load config
static struct llarp_main*
llarp_main_init(const char* fname, bool isRelay)
{
struct llarp_main* m = 0;
struct llarp_config* conf = 0;
if (!llarp_config_load_file(fname, &conf, isRelay))
return 0;
if (conf == NULL)
return 0;
m = llarp_main_init_from_config(conf, isRelay);
llarp_config_free(conf);
return m;
}
/// initialize applicatin context with all defaults
static struct llarp_main*
llarp_main_default_init(bool isRelay)
{
struct llarp_main* m;
struct llarp_config* conf;
conf = llarp_default_config();
if (conf == 0)
return 0;
m = llarp_main_init_from_config(conf, isRelay);
llarp_config_free(conf);
return m;
}
/// (re)configure main context
/// return true if (re)configuration was successful
bool
llarp_main_configure(struct llarp_main* ptr, struct llarp_config* conf, bool isRelay);
/// return true if this main context is running
/// return false otherwise
bool
llarp_main_is_running(struct llarp_main* ptr);
/// handle signal for main context
void
llarp_main_signal(struct llarp_main* ptr, int sig);
/// setup main context, returns 0 on success
int
llarp_main_setup(struct llarp_main* ptr, bool isRelay);
/// run main context, returns 0 on success, blocks until program end
int
llarp_main_run(struct llarp_main* ptr, struct llarp_main_runtime_opts opts);
/// tell main context to stop and wait for complete stop
/// after calling this you can call llarp_main_free safely
void
llarp_main_stop(struct llarp_main* ptr);
/// free main context and end all operations
void
llarp_main_free(struct llarp_main* ptr);
/// get version string
const char*
llarp_version();
/// return sizeof(llarp_main); for jni
size_t
llarp_main_size();
/// return sizeof(llarp_config); for jni
size_t
llarp_config_size();
*/
#ifdef __cplusplus
}

@ -4,6 +4,7 @@
#include <util/fs.hpp>
#include <util/types.hpp>
#include <ev/ev.hpp>
#include <nodedb.hpp>
#include <iostream>
#include <map>
@ -12,9 +13,6 @@
#include <vector>
struct llarp_ev_loop;
struct llarp_nodedb;
struct llarp_nodedb_iter;
struct llarp_main;
#ifdef LOKINET_HIVE
namespace tooling
@ -36,14 +34,16 @@ namespace llarp
class ThreadPool;
}
struct Context
// TODO: replace llarp_main_runtime_opts here
struct RuntimeOptions
{
/// get context from main pointer
static std::shared_ptr<Context>
Get(llarp_main*);
Context() = default;
bool background = false;
bool debug = false;
bool isRouter = false;
};
struct Context
{
std::unique_ptr<Crypto> crypto;
std::unique_ptr<CryptoManager> cryptoManager;
std::unique_ptr<AbstractRouter> router;
@ -54,20 +54,17 @@ namespace llarp
llarp_ev_loop_ptr mainloop;
std::string nodedb_dir;
bool
LoadConfig(const std::string& fname, bool isRelay);
void
Close();
int
LoadDatabase();
int
void
Setup(bool isRelay);
int
Run(llarp_main_runtime_opts opts);
Run(const RuntimeOptions& opts);
void
HandleSignal(int sig);

@ -13,6 +13,7 @@
#include <cxxopts.hpp>
#include <csignal>
#include <stdexcept>
#if (__FreeBSD__) || (__OpenBSD__) || (__NetBSD__)
#include <pthread_np.h>
@ -29,6 +30,11 @@ namespace llarp
bool
Context::Configure(bool isRelay, std::optional<fs::path> dataDir)
{
if (config)
throw std::runtime_error("Re-configure not supported");
config = std::make_unique<Config>();
fs::path defaultDataDir = dataDir ? *dataDir : GetDefaultDataDir();
if (configfile.size())
@ -71,7 +77,7 @@ namespace llarp
return 1;
}
int
void
Context::Setup(bool isRelay)
{
llarp::LogInfo(llarp::VERSION_FULL, " ", llarp::RELEASE_MOTTO);
@ -93,22 +99,17 @@ namespace llarp
nodedb = std::make_unique<llarp_nodedb>(router->diskworker(), nodedb_dir);
if (!router->Configure(config.get(), isRelay, nodedb.get()))
{
llarp::LogError("Failed to configure router");
return 1;
}
throw std::runtime_error("Failed to configure router");
// must be done after router is made so we can use its disk io worker
// must also be done after configure so that netid is properly set if it
// is provided by config
if (!this->LoadDatabase())
return 2;
return 0;
throw std::runtime_error("Config::Setup() failed to load database");
}
int
Context::Run(llarp_main_runtime_opts opts)
Context::Run(const RuntimeOptions& opts)
{
if (router == nullptr)
{
@ -209,15 +210,6 @@ namespace llarp
logic.reset();
}
bool
Context::LoadConfig(const std::string& fname, bool isRelay)
{
config = std::make_unique<Config>();
configfile = fname;
const fs::path filepath(fname);
return Configure(isRelay, filepath.parent_path());
}
#ifdef LOKINET_HIVE
void
Context::InjectHive(tooling::RouterHive* hive)
@ -251,89 +243,6 @@ namespace llarp
extern "C"
{
size_t
llarp_main_size()
{
return sizeof(llarp_main);
}
size_t
llarp_config_size()
{
return sizeof(llarp_config);
}
struct llarp_config*
llarp_default_config()
{
llarp_config* conf = new llarp_config();
#ifdef ANDROID
// put andrid config overrides here
#endif
#ifdef IOS
// put IOS config overrides here
#endif
return conf;
}
void
llarp_config_free(struct llarp_config* conf)
{
if (conf)
delete conf;
}
struct llarp_main*
llarp_main_init_from_config(struct llarp_config* conf, bool isRelay)
{
if (conf == nullptr)
return nullptr;
llarp_main* m = new llarp_main(conf);
if (m->ctx->Configure(isRelay, {}))
return m;
delete m;
return nullptr;
}
bool
llarp_config_load_file(const char* fname, struct llarp_config** conf, bool isRelay)
{
llarp_config* c = new llarp_config();
const fs::path filepath(fname);
if (c->impl.Load(fname, isRelay, filepath.parent_path()))
{
*conf = c;
return true;
}
delete c;
*conf = nullptr;
return false;
}
void
llarp_main_signal(struct llarp_main* ptr, int sig)
{
LogicCall(ptr->ctx->logic, std::bind(&llarp::Context::HandleSignal, ptr->ctx.get(), sig));
}
int
llarp_main_setup(struct llarp_main* ptr, bool isRelay)
{
return ptr->ctx->Setup(isRelay);
}
int
llarp_main_run(struct llarp_main* ptr, struct llarp_main_runtime_opts opts)
{
return ptr->ctx->Run(opts);
}
const char*
llarp_version()
{
return llarp::VERSION_FULL;
}
ssize_t
llarp_vpn_io_readpkt(struct llarp_vpn_pkt_reader* r, unsigned char* dst, size_t dstlen)
{
@ -414,59 +323,4 @@ extern "C"
llarp_vpn_io_impl* vpn = static_cast<llarp_vpn_io_impl*>(io->impl);
return &vpn->reader;
}
void
llarp_main_free(struct llarp_main* ptr)
{
delete ptr;
}
const char*
llarp_main_get_default_endpoint_name(struct llarp_main*)
{
return "default";
}
void
llarp_main_stop(struct llarp_main* ptr)
{
if (ptr == nullptr)
return;
ptr->ctx->CloseAsync();
ptr->ctx->Wait();
}
bool
llarp_main_configure(struct llarp_main* ptr, struct llarp_config* conf, bool isRelay)
{
if (ptr == nullptr || conf == nullptr)
return false;
// give new config
ptr->ctx->config.reset(new llarp::Config(conf->impl));
return ptr->ctx->Configure(isRelay, {});
}
bool
llarp_main_is_running(struct llarp_main* ptr)
{
return ptr && ptr->ctx->router && ptr->ctx->router->IsRunning();
}
}
llarp_main::llarp_main(llarp_config* conf)
: ctx(new llarp::Context())
{
ctx->config.reset(new llarp::Config(conf->impl));
}
namespace llarp
{
std::shared_ptr<Context>
Context::Get(llarp_main* m)
{
if (m == nullptr || m->ctx == nullptr)
return nullptr;
return m->ctx;
}
} // namespace llarp

@ -8,17 +8,9 @@ llarp_vpn_io_impl::AsyncClose()
{
reader.queue.disable();
writer.queue.disable();
CallSafe(std::bind(&llarp_vpn_io_impl::Expunge, this));
}
void
llarp_vpn_io_impl::CallSafe(std::function<void(void)> f)
{
auto ctx = llarp::Context::Get(ptr);
if (ctx && ctx->CallSafe(f))
return;
else if (ctx == nullptr || ctx->logic == nullptr)
f();
// TODO: call asynchronously
Expunge();
}
void
@ -28,4 +20,4 @@ llarp_vpn_io_impl::Expunge()
if (parent->closed)
parent->closed(parent);
delete this;
}
}

@ -41,9 +41,6 @@ struct llarp_vpn_io_impl
AsyncClose();
private:
void
CallSafe(std::function<void(void)> f);
void
Expunge();
};

@ -6,16 +6,17 @@
#include <catch2/catch.hpp>
/// make a llarp_main* with 1 endpoint that specifies a keyfile
static llarp_main*
static std::shared_ptr<llarp::Context>
make_context(std::optional<fs::path> keyfile)
{
auto config = llarp_default_config();
config->impl.network.m_endpointType = "null";
config->impl.network.m_keyfile = keyfile;
config->impl.bootstrap.skipBootstrap = true;
auto ptr = llarp_main_init_from_config(config, false);
llarp_config_free(config);
return ptr;
auto context = std::make_shared<llarp::Context>();
context->Configure(false, {});
context->config->network.m_endpointType = "null";
context->config->network.m_keyfile = keyfile;
context->config->bootstrap.skipBootstrap = true;
return context;
}
/// test that we dont back up all keys when self.signed is missing or invalid as client
@ -33,9 +34,8 @@ TEST_CASE("key backup bug regression test", "[regress]")
// try 10 start up and shut downs and see if our key changes or not
for (size_t index = 0; index < 10; index++)
{
auto context = make_context(path);
REQUIRE(llarp_main_setup(context, false) == 0);
auto ctx = llarp::Context::Get(context);
auto ctx = make_context(path);
REQUIRE_NOTHROW(ctx->Setup(false));
ctx->CallSafe([ctx, index, &endpointAddress, &path]() {
auto ep = ctx->router->hiddenServiceContext().GetDefault();
REQUIRE(ep != nullptr);
@ -64,8 +64,8 @@ TEST_CASE("key backup bug regression test", "[regress]")
// close the router "later" so llarp_main_run exits
ctx->CloseAsync();
});
REQUIRE(llarp_main_run(context, llarp_main_runtime_opts{}) == 0);
llarp_main_free(context);
REQUIRE(ctx->Run({}) == 0);
ctx.reset();
}
// remove keys if provied
if (path.has_value() and not path->empty())

Loading…
Cancel
Save