From db7a7204456410fcf294a170358dedba299df93c Mon Sep 17 00:00:00 2001 From: Miguel Portilla Date: Mon, 14 Jul 2014 18:43:03 -0400 Subject: [PATCH] Fix static initializers in RippleSSLContext (RIPD-375) --- src/ripple/common/impl/RippleSSLContext.cpp | 41 +++++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/ripple/common/impl/RippleSSLContext.cpp b/src/ripple/common/impl/RippleSSLContext.cpp index 04e0eb623..3c01e28a0 100644 --- a/src/ripple/common/impl/RippleSSLContext.cpp +++ b/src/ripple/common/impl/RippleSSLContext.cpp @@ -22,10 +22,11 @@ #include #include +#include + #include #include - namespace ripple { class RippleSSLContextImp : public RippleSSLContext @@ -35,6 +36,16 @@ private: // track when SSL connections have last negotiated + struct StaticData + { + StaticData() : set (ripple::get_seconds_clock ()) + { + } + + std::mutex lock; + beast::aged_unordered_set set; + }; + public: RippleSSLContextImp () : RippleSSLContext (m_context) @@ -56,36 +67,34 @@ public: // Do not allow a connection to renegotiate // more than once every 4 minutes - static std::mutex negotiationSetLock; - static beast::aged_unordered_set negotiationSet (ripple::get_seconds_clock ()); - static std::chrono::seconds const minRenegotiationSeconds = std::chrono::minutes (4); + static beast::static_initializer static_data; - std::lock_guard locker (negotiationSetLock); - - auto const expired = (negotiationSet.clock().now() - minRenegotiationSeconds); + auto& sd (static_data.get ()); + std::lock_guard lock (sd.lock); + auto const expired (sd.set.clock().now() - std::chrono::minutes (4)); // Remove expired entries - for (auto iter (negotiationSet.chronological.begin ()); - (iter != negotiationSet.chronological.end ()) && (iter.when () <= expired); - iter = negotiationSet.chronological.begin ()) + for (auto iter (sd.set.chronological.begin ()); + (iter != sd.set.chronological.end ()) && (iter.when () <= expired); + iter = sd.set.chronological.begin ()) { - negotiationSet.erase (iter); + sd.set.erase (iter); } - auto iter = negotiationSet.find (ssl); - if (iter != negotiationSet.end ()) + auto iter = sd.set.find (ssl); + if (iter != sd.set.end ()) { - if (!isNew) + if (! isNew) { // This is a renegotiation and the last negotiation was recent return true; } - negotiationSet.touch (iter); + sd.set.touch (iter); } else { - negotiationSet.emplace (ssl); + sd.set.emplace (ssl); } return false;