diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 6c868916c..0e902594d 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -307,7 +308,7 @@ namespace llarp constexpr bool DefaultWhitelistRouters = false; constexpr auto DefaultLokidRPCAddr = "127.0.0.1:22023"; - conf.defineOption("lokid", "service-node-seed", false, "", + conf.defineOption("lokid", "service-node-seed", false, our_identity_filename, [this](std::string arg) { if (not arg.empty()) { @@ -383,7 +384,7 @@ namespace llarp m_keyfile = arg; }); - conf.defineOption("snapp", "keyfile", false, ReachableDefault, + conf.defineOption("snapp", "reachable", false, ReachableDefault, AssignmentAcceptor(m_reachable)); conf.defineOption("snapp", "hops", false, HopsDefault, @@ -495,29 +496,6 @@ namespace llarp 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 ensureConfig(const fs::path& defaultDataDir, const fs::path& confFile, diff --git a/llarp/config/config.hpp b/llarp/config/config.hpp index 69909452a..074414a79 100644 --- a/llarp/config/config.hpp +++ b/llarp/config/config.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -131,7 +132,7 @@ namespace llarp { bool usingSNSeed; bool whitelistRouters; - fs::path ident_keyfile = "identity.key"; // TODO: derive from [router]:data-dir + fs::path ident_keyfile; std::string lokidRPCAddr; std::string lokidRPCUser; std::string lokidRPCPassword; @@ -211,15 +212,6 @@ namespace llarp generateBaseRouterConfig(fs::path defaultDataDir); }; - fs::path - GetDefaultDataDir(); - - fs::path - GetDefaultConfigFilename(); - - fs::path - GetDefaultConfigPath(); - void ensureConfig(const fs::path& defaultDataDir, const fs::path& confFile, diff --git a/llarp/config/key_manager.cpp b/llarp/config/key_manager.cpp index 0b7e3cf9d..91be19e6d 100644 --- a/llarp/config/key_manager.cpp +++ b/llarp/config/key_manager.cpp @@ -34,10 +34,10 @@ namespace llarp fs::path root = config.router.m_dataDir; // TODO: use fs::path, or at least support windows-style separators - m_rcPath = root / "self.signed"; - m_idKeyPath = root / "identity.key"; - m_encKeyPath = root / "encryption.key"; - m_transportKeyPath = root / "transport.key"; + m_rcPath = root / our_rc_filename; + m_idKeyPath = root / our_identity_filename; + m_encKeyPath = root / our_enc_key_filename; + m_transportKeyPath = root / our_transport_key_filename; m_usingLokid = config.lokid.whitelistRouters; m_lokidRPCAddr = config.lokid.lokidRPCAddr; diff --git a/llarp/constants/files.hpp b/llarp/constants/files.hpp new file mode 100644 index 000000000..9a686d21b --- /dev/null +++ b/llarp/constants/files.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include + +#include + +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 + diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 51f5cafe1..84357de93 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -395,9 +396,9 @@ namespace llarp 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"; + encryption_keyfile = conf->router.m_dataDir / our_enc_key_filename; + our_rc_file = conf->router.m_dataDir / our_rc_filename; + transport_keyfile = conf->router.m_dataDir / our_transport_key_filename; addrInfo = conf->router.m_addrInfo; publicOverride = conf->router.m_publicOverride; ip4addr = conf->router.m_ip4addr; @@ -534,7 +535,7 @@ namespace llarp 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 diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index e81adebaf..566842447 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -54,19 +54,15 @@ namespace llarp llarp_time_t _lastPump = 0s; bool ready; // transient iwp encryption key - fs::path transport_keyfile = "transport.key"; - - // nodes to connect to on startup - // DEPRECATED - // std::map< std::string, fs::path > connect; + fs::path transport_keyfile; // 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 - fs::path our_rc_file = "rc.signed"; + fs::path our_rc_file; // use file based logging? bool m_UseFileLogging = false;