Browse Source

support multiple RouterInfo request callbacks

pull/2010/head
orignal 11 months ago
parent
commit
4afdca090d
  1. 20
      libi2pd/NetDbRequests.cpp
  2. 1
      libi2pd/NetDbRequests.h

20
libi2pd/NetDbRequests.cpp

@ -83,9 +83,27 @@ namespace data
dest->SetRequestComplete (requestComplete); dest->SetRequestComplete (requestComplete);
{ {
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex); std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
if (!m_RequestedDestinations.emplace (destination, dest).second) // not inserted auto ret = m_RequestedDestinations.emplace (destination, dest);
if (!ret.second) // not inserted
{
dest->SetRequestComplete (nullptr); // don't call requestComplete in destructor
if (requestComplete)
{
auto prev = ret.first->second->GetRequestComplete ();
if (prev) // if already set
ret.first->second->SetRequestComplete (
[requestComplete, prev](std::shared_ptr<RouterInfo> r)
{
prev (r); // call previous
requestComplete (r); // then new
});
else
ret.first->second->SetRequestComplete (requestComplete);
}
return nullptr; return nullptr;
} }
}
return dest; return dest;
} }

1
libi2pd/NetDbRequests.h

@ -46,6 +46,7 @@ namespace data
std::shared_ptr<I2NPMessage> CreateRequestMessage (const IdentHash& floodfill); std::shared_ptr<I2NPMessage> CreateRequestMessage (const IdentHash& floodfill);
void SetRequestComplete (const RequestComplete& requestComplete) { m_RequestComplete = requestComplete; }; void SetRequestComplete (const RequestComplete& requestComplete) { m_RequestComplete = requestComplete; };
RequestComplete GetRequestComplete () const { return m_RequestComplete; };
bool IsRequestComplete () const { return m_RequestComplete != nullptr; }; bool IsRequestComplete () const { return m_RequestComplete != nullptr; };
void Success (std::shared_ptr<RouterInfo> r); void Success (std::shared_ptr<RouterInfo> r);
void Fail (); void Fail ();

Loading…
Cancel
Save