From 2761da0b5f89087d327ea731d32cda7b9806a30a Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 17 Sep 2018 08:02:09 -0400 Subject: [PATCH] actually load config --- include/llarp.hpp | 3 +-- llarp/config.cpp | 1 - llarp/context.cpp | 23 +++++++++-------------- llarp/fs.hpp | 17 ++--------------- 4 files changed, 12 insertions(+), 32 deletions(-) diff --git a/include/llarp.hpp b/include/llarp.hpp index fc7f579c7..e0f74743a 100644 --- a/include/llarp.hpp +++ b/include/llarp.hpp @@ -24,8 +24,7 @@ namespace llarp llarp_config *config = nullptr; llarp_nodedb *nodedb = nullptr; llarp_ev_loop *mainloop = nullptr; - char nodedb_dir[256] = {0}; - char conatctFile[256] = "router.signed"; + std::string nodedb_dir; bool LoadConfig(const std::string &fname); diff --git a/llarp/config.cpp b/llarp/config.cpp index 00f2a0c55..264f4349b 100644 --- a/llarp/config.cpp +++ b/llarp/config.cpp @@ -34,7 +34,6 @@ namespace llarp dns = find_section(top, "dns", section_t{}); iwp_links = find_section(top, "bind", section_t{}); services = find_section(top, "services", section_t{}); - dns = find_section(top, "dns", section_t{}); system = find_section(top, "system", section_t{}); return true; } diff --git a/llarp/context.cpp b/llarp/context.cpp index 8767f345a..7a55a2bdb 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -47,6 +47,10 @@ namespace llarp llarp::LogError("failed to load config file ", configfile); return false; } + llarp_config_iterator iter; + iter.user = this; + iter.visit = &iter_config; + llarp_config_iter(config, &iter); return router->ReloadConfig(config); } @@ -65,10 +69,6 @@ namespace llarp ctx->worker = llarp_init_threadpool(workers, "llarp-worker"); } } - else if(!strcmp(key, "contact-file")) - { - strncpy(ctx->conatctFile, val, fmin(255, strlen(val))); - } else if(!strcmp(key, "net-threads")) { ctx->num_nethreads = atoi(val); @@ -82,7 +82,7 @@ namespace llarp { if(!strcmp(key, "dir")) { - strncpy(ctx->nodedb_dir, val, sizeof(ctx->nodedb_dir)); + ctx->nodedb_dir = val; } } } @@ -92,20 +92,14 @@ namespace llarp { llarp_crypto_init(&crypto); nodedb = llarp_nodedb_new(&crypto); - if(!nodedb_dir[0]) - { - llarp::LogError("no nodedb_dir configured"); - return 0; - } - nodedb_dir[sizeof(nodedb_dir) - 1] = 0; - if(!llarp_nodedb_ensure_dir(nodedb_dir)) + if(!llarp_nodedb_ensure_dir(nodedb_dir.c_str())) { llarp::LogError("nodedb_dir is incorrect"); return 0; } // llarp::LogInfo("nodedb_dir [", nodedb_dir, "] configured!"); - ssize_t loaded = llarp_nodedb_load_dir(nodedb, nodedb_dir); + ssize_t loaded = llarp_nodedb_load_dir(nodedb, nodedb_dir.c_str()); llarp::LogInfo("nodedb_dir loaded ", loaded, " RCs from [", nodedb_dir, "]"); if(loaded < 0) @@ -122,7 +116,8 @@ namespace llarp { llarp::LogInfo(LLARP_VERSION, " ", LLARP_RELEASE_MOTTO); llarp::LogInfo("starting up"); - this->LoadDatabase(); + if(!this->LoadDatabase()) + return -1; llarp_ev_loop_alloc(&mainloop); // ensure worker thread pool diff --git a/llarp/fs.hpp b/llarp/fs.hpp index 1ac27e3be..c3816b7f2 100644 --- a/llarp/fs.hpp +++ b/llarp/fs.hpp @@ -22,8 +22,8 @@ namespace fs = std::experimental::filesystem; // openbsd needs this // linux gcc 7.2 needs this namespace fs = cpp17::filesystem; -#include #endif +#include namespace llarp { @@ -31,19 +31,7 @@ namespace llarp { typedef std::function< bool(const fs::path &) > PathVisitor; typedef std::function< void(const fs::path &, PathVisitor) > PathIter; -#if defined(USE_CXX17_FILESYSTEM) - static PathIter IterDir = [](const fs::path &path, PathVisitor visit) { - fs::directory_iterator i(path); - auto itr = fs::begin(i); - while(itr != fs::end(i)) - { - fs::path p = *itr; - if(!visit(p)) - return; - ++itr; - } - }; -#else + static PathIter IterDir = [](const fs::path &path, PathVisitor visit) { DIR *d = opendir(path.c_str()); if(d == nullptr) @@ -62,7 +50,6 @@ namespace llarp } while(ent); closedir(d); }; -#endif } // namespace util } // namespace llarp #endif // end LLARP_FS_HPP