2019-07-02 21:28:28 +00:00
|
|
|
#ifndef LLARP_CONFIG_HPP
|
|
|
|
#define LLARP_CONFIG_HPP
|
|
|
|
|
|
|
|
#include <crypto/types.hpp>
|
|
|
|
#include <router_contact.hpp>
|
|
|
|
#include <util/fs.hpp>
|
2019-07-08 23:29:37 +00:00
|
|
|
#include <util/str.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-02-27 22:05:25 +00:00
|
|
|
|
|
|
|
struct llarp_config;
|
2019-07-02 21:28:28 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
2019-07-06 13:46:21 +00:00
|
|
|
struct ConfigParser;
|
|
|
|
|
2020-02-22 21:40:12 +00:00
|
|
|
inline const char*
|
|
|
|
lokinetEnv(string_view suffix);
|
|
|
|
|
|
|
|
std::string
|
|
|
|
fromEnv(string_view val, string_view envNameSuffix);
|
|
|
|
int
|
|
|
|
fromEnv(const int& val, string_view envNameSuffix);
|
|
|
|
uint16_t
|
|
|
|
fromEnv(const uint16_t& val, string_view envNameSuffix);
|
|
|
|
size_t
|
|
|
|
fromEnv(const size_t& val, string_view envNameSuffix);
|
|
|
|
nonstd::optional< bool >
|
|
|
|
fromEnv(const nonstd::optional< bool >& val, string_view envNameSuffix);
|
2019-07-08 23:29:37 +00:00
|
|
|
|
2019-07-01 23:55:02 +00:00
|
|
|
class RouterConfig
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-02-28 01:23:36 +00:00
|
|
|
public:
|
2019-07-02 21:28:28 +00:00
|
|
|
/// always maintain this many connections to other routers
|
2019-07-01 23:55:02 +00:00
|
|
|
size_t m_minConnectedRouters = 2;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
|
|
|
/// hard upperbound limit on the number of router to router connections
|
2019-08-12 11:20:57 +00:00
|
|
|
size_t m_maxConnectedRouters = 5;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-07-01 23:55:02 +00:00
|
|
|
std::string m_netId;
|
|
|
|
std::string m_nickname;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-07-14 11:25:33 +00:00
|
|
|
std::string m_encryptionKeyfile = "encryption.key";
|
2019-07-02 21:28:28 +00:00
|
|
|
|
|
|
|
// path to write our self signed rc to
|
2019-07-14 11:25:33 +00:00
|
|
|
std::string m_ourRcFile = "rc.signed";
|
2019-07-02 21:28:28 +00:00
|
|
|
|
|
|
|
// transient iwp encryption key
|
2019-07-14 11:25:33 +00:00
|
|
|
std::string m_transportKeyfile = "transport.key";
|
2019-07-02 21:28:28 +00:00
|
|
|
|
|
|
|
// long term identity key
|
2019-07-14 11:25:33 +00:00
|
|
|
std::string m_identKeyfile = "identity.key";
|
2019-07-01 23:55:02 +00:00
|
|
|
|
2020-02-19 21:58:01 +00:00
|
|
|
nonstd::optional< bool > m_blockBogons;
|
2019-08-26 23:29:17 +00:00
|
|
|
|
2019-07-01 23:55:02 +00:00
|
|
|
bool m_publicOverride = false;
|
|
|
|
struct sockaddr_in m_ip4addr;
|
|
|
|
AddressInfo m_addrInfo;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-07-13 11:54:58 +00:00
|
|
|
int m_workerThreads = 1;
|
|
|
|
int m_numNetThreads = 1;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-11-25 21:30:34 +00:00
|
|
|
size_t m_JobQueueSize = size_t{1024 * 8};
|
|
|
|
|
2019-08-22 20:56:27 +00:00
|
|
|
std::string m_DefaultLinkProto = "iwp";
|
2019-08-07 16:33:29 +00:00
|
|
|
|
2019-07-01 23:55:02 +00:00
|
|
|
public:
|
|
|
|
// clang-format off
|
2019-11-25 21:30:34 +00:00
|
|
|
size_t jobQueueSize() const { return fromEnv(m_JobQueueSize, "JOB_QUEUE_SIZE"); }
|
2019-08-26 23:29:17 +00:00
|
|
|
size_t minConnectedRouters() const { return fromEnv(m_minConnectedRouters, "MIN_CONNECTED_ROUTERS"); }
|
|
|
|
size_t maxConnectedRouters() const { return fromEnv(m_maxConnectedRouters, "MAX_CONNECTED_ROUTERS"); }
|
|
|
|
std::string encryptionKeyfile() const { return fromEnv(m_encryptionKeyfile, "ENCRYPTION_KEYFILE"); }
|
|
|
|
std::string ourRcFile() const { return fromEnv(m_ourRcFile, "OUR_RC_FILE"); }
|
|
|
|
std::string transportKeyfile() const { return fromEnv(m_transportKeyfile, "TRANSPORT_KEYFILE"); }
|
|
|
|
std::string identKeyfile() const { return fromEnv(m_identKeyfile, "IDENT_KEYFILE"); }
|
|
|
|
std::string netId() const { return fromEnv(m_netId, "NETID"); }
|
2019-10-05 16:48:05 +00:00
|
|
|
std::string nickname() const { return fromEnv(m_nickname, "NICKNAME"); }
|
2019-08-26 23:29:17 +00:00
|
|
|
bool publicOverride() const { return fromEnv(m_publicOverride, "PUBLIC_OVERRIDE"); }
|
|
|
|
const struct sockaddr_in& ip4addr() const { return m_ip4addr; }
|
|
|
|
const AddressInfo& addrInfo() const { return m_addrInfo; }
|
|
|
|
int workerThreads() const { return fromEnv(m_workerThreads, "WORKER_THREADS"); }
|
|
|
|
int numNetThreads() const { return fromEnv(m_numNetThreads, "NUM_NET_THREADS"); }
|
2019-08-27 12:15:41 +00:00
|
|
|
std::string defaultLinkProto() const { return fromEnv(m_DefaultLinkProto, "LINK_PROTO"); }
|
2020-02-19 21:58:01 +00:00
|
|
|
nonstd::optional< bool > blockBogons() const { return fromEnv(m_blockBogons, "BLOCK_BOGONS"); }
|
2019-07-01 23:55:02 +00:00
|
|
|
// clang-format on
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-07-02 00:20:58 +00:00
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
2019-07-02 00:20:58 +00:00
|
|
|
class NetworkConfig
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2019-07-02 00:58:23 +00:00
|
|
|
public:
|
|
|
|
using NetConfig = std::unordered_multimap< std::string, std::string >;
|
|
|
|
|
2020-02-28 01:23:36 +00:00
|
|
|
public:
|
2020-02-19 21:58:01 +00:00
|
|
|
nonstd::optional< bool > m_enableProfiling;
|
2019-07-02 00:20:58 +00:00
|
|
|
std::string m_routerProfilesFile = "profiles.dat";
|
|
|
|
std::string m_strictConnect;
|
2019-07-02 00:58:23 +00:00
|
|
|
NetConfig m_netConfig;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-07-02 00:20:58 +00:00
|
|
|
public:
|
|
|
|
// clang-format off
|
2020-02-19 21:58:01 +00:00
|
|
|
nonstd::optional< bool > enableProfiling() const { return fromEnv(m_enableProfiling, "ENABLE_PROFILING"); }
|
2019-07-08 23:29:37 +00:00
|
|
|
std::string routerProfilesFile() const { return fromEnv(m_routerProfilesFile, "ROUTER_PROFILES_FILE"); }
|
|
|
|
std::string strictConnect() const { return fromEnv(m_strictConnect, "STRICT_CONNECT"); }
|
|
|
|
const NetConfig& netConfig() const { return m_netConfig; }
|
2019-07-02 00:20:58 +00:00
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
2019-07-08 23:29:37 +00:00
|
|
|
class NetdbConfig
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-02-28 01:23:36 +00:00
|
|
|
public:
|
2019-07-08 23:29:37 +00:00
|
|
|
std::string m_nodedbDir;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// clang-format off
|
|
|
|
std::string nodedbDir() const { return fromEnv(m_nodedbDir, "NODEDB_DIR"); }
|
|
|
|
// clang-format on
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-07-02 00:20:58 +00:00
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DnsConfig
|
|
|
|
{
|
|
|
|
std::unordered_multimap< std::string, std::string > netConfig;
|
|
|
|
|
2019-07-02 00:20:58 +00:00
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
2019-08-07 16:33:29 +00:00
|
|
|
class LinksConfig
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2019-07-08 23:29:37 +00:00
|
|
|
public:
|
2019-08-07 16:33:29 +00:00
|
|
|
static constexpr int Interface = 0;
|
|
|
|
static constexpr int AddressFamily = 1;
|
|
|
|
static constexpr int Port = 2;
|
|
|
|
static constexpr int Options = 3;
|
2019-07-08 23:29:37 +00:00
|
|
|
|
2019-08-26 11:16:46 +00:00
|
|
|
using ServerOptions = std::unordered_set< std::string >;
|
2019-08-07 16:33:29 +00:00
|
|
|
using LinkInfo = std::tuple< std::string, int, uint16_t, ServerOptions >;
|
|
|
|
using Links = std::vector< LinkInfo >;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-02-28 01:23:36 +00:00
|
|
|
public:
|
2019-08-07 16:33:29 +00:00
|
|
|
LinkInfo m_OutboundLink;
|
|
|
|
Links m_InboundLinks;
|
2019-07-08 23:29:37 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// clang-format off
|
2019-08-07 16:33:29 +00:00
|
|
|
const LinkInfo& outboundLink() const { return m_OutboundLink; }
|
|
|
|
|
|
|
|
const Links& inboundLinks() const { return m_InboundLinks; }
|
2019-07-08 23:29:37 +00:00
|
|
|
// clang-format on
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-07-02 00:20:58 +00:00
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConnectConfig
|
|
|
|
{
|
|
|
|
std::vector< std::string > routers;
|
|
|
|
|
2019-07-02 00:20:58 +00:00
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ServicesConfig
|
|
|
|
{
|
|
|
|
std::vector< std::pair< std::string, std::string > > services;
|
2019-07-02 00:20:58 +00:00
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SystemConfig
|
|
|
|
{
|
|
|
|
std::string pidfile;
|
|
|
|
|
2019-07-02 00:20:58 +00:00
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
2019-07-08 23:29:37 +00:00
|
|
|
class ApiConfig
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-02-28 01:23:36 +00:00
|
|
|
public:
|
2019-07-08 23:29:37 +00:00
|
|
|
bool m_enableRPCServer = false;
|
|
|
|
std::string m_rpcBindAddr = "127.0.0.1:1190";
|
|
|
|
|
|
|
|
public:
|
|
|
|
// clang-format off
|
|
|
|
bool enableRPCServer() const { return fromEnv(m_enableRPCServer, "ENABLE_RPC_SERVER"); }
|
|
|
|
std::string rpcBindAddr() const { return fromEnv(m_rpcBindAddr, "RPC_BIND_ADDR"); }
|
|
|
|
// clang-format on
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-07-02 00:20:58 +00:00
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-07-02 00:20:58 +00:00
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BootstrapConfig
|
|
|
|
{
|
|
|
|
std::vector< std::string > routers;
|
2019-07-02 00:20:58 +00:00
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LoggingConfig
|
|
|
|
{
|
|
|
|
bool m_LogJSON = false;
|
2019-07-01 23:55:02 +00:00
|
|
|
FILE* m_LogFile = stdout;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-07-02 00:20:58 +00:00
|
|
|
void
|
2019-07-02 21:28:28 +00:00
|
|
|
fromSection(string_view key, string_view val);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Config
|
|
|
|
{
|
2020-02-28 01:23:36 +00:00
|
|
|
public:
|
2019-07-06 13:46:21 +00:00
|
|
|
bool
|
2019-07-01 23:55:02 +00:00
|
|
|
parse(const ConfigParser& parser);
|
2019-07-06 13:46:21 +00:00
|
|
|
|
|
|
|
public:
|
2019-07-02 21:28:28 +00:00
|
|
|
RouterConfig router;
|
|
|
|
NetworkConfig network;
|
|
|
|
ConnectConfig connect;
|
|
|
|
NetdbConfig netdb;
|
|
|
|
DnsConfig dns;
|
2019-08-07 16:33:29 +00:00
|
|
|
LinksConfig links;
|
2019-07-02 21:28:28 +00:00
|
|
|
ServicesConfig services;
|
|
|
|
SystemConfig system;
|
|
|
|
ApiConfig api;
|
|
|
|
LokidConfig lokid;
|
|
|
|
BootstrapConfig bootstrap;
|
|
|
|
LoggingConfig logging;
|
|
|
|
|
|
|
|
bool
|
2019-07-01 23:55:02 +00:00
|
|
|
Load(const char* fname);
|
2019-07-06 13:46:21 +00:00
|
|
|
|
|
|
|
bool
|
2019-07-17 00:08:43 +00:00
|
|
|
LoadFromStr(string_view str);
|
2020-02-27 22:05:25 +00:00
|
|
|
|
|
|
|
llarp_config *
|
|
|
|
Copy() const;
|
2019-07-02 21:28:28 +00:00
|
|
|
};
|
|
|
|
|
2019-10-05 16:48:05 +00:00
|
|
|
fs::path
|
|
|
|
GetDefaultConfigDir();
|
|
|
|
|
|
|
|
fs::path
|
|
|
|
GetDefaultConfigPath();
|
|
|
|
|
2019-07-02 21:28:28 +00:00
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
void
|
2019-08-12 11:20:57 +00:00
|
|
|
llarp_generic_ensure_config(std::ofstream& f, std::string basepath,
|
|
|
|
bool isRouter);
|
2019-07-02 21:28:28 +00:00
|
|
|
|
|
|
|
void
|
2019-07-01 23:55:02 +00:00
|
|
|
llarp_ensure_router_config(std::ofstream& f, std::string basepath);
|
2019-07-02 21:28:28 +00:00
|
|
|
|
|
|
|
bool
|
2019-07-01 23:55:02 +00:00
|
|
|
llarp_ensure_client_config(std::ofstream& f, std::string basepath);
|
2019-07-02 21:28:28 +00:00
|
|
|
|
|
|
|
#endif
|