Move all [endpoint] options to [network]

pull/1246/head
Stephen Shelton 4 years ago committed by Jeff Becker
parent 559610ec94
commit f2a26adcaa
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -144,6 +144,9 @@ namespace llarp
(void)params; (void)params;
constexpr bool DefaultProfilingValue = true; constexpr bool DefaultProfilingValue = true;
static constexpr bool ReachableDefault = false;
static constexpr int HopsDefault = 4;
static constexpr int PathsDefault = 6;
conf.defineOption<bool>( conf.defineOption<bool>(
"network", "network",
@ -162,6 +165,46 @@ namespace llarp
conf.defineOption<std::string>( conf.defineOption<std::string>(
"network", "strict-connect", false, "", AssignmentAcceptor(m_strictConnect)); "network", "strict-connect", false, "", AssignmentAcceptor(m_strictConnect));
conf.defineOption<std::string>(
"network", "keyfile", false, "", [this](std::string arg) { m_keyfile = arg; });
conf.defineOption<bool>(
"network", "reachable", false, ReachableDefault, AssignmentAcceptor(m_reachable));
conf.defineOption<int>("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<int>("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<std::string>("network", "exit-node", false, "", [this](std::string arg) {
// TODO: validate as valid .loki / .snode address
// probably not .snode...?
m_exitNode = arg;
});
#endif
conf.defineOption<std::string>("network", "mapaddr", false, "", [this](std::string arg) {
// TODO: parse / validate as loki_addr : IP addr pair
m_mapAddr = arg;
});
conf.defineOption<std::string>(
"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 void
@ -357,56 +400,6 @@ namespace llarp
"logging", "file", false, DefaultLogFile, AssignmentAcceptor(m_logFile)); "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<std::string>(
"endpoint", "keyfile", false, "", [this](std::string arg) { m_keyfile = arg; });
conf.defineOption<bool>(
"endpoint", "reachable", false, ReachableDefault, AssignmentAcceptor(m_reachable));
conf.defineOption<int>("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<int>("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<std::string>("endpoint", "exit-node", false, "", [this](std::string arg) {
// TODO: validate as valid .loki / .snode address
// probably not .snode...?
m_exitNode = arg;
});
#endif
conf.defineOption<std::string>("endpoint", "mapaddr", false, "", [this](std::string arg) {
// TODO: parse / validate as loki_addr : IP addr pair
m_mapAddr = arg;
});
conf.defineOption<std::string>(
"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 bool
Config::Load(const char* fname, bool isRelay, fs::path defaultDataDir) Config::Load(const char* fname, bool isRelay, fs::path defaultDataDir)
{ {
@ -483,7 +476,6 @@ namespace llarp
lokid.defineConfigOptions(conf, params); lokid.defineConfigOptions(conf, params);
bootstrap.defineConfigOptions(conf, params); bootstrap.defineConfigOptions(conf, params);
logging.defineConfigOptions(conf, params); logging.defineConfigOptions(conf, params);
endpoint.defineConfigOptions(conf, params);
} }
void void
@ -751,15 +743,14 @@ namespace llarp
initializeConfig(def, params); initializeConfig(def, params);
generateCommonConfigComments(def); generateCommonConfigComments(def);
// snapp
def.addSectionComments( def.addSectionComments(
"endpoint", "network",
{ {
"Snapp settings", "Snapp settings",
}); });
def.addOptionComments( def.addOptionComments(
"endpoint", "network",
"keyfile", "keyfile",
{ {
"The private key to persist address with. If not specified the address will be", "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? // TODO: is this redundant with / should be merged with basic client config?
def.addOptionComments( def.addOptionComments(
"endpoint", "network",
"reachable", "reachable",
{ {
"Determines whether we will publish our snapp's introset to the DHT.", "Determines whether we will publish our snapp's introset to the DHT.",
}); });
def.addOptionComments( def.addOptionComments(
"endpoint", "network",
"hops", "hops",
{ {
"Number of hops in a path. Min 1, max 8.", "Number of hops in a path. Min 1, max 8.",
}); });
def.addOptionComments( def.addOptionComments(
"endpoint", "network",
"paths", "paths",
{ {
"Number of paths to maintain at any given time.", "Number of paths to maintain at any given time.",
}); });
def.addOptionComments( def.addOptionComments(
"endpoint", "network",
"blacklist-snode", "blacklist-snode",
{ {
"Adds a `.snode` address to the blacklist.", "Adds a `.snode` address to the blacklist.",
@ -797,7 +788,7 @@ namespace llarp
#ifdef LOKINET_EXITS #ifdef LOKINET_EXITS
def.addOptionComments( def.addOptionComments(
"endpoint", "network",
"exit-node", "exit-node",
{ {
"Specify a `.snode` or `.loki` address to use as an exit broker.", "Specify a `.snode` or `.loki` address to use as an exit broker.",
@ -805,7 +796,7 @@ namespace llarp
#endif #endif
def.addOptionComments( def.addOptionComments(
"endpoint", "network",
"mapaddr", "mapaddr",
{ {
"Permanently map a `.loki` address to an IP owned by the snapp. Example:", "Permanently map a `.loki` address to an IP owned by the snapp. Example:",

@ -71,6 +71,22 @@ namespace llarp
std::string m_ifname; std::string m_ifname;
std::string m_ifaddr; std::string m_ifaddr;
std::string m_keyfile;
std::string m_endpointType;
bool m_reachable;
int m_hops;
int m_paths;
std::set<RouterID> m_snodeBlacklist;
#ifdef LOKINET_EXITS
std::string m_exitNode;
#endif
std::string m_mapAddr;
// TODO:
// on-up
// on-down
// on-ready
void void
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params); defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params);
}; };
@ -151,28 +167,6 @@ namespace llarp
defineConfigOptions(ConfigDefinition& conf, const ConfigGenParameters& params); 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<RouterID> 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 struct Config
{ {
RouterConfig router; RouterConfig router;
@ -184,7 +178,6 @@ namespace llarp
LokidConfig lokid; LokidConfig lokid;
BootstrapConfig bootstrap; BootstrapConfig bootstrap;
LoggingConfig logging; LoggingConfig logging;
EndpointConfig endpoint;
// Initialize config definition // Initialize config definition
void void

@ -104,7 +104,7 @@ namespace llarp
} }
bool bool
TunEndpoint::Configure(EndpointConfig conf) TunEndpoint::Configure(const NetworkConfig& conf)
{ {
/* /*
if (k == "reachable") if (k == "reachable")

@ -33,7 +33,7 @@ namespace llarp
} }
bool bool
Configure(EndpointConfig conf) override; Configure(const NetworkConfig& conf) override;
void void
Tick(llarp_time_t now) override; Tick(llarp_time_t now) override;

@ -375,9 +375,6 @@ namespace llarp
bool bool
Router::FromConfig(Config* conf) Router::FromConfig(Config* conf)
{ {
networkConfig = conf->network;
dnsConfig = conf->dns;
// Set netid before anything else // Set netid before anything else
if (!conf->router.m_netId.empty() && strcmp(conf->router.m_netId.c_str(), llarp::DEFAULT_NETID)) 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; enableRPCServer = conf->api.m_enableRPCServer;
rpcBindAddr = conf->api.m_rpcBindAddr; rpcBindAddr = conf->api.m_rpcBindAddr;
hiddenServiceContext().AddEndpoint(conf->endpoint); hiddenServiceContext().AddEndpoint(conf->network);
// Logging config // Logging config
LogContext::Instance().Initialize( LogContext::Instance().Initialize(

@ -172,7 +172,7 @@ namespace llarp
} }
void void
Context::AddEndpoint(const EndpointConfig& conf, bool autostart) Context::AddEndpoint(const NetworkConfig& conf, bool autostart)
{ {
// TODO: refactor Context to only contain one endpoint // TODO: refactor Context to only contain one endpoint
constexpr auto endpointName = "endpoint"; constexpr auto endpointName = "endpoint";

@ -39,7 +39,7 @@ namespace llarp
/// add endpoint via config /// add endpoint via config
void void
AddEndpoint(const EndpointConfig& conf, bool autostart = false); AddEndpoint(const NetworkConfig& conf, bool autostart = false);
/// inject endpoint instance /// inject endpoint instance
void void

@ -43,7 +43,7 @@ namespace llarp
} }
bool bool
Endpoint::Configure(EndpointConfig conf) Endpoint::Configure(const NetworkConfig& conf)
{ {
numPaths = conf.m_paths; numPaths = conf.m_paths;
numHops = conf.m_hops; numHops = conf.m_hops;

@ -94,7 +94,7 @@ namespace llarp
SetHandler(IDataHandler* h); SetHandler(IDataHandler* h);
virtual bool virtual bool
Configure(EndpointConfig conf); Configure(const NetworkConfig& conf);
void void
Tick(llarp_time_t now) override; Tick(llarp_time_t now) override;

@ -11,7 +11,7 @@ namespace llarp
namespace service namespace service
{ {
bool bool
EndpointState::Configure(const EndpointConfig& conf) EndpointState::Configure(const NetworkConfig& conf)
{ {
m_Keyfile = conf.m_keyfile; m_Keyfile = conf.m_keyfile;
m_SnodeBlacklist = conf.m_snodeBlacklist; m_SnodeBlacklist = conf.m_snodeBlacklist;

@ -90,7 +90,7 @@ namespace llarp
util::DecayingHashSet<Address> m_RemoteLookupFilter; util::DecayingHashSet<Address> m_RemoteLookupFilter;
bool bool
Configure(const EndpointConfig& conf); Configure(const NetworkConfig& conf);
util::StatusObject util::StatusObject
ExtractStatus(util::StatusObject& obj) const; ExtractStatus(util::StatusObject& obj) const;

Loading…
Cancel
Save