mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
limit number of DH precalculations at the time
This commit is contained in:
parent
bd82e81e26
commit
c0a1a8b47c
|
@ -48,19 +48,29 @@ namespace transport
|
||||||
{
|
{
|
||||||
while (m_IsRunning)
|
while (m_IsRunning)
|
||||||
{
|
{
|
||||||
int num;
|
int num, total = 0;
|
||||||
while ((num = m_QueueSize - (int)m_Queue.size ()) > 0)
|
while ((num = m_QueueSize - (int)m_Queue.size ()) > 0 && total < 20)
|
||||||
|
{
|
||||||
CreateDHKeysPairs (num);
|
CreateDHKeysPairs (num);
|
||||||
|
total += num;
|
||||||
|
}
|
||||||
|
if (total >= 20)
|
||||||
|
{
|
||||||
|
LogPrint (eLogWarning, "Transports: ", total, " DH keys generated at the time");
|
||||||
|
std::this_thread::sleep_for (std::chrono::seconds(1)); // take a break
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
std::unique_lock<std::mutex> l(m_AcquiredMutex);
|
std::unique_lock<std::mutex> l(m_AcquiredMutex);
|
||||||
m_Acquired.wait (l); // wait for element gets aquired
|
m_Acquired.wait (l); // wait for element gets aquired
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DHKeysPairSupplier::CreateDHKeysPairs (int num)
|
void DHKeysPairSupplier::CreateDHKeysPairs (int num)
|
||||||
{
|
{
|
||||||
if (num > 0)
|
if (num > 0)
|
||||||
{
|
{
|
||||||
i2p::crypto::DHKeys dh;
|
|
||||||
for (int i = 0; i < num; i++)
|
for (int i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
auto pair = std::make_shared<i2p::crypto::DHKeys> ();
|
auto pair = std::make_shared<i2p::crypto::DHKeys> ();
|
||||||
|
|
Loading…
Reference in a new issue