mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
fixed potential deadlock
This commit is contained in:
parent
63e6731207
commit
56a60772a4
|
@ -658,16 +658,23 @@ namespace client
|
||||||
if (!leaseSet)
|
if (!leaseSet)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(newDataReceivedMutex);
|
std::unique_lock<std::mutex> l(newDataReceivedMutex);
|
||||||
i2p::client::context.GetSharedLocalDestination ()->RequestDestination (m_Ident,
|
if (i2p::client::context.GetSharedLocalDestination ()->RequestDestination (m_Ident,
|
||||||
[&newDataReceived, &leaseSet](std::shared_ptr<i2p::data::LeaseSet> ls)
|
[&newDataReceived, &leaseSet](std::shared_ptr<i2p::data::LeaseSet> ls)
|
||||||
{
|
{
|
||||||
leaseSet = ls;
|
leaseSet = ls;
|
||||||
newDataReceived.notify_all ();
|
newDataReceived.notify_all ();
|
||||||
});
|
}))
|
||||||
if (newDataReceived.wait_for (l, std::chrono::seconds (SUBSCRIPTION_REQUEST_TIMEOUT)) == std::cv_status::timeout)
|
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "Addressbook: Subscription LeaseSet request timeout expired");
|
if (newDataReceived.wait_for (l, std::chrono::seconds (SUBSCRIPTION_REQUEST_TIMEOUT)) == std::cv_status::timeout)
|
||||||
i2p::client::context.GetSharedLocalDestination ()->CancelDestinationRequest (m_Ident);
|
{
|
||||||
|
LogPrint (eLogError, "Addressbook: Subscription LeaseSet request timeout expired");
|
||||||
|
i2p::client::context.GetSharedLocalDestination ()->CancelDestinationRequest (m_Ident, false); // don't notify, because we know it already
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint (eLogError, "Addressbook: Destination is not ready");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -486,17 +486,17 @@ namespace client
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LeaseSetDestination::CancelDestinationRequest (const i2p::data::IdentHash& dest)
|
void LeaseSetDestination::CancelDestinationRequest (const i2p::data::IdentHash& dest, bool notify)
|
||||||
{
|
{
|
||||||
auto s = shared_from_this ();
|
auto s = shared_from_this ();
|
||||||
m_Service.post ([dest, s](void)
|
m_Service.post ([dest, notify, s](void)
|
||||||
{
|
{
|
||||||
auto it = s->m_LeaseSetRequests.find (dest);
|
auto it = s->m_LeaseSetRequests.find (dest);
|
||||||
if (it != s->m_LeaseSetRequests.end ())
|
if (it != s->m_LeaseSetRequests.end ())
|
||||||
{
|
{
|
||||||
auto requestComplete = it->second->requestComplete;
|
auto requestComplete = it->second->requestComplete;
|
||||||
s->m_LeaseSetRequests.erase (it);
|
s->m_LeaseSetRequests.erase (it);
|
||||||
if (requestComplete) requestComplete (nullptr);
|
if (notify && requestComplete) requestComplete (nullptr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ namespace client
|
||||||
bool IsReady () const { return m_LeaseSet && !m_LeaseSet->IsExpired () && m_Pool->GetOutboundTunnels ().size () > 0; };
|
bool IsReady () const { return m_LeaseSet && !m_LeaseSet->IsExpired () && m_Pool->GetOutboundTunnels ().size () > 0; };
|
||||||
std::shared_ptr<const i2p::data::LeaseSet> FindLeaseSet (const i2p::data::IdentHash& ident);
|
std::shared_ptr<const i2p::data::LeaseSet> FindLeaseSet (const i2p::data::IdentHash& ident);
|
||||||
bool RequestDestination (const i2p::data::IdentHash& dest, RequestComplete requestComplete = nullptr);
|
bool RequestDestination (const i2p::data::IdentHash& dest, RequestComplete requestComplete = nullptr);
|
||||||
void CancelDestinationRequest (const i2p::data::IdentHash& dest);
|
void CancelDestinationRequest (const i2p::data::IdentHash& dest, bool notify = true);
|
||||||
|
|
||||||
// implements GarlicDestination
|
// implements GarlicDestination
|
||||||
std::shared_ptr<const i2p::data::LocalLeaseSet> GetLeaseSet ();
|
std::shared_ptr<const i2p::data::LocalLeaseSet> GetLeaseSet ();
|
||||||
|
|
Loading…
Reference in a new issue