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 ();