actually load config

pull/15/head
Jeff Becker 6 years ago
parent e047bfa266
commit 2761da0b5f
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

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

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

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

@ -22,8 +22,8 @@ namespace fs = std::experimental::filesystem;
// openbsd needs this
// linux gcc 7.2 needs this
namespace fs = cpp17::filesystem;
#include <dirent.h>
#endif
#include <dirent.h>
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

Loading…
Cancel
Save