Organize some constants and default values

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

@ -2,6 +2,7 @@
#include <config/ini.hpp> #include <config/ini.hpp>
#include <constants/defaults.hpp> #include <constants/defaults.hpp>
#include <constants/files.hpp>
#include <net/net.hpp> #include <net/net.hpp>
#include <router_contact.hpp> #include <router_contact.hpp>
#include <stdexcept> #include <stdexcept>
@ -307,7 +308,7 @@ namespace llarp
constexpr bool DefaultWhitelistRouters = false; constexpr bool DefaultWhitelistRouters = false;
constexpr auto DefaultLokidRPCAddr = "127.0.0.1:22023"; constexpr auto DefaultLokidRPCAddr = "127.0.0.1:22023";
conf.defineOption<std::string>("lokid", "service-node-seed", false, "", conf.defineOption<std::string>("lokid", "service-node-seed", false, our_identity_filename,
[this](std::string arg) { [this](std::string arg) {
if (not arg.empty()) if (not arg.empty())
{ {
@ -383,7 +384,7 @@ namespace llarp
m_keyfile = arg; m_keyfile = arg;
}); });
conf.defineOption<bool>("snapp", "keyfile", false, ReachableDefault, conf.defineOption<bool>("snapp", "reachable", false, ReachableDefault,
AssignmentAcceptor(m_reachable)); AssignmentAcceptor(m_reachable));
conf.defineOption<int>("snapp", "hops", false, HopsDefault, conf.defineOption<int>("snapp", "hops", false, HopsDefault,
@ -495,29 +496,6 @@ namespace llarp
logging.defineConfigOptions(conf, params); logging.defineConfigOptions(conf, params);
} }
fs::path
GetDefaultDataDir()
{
#ifdef _WIN32
const fs::path homedir = fs::path(getenv("APPDATA"));
#else
const fs::path homedir = fs::path(getenv("HOME"));
#endif
return homedir / fs::path(".lokinet/");
}
fs::path
GetDefaultConfigFilename()
{
return fs::path("lokinet.ini");
}
fs::path
GetDefaultConfigPath()
{
return GetDefaultDataDir() / GetDefaultConfigFilename();
}
void void
ensureConfig(const fs::path& defaultDataDir, ensureConfig(const fs::path& defaultDataDir,
const fs::path& confFile, const fs::path& confFile,

@ -7,6 +7,7 @@
#include <util/str.hpp> #include <util/str.hpp>
#include <config/ini.hpp> #include <config/ini.hpp>
#include <config/definition.hpp> #include <config/definition.hpp>
#include <constants/files.hpp>
#include <cstdlib> #include <cstdlib>
#include <functional> #include <functional>
@ -131,7 +132,7 @@ namespace llarp
{ {
bool usingSNSeed; bool usingSNSeed;
bool whitelistRouters; bool whitelistRouters;
fs::path ident_keyfile = "identity.key"; // TODO: derive from [router]:data-dir fs::path ident_keyfile;
std::string lokidRPCAddr; std::string lokidRPCAddr;
std::string lokidRPCUser; std::string lokidRPCUser;
std::string lokidRPCPassword; std::string lokidRPCPassword;
@ -211,15 +212,6 @@ namespace llarp
generateBaseRouterConfig(fs::path defaultDataDir); generateBaseRouterConfig(fs::path defaultDataDir);
}; };
fs::path
GetDefaultDataDir();
fs::path
GetDefaultConfigFilename();
fs::path
GetDefaultConfigPath();
void void
ensureConfig(const fs::path& defaultDataDir, ensureConfig(const fs::path& defaultDataDir,
const fs::path& confFile, const fs::path& confFile,

@ -34,10 +34,10 @@ namespace llarp
fs::path root = config.router.m_dataDir; fs::path root = config.router.m_dataDir;
// TODO: use fs::path, or at least support windows-style separators // TODO: use fs::path, or at least support windows-style separators
m_rcPath = root / "self.signed"; m_rcPath = root / our_rc_filename;
m_idKeyPath = root / "identity.key"; m_idKeyPath = root / our_identity_filename;
m_encKeyPath = root / "encryption.key"; m_encKeyPath = root / our_enc_key_filename;
m_transportKeyPath = root / "transport.key"; m_transportKeyPath = root / our_transport_key_filename;
m_usingLokid = config.lokid.whitelistRouters; m_usingLokid = config.lokid.whitelistRouters;
m_lokidRPCAddr = config.lokid.lokidRPCAddr; m_lokidRPCAddr = config.lokid.lokidRPCAddr;

@ -0,0 +1,41 @@
#pragma once
#include <util/fs.hpp>
#include <stdlib.h>
namespace llarp
{
constexpr auto our_rc_filename = "self.signed";
constexpr auto our_identity_filename = "identity.key";
constexpr auto our_enc_key_filename = "encryption.key";
constexpr auto our_transport_key_filename = "transport.key";
inline
fs::path
GetDefaultDataDir()
{
#ifdef _WIN32
const fs::path homedir = getenv("APPDATA");
#else
const fs::path homedir = getenv("HOME");
#endif
return homedir / ".lokinet/";
}
inline
fs::path
GetDefaultConfigFilename()
{
return "lokinet.ini";
}
inline
fs::path
GetDefaultConfigPath()
{
return GetDefaultDataDir() / GetDefaultConfigFilename();
}
} // namespace llarp

@ -3,6 +3,7 @@
#include <config/config.hpp> #include <config/config.hpp>
#include <constants/proto.hpp> #include <constants/proto.hpp>
#include <constants/files.hpp>
#include <crypto/crypto_libsodium.hpp> #include <crypto/crypto_libsodium.hpp>
#include <crypto/crypto.hpp> #include <crypto/crypto.hpp>
#include <dht/context.hpp> #include <dht/context.hpp>
@ -395,9 +396,9 @@ namespace llarp
conf->router.m_maxConnectedRouters; conf->router.m_maxConnectedRouters;
_outboundSessionMaker.minConnectedRouters = _outboundSessionMaker.minConnectedRouters =
conf->router.m_minConnectedRouters; conf->router.m_minConnectedRouters;
encryption_keyfile = conf->router.m_dataDir / "encryption.key"; encryption_keyfile = conf->router.m_dataDir / our_enc_key_filename;
our_rc_file = conf->router.m_dataDir / "rc.signed"; our_rc_file = conf->router.m_dataDir / our_rc_filename;
transport_keyfile = conf->router.m_dataDir / "transport.key"; transport_keyfile = conf->router.m_dataDir / our_transport_key_filename;
addrInfo = conf->router.m_addrInfo; addrInfo = conf->router.m_addrInfo;
publicOverride = conf->router.m_publicOverride; publicOverride = conf->router.m_publicOverride;
ip4addr = conf->router.m_ip4addr; ip4addr = conf->router.m_ip4addr;
@ -534,7 +535,7 @@ namespace llarp
if (!usingSNSeed) if (!usingSNSeed)
{ {
ident_keyfile = conf->router.m_dataDir / "identity.key"; ident_keyfile = conf->router.m_dataDir / our_identity_filename;
} }
// create inbound links, if we are a service node // create inbound links, if we are a service node

@ -54,19 +54,15 @@ namespace llarp
llarp_time_t _lastPump = 0s; llarp_time_t _lastPump = 0s;
bool ready; bool ready;
// transient iwp encryption key // transient iwp encryption key
fs::path transport_keyfile = "transport.key"; fs::path transport_keyfile;
// nodes to connect to on startup
// DEPRECATED
// std::map< std::string, fs::path > connect;
// long term identity key // long term identity key
fs::path ident_keyfile = "identity.key"; fs::path ident_keyfile;
fs::path encryption_keyfile = "encryption.key"; fs::path encryption_keyfile;
// path to write our self signed rc to // path to write our self signed rc to
fs::path our_rc_file = "rc.signed"; fs::path our_rc_file;
// use file based logging? // use file based logging?
bool m_UseFileLogging = false; bool m_UseFileLogging = false;

Loading…
Cancel
Save