From 1340cd0dce086344aee1c727137dd6c5c37d6f39 Mon Sep 17 00:00:00 2001 From: Rick V Date: Tue, 26 May 2020 22:42:01 -0500 Subject: [PATCH] remove some string conversions entirely --- llarp/config/key_manager.cpp | 6 +++--- llarp/crypto/types.cpp | 14 ++++++-------- llarp/crypto/types.hpp | 7 ++++--- llarp/nodedb.cpp | 4 ++-- llarp/router/router.cpp | 4 ++-- llarp/util/bencode.hpp | 4 ++-- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/llarp/config/key_manager.cpp b/llarp/config/key_manager.cpp index 0099fb8c1..0622b59dc 100644 --- a/llarp/config/key_manager.cpp +++ b/llarp/config/key_manager.cpp @@ -186,7 +186,7 @@ namespace llarp bool KeyManager::backupKeyFilesByMoving() const { - std::vector files = {m_rcPath.string(), m_idKeyPath.string(), m_encKeyPath.string(), m_transportKeyPath.string()}; + std::vector files = {m_rcPath, m_idKeyPath, m_encKeyPath, m_transportKeyPath}; for (auto& filepath : files) { @@ -216,7 +216,7 @@ namespace llarp LogInfo("Generating new key", filepath); keygen(key); - if (!key.SaveToFile(filepath.string().c_str())) + if (!key.SaveToFile(filepath)) { LogError("Failed to save new key"); return false; @@ -224,7 +224,7 @@ namespace llarp } LogDebug("Loading key from file ", filepath); - return key.LoadFromFile(filepath.string().c_str()); + return key.LoadFromFile(filepath); } bool diff --git a/llarp/crypto/types.cpp b/llarp/crypto/types.cpp index df39e412a..6a0ab1287 100644 --- a/llarp/crypto/types.cpp +++ b/llarp/crypto/types.cpp @@ -27,9 +27,9 @@ namespace llarp } bool - SecretKey::LoadFromFile(const char* fname) + SecretKey::LoadFromFile(const fs::path& fname) { - std::ifstream f(fname, std::ios::in | std::ios::binary); + std::ifstream f(fname.string(), std::ios::in | std::ios::binary); if (!f.is_open()) { return false; @@ -89,7 +89,7 @@ namespace llarp } bool - SecretKey::SaveToFile(const char* fname) const + SecretKey::SaveToFile(const fs::path& fname) const { std::array tmp; llarp_buffer_t buf(tmp); @@ -97,8 +97,7 @@ namespace llarp { return false; } - const fs::path fpath = std::string(fname); - auto optional_f = llarp::util::OpenFileStream(fpath, std::ios::binary); + auto optional_f = llarp::util::OpenFileStream(fname, std::ios::binary); if (!optional_f) return false; auto& f = *optional_f; @@ -109,10 +108,9 @@ namespace llarp } bool - IdentitySecret::LoadFromFile(const char* fname) + IdentitySecret::LoadFromFile(const fs::path& fname) { - const fs::path fpath = std::string(fname); - auto optional = util::OpenFileStream(fpath, std::ios::binary | std::ios::in); + auto optional = util::OpenFileStream(fname, std::ios::binary | std::ios::in); if (!optional) return false; auto& f = *optional; diff --git a/llarp/crypto/types.hpp b/llarp/crypto/types.hpp index acaa4669d..a7c6ecdb0 100644 --- a/llarp/crypto/types.hpp +++ b/llarp/crypto/types.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -122,10 +123,10 @@ namespace llarp toPrivate(PrivateKey& key) const; bool - LoadFromFile(const char* fname); + LoadFromFile(const fs::path& fname); bool - SaveToFile(const char* fname) const; + SaveToFile(const fs::path& fname) const; }; inline std::ostream& @@ -204,7 +205,7 @@ namespace llarp /// load service node seed from file bool - LoadFromFile(const char* fname); + LoadFromFile(const fs::path& fname); }; inline std::ostream& diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index 196997b83..4380ab6a4 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -301,12 +301,12 @@ llarp_nodedb::loadfile(const fs::path& fpath) llarp::RouterContact rc; if (!rc.Read(fpath)) { - llarp::LogError("failed to read file ", fpath.string()); + llarp::LogError("failed to read file ", fpath); return false; } if (!rc.Verify(llarp::time_now_ms())) { - llarp::LogError(fpath.string(), " contains invalid RC"); + llarp::LogError(fpath, " contains invalid RC"); return false; } { diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 55651c335..f627960ac 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -473,7 +473,7 @@ namespace llarp } if (isListFile) { - if (not BDecodeReadFile(router.string().c_str(), b_list)) + if (not BDecodeReadFile(router, b_list)) { throw std::runtime_error(stringify("failed to read bootstrap list file '", router, "'")); } @@ -481,7 +481,7 @@ namespace llarp else { RouterContact rc; - if (not rc.Read(router.string().c_str())) + if (not rc.Read(router)) { throw std::runtime_error( stringify("failed to decode bootstrap RC, file='", router, "' rc=", rc)); diff --git a/llarp/util/bencode.hpp b/llarp/util/bencode.hpp index 4fcfdb36d..a28900fbc 100644 --- a/llarp/util/bencode.hpp +++ b/llarp/util/bencode.hpp @@ -296,12 +296,12 @@ namespace llarp /// read entire file and decode its contents into t template bool - BDecodeReadFile(const char* fpath, T& t) + BDecodeReadFile(const fs::path& fpath, T& t) { std::vector ptr; { std::ifstream f; - f.open(fpath); + f.open(fpath.string()); if (!f.is_open()) { return false;