|
|
@ -29,7 +29,7 @@ namespace data |
|
|
|
|
|
|
|
|
|
|
|
RequestedDestination::~RequestedDestination () |
|
|
|
RequestedDestination::~RequestedDestination () |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_RequestComplete) m_RequestComplete (nullptr); |
|
|
|
InvokeRequestComplete (nullptr); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<I2NPMessage> RequestedDestination::CreateRequestMessage (std::shared_ptr<const RouterInfo> router, |
|
|
|
std::shared_ptr<I2NPMessage> RequestedDestination::CreateRequestMessage (std::shared_ptr<const RouterInfo> router, |
|
|
@ -69,16 +69,22 @@ namespace data |
|
|
|
m_ExcludedPeers.clear (); |
|
|
|
m_ExcludedPeers.clear (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RequestedDestination::InvokeRequestComplete (std::shared_ptr<RouterInfo> r) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!m_RequestComplete.empty ()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (auto it: m_RequestComplete) |
|
|
|
|
|
|
|
if (it != nullptr) it (r); |
|
|
|
|
|
|
|
m_RequestComplete.clear (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RequestedDestination::Success (std::shared_ptr<RouterInfo> r) |
|
|
|
void RequestedDestination::Success (std::shared_ptr<RouterInfo> r) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_IsActive) |
|
|
|
if (m_IsActive) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_IsActive = false; |
|
|
|
m_IsActive = false; |
|
|
|
if (m_RequestComplete) |
|
|
|
InvokeRequestComplete (r); |
|
|
|
{ |
|
|
|
|
|
|
|
m_RequestComplete (r); |
|
|
|
|
|
|
|
m_RequestComplete = nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -87,11 +93,7 @@ namespace data |
|
|
|
if (m_IsActive) |
|
|
|
if (m_IsActive) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_IsActive = false; |
|
|
|
m_IsActive = false; |
|
|
|
if (m_RequestComplete) |
|
|
|
InvokeRequestComplete (nullptr); |
|
|
|
{ |
|
|
|
|
|
|
|
m_RequestComplete (nullptr); |
|
|
|
|
|
|
|
m_RequestComplete = nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -154,26 +156,21 @@ namespace data |
|
|
|
{ |
|
|
|
{ |
|
|
|
// request RouterInfo directly
|
|
|
|
// request RouterInfo directly
|
|
|
|
auto dest = m_RequestedDestinationsPool.AcquireSharedMt (destination, isExploratory, direct); |
|
|
|
auto dest = m_RequestedDestinationsPool.AcquireSharedMt (destination, isExploratory, direct); |
|
|
|
dest->SetRequestComplete (requestComplete); |
|
|
|
if (requestComplete) |
|
|
|
|
|
|
|
dest->AddRequestComplete (requestComplete); |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex); |
|
|
|
auto ret = m_RequestedDestinations.emplace (destination, dest); |
|
|
|
auto ret = m_RequestedDestinations.emplace (destination, dest); |
|
|
|
if (!ret.second) // not inserted
|
|
|
|
if (!ret.second) // not inserted
|
|
|
|
{ |
|
|
|
{ |
|
|
|
dest->SetRequestComplete (nullptr); // don't call requestComplete in destructor
|
|
|
|
dest->ResetRequestComplete (); // don't call requestComplete in destructor
|
|
|
|
dest = ret.first->second; // existing one
|
|
|
|
dest = ret.first->second; // existing one
|
|
|
|
if (requestComplete && dest->IsActive ()) |
|
|
|
if (requestComplete) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto prev = dest->GetRequestComplete (); |
|
|
|
if (dest->IsActive ()) |
|
|
|
if (prev) // if already set
|
|
|
|
dest->AddRequestComplete (requestComplete); |
|
|
|
dest->SetRequestComplete ( |
|
|
|
|
|
|
|
[requestComplete, prev](std::shared_ptr<RouterInfo> r) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
prev (r); // call previous
|
|
|
|
|
|
|
|
requestComplete (r); // then new
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
else |
|
|
|
else |
|
|
|
dest->SetRequestComplete (requestComplete); |
|
|
|
requestComplete (nullptr); |
|
|
|
} |
|
|
|
} |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|