From 4100249313be63007e219d18d68002c452aca87c Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 31 May 2024 21:11:47 -0400 Subject: [PATCH] removed bootstrap from floodfill. Removed requested destinations mutex --- libi2pd/Config.cpp | 2 +- libi2pd/NetDb.cpp | 36 ---------------------------- libi2pd/NetDb.hpp | 6 +---- libi2pd/NetDbRequests.cpp | 49 ++++++++++++++++----------------------- libi2pd/NetDbRequests.h | 5 ++-- 5 files changed, 24 insertions(+), 74 deletions(-) diff --git a/libi2pd/Config.cpp b/libi2pd/Config.cpp index a6885178..c9a7b2cc 100644 --- a/libi2pd/Config.cpp +++ b/libi2pd/Config.cpp @@ -205,7 +205,7 @@ namespace config { reseed.add_options() ("reseed.verify", value()->default_value(false), "Verify .su3 signature") ("reseed.threshold", value()->default_value(25), "Minimum number of known routers before requesting reseed") - ("reseed.floodfill", value()->default_value(""), "Path to router info of floodfill to reseed from") + ("reseed.floodfill", value()->default_value(""), "Ignored. Always empty") ("reseed.file", value()->default_value(""), "Path to local .su3 file or HTTPS URL to reseed from") ("reseed.zipfile", value()->default_value(""), "Path to local .zip file to reseed from") ("reseed.proxy", value()->default_value(""), "url for reseed proxy, supports http/socks") diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index 246d1888..80e6a964 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -478,28 +478,6 @@ namespace data m_Reseeder->LoadCertificates (); // we need certificates for SU3 verification } - // try reseeding from floodfill first if specified - std::string riPath; i2p::config::GetOption("reseed.floodfill", riPath); - if (!riPath.empty()) - { - auto ri = std::make_shared(riPath); - if (ri->IsFloodfill()) - { - const uint8_t * riData = ri->GetBuffer(); - int riLen = ri->GetBufferLen(); - if (!i2p::data::netdb.AddRouterInfo(riData, riLen)) - { - // bad router info - LogPrint(eLogError, "NetDb: Bad router info"); - return; - } - m_FloodfillBootstrap = ri; - //ReseedFromFloodfill(*ri); - // don't try reseed servers if trying to bootstrap from floodfill - return; - } - } - m_Reseeder->Bootstrap (); } @@ -792,20 +770,6 @@ namespace data LogPrint (eLogError, "NetDb: Requests is null"); } - void NetDb::RequestDestinationFrom (const IdentHash& destination, const IdentHash & from, bool exploratory, RequestedDestination::RequestComplete requestComplete) - { - auto dest = m_Requests->CreateRequest (destination, exploratory, true, requestComplete); // non-exploratory - if (!dest) - { - LogPrint (eLogWarning, "NetDb: Destination ", destination.ToBase64(), " is requested already"); - return; - } - if (CheckLogLevel (eLogDebug)) - LogPrint(eLogDebug, "NetDb: Destination ", destination.ToBase64(), " being requested directly from ", from.ToBase64()); - // direct - transports.SendMessage (from, dest->CreateRequestMessage (nullptr, nullptr)); - } - void NetDb::HandleNTCP2RouterInfoMsg (std::shared_ptr m) { uint8_t flood = m->GetPayload ()[0] & NTCP2_ROUTER_INFO_FLAG_REQUEST_FLOOD; diff --git a/libi2pd/NetDb.hpp b/libi2pd/NetDb.hpp index 7fe0e0d5..5691a458 100644 --- a/libi2pd/NetDb.hpp +++ b/libi2pd/NetDb.hpp @@ -83,8 +83,7 @@ namespace data std::shared_ptr FindRouterProfile (const IdentHash& ident) const; void RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete = nullptr, bool direct = true); - void RequestDestinationFrom (const IdentHash& destination, const IdentHash & from, bool exploritory, RequestedDestination::RequestComplete requestComplete = nullptr); - + std::shared_ptr GetRandomRouter () const; std::shared_ptr GetRandomRouter (std::shared_ptr compatibleWith, bool reverse, bool endpoint) const; std::shared_ptr GetHighBandwidthRandomRouter (std::shared_ptr compatibleWith, bool reverse, bool endpoint) const; @@ -185,9 +184,6 @@ namespace data bool m_PersistProfiles; std::future m_SavingProfiles, m_DeletingProfiles, m_PersistingRouters; - /** router info we are bootstrapping from or nullptr if we are not currently doing that*/ - std::shared_ptr m_FloodfillBootstrap; - std::vector > m_ExploratorySelection; uint64_t m_LastExploratorySelectionUpdateTime; // in monotonic seconds diff --git a/libi2pd/NetDbRequests.cpp b/libi2pd/NetDbRequests.cpp index e323469d..a17bcdb5 100644 --- a/libi2pd/NetDbRequests.cpp +++ b/libi2pd/NetDbRequests.cpp @@ -157,23 +157,21 @@ namespace data auto dest = m_RequestedDestinationsPool.AcquireSharedMt (destination, isExploratory, direct); if (requestComplete) dest->AddRequestComplete (requestComplete); - { - std::unique_lock l(m_RequestedDestinationsMutex); - auto ret = m_RequestedDestinations.emplace (destination, dest); - if (!ret.second) // not inserted + + auto ret = m_RequestedDestinations.emplace (destination, dest); + if (!ret.second) // not inserted + { + dest->ResetRequestComplete (); // don't call requestComplete in destructor + dest = ret.first->second; // existing one + if (requestComplete) { - dest->ResetRequestComplete (); // don't call requestComplete in destructor - dest = ret.first->second; // existing one - if (requestComplete) - { - if (dest->IsActive ()) - dest->AddRequestComplete (requestComplete); - else - requestComplete (nullptr); - } - return nullptr; + if (dest->IsActive ()) + dest->AddRequestComplete (requestComplete); + else + requestComplete (nullptr); } - } + return nullptr; + } return dest; } @@ -182,16 +180,13 @@ namespace data GetIOService ().post ([this, ident, r]() { std::shared_ptr request; + auto it = m_RequestedDestinations.find (ident); + if (it != m_RequestedDestinations.end ()) { - std::unique_lock l(m_RequestedDestinationsMutex); - auto it = m_RequestedDestinations.find (ident); - if (it != m_RequestedDestinations.end ()) - { - request = it->second; - if (request->IsExploratory ()) - m_RequestedDestinations.erase (it); - // otherwise cache for a while - } + request = it->second; + if (request->IsExploratory ()) + m_RequestedDestinations.erase (it); + // otherwise cache for a while } if (request) { @@ -205,7 +200,6 @@ namespace data std::shared_ptr NetDbRequests::FindRequest (const IdentHash& ident) const { - std::unique_lock l(m_RequestedDestinationsMutex); auto it = m_RequestedDestinations.find (ident); if (it != m_RequestedDestinations.end ()) return it->second; @@ -215,7 +209,6 @@ namespace data void NetDbRequests::ManageRequests () { uint64_t ts = i2p::util::GetSecondsSinceEpoch (); - std::unique_lock l(m_RequestedDestinationsMutex); for (auto it = m_RequestedDestinations.begin (); it != m_RequestedDestinations.end ();) { auto& dest = it->second; @@ -424,9 +417,7 @@ namespace data { // router with ident not found or too old (1 hour) LogPrint (eLogDebug, "NetDbReq: Found new/outdated router. Requesting RouterInfo..."); - /* if(m_FloodfillBootstrap) - RequestDestinationFrom(router, m_FloodfillBootstrap->GetIdentHash(), true); - else */if (!IsRouterBanned (router)) + if (!IsRouterBanned (router)) RequestDestination (router, nullptr, true); else LogPrint (eLogDebug, "NetDbReq: Router ", router.ToBase64 (), " is banned. Skipped"); diff --git a/libi2pd/NetDbRequests.h b/libi2pd/NetDbRequests.h index ea9b8537..1ce5f8c1 100644 --- a/libi2pd/NetDbRequests.h +++ b/libi2pd/NetDbRequests.h @@ -86,14 +86,14 @@ namespace data void Start (); void Stop (); - std::shared_ptr CreateRequest (const IdentHash& destination, bool isExploratory, - bool direct = false, RequestedDestination::RequestComplete requestComplete = nullptr); void RequestComplete (const IdentHash& ident, std::shared_ptr r); void PostDatabaseSearchReplyMsg (std::shared_ptr msg); void PostRequestDestination (const IdentHash& destination, const RequestedDestination::RequestComplete& requestComplete, bool direct); private: + std::shared_ptr CreateRequest (const IdentHash& destination, bool isExploratory, + bool direct = false, RequestedDestination::RequestComplete requestComplete = nullptr); std::shared_ptr FindRequest (const IdentHash& ident) const; bool SendNextRequest (std::shared_ptr dest); @@ -114,7 +114,6 @@ namespace data private: - mutable std::mutex m_RequestedDestinationsMutex; std::unordered_map > m_RequestedDestinations; std::list m_DiscoveredRouterHashes; i2p::util::MemoryPoolMt m_RequestedDestinationsPool;