2019-07-02 21:28:28 +00:00
|
|
|
#include <config/config.hpp>
|
|
|
|
|
|
|
|
#include <config/ini.hpp>
|
|
|
|
#include <constants/defaults.hpp>
|
2020-04-02 15:48:20 +00:00
|
|
|
#include <constants/files.hpp>
|
2019-07-02 21:28:28 +00:00
|
|
|
#include <net/net.hpp>
|
2019-08-26 23:29:17 +00:00
|
|
|
#include <router_contact.hpp>
|
2020-03-13 20:45:33 +00:00
|
|
|
#include <stdexcept>
|
2019-07-02 21:28:28 +00:00
|
|
|
#include <util/fs.hpp>
|
2019-09-01 12:10:49 +00:00
|
|
|
#include <util/logging/logger.hpp>
|
2019-07-02 21:28:28 +00:00
|
|
|
#include <util/mem.hpp>
|
|
|
|
#include <util/str.hpp>
|
2019-11-15 19:40:43 +00:00
|
|
|
#include <util/lokinet_init.h>
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2019-07-13 15:13:10 +00:00
|
|
|
#include <cstdlib>
|
2019-07-02 21:28:28 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <ios>
|
|
|
|
#include <iostream>
|
2020-03-23 20:53:42 +00:00
|
|
|
#include "ghc/filesystem.hpp"
|
2019-07-02 21:28:28 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2020-03-27 00:49:05 +00:00
|
|
|
// constants for config file default values
|
|
|
|
constexpr int DefaultMinConnectionsForRouter = 6;
|
|
|
|
constexpr int DefaultMaxConnectionsForRouter = 60;
|
|
|
|
|
|
|
|
constexpr int DefaultMinConnectionsForClient = 4;
|
|
|
|
constexpr int DefaultMaxConnectionsForClient = 6;
|
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
RouterConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-31 15:51:24 +00:00
|
|
|
constexpr int DefaultJobQueueSize = 1024 * 8;
|
|
|
|
constexpr auto DefaultNetId = "lokinet";
|
|
|
|
constexpr int DefaultPublicPort = 1090;
|
|
|
|
constexpr int DefaultWorkerThreads = 1;
|
|
|
|
constexpr int DefaultNetThreads = 1;
|
2020-03-31 16:04:47 +00:00
|
|
|
constexpr bool DefaultBlockBogons = true;
|
2020-03-31 15:51:24 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<int>("router", "job-queue-size", false, DefaultJobQueueSize, [this](int arg) {
|
|
|
|
if (arg < 1024)
|
|
|
|
throw std::invalid_argument("job-queue-size must be 1024 or greater");
|
2020-03-13 20:45:33 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
m_JobQueueSize = arg;
|
|
|
|
});
|
2020-03-13 20:45:33 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>("router", "netid", false, DefaultNetId, [this](std::string arg) {
|
|
|
|
if (arg.size() > NetID::size())
|
|
|
|
throw std::invalid_argument(stringify("netid is too long, max length is ", NetID::size()));
|
2020-03-13 20:45:33 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
m_netId = std::move(arg);
|
|
|
|
});
|
2020-03-13 20:45:33 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
int minConnections =
|
|
|
|
(params.isRelay ? DefaultMinConnectionsForRouter : DefaultMinConnectionsForClient);
|
|
|
|
conf.defineOption<int>("router", "min-connections", false, minConnections, [=](int arg) {
|
|
|
|
if (arg < minConnections)
|
|
|
|
throw std::invalid_argument(stringify("min-connections must be >= ", minConnections));
|
2020-03-13 20:45:33 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
m_minConnectedRouters = arg;
|
|
|
|
});
|
2020-03-13 20:45:33 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
int maxConnections =
|
|
|
|
(params.isRelay ? DefaultMaxConnectionsForRouter : DefaultMaxConnectionsForClient);
|
|
|
|
conf.defineOption<int>("router", "max-connections", false, maxConnections, [=](int arg) {
|
|
|
|
if (arg < maxConnections)
|
|
|
|
throw std::invalid_argument(stringify("max-connections must be >= ", maxConnections));
|
2020-03-13 20:45:33 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
m_maxConnectedRouters = arg;
|
|
|
|
});
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>("router", "nickname", false, "", AssignmentAcceptor(m_nickname));
|
2020-04-02 15:12:45 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"router", "data-dir", false, GetDefaultDataDir(), [this](std::string arg) {
|
|
|
|
fs::path dir = arg;
|
|
|
|
if (not fs::exists(dir))
|
|
|
|
throw std::runtime_error(
|
|
|
|
stringify("Specified [router]:data-dir ", arg, " does not exist"));
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
m_dataDir = std::move(dir);
|
|
|
|
});
|
2020-03-31 22:33:26 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>("router", "public-address", false, "", [this](std::string arg) {
|
|
|
|
if (not arg.empty())
|
|
|
|
{
|
|
|
|
llarp::LogInfo("public ip ", arg, " size ", arg.size());
|
2020-03-31 22:33:26 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
if (arg.size() > 16)
|
|
|
|
throw std::invalid_argument(stringify("Not a valid IPv4 addr: ", arg));
|
2020-03-31 22:33:26 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
// assume IPv4
|
|
|
|
llarp::Addr a(arg);
|
|
|
|
llarp::LogInfo("setting public ipv4 ", a);
|
|
|
|
m_addrInfo.ip = *a.addr6();
|
|
|
|
m_publicOverride = true;
|
|
|
|
}
|
|
|
|
});
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<int>("router", "public-port", false, DefaultPublicPort, [this](int arg) {
|
|
|
|
if (arg <= 0)
|
|
|
|
throw std::invalid_argument("public-port must be > 0");
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
// Not needed to flip upside-down - this is done in llarp::Addr(const AddressInfo&)
|
|
|
|
m_ip4addr.sin_port = arg;
|
|
|
|
m_addrInfo.port = arg;
|
|
|
|
m_publicOverride = true;
|
|
|
|
});
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<int>(
|
|
|
|
"router", "worker-threads", false, DefaultWorkerThreads, [this](int arg) {
|
|
|
|
if (arg <= 0)
|
|
|
|
throw std::invalid_argument("worker-threads must be > 0");
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
m_workerThreads = arg;
|
|
|
|
});
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<int>("router", "net-threads", false, DefaultNetThreads, [this](int arg) {
|
|
|
|
if (arg <= 0)
|
|
|
|
throw std::invalid_argument("net-threads must be > 0");
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
m_numNetThreads = arg;
|
|
|
|
});
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<bool>(
|
|
|
|
"router", "block-bogons", false, DefaultBlockBogons, AssignmentAcceptor(m_blockBogons));
|
2019-07-02 21:28:28 +00:00
|
|
|
}
|
2019-07-02 00:20:58 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
NetworkConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
(void)params;
|
2020-03-27 01:07:45 +00:00
|
|
|
|
2020-03-31 15:51:24 +00:00
|
|
|
constexpr bool DefaultProfilingValue = true;
|
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<bool>(
|
|
|
|
"network",
|
|
|
|
"profiling",
|
|
|
|
false,
|
|
|
|
DefaultProfilingValue,
|
|
|
|
AssignmentAcceptor(m_enableProfiling));
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-03-31 15:51:24 +00:00
|
|
|
// TODO: this should be implied from [router]:data-dir
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"network",
|
|
|
|
"profiles",
|
|
|
|
false,
|
|
|
|
m_routerProfilesFile,
|
|
|
|
AssignmentAcceptor(m_routerProfilesFile));
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"network", "strict-connect", false, "", AssignmentAcceptor(m_strictConnect));
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-03-31 21:26:55 +00:00
|
|
|
// TODO: make sure this is documented... what does it mean though?
|
2020-03-31 15:25:29 +00:00
|
|
|
conf.addUndeclaredHandler("network", [&](string_view, string_view name, string_view value) {
|
|
|
|
m_options.emplace(name, value);
|
|
|
|
return true;
|
|
|
|
});
|
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
|
|
|
DnsConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
(void)params;
|
2020-03-27 01:07:45 +00:00
|
|
|
|
2020-03-31 21:26:55 +00:00
|
|
|
// TODO: make sure this is documented
|
|
|
|
// TODO: refactor to remove freehand options map
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"network", "upstream-dns", false, true, "", [this](std::string arg) {
|
|
|
|
m_options.emplace("upstream-dns", std::move(arg));
|
|
|
|
});
|
2020-03-31 15:25:29 +00:00
|
|
|
|
2020-03-31 21:26:55 +00:00
|
|
|
// TODO: make sure this is documented
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"network", "local-dns", false, true, "", [this](std::string arg) {
|
|
|
|
m_options.emplace("local-dns", std::move(arg));
|
|
|
|
});
|
2019-07-02 21:28:28 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 16:15:00 +00:00
|
|
|
LinksConfig::LinkInfo
|
|
|
|
LinksConfig::LinkInfoFromINIValues(string_view name, string_view value)
|
|
|
|
{
|
|
|
|
// we treat the INI k:v pair as:
|
|
|
|
// k: interface name, * indicating outbound
|
|
|
|
// v: a comma-separated list of values, an int indicating port (everything else ignored)
|
|
|
|
// this is somewhat of a backwards- and forwards-compatibility thing
|
|
|
|
|
|
|
|
LinkInfo info;
|
|
|
|
info.addressFamily = AF_INET;
|
|
|
|
info.interface = str(name);
|
|
|
|
|
|
|
|
std::vector<string_view> splits = split(value, ',');
|
|
|
|
for (string_view str : splits)
|
|
|
|
{
|
|
|
|
int asNum = std::atoi(str.data());
|
|
|
|
if (asNum > 0)
|
|
|
|
info.port = asNum;
|
|
|
|
|
|
|
|
// otherwise, ignore ("future-proofing")
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
LinksConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
(void)params;
|
2020-03-27 01:07:45 +00:00
|
|
|
|
2020-03-23 16:15:00 +00:00
|
|
|
conf.addUndeclaredHandler("bind", [&](string_view, string_view name, string_view value) {
|
|
|
|
LinkInfo info = LinkInfoFromINIValues(name, value);
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-23 16:15:00 +00:00
|
|
|
if (info.port <= 0)
|
|
|
|
throw std::invalid_argument(stringify("Invalid [bind] port specified on interface", name));
|
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
if (name == "*")
|
2020-03-23 16:15:00 +00:00
|
|
|
m_OutboundLink = std::move(info);
|
2019-08-07 16:33:29 +00:00
|
|
|
else
|
2020-03-23 16:15:00 +00:00
|
|
|
m_InboundLinks.emplace_back(std::move(info));
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-23 16:15:00 +00:00
|
|
|
return true;
|
|
|
|
});
|
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
|
|
|
ConnectConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
(void)params;
|
2020-03-27 01:07:45 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.addUndeclaredHandler(
|
|
|
|
"connect", [this](string_view section, string_view name, string_view value) {
|
|
|
|
fs::path file = str(value);
|
|
|
|
if (not fs::exists(file))
|
|
|
|
throw std::runtime_error(stringify(
|
|
|
|
"Specified bootstrap file ",
|
|
|
|
value,
|
|
|
|
"specified in [",
|
|
|
|
section,
|
|
|
|
"]:",
|
|
|
|
name,
|
|
|
|
" does not exist"));
|
|
|
|
|
|
|
|
routers.emplace_back(std::move(file));
|
|
|
|
return true;
|
|
|
|
});
|
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
|
|
|
ServicesConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
(void)params;
|
2020-03-27 01:07:45 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.addUndeclaredHandler(
|
|
|
|
"services", [this](string_view section, string_view name, string_view value) {
|
|
|
|
(void)section;
|
|
|
|
services.emplace_back(name, value);
|
|
|
|
return true;
|
|
|
|
});
|
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
|
|
|
ApiConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
(void)params;
|
2020-03-27 01:07:45 +00:00
|
|
|
|
2020-03-31 15:51:24 +00:00
|
|
|
constexpr bool DefaultRPCEnabled = true;
|
|
|
|
constexpr auto DefaultRPCBindAddr = "127.0.0.1:1190";
|
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<bool>(
|
|
|
|
"api", "enabled", false, DefaultRPCEnabled, AssignmentAcceptor(m_enableRPCServer));
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"api", "bind", false, DefaultRPCBindAddr, AssignmentAcceptor(m_rpcBindAddr));
|
2020-03-30 17:16:29 +00:00
|
|
|
|
2020-03-18 18:24:23 +00:00
|
|
|
// TODO: this was from pre-refactor:
|
2020-04-07 20:41:11 +00:00
|
|
|
// TODO: add pubkey to whitelist
|
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
|
|
|
LokidConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
(void)params;
|
2020-03-27 01:07:45 +00:00
|
|
|
|
2020-03-31 15:51:24 +00:00
|
|
|
constexpr bool DefaultWhitelistRouters = false;
|
|
|
|
constexpr auto DefaultLokidRPCAddr = "127.0.0.1:22023";
|
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"lokid", "service-node-seed", false, our_identity_filename, [this](std::string arg) {
|
|
|
|
if (not arg.empty())
|
|
|
|
{
|
|
|
|
usingSNSeed = true;
|
|
|
|
ident_keyfile = std::move(arg);
|
|
|
|
}
|
|
|
|
});
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<bool>(
|
|
|
|
"lokid", "enabled", false, DefaultWhitelistRouters, AssignmentAcceptor(whitelistRouters));
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"lokid", "jsonrpc", false, DefaultLokidRPCAddr, AssignmentAcceptor(lokidRPCAddr));
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"lokid", "username", false, "", AssignmentAcceptor(lokidRPCUser));
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"lokid", "password", false, "", AssignmentAcceptor(lokidRPCPassword));
|
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
|
|
|
BootstrapConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
(void)params;
|
2020-03-27 01:07:45 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"bootstrap", "add-node", false, true, "", [this](std::string arg) {
|
|
|
|
// TODO: validate as router fs path
|
|
|
|
routers.emplace_back(std::move(arg));
|
|
|
|
});
|
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
|
|
|
LoggingConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
(void)params;
|
2020-03-27 01:07:45 +00:00
|
|
|
|
2020-04-02 16:47:56 +00:00
|
|
|
constexpr auto DefaultLogType = "file";
|
|
|
|
constexpr auto DefaultLogFile = "stdout";
|
|
|
|
constexpr auto DefaultLogLevel = "info";
|
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"logging", "type", false, DefaultLogType, [this](std::string arg) {
|
|
|
|
LogType type = LogTypeFromString(arg);
|
|
|
|
if (type == LogType::Unknown)
|
|
|
|
throw std::invalid_argument(stringify("invalid log type: ", arg));
|
2020-03-19 21:51:22 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
m_logType = type;
|
|
|
|
});
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"logging", "level", false, DefaultLogLevel, [this](std::string arg) {
|
|
|
|
nonstd::optional<LogLevel> level = LogLevelFromString(arg);
|
|
|
|
if (not level.has_value())
|
|
|
|
throw std::invalid_argument(stringify("invalid log level value: ", arg));
|
2020-03-19 21:51:22 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
m_logLevel = level.value();
|
|
|
|
});
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"logging", "file", false, DefaultLogFile, AssignmentAcceptor(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
|
|
|
SnappConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2020-03-30 16:25:02 +00:00
|
|
|
{
|
|
|
|
(void)params;
|
|
|
|
|
|
|
|
static constexpr bool ReachableDefault = true;
|
|
|
|
static constexpr int HopsDefault = 4;
|
|
|
|
static constexpr int PathsDefault = 6;
|
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>("snapp", "keyfile", false, "", [this](std::string arg) {
|
|
|
|
// TODO: validate as valid .loki / .snode address
|
|
|
|
m_keyfile = arg;
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<bool>(
|
|
|
|
"snapp", "reachable", false, ReachableDefault, AssignmentAcceptor(m_reachable));
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<int>("snapp", "hops", false, HopsDefault, [this](int arg) {
|
|
|
|
if (arg < 1 or arg > 8)
|
|
|
|
throw std::invalid_argument("[snapp]:hops must be >= 1 and <= 8");
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<int>("snapp", "paths", false, PathsDefault, [this](int arg) {
|
|
|
|
if (arg < 1 or arg > 8)
|
|
|
|
throw std::invalid_argument("[snapp]:paths must be >= 1 and <= 8");
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>("snapp", "exit-node", false, "", [this](std::string arg) {
|
|
|
|
// TODO: validate as valid .loki / .snode address
|
|
|
|
m_exitNode = arg;
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>("snapp", "local-dns", false, "", [this](std::string arg) {
|
|
|
|
// TODO: validate as IP address
|
|
|
|
m_localDNS = arg;
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>("snapp", "upstream-dns", false, "", [this](std::string arg) {
|
|
|
|
// TODO: validate as IP address
|
|
|
|
m_upstreamDNS = arg;
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>("snapp", "mapaddr", false, "", [this](std::string arg) {
|
|
|
|
// TODO: parse / validate as loki_addr : IP addr pair
|
|
|
|
m_mapAddr = arg;
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
|
|
|
conf.addUndeclaredHandler("snapp", [&](string_view, string_view name, string_view value) {
|
|
|
|
if (name == "blacklist-snode")
|
|
|
|
{
|
|
|
|
m_snodeBlacklist.push_back(str(value));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-19 20:07:56 +00:00
|
|
|
bool
|
2020-04-07 20:41:11 +00:00
|
|
|
Config::Load(const char* fname, bool isRelay, fs::path defaultDataDir)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-19 20:07:56 +00:00
|
|
|
try
|
2019-08-26 23:29:17 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
ConfigGenParameters params;
|
|
|
|
params.isRelay = isRelay;
|
|
|
|
params.defaultDataDir = std::move(defaultDataDir);
|
|
|
|
|
2020-03-31 17:33:36 +00:00
|
|
|
ConfigDefinition conf;
|
2020-03-27 21:39:40 +00:00
|
|
|
initializeConfig(conf, params);
|
2019-07-06 17:03:40 +00:00
|
|
|
|
2020-03-19 20:07:56 +00:00
|
|
|
ConfigParser parser;
|
2020-04-07 20:41:11 +00:00
|
|
|
if (!parser.LoadFile(fname))
|
2020-03-19 20:07:56 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-19 20:07:56 +00:00
|
|
|
parser.IterAll([&](string_view section, const SectionValues_t& values) {
|
|
|
|
for (const auto& pair : values)
|
|
|
|
{
|
|
|
|
conf.addConfigValue(section, pair.first, pair.second);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-31 15:01:55 +00:00
|
|
|
conf.acceptAllOptions();
|
|
|
|
|
|
|
|
// TODO: better way to support inter-option constraints
|
|
|
|
if (router.m_maxConnectedRouters < router.m_minConnectedRouters)
|
|
|
|
throw std::invalid_argument("[router]:min-connections must be <= [router]:max-connections");
|
|
|
|
|
2020-03-19 20:07:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-04-07 20:41:11 +00:00
|
|
|
catch (const std::exception& e)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-19 20:07:56 +00:00
|
|
|
LogError("Error trying to init and parse config from file: ", e.what());
|
2019-07-02 21:28:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-07-06 13:46:21 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 20:07:56 +00:00
|
|
|
void
|
2020-03-31 17:33:36 +00:00
|
|
|
Config::initializeConfig(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-06 13:46:21 +00:00
|
|
|
{
|
2020-03-19 20:07:56 +00:00
|
|
|
// TODO: this seems like a random place to put this, should this be closer
|
|
|
|
// to main() ?
|
2020-04-07 20:41:11 +00:00
|
|
|
if (Lokinet_INIT())
|
2020-03-19 20:07:56 +00:00
|
|
|
throw std::runtime_error("Can't initializeConfig() when Lokinet_INIT() == true");
|
|
|
|
|
2020-03-27 21:39:40 +00:00
|
|
|
router.defineConfigOptions(conf, params);
|
|
|
|
network.defineConfigOptions(conf, params);
|
|
|
|
connect.defineConfigOptions(conf, params);
|
|
|
|
dns.defineConfigOptions(conf, params);
|
|
|
|
links.defineConfigOptions(conf, params);
|
|
|
|
services.defineConfigOptions(conf, params);
|
|
|
|
api.defineConfigOptions(conf, params);
|
|
|
|
lokid.defineConfigOptions(conf, params);
|
|
|
|
bootstrap.defineConfigOptions(conf, params);
|
|
|
|
logging.defineConfigOptions(conf, params);
|
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
|
|
|
std::error_code ec;
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-23 20:53:42 +00:00
|
|
|
// fail to overwrite if not instructed to do so
|
2020-04-07 20:41:11 +00:00
|
|
|
if (fs::exists(confFile, ec) && !overwrite)
|
2020-03-31 22:16:24 +00:00
|
|
|
{
|
|
|
|
LogDebug("Not creating config file; it already exists.");
|
|
|
|
return;
|
|
|
|
}
|
2020-03-23 20:53:42 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
if (ec)
|
|
|
|
throw std::runtime_error(stringify("filesystem error: ", ec));
|
2020-03-23 20:53:42 +00:00
|
|
|
|
|
|
|
// create parent dir if it doesn't exist
|
2020-03-27 21:39:40 +00:00
|
|
|
if (not fs::exists(confFile.parent_path(), ec))
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
if (not fs::create_directory(confFile.parent_path()))
|
|
|
|
throw std::runtime_error(stringify("Failed to create parent directory for ", confFile));
|
2019-07-02 21:28:28 +00:00
|
|
|
}
|
2020-04-07 20:41:11 +00:00
|
|
|
if (ec)
|
|
|
|
throw std::runtime_error(stringify("filesystem error: ", ec));
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
llarp::LogInfo("Attempting to create config file, asRouter: ", asRouter, " path: ", confFile);
|
2020-03-23 20:53:42 +00:00
|
|
|
|
|
|
|
llarp::Config config;
|
|
|
|
std::string confStr;
|
|
|
|
if (asRouter)
|
2020-03-27 21:39:40 +00:00
|
|
|
confStr = config.generateBaseRouterConfig(std::move(defaultDataDir));
|
2020-03-25 22:41:22 +00:00
|
|
|
else
|
2020-03-27 21:39:40 +00:00
|
|
|
confStr = config.generateBaseClientConfig(std::move(defaultDataDir));
|
2020-03-23 20:53:42 +00:00
|
|
|
|
|
|
|
// open a filestream
|
2020-03-27 21:39:40 +00:00
|
|
|
auto stream = llarp::util::OpenFileStream<std::ofstream>(confFile.c_str(), std::ios::binary);
|
2020-03-23 20:53:42 +00:00
|
|
|
if (not stream.has_value() or not stream.value().is_open())
|
2020-03-27 21:39:40 +00:00
|
|
|
throw std::runtime_error(stringify("Failed to open file ", confFile, " for writing"));
|
2020-03-23 20:53:42 +00:00
|
|
|
|
2020-03-25 22:41:22 +00:00
|
|
|
llarp::LogInfo("confStr: ", confStr);
|
|
|
|
|
2020-03-23 20:53:42 +00:00
|
|
|
stream.value() << confStr;
|
|
|
|
stream.value().flush();
|
|
|
|
|
2020-03-27 21:39:40 +00:00
|
|
|
llarp::LogInfo("Generated new config ", confFile);
|
2019-07-02 21:28:28 +00:00
|
|
|
}
|
2020-03-23 20:53:42 +00:00
|
|
|
|
2020-03-31 22:07:17 +00:00
|
|
|
void
|
|
|
|
generateCommonConfigComments(ConfigDefinition& def)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-25 22:41:22 +00:00
|
|
|
// router
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addSectionComments(
|
|
|
|
"router",
|
|
|
|
{
|
|
|
|
"Configuration for routing activity.",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"router",
|
|
|
|
"threads",
|
|
|
|
{
|
|
|
|
"The number of threads available for performing cryptographic functions.",
|
|
|
|
"The minimum is one thread, but network performance may increase with more.",
|
|
|
|
"threads. Should not exceed the number of logical CPU cores.",
|
|
|
|
});
|
|
|
|
|
|
|
|
def.addOptionComments(
|
|
|
|
"router",
|
|
|
|
"data-dir",
|
|
|
|
{
|
|
|
|
"Optional directory for containing lokinet runtime data. This includes generated",
|
|
|
|
"private keys.",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
|
|
|
// TODO: why did Kee want this, and/or what does it really do? Something about logs?
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments("router", "nickname", {"Router nickname. Kee wanted it."});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"router",
|
|
|
|
"min-connections",
|
|
|
|
{
|
|
|
|
"Minimum number of routers lokinet will attempt to maintain connections to.",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"router",
|
|
|
|
"max-connections",
|
|
|
|
{
|
|
|
|
"Maximum number (hard limit) of routers lokinet will be connected to at any time.",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
|
|
|
// logging
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addSectionComments(
|
|
|
|
"logging",
|
|
|
|
{
|
|
|
|
"logging settings",
|
|
|
|
});
|
2020-03-31 20:12:06 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"logging",
|
|
|
|
"level",
|
|
|
|
{
|
|
|
|
"Minimum log level to print. Logging below this level will be ignored.",
|
|
|
|
"Valid log levels, in ascending order, are:",
|
|
|
|
" trace",
|
|
|
|
" debug",
|
|
|
|
" info",
|
|
|
|
" warn",
|
|
|
|
" error",
|
|
|
|
});
|
|
|
|
|
|
|
|
def.addOptionComments(
|
|
|
|
"logging",
|
|
|
|
"type",
|
|
|
|
{
|
|
|
|
"Log type (format). Valid options are:",
|
|
|
|
" file - plaintext formatting",
|
|
|
|
" json - json-formatted log statements",
|
|
|
|
" syslog - logs directed to syslog",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
|
|
|
// api
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addSectionComments(
|
|
|
|
"api",
|
|
|
|
{
|
|
|
|
"JSON API settings",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"api",
|
|
|
|
"enabled",
|
|
|
|
{
|
|
|
|
"Determines whether or not the JSON API is enabled.",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"api",
|
|
|
|
"bind",
|
|
|
|
{
|
|
|
|
"IP address and port to bind to.",
|
|
|
|
"Recommend localhost-only for security purposes.",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
|
|
|
// dns
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addSectionComments(
|
|
|
|
"dns",
|
|
|
|
{
|
|
|
|
"DNS configuration",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"dns",
|
|
|
|
"upstream",
|
|
|
|
{
|
|
|
|
"Upstream resolver to use as fallback for non-loki addresses.",
|
|
|
|
"Multiple values accepted.",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"dns",
|
|
|
|
"bind",
|
|
|
|
{
|
|
|
|
"Address to bind to for handling DNS requests.",
|
|
|
|
"Multiple values accepted.",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
|
|
|
// bootstrap
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addSectionComments(
|
|
|
|
"bootstrap",
|
|
|
|
{
|
|
|
|
"Configure nodes that will bootstrap us onto the network",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"bootstrap",
|
|
|
|
"add-node",
|
|
|
|
{
|
|
|
|
"Specify a bootstrap file containing a signed RouterContact of a service node",
|
|
|
|
"which can act as a bootstrap. Accepts multiple values.",
|
|
|
|
});
|
2020-03-25 22:41:22 +00:00
|
|
|
|
2020-03-27 00:55:52 +00:00
|
|
|
// network
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addSectionComments(
|
|
|
|
"network",
|
|
|
|
{
|
|
|
|
"Network settings",
|
|
|
|
});
|
2020-03-27 00:55:52 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"profiles",
|
|
|
|
{
|
|
|
|
"File to contain router profiles.",
|
|
|
|
});
|
2020-03-27 00:55:52 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"strict-connect",
|
|
|
|
{
|
|
|
|
"Public key of a router which will act as sole first-hop. This may be used to",
|
|
|
|
"provide a trusted router (consider that you are not fully anonymous with your",
|
|
|
|
"first hop).",
|
|
|
|
});
|
|
|
|
|
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"exit-node",
|
|
|
|
{
|
|
|
|
"Public key of an exit-node.",
|
|
|
|
});
|
2020-03-27 00:55:52 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"ifname",
|
|
|
|
{
|
|
|
|
"Interface name for lokinet traffic.",
|
|
|
|
});
|
2020-03-27 00:55:52 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"ifaddr",
|
|
|
|
{
|
|
|
|
"Local IP address for lokinet traffic.",
|
|
|
|
});
|
2020-03-31 22:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
Config::generateBaseClientConfig(fs::path defaultDataDir)
|
|
|
|
{
|
|
|
|
ConfigGenParameters params;
|
|
|
|
params.isRelay = false;
|
|
|
|
params.defaultDataDir = std::move(defaultDataDir);
|
|
|
|
|
|
|
|
llarp::ConfigDefinition def;
|
|
|
|
initializeConfig(def, params);
|
|
|
|
generateCommonConfigComments(def);
|
2020-03-27 00:55:52 +00:00
|
|
|
|
2020-03-30 16:25:02 +00:00
|
|
|
// snapp
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addSectionComments(
|
|
|
|
"snapp",
|
|
|
|
{
|
|
|
|
"Snapp settings",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"snapp",
|
|
|
|
"keyfile",
|
|
|
|
{
|
|
|
|
"The private key to persist address with. If not specified the address will be",
|
|
|
|
"ephemeral.",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
|
|
|
// TODO: is this redundant with / should be merged with basic client config?
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"snapp",
|
|
|
|
"reachable",
|
|
|
|
{
|
|
|
|
"Determines whether we will publish our snapp's introset to the DHT.",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
|
|
|
// TODO: merge with client conf?
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"snapp",
|
|
|
|
"hops",
|
|
|
|
{
|
|
|
|
"Number of hops in a path. Min 1, max 8.",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
|
|
|
// TODO: is this actually different than client's paths min/max config?
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"snapp",
|
|
|
|
"paths",
|
|
|
|
{
|
|
|
|
"Number of paths to maintain at any given time.",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"snapp",
|
|
|
|
"blacklist-snode",
|
|
|
|
{
|
|
|
|
"Adds a `.snode` address to the blacklist.",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"snapp",
|
|
|
|
"exit-node",
|
|
|
|
{
|
|
|
|
"Specify a `.snode` or `.loki` address to use as an exit broker.",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
|
|
|
// TODO: merge with client conf?
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"snapp",
|
|
|
|
"local-dns",
|
|
|
|
{
|
|
|
|
"Address to bind local DNS resolver to. Ex: `127.3.2.1:53`. Iif port is omitted, port",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"snapp",
|
|
|
|
"upstream-dns",
|
|
|
|
{
|
|
|
|
"Address to forward non-lokinet related queries to. If not set, lokinet DNS will reply",
|
|
|
|
"with `srvfail`.",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"snapp",
|
|
|
|
"mapaddr",
|
|
|
|
{
|
|
|
|
"Permanently map a `.loki` address to an IP owned by the snapp. Example:",
|
|
|
|
"mapaddr=whatever.loki:10.0.10.10 # maps `whatever.loki` to `10.0.10.10`.",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-03-25 22:41:22 +00:00
|
|
|
return def.generateINIConfig(true);
|
2019-07-02 21:28:28 +00:00
|
|
|
}
|
2020-03-23 20:53:42 +00:00
|
|
|
|
|
|
|
std::string
|
2020-03-27 21:39:40 +00:00
|
|
|
Config::generateBaseRouterConfig(fs::path defaultDataDir)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-03-27 21:39:40 +00:00
|
|
|
ConfigGenParameters params;
|
|
|
|
params.isRelay = true;
|
|
|
|
params.defaultDataDir = std::move(defaultDataDir);
|
|
|
|
|
2020-03-31 17:33:36 +00:00
|
|
|
llarp::ConfigDefinition def;
|
2020-03-27 21:39:40 +00:00
|
|
|
initializeConfig(def, params);
|
2020-03-31 22:07:17 +00:00
|
|
|
generateCommonConfigComments(def);
|
2020-03-23 20:53:42 +00:00
|
|
|
|
2020-03-27 00:55:52 +00:00
|
|
|
// lokid
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addSectionComments(
|
|
|
|
"lokid",
|
|
|
|
{
|
|
|
|
"Lokid configuration (settings for talking to lokid",
|
|
|
|
});
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"lokid",
|
|
|
|
"enabled",
|
|
|
|
{
|
|
|
|
"Whether or not we should talk to lokid. Must be enabled for staked routers.",
|
|
|
|
});
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"lokid",
|
|
|
|
"jsonrpc",
|
|
|
|
{
|
|
|
|
"Host and port of running lokid that we should talk to.",
|
|
|
|
});
|
2020-03-23 20:53:42 +00:00
|
|
|
|
2020-03-27 00:55:52 +00:00
|
|
|
// TODO: doesn't appear to be used in the codebase
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"lokid",
|
|
|
|
"service-node-seed",
|
|
|
|
{
|
|
|
|
"File containing service node's seed.",
|
|
|
|
});
|
2020-03-23 20:53:42 +00:00
|
|
|
|
2020-03-27 00:55:52 +00:00
|
|
|
// extra [network] options
|
|
|
|
// TODO: probably better to create an [exit] section and only allow it for routers
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"exit",
|
|
|
|
{
|
|
|
|
"Whether or not we should act as an exit node. Beware that this increases demand",
|
|
|
|
"on the server and may pose liability concerns. Enable at your own risk.",
|
|
|
|
});
|
2020-03-27 00:55:52 +00:00
|
|
|
|
|
|
|
// TODO: define the order of precedence (e.g. is whitelist applied before blacklist?)
|
|
|
|
// additionally, what's default? What if I don't whitelist anything?
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"exit-whitelist",
|
|
|
|
{
|
|
|
|
"List of destination protocol:port pairs to whitelist, example: udp:*",
|
|
|
|
"or tcp:80. Multiple values supported.",
|
|
|
|
});
|
2020-03-27 00:55:52 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"exit-blacklist",
|
|
|
|
{
|
|
|
|
"Blacklist of destinations (same format as whitelist).",
|
|
|
|
});
|
2020-03-27 00:55:52 +00:00
|
|
|
|
|
|
|
return def.generateINIConfig(true);
|
2019-08-26 23:29:17 +00:00
|
|
|
}
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-03-27 00:55:52 +00:00
|
|
|
} // namespace llarp
|