diff --git a/llarp/config/config.cpp b/llarp/config/config.cpp index 9b094eae9..4dbc60fc7 100644 --- a/llarp/config/config.cpp +++ b/llarp/config/config.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -1377,22 +1378,19 @@ namespace llarp const auto overridesDir = GetOverridesDir(data_dir); if (fs::exists(overridesDir)) { - util::IterDir(overridesDir, [&](const fs::path& overrideFile) { - if (overrideFile.extension() == ".ini") - { - ConfigParser parser; - if (not parser.load_file(overrideFile)) - throw std::runtime_error{"cannot load '" + overrideFile.u8string() + "'"}; - - parser.iter_all_sections([&](std::string_view section, const SectionValues& values) { - for (const auto& pair : values) - { - conf.add_config_value(section, pair.first, pair.second); - } - }); - } - return true; - }); + for (const auto& f : fs::directory_iterator{overridesDir}) + { + if (not f.is_regular_file() or f.path().extension() != ".ini") + continue; + ConfigParser parser; + if (not parser.load_file(f.path())) + throw std::runtime_error{"cannot load '" + f.path().u8string() + "'"}; + + parser.iter_all_sections([&](std::string_view section, const SectionValues& values) { + for (const auto& [k, v] : values) + conf.add_config_value(section, k, v); + }); + } } } diff --git a/llarp/link/link_manager.cpp b/llarp/link/link_manager.cpp index 706019c7e..759225118 100644 --- a/llarp/link/link_manager.cpp +++ b/llarp/link/link_manager.cpp @@ -248,7 +248,6 @@ namespace llarp std::optional id) -> std::shared_ptr { if (id && *id == 0) { - log::critical(logcat, "Stream constructor constructing BTStream (ID:{})", id); auto s = e.make_shared( c, e, [](oxen::quic::Stream& s, uint64_t error_code) { log::warning( @@ -261,8 +260,6 @@ namespace llarp return s; } - log::critical(logcat, "Stream constructor constructing Stream (ID:{})!", id); - return e.make_shared(c, e); } */); } diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index 4a7eb7fee..d2ddc81fb 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -10,7 +10,6 @@ #include #include -static const char skiplist_subdirs[] = "0123456789abcdef"; static const std::string RC_FILE_EXT = ".signed"; namespace llarp @@ -31,19 +30,6 @@ namespace llarp if (not fs::is_directory(nodedbDir)) throw std::runtime_error{fmt::format("nodedb {} is not a directory", nodedbDir)}; - - for (const char& ch : skiplist_subdirs) - { - // this seems to be a problem on all targets - // perhaps cpp17::fs is just as screwed-up - // attempting to create a folder with no name - // what does this mean...? - if (!ch) - continue; - - fs::path sub = nodedbDir / std::string(&ch, 1); - fs::create_directory(sub); - } } NodeDB::NodeDB(fs::path root, std::function)> diskCaller, Router* r) @@ -169,17 +155,9 @@ namespace llarp } fs::path - NodeDB::get_path_by_pubkey(RouterID pubkey) const + NodeDB::get_path_by_pubkey(const RouterID& pubkey) const { - std::string hexString = oxenc::to_hex(pubkey.begin(), pubkey.end()); - std::string skiplistDir; - - const llarp::RouterID r{pubkey}; - std::string fname = r.ToString(); - - skiplistDir += hexString[0]; - fname += RC_FILE_EXT; - return _root / skiplistDir / fname; + return _root / (pubkey.ToString() + RC_FILE_EXT); } bool @@ -875,48 +853,26 @@ namespace llarp if (_root.empty()) return; - std::set purge; + std::vector purge; const auto now = time_now_ms(); - for (const char& ch : skiplist_subdirs) + for (const auto& f : fs::directory_iterator{_root}) { - if (!ch) + if (not f.is_regular_file() or f.path().extension() != RC_FILE_EXT) continue; - std::string p; - p += ch; - fs::path sub = _root / p; - - llarp::util::IterDir(sub, [&](const fs::path& f) -> bool { - // skip files that are not suffixed with .signed - if (not(fs::is_regular_file(f) and f.extension() == RC_FILE_EXT)) - return true; - - RemoteRC rc{}; - - if (not rc.read(f)) - { - // try loading it, purge it if it is junk - purge.emplace(f); - return true; - } - - if (rc.is_expired(now)) - { - // rc expired dont load it and purge it later - purge.emplace(f); - return true; - } + RemoteRC rc{}; - const auto& rid = rc.router_id(); + if (not rc.read(f) or rc.is_expired(now)) + // try loading it, purge it if it is junk or expired + purge.push_back(f); - auto [itr, b] = known_rcs.insert(std::move(rc)); - rc_lookup.emplace(rid, *itr); - known_rids.insert(rid); + const auto& rid = rc.router_id(); - return true; - }); + auto [itr, b] = known_rcs.insert(std::move(rc)); + rc_lookup.emplace(rid, *itr); + known_rids.insert(rid); } if (not purge.empty()) diff --git a/llarp/nodedb.hpp b/llarp/nodedb.hpp index 3f6b73e31..455fd7eb2 100644 --- a/llarp/nodedb.hpp +++ b/llarp/nodedb.hpp @@ -187,7 +187,7 @@ namespace llarp /// get filename of an RC file given its public ident key fs::path - get_path_by_pubkey(RouterID pk) const; + get_path_by_pubkey(const RouterID& pk) const; public: explicit NodeDB( diff --git a/llarp/util/file.hpp b/llarp/util/file.hpp index 39c140673..8629a9d2c 100644 --- a/llarp/util/file.hpp +++ b/llarp/util/file.hpp @@ -25,7 +25,7 @@ namespace llarp::util template < typename Char, std::enable_if_t, int> = 1> - inline size_t + size_t file_to_buffer(const fs::path& filename, Char* buffer, size_t buffer_size) { return file_to_buffer(filename, reinterpret_cast(buffer), buffer_size); @@ -38,7 +38,7 @@ namespace llarp::util /// Same as above, but works via char-like buffer template = 0> - inline void + void buffer_to_file(const fs::path& filename, const Char* buffer, size_t buffer_size) { return buffer_to_file( @@ -73,31 +73,4 @@ namespace llarp::util return std::make_optional(pathname, mode); } - template - static void - IterDir(const fs::path& path, PathVisitor visit) - { - DIR* d = opendir(path.string().c_str()); - if (d == nullptr) - return; - struct dirent* ent = nullptr; - std::set entries; - do - { - ent = readdir(d); - if (not ent) - break; - if (ent->d_name[0] == '.') - continue; - entries.emplace(path / fs::path{ent->d_name}); - } while (ent); - closedir(d); - - for (const auto& p : entries) - { - if (not visit(p)) - return; - } - } - } // namespace llarp::util