2019-07-02 21:28:28 +00:00
|
|
|
#ifndef LLARP_CONFIG_HPP
|
|
|
|
#define LLARP_CONFIG_HPP
|
|
|
|
|
2020-04-20 20:36:42 +00:00
|
|
|
#include <chrono>
|
2019-07-02 21:28:28 +00:00
|
|
|
#include <crypto/types.hpp>
|
|
|
|
#include <router_contact.hpp>
|
|
|
|
#include <util/fs.hpp>
|
2019-07-08 23:29:37 +00:00
|
|
|
#include <util/str.hpp>
|
2020-03-13 20:45:33 +00:00
|
|
|
#include <config/ini.hpp>
|
2020-03-18 18:24:23 +00:00
|
|
|
#include <config/definition.hpp>
|
2020-04-02 15:48:20 +00:00
|
|
|
#include <constants/files.hpp>
|
2020-05-06 20:38:44 +00:00
|
|
|
#include <net/ip_address.hpp>
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-07-02 00:58:23 +00:00
|
|
|
#include <cstdlib>
|
2019-07-02 21:28:28 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2019-08-26 11:16:46 +00:00
|
|
|
#include <unordered_set>
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-04-07 23:50:50 +00:00
|
|
|
struct llarp_config;
|
|
|
|
|
2019-07-02 21:28:28 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
2020-03-13 20:45:33 +00:00
|
|
|
using SectionValues_t = llarp::ConfigParser::SectionValues_t;
|
|
|
|
using Config_impl_t = llarp::ConfigParser::Config_impl_t;
|
2019-07-06 13:46:21 +00:00
|
|
|
|
2020-03-31 15:25:29 +00:00
|
|
|
// TODO: don't use these maps. they're sloppy and difficult to follow
|
2020-03-27 21:39:40 +00:00
|
|
|
/// Small struct to gather all parameters needed for config generation to reduce the number of
|
|
|
|
/// parameters that need to be passed around.
|
|
|
|
struct ConfigGenParameters
|
|
|
|
{
|
|
|
|
bool isRelay = false;
|
|
|
|
fs::path defaultDataDir;
|
|
|
|
};
|
|
|
|
|
2020-03-27 21:53:43 +00:00
|
|
|
struct RouterConfig
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-31 15:51:24 +00:00
|
|
|
size_t m_minConnectedRouters;
|
|
|
|
size_t m_maxConnectedRouters;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-31 15:51:24 +00:00
|
|
|
std::string m_netId;
|
2019-07-01 23:55:02 +00:00
|
|
|
std::string m_nickname;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-04-02 15:12:45 +00:00
|
|
|
fs::path m_dataDir;
|
2019-07-01 23:55:02 +00:00
|
|
|
|
2020-03-31 16:04:47 +00:00
|
|
|
bool m_blockBogons;
|
2019-08-26 23:29:17 +00:00
|
|
|
|
2020-05-06 20:38:44 +00:00
|
|
|
IpAddress m_publicAddress;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-31 15:51:24 +00:00
|
|
|
int m_workerThreads;
|
|
|
|
int m_numNetThreads;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-31 15:51:24 +00:00
|
|
|
size_t m_JobQueueSize;
|
2019-11-25 21:30:34 +00:00
|
|
|
|
2020-04-29 19:41:39 +00:00
|
|
|
std::string m_routerContactFile;
|
|
|
|
std::string m_encryptionKeyFile;
|
|
|
|
std::string m_identityKeyFile;
|
|
|
|
std::string m_transportKeyFile;
|
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 21:53:43 +00:00
|
|
|
struct NetworkConfig
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-05-01 19:51:15 +00:00
|
|
|
std::optional<bool> m_enableProfiling;
|
2020-04-02 15:12:45 +00:00
|
|
|
std::string m_routerProfilesFile;
|
2019-07-02 00:20:58 +00:00
|
|
|
std::string m_strictConnect;
|
2020-04-27 15:24:05 +00:00
|
|
|
std::string m_ifname;
|
|
|
|
std::string m_ifaddr;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-04-30 22:11:05 +00:00
|
|
|
std::string m_keyfile;
|
|
|
|
std::string m_endpointType;
|
|
|
|
bool m_reachable;
|
|
|
|
int m_hops;
|
|
|
|
int m_paths;
|
|
|
|
std::set<RouterID> m_snodeBlacklist;
|
|
|
|
#ifdef LOKINET_EXITS
|
|
|
|
std::string m_exitNode;
|
|
|
|
#endif
|
|
|
|
std::string m_mapAddr;
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// on-up
|
|
|
|
// on-down
|
|
|
|
// on-ready
|
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DnsConfig
|
|
|
|
{
|
2020-05-06 20:38:44 +00:00
|
|
|
IpAddress m_bind;
|
|
|
|
std::vector<IpAddress> m_upstreamDNS;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 21:53:43 +00:00
|
|
|
struct LinksConfig
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-19 22:20:45 +00:00
|
|
|
struct LinkInfo
|
|
|
|
{
|
|
|
|
std::string interface;
|
|
|
|
int addressFamily;
|
2020-03-23 16:15:00 +00:00
|
|
|
uint16_t port = -1;
|
2020-03-19 22:20:45 +00:00
|
|
|
};
|
2020-03-23 16:15:00 +00:00
|
|
|
/// Create a LinkInfo from the given string.
|
|
|
|
/// @throws if str does not represent a LinkInfo.
|
|
|
|
LinkInfo
|
2020-05-01 19:51:15 +00:00
|
|
|
LinkInfoFromINIValues(std::string_view name, std::string_view value);
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-08-07 16:33:29 +00:00
|
|
|
LinkInfo m_OutboundLink;
|
2020-03-19 22:20:45 +00:00
|
|
|
std::vector<LinkInfo> m_InboundLinks;
|
2019-07-08 23:29:37 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ConnectConfig
|
|
|
|
{
|
2020-04-02 15:12:45 +00:00
|
|
|
std::vector<fs::path> routers;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 21:53:43 +00:00
|
|
|
struct ApiConfig
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-31 15:51:24 +00:00
|
|
|
bool m_enableRPCServer;
|
|
|
|
std::string m_rpcBindAddr;
|
2019-07-08 23:29:37 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct LokidConfig
|
|
|
|
{
|
2020-03-31 15:51:24 +00:00
|
|
|
bool usingSNSeed;
|
|
|
|
bool whitelistRouters;
|
2020-04-02 15:48:20 +00:00
|
|
|
fs::path ident_keyfile;
|
2020-03-31 15:51:24 +00:00
|
|
|
std::string lokidRPCAddr;
|
2019-07-02 21:28:28 +00:00
|
|
|
std::string lokidRPCUser;
|
|
|
|
std::string lokidRPCPassword;
|
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BootstrapConfig
|
|
|
|
{
|
2020-04-07 20:41:11 +00:00
|
|
|
std::vector<std::string> routers;
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct LoggingConfig
|
|
|
|
{
|
2020-03-19 21:51:22 +00:00
|
|
|
LogType m_logType;
|
|
|
|
LogLevel m_logLevel;
|
|
|
|
std::string m_logFile;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-30 16:25:02 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2020-03-30 16:25:02 +00:00
|
|
|
};
|
|
|
|
|
2019-07-02 21:28:28 +00:00
|
|
|
struct Config
|
|
|
|
{
|
|
|
|
RouterConfig router;
|
|
|
|
NetworkConfig network;
|
|
|
|
ConnectConfig connect;
|
|
|
|
DnsConfig dns;
|
2019-08-07 16:33:29 +00:00
|
|
|
LinksConfig links;
|
2019-07-02 21:28:28 +00:00
|
|
|
ApiConfig api;
|
|
|
|
LokidConfig lokid;
|
|
|
|
BootstrapConfig bootstrap;
|
|
|
|
LoggingConfig logging;
|
|
|
|
|
2020-03-23 20:53:42 +00:00
|
|
|
// Initialize config definition
|
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
initializeConfig(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2020-03-23 20:53:42 +00:00
|
|
|
|
2020-04-29 16:47:51 +00:00
|
|
|
/// Insert config entries for backwards-compatibility (e.g. so that the config system will
|
|
|
|
/// tolerate old values that are no longer accepted)
|
|
|
|
///
|
|
|
|
/// @param conf is the config to modify
|
|
|
|
void
|
|
|
|
addBackwardsCompatibleConfigOptions(ConfigDefinition& conf);
|
|
|
|
|
2020-03-23 20:53:42 +00:00
|
|
|
// Load a config from the given file
|
2019-07-02 21:28:28 +00:00
|
|
|
bool
|
2020-03-27 21:39:40 +00:00
|
|
|
Load(const char* fname, bool isRelay, fs::path defaultDataDir);
|
2019-07-06 13:46:21 +00:00
|
|
|
|
2020-04-24 17:10:05 +00:00
|
|
|
/// Load (initialize) a default config.
|
|
|
|
///
|
|
|
|
/// This delegates to the ConfigDefinition to generate a default config,
|
|
|
|
/// as though an empty config were specified.
|
|
|
|
///
|
|
|
|
/// If using Config without the intention of loading from file (or string), this is necessary
|
|
|
|
/// in order to obtain sane defaults.
|
|
|
|
///
|
|
|
|
/// @param isRelay determines whether the config will reflect that of a relay or client
|
|
|
|
/// @param dataDir is a path representing a directory to be used as the data dir
|
|
|
|
/// @return true on success, false otherwise
|
|
|
|
bool
|
|
|
|
LoadDefault(bool isRelay, fs::path dataDir);
|
|
|
|
|
2020-03-23 20:53:42 +00:00
|
|
|
std::string
|
2020-03-27 21:39:40 +00:00
|
|
|
generateBaseClientConfig(fs::path defaultDataDir);
|
2020-03-23 20:53:42 +00:00
|
|
|
|
|
|
|
std::string
|
2020-03-27 21:39:40 +00:00
|
|
|
generateBaseRouterConfig(fs::path defaultDataDir);
|
2020-04-07 23:50:50 +00:00
|
|
|
|
|
|
|
llarp_config*
|
|
|
|
Copy() const;
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
2020-03-23 20:53:42 +00:00
|
|
|
void
|
2020-04-07 20:41:11 +00:00
|
|
|
ensureConfig(
|
|
|
|
const fs::path& defaultDataDir, const fs::path& confFile, bool overwrite, bool asRouter);
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-23 20:53:42 +00:00
|
|
|
} // namespace llarp
|
2019-07-02 21:28:28 +00:00
|
|
|
|
|
|
|
#endif
|