mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-18 20:59:57 +00:00
support multiple RouterInfo request callbacks
This commit is contained in:
parent
d8f6c4a93d
commit
4afdca090d
@ -83,8 +83,26 @@ namespace data
|
||||
dest->SetRequestComplete (requestComplete);
|
||||
{
|
||||
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 dest;
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ namespace data
|
||||
std::shared_ptr<I2NPMessage> CreateRequestMessage (const IdentHash& floodfill);
|
||||
|
||||
void SetRequestComplete (const RequestComplete& requestComplete) { m_RequestComplete = requestComplete; };
|
||||
RequestComplete GetRequestComplete () const { return m_RequestComplete; };
|
||||
bool IsRequestComplete () const { return m_RequestComplete != nullptr; };
|
||||
void Success (std::shared_ptr<RouterInfo> r);
|
||||
void Fail ();
|
||||
|
Loading…
x
Reference in New Issue
Block a user