diff --git a/llarp/config/config.hpp b/llarp/config/config.hpp index 2c94e1e9f..c143f1fe8 100644 --- a/llarp/config/config.hpp +++ b/llarp/config/config.hpp @@ -5,6 +5,8 @@ #include #include +#include +#include #include #include #include @@ -14,6 +16,22 @@ namespace llarp { struct ConfigParser; + template < typename Type > + Type + fromEnv(const Type& val, string_view envNameSuffix) + { + std::string envName = absl::StrCat("LOKINET_", envNameSuffix); + auto ptr = std::getenv(envName.c_str()); + if(ptr) + { + return ptr; + } + else + { + return val; + } + } + class RouterConfig { private: @@ -67,16 +85,21 @@ namespace llarp class NetworkConfig { + public: + using NetConfig = std::unordered_multimap< std::string, std::string >; + private: absl::optional< bool > m_enableProfiling; std::string m_routerProfilesFile = "profiles.dat"; std::string m_strictConnect; + NetConfig m_netConfig; 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; } // clang-format on void diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index b04d90863..607d20f78 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -808,7 +808,7 @@ namespace llarp } // set network config - netConfig = conf->network.netConfig; + netConfig = conf->network.netConfig(); // Network config if(conf->network.enableProfiling().has_value()) diff --git a/test/config/test_llarp_config_config.cpp b/test/config/test_llarp_config_config.cpp index fed4dac0d..80b399bdb 100644 --- a/test/config/test_llarp_config_config.cpp +++ b/test/config/test_llarp_config_config.cpp @@ -92,9 +92,9 @@ metric-tank-host=52.80.56.123:2003 ASSERT_TRUE(config.LoadFromString(text)); { - using kv = decltype(config.network.netConfig)::value_type; + using kv = NetworkConfig::NetConfig::value_type; - ASSERT_THAT(config.network.netConfig, + ASSERT_THAT(config.network.netConfig(), UnorderedElementsAre(kv("ifname", "cluster-1"), kv("ifaddr", "10.101.0.1/16"))); }