2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-04-20 20:36:42 +00:00
|
|
|
#include <chrono>
|
2021-09-20 21:55:07 +00:00
|
|
|
#include <llarp/bootstrap.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/crypto/types.hpp>
|
|
|
|
#include <llarp/router_contact.hpp>
|
|
|
|
#include <llarp/util/fs.hpp>
|
|
|
|
#include <llarp/util/str.hpp>
|
2022-07-16 00:41:14 +00:00
|
|
|
#include <llarp/util/logging.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include "ini.hpp"
|
|
|
|
#include "definition.hpp"
|
|
|
|
#include <llarp/constants/files.hpp>
|
|
|
|
#include <llarp/net/ip_address.hpp>
|
|
|
|
#include <llarp/net/net_int.hpp>
|
|
|
|
#include <llarp/net/ip_range_map.hpp>
|
|
|
|
#include <llarp/service/address.hpp>
|
|
|
|
#include <llarp/service/auth.hpp>
|
|
|
|
#include <llarp/dns/srv_data.hpp>
|
|
|
|
|
|
|
|
#include <llarp/router_contact.hpp>
|
2021-02-18 13:28:53 +00:00
|
|
|
|
2019-07-02 00:58:23 +00:00
|
|
|
#include <cstdlib>
|
2019-07-02 21:28:28 +00:00
|
|
|
#include <functional>
|
2021-03-18 15:59:02 +00:00
|
|
|
#include <optional>
|
2019-07-02 21:28:28 +00:00
|
|
|
#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
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
#include <oxenmq/address.h>
|
2020-06-30 16:38:08 +00:00
|
|
|
|
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
|
|
|
|
{
|
2022-07-09 15:05:52 +00:00
|
|
|
ConfigGenParameters() = default;
|
|
|
|
virtual ~ConfigGenParameters() = default;
|
|
|
|
|
|
|
|
ConfigGenParameters(const ConfigGenParameters&) = delete;
|
|
|
|
ConfigGenParameters(ConfigGenParameters&&) = delete;
|
|
|
|
|
2020-03-27 21:39:40 +00:00
|
|
|
bool isRelay = false;
|
|
|
|
fs::path defaultDataDir;
|
2022-07-09 15:05:52 +00:00
|
|
|
|
|
|
|
/// get network platform (virtual for unit test mocks)
|
|
|
|
virtual const llarp::net::Platform*
|
|
|
|
Net_ptr() const = 0;
|
2020-03-27 21:39:40 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 21:53:43 +00:00
|
|
|
struct RouterConfig
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-05-20 21:15:06 +00:00
|
|
|
size_t m_minConnectedRouters = 0;
|
|
|
|
size_t m_maxConnectedRouters = 0;
|
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-05-20 21:15:06 +00:00
|
|
|
bool m_blockBogons = false;
|
2019-08-26 23:29:17 +00:00
|
|
|
|
2020-05-20 21:15:06 +00:00
|
|
|
int m_workerThreads = -1;
|
|
|
|
int m_numNetThreads = -1;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-05-20 21:15:06 +00:00
|
|
|
size_t m_JobQueueSize = 0;
|
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-08-14 15:36:08 +00:00
|
|
|
bool m_isRelay = false;
|
2022-07-09 15:05:52 +00:00
|
|
|
/// deprecated
|
|
|
|
std::optional<net::ipaddr_t> PublicIP;
|
|
|
|
/// deprecated
|
|
|
|
std::optional<net::port_t> PublicPort;
|
2020-05-26 17:03:21 +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
|
|
|
};
|
|
|
|
|
2021-02-18 13:28:53 +00:00
|
|
|
/// config for path hop selection
|
|
|
|
struct PeerSelectionConfig
|
|
|
|
{
|
|
|
|
/// in our hops what netmask will we use for unique ips for hops
|
|
|
|
/// i.e. 32 for every hop unique ip, 24 unique /24 per hop, etc
|
|
|
|
///
|
2021-02-19 22:19:21 +00:00
|
|
|
int m_UniqueHopsNetmaskSize;
|
2021-02-18 13:28:53 +00:00
|
|
|
|
|
|
|
/// set of countrys to exclude from path building (2 char country code)
|
|
|
|
std::unordered_set<std::string> m_ExcludeCountries;
|
|
|
|
|
|
|
|
void
|
|
|
|
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
|
|
|
|
|
|
|
|
/// return true if this set of router contacts is acceptable against this config
|
|
|
|
bool
|
2021-02-18 17:20:58 +00:00
|
|
|
Acceptable(const std::set<RouterContact>& hops) const;
|
2021-02-18 13:28:53 +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;
|
2021-04-02 16:08:06 +00:00
|
|
|
bool m_saveProfiles;
|
2021-04-12 11:39:07 +00:00
|
|
|
std::set<RouterID> m_strictConnect;
|
2020-04-27 15:24:05 +00:00
|
|
|
std::string m_ifname;
|
2020-06-24 13:24:07 +00:00
|
|
|
IPRange m_ifaddr;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-06-08 12:42:10 +00:00
|
|
|
std::optional<fs::path> m_keyfile;
|
2020-04-30 22:11:05 +00:00
|
|
|
std::string m_endpointType;
|
2020-05-20 21:15:06 +00:00
|
|
|
bool m_reachable = false;
|
2020-06-08 12:42:10 +00:00
|
|
|
std::optional<int> m_Hops;
|
|
|
|
std::optional<int> m_Paths;
|
2020-05-21 14:18:23 +00:00
|
|
|
bool m_AllowExit = false;
|
2020-04-30 22:11:05 +00:00
|
|
|
std::set<RouterID> m_snodeBlacklist;
|
2020-06-24 13:24:07 +00:00
|
|
|
net::IPRangeMap<service::Address> m_ExitMap;
|
2020-10-21 09:39:01 +00:00
|
|
|
net::IPRangeMap<std::string> m_LNSExitMap;
|
|
|
|
|
2021-03-09 18:39:40 +00:00
|
|
|
std::unordered_map<service::Address, service::AuthInfo> m_ExitAuths;
|
2020-10-21 09:39:01 +00:00
|
|
|
std::unordered_map<std::string, service::AuthInfo> m_LNSExitAuths;
|
|
|
|
|
2020-05-21 14:18:23 +00:00
|
|
|
std::unordered_map<huint128_t, service::Address> m_mapAddrs;
|
2020-04-30 22:11:05 +00:00
|
|
|
|
2020-06-30 16:02:29 +00:00
|
|
|
service::AuthType m_AuthType = service::AuthType::eAuthTypeNone;
|
2022-04-01 16:52:25 +00:00
|
|
|
service::AuthFileType m_AuthFileType = service::AuthFileType::eAuthFileHashes;
|
2020-06-02 21:10:42 +00:00
|
|
|
std::optional<std::string> m_AuthUrl;
|
|
|
|
std::optional<std::string> m_AuthMethod;
|
2021-03-09 18:39:40 +00:00
|
|
|
std::unordered_set<service::Address> m_AuthWhitelist;
|
2021-12-26 21:48:27 +00:00
|
|
|
std::unordered_set<std::string> m_AuthStaticTokens;
|
2022-01-17 12:57:08 +00:00
|
|
|
std::set<fs::path> m_AuthFiles;
|
2020-06-02 21:10:42 +00:00
|
|
|
|
2020-08-31 20:07:17 +00:00
|
|
|
std::vector<llarp::dns::SRVData> m_SRVRecords;
|
|
|
|
|
2021-03-18 15:59:02 +00:00
|
|
|
std::optional<huint128_t> m_baseV6Address;
|
|
|
|
|
2021-04-14 19:40:57 +00:00
|
|
|
std::set<IPRange> m_OwnedRanges;
|
2021-04-14 15:07:06 +00:00
|
|
|
std::optional<net::TrafficPolicy> m_TrafficPolicy;
|
|
|
|
|
2021-05-01 20:25:32 +00:00
|
|
|
std::optional<llarp_time_t> m_PathAlignmentTimeout;
|
|
|
|
|
2021-06-17 16:05:50 +00:00
|
|
|
std::optional<fs::path> m_AddrMapPersistFile;
|
2020-04-30 22:11:05 +00:00
|
|
|
|
2021-12-04 15:08:18 +00:00
|
|
|
bool m_EnableRoutePoker;
|
2022-01-14 18:03:01 +00:00
|
|
|
bool m_BlackholeRoutes;
|
2021-12-04 15:08:18 +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 DnsConfig
|
|
|
|
{
|
2022-07-28 16:07:38 +00:00
|
|
|
bool m_raw_dns;
|
2022-04-07 20:44:23 +00:00
|
|
|
std::vector<SockAddr> m_bind;
|
2021-05-30 17:29:00 +00:00
|
|
|
std::vector<SockAddr> m_upstreamDNS;
|
2021-06-09 10:38:11 +00:00
|
|
|
std::vector<fs::path> m_hostfiles;
|
2022-07-28 16:07:38 +00:00
|
|
|
std::optional<SockAddr> m_QueryBind;
|
|
|
|
|
2022-04-07 20:44:23 +00:00
|
|
|
std::unordered_multimap<std::string, std::string> m_ExtraOpts;
|
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
|
|
|
{
|
2022-07-09 15:05:52 +00:00
|
|
|
std::optional<net::ipaddr_t> PublicAddress;
|
|
|
|
std::optional<net::port_t> PublicPort;
|
|
|
|
std::vector<SockAddr> OutboundLinks;
|
|
|
|
std::vector<SockAddr> InboundListenAddrs;
|
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-05-20 21:15:06 +00:00
|
|
|
bool m_enableRPCServer = false;
|
2020-03-31 15:51:24 +00:00
|
|
|
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-05-20 21:15:06 +00:00
|
|
|
bool whitelistRouters = false;
|
2020-04-02 15:48:20 +00:00
|
|
|
fs::path ident_keyfile;
|
2021-02-02 14:35:40 +00:00
|
|
|
oxenmq::address lokidRPCAddr;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
struct BootstrapConfig
|
|
|
|
{
|
2021-04-02 15:10:37 +00:00
|
|
|
std::vector<fs::path> files;
|
2021-09-20 21:55:07 +00:00
|
|
|
BootstrapList routers;
|
2020-10-21 12:58:08 +00:00
|
|
|
bool seednode;
|
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
|
|
|
|
{
|
2022-07-19 16:19:35 +00:00
|
|
|
log::Type m_logType = log::Type::Print;
|
2022-07-16 00:41:14 +00:00
|
|
|
log::Level m_logLevel = log::Level::off;
|
2020-03-19 21:51:22 +00:00
|
|
|
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
|
|
|
|
{
|
2022-07-09 15:05:52 +00:00
|
|
|
explicit Config(std::optional<fs::path> datadir = std::nullopt);
|
2020-10-21 12:58:08 +00:00
|
|
|
|
2022-07-09 15:05:52 +00:00
|
|
|
virtual ~Config() = default;
|
|
|
|
|
|
|
|
/// create generation params (virtual for unit test mock)
|
|
|
|
virtual std::unique_ptr<ConfigGenParameters>
|
|
|
|
MakeGenParams() const;
|
2020-10-21 12:58:08 +00:00
|
|
|
|
2019-07-02 21:28:28 +00:00
|
|
|
RouterConfig router;
|
|
|
|
NetworkConfig network;
|
2021-02-18 13:28:53 +00:00
|
|
|
PeerSelectionConfig paths;
|
2019-07-02 21:28:28 +00:00
|
|
|
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-10-21 12:58:08 +00:00
|
|
|
// Load a config from the given file if the config file is not provided LoadDefault is called
|
2019-07-02 21:28:28 +00:00
|
|
|
bool
|
2020-10-21 12:58:08 +00:00
|
|
|
Load(std::optional<fs::path> fname = std::nullopt, bool isRelay = false);
|
|
|
|
|
2022-07-09 15:05:52 +00:00
|
|
|
// Load a config from a string of ini, same effects as Config::Load
|
|
|
|
bool
|
|
|
|
LoadString(std::string_view ini, bool isRelay = false);
|
|
|
|
|
2020-10-21 12:58:08 +00:00
|
|
|
std::string
|
|
|
|
generateBaseClientConfig();
|
|
|
|
|
|
|
|
std::string
|
|
|
|
generateBaseRouterConfig();
|
|
|
|
|
|
|
|
void
|
|
|
|
Save();
|
|
|
|
|
|
|
|
void
|
|
|
|
Override(std::string section, std::string key, std::string value);
|
2019-07-06 13:46:21 +00:00
|
|
|
|
2021-03-02 18:18:22 +00:00
|
|
|
void
|
|
|
|
AddDefault(std::string section, std::string key, std::string value);
|
|
|
|
|
2021-04-01 11:13:39 +00:00
|
|
|
/// create a config with the default parameters for an embedded lokinet
|
|
|
|
static std::shared_ptr<Config>
|
|
|
|
EmbeddedConfig();
|
|
|
|
|
2020-10-21 12:58:08 +00:00
|
|
|
private:
|
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
|
2020-10-21 12:58:08 +00:00
|
|
|
LoadDefault(bool isRelay);
|
2020-08-27 12:43:53 +00:00
|
|
|
|
2022-06-27 17:14:03 +00:00
|
|
|
bool
|
|
|
|
LoadConfigData(
|
|
|
|
std::string_view ini, std::optional<fs::path> fname = std::nullopt, bool isRelay = false);
|
|
|
|
|
2020-08-27 12:43:53 +00:00
|
|
|
void
|
2022-06-27 17:14:03 +00:00
|
|
|
LoadOverrides(ConfigDefinition& conf) const;
|
2020-08-27 12:43:53 +00:00
|
|
|
|
2021-03-02 18:18:22 +00:00
|
|
|
std::vector<std::array<std::string, 3>> m_Additional;
|
2020-08-27 12:43:53 +00:00
|
|
|
ConfigParser m_Parser;
|
2020-10-21 12:58:08 +00:00
|
|
|
const fs::path m_DataDir;
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
2020-03-23 20:53:42 +00:00
|
|
|
void
|
2020-10-30 13:38:17 +00:00
|
|
|
ensureConfig(fs::path dataDir, 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
|