From c0a1a8b47cff2a2abb6e06fdece73b8c8507b0d0 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 7 Nov 2016 14:44:32 -0500 Subject: [PATCH] limit number of DH precalculations at the time --- Transports.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Transports.cpp b/Transports.cpp index 39500e8c..358ca4c7 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -48,11 +48,22 @@ namespace transport { while (m_IsRunning) { - int num; - while ((num = m_QueueSize - (int)m_Queue.size ()) > 0) + int num, total = 0; + while ((num = m_QueueSize - (int)m_Queue.size ()) > 0 && total < 20) + { CreateDHKeysPairs (num); - std::unique_lock l(m_AcquiredMutex); - m_Acquired.wait (l); // wait for element gets aquired + 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 l(m_AcquiredMutex); + m_Acquired.wait (l); // wait for element gets aquired + } } } @@ -60,7 +71,6 @@ namespace transport { if (num > 0) { - i2p::crypto::DHKeys dh; for (int i = 0; i < num; i++) { auto pair = std::make_shared ();