Have fromSection return void

pull/687/head
Michael 5 years ago
parent 937f28f75d
commit 08d306f6e9
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -16,7 +16,7 @@
namespace llarp namespace llarp
{ {
bool void
RouterConfig::fromSection(string_view key, string_view val) RouterConfig::fromSection(string_view key, string_view val)
{ {
if(key == "netid") if(key == "netid")
@ -106,51 +106,43 @@ namespace llarp
m_numNethreads = 1; m_numNethreads = 1;
} }
} }
return true;
} }
bool
void
NetworkConfig::fromSection(string_view key, string_view val) NetworkConfig::fromSection(string_view key, string_view val)
{ {
if(key == "profiling") if(key == "profiling")
{ {
if(IsTrueValue(val)) if(IsTrueValue(val))
{ {
enableProfiling.emplace(true); m_enableProfiling.emplace(true);
} }
else if(IsFalseValue(val)) else if(IsFalseValue(val))
{ {
enableProfiling.emplace(false); m_enableProfiling.emplace(false);
} }
} }
if(key == "profiles") if(key == "profiles")
{ {
routerProfilesFile.assign(val.begin(), val.end()); m_routerProfilesFile.assign(val.begin(), val.end());
llarp::LogInfo("setting profiles to ", routerProfilesFile); llarp::LogInfo("setting profiles to ", routerProfilesFile());
} }
else if(key == "strict-connect") 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) NetdbConfig::fromSection(string_view key, string_view val)
{ {
if(key == "dir") if(key == "dir")
{ {
nodedb_dir.assign(val.begin(), val.end()); nodedb_dir.assign(val.begin(), val.end());
} }
return true;
} }
bool void
DnsConfig::fromSection(string_view key, string_view val) DnsConfig::fromSection(string_view key, string_view val)
{ {
if(key == "upstream") if(key == "upstream")
@ -163,10 +155,9 @@ namespace llarp
llarp::LogInfo("set local dns to ", val); llarp::LogInfo("set local dns to ", val);
netConfig.emplace("local-dns", val); netConfig.emplace("local-dns", val);
} }
return true;
} }
bool void
IwpConfig::fromSection(string_view key, string_view val) IwpConfig::fromSection(string_view key, string_view val)
{ {
// try IPv4 first // try IPv4 first
@ -212,37 +203,32 @@ namespace llarp
{ {
servers.emplace_back(key, AF_INET, proto); servers.emplace_back(key, AF_INET, proto);
} }
return true;
} }
bool void
ConnectConfig::fromSection(ABSL_ATTRIBUTE_UNUSED string_view key, ConnectConfig::fromSection(ABSL_ATTRIBUTE_UNUSED string_view key,
string_view val) string_view val)
{ {
routers.emplace_back(val.begin(), val.end()); routers.emplace_back(val.begin(), val.end());
return true;
} }
bool void
ServicesConfig::fromSection(string_view key, string_view val) ServicesConfig::fromSection(string_view key, string_view val)
{ {
services.emplace_back(std::string(key.begin(), key.end()), services.emplace_back(std::string(key.begin(), key.end()),
std::string(val.begin(), val.end())); std::string(val.begin(), val.end()));
return true;
} }
bool void
SystemConfig::fromSection(string_view key, string_view val) SystemConfig::fromSection(string_view key, string_view val)
{ {
if(key == "pidfile") if(key == "pidfile")
{ {
pidfile.assign(val.begin(), val.end()); pidfile.assign(val.begin(), val.end());
} }
return true;
} }
bool void
MetricsConfig::fromSection(string_view key, string_view val) MetricsConfig::fromSection(string_view key, string_view val)
{ {
if(key == "disable-metrics") if(key == "disable-metrics")
@ -266,11 +252,9 @@ namespace llarp
// consume everything else as a metric tag // consume everything else as a metric tag
metricTags[std::string(key)] = std::string(val); metricTags[std::string(key)] = std::string(val);
} }
return true;
} }
bool void
ApiConfig::fromSection(string_view key, string_view val) ApiConfig::fromSection(string_view key, string_view val)
{ {
if(key == "enabled") if(key == "enabled")
@ -285,11 +269,9 @@ namespace llarp
{ {
// TODO: add pubkey to whitelist // TODO: add pubkey to whitelist
} }
return true;
} }
bool void
LokidConfig::fromSection(string_view key, string_view val) LokidConfig::fromSection(string_view key, string_view val)
{ {
if(key == "service-node-seed") if(key == "service-node-seed")
@ -313,22 +295,18 @@ namespace llarp
{ {
lokidRPCPassword.assign(val.begin(), val.end()); lokidRPCPassword.assign(val.begin(), val.end());
} }
return true;
} }
bool void
BootstrapConfig::fromSection(string_view key, string_view val) BootstrapConfig::fromSection(string_view key, string_view val)
{ {
if(key == "add-node") if(key == "add-node")
{ {
routers.emplace_back(val.begin(), val.end()); routers.emplace_back(val.begin(), val.end());
} }
return true;
} }
bool void
LoggingConfig::fromSection(string_view key, string_view val) LoggingConfig::fromSection(string_view key, string_view val)
{ {
if(key == "type" && val == "syslog") if(key == "type" && val == "syslog")
@ -367,8 +345,6 @@ namespace llarp
::abort(); ::abort();
} }
} }
return true;
} }
template < typename Section, typename Config > template < typename Section, typename Config >
@ -380,10 +356,7 @@ namespace llarp
auto visitor = [&ret](const ConfigParser::Section_t &section) -> bool { auto visitor = [&ret](const ConfigParser::Section_t &section) -> bool {
for(const auto &sec : section) for(const auto &sec : section)
{ {
if(!ret.fromSection(sec.first, sec.second)) ret.fromSection(sec.first, sec.second);
{
return false;
}
} }
return true; return true;
}; };

@ -59,21 +59,27 @@ namespace llarp
const AddressInfo& addrInfo() const { return m_addrInfo; } const AddressInfo& addrInfo() const { return m_addrInfo; }
int workerThreads() const { return m_workerThreads; } int workerThreads() const { return m_workerThreads; }
int numNethreads() const { return m_numNethreads; } int numNethreads() const { return m_numNethreads; }
// clang-format on // clang-format on
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };
struct NetworkConfig class NetworkConfig
{ {
absl::optional< bool > enableProfiling; private:
std::string routerProfilesFile = "profiles.dat"; absl::optional< bool > m_enableProfiling;
std::string strictConnect; std::string m_routerProfilesFile = "profiles.dat";
std::unordered_multimap< std::string, std::string > netConfig; 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); fromSection(string_view key, string_view val);
}; };
@ -81,7 +87,7 @@ namespace llarp
{ {
std::string nodedb_dir; std::string nodedb_dir;
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };
@ -89,7 +95,7 @@ namespace llarp
{ {
std::unordered_multimap< std::string, std::string > netConfig; std::unordered_multimap< std::string, std::string > netConfig;
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };
@ -99,7 +105,7 @@ namespace llarp
std::vector< std::tuple< std::string, int, uint16_t > > servers; std::vector< std::tuple< std::string, int, uint16_t > > servers;
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };
@ -107,14 +113,14 @@ namespace llarp
{ {
std::vector< std::string > routers; std::vector< std::string > routers;
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };
struct ServicesConfig struct ServicesConfig
{ {
std::vector< std::pair< std::string, std::string > > services; std::vector< std::pair< std::string, std::string > > services;
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };
@ -122,7 +128,7 @@ namespace llarp
{ {
std::string pidfile; std::string pidfile;
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };
@ -134,7 +140,7 @@ namespace llarp
std::string metricTankHost; std::string metricTankHost;
std::map< std::string, std::string > metricTags; std::map< std::string, std::string > metricTags;
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };
@ -143,7 +149,7 @@ namespace llarp
bool enableRPCServer = false; bool enableRPCServer = false;
std::string rpcBindAddr = "127.0.0.1:1190"; std::string rpcBindAddr = "127.0.0.1:1190";
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };
@ -156,14 +162,14 @@ namespace llarp
std::string lokidRPCUser; std::string lokidRPCUser;
std::string lokidRPCPassword; std::string lokidRPCPassword;
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };
struct BootstrapConfig struct BootstrapConfig
{ {
std::vector< std::string > routers; std::vector< std::string > routers;
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };
@ -172,7 +178,7 @@ namespace llarp
bool m_LogJSON = false; bool m_LogJSON = false;
FILE* m_LogFile = stdout; FILE* m_LogFile = stdout;
bool void
fromSection(string_view key, string_view val); fromSection(string_view key, string_view val);
}; };

@ -811,9 +811,9 @@ namespace llarp
netConfig = conf->network.netConfig; netConfig = conf->network.netConfig;
// Network config // 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(); routerProfiling().Enable();
LogInfo("router profiling explicitly enabled"); 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()); routerProfiling().Load(routerProfilesFile.c_str());
llarp::LogInfo("setting profiles to ", routerProfilesFile); 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()) if(IsServiceNode())
{ {
llarp::LogError("cannot use strict-connect option as service node"); llarp::LogError("cannot use strict-connect option as service node");

Loading…
Cancel
Save