From 733efbab407e824ba14947dd238ac416cbd5d989 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Fri, 27 Mar 2020 16:15:26 -0600 Subject: [PATCH] Reflect removal of accessors on config structs --- llarp/config/config.cpp | 2 - llarp/config/key_manager.cpp | 8 +-- llarp/context.cpp | 13 ++-- llarp/router/router.cpp | 84 +++++++++++++------------- test/crypto/test_llarp_key_manager.cpp | 12 ---- 5 files changed, 53 insertions(+), 66 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 3b3b73a04..283a66e94 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -93,8 +93,6 @@ namespace llarp conf.defineOption("router", "nickname", false, m_nickname, [this](std::string arg) { m_nickname = std::move(arg); - // TODO: side effect here, no side effects in config parsing!! - LogContext::Instance().nodeName = nickname(); }); conf.defineOption("router", "data-dir", false, GetDefaultDataDir(), diff --git a/llarp/config/key_manager.cpp b/llarp/config/key_manager.cpp index b69b48534..5feeeb95f 100644 --- a/llarp/config/key_manager.cpp +++ b/llarp/config/key_manager.cpp @@ -31,10 +31,10 @@ namespace llarp if (m_initialized) return false; - m_rcPath = config.router.ourRcFile(); - m_idKeyPath = config.router.identKeyfile(); - m_encKeyPath = config.router.encryptionKeyfile(); - m_transportKeyPath = config.router.transportKeyfile(); + m_rcPath = config.router.m_dataDir + "/rc.signed"; + m_idKeyPath = config.router.m_dataDir + "/identity.key"; + m_encKeyPath = config.router.m_dataDir + "/encryption.key"; + m_transportKeyPath = config.router.m_dataDir + "/transport.key"; m_usingLokid = config.lokid.whitelistRouters; m_lokidRPCAddr = config.lokid.lokidRPCAddr; diff --git a/llarp/context.cpp b/llarp/context.cpp index a75db7509..f1e08937f 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -49,16 +49,17 @@ namespace llarp { SetPIDFile(config->system.pidfile); } - auto threads = config->router.workerThreads(); - if (threads <= 0) + auto threads = config->router.m_workerThreads; + if(threads <= 0) threads = 1; - worker = std::make_shared(threads, 1024, "llarp-worker"); - auto jobQueueSize = config->router.jobQueueSize(); - if (jobQueueSize < 1024) + worker = std::make_shared< llarp::thread::ThreadPool >(threads, 1024, + "llarp-worker"); + auto jobQueueSize = config->router.m_JobQueueSize; + if(jobQueueSize < 1024) jobQueueSize = 1024; logic = std::make_shared(jobQueueSize); - nodedb_dir = config->netdb.nodedbDir(); + nodedb_dir = config->netdb.m_nodedbDir; return true; } diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index a26375b31..16208eb2b 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -372,46 +372,45 @@ namespace llarp Router::FromConfig(Config* conf) { // 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(); - llarp::LogWarn( - "!!!! you have manually set netid to be '", - netid, - "' which does not equal '", - llarp::DEFAULT_NETID, - "' you will run as a different network, good luck " - "and don't forget: something something MUH traffic " - "shape correlation !!!!"); - NetID::DefaultValue() = NetID(reinterpret_cast(netid.c_str())); + const auto &netid = conf->router.m_netId; + llarp::LogWarn("!!!! you have manually set netid to be '", netid, + "' which does not equal '", llarp::DEFAULT_NETID, + "' 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(); } - const auto linktypename = conf->router.defaultLinkProto(); - _defaultLinkType = LinkFactory::TypeFromName(linktypename); - if (_defaultLinkType == LinkFactory::LinkType::eLinkUnknown) + // TODO: dead code, rip this out. we only support IWP now. + const auto linktypename = conf->router.m_DefaultLinkProto; + _defaultLinkType = LinkFactory::TypeFromName(linktypename); + if(_defaultLinkType == LinkFactory::LinkType::eLinkUnknown) { LogError("failed to set link type to '", linktypename, "' as that is invalid"); return false; } // IWP config - m_OutboundPort = conf->links.outboundLink().port; + m_OutboundPort = conf->links.m_OutboundLink.port; // Router config - _rc.SetNick(conf->router.nickname()); - _outboundSessionMaker.maxConnectedRouters = conf->router.maxConnectedRouters(); - _outboundSessionMaker.minConnectedRouters = conf->router.minConnectedRouters(); - encryption_keyfile = conf->router.encryptionKeyfile(); - our_rc_file = conf->router.ourRcFile(); - transport_keyfile = conf->router.transportKeyfile(); - addrInfo = conf->router.addrInfo(); - publicOverride = conf->router.publicOverride(); - ip4addr = conf->router.ip4addr(); - - if (!conf->router.blockBogons().value_or(true)) - { - RouterContact::BlockBogons = false; - } + _rc.SetNick(conf->router.m_nickname); + _outboundSessionMaker.maxConnectedRouters = + conf->router.m_maxConnectedRouters; + _outboundSessionMaker.minConnectedRouters = + conf->router.m_minConnectedRouters; + encryption_keyfile = conf->router.m_dataDir + "/encryption.key"; + our_rc_file = conf->router.m_dataDir + "/rc.signed"; + transport_keyfile = conf->router.m_dataDir + "/transport.key"; + addrInfo = conf->router.m_addrInfo; + publicOverride = conf->router.m_publicOverride; + ip4addr = conf->router.m_ip4addr; + + RouterContact::BlockBogons = conf->router.m_blockBogons.value_or(true); // Lokid Config usingSNSeed = conf->lokid.usingSNSeed; @@ -422,17 +421,17 @@ namespace llarp lokidRPCPassword = conf->lokid.lokidRPCPassword; // TODO: add config flag for "is service node" - if (conf->links.inboundLinks().size()) + if(conf->links.m_InboundLinks.size()) { m_isServiceNode = true; } std::set strictConnectPubkeys; - if (!conf->network.strictConnect().empty()) + if(!conf->network.m_strictConnect.empty()) { - const auto& val = conf->network.strictConnect(); - if (IsServiceNode()) + const auto &val = conf->network.m_strictConnect; + if(IsServiceNode()) { llarp::LogError("cannot use strict-connect option as service node"); return false; @@ -526,11 +525,11 @@ namespace llarp if (!usingSNSeed) { - ident_keyfile = conf->router.identKeyfile(); + ident_keyfile = conf->router.m_dataDir + "/identity.key"; } // 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 // TODO: this is dead code, as is everything related to _defaultLinkType, @@ -560,28 +559,28 @@ namespace llarp } // set network config - netConfig = conf->network.netConfig(); + netConfig = conf->network.m_netConfig; // 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(); 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()); llarp::LogInfo("setting profiles to ", routerProfilesFile); } // API config - enableRPCServer = conf->api.enableRPCServer(); - rpcBindAddr = conf->api.rpcBindAddr(); + enableRPCServer = conf->api.m_enableRPCServer; + rpcBindAddr = conf->api.m_rpcBindAddr; // Services config for (const auto& service : conf->services.services) @@ -597,6 +596,7 @@ namespace llarp } // Logging config + LogContext::Instance().nodeName = conf->router.m_nickname; FILE* logfile = nullptr; if (conf->logging.m_logFile == "stdout") diff --git a/test/crypto/test_llarp_key_manager.cpp b/test/crypto/test_llarp_key_manager.cpp index d7771150b..784e3174f 100644 --- a/test/crypto/test_llarp_key_manager.cpp +++ b/test/crypto/test_llarp_key_manager.cpp @@ -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) { llarp::Config conf;