From f2a26adcaa64a317c0fdb6958089c701be10d9a3 Mon Sep 17 00:00:00 2001 From: Stephen Shelton Date: Thu, 30 Apr 2020 16:11:05 -0600 Subject: [PATCH] Move all [endpoint] options to [network] --- llarp/config/config.cpp | 111 ++++++++++++++----------------- llarp/config/config.hpp | 39 +++++------ llarp/handlers/tun.cpp | 2 +- llarp/handlers/tun.hpp | 2 +- llarp/router/router.cpp | 5 +- llarp/service/context.cpp | 2 +- llarp/service/context.hpp | 2 +- llarp/service/endpoint.cpp | 2 +- llarp/service/endpoint.hpp | 2 +- llarp/service/endpoint_state.cpp | 2 +- llarp/service/endpoint_state.hpp | 2 +- 11 files changed, 76 insertions(+), 95 deletions(-) diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 35115532a..1212b20fb 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -144,6 +144,9 @@ namespace llarp (void)params; constexpr bool DefaultProfilingValue = true; + static constexpr bool ReachableDefault = false; + static constexpr int HopsDefault = 4; + static constexpr int PathsDefault = 6; conf.defineOption( "network", @@ -162,6 +165,46 @@ namespace llarp conf.defineOption( "network", "strict-connect", false, "", AssignmentAcceptor(m_strictConnect)); + + conf.defineOption( + "network", "keyfile", false, "", [this](std::string arg) { m_keyfile = arg; }); + + conf.defineOption( + "network", "reachable", false, ReachableDefault, AssignmentAcceptor(m_reachable)); + + conf.defineOption("network", "hops", false, HopsDefault, [this](int arg) { + if (arg < 1 or arg > 8) + throw std::invalid_argument("[endpoint]:hops must be >= 1 and <= 8"); + }); + + conf.defineOption("network", "paths", false, PathsDefault, [this](int arg) { + if (arg < 1 or arg > 8) + throw std::invalid_argument("[endpoint]:paths must be >= 1 and <= 8"); + }); + +#ifdef LOKINET_EXITS + conf.defineOption("network", "exit-node", false, "", [this](std::string arg) { + // TODO: validate as valid .loki / .snode address + // probably not .snode...? + m_exitNode = arg; + }); +#endif + + conf.defineOption("network", "mapaddr", false, "", [this](std::string arg) { + // TODO: parse / validate as loki_addr : IP addr pair + m_mapAddr = arg; + }); + + conf.defineOption( + "network", "blacklist-snode", false, true, "", [this](std::string arg) { + RouterID id; + if (not id.FromString(arg)) + throw std::invalid_argument(stringify("Invalide RouterID: ", arg)); + + auto itr = m_snodeBlacklist.emplace(std::move(id)); + if (itr.second) + throw std::invalid_argument(stringify("Duplicate blacklist-snode: ", arg)); + }); } void @@ -357,56 +400,6 @@ namespace llarp "logging", "file", false, DefaultLogFile, AssignmentAcceptor(m_logFile)); } - void - EndpointConfig::defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params) - { - (void)params; - - static constexpr bool ReachableDefault = false; - static constexpr int HopsDefault = 4; - static constexpr int PathsDefault = 6; - - conf.defineOption( - "endpoint", "keyfile", false, "", [this](std::string arg) { m_keyfile = arg; }); - - conf.defineOption( - "endpoint", "reachable", false, ReachableDefault, AssignmentAcceptor(m_reachable)); - - conf.defineOption("endpoint", "hops", false, HopsDefault, [this](int arg) { - if (arg < 1 or arg > 8) - throw std::invalid_argument("[endpoint]:hops must be >= 1 and <= 8"); - }); - - conf.defineOption("endpoint", "paths", false, PathsDefault, [this](int arg) { - if (arg < 1 or arg > 8) - throw std::invalid_argument("[endpoint]:paths must be >= 1 and <= 8"); - }); - -#ifdef LOKINET_EXITS - conf.defineOption("endpoint", "exit-node", false, "", [this](std::string arg) { - // TODO: validate as valid .loki / .snode address - // probably not .snode...? - m_exitNode = arg; - }); -#endif - - conf.defineOption("endpoint", "mapaddr", false, "", [this](std::string arg) { - // TODO: parse / validate as loki_addr : IP addr pair - m_mapAddr = arg; - }); - - conf.defineOption( - "endpoint", "blacklist-snode", false, true, "", [this](std::string arg) { - RouterID id; - if (not id.FromString(arg)) - throw std::invalid_argument(stringify("Invalide RouterID: ", arg)); - - auto itr = m_snodeBlacklist.emplace(std::move(id)); - if (itr.second) - throw std::invalid_argument(stringify("Duplicate blacklist-snode: ", arg)); - }); - } - bool Config::Load(const char* fname, bool isRelay, fs::path defaultDataDir) { @@ -483,7 +476,6 @@ namespace llarp lokid.defineConfigOptions(conf, params); bootstrap.defineConfigOptions(conf, params); logging.defineConfigOptions(conf, params); - endpoint.defineConfigOptions(conf, params); } void @@ -751,15 +743,14 @@ namespace llarp initializeConfig(def, params); generateCommonConfigComments(def); - // snapp def.addSectionComments( - "endpoint", + "network", { "Snapp settings", }); def.addOptionComments( - "endpoint", + "network", "keyfile", { "The private key to persist address with. If not specified the address will be", @@ -768,28 +759,28 @@ namespace llarp // TODO: is this redundant with / should be merged with basic client config? def.addOptionComments( - "endpoint", + "network", "reachable", { "Determines whether we will publish our snapp's introset to the DHT.", }); def.addOptionComments( - "endpoint", + "network", "hops", { "Number of hops in a path. Min 1, max 8.", }); def.addOptionComments( - "endpoint", + "network", "paths", { "Number of paths to maintain at any given time.", }); def.addOptionComments( - "endpoint", + "network", "blacklist-snode", { "Adds a `.snode` address to the blacklist.", @@ -797,7 +788,7 @@ namespace llarp #ifdef LOKINET_EXITS def.addOptionComments( - "endpoint", + "network", "exit-node", { "Specify a `.snode` or `.loki` address to use as an exit broker.", @@ -805,7 +796,7 @@ namespace llarp #endif def.addOptionComments( - "endpoint", + "network", "mapaddr", { "Permanently map a `.loki` address to an IP owned by the snapp. Example:", diff --git a/llarp/config/config.hpp b/llarp/config/config.hpp index e54d1481a..b4d959988 100644 --- a/llarp/config/config.hpp +++ b/llarp/config/config.hpp @@ -71,6 +71,22 @@ namespace llarp std::string m_ifname; std::string m_ifaddr; + std::string m_keyfile; + std::string m_endpointType; + bool m_reachable; + int m_hops; + int m_paths; + std::set m_snodeBlacklist; +#ifdef LOKINET_EXITS + std::string m_exitNode; +#endif + std::string m_mapAddr; + + // TODO: + // on-up + // on-down + // on-ready + void defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params); }; @@ -151,28 +167,6 @@ namespace llarp defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params); }; - struct EndpointConfig - { - std::string m_keyfile; - std::string m_endpointType; - bool m_reachable; - int m_hops; - int m_paths; - std::set m_snodeBlacklist; -#ifdef LOKINET_EXITS - std::string m_exitNode; -#endif - std::string m_mapAddr; - - // TODO: - // on-up - // on-down - // on-ready - - void - defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params); - }; - struct Config { RouterConfig router; @@ -184,7 +178,6 @@ namespace llarp LokidConfig lokid; BootstrapConfig bootstrap; LoggingConfig logging; - EndpointConfig endpoint; // Initialize config definition void diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index 44b8cb7d8..041f09aea 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -104,7 +104,7 @@ namespace llarp } bool - TunEndpoint::Configure(EndpointConfig conf) + TunEndpoint::Configure(const NetworkConfig& conf) { /* if (k == "reachable") diff --git a/llarp/handlers/tun.hpp b/llarp/handlers/tun.hpp index 1c572cb56..fc1632fcc 100644 --- a/llarp/handlers/tun.hpp +++ b/llarp/handlers/tun.hpp @@ -33,7 +33,7 @@ namespace llarp } bool - Configure(EndpointConfig conf) override; + Configure(const NetworkConfig& conf) override; void Tick(llarp_time_t now) override; diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 918d93312..ca4c8183f 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -375,9 +375,6 @@ namespace llarp bool Router::FromConfig(Config* conf) { - networkConfig = conf->network; - dnsConfig = conf->dns; - // Set netid before anything else if (!conf->router.m_netId.empty() && strcmp(conf->router.m_netId.c_str(), llarp::DEFAULT_NETID)) { @@ -575,7 +572,7 @@ namespace llarp enableRPCServer = conf->api.m_enableRPCServer; rpcBindAddr = conf->api.m_rpcBindAddr; - hiddenServiceContext().AddEndpoint(conf->endpoint); + hiddenServiceContext().AddEndpoint(conf->network); // Logging config LogContext::Instance().Initialize( diff --git a/llarp/service/context.cpp b/llarp/service/context.cpp index 44e6949b8..3a6f4d5b9 100644 --- a/llarp/service/context.cpp +++ b/llarp/service/context.cpp @@ -172,7 +172,7 @@ namespace llarp } void - Context::AddEndpoint(const EndpointConfig& conf, bool autostart) + Context::AddEndpoint(const NetworkConfig& conf, bool autostart) { // TODO: refactor Context to only contain one endpoint constexpr auto endpointName = "endpoint"; diff --git a/llarp/service/context.hpp b/llarp/service/context.hpp index 7a6430a67..3c79edaed 100644 --- a/llarp/service/context.hpp +++ b/llarp/service/context.hpp @@ -39,7 +39,7 @@ namespace llarp /// add endpoint via config void - AddEndpoint(const EndpointConfig& conf, bool autostart = false); + AddEndpoint(const NetworkConfig& conf, bool autostart = false); /// inject endpoint instance void diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index a03782f56..9e6620bc6 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -43,7 +43,7 @@ namespace llarp } bool - Endpoint::Configure(EndpointConfig conf) + Endpoint::Configure(const NetworkConfig& conf) { numPaths = conf.m_paths; numHops = conf.m_hops; diff --git a/llarp/service/endpoint.hpp b/llarp/service/endpoint.hpp index 1ba328861..3eb05f8e0 100644 --- a/llarp/service/endpoint.hpp +++ b/llarp/service/endpoint.hpp @@ -94,7 +94,7 @@ namespace llarp SetHandler(IDataHandler* h); virtual bool - Configure(EndpointConfig conf); + Configure(const NetworkConfig& conf); void Tick(llarp_time_t now) override; diff --git a/llarp/service/endpoint_state.cpp b/llarp/service/endpoint_state.cpp index 91f465d25..d7c02a382 100644 --- a/llarp/service/endpoint_state.cpp +++ b/llarp/service/endpoint_state.cpp @@ -11,7 +11,7 @@ namespace llarp namespace service { bool - EndpointState::Configure(const EndpointConfig& conf) + EndpointState::Configure(const NetworkConfig& conf) { m_Keyfile = conf.m_keyfile; m_SnodeBlacklist = conf.m_snodeBlacklist; diff --git a/llarp/service/endpoint_state.hpp b/llarp/service/endpoint_state.hpp index 1d24e4887..2b5448c98 100644 --- a/llarp/service/endpoint_state.hpp +++ b/llarp/service/endpoint_state.hpp @@ -90,7 +90,7 @@ namespace llarp util::DecayingHashSet
m_RemoteLookupFilter; bool - Configure(const EndpointConfig& conf); + Configure(const NetworkConfig& conf); util::StatusObject ExtractStatus(util::StatusObject& obj) const;