From b75e4188795acd223f20a11f27da5a87f043c6f3 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 22 May 2024 13:43:00 -0400 Subject: [PATCH] request destination in netdb requests thread --- libi2pd/NetDb.cpp | 10 +++------- libi2pd/NetDbRequests.cpp | 23 ++++++++++++++++++++++- libi2pd/NetDbRequests.h | 2 ++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index 2ec8097c..f29ed7aa 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -807,14 +807,10 @@ namespace data void NetDb::RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete, bool direct) { if (direct && i2p::transport::transports.RoutesRestricted ()) direct = false; // always use tunnels for restricted routes - auto dest = m_Requests->CreateRequest (destination, false, direct, requestComplete); // non-exploratory - if (dest) - { - if (!m_Requests->SendNextRequest (dest)) - m_Requests->RequestComplete (destination, nullptr); - } + if (m_Requests) + m_Requests->PostRequestDestination (destination, requestComplete, direct); else - LogPrint (eLogWarning, "NetDb: Destination ", destination.ToBase64(), " is requested already or cached"); + LogPrint (eLogError, "NetDb: Requests is null"); } void NetDb::RequestDestinationFrom (const IdentHash& destination, const IdentHash & from, bool exploratory, RequestedDestination::RequestComplete requestComplete) diff --git a/libi2pd/NetDbRequests.cpp b/libi2pd/NetDbRequests.cpp index fae838c3..900fc6c4 100644 --- a/libi2pd/NetDbRequests.cpp +++ b/libi2pd/NetDbRequests.cpp @@ -405,7 +405,7 @@ namespace data /* if(m_FloodfillBootstrap) RequestDestinationFrom(router, m_FloodfillBootstrap->GetIdentHash(), true); else */if (!IsRouterBanned (router)) - netdb.RequestDestination (router); + RequestDestination (router, nullptr, true); else LogPrint (eLogDebug, "NetDbReq: Router ", peerHash, " is banned. Skipped"); } @@ -413,5 +413,26 @@ namespace data LogPrint (eLogDebug, "NetDbReq: [:|||:]"); } } + + void NetDbRequests::PostRequestDestination (const IdentHash& destination, + const RequestedDestination::RequestComplete& requestComplete, bool direct) + { + GetIOService ().post ([this, destination, requestComplete, direct]() + { + RequestDestination (destination, requestComplete, direct); + }); + } + + void NetDbRequests::RequestDestination (const IdentHash& destination, const RequestedDestination::RequestComplete& requestComplete, bool direct) + { + auto dest = CreateRequest (destination, false, direct, requestComplete); // non-exploratory + if (dest) + { + if (!SendNextRequest (dest)) + RequestComplete (destination, nullptr); + } + else + LogPrint (eLogWarning, "NetDbReq: Destination ", destination.ToBase64(), " is requested already or cached"); + } } } diff --git a/libi2pd/NetDbRequests.h b/libi2pd/NetDbRequests.h index c18c5cd3..47d2fafa 100644 --- a/libi2pd/NetDbRequests.h +++ b/libi2pd/NetDbRequests.h @@ -86,10 +86,12 @@ namespace data bool SendNextRequest (std::shared_ptr dest); void PostDatabaseSearchReplyMsg (std::shared_ptr msg); + void PostRequestDestination (const IdentHash& destination, const RequestedDestination::RequestComplete& requestComplete, bool direct); private: void HandleDatabaseSearchReplyMsg (std::shared_ptr msg); + void RequestDestination (const IdentHash& destination, const RequestedDestination::RequestComplete& requestComplete, bool direct); void ManageRequests (); // timer void ScheduleManageRequests ();