1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/config/config.hpp

244 lines
5.4 KiB
C++
Raw Normal View History

#ifndef LLARP_CONFIG_HPP
#define LLARP_CONFIG_HPP
#include <crypto/types.hpp>
#include <router_contact.hpp>
#include <util/fs.hpp>
#include <util/str.hpp>
#include <config/ini.hpp>
#include <config/definition.hpp>
#include <cstdlib>
#include <functional>
#include <string>
#include <utility>
#include <vector>
#include <unordered_set>
namespace llarp
{
using SectionValues_t = llarp::ConfigParser::SectionValues_t;
using Config_impl_t = llarp::ConfigParser::Config_impl_t;
2019-07-06 15:46:21 +02:00
2020-03-31 17:25:29 +02:00
// TODO: don't use these maps. they're sloppy and difficult to follow
using FreehandOptions = std::unordered_multimap< std::string, std::string >;
/// 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;
};
struct RouterConfig
{
/// always maintain this many connections to other routers
2019-07-02 01:55:02 +02:00
size_t m_minConnectedRouters = 2;
/// hard upperbound limit on the number of router to router connections
2019-08-12 13:20:57 +02:00
size_t m_maxConnectedRouters = 5;
std::string m_netId = "lokinet";
2019-07-02 01:55:02 +02:00
std::string m_nickname;
std::string m_dataDir;
2019-07-02 01:55:02 +02:00
nonstd::optional<bool> m_blockBogons;
2019-08-27 01:29:17 +02:00
2019-07-02 01:55:02 +02:00
bool m_publicOverride = false;
struct sockaddr_in m_ip4addr;
AddressInfo m_addrInfo;
2019-07-13 13:54:58 +02:00
int m_workerThreads = 1;
int m_numNetThreads = 1;
2019-11-25 22:30:34 +01:00
size_t m_JobQueueSize = size_t{1024 * 8};
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct NetworkConfig
{
nonstd::optional< bool > m_enableProfiling;
2019-07-02 02:20:58 +02:00
std::string m_routerProfilesFile = "profiles.dat";
std::string m_strictConnect;
2020-03-31 17:25:29 +02:00
FreehandOptions m_options;
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct NetdbConfig
{
std::string m_nodedbDir;
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct DnsConfig
{
2020-03-31 17:25:29 +02:00
FreehandOptions m_options;
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct LinksConfig
{
2020-03-19 23:20:45 +01:00
struct LinkInfo
{
std::string interface;
int addressFamily;
uint16_t port = -1;
2020-03-19 23:20:45 +01:00
};
/// Create a LinkInfo from the given string.
/// @throws if str does not represent a LinkInfo.
LinkInfo
LinkInfoFromINIValues(string_view name, string_view value);
2019-08-07 18:33:29 +02:00
LinkInfo m_OutboundLink;
2020-03-19 23:20:45 +01:00
std::vector<LinkInfo> m_InboundLinks;
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct ConnectConfig
{
std::vector<std::string> routers;
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct ServicesConfig
{
std::vector< std::pair< std::string, std::string > > services;
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct SystemConfig
{
std::string pidfile;
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct ApiConfig
{
bool m_enableRPCServer = false;
std::string m_rpcBindAddr = "127.0.0.1:1190";
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct LokidConfig
{
bool usingSNSeed = false;
bool whitelistRouters = false;
fs::path ident_keyfile = "identity.key";
std::string lokidRPCAddr = "127.0.0.1:22023";
std::string lokidRPCUser;
std::string lokidRPCPassword;
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct BootstrapConfig
{
std::vector< std::string > routers;
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct LoggingConfig
{
enum class LogType
{
Unknown = 0,
File,
Json,
Syslog,
};
static LogType LogTypeFromString(const std::string&);
LogType m_logType;
LogLevel m_logLevel;
std::string m_logFile;
2020-03-30 18:25:02 +02:00
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct SnappConfig
{
std::string m_keyfile;
bool m_reachable;
int m_hops;
int m_paths;
std::vector<std::string> m_snodeBlacklist;
std::string m_exitNode;
std::string m_localDNS;
std::string m_upstreamDNS;
std::string m_mapAddr;
void
defineConfigOptions(Configuration& conf, const ConfigGenParameters& params);
};
struct Config
{
RouterConfig router;
NetworkConfig network;
ConnectConfig connect;
NetdbConfig netdb;
DnsConfig dns;
2019-08-07 18:33:29 +02:00
LinksConfig links;
ServicesConfig services;
SystemConfig system;
ApiConfig api;
LokidConfig lokid;
BootstrapConfig bootstrap;
LoggingConfig logging;
// Initialize config definition
void
initializeConfig(Configuration& conf, const ConfigGenParameters& params);
// Load a config from the given file
bool
Load(const char* fname, bool isRelay, fs::path defaultDataDir);
2019-07-06 15:46:21 +02:00
std::string
generateBaseClientConfig(fs::path defaultDataDir);
std::string
generateBaseRouterConfig(fs::path defaultDataDir);
};
fs::path
GetDefaultDataDir();
fs::path
GetDefaultConfigFilename();
fs::path
GetDefaultConfigPath();
void
ensureConfig(const fs::path& defaultDataDir,
const fs::path& confFile,
bool overwrite,
bool asRouter);
} // namespace llarp
#endif