From 0aa43c6b07fee11069c2319ef507041ea6a18a84 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Wed, 1 Jul 2020 08:38:56 -0600 Subject: [PATCH] Pass RuntimeOptions instead of 'bool isRelay' --- daemon/main.cpp | 4 ++-- include/llarp.hpp | 4 ++-- llarp/context.cpp | 8 ++++---- test/regress/2020-06-08-key-backup-bug.cpp | 6 ++++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/daemon/main.cpp b/daemon/main.cpp index 4ac024348..0b43f49c2 100644 --- a/daemon/main.cpp +++ b/daemon/main.cpp @@ -99,7 +99,7 @@ run_main_context(const fs::path confFile, const llarp::RuntimeOptions opts) conf.Load(confFile, opts.isRouter, confFile.parent_path()); ctx = std::shared_ptr(); - ctx->Configure(opts.isRouter, {}); + ctx->Configure(opts, {}); signal(SIGINT, handle_signal); signal(SIGTERM, handle_signal); @@ -107,7 +107,7 @@ run_main_context(const fs::path confFile, const llarp::RuntimeOptions opts) signal(SIGHUP, handle_signal); #endif - ctx->Setup(opts.isRouter); + ctx->Setup(opts); llarp::util::SetThreadName("llarp-mainloop"); diff --git a/include/llarp.hpp b/include/llarp.hpp index d903137b8..880d48dd8 100644 --- a/include/llarp.hpp +++ b/include/llarp.hpp @@ -60,7 +60,7 @@ namespace llarp LoadDatabase(); void - Setup(bool isRelay); + Setup(const RuntimeOptions& opts); int Run(const RuntimeOptions& opts); @@ -69,7 +69,7 @@ namespace llarp HandleSignal(int sig); bool - Configure(bool isRelay, std::optional dataDir); + Configure(const RuntimeOptions& opts, std::optional dataDir); bool IsUp() const; diff --git a/llarp/context.cpp b/llarp/context.cpp index bbe535a81..f86d125fd 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -28,7 +28,7 @@ namespace llarp } bool - Context::Configure(bool isRelay, std::optional dataDir) + Context::Configure(const RuntimeOptions& opts, std::optional dataDir) { if (config) throw std::runtime_error("Re-configure not supported"); @@ -39,7 +39,7 @@ namespace llarp if (configfile.size()) { - if (!config->Load(configfile.c_str(), isRelay, defaultDataDir)) + if (!config->Load(configfile.c_str(), opts.isRouter, defaultDataDir)) { config.release(); llarp::LogError("failed to load config file ", configfile); @@ -78,7 +78,7 @@ namespace llarp } void - Context::Setup(bool isRelay) + Context::Setup(const RuntimeOptions& opts) { llarp::LogInfo(llarp::VERSION_FULL, " ", llarp::RELEASE_MOTTO); llarp::LogInfo("starting up"); @@ -98,7 +98,7 @@ namespace llarp nodedb = std::make_unique(router->diskworker(), nodedb_dir); - if (!router->Configure(config.get(), isRelay, nodedb.get())) + if (!router->Configure(config.get(), opts.isRouter, nodedb.get())) throw std::runtime_error("Failed to configure router"); // must be done after router is made so we can use its disk io worker diff --git a/test/regress/2020-06-08-key-backup-bug.cpp b/test/regress/2020-06-08-key-backup-bug.cpp index c63610dcf..9bf91e13f 100644 --- a/test/regress/2020-06-08-key-backup-bug.cpp +++ b/test/regress/2020-06-08-key-backup-bug.cpp @@ -5,12 +5,14 @@ #include #include +llarp::RuntimeOptions opts = {false, false, false}; + /// make a llarp_main* with 1 endpoint that specifies a keyfile static std::shared_ptr make_context(std::optional keyfile) { auto context = std::make_shared(); - context->Configure(false, {}); + context->Configure(opts, {}); context->config->network.m_endpointType = "null"; context->config->network.m_keyfile = keyfile; @@ -35,7 +37,7 @@ TEST_CASE("key backup bug regression test", "[regress]") for (size_t index = 0; index < 10; index++) { auto ctx = make_context(path); - REQUIRE_NOTHROW(ctx->Setup(false)); + REQUIRE_NOTHROW(ctx->Setup(opts)); ctx->CallSafe([ctx, index, &endpointAddress, &path]() { auto ep = ctx->router->hiddenServiceContext().GetDefault(); REQUIRE(ep != nullptr);