|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|