From f494c72006dae0634484b54acffca2659c29576f Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Sat, 30 Mar 2013 19:54:26 -0500 Subject: [PATCH] adds RNG support for endpoints, connections, and processors --- websocketpp/connection.hpp | 9 +++++++-- websocketpp/endpoint.hpp | 5 ++++- websocketpp/impl/connection_impl.hpp | 9 ++++++--- websocketpp/impl/endpoint_impl.hpp | 2 +- websocketpp/processors/hybi07.hpp | 6 ++++-- websocketpp/processors/hybi08.hpp | 6 ++++-- websocketpp/processors/hybi13.hpp | 7 +++++-- 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/websocketpp/connection.hpp b/websocketpp/connection.hpp index b5f4325bae..0c9a24ea28 100644 --- a/websocketpp/connection.hpp +++ b/websocketpp/connection.hpp @@ -155,7 +155,9 @@ public: typedef typename config::con_msg_manager_type con_msg_manager_type; typedef typename con_msg_manager_type::ptr con_msg_manager_ptr; - + + /// Type of RNG + typedef processor::processor processor_type; typedef lib::shared_ptr processor_ptr; @@ -166,7 +168,7 @@ public: typedef session::internal_state::value istate_type; explicit connection(bool is_server, const std::string& ua, alog_type& alog, - elog_type& elog) + elog_type& elog, rng_type & rng) : transport_con_type(is_server,alog,elog) , m_user_agent(ua) , m_state(session::state::CONNECTING) @@ -177,6 +179,7 @@ public: , m_is_server(is_server) , m_alog(alog) , m_elog(elog) + , m_rng(rng) { m_alog.write(log::alevel::devel,"connection constructor"); } @@ -935,6 +938,8 @@ private: alog_type& m_alog; elog_type& m_elog; + rng_type & m_rng; + // Close state /// Close code that was sent on the wire by this endpoint close::status::value m_local_close_code; diff --git a/websocketpp/endpoint.hpp b/websocketpp/endpoint.hpp index 244ea88bcf..4883c9e6dc 100644 --- a/websocketpp/endpoint.hpp +++ b/websocketpp/endpoint.hpp @@ -80,6 +80,9 @@ public: /// Type of our concurrency policy's mutex object typedef typename concurrency_type::mutex_type mutex_type; + /// Type of RNG + typedef typename config::rng_type rng_type; + // TODO: organize these typedef typename connection_type::termination_handler termination_handler; @@ -339,7 +342,7 @@ private: validate_handler m_validate_handler; message_handler m_message_handler; - + rng_type m_rng; // endpoint resources std::set m_connections; diff --git a/websocketpp/impl/connection_impl.hpp b/websocketpp/impl/connection_impl.hpp index 8e5d63b86e..3706369f4c 100644 --- a/websocketpp/impl/connection_impl.hpp +++ b/websocketpp/impl/connection_impl.hpp @@ -1394,7 +1394,8 @@ connection::get_processor(int version) const { new processor::hybi07( transport_con_type::is_secure(), m_is_server, - m_msg_manager + m_msg_manager, + m_rng ) ); break; @@ -1403,7 +1404,8 @@ connection::get_processor(int version) const { new processor::hybi08( transport_con_type::is_secure(), m_is_server, - m_msg_manager + m_msg_manager, + m_rng ) ); break; @@ -1412,7 +1414,8 @@ connection::get_processor(int version) const { new processor::hybi13( transport_con_type::is_secure(), m_is_server, - m_msg_manager + m_msg_manager, + m_rng ) ); break; diff --git a/websocketpp/impl/endpoint_impl.hpp b/websocketpp/impl/endpoint_impl.hpp index 2ccdf4844c..7f8b0b52b9 100644 --- a/websocketpp/impl/endpoint_impl.hpp +++ b/websocketpp/impl/endpoint_impl.hpp @@ -42,7 +42,7 @@ endpoint::create_connection() { // Create a connection on the heap and manage it using a shared pointer connection_ptr con(new connection_type(m_is_server,m_user_agent,m_alog, - m_elog)); + m_elog, m_rng)); connection_weak_ptr w(con); diff --git a/websocketpp/processors/hybi07.hpp b/websocketpp/processors/hybi07.hpp index 1c2addcb7b..04712a1fe6 100644 --- a/websocketpp/processors/hybi07.hpp +++ b/websocketpp/processors/hybi07.hpp @@ -41,9 +41,11 @@ template class hybi07 : public hybi08 { public: typedef typename config::con_msg_manager_type::ptr msg_manager_ptr; + typedef typename config::rng_type rng_type; - explicit hybi07(bool secure,bool server, msg_manager_ptr manager) - : hybi08(secure, server, manager) {} + explicit hybi07(bool secure,bool server, msg_manager_ptr manager, + rng_type& rng) + : hybi08(secure, server, manager, rng) {} int get_version() const { return 7; diff --git a/websocketpp/processors/hybi08.hpp b/websocketpp/processors/hybi08.hpp index 41f21d323c..4658ea4a35 100644 --- a/websocketpp/processors/hybi08.hpp +++ b/websocketpp/processors/hybi08.hpp @@ -44,9 +44,11 @@ public: typedef typename config::request_type request_type; typedef typename config::con_msg_manager_type::ptr msg_manager_ptr; + typedef typename config::rng_type rng_type; - explicit hybi08(bool secure, bool server, msg_manager_ptr manager) - : hybi13(secure, server, manager) {} + explicit hybi08(bool secure, bool server, msg_manager_ptr manager, + rng_type& rng) + : hybi13(secure, server, manager, rng) {} int get_version() const { return 8; diff --git a/websocketpp/processors/hybi13.hpp b/websocketpp/processors/hybi13.hpp index 9aabd2805f..dabc192edd 100644 --- a/websocketpp/processors/hybi13.hpp +++ b/websocketpp/processors/hybi13.hpp @@ -65,14 +65,17 @@ public: typedef typename config::con_msg_manager_type msg_manager_type; typedef typename msg_manager_type::ptr msg_manager_ptr; + typedef typename config::rng_type rng_type; typedef typename config::permessage_compress_type permessage_compress_type; typedef std::pair err_str_pair; - explicit hybi13(bool secure, bool server, msg_manager_ptr manager) + explicit hybi13(bool secure, bool server, msg_manager_ptr manager, + rng_type& rng) : processor(secure,server) , m_msg_manager(manager) + , m_rng(rng) { reset_headers(); } @@ -899,7 +902,7 @@ protected: // utf8 validator // compression state - + rng_type& m_rng; // Overall state of the processor state m_state;