Browse Source

handle requests completions in netdb requests thread

pull/2072/head
orignal 4 months ago
parent
commit
c00eb8cf44
  1. 41
      libi2pd/NetDbRequests.cpp

41
libi2pd/NetDbRequests.cpp

@ -173,25 +173,28 @@ namespace data @@ -173,25 +173,28 @@ namespace data
void NetDbRequests::RequestComplete (const IdentHash& ident, std::shared_ptr<RouterInfo> r)
{
std::shared_ptr<RequestedDestination> request;
{
std::unique_lock<std::mutex> 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
}
}
if (request)
{
if (r)
request->Success (r);
else
request->Fail ();
}
GetIOService ().post ([this, ident, r]()
{
std::shared_ptr<RequestedDestination> request;
{
std::unique_lock<std::mutex> 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
}
}
if (request)
{
if (r)
request->Success (r);
else
request->Fail ();
}
});
}
std::shared_ptr<RequestedDestination> NetDbRequests::FindRequest (const IdentHash& ident) const

Loading…
Cancel
Save