mirror of https://github.com/oxen-io/lokinet
Allow override of the rest of the config
This commit is contained in:
parent
fbb83704a0
commit
3ce90b678e
|
@ -100,10 +100,10 @@ namespace llarp
|
|||
}
|
||||
if(key == "net-threads")
|
||||
{
|
||||
m_numNethreads = atoi(std::string(val).c_str());
|
||||
if(m_numNethreads <= 0)
|
||||
m_numNetThreads = atoi(std::string(val).c_str());
|
||||
if(m_numNetThreads <= 0)
|
||||
{
|
||||
m_numNethreads = 1;
|
||||
m_numNetThreads = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ namespace llarp
|
|||
m_enableProfiling.emplace(false);
|
||||
}
|
||||
}
|
||||
if(key == "profiles")
|
||||
else if(key == "profiles")
|
||||
{
|
||||
m_routerProfilesFile.assign(val.begin(), val.end());
|
||||
llarp::LogInfo("setting profiles to ", routerProfilesFile());
|
||||
|
@ -131,6 +131,10 @@ namespace llarp
|
|||
{
|
||||
m_strictConnect.assign(val.begin(), val.end());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_netConfig.emplace(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -138,7 +142,7 @@ namespace llarp
|
|||
{
|
||||
if(key == "dir")
|
||||
{
|
||||
nodedb_dir.assign(val.begin(), val.end());
|
||||
m_nodedbDir.assign(val.begin(), val.end());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,7 +205,7 @@ namespace llarp
|
|||
}
|
||||
else
|
||||
{
|
||||
servers.emplace_back(key, AF_INET, proto);
|
||||
m_servers.emplace_back(key, AF_INET, proto);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,11 +263,11 @@ namespace llarp
|
|||
{
|
||||
if(key == "enabled")
|
||||
{
|
||||
enableRPCServer = IsTrueValue(val);
|
||||
m_enableRPCServer = IsTrueValue(val);
|
||||
}
|
||||
if(key == "bind")
|
||||
{
|
||||
rpcBindAddr.assign(val.begin(), val.end());
|
||||
m_rpcBindAddr.assign(val.begin(), val.end());
|
||||
}
|
||||
if(key == "authkey")
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <crypto/types.hpp>
|
||||
#include <router_contact.hpp>
|
||||
#include <util/fs.hpp>
|
||||
#include <util/str.hpp>
|
||||
|
||||
#include <absl/strings/str_cat.h>
|
||||
#include <cstdlib>
|
||||
|
@ -21,7 +22,7 @@ namespace llarp
|
|||
fromEnv(const Type& val, string_view envNameSuffix)
|
||||
{
|
||||
std::string envName = absl::StrCat("LOKINET_", envNameSuffix);
|
||||
auto ptr = std::getenv(envName.c_str());
|
||||
char* ptr = std::getenv(envName.c_str());
|
||||
if(ptr)
|
||||
{
|
||||
return ptr;
|
||||
|
@ -32,6 +33,71 @@ namespace llarp
|
|||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
inline int
|
||||
fromEnv< int >(const int& val, string_view envNameSuffix)
|
||||
{
|
||||
std::string envName = absl::StrCat("LOKINET_", envNameSuffix);
|
||||
const char* ptr = std::getenv(envName.c_str());
|
||||
if(ptr)
|
||||
{
|
||||
return std::atoi(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
inline uint16_t
|
||||
fromEnv< uint16_t >(const uint16_t& val, string_view envNameSuffix)
|
||||
{
|
||||
std::string envName = absl::StrCat("LOKINET_", envNameSuffix);
|
||||
const char* ptr = std::getenv(envName.c_str());
|
||||
if(ptr)
|
||||
{
|
||||
return std::atoi(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
inline size_t
|
||||
fromEnv< size_t >(const size_t& val, string_view envNameSuffix)
|
||||
{
|
||||
std::string envName = absl::StrCat("LOKINET_", envNameSuffix);
|
||||
const char* ptr = std::getenv(envName.c_str());
|
||||
if(ptr)
|
||||
{
|
||||
return std::atoll(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
inline absl::optional< bool >
|
||||
fromEnv< absl::optional< bool > >(const absl::optional< bool >& val,
|
||||
string_view envNameSuffix)
|
||||
{
|
||||
std::string envName = absl::StrCat("LOKINET_", envNameSuffix);
|
||||
const char* ptr = std::getenv(envName.c_str());
|
||||
if(ptr)
|
||||
{
|
||||
return IsTrueValue(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
class RouterConfig
|
||||
{
|
||||
private:
|
||||
|
@ -60,23 +126,23 @@ namespace llarp
|
|||
AddressInfo m_addrInfo;
|
||||
|
||||
int m_workerThreads;
|
||||
int m_numNethreads;
|
||||
int m_numNetThreads;
|
||||
|
||||
public:
|
||||
// clang-format off
|
||||
size_t minConnectedRouters() const { return m_minConnectedRouters; }
|
||||
size_t maxConnectedRouters() const { return m_maxConnectedRouters; }
|
||||
const fs::path& encryptionKeyfile() const { return m_encryptionKeyfile; }
|
||||
const fs::path& ourRcFile() const { return m_ourRcFile; }
|
||||
const fs::path& transportKeyfile() const { return m_transportKeyfile; }
|
||||
const fs::path& identKeyfile() const { return m_identKeyfile; }
|
||||
const std::string& netId() const { return m_netId; }
|
||||
const std::string& nickname() const { return m_nickname; }
|
||||
bool publicOverride() const { return m_publicOverride; }
|
||||
size_t minConnectedRouters() const { return fromEnv(m_minConnectedRouters, "MIN_CONNECTED_ROUTERS"); }
|
||||
size_t maxConnectedRouters() const { return fromEnv(m_maxConnectedRouters, "MAX_CONNECTED_ROUTERS"); }
|
||||
fs::path encryptionKeyfile() const { return fromEnv(m_encryptionKeyfile, "ENCRYPTION_KEYFILE"); }
|
||||
fs::path ourRcFile() const { return fromEnv(m_ourRcFile, "OUR_RC_FILE"); }
|
||||
fs::path transportKeyfile() const { return fromEnv(m_transportKeyfile, "TRANSPORT_KEYFILE"); }
|
||||
fs::path identKeyfile() const { return fromEnv(m_identKeyfile, "IDENT_KEYFILE"); }
|
||||
std::string netId() const { return fromEnv(m_netId, "NETID"); }
|
||||
std::string nickname() const { return fromEnv(m_nickname, "NICKNAME"); }
|
||||
bool publicOverride() const { return fromEnv(m_publicOverride, "PUBLIC_OVERRIDE"); }
|
||||
const struct sockaddr_in& ip4addr() const { return m_ip4addr; }
|
||||
const AddressInfo& addrInfo() const { return m_addrInfo; }
|
||||
int workerThreads() const { return m_workerThreads; }
|
||||
int numNethreads() const { return m_numNethreads; }
|
||||
int workerThreads() const { return fromEnv(m_workerThreads, "WORKER_THREADS"); }
|
||||
int numNetThreads() const { return fromEnv(m_numNetThreads, "NUM_NET_THREADS"); }
|
||||
// clang-format on
|
||||
|
||||
void
|
||||
|
@ -96,19 +162,25 @@ namespace llarp
|
|||
|
||||
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; }
|
||||
const NetConfig& netConfig() const { return m_netConfig; }
|
||||
absl::optional< bool > enableProfiling() const { return fromEnv(m_enableProfiling, "ENABLE_PROFILING"); }
|
||||
std::string routerProfilesFile() const { return fromEnv(m_routerProfilesFile, "ROUTER_PROFILES_FILE"); }
|
||||
std::string strictConnect() const { return fromEnv(m_strictConnect, "STRICT_CONNECT"); }
|
||||
const NetConfig& netConfig() const { return m_netConfig; }
|
||||
// clang-format on
|
||||
|
||||
void
|
||||
fromSection(string_view key, string_view val);
|
||||
};
|
||||
|
||||
struct NetdbConfig
|
||||
class NetdbConfig
|
||||
{
|
||||
std::string nodedb_dir;
|
||||
private:
|
||||
std::string m_nodedbDir;
|
||||
|
||||
public:
|
||||
// clang-format off
|
||||
std::string nodedbDir() const { return fromEnv(m_nodedbDir, "NODEDB_DIR"); }
|
||||
// clang-format on
|
||||
|
||||
void
|
||||
fromSection(string_view key, string_view val);
|
||||
|
@ -122,11 +194,21 @@ namespace llarp
|
|||
fromSection(string_view key, string_view val);
|
||||
};
|
||||
|
||||
struct IwpConfig
|
||||
class IwpConfig
|
||||
{
|
||||
public:
|
||||
using Servers = std::vector< std::tuple< std::string, int, uint16_t > >;
|
||||
|
||||
private:
|
||||
uint16_t m_OutboundPort = 0;
|
||||
|
||||
std::vector< std::tuple< std::string, int, uint16_t > > servers;
|
||||
Servers m_servers;
|
||||
|
||||
public:
|
||||
// clang-format off
|
||||
uint16_t outboundPort() const { return fromEnv(m_OutboundPort, "OUTBOUND_PORT"); }
|
||||
const Servers& servers() const { return m_servers; }
|
||||
// clang-format on
|
||||
|
||||
void
|
||||
fromSection(string_view key, string_view val);
|
||||
|
@ -167,10 +249,17 @@ namespace llarp
|
|||
fromSection(string_view key, string_view val);
|
||||
};
|
||||
|
||||
struct ApiConfig
|
||||
class ApiConfig
|
||||
{
|
||||
bool enableRPCServer = false;
|
||||
std::string rpcBindAddr = "127.0.0.1:1190";
|
||||
private:
|
||||
bool m_enableRPCServer = false;
|
||||
std::string m_rpcBindAddr = "127.0.0.1:1190";
|
||||
|
||||
public:
|
||||
// clang-format off
|
||||
bool enableRPCServer() const { return fromEnv(m_enableRPCServer, "ENABLE_RPC_SERVER"); }
|
||||
std::string rpcBindAddr() const { return fromEnv(m_rpcBindAddr, "RPC_BIND_ADDR"); }
|
||||
// clang-format on
|
||||
|
||||
void
|
||||
fromSection(string_view key, string_view val);
|
||||
|
|
|
@ -72,10 +72,10 @@ namespace llarp
|
|||
}
|
||||
else
|
||||
{
|
||||
num_nethreads = config->router.numNethreads();
|
||||
num_nethreads = config->router.numNetThreads();
|
||||
}
|
||||
|
||||
nodedb_dir = config->netdb.nodedb_dir;
|
||||
nodedb_dir = config->netdb.nodedbDir();
|
||||
|
||||
if(!config->metrics.disableMetrics)
|
||||
{
|
||||
|
|
|
@ -785,9 +785,9 @@ namespace llarp
|
|||
}
|
||||
|
||||
// IWP config
|
||||
m_OutboundPort = conf->iwp_links.m_OutboundPort;
|
||||
m_OutboundPort = conf->iwp_links.outboundPort();
|
||||
|
||||
for(const auto &serverConfig : conf->iwp_links.servers)
|
||||
for(const auto &serverConfig : conf->iwp_links.servers())
|
||||
{
|
||||
auto server = llarp::utp::NewServerFromRouter(this);
|
||||
if(!server->EnsureKeys(transport_keyfile.string().c_str()))
|
||||
|
@ -864,8 +864,8 @@ namespace llarp
|
|||
}
|
||||
|
||||
// API config
|
||||
enableRPCServer = conf->api.enableRPCServer;
|
||||
rpcBindAddr = conf->api.rpcBindAddr;
|
||||
enableRPCServer = conf->api.enableRPCServer();
|
||||
rpcBindAddr = conf->api.rpcBindAddr();
|
||||
|
||||
// Services config
|
||||
for(const auto &service : conf->services.services)
|
||||
|
|
|
@ -102,9 +102,9 @@ metric-tank-host=52.80.56.123:2003
|
|||
ASSERT_FALSE(config.metrics.disableMetrics);
|
||||
|
||||
{
|
||||
using kv = decltype(config.iwp_links.servers)::value_type;
|
||||
using kv = IwpConfig::Servers::value_type;
|
||||
|
||||
ASSERT_THAT(config.iwp_links.servers,
|
||||
ASSERT_THAT(config.iwp_links.servers(),
|
||||
UnorderedElementsAre(kv("eth0", AF_INET, 5501)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue