diff --git a/AddressBook.cpp b/AddressBook.cpp index 6fdde4eb..f778fff6 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -658,16 +658,23 @@ namespace client if (!leaseSet) { std::unique_lock l(newDataReceivedMutex); - i2p::client::context.GetSharedLocalDestination ()->RequestDestination (m_Ident, + if (i2p::client::context.GetSharedLocalDestination ()->RequestDestination (m_Ident, [&newDataReceived, &leaseSet](std::shared_ptr ls) { leaseSet = ls; newDataReceived.notify_all (); - }); - if (newDataReceived.wait_for (l, std::chrono::seconds (SUBSCRIPTION_REQUEST_TIMEOUT)) == std::cv_status::timeout) + })) + { + if (newDataReceived.wait_for (l, std::chrono::seconds (SUBSCRIPTION_REQUEST_TIMEOUT)) == std::cv_status::timeout) + { + 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: Subscription LeaseSet request timeout expired"); - i2p::client::context.GetSharedLocalDestination ()->CancelDestinationRequest (m_Ident); + LogPrint (eLogError, "Addressbook: Destination is not ready"); return false; } } diff --git a/Destination.cpp b/Destination.cpp index b1ab2a6c..05216d18 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -486,17 +486,17 @@ namespace client 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 (); - m_Service.post ([dest, s](void) + m_Service.post ([dest, notify, s](void) { auto it = s->m_LeaseSetRequests.find (dest); if (it != s->m_LeaseSetRequests.end ()) { auto requestComplete = it->second->requestComplete; s->m_LeaseSetRequests.erase (it); - if (requestComplete) requestComplete (nullptr); + if (notify && requestComplete) requestComplete (nullptr); } }); } diff --git a/Destination.h b/Destination.h index e64508c9..ac7ef7c9 100644 --- a/Destination.h +++ b/Destination.h @@ -79,7 +79,7 @@ namespace client bool IsReady () const { return m_LeaseSet && !m_LeaseSet->IsExpired () && m_Pool->GetOutboundTunnels ().size () > 0; }; std::shared_ptr FindLeaseSet (const i2p::data::IdentHash& ident); 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 std::shared_ptr GetLeaseSet ();