From caf36cb638aea639a92151abb45cc762f22afb74 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 6 Apr 2026 15:28:58 -0400 Subject: [PATCH] persist.netdbinterval param --- libi2pd/Config.cpp | 1 + libi2pd/NetDb.cpp | 9 ++++++++- libi2pd/NetDb.hpp | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libi2pd/Config.cpp b/libi2pd/Config.cpp index 3b15fc88..beeff501 100644 --- a/libi2pd/Config.cpp +++ b/libi2pd/Config.cpp @@ -359,6 +359,7 @@ namespace config { persist.add_options() ("persist.profiles", value()->default_value(true), "Persist peer profiles (default: true)") ("persist.addressbook", value()->default_value(true), "Persist full addresses (default: true)") + ("persist.netdbinterval", value()->default_value(60), "NetDb persist interval in seconds (default: 60)") ; options_description cpuext("CPU encryption extensions options. Deprecated"); diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index 89d24b79..c6c68237 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -39,6 +39,7 @@ namespace data NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr), m_Storage("netDb", "r", "routerInfo-", "dat"), m_PersistProfiles (true), + m_NetDbPersistInterval (NETDB_MIN_PERSIST_INTERVAL*1000LL), m_LastExploratorySelectionUpdateTime (0), m_Rng(i2p::util::GetMonotonicMicroseconds () % 1000000LL) { } @@ -85,6 +86,12 @@ namespace data i2p::config::GetOption("persist.profiles", m_PersistProfiles); + int persistInterval = 0; + i2p::config::GetOption("persist.netdbinterval", persistInterval); + if (persistInterval < NETDB_MIN_PERSIST_INTERVAL) persistInterval = NETDB_MIN_PERSIST_INTERVAL; + if (persistInterval > NETDB_MAX_PERSIST_INTERVAL) persistInterval = NETDB_MAX_PERSIST_INTERVAL; + m_NetDbPersistInterval = persistInterval*1000LL; + m_IsRunning = true; m_Thread = new std::thread (std::bind (&NetDb::Run, this)); } @@ -154,7 +161,7 @@ namespace data continue; // don't manage netdb when offline or transports are not running uint64_t mts = i2p::util::GetMonotonicMilliseconds (); - if (mts >= lastManage + 60000) // manage routers and leasesets every minute + if (mts >= lastManage + m_NetDbPersistInterval) // manage routers and leasesets every persist.netdbinterval { if (lastManage) { diff --git a/libi2pd/NetDb.hpp b/libi2pd/NetDb.hpp index 4464a9e9..c60bcc24 100644 --- a/libi2pd/NetDb.hpp +++ b/libi2pd/NetDb.hpp @@ -60,6 +60,8 @@ namespace data const int NETDB_EXPLORATORY_SELECTION_UPDATE_INTERVAL = 82; // in seconds. for floodfill const int NETDB_NEXT_DAY_ROUTER_INFO_THRESHOLD = 45; // in minutes const int NETDB_NEXT_DAY_LEASESET_THRESHOLD = 10; // in minutes + const int NETDB_MIN_PERSIST_INTERVAL = 15; // 15 secs in seconds + const int NETDB_MAX_PERSIST_INTERVAL = 1800; // 30 minutes in seconds /** function for visiting a leaseset stored in a floodfill */ typedef std::function)> LeaseSetVisitor; @@ -195,6 +197,7 @@ namespace data bool m_PersistProfiles; std::future m_SavingProfiles, m_DeletingProfiles, m_ApplyingProfileUpdates, m_PersistingRouters; + uint64_t m_NetDbPersistInterval; // in milliseconds std::vector > m_ExploratorySelection; uint64_t m_LastExploratorySelectionUpdateTime; // in monotonic seconds