Reflect removal of accessors on config structs

pull/1186/head
Stephen Shelton 4 years ago
parent c8c940b0f5
commit 733efbab40
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -93,8 +93,6 @@ namespace llarp
conf.defineOption<std::string>("router", "nickname", false, m_nickname, conf.defineOption<std::string>("router", "nickname", false, m_nickname,
[this](std::string arg) { [this](std::string arg) {
m_nickname = std::move(arg); m_nickname = std::move(arg);
// TODO: side effect here, no side effects in config parsing!!
LogContext::Instance().nodeName = nickname();
}); });
conf.defineOption<std::string>("router", "data-dir", false, GetDefaultDataDir(), conf.defineOption<std::string>("router", "data-dir", false, GetDefaultDataDir(),

@ -31,10 +31,10 @@ namespace llarp
if (m_initialized) if (m_initialized)
return false; return false;
m_rcPath = config.router.ourRcFile(); m_rcPath = config.router.m_dataDir + "/rc.signed";
m_idKeyPath = config.router.identKeyfile(); m_idKeyPath = config.router.m_dataDir + "/identity.key";
m_encKeyPath = config.router.encryptionKeyfile(); m_encKeyPath = config.router.m_dataDir + "/encryption.key";
m_transportKeyPath = config.router.transportKeyfile(); m_transportKeyPath = config.router.m_dataDir + "/transport.key";
m_usingLokid = config.lokid.whitelistRouters; m_usingLokid = config.lokid.whitelistRouters;
m_lokidRPCAddr = config.lokid.lokidRPCAddr; m_lokidRPCAddr = config.lokid.lokidRPCAddr;

@ -49,16 +49,17 @@ namespace llarp
{ {
SetPIDFile(config->system.pidfile); SetPIDFile(config->system.pidfile);
} }
auto threads = config->router.workerThreads(); auto threads = config->router.m_workerThreads;
if (threads <= 0) if(threads <= 0)
threads = 1; threads = 1;
worker = std::make_shared<llarp::thread::ThreadPool>(threads, 1024, "llarp-worker"); worker = std::make_shared< llarp::thread::ThreadPool >(threads, 1024,
auto jobQueueSize = config->router.jobQueueSize(); "llarp-worker");
if (jobQueueSize < 1024) auto jobQueueSize = config->router.m_JobQueueSize;
if(jobQueueSize < 1024)
jobQueueSize = 1024; jobQueueSize = 1024;
logic = std::make_shared<Logic>(jobQueueSize); logic = std::make_shared<Logic>(jobQueueSize);
nodedb_dir = config->netdb.nodedbDir(); nodedb_dir = config->netdb.m_nodedbDir;
return true; return true;
} }

@ -372,46 +372,45 @@ namespace llarp
Router::FromConfig(Config* conf) Router::FromConfig(Config* conf)
{ {
// Set netid before anything else // Set netid before anything else
if (!conf->router.netId().empty() && strcmp(conf->router.netId().c_str(), llarp::DEFAULT_NETID)) if(!conf->router.m_netId.empty()
&& strcmp(conf->router.m_netId.c_str(), llarp::DEFAULT_NETID))
{ {
const auto& netid = conf->router.netId(); const auto &netid = conf->router.m_netId;
llarp::LogWarn( llarp::LogWarn("!!!! you have manually set netid to be '", netid,
"!!!! you have manually set netid to be '", "' which does not equal '", llarp::DEFAULT_NETID,
netid, "' you will run as a different network, good luck "
"' which does not equal '", "and don't forget: something something MUH traffic "
llarp::DEFAULT_NETID, "shape correlation !!!!");
"' you will run as a different network, good luck " NetID::DefaultValue() =
"and don't forget: something something MUH traffic " NetID(reinterpret_cast< const byte_t * >(netid.c_str()));
"shape correlation !!!!");
NetID::DefaultValue() = NetID(reinterpret_cast<const byte_t*>(netid.c_str()));
// reset netid in our rc // reset netid in our rc
_rc.netID = llarp::NetID(); _rc.netID = llarp::NetID();
} }
const auto linktypename = conf->router.defaultLinkProto(); // TODO: dead code, rip this out. we only support IWP now.
_defaultLinkType = LinkFactory::TypeFromName(linktypename); const auto linktypename = conf->router.m_DefaultLinkProto;
if (_defaultLinkType == LinkFactory::LinkType::eLinkUnknown) _defaultLinkType = LinkFactory::TypeFromName(linktypename);
if(_defaultLinkType == LinkFactory::LinkType::eLinkUnknown)
{ {
LogError("failed to set link type to '", linktypename, "' as that is invalid"); LogError("failed to set link type to '", linktypename, "' as that is invalid");
return false; return false;
} }
// IWP config // IWP config
m_OutboundPort = conf->links.outboundLink().port; m_OutboundPort = conf->links.m_OutboundLink.port;
// Router config // Router config
_rc.SetNick(conf->router.nickname()); _rc.SetNick(conf->router.m_nickname);
_outboundSessionMaker.maxConnectedRouters = conf->router.maxConnectedRouters(); _outboundSessionMaker.maxConnectedRouters =
_outboundSessionMaker.minConnectedRouters = conf->router.minConnectedRouters(); conf->router.m_maxConnectedRouters;
encryption_keyfile = conf->router.encryptionKeyfile(); _outboundSessionMaker.minConnectedRouters =
our_rc_file = conf->router.ourRcFile(); conf->router.m_minConnectedRouters;
transport_keyfile = conf->router.transportKeyfile(); encryption_keyfile = conf->router.m_dataDir + "/encryption.key";
addrInfo = conf->router.addrInfo(); our_rc_file = conf->router.m_dataDir + "/rc.signed";
publicOverride = conf->router.publicOverride(); transport_keyfile = conf->router.m_dataDir + "/transport.key";
ip4addr = conf->router.ip4addr(); addrInfo = conf->router.m_addrInfo;
publicOverride = conf->router.m_publicOverride;
if (!conf->router.blockBogons().value_or(true)) ip4addr = conf->router.m_ip4addr;
{
RouterContact::BlockBogons = false; RouterContact::BlockBogons = conf->router.m_blockBogons.value_or(true);
}
// Lokid Config // Lokid Config
usingSNSeed = conf->lokid.usingSNSeed; usingSNSeed = conf->lokid.usingSNSeed;
@ -422,17 +421,17 @@ namespace llarp
lokidRPCPassword = conf->lokid.lokidRPCPassword; lokidRPCPassword = conf->lokid.lokidRPCPassword;
// TODO: add config flag for "is service node" // TODO: add config flag for "is service node"
if (conf->links.inboundLinks().size()) if(conf->links.m_InboundLinks.size())
{ {
m_isServiceNode = true; m_isServiceNode = true;
} }
std::set<RouterID> strictConnectPubkeys; std::set<RouterID> strictConnectPubkeys;
if (!conf->network.strictConnect().empty()) if(!conf->network.m_strictConnect.empty())
{ {
const auto& val = conf->network.strictConnect(); const auto &val = conf->network.m_strictConnect;
if (IsServiceNode()) if(IsServiceNode())
{ {
llarp::LogError("cannot use strict-connect option as service node"); llarp::LogError("cannot use strict-connect option as service node");
return false; return false;
@ -526,11 +525,11 @@ namespace llarp
if (!usingSNSeed) if (!usingSNSeed)
{ {
ident_keyfile = conf->router.identKeyfile(); ident_keyfile = conf->router.m_dataDir + "/identity.key";
} }
// create inbound links, if we are a service node // create inbound links, if we are a service node
for(const LinksConfig::LinkInfo &serverConfig : conf->links.inboundLinks()) for(const LinksConfig::LinkInfo &serverConfig : conf->links.m_InboundLinks)
{ {
// get default factory // get default factory
// TODO: this is dead code, as is everything related to _defaultLinkType, // TODO: this is dead code, as is everything related to _defaultLinkType,
@ -560,28 +559,28 @@ namespace llarp
} }
// set network config // set network config
netConfig = conf->network.netConfig(); netConfig = conf->network.m_netConfig;
// Network config // Network config
if (conf->network.enableProfiling().has_value()) if(conf->network.m_enableProfiling.has_value())
{ {
if (not conf->network.enableProfiling().value()) if(not conf->network.m_enableProfiling.value())
{ {
routerProfiling().Disable(); routerProfiling().Disable();
LogWarn("router profiling explicitly disabled"); LogWarn("router profiling explicitly disabled");
} }
} }
if (!conf->network.routerProfilesFile().empty()) if(!conf->network.m_routerProfilesFile.empty())
{ {
routerProfilesFile = conf->network.routerProfilesFile(); routerProfilesFile = conf->network.m_routerProfilesFile;
routerProfiling().Load(routerProfilesFile.c_str()); routerProfiling().Load(routerProfilesFile.c_str());
llarp::LogInfo("setting profiles to ", routerProfilesFile); llarp::LogInfo("setting profiles to ", routerProfilesFile);
} }
// API config // API config
enableRPCServer = conf->api.enableRPCServer(); enableRPCServer = conf->api.m_enableRPCServer;
rpcBindAddr = conf->api.rpcBindAddr(); rpcBindAddr = conf->api.m_rpcBindAddr;
// Services config // Services config
for (const auto& service : conf->services.services) for (const auto& service : conf->services.services)
@ -597,6 +596,7 @@ namespace llarp
} }
// Logging config // Logging config
LogContext::Instance().nodeName = conf->router.m_nickname;
FILE* logfile = nullptr; FILE* logfile = nullptr;
if (conf->logging.m_logFile == "stdout") if (conf->logging.m_logFile == "stdout")

@ -115,18 +115,6 @@ TEST_F(KeyManagerTest, TestBackupFileByMoving_FailsIfBackupNamesAreExausted)
}; };
TEST_F(KeyManagerTest, EnsureDefaultConfNames)
{
llarp::Config conf;
// the default config filenames will suffice, this exists as sanity check to
// protect against the assumptions made below
ASSERT_EQ(conf.router.ourRcFile(), rcFile);
ASSERT_EQ(conf.router.encryptionKeyfile(), encFile);
ASSERT_EQ(conf.router.transportKeyfile(), transportFile);
ASSERT_EQ(conf.router.identKeyfile(), identFile);
}
TEST_F(KeyManagerTest, TestInitialize_MakesKeyfiles) TEST_F(KeyManagerTest, TestInitialize_MakesKeyfiles)
{ {
llarp::Config conf; llarp::Config conf;

Loading…
Cancel
Save