2020-04-20 20:36:42 +00:00
|
|
|
#include <chrono>
|
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>
|
2020-05-21 14:18:23 +00:00
|
|
|
#include <net/ip.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-07-13 15:13:10 +00:00
|
|
|
#include <cstdlib>
|
2019-07-02 21:28:28 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <ios>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
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-05-04 17:14:46 +00:00
|
|
|
conf.defineOption<fs::path>(
|
|
|
|
"router", "data-dir", false, params.defaultDataDir, [this](fs::path arg) {
|
|
|
|
if (not fs::exists(arg))
|
2020-04-07 20:41:11 +00:00
|
|
|
throw std::runtime_error(
|
|
|
|
stringify("Specified [router]:data-dir ", arg, " does not exist"));
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-05-04 17:14:46 +00:00
|
|
|
m_dataDir = std::move(arg);
|
2020-04-07 20:41:11 +00:00
|
|
|
});
|
2020-03-31 22:33:26 +00:00
|
|
|
|
2020-10-02 18:47:14 +00:00
|
|
|
conf.defineOption<std::string>("router", "public-ip", false, "", [this](std::string arg) {
|
2020-04-07 20:41:11 +00:00
|
|
|
if (not arg.empty())
|
|
|
|
{
|
|
|
|
llarp::LogInfo("public ip ", arg, " size ", arg.size());
|
2020-03-31 22:33:26 +00:00
|
|
|
|
2020-10-02 18:47:14 +00:00
|
|
|
if (arg.size() > 15)
|
|
|
|
throw std::invalid_argument(stringify("Not a valid IPv4 addr: ", arg));
|
|
|
|
|
|
|
|
m_publicAddress.setAddress(arg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
conf.defineOption<std::string>("router", "public-address", false, "", [this](std::string arg) {
|
|
|
|
if (not arg.empty())
|
|
|
|
{
|
2020-10-02 19:50:20 +00:00
|
|
|
llarp::LogWarn(
|
|
|
|
"*** WARNING: The config option [router]:public-address=",
|
|
|
|
arg,
|
|
|
|
" is deprecated, use public-ip=",
|
|
|
|
arg,
|
|
|
|
" instead.");
|
2020-10-02 18:47:14 +00:00
|
|
|
|
|
|
|
if (arg.size() > 15)
|
2020-04-07 20:41:11 +00:00
|
|
|
throw std::invalid_argument(stringify("Not a valid IPv4 addr: ", arg));
|
2020-03-31 22:33:26 +00:00
|
|
|
|
2020-05-06 20:38:44 +00:00
|
|
|
m_publicAddress.setAddress(arg);
|
2020-04-07 20:41:11 +00:00
|
|
|
}
|
|
|
|
});
|
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) {
|
2020-05-06 20:38:44 +00:00
|
|
|
if (arg <= 0 || arg > std::numeric_limits<uint16_t>::max())
|
|
|
|
throw std::invalid_argument("public-port must be >= 0 and <= 65536");
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-05-06 20:38:44 +00:00
|
|
|
m_publicAddress.setPort(arg);
|
2020-04-07 20:41:11 +00:00
|
|
|
});
|
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));
|
2020-04-29 19:41:39 +00:00
|
|
|
|
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"router", "contact-file", false, "", AssignmentAcceptor(m_routerContactFile));
|
|
|
|
|
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"router", "encryption-privkey", false, "", AssignmentAcceptor(m_encryptionKeyFile));
|
|
|
|
|
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"router", "ident-privkey", false, "", AssignmentAcceptor(m_identityKeyFile));
|
|
|
|
|
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"router", "transport-privkey", false, "", AssignmentAcceptor(m_transportKeyFile));
|
2020-05-26 17:03:21 +00:00
|
|
|
|
2020-08-20 14:20:29 +00:00
|
|
|
conf.defineOption<bool>(
|
|
|
|
"router",
|
|
|
|
"enable-peer-stats",
|
|
|
|
false,
|
2020-10-02 09:48:08 +00:00
|
|
|
params.isRelay,
|
2020-08-20 14:20:29 +00:00
|
|
|
AssignmentAcceptor(m_enablePeerStats));
|
|
|
|
m_isRelay = params.isRelay;
|
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-09-14 22:19:17 +00:00
|
|
|
static constexpr bool ReachableDefault = true;
|
2020-04-30 22:11:05 +00:00
|
|
|
static constexpr int HopsDefault = 4;
|
|
|
|
static constexpr int PathsDefault = 6;
|
2020-03-31 15:51:24 +00:00
|
|
|
|
2020-05-06 14:45:30 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"network", "type", false, "tun", AssignmentAcceptor(m_endpointType));
|
|
|
|
|
2020-05-21 14:18:23 +00:00
|
|
|
conf.defineOption<bool>("network", "exit", false, false, AssignmentAcceptor(m_AllowExit));
|
|
|
|
|
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-04-30 22:11:05 +00:00
|
|
|
|
2020-05-14 17:51:27 +00:00
|
|
|
conf.defineOption<std::string>("network", "keyfile", false, "", AssignmentAcceptor(m_keyfile));
|
2020-04-30 22:11:05 +00:00
|
|
|
|
2020-06-30 16:02:29 +00:00
|
|
|
conf.defineOption<std::string>("network", "auth", false, "", [this](std::string arg) {
|
|
|
|
if (arg.empty())
|
|
|
|
return;
|
|
|
|
m_AuthType = service::ParseAuthType(arg);
|
|
|
|
});
|
2020-06-02 21:10:42 +00:00
|
|
|
|
2020-06-30 16:02:29 +00:00
|
|
|
conf.defineOption<std::string>("network", "auth-lmq", false, "", AssignmentAcceptor(m_AuthUrl));
|
2020-06-05 19:01:42 +00:00
|
|
|
|
|
|
|
conf.defineOption<std::string>(
|
2020-06-30 16:02:29 +00:00
|
|
|
"network", "auth-lmq-method", false, "llarp.auth", [this](std::string arg) {
|
2020-06-05 19:01:42 +00:00
|
|
|
if (arg.empty())
|
|
|
|
return;
|
|
|
|
m_AuthMethod = std::move(arg);
|
|
|
|
});
|
|
|
|
|
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"network", "auth-whitelist", false, true, "", [this](std::string arg) {
|
|
|
|
service::Address addr;
|
|
|
|
if (not addr.FromString(arg))
|
|
|
|
throw std::invalid_argument(stringify("bad loki address: ", arg));
|
|
|
|
m_AuthWhitelist.emplace(std::move(addr));
|
|
|
|
});
|
2020-06-02 21:10:42 +00:00
|
|
|
|
2020-04-30 22:11:05 +00:00
|
|
|
conf.defineOption<bool>(
|
|
|
|
"network", "reachable", false, ReachableDefault, AssignmentAcceptor(m_reachable));
|
|
|
|
|
2020-05-21 14:18:23 +00:00
|
|
|
conf.defineOption<int>("network", "hops", false, HopsDefault, [this](int arg) {
|
2020-04-30 22:11:05 +00:00
|
|
|
if (arg < 1 or arg > 8)
|
|
|
|
throw std::invalid_argument("[endpoint]:hops must be >= 1 and <= 8");
|
2020-06-08 12:42:10 +00:00
|
|
|
m_Hops = arg;
|
2020-04-30 22:11:05 +00:00
|
|
|
});
|
|
|
|
|
2020-05-21 14:18:23 +00:00
|
|
|
conf.defineOption<int>("network", "paths", false, PathsDefault, [this](int arg) {
|
2020-06-02 13:30:21 +00:00
|
|
|
if (arg < 2 or arg > 8)
|
|
|
|
throw std::invalid_argument("[endpoint]:paths must be >= 2 and <= 8");
|
2020-06-08 12:42:10 +00:00
|
|
|
m_Paths = arg;
|
2020-04-30 22:11:05 +00:00
|
|
|
});
|
|
|
|
|
2020-08-27 11:12:56 +00:00
|
|
|
conf.defineOption<std::string>("network", "exit-auth", false, "", [this](std::string arg) {
|
|
|
|
if (arg.empty())
|
|
|
|
return;
|
|
|
|
service::Address exit;
|
|
|
|
service::AuthInfo auth;
|
|
|
|
const auto pos = arg.find(":");
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
{
|
|
|
|
throw std::invalid_argument(
|
|
|
|
"[network]:exit-auth invalid format, expects exit-address.loki:auth-code-goes-here");
|
|
|
|
}
|
|
|
|
const auto exit_str = arg.substr(0, pos);
|
|
|
|
auth.token = arg.substr(pos + 1);
|
|
|
|
if (not exit.FromString(exit_str))
|
|
|
|
{
|
|
|
|
throw std::invalid_argument("[network]:exit-auth invalid exit address");
|
|
|
|
}
|
|
|
|
m_ExitAuths.emplace(exit, auth);
|
|
|
|
});
|
|
|
|
|
2020-04-30 22:11:05 +00:00
|
|
|
conf.defineOption<std::string>("network", "exit-node", false, "", [this](std::string arg) {
|
2020-05-21 14:18:23 +00:00
|
|
|
if (arg.empty())
|
|
|
|
return;
|
|
|
|
service::Address exit;
|
2020-06-24 13:24:07 +00:00
|
|
|
IPRange range;
|
|
|
|
const auto pos = arg.find(":");
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
{
|
|
|
|
range.FromString("0.0.0.0/0");
|
|
|
|
}
|
|
|
|
else if (not range.FromString(arg.substr(pos + 1)))
|
|
|
|
{
|
|
|
|
throw std::invalid_argument("[network]:exit-node invalid ip range for exit provided");
|
|
|
|
}
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
|
|
|
arg = arg.substr(0, pos);
|
|
|
|
}
|
2020-05-21 14:18:23 +00:00
|
|
|
if (not exit.FromString(arg))
|
|
|
|
{
|
2020-06-24 13:24:07 +00:00
|
|
|
throw std::invalid_argument(stringify("[network]:exit-node bad address: ", arg));
|
2020-05-21 14:18:23 +00:00
|
|
|
}
|
2020-06-24 13:24:07 +00:00
|
|
|
m_ExitMap.Insert(range, exit);
|
2020-04-30 22:11:05 +00:00
|
|
|
});
|
|
|
|
|
2020-06-02 21:10:42 +00:00
|
|
|
conf.defineOption<std::string>("network", "mapaddr", false, true, "", [this](std::string arg) {
|
2020-05-21 14:18:23 +00:00
|
|
|
if (arg.empty())
|
|
|
|
return;
|
|
|
|
huint128_t ip;
|
|
|
|
service::Address addr;
|
|
|
|
const auto pos = arg.find(":");
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
{
|
|
|
|
throw std::invalid_argument(stringify("[endpoint]:mapaddr invalid entry: ", arg));
|
|
|
|
}
|
|
|
|
std::string addrstr = arg.substr(0, pos);
|
|
|
|
std::string ipstr = arg.substr(pos + 1);
|
|
|
|
if (not ip.FromString(ipstr))
|
|
|
|
{
|
|
|
|
huint32_t ipv4;
|
|
|
|
if (not ipv4.FromString(ipstr))
|
|
|
|
{
|
|
|
|
throw std::invalid_argument(stringify("[endpoint]:mapaddr invalid ip: ", ipstr));
|
|
|
|
}
|
|
|
|
ip = net::ExpandV4(ipv4);
|
|
|
|
}
|
|
|
|
if (not addr.FromString(addrstr))
|
|
|
|
{
|
|
|
|
throw std::invalid_argument(stringify("[endpoint]:mapaddr invalid addresss: ", addrstr));
|
|
|
|
}
|
|
|
|
if (m_mapAddrs.find(ip) != m_mapAddrs.end())
|
|
|
|
{
|
|
|
|
throw std::invalid_argument(stringify("[endpoint]:mapaddr ip already mapped: ", ipstr));
|
|
|
|
}
|
|
|
|
m_mapAddrs[ip] = addr;
|
2020-04-30 22:11:05 +00:00
|
|
|
});
|
|
|
|
|
2020-05-04 16:51:57 +00:00
|
|
|
conf.defineOption<std::string>("network", "ifaddr", false, "", [this](std::string arg) {
|
|
|
|
if (arg.empty())
|
|
|
|
{
|
|
|
|
const auto maybe = llarp::FindFreeRange();
|
2020-05-20 19:46:08 +00:00
|
|
|
if (not maybe)
|
2020-05-04 16:51:57 +00:00
|
|
|
throw std::invalid_argument("cannot determine free ip range");
|
2020-06-24 13:24:07 +00:00
|
|
|
m_ifaddr = *maybe;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (not m_ifaddr.FromString(arg))
|
|
|
|
{
|
|
|
|
throw std::invalid_argument(stringify("[network]:ifaddr invalid value: ", arg));
|
2020-05-04 16:51:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
conf.defineOption<std::string>("network", "ifname", false, "", [this](std::string arg) {
|
|
|
|
if (arg.empty())
|
|
|
|
{
|
|
|
|
const auto maybe = llarp::FindFreeTun();
|
2020-05-20 19:46:08 +00:00
|
|
|
if (not maybe)
|
2020-05-04 16:51:57 +00:00
|
|
|
throw std::invalid_argument("cannot determine free interface name");
|
2020-05-20 19:46:08 +00:00
|
|
|
arg = *maybe;
|
2020-05-04 16:51:57 +00:00
|
|
|
}
|
|
|
|
m_ifname = arg;
|
|
|
|
});
|
2020-05-04 15:44:56 +00:00
|
|
|
|
2020-04-30 22:11:05 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"network", "blacklist-snode", false, true, "", [this](std::string arg) {
|
|
|
|
RouterID id;
|
|
|
|
if (not id.FromString(arg))
|
2020-05-04 16:02:28 +00:00
|
|
|
throw std::invalid_argument(stringify("Invalid RouterID: ", arg));
|
2020-04-30 22:11:05 +00:00
|
|
|
|
|
|
|
auto itr = m_snodeBlacklist.emplace(std::move(id));
|
2020-08-31 20:07:17 +00:00
|
|
|
if (not itr.second)
|
2020-04-30 22:11:05 +00:00
|
|
|
throw std::invalid_argument(stringify("Duplicate blacklist-snode: ", arg));
|
|
|
|
});
|
2020-08-31 20:07:17 +00:00
|
|
|
|
|
|
|
conf.defineOption<std::string>("network", "srv", false, true, "", [this](std::string arg) {
|
|
|
|
llarp::dns::SRVData newSRV;
|
|
|
|
if (not newSRV.fromString(arg))
|
|
|
|
throw std::invalid_argument(stringify("Invalid SRV Record string: ", arg));
|
|
|
|
|
|
|
|
m_SRVRecords.push_back(std::move(newSRV));
|
|
|
|
});
|
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-05-14 17:30:23 +00:00
|
|
|
auto parseDNSAddr = [](auto arg) {
|
2020-05-14 16:33:37 +00:00
|
|
|
IpAddress addr{arg};
|
2020-05-20 19:46:08 +00:00
|
|
|
if (not addr.getPort())
|
2020-05-14 16:33:37 +00:00
|
|
|
addr.setPort(53);
|
|
|
|
return addr;
|
|
|
|
};
|
2020-10-02 22:01:26 +00:00
|
|
|
|
|
|
|
constexpr auto DefaultUpstreamDNS = "1.1.1.1:53";
|
2020-10-02 22:02:03 +00:00
|
|
|
|
2020-04-30 20:05:05 +00:00
|
|
|
conf.defineOption<std::string>(
|
2020-10-02 22:01:26 +00:00
|
|
|
"dns", "upstream", false, true, DefaultUpstreamDNS, [=](std::string arg) {
|
2020-05-14 16:33:37 +00:00
|
|
|
m_upstreamDNS.push_back(parseDNSAddr(std::move(arg)));
|
2020-04-30 20:05:05 +00:00
|
|
|
});
|
2020-04-28 15:37:22 +00:00
|
|
|
|
2020-05-21 14:26:51 +00:00
|
|
|
conf.defineOption<std::string>("dns", "bind", false, "127.3.2.1:53", [=](std::string arg) {
|
2020-05-14 16:33:37 +00:00
|
|
|
m_bind = parseDNSAddr(std::move(arg));
|
2020-05-14 12:14:19 +00:00
|
|
|
});
|
2020-09-22 21:46:06 +00:00
|
|
|
|
|
|
|
// Ignored option (used by the systemd service file to disable resolvconf configuration).
|
|
|
|
conf.defineOption<bool>("dns", "no-resolvconf", false, false);
|
2019-07-02 21:28:28 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 16:15:00 +00:00
|
|
|
LinksConfig::LinkInfo
|
2020-05-01 19:51:15 +00:00
|
|
|
LinksConfig::LinkInfoFromINIValues(std::string_view name, std::string_view value)
|
2020-03-23 16:15:00 +00:00
|
|
|
{
|
|
|
|
// 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;
|
2020-04-29 20:23:50 +00:00
|
|
|
info.port = 0;
|
2020-03-23 16:15:00 +00:00
|
|
|
info.addressFamily = AF_INET;
|
|
|
|
|
2020-07-30 14:36:36 +00:00
|
|
|
if (name == "address")
|
2020-03-23 16:15:00 +00:00
|
|
|
{
|
2020-07-30 14:36:36 +00:00
|
|
|
const IpAddress addr{value};
|
|
|
|
if (not addr.hasPort())
|
|
|
|
throw std::invalid_argument("no port provided in link address");
|
2020-08-25 00:27:47 +00:00
|
|
|
info.interface = addr.toHost();
|
2020-07-30 14:36:36 +00:00
|
|
|
info.port = *addr.getPort();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info.interface = name;
|
2020-03-23 16:15:00 +00:00
|
|
|
|
2020-07-30 14:36:36 +00:00
|
|
|
std::vector<std::string_view> splits = split(value, ',');
|
|
|
|
for (std::string_view str : splits)
|
|
|
|
{
|
|
|
|
int asNum = std::atoi(str.data());
|
|
|
|
if (asNum > 0)
|
|
|
|
info.port = asNum;
|
|
|
|
|
|
|
|
// otherwise, ignore ("future-proofing")
|
|
|
|
}
|
2020-03-23 16:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-04-29 20:19:35 +00:00
|
|
|
constexpr auto DefaultOutboundLinkValue = "0";
|
2020-04-24 17:10:05 +00:00
|
|
|
|
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"bind", "*", false, false, DefaultOutboundLinkValue, [this](std::string arg) {
|
2020-05-01 19:51:15 +00:00
|
|
|
m_OutboundLink = LinkInfoFromINIValues("*", arg);
|
2020-04-24 17:10:05 +00:00
|
|
|
});
|
|
|
|
|
2020-05-01 22:25:18 +00:00
|
|
|
conf.addUndeclaredHandler(
|
|
|
|
"bind", [&](std::string_view, std::string_view name, std::string_view value) {
|
|
|
|
LinkInfo info = LinkInfoFromINIValues(name, value);
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-05-01 22:25:18 +00:00
|
|
|
if (info.port <= 0)
|
|
|
|
throw std::invalid_argument(
|
|
|
|
stringify("Invalid [bind] port specified on interface", name));
|
2020-03-23 16:15:00 +00:00
|
|
|
|
2020-05-01 22:25:18 +00:00
|
|
|
assert(name != "*"); // handled by defineOption("bind", "*", ...) above
|
2020-04-24 17:10:05 +00:00
|
|
|
|
2020-05-01 22:25:18 +00:00
|
|
|
m_InboundLinks.emplace_back(std::move(info));
|
|
|
|
});
|
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(
|
2020-05-01 19:51:15 +00:00
|
|
|
"connect", [this](std::string_view section, std::string_view name, std::string_view value) {
|
2020-05-21 20:21:04 +00:00
|
|
|
fs::path file{value.begin(), value.end()};
|
2020-04-07 20:41:11 +00:00
|
|
|
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
|
|
|
ApiConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params)
|
2019-07-02 21:28:28 +00:00
|
|
|
{
|
2020-06-12 13:28:31 +00:00
|
|
|
constexpr auto DefaultRPCBindAddr = "tcp://127.0.0.1:1190";
|
2020-03-31 15:51:24 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<bool>(
|
2020-10-02 20:54:31 +00:00
|
|
|
"api", "enabled", false, not params.isRelay, AssignmentAcceptor(m_enableRPCServer));
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
conf.defineOption<std::string>(
|
2020-08-13 13:47:35 +00:00
|
|
|
"api", "bind", false, DefaultRPCBindAddr, [this](std::string arg) {
|
|
|
|
if (arg.empty())
|
|
|
|
{
|
|
|
|
arg = DefaultRPCBindAddr;
|
|
|
|
}
|
|
|
|
if (arg.find("://") == std::string::npos)
|
|
|
|
{
|
|
|
|
arg = "tcp://" + arg;
|
|
|
|
}
|
|
|
|
m_rpcBindAddr = std::move(arg);
|
|
|
|
});
|
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-06-12 13:28:31 +00:00
|
|
|
constexpr auto DefaultLokidRPCAddr = "tcp://127.0.0.1:22023";
|
2020-03-31 15:51:24 +00:00
|
|
|
|
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>(
|
2020-10-02 09:48:08 +00:00
|
|
|
"lokid", "enabled", false, params.isRelay, AssignmentAcceptor(whitelistRouters));
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-07-01 12:12:17 +00:00
|
|
|
conf.defineOption<std::string>("lokid", "jsonrpc", false, "", [](std::string arg) {
|
|
|
|
if (arg.empty())
|
|
|
|
return;
|
|
|
|
throw std::invalid_argument(
|
|
|
|
"the [lokid]::jsonrpc option is deprecated please use the "
|
|
|
|
"[lokid]::rpc "
|
|
|
|
"config option instead");
|
|
|
|
});
|
2020-03-18 18:24:23 +00:00
|
|
|
|
2020-06-30 18:08:19 +00:00
|
|
|
conf.defineOption<std::string>(
|
|
|
|
"lokid", "rpc", false, DefaultLokidRPCAddr, [this](std::string arg) {
|
|
|
|
lokidRPCAddr = lokimq::address(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
|
|
|
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) {
|
2020-06-08 12:42:10 +00:00
|
|
|
if (arg.empty())
|
|
|
|
{
|
|
|
|
throw std::invalid_argument("cannot use empty filename as bootstrap");
|
|
|
|
}
|
2020-04-07 20:41:11 +00:00
|
|
|
routers.emplace_back(std::move(arg));
|
2020-06-08 12:42:10 +00:00
|
|
|
if (not fs::exists(routers.back()))
|
|
|
|
{
|
|
|
|
throw std::invalid_argument("file does not exist: " + arg);
|
|
|
|
}
|
2020-04-07 20:41:11 +00:00
|
|
|
});
|
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) {
|
2020-05-01 19:51:15 +00:00
|
|
|
std::optional<LogLevel> level = LogLevelFromString(arg);
|
2020-05-20 19:46:08 +00:00
|
|
|
if (not level)
|
2020-04-07 20:41:11 +00:00
|
|
|
throw std::invalid_argument(stringify("invalid log level value: ", arg));
|
2020-03-19 21:51:22 +00:00
|
|
|
|
2020-05-20 19:46:08 +00:00
|
|
|
m_logLevel = *level;
|
2020-04-07 20:41:11 +00:00
|
|
|
});
|
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-08-27 12:43:53 +00:00
|
|
|
void
|
2020-09-29 13:26:45 +00:00
|
|
|
Config::Save()
|
2020-08-27 12:43:53 +00:00
|
|
|
{
|
|
|
|
m_Parser.Save();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Config::Override(std::string section, std::string key, std::string value)
|
|
|
|
{
|
|
|
|
m_Parser.AddOverride(std::move(section), std::move(key), std::move(value));
|
|
|
|
}
|
|
|
|
|
2020-03-19 20:07:56 +00:00
|
|
|
bool
|
2020-06-08 12:42:10 +00:00
|
|
|
Config::Load(const fs::path 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);
|
2020-04-29 16:47:51 +00:00
|
|
|
addBackwardsCompatibleConfigOptions(conf);
|
2020-08-27 12:43:53 +00:00
|
|
|
m_Parser.Clear();
|
|
|
|
if (!m_Parser.LoadFile(fname))
|
2020-03-19 20:07:56 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-02 21:28:28 +00:00
|
|
|
|
2020-08-27 12:43:53 +00:00
|
|
|
m_Parser.IterAll([&](std::string_view section, const SectionValues_t& values) {
|
2020-03-19 20:07:56 +00:00
|
|
|
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-04-24 17:10:05 +00:00
|
|
|
bool
|
|
|
|
Config::LoadDefault(bool isRelay, fs::path dataDir)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ConfigGenParameters params;
|
|
|
|
params.isRelay = isRelay;
|
|
|
|
params.defaultDataDir = std::move(dataDir);
|
|
|
|
|
|
|
|
ConfigDefinition conf;
|
|
|
|
initializeConfig(conf, params);
|
|
|
|
|
|
|
|
conf.acceptAllOptions();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
LogError("Error trying to init default config: ", e.what());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-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);
|
|
|
|
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-04-29 16:47:51 +00:00
|
|
|
void
|
|
|
|
Config::addBackwardsCompatibleConfigOptions(ConfigDefinition& conf)
|
|
|
|
{
|
|
|
|
auto addIgnoreOption = [&](const std::string& section, const std::string& name) {
|
|
|
|
conf.defineOption<std::string>(section, name, false, true, "", [=](std::string arg) {
|
|
|
|
(void)arg;
|
|
|
|
LogWarn("*** WARNING: The config option [", section, "]:", name, " is deprecated");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
addIgnoreOption("system", "user");
|
|
|
|
addIgnoreOption("system", "group");
|
|
|
|
addIgnoreOption("system", "pidfile");
|
|
|
|
|
|
|
|
addIgnoreOption("api", "authkey");
|
2020-04-29 19:42:06 +00:00
|
|
|
|
|
|
|
addIgnoreOption("netdb", "dir");
|
|
|
|
|
|
|
|
// these weren't even ever used!
|
|
|
|
addIgnoreOption("router", "max-routers");
|
|
|
|
addIgnoreOption("router", "min-routers");
|
|
|
|
|
|
|
|
// TODO: this may have been a synonym for [router]worker-threads
|
|
|
|
addIgnoreOption("router", "threads");
|
|
|
|
|
|
|
|
addIgnoreOption("metrics", "json-metrics-path");
|
2020-05-04 16:02:28 +00:00
|
|
|
|
|
|
|
addIgnoreOption("network", "enabled");
|
2020-06-30 16:38:08 +00:00
|
|
|
|
|
|
|
addIgnoreOption("lokid", "username");
|
|
|
|
addIgnoreOption("lokid", "password");
|
2020-04-29 16:47:51 +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-05-20 19:46:08 +00:00
|
|
|
if (not stream or not stream->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-05-20 19:46:08 +00:00
|
|
|
*stream << confStr;
|
|
|
|
stream->flush();
|
2020-03-23 20:53:42 +00:00
|
|
|
|
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
|
|
|
|
2020-10-02 18:47:14 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"router",
|
|
|
|
"public-ip",
|
|
|
|
{
|
|
|
|
"For complex network configurations where the detected IP is incorrect or non-public",
|
|
|
|
"this setting specifies the public IP at which this router is reachable. When",
|
2020-10-02 19:50:20 +00:00
|
|
|
"provided the public-port option must also be specified.",
|
2020-10-02 18:47:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
def.addOptionComments(
|
|
|
|
"router",
|
|
|
|
"public-port",
|
|
|
|
{
|
|
|
|
"When specifying public-ip=, this specifies the public UDP port at which this lokinet",
|
|
|
|
"router is reachable. Required when public-ip is used.",
|
|
|
|
});
|
|
|
|
|
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",
|
2020-09-22 21:46:06 +00:00
|
|
|
"upstream",
|
2020-04-07 20:41:11 +00:00
|
|
|
{
|
2020-04-28 15:37:22 +00:00
|
|
|
"Upstream resolver(s) to use as fallback for non-loki addresses.",
|
2020-04-07 20:41:11 +00:00
|
|
|
"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
|
|
|
|
2020-09-22 21:46:06 +00:00
|
|
|
def.addOptionComments(
|
|
|
|
"dns",
|
|
|
|
"no-resolvconf",
|
|
|
|
{
|
|
|
|
"Can be uncommented and set to 1 to disable resolvconf configuration of lokinet DNS.",
|
|
|
|
"(This is not used directly by lokinet itself, but by the lokinet init scripts",
|
|
|
|
"on systems which use resolveconf)",
|
|
|
|
});
|
|
|
|
|
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-04-07 20:41:11 +00:00
|
|
|
def.addSectionComments(
|
2020-04-30 22:11:05 +00:00
|
|
|
"network",
|
2020-04-07 20:41:11 +00:00
|
|
|
{
|
|
|
|
"Snapp settings",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
2020-04-30 22:11:05 +00:00
|
|
|
"network",
|
2020-04-07 20:41:11 +00:00
|
|
|
"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(
|
2020-04-30 22:11:05 +00:00
|
|
|
"network",
|
2020-04-07 20:41:11 +00:00
|
|
|
"reachable",
|
|
|
|
{
|
|
|
|
"Determines whether we will publish our snapp's introset to the DHT.",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
2020-04-30 22:11:05 +00:00
|
|
|
"network",
|
2020-04-07 20:41:11 +00:00
|
|
|
"hops",
|
|
|
|
{
|
|
|
|
"Number of hops in a path. Min 1, max 8.",
|
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
2020-04-30 22:11:05 +00:00
|
|
|
"network",
|
2020-04-07 20:41:11 +00:00
|
|
|
"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(
|
2020-04-30 22:11:05 +00:00
|
|
|
"network",
|
2020-04-07 20:41:11 +00:00
|
|
|
"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(
|
2020-04-30 22:11:05 +00:00
|
|
|
"network",
|
2020-04-07 20:41:11 +00:00
|
|
|
"exit-node",
|
|
|
|
{
|
2020-06-30 16:02:29 +00:00
|
|
|
"Specify a `.loki` address and an optional ip range to use as an exit broker.",
|
|
|
|
"Example:",
|
|
|
|
"exit-node=whatever.loki # maps all exit traffic to whatever.loki",
|
|
|
|
"exit-node=stuff.loki:100.0.0.0/24 # maps 100.0.0.0/24 to stuff.loki",
|
2020-04-07 20:41:11 +00:00
|
|
|
});
|
2020-03-30 16:25:02 +00:00
|
|
|
|
2020-04-07 20:41:11 +00:00
|
|
|
def.addOptionComments(
|
2020-04-30 22:11:05 +00:00
|
|
|
"network",
|
2020-04-07 20:41:11 +00:00
|
|
|
"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-06-05 19:01:42 +00:00
|
|
|
// extra [network] options
|
|
|
|
// TODO: probably better to create an [exit] section and only allow it for routers
|
|
|
|
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.",
|
|
|
|
});
|
|
|
|
|
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"auth",
|
|
|
|
{
|
2020-06-30 16:02:29 +00:00
|
|
|
"Set the endpoint authentication mechanism.",
|
|
|
|
"none/whitelist/lmq",
|
2020-06-05 19:01:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
2020-06-30 16:02:29 +00:00
|
|
|
"auth-lmq",
|
2020-06-05 19:01:42 +00:00
|
|
|
{
|
|
|
|
"lmq endpoint to talk to for authenticating new sessions",
|
|
|
|
"ipc:///var/lib/lokinet/auth.socket",
|
2020-06-30 16:02:29 +00:00
|
|
|
"tcp://127.0.0.1:5555",
|
2020-06-05 19:01:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
2020-06-30 16:02:29 +00:00
|
|
|
"auth-lmq-method",
|
2020-06-05 19:01:42 +00:00
|
|
|
{
|
|
|
|
"lmq function to call for authenticating new sessions",
|
|
|
|
"llarp.auth",
|
|
|
|
});
|
|
|
|
|
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"auth-whitelist",
|
|
|
|
{
|
|
|
|
"manually add a remote endpoint by .loki address to the access whitelist",
|
|
|
|
});
|
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",
|
2020-06-30 16:38:08 +00:00
|
|
|
"rpc",
|
2020-04-07 20:41:11 +00:00
|
|
|
{
|
2020-06-30 16:38:08 +00:00
|
|
|
"Host and port of running lokid's rpc that we should talk to.",
|
2020-04-07 20:41:11 +00:00
|
|
|
});
|
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-05-26 17:03:21 +00:00
|
|
|
// extra [network] options
|
|
|
|
// TODO: probably better to create an [exit] section and only allow it for routers
|
|
|
|
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.",
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: define the order of precedence (e.g. is whitelist applied before blacklist?)
|
|
|
|
// additionally, what's default? What if I don't whitelist anything?
|
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"exit-whitelist",
|
|
|
|
{
|
|
|
|
"List of destination protocol:port pairs to whitelist, example: udp:*",
|
|
|
|
"or tcp:80. Multiple values supported.",
|
|
|
|
});
|
|
|
|
|
|
|
|
def.addOptionComments(
|
|
|
|
"network",
|
|
|
|
"exit-blacklist",
|
|
|
|
{
|
|
|
|
"Blacklist of destinations (same format as whitelist).",
|
|
|
|
});
|
|
|
|
|
|
|
|
def.addOptionComments(
|
|
|
|
"router",
|
|
|
|
"enable-peer-stats",
|
|
|
|
{
|
|
|
|
"Enable collection of SNode peer stats",
|
|
|
|
});
|
|
|
|
|
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
|