mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
handle default subscription in separate thread
This commit is contained in:
parent
793e80490c
commit
2dd5de4373
|
@ -260,8 +260,6 @@ namespace client
|
||||||
m_Storage = nullptr;
|
m_Storage = nullptr;
|
||||||
}
|
}
|
||||||
m_DefaultSubscription = nullptr;
|
m_DefaultSubscription = nullptr;
|
||||||
for (auto& it: m_Subscriptions)
|
|
||||||
delete it;
|
|
||||||
m_Subscriptions.clear ();
|
m_Subscriptions.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +401,7 @@ namespace client
|
||||||
{
|
{
|
||||||
getline(f, s);
|
getline(f, s);
|
||||||
if (!s.length()) continue; // skip empty line
|
if (!s.length()) continue; // skip empty line
|
||||||
m_Subscriptions.push_back (new AddressBookSubscription (*this, s));
|
m_Subscriptions.push_back (std::make_shared<AddressBookSubscription> (*this, s));
|
||||||
}
|
}
|
||||||
LogPrint (eLogInfo, "Addressbook: ", m_Subscriptions.size (), " subscriptions urls loaded");
|
LogPrint (eLogInfo, "Addressbook: ", m_Subscriptions.size (), " subscriptions urls loaded");
|
||||||
}
|
}
|
||||||
|
@ -462,7 +460,7 @@ namespace client
|
||||||
int nextUpdateTimeout = CONTINIOUS_SUBSCRIPTION_RETRY_TIMEOUT;
|
int nextUpdateTimeout = CONTINIOUS_SUBSCRIPTION_RETRY_TIMEOUT;
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
if (m_DefaultSubscription) m_DefaultSubscription.reset (nullptr);
|
if (m_DefaultSubscription) m_DefaultSubscription = nullptr;
|
||||||
if (m_IsLoaded)
|
if (m_IsLoaded)
|
||||||
nextUpdateTimeout = CONTINIOUS_SUBSCRIPTION_UPDATE_TIMEOUT;
|
nextUpdateTimeout = CONTINIOUS_SUBSCRIPTION_UPDATE_TIMEOUT;
|
||||||
else
|
else
|
||||||
|
@ -516,16 +514,17 @@ namespace client
|
||||||
// download it from http://i2p-projekt.i2p/hosts.txt
|
// download it from http://i2p-projekt.i2p/hosts.txt
|
||||||
LogPrint (eLogInfo, "Addressbook: trying to download it from default subscription.");
|
LogPrint (eLogInfo, "Addressbook: trying to download it from default subscription.");
|
||||||
if (!m_DefaultSubscription)
|
if (!m_DefaultSubscription)
|
||||||
m_DefaultSubscription.reset (new AddressBookSubscription (*this, DEFAULT_SUBSCRIPTION_ADDRESS));
|
m_DefaultSubscription = std::make_shared<AddressBookSubscription>(*this, DEFAULT_SUBSCRIPTION_ADDRESS);
|
||||||
m_IsDownloading = true;
|
m_IsDownloading = true;
|
||||||
m_DefaultSubscription->CheckUpdates ();
|
std::thread load_hosts(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_IsDownloading = true;
|
||||||
std::thread load_hosts(&AddressBookSubscription::CheckUpdates, m_Subscriptions[ind]);
|
std::thread load_hosts(std::bind (&AddressBookSubscription::CheckUpdates, m_Subscriptions[ind]));
|
||||||
load_hosts.detach(); // TODO: use join
|
load_hosts.detach(); // TODO: use join
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,8 +102,8 @@ namespace client
|
||||||
std::map<uint32_t, std::string> m_Lookups; // nonce -> address
|
std::map<uint32_t, std::string> m_Lookups; // nonce -> address
|
||||||
AddressBookStorage * m_Storage;
|
AddressBookStorage * m_Storage;
|
||||||
volatile bool m_IsLoaded, m_IsDownloading;
|
volatile bool m_IsLoaded, m_IsDownloading;
|
||||||
std::vector<AddressBookSubscription *> m_Subscriptions;
|
std::vector<std::shared_ptr<AddressBookSubscription> > m_Subscriptions;
|
||||||
std::unique_ptr<AddressBookSubscription> m_DefaultSubscription; // in case if we don't know any addresses yet
|
std::shared_ptr<AddressBookSubscription> m_DefaultSubscription; // in case if we don't know any addresses yet
|
||||||
boost::asio::deadline_timer * m_SubscriptionsUpdateTimer;
|
boost::asio::deadline_timer * m_SubscriptionsUpdateTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue