diff options
author | Kozoriz <kozorizandriy@gmail.com> | 2016-02-29 10:38:32 +0200 |
---|---|---|
committer | Kozoriz <kozorizandriy@gmail.com> | 2016-03-04 10:11:53 +0200 |
commit | 35abe5200347d11e7b6012fd45176f2bd731abe4 (patch) | |
tree | 743fcbba640441aa1a7d05a2dc7ba073d548a67c /src | |
parent | 417961e8ae88a7b725e8311789a0851bf48dfa22 (diff) | |
download | sdl_core-35abe5200347d11e7b6012fd45176f2bd731abe4.tar.gz |
Remove singleton from ProtocolHandler
Remove singletone.
Corrected tests.
Created new mocks and settings.
Related to : APPLINK-21440
Diffstat (limited to 'src')
15 files changed, 540 insertions, 596 deletions
diff --git a/src/components/include/protocol_handler/protocol_handler.h b/src/components/include/protocol_handler/protocol_handler.h index 9bb77ae483..d124f5ab8f 100644 --- a/src/components/include/protocol_handler/protocol_handler.h +++ b/src/components/include/protocol_handler/protocol_handler.h @@ -33,6 +33,7 @@ #define SRC_COMPONENTS_INCLUDE_PROTOCOL_HANDLER_PROTOCOL_HANDLER_H_ #include "protocol/common.h" +#include "protocol_handler/protocol_handler_settings.h" /** *\namespace protocol_handlerHandler @@ -100,6 +101,11 @@ class ProtocolHandler { virtual void SendEndService(int32_t connection_id, uint8_t session_id, uint8_t service_type) = 0; + /** + * \brief Protocol handler settings getter + * \return pointer to protocol handler settings class + */ + virtual const ProtocolHandlerSettings& get_settings() const = 0; protected: /** diff --git a/src/components/include/protocol_handler/protocol_handler_settings.h b/src/components/include/protocol_handler/protocol_handler_settings.h new file mode 100644 index 0000000000..6da476052f --- /dev/null +++ b/src/components/include/protocol_handler/protocol_handler_settings.h @@ -0,0 +1,46 @@ +#ifndef SRC_COMPONENTS_INCLUDE_PROTOCOL_HANDLER_PROTOCOL_HANDLER_SETTINGS_H_ +#define SRC_COMPONENTS_INCLUDE_PROTOCOL_HANDLER_PROTOCOL_HANDLER_SETTINGS_H_ +#include <stdint.h> +#include <string> +#include <vector> + +namespace protocol_handler { +/** + * \class ProtocolHandlerSettings + * \brief Interface for protocol handler component settings. + */ +class ProtocolHandlerSettings { + public: + virtual ~ProtocolHandlerSettings() {} + + virtual size_t maximum_payload_size() const = 0; + virtual size_t message_frequency_count() const = 0; + virtual size_t message_frequency_time() const = 0; + virtual bool malformed_message_filtering() const = 0; + virtual size_t malformed_frequency_count() const = 0; + virtual size_t malformed_frequency_time() const = 0; + /* + * @brief Heartbeat timeout before closing connection + */ + virtual uint32_t heart_beat_timeout() const = 0; + + virtual uint16_t max_supported_protocol_version() const = 0; + /* + * @brief Protocol version, from .ini file. + */ + virtual bool enable_protocol_4() const = 0; + + virtual uint32_t multiframe_waiting_timeout() const = 0; +#ifdef ENABLE_SECURITY + /** + * @brief Returns force protected services + */ + virtual const std::vector<int>& force_protected_service() const = 0; + /** + * @brief Returns force unprotected services + */ + virtual const std::vector<int>& force_unprotected_service() const = 0; +#endif // ENABLE_SECURITY +}; +} // namespace protocol_handler +#endif // SRC_COMPONENTS_INCLUDE_PROTOCOL_HANDLER_PROTOCOL_HANDLER_SETTINGS_H_ diff --git a/src/components/include/protocol_handler/session_observer.h b/src/components/include/protocol_handler/session_observer.h index cea1dfbb41..cbc0555425 100644 --- a/src/components/include/protocol_handler/session_observer.h +++ b/src/components/include/protocol_handler/session_observer.h @@ -76,7 +76,7 @@ class SessionObserver { * \return uint32_t Id (number) of new session if successful, otherwise 0. */ virtual uint32_t OnSessionStartedCallback( - const transport_manager::ConnectionUID &connection_handle, + const transport_manager::ConnectionUID connection_handle, const uint8_t sessionId, const protocol_handler::ServiceType &service_type, const bool is_protected, uint32_t* hash_id) = 0; @@ -92,7 +92,7 @@ class SessionObserver { * \return uint32_t 0 if operation fails, session key otherwise */ virtual uint32_t OnSessionEndedCallback( - const transport_manager::ConnectionUID &connection_handle, + const transport_manager::ConnectionUID connection_handle, const uint8_t sessionId, const uint32_t &hashCode, const protocol_handler::ServiceType &service_type) = 0; @@ -121,7 +121,7 @@ class SessionObserver { */ virtual uint32_t KeyFromPair( transport_manager::ConnectionUID connection_handle, - uint8_t session_id) = 0; + uint8_t session_id) const = 0; /** * \brief Returns connection identifier and session number from given @@ -133,7 +133,7 @@ class SessionObserver { virtual void PairFromKey( uint32_t key, transport_manager::ConnectionUID *connection_handle, - uint8_t *sessionId) = 0; + uint8_t *sessionId) const = 0; /** * \brief information about given Connection Key. @@ -146,7 +146,7 @@ class SessionObserver { virtual int32_t GetDataOnSessionKey(uint32_t key, uint32_t *app_id, std::list<int32_t> *sessions_list, - uint32_t *device_id) = 0; + uint32_t *device_id) const = 0; /** * \brief information about device @@ -157,11 +157,12 @@ class SessionObserver { * \param connection_type Returned: type of connection (USB, BT, etc.) * \return int32_t -1 in case of error or 0 in case of success */ - virtual int32_t GetDataOnDeviceID(uint32_t device_handle, - std::string *device_name, - std::list<uint32_t> *applications_list, - std::string *mac_address, - std::string *connection_type) = 0; + virtual int32_t GetDataOnDeviceID( + transport_manager::DeviceHandle device_handle, + std::string *device_name = NULL, + std::list<uint32_t> *applications_list = NULL, + std::string *mac_address = NULL, + std::string *connection_type = NULL) const = 0; /** * \brief returns TRUE if session supports sending HEARTBEAT ACK to mobile side @@ -171,7 +172,7 @@ class SessionObserver { */ virtual bool IsHeartBeatSupported( transport_manager::ConnectionUID connection_handle, - uint8_t session_id) = 0; + uint8_t session_id) const = 0; /** * @brief returns protocol version which application supports @@ -181,7 +182,7 @@ class SessionObserver { * @return TRUE if session and connection exist otherwise returns FALSE */ virtual bool ProtocolVersionUsed(uint32_t connection_id, - uint8_t session_id, uint8_t& protocol_version) = 0; + uint8_t session_id, uint8_t& protocol_version) const = 0; #ifdef ENABLE_SECURITY diff --git a/src/components/include/test/protocol_handler/mock_protocol_handler.h b/src/components/include/test/protocol_handler/mock_protocol_handler.h index 5a93158de1..36dd61baa8 100644 --- a/src/components/include/test/protocol_handler/mock_protocol_handler.h +++ b/src/components/include/test/protocol_handler/mock_protocol_handler.h @@ -34,6 +34,8 @@ #include "gmock/gmock.h" #include "protocol_handler/protocol_packet.h" +#include "protocol_handler/protocol_handler.h" +#include "protocol_handler/protocol_handler_settings.h" namespace test { namespace components { @@ -54,6 +56,8 @@ class MockProtocolHandler : public ::protocol_handler::ProtocolHandler { MOCK_METHOD2(SendEndSession, void(int32_t connection_id, uint8_t session_id)); MOCK_METHOD3(SendEndService, void(int32_t connection_id, uint8_t session_id, uint8_t service_type)); + MOCK_CONST_METHOD0(get_settings, + protocol_handler::ProtocolHandlerSettings &()); }; } // namespace protocol_handler_test } // namespace components diff --git a/src/components/include/test/protocol_handler/mock_protocol_handler_settings.h b/src/components/include/test/protocol_handler/mock_protocol_handler_settings.h new file mode 100644 index 0000000000..6d7fe727a2 --- /dev/null +++ b/src/components/include/test/protocol_handler/mock_protocol_handler_settings.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2016, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef SRC_COMPONENTS_INCLUDE_TEST_PROTOCOL_HANDLER_MOCK_PROTOCOL_HANDLER_SETTINGS_H_ +#define SRC_COMPONENTS_INCLUDE_TEST_PROTOCOL_HANDLER_MOCK_PROTOCOL_HANDLER_SETTINGS_H_ + +#include "gmock/gmock.h" +#include "protocol_handler/protocol_handler.h" +#include "protocol_handler/protocol_handler_settings.h" + +namespace test { +namespace components { +namespace protocol_handler_test { + +class MockProtocolHandlerSettings : public protocol_handler::ProtocolHandlerSettings { + public: + MOCK_CONST_METHOD0(maximum_payload_size, + size_t()); + MOCK_CONST_METHOD0(message_frequency_count, + size_t()); + MOCK_CONST_METHOD0(message_frequency_time, + size_t()); + MOCK_CONST_METHOD0(malformed_message_filtering, + bool()); + MOCK_CONST_METHOD0(malformed_frequency_count, + size_t()); + MOCK_CONST_METHOD0(malformed_frequency_time, + size_t()); + MOCK_CONST_METHOD0(heart_beat_timeout, + uint32_t()); + MOCK_CONST_METHOD0(max_supported_protocol_version, + uint16_t()); + MOCK_CONST_METHOD0(enable_protocol_4, + bool()); + MOCK_CONST_METHOD0(multiframe_waiting_timeout, + uint32_t()); +#ifdef ENABLE_SECURITY + MOCK_CONST_METHOD0(force_protected_service, + const std::vector<int>&()); + MOCK_CONST_METHOD0(force_unprotected_service, + const std::vector<int>&()); +#endif +}; + +} // namespace protocol_handler_test +} // namespace components +} // namespace test + +#endif // SRC_COMPONENTS_INCLUDE_TEST_PROTOCOL_HANDLER_MOCK_PROTOCOL_HANDLER_SETTINGS_H_ diff --git a/src/components/include/test/protocol_handler/mock_session_observer.h b/src/components/include/test/protocol_handler/mock_session_observer.h index 5245c4569d..994c78b961 100644 --- a/src/components/include/test/protocol_handler/mock_session_observer.h +++ b/src/components/include/test/protocol_handler/mock_session_observer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Ford Motor Company + * Copyright (c) 2014, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,10 +30,10 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SRC_COMPONENTS_INCLUDE_TEST_PROTOCOL_HANDLER_MOCK_SESSION_OBSERVER_H_ -#define SRC_COMPONENTS_INCLUDE_TEST_PROTOCOL_HANDLER_MOCK_SESSION_OBSERVER_H_ +#ifndef TEST_COMPONENTS_INCLUDE_PROTOCOL_HANDLER_SESSION_OBSERVER_MOCK_H_ +#define TEST_COMPONENTS_INCLUDE_PROTOCOL_HANDLER_SESSION_OBSERVER_MOCK_H_ -#include "gmock/gmock.h" +#include <gmock/gmock.h> #include <string> #include <list> #include "protocol_handler/session_observer.h" @@ -41,60 +41,71 @@ namespace test { namespace components { namespace protocol_handler_test { - +/* + * MOCK implementation of ::protocol_handler::SessionObserver interface + */ class MockSessionObserver : public ::protocol_handler::SessionObserver { public: MOCK_METHOD5( OnSessionStartedCallback, - uint32_t(const transport_manager::ConnectionUID& connection_handle, - const uint8_t session_id, - const ::protocol_handler::ServiceType& service_type, - const bool is_protected, uint32_t* hash_id)); + uint32_t(const transport_manager::ConnectionUID connection_handle, + const uint8_t sessionId, + const protocol_handler::ServiceType& service_type, + const bool is_protected, + uint32_t* hash_id)); MOCK_METHOD4( OnSessionEndedCallback, - uint32_t(const transport_manager::ConnectionUID& connection_handle, - const uint8_t sessionId, const uint32_t& hashCode, - const ::protocol_handler::ServiceType& service_type)); - MOCK_METHOD1(OnApplicationFloodCallBack, void(const uint32_t&)); - MOCK_METHOD1(OnMalformedMessageCallback, void(const uint32_t&)); - MOCK_METHOD2(KeyFromPair, - uint32_t(transport_manager::ConnectionUID connection_handle, - uint8_t sessionId)); - MOCK_METHOD3(PairFromKey, - void(uint32_t key, - transport_manager::ConnectionUID* connection_handle, - uint8_t* sessionId)); - MOCK_METHOD4(GetDataOnSessionKey, - int32_t(uint32_t key, uint32_t* app_id, - std::list<int32_t>* sessions_list, uint32_t* device_id)); - MOCK_METHOD5(GetDataOnDeviceID, - int32_t(uint32_t device_handle, std::string* device_name, - std::list<uint32_t>* applications_list, - std::string* mac_address, std::string* connection_type)); - MOCK_METHOD2(IsHeartBeatSupported, - bool(transport_manager::ConnectionUID connection_handle, - uint8_t session_id)); - MOCK_METHOD3(ProtocolVersionUsed, - bool(uint32_t connection_id, uint8_t session_id, - uint8_t& protocol_version)); + uint32_t(const transport_manager::ConnectionUID connection_handle, + const uint8_t sessionId, + const uint32_t& hashCode, + const protocol_handler::ServiceType& service_type)); + MOCK_METHOD1(OnApplicationFloodCallBack, + void(const uint32_t& connection_key)); + MOCK_METHOD1(OnMalformedMessageCallback, + void(const uint32_t& connection_key)); + MOCK_CONST_METHOD2( + KeyFromPair, + uint32_t(transport_manager::ConnectionUID connection_handle, + uint8_t session_id)); + MOCK_CONST_METHOD3(PairFromKey, + void(uint32_t key, + transport_manager::ConnectionUID* connection_handle, + uint8_t* sessionId)); + MOCK_CONST_METHOD4(GetDataOnSessionKey, + int32_t(uint32_t key, + uint32_t* app_id, + std::list<int32_t>* sessions_list, + uint32_t* device_id)); + MOCK_CONST_METHOD5(GetDataOnDeviceID, + int32_t(uint32_t device_handle, + std::string* device_name, + std::list<uint32_t>* applications_list, + std::string* mac_address, + std::string* connection_type)); + MOCK_CONST_METHOD2(IsHeartBeatSupported, + bool(transport_manager::ConnectionUID connection_handle, + uint8_t session_id)); + MOCK_CONST_METHOD3(ProtocolVersionUsed, + bool(uint32_t connection_id, + uint8_t session_id, + uint8_t& protocol_version)); + #ifdef ENABLE_SECURITY - MOCK_METHOD2(SetSSLContext, int(const uint32_t& key, - ::security_manager::SSLContext* context)); + MOCK_METHOD2(SetSSLContext, + int(const uint32_t& key, security_manager::SSLContext* context)); MOCK_METHOD2(GetSSLContext, - ::security_manager::SSLContext*( + security_manager::SSLContext*( const uint32_t& key, - const ::protocol_handler::ServiceType& service_type)); + const protocol_handler::ServiceType& service_type)); MOCK_METHOD2(SetProtectionFlag, void(const uint32_t& key, - const ::protocol_handler::ServiceType& service_type)); + const protocol_handler::ServiceType& service_type)); MOCK_CONST_METHOD1( GetHandshakeContext, - security_manager::SSLContext::HandshakeContext(const uint32_t key)); - + security_manager::SSLContext::HandshakeContext(uint32_t key)); #endif // ENABLE_SECURITY }; } // namespace protocol_handler_test } // namespace components } // namespace test - -#endif // SRC_COMPONENTS_INCLUDE_TEST_PROTOCOL_HANDLER_MOCK_SESSION_OBSERVER_H_ +#endif // TEST_COMPONENTS_INCLUDE_PROTOCOL_HANDLER_SESSION_OBSERVER_MOCK_H_ diff --git a/src/components/protocol_handler/CMakeLists.txt b/src/components/protocol_handler/CMakeLists.txt index 81ce371001..a09a565844 100644 --- a/src/components/protocol_handler/CMakeLists.txt +++ b/src/components/protocol_handler/CMakeLists.txt @@ -34,7 +34,6 @@ include_directories( ${COMPONENTS_DIR}/utils/include/ ${COMPONENTS_DIR}/protocol_handler/include/ ${COMPONENTS_DIR}/connection_handler/include/ - ${COMPONENTS_DIR}/config_profile/include/ ${LOG4CXX_INCLUDE_DIRECTORY} ) diff --git a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h index 1e189f0aa2..10acbe449d 100644 --- a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h +++ b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h @@ -39,6 +39,7 @@ #include <list> #include <cstdint> #include <utility> // std::make_pair +#include <vector> #include "utils/prioritized_queue.h" #include "utils/message_queue.h" #include "utils/threads/message_loop_thread.h" @@ -47,6 +48,7 @@ #include "protocol_handler/protocol_handler.h" #include "protocol_handler/protocol_packet.h" +#include "protocol_handler/protocol_handler_settings.h" #include "protocol_handler/session_observer.h" #include "protocol_handler/protocol_observer.h" #include "protocol_handler/incoming_data_handler.h" @@ -54,6 +56,8 @@ #include "transport_manager/common.h" #include "transport_manager/transport_manager.h" #include "transport_manager/transport_manager_listener_empty.h" +#include "connection_handler/connection_handler.h" + #ifdef TIME_TESTER #include "protocol_handler/time_metric_observer.h" #endif // TIME_TESTER @@ -62,6 +66,10 @@ #include "security_manager/security_manager.h" #endif // ENABLE_SECURITY +namespace connection_handler { +class ConnectionHandlerImpl; +} // namespace connection_handler + /** *\namespace protocol_handlerHandler *\brief Namespace for SmartDeviceLink ProtocolHandler related functionality. @@ -134,27 +142,16 @@ class ProtocolHandlerImpl public impl::ToMobileQueue::Handler { public: /** - * \brief Constructor - * \param transportManager Pointer to Transport layer handler for - * \param message_frequency_time used as time for flood filtering - * \param message_frequency_count used as maximum value of messages - * per message_frequency_time period - * \param malformed_message_filtering used for malformed filtering enabling - * \param malformed_message_frequency_time used as time for malformed flood filtering - * \param malformed_message_frequency_count used as maximum value of malformed - * messages per message_frequency_time period - * \param multiframe_waiting_timeout used as maximum time of consecutive - * frames handling - * message exchange. - */ - explicit ProtocolHandlerImpl( - transport_manager::TransportManager *transport_manager_param, - size_t message_frequency_time, size_t message_frequency_count, - bool malformed_message_filtering, - size_t malformed_message_frequency_time, - size_t malformed_message_frequency_count, - uint32_t multiframe_waiting_timeout); - + * @brief Constructor + * @param settings reference to ProtocolHandlerSettingsImpl object + * @param session_observer reference to SessionObserver to access session + * information and controll session life cycle + * @param transportManager Pointer to Transport layer handler for + */ + ProtocolHandlerImpl(const ProtocolHandlerSettings& settings, + protocol_handler::SessionObserver& session_observer, + connection_handler::ConnectionHandler& connection_handler, + transport_manager::TransportManager& transport_manager); /** * \brief Destructor */ @@ -167,19 +164,8 @@ class ProtocolHandlerImpl */ void AddProtocolObserver(ProtocolObserver *observer); - /** - * \brief Removes pointer to higher layer handler for message exchange - * \param observer Pointer to object of the class implementing - * IProtocolObserver. - */ - void RemoveProtocolObserver(ProtocolObserver *observer); - - /** - * \brief Sets pointer for Connection Handler layer for managing sessions - * \param observer Pointer to object of the class implementing - * ISessionObserver - */ - void set_session_observer(SessionObserver *observer); + void RemoveProtocolObserver( + ProtocolObserver* observer) OVERRIDE; #ifdef ENABLE_SECURITY /** @@ -256,6 +242,10 @@ class ProtocolHandlerImpl uint8_t service_type, bool protection); + const ProtocolHandlerSettings& get_settings() const OVERRIDE { + return settings_; + } + /** * \brief Sends fail of starting session to mobile application * \param connection_id Identifier of connection within which session @@ -313,22 +303,22 @@ class ProtocolHandlerImpl * * @param message Received message **/ - virtual void OnTMMessageReceived( - const RawMessagePtr message); + void OnTMMessageReceived( + const RawMessagePtr message) OVERRIDE; /** * @brief Notifies about error on receiving message from TM. * * @param error Occurred error **/ - virtual void OnTMMessageReceiveFailed( - const transport_manager::DataReceiveError &error); + void OnTMMessageReceiveFailed( + const transport_manager::DataReceiveError &error) OVERRIDE; /** * @brief Notifies about successfully sending message. * **/ - virtual void OnTMMessageSend(const RawMessagePtr message); + void OnTMMessageSend(const RawMessagePtr message) OVERRIDE; /** * @brief Notifies about error occurred during @@ -337,16 +327,15 @@ class ProtocolHandlerImpl * @param error Describes occurred error. * @param message Message during sending which error occurred. **/ - virtual void OnTMMessageSendFailed( + void OnTMMessageSendFailed( const transport_manager::DataSendError &error, - const RawMessagePtr message); + const RawMessagePtr message) OVERRIDE; - virtual void OnConnectionEstablished( - const transport_manager::DeviceInfo &device_info, - const transport_manager::ConnectionUID &connection_id); + void OnConnectionEstablished(const transport_manager::DeviceInfo &device_info, + const transport_manager::ConnectionUID connection_id) OVERRIDE; - virtual void OnConnectionClosed( - const transport_manager::ConnectionUID &connection_id); + void OnConnectionClosed( + const transport_manager::ConnectionUID connection_id) OVERRIDE; /** * @brief Notifies subscribers about message @@ -406,6 +395,8 @@ class ProtocolHandlerImpl /** * \brief Handles received message. + * \param connection_handle Identifier of connection through which message + * is received. * \param packet Received message with protocol header. * \return \saRESULT_CODE Status of operation */ @@ -413,6 +404,8 @@ class ProtocolHandlerImpl /** * \brief Handles message received in single frame. + * \param connection_handle Identifier of connection through which message + * is received. * \param packet Frame of message with protocol header. * \return \saRESULT_CODE Status of operation */ @@ -420,6 +413,8 @@ class ProtocolHandlerImpl /** * \brief Handles message received in multiple frames. Collects all frames * of message. + * \param connection_handle Identifier of connection through which message + * is received. * \param packet Current frame of message with protocol header. * \return \saRESULT_CODE Status of operation */ @@ -427,6 +422,8 @@ class ProtocolHandlerImpl /** * \brief Handles message received in single frame. + * \param connection_handle Identifier of connection through which message + * is received. * \param packet Received message with protocol header. * \return \saRESULT_CODE Status of operation */ @@ -461,8 +458,13 @@ class ProtocolHandlerImpl bool TrackMalformedMessage(const uint32_t &connection_key, const size_t count); + /** + * @brief Function returns supported SDL Protocol Version, + */ + uint8_t SupportedSDLProtocolVersion() const; + + const ProtocolHandlerSettings& settings_; - private: /** *\brief Pointer on instance of class implementing IProtocolObserver *\brief (JSON Handler) @@ -471,14 +473,22 @@ class ProtocolHandlerImpl /** *\brief Pointer on instance of class implementing ISessionObserver - *\brief (Connection Handler) + *\brief (Connection Handler). + * According to usage it can't be null + */ + SessionObserver& session_observer_; + + /** + *\brief Pointer on instance of Transport layer handler for message exchange. + *\brief Instance of class implementing Connection Handler t keep connection + *alive */ - SessionObserver *session_observer_; + connection_handler::ConnectionHandler& connection_handler_; /** *\brief Pointer on instance of Transport layer handler for message exchange. */ - transport_manager::TransportManager *transport_manager_; + transport_manager::TransportManager& transport_manager_; /** *\brief Assembling support class. @@ -516,19 +526,14 @@ class ProtocolHandlerImpl /** *\brief Connections that must be closed after their last messages were sent */ - std::list<uint32_t> ready_to_close_connections_; + std::vector<uint32_t> ready_to_close_connections_; ProtocolPacket::ProtocolHeaderValidator protocol_header_validator_; IncomingDataHandler incoming_data_handler_; // Use uint32_t as application identifier utils::MessageMeter<uint32_t> message_meter_; - size_t message_max_frequency_; - size_t message_frequency_time_; - bool malformed_message_filtering_; // Use uint32_t as connection identifier utils::MessageMeter<uint32_t> malformed_message_meter_; - size_t malformed_message_max_frequency_; - size_t malformed_message_frequency_time_; #ifdef ENABLE_SECURITY security_manager::SecurityManager *security_manager_; diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index 8c08afd4cc..e0ab97bdcb 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -35,7 +35,6 @@ #include <algorithm> // std::find #include "connection_handler/connection_handler_impl.h" -#include "config_profile/profile.h" #include "utils/byte_order.h" #include "protocol/common.h" @@ -55,29 +54,19 @@ CREATE_LOGGERPTR_GLOBAL(logger_, "ProtocolHandler") std::string ConvertPacketDataToString(const uint8_t *data, const size_t data_size); -/** - * @brief Function returns supported SDL Protocol Version, - */ -uint8_t SupportedSDLProtocolVersion(); - - const size_t kStackSize = 32768; -ProtocolHandlerImpl::ProtocolHandlerImpl(transport_manager::TransportManager *transport_manager_param, - size_t message_frequency_time, size_t message_frequency_count, - bool malformed_message_filtering, - size_t malformed_message_frequency_time, - size_t malformed_message_frequency_count, - uint32_t multiframe_waiting_timeout) - : protocol_observers_(), - session_observer_(0), - transport_manager_(transport_manager_param), - kPeriodForNaviAck(5), - message_max_frequency_(message_frequency_count), - message_frequency_time_(message_frequency_time), - malformed_message_filtering_(malformed_message_filtering), - malformed_message_max_frequency_(malformed_message_frequency_count), - malformed_message_frequency_time_(malformed_message_frequency_time), +ProtocolHandlerImpl::ProtocolHandlerImpl(const ProtocolHandlerSettings& settings, + protocol_handler::SessionObserver& session_observer, + connection_handler::ConnectionHandler& connection_handler, + transport_manager::TransportManager& transport_manager) + : settings_(settings) + , protocol_observers_() + , session_observer_(session_observer) + , connection_handler_(connection_handler) + , transport_manager_(transport_manager) + , kPeriodForNaviAck(5) + , #ifdef ENABLE_SECURITY security_manager_(NULL), #endif // ENABLE_SECURITY @@ -92,25 +81,31 @@ ProtocolHandlerImpl::ProtocolHandlerImpl(transport_manager::TransportManager *tr { LOG4CXX_AUTO_TRACE(logger_); protocol_header_validator_.set_max_payload_size( - profile::Profile::instance()->maximum_payload_size()); + get_settings().maximum_payload_size()); incoming_data_handler_.set_validator(&protocol_header_validator_); - if (message_frequency_time_ > 0u && - message_max_frequency_ > 0u) { - message_meter_.set_time_range(message_frequency_time_); - LOG4CXX_DEBUG(logger_, "Frequency meter is enabled ( " << message_max_frequency_ - << " per " << message_frequency_time_ << " mSecond)"); + const size_t& message_frequency_count = get_settings().message_frequency_count(); + const size_t& message_frequency_time = get_settings().message_frequency_time(); + + if (message_frequency_time > 0u && + message_frequency_count > 0u) { + message_meter_.set_time_range(message_frequency_time); + LOG4CXX_DEBUG(logger_, "Frequency meter is enabled ( " << message_frequency_count + << " per " << message_frequency_time << " mSecond)"); } else { LOG4CXX_WARN(logger_, "Frequency meter is disabled"); } - if (malformed_message_filtering_) { - if (malformed_message_frequency_time_ > 0u && - malformed_message_max_frequency_ > 0u) { - malformed_message_meter_.set_time_range(malformed_message_frequency_time_); + const size_t& malformed_frequency_time = get_settings().malformed_frequency_time(); + const size_t& malformed_frequency_count = get_settings().message_frequency_time(); + + if (get_settings().malformed_message_filtering()) { + if (malformed_frequency_time > 0u && + malformed_frequency_count > 0u) { + malformed_message_meter_.set_time_range(malformed_frequency_time); LOG4CXX_DEBUG(logger_, "Malformed frequency meter is enabled ( " - << malformed_message_max_frequency_ << " per " - << malformed_message_frequency_time_ << " mSecond)"); + << malformed_frequency_count << " per " + << malformed_frequency_time << " mSecond)"); } else { LOG4CXX_WARN(logger_, "Malformed frequency meter is disabled"); } @@ -118,7 +113,7 @@ ProtocolHandlerImpl::ProtocolHandlerImpl(transport_manager::TransportManager *tr LOG4CXX_WARN(logger_, "Malformed message filtering is disabled." << "Connection will be close on first malformed message detection"); } - multiframe_builder_.set_waiting_timeout(multiframe_waiting_timeout); + multiframe_builder_.set_waiting_timeout(get_settings().multiframe_waiting_timeout()); } ProtocolHandlerImpl::~ProtocolHandlerImpl() { @@ -148,14 +143,6 @@ void ProtocolHandlerImpl::RemoveProtocolObserver(ProtocolObserver* observer) { protocol_observers_.erase(observer); } -void ProtocolHandlerImpl::set_session_observer(SessionObserver *observer) { - if (!observer) { - LOG4CXX_WARN(logger_, "Invalid (NULL) pointer to ISessionObserver."); - // Do not return from here! - } - session_observer_ = observer; -} - void set_hash_id(uint32_t hash_id, protocol_handler::ProtocolPacket& packet) { if (HASH_ID_NOT_SUPPORTED == hash_id || HASH_ID_WRONG == hash_id) { @@ -265,7 +252,7 @@ void ProtocolHandlerImpl::SendEndServicePrivate(int32_t connection_id, LOG4CXX_AUTO_TRACE(logger_); uint8_t protocol_version; - if (session_observer_->ProtocolVersionUsed(connection_id, + if (session_observer_.ProtocolVersionUsed(connection_id, session_id, protocol_version)) { ProtocolFramePtr ptr(new protocol_handler::ProtocolPacket(connection_id, protocol_version, PROTECTION_OFF, FRAME_TYPE_CONTROL, @@ -299,7 +286,7 @@ RESULT_CODE ProtocolHandlerImpl::SendHeartBeatAck(ConnectionID connection_id, LOG4CXX_AUTO_TRACE(logger_); uint8_t protocol_version; - if (session_observer_->ProtocolVersionUsed(connection_id, + if (session_observer_.ProtocolVersionUsed(connection_id, session_id, protocol_version)) { ProtocolFramePtr ptr(new protocol_handler::ProtocolPacket(connection_id, protocol_version, PROTECTION_OFF, FRAME_TYPE_CONTROL, @@ -318,7 +305,7 @@ void ProtocolHandlerImpl::SendHeartBeat(int32_t connection_id, uint8_t session_id) { LOG4CXX_AUTO_TRACE(logger_); uint8_t protocol_version; - if (session_observer_->ProtocolVersionUsed(connection_id, + if (session_observer_.ProtocolVersionUsed(connection_id, session_id, protocol_version)) { ProtocolFramePtr ptr(new protocol_handler::ProtocolPacket(connection_id, protocol_version, PROTECTION_OFF, FRAME_TYPE_CONTROL, @@ -343,16 +330,9 @@ void ProtocolHandlerImpl::SendMessageToMobileApp(const RawMessagePtr message, return; } - if (!session_observer_) { - LOG4CXX_ERROR( - logger_, - "Cannot handle message to mobile app:" << - " ISessionObserver doesn't exist."); - return; - } uint32_t connection_handle = 0; uint8_t sessionID = 0; - session_observer_->PairFromKey(message->connection_key(), &connection_handle, + session_observer_.PairFromKey(message->connection_key(), &connection_handle, &sessionID); #ifdef TIME_TESTER uint32_t message_id = message_counters_[sessionID]; @@ -360,8 +340,7 @@ void ProtocolHandlerImpl::SendMessageToMobileApp(const RawMessagePtr message, metric_observer_->StartMessageProcess(message_id, start_time); } #endif // TIME_TESTER - const size_t max_frame_size = - profile::Profile::instance()->maximum_payload_size(); + const size_t max_frame_size = get_settings().maximum_payload_size(); size_t frame_size = MAXIMUM_FRAME_DATA_V2_SIZE; switch (message->protocol_version()) { case PROTOCOL_VERSION_3: @@ -373,7 +352,7 @@ void ProtocolHandlerImpl::SendMessageToMobileApp(const RawMessagePtr message, break; } #ifdef ENABLE_SECURITY - const security_manager::SSLContext *ssl_context = session_observer_-> + const security_manager::SSLContext *ssl_context = session_observer_. GetSSLContext(message->connection_key(), message->service_type()); if (ssl_context && ssl_context->IsInitCompleted()) { const size_t max_block_size = ssl_context->get_max_block_size(frame_size); @@ -445,18 +424,16 @@ void ProtocolHandlerImpl::OnTMMessageReceived(const RawMessagePtr tm_message) { RESULT_CODE result; size_t malformed_occurs = 0u; - const std::list<ProtocolFramePtr> protocol_frames = + const ProtocolFramePtrList protocol_frames = incoming_data_handler_.ProcessData(*tm_message, &result, &malformed_occurs); LOG4CXX_DEBUG(logger_, "Proccessed " << protocol_frames.size() << " frames"); if (result != RESULT_OK) { if (result == RESULT_MALFORMED_OCCURS) { LOG4CXX_WARN(logger_, "Malformed message occurs, connection id " << connection_key); - if (!malformed_message_filtering_) { + if (!get_settings().malformed_message_filtering()) { LOG4CXX_DEBUG(logger_, "Malformed message filterign disabled"); - if (session_observer_) { - session_observer_->OnMalformedMessageCallback(connection_key); - } + session_observer_.OnMalformedMessageCallback(connection_key); // For tracking only malformed occurrence check outpute } else { if (malformed_occurs > 0) { @@ -465,11 +442,11 @@ void ProtocolHandlerImpl::OnTMMessageReceived(const RawMessagePtr tm_message) { } } else { LOG4CXX_ERROR(logger_, "Incoming data processing failed."); - transport_manager_->DisconnectForce(connection_key); + transport_manager_.DisconnectForce(connection_key); } } - for (std::list<ProtocolFramePtr>::const_iterator it = + for (ProtocolFramePtrList::const_iterator it = protocol_frames.begin(); it != protocol_frames.end(); ++it) { #ifdef TIME_TESTER const TimevalStruct start_time = date_time::DateTime::getCurrentTime(); @@ -520,17 +497,17 @@ void ProtocolHandlerImpl::OnTMMessageSend(const RawMessagePtr message) { uint32_t connection_handle = 0; uint8_t sessionID = 0; - session_observer_->PairFromKey(message->connection_key(), + session_observer_.PairFromKey(message->connection_key(), &connection_handle, &sessionID); - std::list<uint32_t>::iterator connection_it = + std::vector<uint32_t>::iterator connection_it = std::find(ready_to_close_connections_.begin(), ready_to_close_connections_.end(), connection_handle); if (ready_to_close_connections_.end() != connection_it) { ready_to_close_connections_.erase(connection_it); - transport_manager_->Disconnect(connection_handle); + transport_manager_.Disconnect(connection_handle); return; } @@ -574,13 +551,13 @@ void ProtocolHandlerImpl::OnTMMessageSendFailed( void ProtocolHandlerImpl::OnConnectionEstablished( const transport_manager::DeviceInfo &device_info, - const transport_manager::ConnectionUID &connection_id) { + const transport_manager::ConnectionUID connection_id) { incoming_data_handler_.AddConnection(connection_id); multiframe_builder_.AddConnection(connection_id); } void ProtocolHandlerImpl::OnConnectionClosed( - const transport_manager::ConnectionUID &connection_id) { + const transport_manager::ConnectionUID connection_id) { incoming_data_handler_.RemoveConnection(connection_id); message_meter_.ClearIdentifiers(); malformed_message_meter_.ClearIdentifiers(); @@ -614,12 +591,8 @@ RESULT_CODE ProtocolHandlerImpl::SendFrame(const ProtocolFramePtr packet) { "Message to send with connection id " << static_cast<int>(packet->connection_id())); - if (!transport_manager_) { - LOG4CXX_WARN(logger_, "No Transport Manager found."); - return RESULT_FAIL; - } if (transport_manager::E_SUCCESS != - transport_manager_->SendMessageToDevice(message_to_send)) { + transport_manager_.SendMessageToDevice(message_to_send)) { LOG4CXX_WARN(logger_, "Can't send message to device"); return RESULT_FAIL; } @@ -743,15 +716,8 @@ RESULT_CODE ProtocolHandlerImpl::HandleSingleFrameMessage(const ProtocolFramePtr "FRAME_TYPE_SINGLE message of size " << packet->data_size() << "; message " << ConvertPacketDataToString(packet->data(), packet->data_size())); - if (!session_observer_) { - LOG4CXX_ERROR(logger_, - "Cannot handle message from Transport" - << " Manager: ISessionObserver doesn't exist."); - return RESULT_FAIL; - } - const uint32_t connection_key = - session_observer_->KeyFromPair(packet->connection_id(), packet->session_id()); + session_observer_.KeyFromPair(packet->connection_id(), packet->session_id()); const RawMessagePtr rawMessage( new RawMessage(connection_key, @@ -782,11 +748,6 @@ RESULT_CODE ProtocolHandlerImpl::HandleSingleFrameMessage(const ProtocolFramePtr RESULT_CODE ProtocolHandlerImpl::HandleMultiFrameMessage(const ProtocolFramePtr packet) { LOG4CXX_AUTO_TRACE(logger_); - if (!session_observer_) { - LOG4CXX_ERROR(logger_, "No ISessionObserver set."); - return RESULT_FAIL; - } - if (multiframe_builder_.AddFrame(packet) != RESULT_OK) { LOG4CXX_WARN(logger_, "Frame assembling issue"); } @@ -797,11 +758,6 @@ RESULT_CODE ProtocolHandlerImpl::HandleMultiFrameMessage(const ProtocolFramePtr RESULT_CODE ProtocolHandlerImpl::HandleControlMessage(const ProtocolFramePtr packet) { LOG4CXX_AUTO_TRACE(logger_); - if (!session_observer_) { - LOG4CXX_ERROR(logger_, "ISessionObserver is not set."); - return RESULT_FAIL; - } - // TODO{ALeshin}: Rename "Session" to "Service" on PH, CH, AM levels switch (packet->frame_data()) { case FRAME_DATA_START_SERVICE: { @@ -858,7 +814,7 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageEndSession(const ProtocolPa const ServiceType service_type = ServiceTypeFromByte(packet.service_type()); const ConnectionID connection_id = packet.connection_id(); - const uint32_t session_key = session_observer_->OnSessionEndedCallback( + const uint32_t session_key = session_observer_.OnSessionEndedCallback( connection_id, current_session_id, hash_id, service_type); // TODO(EZamakhov): add clean up output queue (for removed service) @@ -879,17 +835,12 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageEndSession(const ProtocolPa RESULT_CODE ProtocolHandlerImpl::HandleControlMessageEndServiceACK(const ProtocolPacket& packet) { LOG4CXX_AUTO_TRACE(logger_); - if (!session_observer_) { - LOG4CXX_ERROR(logger_, "No ISessionObserver set."); - return RESULT_FAIL; - } - const uint8_t current_session_id = packet.session_id(); const uint32_t hash_id = get_hash_id(packet); const ServiceType service_type = ServiceTypeFromByte(packet.service_type()); const ConnectionID connection_id = packet.connection_id(); - const uint32_t session_key = session_observer_->OnSessionEndedCallback( + const uint32_t session_key = session_observer_.OnSessionEndedCallback( connection_id, current_session_id, hash_id, service_type); if (0 == session_key) { @@ -911,12 +862,13 @@ class StartSessionHandler : public security_manager::SecurityManagerListener { StartSessionHandler( uint32_t connection_key, ProtocolHandlerImpl *protocol_handler, - SessionObserver *session_observer, + SessionObserver& session_observer, ConnectionID connection_id, int32_t session_id, uint8_t protocol_version, uint32_t hash_id, - ServiceType service_type) + ServiceType service_type, + const std::vector<int>& force_protected_service) : connection_key_(connection_key), protocol_handler_(protocol_handler), session_observer_(session_observer), @@ -924,23 +876,24 @@ class StartSessionHandler : public security_manager::SecurityManagerListener { session_id_(session_id), protocol_version_(protocol_version), hash_id_(hash_id), - service_type_(service_type) { + service_type_(service_type) + ,force_protected_service_(force_protected_service) + { } + bool OnHandshakeDone( const uint32_t connection_key, security_manager::SSLContext::HandshakeResult result) OVERRIDE { if (connection_key != connection_key_) { return false; } + const bool success = + result == security_manager::SSLContext::Handshake_Result_Success; // check current service protection const bool was_service_protection_enabled = - session_observer_->GetSSLContext(connection_key_, service_type_) != NULL; + session_observer_.GetSSLContext(connection_key_, service_type_) != NULL; if (was_service_protection_enabled) { - if (result != security_manager::SSLContext::Handshake_Result_Success) { -// const std::string error_text("Connection is already protected"); -// LOG4CXX_WARN(logger_, error_text << ", key " << connection_key); -// security_manager_->SendInternalError( -// connection_key, security_manager::SecurityManager::ERROR_SERVICE_ALREADY_PROTECTED, error_text); + if (!success) { protocol_handler_->SendStartSessionNAck(connection_id_, session_id_, protocol_version_, service_type_); } else { @@ -948,14 +901,14 @@ class StartSessionHandler : public security_manager::SecurityManagerListener { NOTREACHED(); } } else { - if (result == security_manager::SSLContext::Handshake_Result_Success) { - session_observer_->SetProtectionFlag(connection_key_, service_type_); + if (success) { + session_observer_.SetProtectionFlag(connection_key_, service_type_); } protocol_handler_->SendStartSessionAck( connection_id_, session_id_, protocol_version_, hash_id_, service_type_, - security_manager::SSLContext::Handshake_Result_Success == result); + success); } delete this; return true; @@ -964,16 +917,21 @@ class StartSessionHandler : public security_manager::SecurityManagerListener { void OnCertificateUpdateRequired() OVERRIDE { } + virtual const std::vector<int>& force_protected_service() const { + return force_protected_service_; + } + private: const uint32_t connection_key_; ProtocolHandlerImpl *protocol_handler_; - SessionObserver *session_observer_; + SessionObserver& session_observer_; const ConnectionID connection_id_; const int32_t session_id_; const uint8_t protocol_version_; const uint32_t hash_id_; const ServiceType service_type_; + const std::vector<int> force_protected_service_; }; } // namespace #endif // ENABLE_SECURITY @@ -994,10 +952,9 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(const Protocol const bool protection = false; #endif // ENABLE_SECURITY - DCHECK(session_observer_); uint32_t hash_id; const ConnectionID connection_id = packet.connection_id(); - const uint32_t session_id = session_observer_->OnSessionStartedCallback( + const uint32_t session_id = session_observer_.OnSessionStartedCallback( connection_id, packet.session_id(), service_type, protection, &hash_id); if (0 == session_id) { @@ -1012,7 +969,7 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(const Protocol // for packet is encrypted and security plugin is enable if (protection && security_manager_) { const uint32_t connection_key = - session_observer_->KeyFromPair(connection_id, session_id); + session_observer_.KeyFromPair(connection_id, session_id); security_manager::SSLContext *ssl_context = security_manager_->CreateSSLContext(connection_key); @@ -1028,7 +985,7 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(const Protocol } if (ssl_context->IsInitCompleted()) { // mark service as protected - session_observer_->SetProtectionFlag(connection_key, service_type); + session_observer_.SetProtectionFlag(connection_key, service_type); // Start service as protected with current SSLContext SendStartSessionAck(connection_id, session_id, packet.protocol_version(), hash_id, packet.service_type(), PROTECTION_ON); @@ -1037,7 +994,7 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(const Protocol new StartSessionHandler( connection_key, this, session_observer_, connection_id, session_id, packet.protocol_version(), - hash_id, service_type)); + hash_id, service_type, get_settings().force_protected_service())); if (!ssl_context->IsHandshakePending()) { // Start handshake process security_manager_->StartHandshake(connection_key); @@ -1060,7 +1017,7 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageHeartBeat(const ProtocolPac logger_, "Sending heart beat acknowledgment for connection " << connection_id); uint8_t protocol_version; - if (session_observer_->ProtocolVersionUsed( + if (session_observer_.ProtocolVersionUsed( connection_id, packet.session_id(), protocol_version)) { // TODO(EZamakhov): investigate message_id for HeartBeatAck if (PROTOCOL_VERSION_3 == protocol_version || @@ -1089,7 +1046,7 @@ void ProtocolHandlerImpl::PopValideAndExpirateMultiframes() { } const uint32_t connection_key = - session_observer_->KeyFromPair(frame->connection_id(), frame->session_id()); + session_observer_.KeyFromPair(frame->connection_id(), frame->session_id()); LOG4CXX_DEBUG(logger_, "Result frame" << frame << "for connection "<< connection_key); const RawMessagePtr rawMessage( @@ -1115,15 +1072,14 @@ void ProtocolHandlerImpl::PopValideAndExpirateMultiframes() { bool ProtocolHandlerImpl::TrackMessage(const uint32_t& connection_key) { LOG4CXX_AUTO_TRACE(logger_); - if (message_frequency_time_ > 0u && - message_max_frequency_ > 0u) { + const size_t& frequency_time = get_settings().message_frequency_time(); + const size_t& frequency_count = get_settings().message_frequency_count(); + if (frequency_time > 0u && frequency_count > 0u) { const size_t message_frequency = message_meter_.TrackMessage(connection_key); LOG4CXX_DEBUG(logger_, "Frequency of " << connection_key << " is " << message_frequency); - if (message_frequency > message_max_frequency_) { + if (message_frequency > frequency_count) { LOG4CXX_WARN(logger_, "Frequency of " << connection_key << " is marked as high."); - if (session_observer_) { - session_observer_->OnApplicationFloodCallBack(connection_key); - } + session_observer_.OnApplicationFloodCallBack(connection_key); message_meter_.RemoveIdentifier(connection_key); return true; } @@ -1133,20 +1089,20 @@ bool ProtocolHandlerImpl::TrackMessage(const uint32_t& connection_key) { bool ProtocolHandlerImpl::TrackMalformedMessage(const uint32_t &connection_key, const size_t count) { + const size_t& malformed_frequency_count = + get_settings().malformed_frequency_count(); LOG4CXX_AUTO_TRACE(logger_); - if (malformed_message_frequency_time_ > 0u && - malformed_message_max_frequency_ > 0u) { + if (get_settings().malformed_frequency_time() > 0u && + malformed_frequency_count > 0u) { const size_t malformed_message_frequency = malformed_message_meter_.TrackMessages(connection_key, count); LOG4CXX_DEBUG(logger_, "Malformed frequency of " << connection_key << " is " << malformed_message_frequency); - if (!malformed_message_filtering_ || - malformed_message_frequency > malformed_message_max_frequency_) { + if (!get_settings().malformed_message_filtering() || + malformed_message_frequency > malformed_frequency_count) { LOG4CXX_WARN(logger_, "Malformed frequency of " << connection_key << " is marked as high."); - if (session_observer_) { - session_observer_->OnMalformedMessageCallback(connection_key); - } + session_observer_.OnMalformedMessageCallback(connection_key); malformed_message_meter_.RemoveIdentifier(connection_key); return true; } @@ -1154,21 +1110,15 @@ bool ProtocolHandlerImpl::TrackMalformedMessage(const uint32_t &connection_key, return false; } -void ProtocolHandlerImpl::Handle( - const impl::RawFordMessageFromMobile message) { +void ProtocolHandlerImpl::Handle(const impl::RawFordMessageFromMobile message) { LOG4CXX_AUTO_TRACE(logger_); - if (NULL == session_observer_) { - LOG4CXX_WARN(logger_, "Session Observer is NULL"); - return; - } - switch (message->service_type()) { case kMobileNav: case kAudio: break; default: { - const uint32_t connection_key = session_observer_->KeyFromPair( + const uint32_t connection_key = session_observer_.KeyFromPair( message->connection_id(), message->session_id()); if (TrackMessage(connection_key)) { return; @@ -1176,15 +1126,12 @@ void ProtocolHandlerImpl::Handle( } break; } - - connection_handler::ConnectionHandlerImpl *connection_handler = - connection_handler::ConnectionHandlerImpl::instance(); LOG4CXX_DEBUG(logger_, "Message : " << message.get()); const uint8_t c_id = message->connection_id(); - const uint32_t m_id = message->session_id(); + const uint32_t m_id = message->session_id(); - if (session_observer_->IsHeartBeatSupported(c_id, m_id)) { - connection_handler->KeepConnectionAlive(c_id, m_id); + if (session_observer_.IsHeartBeatSupported(c_id, m_id)) { + connection_handler_.KeepConnectionAlive(c_id, m_id); } // TODO(EZamakhov): remove dublication of IncomingDataHandler logic @@ -1239,17 +1186,13 @@ RESULT_CODE ProtocolHandlerImpl::EncryptFrame(ProtocolFramePtr packet) { packet->frame_type() == FRAME_TYPE_CONTROL) { return RESULT_OK; } - if (!session_observer_) { - LOG4CXX_WARN(logger_, "No session_observer_ set."); - return RESULT_FAIL; - } if (!security_manager_) { LOG4CXX_WARN(logger_, "No security_manager_ set."); return RESULT_FAIL; } - const uint32_t connection_key = session_observer_->KeyFromPair( + const uint32_t connection_key = session_observer_.KeyFromPair( packet->connection_id(), packet->session_id()); - security_manager::SSLContext *context = session_observer_->GetSSLContext( + security_manager::SSLContext *context = session_observer_.GetSSLContext( connection_key, ServiceTypeFromByte(packet->service_type())); if (!context || !context->IsInitCompleted()) { return RESULT_OK; @@ -1263,7 +1206,7 @@ RESULT_CODE ProtocolHandlerImpl::EncryptFrame(ProtocolFramePtr packet) { security_manager_->SendInternalError(connection_key, security_manager::SecurityManager::ERROR_ENCRYPTION_FAILED, error_text); // Close session to prevent usage unprotected service/session - session_observer_->OnSessionEndedCallback( + session_observer_.OnSessionEndedCallback( packet->connection_id(), packet->session_id(), packet->message_id(), kRpc); return RESULT_OK; @@ -1285,17 +1228,13 @@ RESULT_CODE ProtocolHandlerImpl::DecryptFrame(ProtocolFramePtr packet) { packet->frame_type() == FRAME_TYPE_CONTROL) { return RESULT_OK; } - if (!session_observer_) { - LOG4CXX_WARN(logger_, "No session_observer_ set."); - return RESULT_FAIL; - } if (!security_manager_) { LOG4CXX_WARN(logger_, "No security_manager_ set."); return RESULT_FAIL; } - const uint32_t connection_key = session_observer_->KeyFromPair( + const uint32_t connection_key = session_observer_.KeyFromPair( packet->connection_id(), packet->session_id()); - security_manager::SSLContext *context = session_observer_->GetSSLContext( + security_manager::SSLContext *context = session_observer_.GetSSLContext( connection_key, ServiceTypeFromByte(packet->service_type())); if (!context || !context->IsInitCompleted()) { const std::string error_text("Fail decryption for unprotected service "); @@ -1313,7 +1252,7 @@ RESULT_CODE ProtocolHandlerImpl::DecryptFrame(ProtocolFramePtr packet) { security_manager_->SendInternalError(connection_key, security_manager::SecurityManager::ERROR_DECRYPTION_FAILED, error_text); // Close session to prevent usage unprotected service/session - session_observer_->OnSessionEndedCallback( + session_observer_.OnSessionEndedCallback( packet->connection_id(), packet->session_id(), packet->message_id(), kRpc); return RESULT_ENCRYPTION_FAILED; @@ -1335,9 +1274,9 @@ void ProtocolHandlerImpl::SendFramesNumber(uint32_t connection_key, // TODO(EZamakhov): add protocol version check - to avoid send for PROTOCOL_VERSION_1 transport_manager::ConnectionUID connection_id = 0; uint8_t session_id = 0; - session_observer_->PairFromKey(connection_key, &connection_id, &session_id); + session_observer_.PairFromKey(connection_key, &connection_id, &session_id); uint8_t protocol_version; - if (session_observer_->ProtocolVersionUsed(connection_id, session_id, + if (session_observer_.ProtocolVersionUsed(connection_id, session_id, protocol_version)) { ProtocolFramePtr ptr(new protocol_handler::ProtocolPacket(connection_id, protocol_version, PROTECTION_OFF, FRAME_TYPE_CONTROL, @@ -1380,12 +1319,13 @@ std::string ConvertPacketDataToString(const uint8_t *data, return is_printable_array ? std::string(text, data_size) : std::string("is raw data"); } -uint8_t SupportedSDLProtocolVersion() { +uint8_t ProtocolHandlerImpl::SupportedSDLProtocolVersion() const { LOG4CXX_AUTO_TRACE(logger_); bool heart_beat_support = - (0 != profile::Profile::instance()->heart_beat_timeout()); - bool sdl4_support = profile::Profile::instance()->enable_protocol_4(); + (0 != get_settings().heart_beat_timeout()); + + bool sdl4_support = get_settings().enable_protocol_4(); if (sdl4_support) { return PROTOCOL_VERSION_4; diff --git a/src/components/protocol_handler/test/CMakeLists.txt b/src/components/protocol_handler/test/CMakeLists.txt index 3cb0dfc106..44b609edb9 100644 --- a/src/components/protocol_handler/test/CMakeLists.txt +++ b/src/components/protocol_handler/test/CMakeLists.txt @@ -31,6 +31,7 @@ if(BUILD_TESTS) include_directories( + include ${GMOCK_INCLUDE_DIRECTORY} ${COMPONENTS_DIR}/protocol_handler/include ${COMPONENTS_DIR}/protocol_handler/test/include diff --git a/src/components/protocol_handler/test/include/control_message_matcher.h b/src/components/protocol_handler/test/include/protocol_handler/control_message_matcher.h index 9239d0847f..9239d0847f 100644 --- a/src/components/protocol_handler/test/include/control_message_matcher.h +++ b/src/components/protocol_handler/test/include/protocol_handler/control_message_matcher.h diff --git a/src/components/protocol_handler/test/include/protocol_handler_mock.h b/src/components/protocol_handler/test/include/protocol_handler/protocol_handler_mock.h index 9ad3545ceb..575e82514a 100644 --- a/src/components/protocol_handler/test/include/protocol_handler_mock.h +++ b/src/components/protocol_handler/test/include/protocol_handler/protocol_handler_mock.h @@ -35,7 +35,8 @@ #include <gmock/gmock.h> #include "transport_manager/transport_manager.h" #include "protocol_handler/session_observer.h" -#include "protocol_handler/protocol_packet.h" +#include "protocol_handler/protocol_handler.h" +#include "protocol_handler/protocol_handler_settings.h" namespace test { namespace components { @@ -59,114 +60,12 @@ class ProtocolHandlerMock : public protocol_handler::ProtocolHandler { void(::protocol_handler::ProtocolObserver *observer)); MOCK_METHOD2(SendFramesNumber, void(uint32_t connection_key, int32_t number_of_frames)); - MOCK_METHOD2(SendHeartBeat, - void(int32_t connection_id, uint8_t session_id)); - MOCK_METHOD2(SendEndSession, - void(int32_t connection_id, uint8_t session_id)); + MOCK_METHOD2(SendHeartBeat, void(int32_t connection_id, uint8_t session_id)); + MOCK_METHOD2(SendEndSession, void(int32_t connection_id, uint8_t session_id)); MOCK_METHOD3(SendEndService, void(int32_t connection_id, uint8_t session_id, uint8_t service_type)); -}; - -/* - * MOCK implementation of transport_manager::TransportManager interface - */ -class TransportManagerMock : public TransportManager { - public: - MOCK_METHOD0(Init, - int()); - MOCK_METHOD0(SearchDevices, - int()); - MOCK_METHOD1(ConnectDevice, - int(const DeviceHandle&)); - MOCK_METHOD1(DisconnectDevice, - int(const DeviceHandle&)); - MOCK_METHOD1(Disconnect, - int(const ConnectionUID &)); - MOCK_METHOD1(DisconnectForce, - int(const ConnectionUID &)); - MOCK_METHOD1(SendMessageToDevice, - int(const ::protocol_handler::RawMessagePtr)); - MOCK_METHOD1(ReceiveEventFromDevice, - int(const TransportAdapterEvent&)); - MOCK_METHOD1(AddTransportAdapter, - int(transport_adapter::TransportAdapter *)); - MOCK_METHOD1(AddEventListener, - int(TransportManagerListener *)); - MOCK_METHOD0(Stop, - int()); - MOCK_METHOD1(RemoveDevice, - int(const DeviceHandle& )); - MOCK_CONST_METHOD1(Visibility, - int(const bool &)); - MOCK_METHOD0(Reinit, - int()); -}; - -/* - * MOCK implementation of protocol_handler::SessionObserver interface - */ -class SessionObserverMock : public protocol_handler::SessionObserver { - public: -#ifdef ENABLE_SECURITY - MOCK_METHOD2(SetSSLContext, - int (const uint32_t& key, - security_manager::SSLContext* context)); - MOCK_METHOD2(GetSSLContext, - security_manager::SSLContext* ( - const uint32_t& key, - const protocol_handler::ServiceType& service_type)); -#endif // ENABLE_SECURITY - MOCK_METHOD2(SetProtectionFlag, - void( - const uint32_t& key, - const protocol_handler::ServiceType& service_type)); - MOCK_METHOD5(OnSessionStartedCallback, - uint32_t( - const transport_manager::ConnectionUID &connection_handle, - const uint8_t session_id, - const ::protocol_handler::ServiceType &service_type, - const bool is_protected, uint32_t* hash_id)); - MOCK_METHOD4(OnSessionEndedCallback, - uint32_t( - const transport_manager::ConnectionUID& connection_handle, - const uint8_t sessionId, - const uint32_t& hashCode, - const protocol_handler::ServiceType& service_type)); - MOCK_METHOD1(OnApplicationFloodCallBack, - void(const uint32_t&)); - MOCK_METHOD1(OnMalformedMessageCallback, - void(const uint32_t&)); - MOCK_METHOD2(KeyFromPair, - uint32_t( - transport_manager::ConnectionUID connection_handle, - uint8_t sessionId)); - MOCK_METHOD3(PairFromKey, - void( - uint32_t key, - transport_manager::ConnectionUID* connection_handle, - uint8_t* sessionId)); - MOCK_METHOD4(GetDataOnSessionKey, - int32_t(uint32_t key, - uint32_t* app_id, - std::list<int32_t>* sessions_list, - uint32_t* device_id)); - MOCK_METHOD5(GetDataOnDeviceID, - int32_t( - uint32_t device_handle, - std::string *device_name, - std::list<uint32_t> *applications_list, - std::string *mac_address, - std::string *connection_type)); - MOCK_METHOD2(IsHeartBeatSupported, - bool( transport_manager::ConnectionUID connection_handle, - uint8_t session_id)); - MOCK_METHOD3(ProtocolVersionUsed, - bool( uint32_t connection_id, - uint8_t session_id, uint8_t& protocol_version)); -#ifdef ENABLE_SECURITY - MOCK_CONST_METHOD1(GetHandshakeContext, - security_manager::SSLContext::HandshakeContext (const uint32_t key) ); -#endif // ENABLE_SECURITY + MOCK_CONST_METHOD0(get_settings, + const ::protocol_handler::ProtocolHandlerSettings&()); }; #ifdef ENABLE_SECURITY diff --git a/src/components/protocol_handler/test/include/protocol_observer_mock.h b/src/components/protocol_handler/test/include/protocol_handler/protocol_observer_mock.h index c415e66e40..c415e66e40 100644 --- a/src/components/protocol_handler/test/include/protocol_observer_mock.h +++ b/src/components/protocol_handler/test/include/protocol_handler/protocol_observer_mock.h diff --git a/src/components/protocol_handler/test/include/session_observer_mock.h b/src/components/protocol_handler/test/include/session_observer_mock.h deleted file mode 100644 index 383ebaa161..0000000000 --- a/src/components/protocol_handler/test/include/session_observer_mock.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2014, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef TEST_COMPONENTS_INCLUDE_PROTOCOL_HANDLER_SESSION_OBSERVER_MOCK_H_ -#define TEST_COMPONENTS_INCLUDE_PROTOCOL_HANDLER_SESSION_OBSERVER_MOCK_H_ - -#include <gmock/gmock.h> -#include <string> -#include <list> -#include "protocol_handler/session_observer.h" - -namespace test { -namespace components { -namespace protocol_handler_test { -/* - * MOCK implementation of ::protocol_handler::SessionObserver interface - */ -class SessionObserverMock: public ::protocol_handler::SessionObserver { - public: - MOCK_METHOD5(OnSessionStartedCallback, - uint32_t( - const transport_manager::ConnectionUID &connection_handle, - const uint8_t session_id, - const ::protocol_handler::ServiceType &service_type, - const bool is_protected, uint32_t* hash_id)); - MOCK_METHOD4(OnSessionEndedCallback, - uint32_t( - const transport_manager::ConnectionUID &connection_handle, - const uint8_t sessionId, - const uint32_t &hashCode, - const ::protocol_handler::ServiceType &service_type)); - MOCK_METHOD1(OnApplicationFloodCallBack, - void(const uint32_t&)); - MOCK_METHOD1(OnMalformedMessageCallback, - void(const uint32_t&)); - MOCK_METHOD2(KeyFromPair, - uint32_t( - transport_manager::ConnectionUID connection_handle, - uint8_t sessionId)); - MOCK_METHOD3(PairFromKey, - void( - uint32_t key, - transport_manager::ConnectionUID *connection_handle, - uint8_t *sessionId)); - MOCK_METHOD4(GetDataOnSessionKey, - int32_t(uint32_t key, - uint32_t *app_id, - std::list<int32_t> *sessions_list, - uint32_t *device_id)); - MOCK_METHOD5(GetDataOnDeviceID, - int32_t( - uint32_t device_handle, - std::string *device_name, - std::list<uint32_t> *applications_list, - std::string *mac_address, - std::string *connection_type)); - MOCK_METHOD2(IsHeartBeatSupported, - bool(transport_manager::ConnectionUID connection_handle, - uint8_t session_id)); - MOCK_METHOD3(ProtocolVersionUsed, - bool ( uint32_t connection_id, - uint8_t session_id, uint8_t& protocol_version)); -#ifdef ENABLE_SECURITY - MOCK_METHOD2(SetSSLContext, - int(const uint32_t &key, - ::security_manager::SSLContext *context)); - MOCK_METHOD2(GetSSLContext, - ::security_manager::SSLContext * ( - const uint32_t &key, - const ::protocol_handler::ServiceType &service_type)); - MOCK_METHOD2(SetProtectionFlag, - void( - const uint32_t &key, - const ::protocol_handler::ServiceType &service_type)); - MOCK_CONST_METHOD1(GetHandshakeContext, - security_manager::SSLContext::HandshakeContext (const uint32_t key) ); - -#endif // ENABLE_SECURITY -}; -} // namespace protocol_handler_test -} // namespace components -} // namespace test -#endif // TEST_COMPONENTS_INCLUDE_PROTOCOL_HANDLER_SESSION_OBSERVER_MOCK_H_ diff --git a/src/components/protocol_handler/test/protocol_handler_tm_test.cc b/src/components/protocol_handler/test/protocol_handler_tm_test.cc index ea8f7b122e..769678dc27 100644 --- a/src/components/protocol_handler/test/protocol_handler_tm_test.cc +++ b/src/components/protocol_handler/test/protocol_handler_tm_test.cc @@ -29,32 +29,36 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include <gtest/gtest.h> +#include "gtest/gtest.h" #include <string> +#include "protocol_handler/protocol_handler.h" #include "protocol_handler/protocol_handler_impl.h" #include "protocol/common.h" -#include "control_message_matcher.h" -#include "protocol_handler_mock.h" -#include "protocol_observer_mock.h" +#include "protocol_handler/control_message_matcher.h" +#include "protocol_handler/protocol_handler_mock.h" +#include "protocol_handler/protocol_observer_mock.h" +#include "protocol_handler/mock_protocol_handler_settings.h" +#include "protocol_handler/mock_session_observer.h" +#include "connection_handler/mock_connection_handler.h" +#include "transport_manager/transport_manager_mock.h" +#include "utils/make_shared.h" namespace test { namespace components { namespace protocol_handler_test { -// id passed as NULL for new session establishing +// Id passed as NULL for new session establishing #define NEW_SESSION_ID 0u #define SESSION_START_REJECT 0u using namespace ::protocol_handler; using namespace ::transport_manager; -// For TM states using ::transport_manager::TransportManagerListener; using ::testing::Return; +using ::testing::ReturnRefOfCopy; using ::testing::ReturnNull; using ::testing::AnyOf; -using ::testing::Ge; -using ::testing::Le; using ::testing::_; using ::testing::Invoke; @@ -65,15 +69,26 @@ class ProtocolHandlerImplTest : public ::testing::Test { bool malformed_message_filtering = false, const size_t malformd_period_msec = 0u, const size_t malformd_max_messages = 0u, - const int32_t multiframe_waiting_timeout = 0) { - protocol_handler_impl.reset( - new ProtocolHandlerImpl(&transport_manager_mock, - period_msec, max_messages, - malformed_message_filtering, - malformd_period_msec, - malformd_max_messages, - multiframe_waiting_timeout)); - protocol_handler_impl->set_session_observer(&session_observer_mock); + const int32_t multiframe_waiting_timeout = 0, + const size_t maximum_payload_size = 0u) { + ON_CALL(protocol_handler_settings_mock, maximum_payload_size()) + .WillByDefault(Return(maximum_payload_size)); + ON_CALL(protocol_handler_settings_mock, message_frequency_time()) + .WillByDefault(Return(period_msec)); + ON_CALL(protocol_handler_settings_mock, message_frequency_count()) + .WillByDefault(Return(max_messages)); + ON_CALL(protocol_handler_settings_mock, malformed_message_filtering()) + .WillByDefault(Return(malformed_message_filtering)); + ON_CALL(protocol_handler_settings_mock, malformed_frequency_time()) + .WillByDefault(Return(malformd_period_msec)); + ON_CALL(protocol_handler_settings_mock, malformed_frequency_count()) + .WillByDefault(Return(malformd_max_messages)); + ON_CALL(protocol_handler_settings_mock, multiframe_waiting_timeout()) + .WillByDefault(Return(multiframe_waiting_timeout)); + protocol_handler_impl.reset(new ProtocolHandlerImpl(protocol_handler_settings_mock, + session_observer_mock, + connection_handler_mock, + transport_manager_mock)); tm_listener = protocol_handler_impl.get(); } void SetUp() OVERRIDE { @@ -84,14 +99,14 @@ class ProtocolHandlerImplTest : public ::testing::Test { message_id = 0xABCDEFu; some_data.resize(256, 0xAB); - // expect ConnectionHandler support methods call (conversion, check heartbeat) + // Expect ConnectionHandler support methods call (conversion, check heartbeat) EXPECT_CALL(session_observer_mock, KeyFromPair(connection_id, _)). - //return some connection_key + // Return some connection_key WillRepeatedly(Return(connection_key)); EXPECT_CALL(session_observer_mock, IsHeartBeatSupported(connection_id, _)). - //return false to avoid call KeepConnectionAlive + // Return false to avoid call KeepConnectionAlive WillRepeatedly(Return(false)); } @@ -117,14 +132,14 @@ class ProtocolHandlerImplTest : public ::testing::Test { // For disabled protection callback shall ignore protection income flad and use protection OFF const bool callback_protection_flag = PROTECTION_OFF; #endif // ENABLE_SECURITY - // expect ConnectionHandler check + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback(connection_id, NEW_SESSION_ID, start_service, callback_protection_flag, _)). - //return sessions start success + // Return sessions start success WillOnce(Return(session_id)); - // expect send Ack with PROTECTION_OFF (on no Security Manager) + // Expect send Ack with PROTECTION_OFF (on no Security Manager) EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))) .WillOnce(Return(E_SUCCESS)); @@ -147,9 +162,16 @@ class ProtocolHandlerImplTest : public ::testing::Test { const ProtocolPacket packet(connection_id, version, protection, frameType, serviceType, frameData, sessionId, dataSize, messageID, data); - // Emulate resive packet from transoprt manager + // Emulate receive packet from transoprt manager tm_listener->OnTMMessageReceived(packet.serializePacket()); } + + void SetProtocolVersion2() { + // Set protocol version 2 + ON_CALL(protocol_handler_settings_mock, max_supported_protocol_version()) + .WillByDefault(Return(PROTOCOL_VERSION_2)); + } + void SendControlMessage(bool protection, uint8_t service_type, uint8_t sessionId, uint32_t frame_data, uint32_t dataSize = 0u, const uint8_t *data = NULL) { @@ -158,19 +180,21 @@ class ProtocolHandlerImplTest : public ::testing::Test { dataSize, message_id, data); } + testing::NiceMock<MockProtocolHandlerSettings> protocol_handler_settings_mock; ::utils::SharedPtr<ProtocolHandlerImpl> protocol_handler_impl; TransportManagerListener* tm_listener; // Uniq connection ::transport_manager::ConnectionUID connection_id; - // id of established session + // Id of established session uint8_t session_id; - // uniq id as connection_id and session_id in one + // Uniq id as connection_id and session_id in one uint32_t connection_key; uint32_t message_id; std::vector<uint8_t> some_data; // Strict mocks (same as all methods EXPECT_CALL().Times(0)) - testing::StrictMock<protocol_handler_test::TransportManagerMock> transport_manager_mock; - testing::StrictMock<protocol_handler_test::SessionObserverMock> session_observer_mock; + testing::NiceMock<connection_handler_test::MockConnectionHandler> connection_handler_mock; + testing::StrictMock<transport_manager_test::TransportManagerMock> transport_manager_mock; + testing::StrictMock<protocol_handler_test::MockSessionObserver> session_observer_mock; #ifdef ENABLE_SECURITY testing::NiceMock<protocol_handler_test::SecurityManagerMock> security_manager_mock; testing::NiceMock<protocol_handler_test::SSLContextMock> ssl_context_mock; @@ -216,15 +240,15 @@ TEST_F(ProtocolHandlerImplTest, RecieveOnUnknownConnection) { TEST_F(ProtocolHandlerImplTest, StartSession_Unprotected_SessionObserverReject) { const int call_times = 5; AddConnection(); - // expect ConnectionHandler check + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback( connection_id, NEW_SESSION_ID, AnyOf(kControl, kRpc, kAudio, kMobileNav, kBulk), PROTECTION_OFF, _)).Times(call_times). - //return sessions start rejection + // Return sessions start rejection WillRepeatedly(Return(SESSION_START_REJECT)); - // expect send NAck + // Expect send NAck EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_NACK, PROTECTION_OFF))) .Times(call_times).WillRepeatedly(Return(E_SUCCESS)); @@ -255,16 +279,16 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverReject) { // For disabled protection callback shall ignore protection income flag and use protection OFF const bool callback_protection_flag = PROTECTION_OFF; #endif // ENABLE_SECURITY - // expect ConnectionHandler check + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback( connection_id, NEW_SESSION_ID, AnyOf(kControl, kRpc, kAudio, kMobileNav, kBulk), callback_protection_flag, _)).Times( call_times). - //return sessions start rejection + // Return sessions start rejection WillRepeatedly(Return(SESSION_START_REJECT)); - // expect send NAck with encryption OFF + // Expect send NAck with encryption OFF EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_NACK, PROTECTION_OFF))) .Times(call_times).WillRepeatedly(Return(E_SUCCESS)); @@ -287,14 +311,15 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverReject) { TEST_F(ProtocolHandlerImplTest, StartSession_Unprotected_SessionObserverAccept) { AddConnection(); const ServiceType start_service = kRpc; - // expect ConnectionHandler check + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback(connection_id, NEW_SESSION_ID, start_service, PROTECTION_OFF, _)) . - //return sessions start success + // Return sessions start success WillOnce(Return(session_id)); - // expect send Ack + SetProtocolVersion2(); + // Expect send Ack EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))) .WillOnce(Return(E_SUCCESS)); @@ -308,6 +333,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Unprotected_SessionObserverAccept) * For ENABLE_SECURITY=OFF session_observer shall be called with protection flag OFF */ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverAccept) { + SetProtocolVersion2(); AddSession(); } // TODO(EZamakhov): add test for get_hash_id/set_hash_id from protocol_handler_impl.cc @@ -318,13 +344,14 @@ TEST_F(ProtocolHandlerImplTest, EndSession_SessionObserverReject) { AddSession(); const ServiceType service = kRpc; - // expect ConnectionHandler check + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionEndedCallback(connection_id, session_id, _, service)). // reject session start WillOnce(Return(SESSION_START_REJECT)); - // expect send NAck + SetProtocolVersion2(); + // Expect send NAck EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_END_SERVICE_NACK, PROTECTION_OFF))) .WillOnce(Return(E_SUCCESS)); @@ -339,13 +366,14 @@ TEST_F(ProtocolHandlerImplTest, EndSession_Success) { AddSession(); const ServiceType service = kRpc; - // expect ConnectionHandler check + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionEndedCallback(connection_id, session_id, _, service)). // return sessions start success WillOnce(Return(connection_key)); - // expect send Ack + SetProtocolVersion2(); + // Expect send Ack EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_END_SERVICE_ACK, PROTECTION_OFF))) .WillOnce(Return(E_SUCCESS)); @@ -364,13 +392,14 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtocoloV1) { // Add security manager AddSecurityManager(); const ServiceType start_service = kRpc; - // expect ConnectionHandler check + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback(connection_id, NEW_SESSION_ID, start_service, PROTECTION_OFF, _)). - //return sessions start success + // Return sessions start success WillOnce(Return(session_id)); - // expect send Ack with PROTECTION_OFF (on no Security Manager) + SetProtocolVersion2(); + // Expect send Ack with PROTECTION_OFF (on no Security Manager) EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))). WillOnce(Return(E_SUCCESS)); @@ -386,13 +415,14 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionUnprotected) { // Add security manager AddSecurityManager(); const ServiceType start_service = kRpc; - // expect ConnectionHandler check + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback(connection_id, NEW_SESSION_ID, start_service, PROTECTION_OFF, _)). - //return sessions start success + // Return sessions start success WillOnce(Return(session_id)); - // expect send Ack with PROTECTION_OFF (on no Security Manager) + SetProtocolVersion2(); + // Expect send Ack with PROTECTION_OFF (on no Security Manager) EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))). WillOnce(Return(E_SUCCESS)); @@ -406,19 +436,20 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_Fail) { AddConnection(); AddSecurityManager(); const ServiceType start_service = kRpc; - // expect ConnectionHandler check + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback(connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)). - //return sessions start success + // Return sessions start success WillOnce(Return(session_id)); - // expect start protection for unprotected session + SetProtocolVersion2(); + // Expect start protection for unprotected session EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key)). - //return fail protection + // Return fail protection WillOnce(ReturnNull()); - // expect send Ack with PROTECTION_OFF (on fail SLL creation) + // Expect send Ack with PROTECTION_OFF (on fail SLL creation) EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))). WillOnce(Return(E_SUCCESS)); @@ -432,19 +463,20 @@ TEST_F(ProtocolHandlerImplTest,SecurityEnable_StartSessionProtected_SSLInitializ AddConnection(); AddSecurityManager(); const ServiceType start_service = kRpc; - // expect ConnectionHandler check + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback(connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)). - //return sessions start success + // Return sessions start success WillOnce(Return(session_id)); + SetProtocolVersion2(); // call new SSLContext creation EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key)). - //return new SSLContext + // Return new SSLContext WillOnce(Return(&ssl_context_mock)); - // initilization check + // Initilization check EXPECT_CALL(ssl_context_mock, IsInitCompleted()). //emulate SSL is initilized @@ -454,7 +486,7 @@ TEST_F(ProtocolHandlerImplTest,SecurityEnable_StartSessionProtected_SSLInitializ EXPECT_CALL(session_observer_mock, SetProtectionFlag(connection_key, start_service)); - // expect send Ack with PROTECTION_ON (on SSL is initilized) + // Expect send Ack with PROTECTION_ON (on SSL is initilized) EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_ON))). WillOnce(Return(E_SUCCESS)); @@ -468,19 +500,26 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_HandshakeFa AddConnection(); AddSecurityManager(); const ServiceType start_service = kRpc; - // expect ConnectionHandler check + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback(connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)). - //return sessions start success + // Return sessions start success WillOnce(Return(session_id)); + std::vector<int> services; + // TODO(AKutsan) : APPLINK-21398 use named constants instead of magic numbers + services.push_back(0x0A); + services.push_back(0x0B); + ON_CALL(protocol_handler_settings_mock, force_protected_service()) + .WillByDefault(ReturnRefOfCopy(services)); + // call new SSLContext creation EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key)). - //return new SSLContext + // Return new SSLContext WillOnce(Return(&ssl_context_mock)); - // initilization check + // Initilization check EXPECT_CALL(ssl_context_mock, IsInitCompleted()). //emulate SSL is not initilized @@ -492,10 +531,10 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_HandshakeFa //emulate is pending WillOnce(Return(true)); - // expect add listener for handshake result + // Expect add listener for handshake result EXPECT_CALL(security_manager_mock, AddListener(_)) - // emulate handshake fail + // Emulate handshake fail .WillOnce(Invoke(OnHandshakeDoneFunctor( connection_key, security_manager::SSLContext::Handshake_Result_Fail))); @@ -503,10 +542,10 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_HandshakeFa // Listener check SSLContext EXPECT_CALL(session_observer_mock, GetSSLContext(connection_key, start_service)). - // emulate protection for service is not enabled + // Emulate protection for service is not enabled WillOnce(ReturnNull()); - // expect send Ack with PROTECTION_OFF (on fail handshake) + // Expect send Ack with PROTECTION_OFF (on fail handshake) EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))). WillOnce(Return(E_SUCCESS)); @@ -520,19 +559,25 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_HandshakeSu AddConnection(); AddSecurityManager(); const ServiceType start_service = kRpc; - // expect ConnectionHandler check + + // No services are protected + std::vector<int> services; + ON_CALL(protocol_handler_settings_mock, force_protected_service()) + .WillByDefault(ReturnRefOfCopy(services)); + + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback(connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)). - //return sessions start success + // Return sessions start success WillOnce(Return(session_id)); // call new SSLContext creation EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key)). - //return new SSLContext + // Return new SSLContext WillOnce(Return(&ssl_context_mock)); - // initilization check + // Initilization check EXPECT_CALL(ssl_context_mock, IsInitCompleted()). //emulate SSL is not initilized @@ -544,10 +589,10 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_HandshakeSu //emulate is pending WillOnce(Return(true)); - // expect add listener for handshake result + // Expect add listener for handshake result EXPECT_CALL(security_manager_mock, AddListener(_)) - // emulate handshake fail + // Emulate handshake fail .WillOnce(Invoke(OnHandshakeDoneFunctor( connection_key, security_manager::SSLContext::Handshake_Result_Success))); @@ -555,14 +600,14 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_HandshakeSu // Listener check SSLContext EXPECT_CALL(session_observer_mock, GetSSLContext(connection_key, start_service)). - // emulate protection for service is not enabled + // Emulate protection for service is not enabled WillOnce(ReturnNull()); // Expect service protection enable EXPECT_CALL(session_observer_mock, SetProtectionFlag(connection_key, start_service)); - // expect send Ack with PROTECTION_OFF (on fail handshake) + // Expect send Ack with PROTECTION_OFF (on fail handshake) EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_ON))). WillOnce(Return(E_SUCCESS)); @@ -577,19 +622,24 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSecurityManager(); const ServiceType start_service = kRpc; - // expect ConnectionHandler check + + std::vector<int> services; + ON_CALL(protocol_handler_settings_mock, force_protected_service()) + .WillByDefault(ReturnRefOfCopy(services)); + + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback(connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)). - //return sessions start success + // Return sessions start success WillOnce(Return(session_id)); // call new SSLContext creation EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key)). - //return new SSLContext + // Return new SSLContext WillOnce(Return(&ssl_context_mock)); - // initilization check + // Initilization check EXPECT_CALL(ssl_context_mock, IsInitCompleted()). //emulate SSL is not initilized @@ -601,10 +651,10 @@ TEST_F(ProtocolHandlerImplTest, //emulate is pending WillOnce(Return(true)); - // expect add listener for handshake result + // Expect add listener for handshake result EXPECT_CALL(security_manager_mock, AddListener(_)) - // emulate handshake fail + // Emulate handshake fail .WillOnce(Invoke(OnHandshakeDoneFunctor( connection_key, security_manager::SSLContext::Handshake_Result_Success))); @@ -612,14 +662,14 @@ TEST_F(ProtocolHandlerImplTest, // Listener check SSLContext EXPECT_CALL(session_observer_mock, GetSSLContext(connection_key, start_service)). - // emulate protection for service is not enabled + // Emulate protection for service is not enabled WillOnce(ReturnNull()); // Expect service protection enable EXPECT_CALL(session_observer_mock, SetProtectionFlag(connection_key, start_service)); - // expect send Ack with PROTECTION_OFF (on fail handshake) + // Expect send Ack with PROTECTION_OFF (on fail handshake) EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_ON))). WillOnce(Return(E_SUCCESS)); @@ -634,19 +684,24 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSecurityManager(); const ServiceType start_service = kRpc; - // expect ConnectionHandler check + + std::vector<int> services; + ON_CALL(protocol_handler_settings_mock, force_protected_service()) + .WillByDefault(ReturnRefOfCopy(services)); + + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback(connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)). - //return sessions start success + // Return sessions start success WillOnce(Return(session_id)); // call new SSLContext creation EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key)). - //return new SSLContext + // Return new SSLContext WillOnce(Return(&ssl_context_mock)); - // initilization check + // Initilization check EXPECT_CALL(ssl_context_mock, IsInitCompleted()). //emulate SSL is not initilized @@ -662,10 +717,10 @@ TEST_F(ProtocolHandlerImplTest, EXPECT_CALL(security_manager_mock, StartHandshake(connection_key)); - // expect add listener for handshake result + // Expect add listener for handshake result EXPECT_CALL(security_manager_mock, AddListener(_)) - // emulate handshake fail + // Emulate handshake fail .WillOnce(Invoke(OnHandshakeDoneFunctor( connection_key, security_manager::SSLContext::Handshake_Result_Success))); @@ -673,14 +728,14 @@ TEST_F(ProtocolHandlerImplTest, // Listener check SSLContext EXPECT_CALL(session_observer_mock, GetSSLContext(connection_key, start_service)). - // emulate protection for service is not enabled + // Emulate protection for service is not enabled WillOnce(ReturnNull()); // Expect service protection enable EXPECT_CALL(session_observer_mock, SetProtectionFlag(connection_key, start_service)); - // expect send Ack with PROTECTION_OFF (on fail handshake) + // Expect send Ack with PROTECTION_OFF (on fail handshake) EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_ON))). WillOnce(Return(E_SUCCESS)); @@ -697,11 +752,16 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSession(); - // expect flood notification to CH + // Expect flood notification to CH EXPECT_CALL(session_observer_mock, OnApplicationFloodCallBack(connection_key)). Times(1); + ON_CALL(protocol_handler_settings_mock, message_frequency_time()) + .WillByDefault(Return(period_msec)); + ON_CALL(protocol_handler_settings_mock, message_frequency_count()) + .WillByDefault(Return(max_messages)); + for (size_t i = 0; i < max_messages + 1; ++i) { SendTMMessage(connection_id, PROTOCOL_VERSION_3, PROTECTION_OFF, FRAME_TYPE_SINGLE, kControl, FRAME_DATA_SINGLE, session_id, @@ -716,7 +776,14 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSession(); - // expect NO flood notification to CH + ON_CALL(protocol_handler_settings_mock, message_frequency_time()) + .WillByDefault(Return(period_msec)); + ON_CALL(protocol_handler_settings_mock, message_frequency_count()) + .WillByDefault(Return(max_messages)); + + // Expect NO flood notification to CH + EXPECT_CALL(session_observer_mock, OnApplicationFloodCallBack(connection_key)) + .Times(0); for (size_t i = 0; i < max_messages - 1; ++i) { SendTMMessage(connection_id, PROTOCOL_VERSION_3, PROTECTION_OFF, FRAME_TYPE_SINGLE, kControl, FRAME_DATA_SINGLE, session_id, @@ -731,7 +798,7 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSession(); - // expect NO flood notification to CH on video data streaming + // Expect NO flood notification to CH on video data streaming for (size_t i = 0; i < max_messages + 1; ++i) { SendTMMessage(connection_id, PROTOCOL_VERSION_3, PROTECTION_OFF, FRAME_TYPE_SINGLE, kMobileNav, FRAME_DATA_SINGLE, session_id, @@ -746,7 +813,7 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSession(); - // expect NO flood notification to CH on video data streaming + // Expect NO flood notification to CH on video data streaming for (size_t i = 0; i < max_messages + 1; ++i) { SendTMMessage(connection_id, PROTOCOL_VERSION_3, PROTECTION_OFF, FRAME_TYPE_SINGLE, kAudio, FRAME_DATA_SINGLE, session_id, @@ -761,7 +828,7 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSession(); - // expect NO flood notification to session observer + // Expect NO flood notification to session observer for (size_t i = 0; i < max_messages + 1; ++i) { SendTMMessage(connection_id, PROTOCOL_VERSION_3, PROTECTION_OFF, FRAME_TYPE_SINGLE, kControl, FRAME_DATA_SINGLE, session_id, @@ -778,7 +845,7 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSession(); - // expect malformed notification to CH + // Expect malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)). Times(max_messages); @@ -799,7 +866,7 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSession(); - // expect malformed notification to CH + // Expect malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)). Times(1); @@ -826,7 +893,7 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSession(); - // expect malformed notification to CH + // Expect malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)). Times(1); @@ -864,7 +931,7 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSession(); - // expect NO malformed notification to CH + // Expect NO malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)). Times(0); @@ -899,7 +966,7 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSession(); - // expect no malformed notification to CH + // Expect no malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)). Times(0); @@ -920,7 +987,7 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSession(); - // expect no malformed notification to CH + // Expect no malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)). Times(0); |