Skip to content

Commit

Permalink
handle requests completions in netdb requests thread
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed May 22, 2024
1 parent 265bb8b commit c00eb8c
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions libi2pd/NetDbRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c00eb8c

Please sign in to comment.