mirror of https://github.com/oxen-io/lokinet
Fixup and add tests
This commit is contained in:
parent
2acb163083
commit
f310160065
|
@ -21,19 +21,8 @@ namespace llarp
|
|||
{
|
||||
if(key == "netid")
|
||||
{
|
||||
if(val.size() <= rc.netID.size())
|
||||
if(val.size() <= NetID::size())
|
||||
{
|
||||
llarp::LogWarn("!!!! you have manually set netid to be '", val,
|
||||
"' which does not equal '", Version::LLARP_NET_ID,
|
||||
"' you will run as a different network, good luck "
|
||||
"and "
|
||||
"don't forget: something something MUH traffic "
|
||||
"shape "
|
||||
"correlation !!!!");
|
||||
NetID::DefaultValue() =
|
||||
NetID(reinterpret_cast< const byte_t * >(std::string(val).c_str()));
|
||||
// re set netid in our rc
|
||||
rc.netID = llarp::NetID();
|
||||
netid.assign(val.begin(), val.end());
|
||||
}
|
||||
else
|
||||
|
@ -63,9 +52,9 @@ namespace llarp
|
|||
}
|
||||
if(key == "nickname")
|
||||
{
|
||||
rc.SetNick(val);
|
||||
nickname.assign(val.begin(), val.end());
|
||||
// set logger name here
|
||||
LogContext::Instance().nodeName = rc.Nick();
|
||||
LogContext::Instance().nodeName = nickname;
|
||||
}
|
||||
if(key == "encryption-privkey")
|
||||
{
|
||||
|
@ -94,14 +83,12 @@ namespace llarp
|
|||
addrInfo.ip = *a.addr6();
|
||||
publicOverride = true;
|
||||
}
|
||||
// llarp::Addr a(val);
|
||||
}
|
||||
if(key == "public-port")
|
||||
{
|
||||
llarp::LogInfo("Setting public port ", val);
|
||||
int p = atoi(std::string(val).c_str());
|
||||
// Not needed to flip upside-down - this is done in llarp::Addr(const
|
||||
// AddressInfo&)
|
||||
// Not needed to flip upside-down this is done in Addr(const AddressInfo&)
|
||||
ip4addr.sin_port = p;
|
||||
addrInfo.port = p;
|
||||
publicOverride = true;
|
||||
|
@ -412,6 +399,25 @@ namespace llarp
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return parse(parser);
|
||||
}
|
||||
|
||||
bool
|
||||
Config::LoadFromString(string_view str)
|
||||
{
|
||||
ConfigParser parser;
|
||||
if(!parser.LoadString(str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return parse(parser);
|
||||
}
|
||||
|
||||
bool
|
||||
Config::parse(const ConfigParser &parser)
|
||||
{
|
||||
router = find_section< RouterConfig >(parser, "router");
|
||||
network = find_section< NetworkConfig >(parser, "network");
|
||||
connect = find_section< ConnectConfig >(parser, "connect");
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef LLARP_CONFIG_HPP
|
||||
#define LLARP_CONFIG_HPP
|
||||
|
||||
#include <config/ini.hpp>
|
||||
#include <crypto/types.hpp>
|
||||
#include <router_contact.hpp>
|
||||
#include <util/fs.hpp>
|
||||
|
@ -13,6 +12,8 @@
|
|||
|
||||
namespace llarp
|
||||
{
|
||||
struct ConfigParser;
|
||||
|
||||
struct RouterConfig
|
||||
{
|
||||
/// always maintain this many connections to other routers
|
||||
|
@ -22,7 +23,7 @@ namespace llarp
|
|||
size_t maxConnectedRouters = 2000;
|
||||
|
||||
std::string netid;
|
||||
RouterContact rc;
|
||||
std::string nickname;
|
||||
|
||||
fs::path encryption_keyfile = "encryption.key";
|
||||
|
||||
|
@ -120,8 +121,8 @@ namespace llarp
|
|||
|
||||
struct ApiConfig
|
||||
{
|
||||
bool enableRPCServer = false;
|
||||
std::string rpcBindAddr;
|
||||
bool enableRPCServer = false;
|
||||
std::string rpcBindAddr = "127.0.0.1:1190";
|
||||
|
||||
bool
|
||||
fromSection(string_view key, string_view val);
|
||||
|
@ -158,6 +159,11 @@ namespace llarp
|
|||
|
||||
struct Config
|
||||
{
|
||||
private:
|
||||
bool
|
||||
parse(const ConfigParser &parser);
|
||||
|
||||
public:
|
||||
RouterConfig router;
|
||||
NetworkConfig network;
|
||||
ConnectConfig connect;
|
||||
|
@ -174,6 +180,9 @@ namespace llarp
|
|||
|
||||
bool
|
||||
Load(const char *fname);
|
||||
|
||||
bool
|
||||
LoadFromString(string_view str);
|
||||
};
|
||||
|
||||
} // namespace llarp
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace llarp
|
|||
auto &metricsConfig = config->metrics;
|
||||
auto &tags = metricsConfig.metricTags;
|
||||
tags["netid"] = config->router.netid;
|
||||
tags["nickname"] = config->router.rc.Nick();
|
||||
tags["nickname"] = config->router.nickname;
|
||||
setupMetrics(metricsConfig);
|
||||
if(!config->metrics.disableMetricLogs)
|
||||
{
|
||||
|
|
|
@ -848,7 +848,6 @@ namespace llarp
|
|||
llarp::LogError("invalid key for strict-connect: ", val);
|
||||
}
|
||||
|
||||
|
||||
// API config
|
||||
enableRPCServer = conf->api.enableRPCServer;
|
||||
rpcBindAddr = conf->api.rpcBindAddr;
|
||||
|
@ -928,7 +927,21 @@ namespace llarp
|
|||
}
|
||||
|
||||
// Router config
|
||||
_rc = conf->router.rc;
|
||||
if(!conf->router.netid.empty())
|
||||
{
|
||||
const auto &netid = conf->router.netid;
|
||||
llarp::LogWarn("!!!! you have manually set netid to be '", netid,
|
||||
"' which does not equal '", Version::LLARP_NET_ID,
|
||||
"' you will run as a different network, good luck "
|
||||
"and don't forget: something something MUH traffic "
|
||||
"shape correlation !!!!");
|
||||
NetID::DefaultValue() =
|
||||
NetID(reinterpret_cast< const byte_t * >(netid.c_str()));
|
||||
// reset netid in our rc
|
||||
_rc.netID = llarp::NetID();
|
||||
}
|
||||
|
||||
_rc.SetNick(conf->router.nickname);
|
||||
maxConnectedRouters = conf->router.maxConnectedRouters;
|
||||
minConnectedRouters = conf->router.minConnectedRouters;
|
||||
encryption_keyfile = conf->router.encryption_keyfile;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
set(TEST_EXE testAll)
|
||||
|
||||
list(APPEND TEST_SRC
|
||||
config/test_llarp_config_config.cpp
|
||||
config/test_llarp_config_ini.cpp
|
||||
crypto/test_llarp_crypto_types.cpp
|
||||
crypto/test_llarp_crypto.cpp
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
#include <config/config.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
using namespace llarp;
|
||||
using namespace ::testing;
|
||||
|
||||
TEST(Config, smoke)
|
||||
{
|
||||
Config config;
|
||||
(void)config;
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST(Config, sample_config)
|
||||
{
|
||||
std::string text = R"(
|
||||
[router]
|
||||
# number of crypto worker threads
|
||||
threads=4
|
||||
# path to store signed RC
|
||||
contact-file=/home/lokinet/1/self.signed
|
||||
# path to store transport private key
|
||||
transport-privkey=/home/lokinet/1/transport.private
|
||||
# path to store identity signing key
|
||||
ident-privkey=/home/lokinet/1/identity.private
|
||||
# encryption key for onion routing
|
||||
encryption-privkey=/home/lokinet/1/encryption.private
|
||||
|
||||
# uncomment following line to set router nickname to 'lokinet'
|
||||
netid=bunny
|
||||
|
||||
[logging]
|
||||
level=info
|
||||
# uncomment for logging to file
|
||||
#type=file
|
||||
#file=/path/to/logfile
|
||||
# uncomment for syslog logging
|
||||
#type=syslog
|
||||
[metrics]
|
||||
json-metrics-path=/home/lokinet/1/metrics.json
|
||||
|
||||
# admin api (disabled by default)
|
||||
[api]
|
||||
enabled=false
|
||||
#authkey=insertpubkey1here
|
||||
#authkey=insertpubkey2here
|
||||
#authkey=insertpubkey3here
|
||||
bind=127.0.0.1:1190
|
||||
|
||||
# system settings for privileges and such
|
||||
[system]
|
||||
user=lokinet
|
||||
group=lokinet
|
||||
pidfile=/home/lokinet/1/lokinet.pid
|
||||
|
||||
# dns provider configuration section
|
||||
[dns]
|
||||
# resolver
|
||||
upstream=1.1.1.1
|
||||
bind=127.0.1.1:53
|
||||
|
||||
# network database settings block
|
||||
[netdb]
|
||||
# directory for network database skiplist storage
|
||||
dir=/home/lokinet/1/netdb
|
||||
|
||||
# bootstrap settings
|
||||
[bootstrap]
|
||||
# add a bootstrap node's signed identity to the list of nodes we want to bootstrap from
|
||||
# if we don't have any peers we connect to this router
|
||||
add-node=/home/lokinet/1/bootstrap.signed
|
||||
|
||||
# snapps configuration section
|
||||
[services]# uncomment next line to enable a snapp
|
||||
#example-snapp=/home/lokinet/1/snapp-example.ini
|
||||
|
||||
[bind]
|
||||
eth0=5501
|
||||
|
||||
|
||||
[network]
|
||||
ifname=cluster-1
|
||||
ifaddr=10.101.0.1/16
|
||||
|
||||
[metrics]
|
||||
metric-tank-host=52.80.56.123:2003
|
||||
)";
|
||||
|
||||
Config config;
|
||||
ASSERT_TRUE(config.LoadFromString(text));
|
||||
|
||||
{
|
||||
using kv = decltype(config.network.netConfig)::value_type;
|
||||
|
||||
ASSERT_THAT(config.network.netConfig,
|
||||
UnorderedElementsAre(kv("ifname", "cluster-1"),
|
||||
kv("ifaddr", "10.101.0.1/16")));
|
||||
}
|
||||
ASSERT_FALSE(config.metrics.disableMetricLogs);
|
||||
ASSERT_FALSE(config.metrics.disableMetrics);
|
||||
|
||||
{
|
||||
using kv = decltype(config.iwp_links.servers)::value_type;
|
||||
|
||||
ASSERT_THAT(config.iwp_links.servers,
|
||||
UnorderedElementsAre(kv("eth0", AF_INET, 5501)));
|
||||
}
|
||||
|
||||
ASSERT_THAT(config.bootstrap.routers,
|
||||
ElementsAre("/home/lokinet/1/bootstrap.signed"));
|
||||
}
|
Loading…
Reference in New Issue