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
{
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 &section) -> bool {
for(const auto &sec : section)
{
if(!ret.fromSection(sec.first, sec.second))
{
return false;
}
ret.fromSection(sec.first, sec.second);
}
return true;
};

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

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

Loading…
Cancel
Save