From 08d306f6e938aedd7511088928a510bb36b1701c Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 Jul 2019 01:20:58 +0100 Subject: [PATCH] Have fromSection return void --- llarp/config/config.cpp | 67 ++++++++++++----------------------------- llarp/config/config.hpp | 44 +++++++++++++++------------ llarp/router/router.cpp | 12 ++++---- 3 files changed, 51 insertions(+), 72 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 2f9eae47a..455d8b2ae 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -16,7 +16,7 @@ namespace llarp { - bool + void RouterConfig::fromSection(string_view key, string_view val) { if(key == "netid") @@ -106,51 +106,43 @@ namespace llarp m_numNethreads = 1; } } - - return true; } - bool + + void NetworkConfig::fromSection(string_view key, string_view val) { if(key == "profiling") { if(IsTrueValue(val)) { - enableProfiling.emplace(true); + m_enableProfiling.emplace(true); } else if(IsFalseValue(val)) { - enableProfiling.emplace(false); + m_enableProfiling.emplace(false); } } if(key == "profiles") { - routerProfilesFile.assign(val.begin(), val.end()); - llarp::LogInfo("setting profiles to ", routerProfilesFile); + m_routerProfilesFile.assign(val.begin(), val.end()); + llarp::LogInfo("setting profiles to ", routerProfilesFile()); } else if(key == "strict-connect") { - strictConnect.assign(val.begin(), val.end()); + m_strictConnect.assign(val.begin(), val.end()); } - else - { - netConfig.emplace(key, val); - } - return true; } - bool + void NetdbConfig::fromSection(string_view key, string_view val) { if(key == "dir") { nodedb_dir.assign(val.begin(), val.end()); } - - return true; } - bool + void DnsConfig::fromSection(string_view key, string_view val) { if(key == "upstream") @@ -163,10 +155,9 @@ namespace llarp llarp::LogInfo("set local dns to ", val); netConfig.emplace("local-dns", val); } - return true; } - bool + void IwpConfig::fromSection(string_view key, string_view val) { // try IPv4 first @@ -212,37 +203,32 @@ namespace llarp { servers.emplace_back(key, AF_INET, proto); } - return true; } - bool + void ConnectConfig::fromSection(ABSL_ATTRIBUTE_UNUSED string_view key, string_view val) { routers.emplace_back(val.begin(), val.end()); - return true; } - bool + void ServicesConfig::fromSection(string_view key, string_view val) { services.emplace_back(std::string(key.begin(), key.end()), std::string(val.begin(), val.end())); - return true; } - bool + void SystemConfig::fromSection(string_view key, string_view val) { if(key == "pidfile") { pidfile.assign(val.begin(), val.end()); } - - return true; } - bool + void MetricsConfig::fromSection(string_view key, string_view val) { if(key == "disable-metrics") @@ -266,11 +252,9 @@ namespace llarp // consume everything else as a metric tag metricTags[std::string(key)] = std::string(val); } - - return true; } - bool + void ApiConfig::fromSection(string_view key, string_view val) { if(key == "enabled") @@ -285,11 +269,9 @@ namespace llarp { // TODO: add pubkey to whitelist } - - return true; } - bool + void LokidConfig::fromSection(string_view key, string_view val) { if(key == "service-node-seed") @@ -313,22 +295,18 @@ namespace llarp { lokidRPCPassword.assign(val.begin(), val.end()); } - - return true; } - bool + void BootstrapConfig::fromSection(string_view key, string_view val) { if(key == "add-node") { routers.emplace_back(val.begin(), val.end()); } - - return true; } - bool + void LoggingConfig::fromSection(string_view key, string_view val) { if(key == "type" && val == "syslog") @@ -367,8 +345,6 @@ namespace llarp ::abort(); } } - - return true; } template < typename Section, typename Config > @@ -380,10 +356,7 @@ namespace llarp auto visitor = [&ret](const ConfigParser::Section_t §ion) -> bool { for(const auto &sec : section) { - if(!ret.fromSection(sec.first, sec.second)) - { - return false; - } + ret.fromSection(sec.first, sec.second); } return true; }; diff --git a/llarp/config/config.hpp b/llarp/config/config.hpp index 94ae5a679..2c94e1e9f 100644 --- a/llarp/config/config.hpp +++ b/llarp/config/config.hpp @@ -59,21 +59,27 @@ namespace llarp const AddressInfo& addrInfo() const { return m_addrInfo; } int workerThreads() const { return m_workerThreads; } int numNethreads() const { return m_numNethreads; } - // clang-format on - bool + void fromSection(string_view key, string_view val); }; - struct NetworkConfig + class NetworkConfig { - absl::optional< bool > enableProfiling; - std::string routerProfilesFile = "profiles.dat"; - std::string strictConnect; - std::unordered_multimap< std::string, std::string > netConfig; + private: + absl::optional< bool > m_enableProfiling; + std::string m_routerProfilesFile = "profiles.dat"; + std::string m_strictConnect; - bool + public: + // clang-format off + const absl::optional< bool >& enableProfiling() const { return m_enableProfiling; } + const std::string& routerProfilesFile() const { return m_routerProfilesFile; } + const std::string& strictConnect() const { return m_strictConnect; } + // clang-format on + + void fromSection(string_view key, string_view val); }; @@ -81,7 +87,7 @@ namespace llarp { std::string nodedb_dir; - bool + void fromSection(string_view key, string_view val); }; @@ -89,7 +95,7 @@ namespace llarp { std::unordered_multimap< std::string, std::string > netConfig; - bool + void fromSection(string_view key, string_view val); }; @@ -99,7 +105,7 @@ namespace llarp std::vector< std::tuple< std::string, int, uint16_t > > servers; - bool + void fromSection(string_view key, string_view val); }; @@ -107,14 +113,14 @@ namespace llarp { std::vector< std::string > routers; - bool + void fromSection(string_view key, string_view val); }; struct ServicesConfig { std::vector< std::pair< std::string, std::string > > services; - bool + void fromSection(string_view key, string_view val); }; @@ -122,7 +128,7 @@ namespace llarp { std::string pidfile; - bool + void fromSection(string_view key, string_view val); }; @@ -134,7 +140,7 @@ namespace llarp std::string metricTankHost; std::map< std::string, std::string > metricTags; - bool + void fromSection(string_view key, string_view val); }; @@ -143,7 +149,7 @@ namespace llarp bool enableRPCServer = false; std::string rpcBindAddr = "127.0.0.1:1190"; - bool + void fromSection(string_view key, string_view val); }; @@ -156,14 +162,14 @@ namespace llarp std::string lokidRPCUser; std::string lokidRPCPassword; - bool + void fromSection(string_view key, string_view val); }; struct BootstrapConfig { std::vector< std::string > routers; - bool + void fromSection(string_view key, string_view val); }; @@ -172,7 +178,7 @@ namespace llarp bool m_LogJSON = false; FILE* m_LogFile = stdout; - bool + void fromSection(string_view key, string_view val); }; diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 71c9dd464..b04d90863 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -811,9 +811,9 @@ namespace llarp netConfig = conf->network.netConfig; // Network config - if(conf->network.enableProfiling.has_value()) + if(conf->network.enableProfiling().has_value()) { - if(conf->network.enableProfiling.value()) + if(conf->network.enableProfiling().value()) { routerProfiling().Enable(); LogInfo("router profiling explicitly enabled"); @@ -825,16 +825,16 @@ namespace llarp } } - if(!conf->network.routerProfilesFile.empty()) + if(!conf->network.routerProfilesFile().empty()) { - routerProfilesFile = conf->network.routerProfilesFile; + routerProfilesFile = conf->network.routerProfilesFile(); routerProfiling().Load(routerProfilesFile.c_str()); llarp::LogInfo("setting profiles to ", routerProfilesFile); } - if(!conf->network.strictConnect.empty()) + if(!conf->network.strictConnect().empty()) { - const auto &val = conf->network.strictConnect; + const auto &val = conf->network.strictConnect(); if(IsServiceNode()) { llarp::LogError("cannot use strict-connect option as service node");