|
|
@ -305,7 +305,7 @@ namespace client |
|
|
|
identHash = hash; |
|
|
|
identHash = hash; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AddressBook::AddressBook (): m_Storage(nullptr), m_IsLoaded (false), m_IsDownloading (false), |
|
|
|
AddressBook::AddressBook (): m_Storage(nullptr), m_IsLoaded (false), |
|
|
|
m_NumRetries (0), m_DefaultSubscription (nullptr), m_SubscriptionsUpdateTimer (nullptr), |
|
|
|
m_NumRetries (0), m_DefaultSubscription (nullptr), m_SubscriptionsUpdateTimer (nullptr), |
|
|
|
m_IsEnabled (true) |
|
|
|
m_IsEnabled (true) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -344,20 +344,28 @@ namespace client |
|
|
|
delete m_SubscriptionsUpdateTimer; |
|
|
|
delete m_SubscriptionsUpdateTimer; |
|
|
|
m_SubscriptionsUpdateTimer = nullptr; |
|
|
|
m_SubscriptionsUpdateTimer = nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
if (m_IsDownloading) |
|
|
|
bool isDownloading = m_Downloading.valid (); |
|
|
|
|
|
|
|
if (isDownloading) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogInfo, "Addressbook: Subscriptions are downloading, abort"); |
|
|
|
if (m_Downloading.wait_for(std::chrono::seconds(0)) == std::future_status::ready) |
|
|
|
for (int i = 0; i < 30; i++) |
|
|
|
isDownloading = false; |
|
|
|
|
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_IsDownloading) |
|
|
|
LogPrint (eLogInfo, "Addressbook: Subscriptions are downloading, abort"); |
|
|
|
|
|
|
|
for (int i = 0; i < 30; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint (eLogInfo, "Addressbook: Subscriptions download complete"); |
|
|
|
if (m_Downloading.wait_for(std::chrono::seconds(1)) == std::future_status::ready) // wait for 1 seconds
|
|
|
|
break; |
|
|
|
{ |
|
|
|
|
|
|
|
isDownloading = false; |
|
|
|
|
|
|
|
LogPrint (eLogInfo, "Addressbook: Subscriptions download complete"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
std::this_thread::sleep_for (std::chrono::seconds (1)); // wait for 1 seconds
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
LogPrint (eLogError, "Addressbook: Subscription download timeout"); |
|
|
|
if (!isDownloading) |
|
|
|
m_IsDownloading = false; |
|
|
|
m_Downloading.get (); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
LogPrint (eLogError, "Addressbook: Subscription download timeout"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (m_Storage) |
|
|
|
if (m_Storage) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -644,7 +652,6 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
void AddressBook::DownloadComplete (bool success, const i2p::data::IdentHash& subscription, const std::string& etag, const std::string& lastModified) |
|
|
|
void AddressBook::DownloadComplete (bool success, const i2p::data::IdentHash& subscription, const std::string& etag, const std::string& lastModified) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_IsDownloading = false; |
|
|
|
|
|
|
|
m_NumRetries++; |
|
|
|
m_NumRetries++; |
|
|
|
int nextUpdateTimeout = m_NumRetries*CONTINIOUS_SUBSCRIPTION_RETRY_TIMEOUT; |
|
|
|
int nextUpdateTimeout = m_NumRetries*CONTINIOUS_SUBSCRIPTION_RETRY_TIMEOUT; |
|
|
|
if (m_NumRetries > CONTINIOUS_SUBSCRIPTION_MAX_NUM_RETRIES || nextUpdateTimeout > CONTINIOUS_SUBSCRIPTION_UPDATE_TIMEOUT) |
|
|
|
if (m_NumRetries > CONTINIOUS_SUBSCRIPTION_MAX_NUM_RETRIES || nextUpdateTimeout > CONTINIOUS_SUBSCRIPTION_UPDATE_TIMEOUT) |
|
|
@ -699,7 +706,13 @@ namespace client |
|
|
|
LogPrint(eLogWarning, "Addressbook: Missing local destination, skip subscription update"); |
|
|
|
LogPrint(eLogWarning, "Addressbook: Missing local destination, skip subscription update"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!m_IsDownloading && dest->IsReady ()) |
|
|
|
bool isDownloading = m_Downloading.valid (); |
|
|
|
|
|
|
|
if (isDownloading && m_Downloading.wait_for(std::chrono::seconds(0)) == std::future_status::ready) // still active?
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_Downloading.get (); |
|
|
|
|
|
|
|
isDownloading = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!isDownloading && dest->IsReady ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_IsLoaded) |
|
|
|
if (!m_IsLoaded) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -708,17 +721,15 @@ namespace client |
|
|
|
std::string defaultSubURL; i2p::config::GetOption("addressbook.defaulturl", defaultSubURL); |
|
|
|
std::string defaultSubURL; i2p::config::GetOption("addressbook.defaulturl", defaultSubURL); |
|
|
|
if (!m_DefaultSubscription) |
|
|
|
if (!m_DefaultSubscription) |
|
|
|
m_DefaultSubscription = std::make_shared<AddressBookSubscription>(*this, defaultSubURL); |
|
|
|
m_DefaultSubscription = std::make_shared<AddressBookSubscription>(*this, defaultSubURL); |
|
|
|
m_IsDownloading = true; |
|
|
|
m_Downloading = std::async (std::launch::async, |
|
|
|
std::thread load_hosts(std::bind (&AddressBookSubscription::CheckUpdates, m_DefaultSubscription)); |
|
|
|
std::bind (&AddressBookSubscription::CheckUpdates, m_DefaultSubscription)); |
|
|
|
load_hosts.detach(); // TODO: use join
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else if (!m_Subscriptions.empty ()) |
|
|
|
else if (!m_Subscriptions.empty ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// pick random subscription
|
|
|
|
// pick random subscription
|
|
|
|
auto ind = rand () % m_Subscriptions.size(); |
|
|
|
auto ind = rand () % m_Subscriptions.size(); |
|
|
|
m_IsDownloading = true; |
|
|
|
m_Downloading = std::async (std::launch::async, |
|
|
|
std::thread load_hosts(std::bind (&AddressBookSubscription::CheckUpdates, m_Subscriptions[ind])); |
|
|
|
std::bind (&AddressBookSubscription::CheckUpdates, m_Subscriptions[ind])); |
|
|
|
load_hosts.detach(); // TODO: use join
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|