2021-03-09 22:24:35 +00:00
|
|
|
#pragma once
|
2023-10-24 13:18:03 +00:00
|
|
|
#include "definition.hpp"
|
|
|
|
#include "ini.hpp"
|
|
|
|
|
2021-09-20 21:55:07 +00:00
|
|
|
#include <llarp/bootstrap.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/constants/files.hpp>
|
2023-10-24 13:18:03 +00:00
|
|
|
#include <llarp/crypto/types.hpp>
|
|
|
|
#include <llarp/dns/srv_data.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/net/ip_address.hpp>
|
|
|
|
#include <llarp/net/ip_range_map.hpp>
|
2023-10-24 13:18:03 +00:00
|
|
|
#include <llarp/net/net.hpp>
|
|
|
|
#include <llarp/net/net_int.hpp>
|
|
|
|
#include <llarp/net/traffic_policy.hpp>
|
|
|
|
#include <llarp/router_contact.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/service/address.hpp>
|
|
|
|
#include <llarp/service/auth.hpp>
|
2023-10-24 13:18:03 +00:00
|
|
|
#include <llarp/util/fs.hpp>
|
|
|
|
#include <llarp/util/logging.hpp>
|
|
|
|
#include <llarp/util/str.hpp>
|
|
|
|
|
2023-10-19 21:59:57 +00:00
|
|
|
#include <oxenmq/address.h>
|
2023-10-24 13:18:03 +00:00
|
|
|
|
2023-10-19 21:59:57 +00:00
|
|
|
#include <chrono>
|
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>
|
2023-10-24 13:18:03 +00:00
|
|
|
#include <unordered_set>
|
2019-07-02 21:28:28 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2020-06-30 16:38:08 +00:00
|
|
|
|
2019-07-02 21:28:28 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
2023-11-03 13:40:14 +00:00
|
|
|
using SectionValues = llarp::ConfigParser::SectionValues;
|
|
|
|
using ConfigMap = llarp::ConfigParser::ConfigMap;
|
2019-07-06 13:46:21 +00:00
|
|
|
|
2023-11-03 22:11:35 +00:00
|
|
|
inline static constexpr uint16_t DEFAULT_LISTEN_PORT{1090};
|
|
|
|
|
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;
|
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
bool is_relay = false;
|
|
|
|
fs::path default_data_dir;
|
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
|
|
|
{
|
2023-11-03 13:40:14 +00:00
|
|
|
size_t min_connected_routers = 0;
|
|
|
|
size_t max_connected_routers = 0;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::string net_id;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
fs::path data_dir;
|
2019-07-01 23:55:02 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
bool block_bogons = false;
|
2019-08-26 23:29:17 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
int worker_threads = -1;
|
|
|
|
int net_threads = -1;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
size_t job_que_size = 0;
|
2019-11-25 21:30:34 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::string rc_file;
|
|
|
|
std::string enckey_file;
|
|
|
|
std::string idkey_file;
|
|
|
|
std::string transkey_file;
|
2020-04-29 19:41:39 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
bool is_relay = false;
|
2022-07-09 15:05:52 +00:00
|
|
|
/// deprecated
|
2023-11-03 13:40:14 +00:00
|
|
|
std::optional<net::ipaddr_t> public_ip;
|
2022-07-09 15:05:52 +00:00
|
|
|
/// deprecated
|
2023-11-03 13:40:14 +00:00
|
|
|
std::optional<net::port_t> public_port;
|
2020-05-26 17:03:21 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
define_config_options(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
|
|
|
|
///
|
2023-11-03 13:40:14 +00:00
|
|
|
int unique_hop_netmask;
|
2021-02-18 13:28:53 +00:00
|
|
|
|
|
|
|
/// set of countrys to exclude from path building (2 char country code)
|
2023-11-03 13:40:14 +00:00
|
|
|
std::unordered_set<std::string> exclude_countries;
|
2021-02-18 13:28:53 +00:00
|
|
|
|
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
define_config_options(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2021-02-18 13:28:53 +00:00
|
|
|
|
|
|
|
/// return true if this set of router contacts is acceptable against this config
|
|
|
|
bool
|
2023-11-03 13:40:14 +00:00
|
|
|
check_rcs(const std::set<RemoteRC>& 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
|
|
|
{
|
2023-11-03 13:40:14 +00:00
|
|
|
std::optional<bool> enable_profiling;
|
|
|
|
bool save_profiles;
|
|
|
|
std::set<RouterID> strict_connect;
|
|
|
|
std::string if_name;
|
|
|
|
IPRange if_addr;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::optional<fs::path> keyfile;
|
|
|
|
std::string endpoint_type;
|
|
|
|
bool is_reachable = false;
|
|
|
|
std::optional<int> hops;
|
|
|
|
std::optional<int> paths;
|
|
|
|
bool allow_exit = false;
|
|
|
|
std::set<RouterID> snode_blacklist;
|
|
|
|
net::IPRangeMap<service::Address> exit_map;
|
|
|
|
net::IPRangeMap<std::string> ons_exit_map;
|
2020-10-21 09:39:01 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::unordered_map<service::Address, service::AuthInfo> exit_auths;
|
|
|
|
std::unordered_map<std::string, service::AuthInfo> ons_exit_auths;
|
2020-10-21 09:39:01 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::unordered_map<huint128_t, service::Address> map_addrs;
|
2020-04-30 22:11:05 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
service::AuthType auth_type = service::AuthType::NONE;
|
|
|
|
service::AuthFileType auth_file_type = service::AuthFileType::HASHES;
|
|
|
|
std::optional<std::string> auth_url;
|
|
|
|
std::optional<std::string> auth_method;
|
|
|
|
std::unordered_set<service::Address> auth_whitelist;
|
|
|
|
std::unordered_set<std::string> auth_static_tokens;
|
|
|
|
std::set<fs::path> auth_files;
|
2020-06-02 21:10:42 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::vector<llarp::dns::SRVData> srv_records;
|
2020-08-31 20:07:17 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::optional<huint128_t> base_ipv6_addr;
|
2021-03-18 15:59:02 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::set<IPRange> owned_ranges;
|
|
|
|
std::optional<net::TrafficPolicy> traffic_policy;
|
2021-04-14 15:07:06 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::optional<llarp_time_t> path_alignment_timeout;
|
2021-05-01 20:25:32 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::optional<fs::path> addr_map_persist_file;
|
2020-04-30 22:11:05 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
bool enable_route_poker;
|
|
|
|
bool blackhole_routes;
|
2021-12-04 15:08:18 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
define_config_options(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DnsConfig
|
|
|
|
{
|
2023-11-03 13:40:14 +00:00
|
|
|
bool raw;
|
|
|
|
std::vector<SockAddr> bind_addr;
|
|
|
|
std::vector<SockAddr> upstream_dns;
|
|
|
|
std::vector<fs::path> hostfiles;
|
|
|
|
std::optional<SockAddr> query_bind;
|
2022-07-28 16:07:38 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::unordered_multimap<std::string, std::string> extra_opts;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
define_config_options(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
|
|
|
{
|
2023-11-03 13:40:14 +00:00
|
|
|
std::optional<net::ipaddr_t> public_addr;
|
|
|
|
std::optional<net::port_t> public_port;
|
2023-11-03 22:11:35 +00:00
|
|
|
|
|
|
|
std::optional<oxen::quic::Address> addr;
|
|
|
|
bool using_new_api = false;
|
2019-07-08 23:29:37 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
define_config_options(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
|
2023-11-03 13:40:14 +00:00
|
|
|
define_config_options(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
2023-10-23 22:58:58 +00:00
|
|
|
// TODO: remove oxenmq from this header
|
2020-03-27 21:53:43 +00:00
|
|
|
struct ApiConfig
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2023-11-03 13:40:14 +00:00
|
|
|
bool enable_rpc_server = false;
|
|
|
|
std::vector<oxenmq::address> rpc_bind_addrs;
|
2019-07-08 23:29:37 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
define_config_options(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct LokidConfig
|
|
|
|
{
|
2023-11-03 13:40:14 +00:00
|
|
|
fs::path id_keyfile;
|
|
|
|
oxenmq::address rpc_addr;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
define_config_options(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;
|
2023-11-03 13:40:14 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
define_config_options(ConfigDefinition& conf, const ConfigGenParameters& params);
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct LoggingConfig
|
|
|
|
{
|
2023-11-03 13:40:14 +00:00
|
|
|
log::Type type = log::Type::Print;
|
|
|
|
log::Level level = log::Level::off;
|
|
|
|
std::string file;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-30 16:25:02 +00:00
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
define_config_options(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>
|
2023-11-03 13:40:14 +00:00
|
|
|
make_gen_params() 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
|
2023-11-03 13:40:14 +00:00
|
|
|
init_config(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
|
2023-11-03 13:40:14 +00:00
|
|
|
add_backcompat_opts(ConfigDefinition& conf);
|
2020-04-29 16:47:51 +00:00
|
|
|
|
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
|
2023-11-03 13:40:14 +00:00
|
|
|
load(std::optional<fs::path> fname = std::nullopt, bool isRelay = false);
|
2020-10-21 12:58:08 +00:00
|
|
|
|
2022-07-09 15:05:52 +00:00
|
|
|
// Load a config from a string of ini, same effects as Config::Load
|
|
|
|
bool
|
2023-11-03 13:40:14 +00:00
|
|
|
load_string(std::string_view ini, bool isRelay = false);
|
2022-07-09 15:05:52 +00:00
|
|
|
|
2020-10-21 12:58:08 +00:00
|
|
|
std::string
|
2023-11-03 13:40:14 +00:00
|
|
|
generate_client_config_base();
|
2020-10-21 12:58:08 +00:00
|
|
|
|
|
|
|
std::string
|
2023-11-03 13:40:14 +00:00
|
|
|
generate_router_config_base();
|
2020-10-21 12:58:08 +00:00
|
|
|
|
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
save();
|
2020-10-21 12:58:08 +00:00
|
|
|
|
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
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
|
2023-11-03 13:40:14 +00:00
|
|
|
add_default(std::string section, std::string key, std::string value);
|
2021-03-02 18:18:22 +00:00
|
|
|
|
2021-04-01 11:13:39 +00:00
|
|
|
/// create a config with the default parameters for an embedded lokinet
|
|
|
|
static std::shared_ptr<Config>
|
2023-11-03 13:40:14 +00:00
|
|
|
make_embedded_config();
|
2021-04-01 11:13:39 +00:00
|
|
|
|
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
|
2023-11-03 13:40:14 +00:00
|
|
|
load_default_config(bool isRelay);
|
2020-08-27 12:43:53 +00:00
|
|
|
|
2022-06-27 17:14:03 +00:00
|
|
|
bool
|
2023-11-03 13:40:14 +00:00
|
|
|
load_config_data(
|
2022-06-27 17:14:03 +00:00
|
|
|
std::string_view ini, std::optional<fs::path> fname = std::nullopt, bool isRelay = false);
|
|
|
|
|
2020-08-27 12:43:53 +00:00
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
load_overrides(ConfigDefinition& conf) const;
|
2020-08-27 12:43:53 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
std::vector<std::array<std::string, 3>> additional;
|
|
|
|
ConfigParser parser;
|
|
|
|
const fs::path data_dir;
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
2020-03-23 20:53:42 +00:00
|
|
|
void
|
2023-11-03 13:40:14 +00:00
|
|
|
ensure_config(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
|