mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-10-31 09:20:21 +00:00
12eb32a816
* add conf.d directory for config overrides * refactor llarp::Config * add explicit constructor with datadir as parameter * have all config files be passed as std::optional * make Config::LoadDefault private and use std::optional in Config::Load to remove ambiguity * update rest of codebase to reflect above changes * fix pybind * rename bootstrap config skipBootstrap to seednode as it's more descriptive * make seednode configurable * make pybind layer compile * make pybind layer run
64 lines
1.5 KiB
C++
64 lines
1.5 KiB
C++
#ifndef LOKINET_BOOTSERV_CONFIG_HPP
|
|
#define LOKINET_BOOTSERV_CONFIG_HPP
|
|
|
|
#include <string_view>
|
|
#include <string>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
#include <util/fs.hpp>
|
|
|
|
namespace llarp
|
|
{
|
|
struct ConfigParser
|
|
{
|
|
using SectionValues_t = std::unordered_multimap<std::string, std::string>;
|
|
using Config_impl_t = std::unordered_map<std::string, SectionValues_t>;
|
|
/// clear parser
|
|
void
|
|
Clear();
|
|
|
|
/// load config file for bootserv
|
|
/// return true on success
|
|
/// return false on error
|
|
bool
|
|
LoadFile(const fs::path fname);
|
|
|
|
/// load from string
|
|
/// return true on success
|
|
/// return false on error
|
|
bool
|
|
LoadFromStr(std::string_view str);
|
|
|
|
/// iterate all sections and thier values
|
|
void
|
|
IterAll(std::function<void(std::string_view, const SectionValues_t&)> visit);
|
|
|
|
/// visit a section in config read only by name
|
|
/// return false if no section or value propagated from visitor
|
|
bool
|
|
VisitSection(const char* name, std::function<bool(const SectionValues_t&)> visit) const;
|
|
|
|
/// add a config option that is appended in another file
|
|
void
|
|
AddOverride(fs::path file, std::string section, std::string key, std::string value);
|
|
|
|
/// save config overrides
|
|
void
|
|
Save();
|
|
|
|
private:
|
|
bool
|
|
Parse();
|
|
|
|
std::vector<char> m_Data;
|
|
Config_impl_t m_Config;
|
|
std::unordered_map<fs::path, Config_impl_t, util::FileHash> m_Overrides;
|
|
fs::path m_FileName;
|
|
};
|
|
|
|
} // namespace llarp
|
|
|
|
#endif
|