summaryrefslogtreecommitdiff
path: root/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h')
-rw-r--r--src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h143
1 files changed, 89 insertions, 54 deletions
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 3732e23a4..bff972ede 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
@@ -36,20 +36,23 @@
#include <map>
#include <memory>
#include <set>
+#include <list>
#include "utils/prioritized_queue.h"
#include "utils/message_queue.h"
#include "utils/threads/message_loop_thread.h"
#include "utils/shared_ptr.h"
+#include "utils/messagemeter.h"
#include "protocol_handler/protocol_handler.h"
#include "protocol_handler/protocol_packet.h"
#include "protocol_handler/session_observer.h"
#include "protocol_handler/protocol_observer.h"
+#include "protocol_handler/incoming_data_handler.h"
#include "transport_manager/common.h"
#include "transport_manager/transport_manager.h"
#include "transport_manager/transport_manager_listener_empty.h"
#ifdef TIME_TESTER
-#include "time_metric_observer.h"
+#include "protocol_handler/time_metric_observer.h"
#endif // TIME_TESTER
#ifdef ENABLE_SECURITY
@@ -69,11 +72,6 @@ class MessagesToMobileAppHandler;
using transport_manager::TransportManagerListenerEmpty;
-/**
- * @brief Type definition for variable that hold shared pointer to raw message.
- */
-typedef utils::SharedPtr<protocol_handler::ProtocolPacket> ProtocolFramePtr;
-
typedef std::multimap<int32_t, RawMessagePtr> MessagesOverNaviMap;
typedef std::set<ProtocolObserver*> ProtocolObservers;
typedef transport_manager::ConnectionUID ConnectionID;
@@ -92,7 +90,8 @@ struct RawFordMessageFromMobile: public ProtocolFramePtr {
// PrioritizedQueue requires this method to decide which priority to assign
size_t PriorityOrder() const {
return MessagePriority::FromServiceType(
- ServiceTypeFromByte(get()->service_type())).OrderingValue(); }
+ ServiceTypeFromByte(get()->service_type())).OrderingValue();
+ }
};
struct RawFordMessageToMobile: public ProtocolFramePtr {
@@ -102,15 +101,16 @@ struct RawFordMessageToMobile: public ProtocolFramePtr {
// PrioritizedQueue requires this method to decide which priority to assign
size_t PriorityOrder() const {
return MessagePriority::FromServiceType(
- ServiceTypeFromByte(get()->service_type())).OrderingValue(); }
+ ServiceTypeFromByte(get()->service_type())).OrderingValue();
+ }
// Signals whether connection to mobile must be closed after processing this message
bool is_final;
};
// Short type names for prioritized message queues
-typedef threads::MessageLoopThread<
+typedef threads::MessageLoopThread <
utils::PrioritizedQueue<RawFordMessageFromMobile> > FromMobileQueue;
-typedef threads::MessageLoopThread<
+typedef threads::MessageLoopThread <
utils::PrioritizedQueue<RawFordMessageToMobile> > ToMobileQueue;
} // namespace impl
@@ -123,7 +123,7 @@ typedef threads::MessageLoopThread<
* about activities around sessions.
*/
class ProtocolHandlerImpl
- : public ProtocolHandler,
+ : public ProtocolHandler,
public TransportManagerListenerEmpty,
public impl::FromMobileQueue::Handler,
public impl::ToMobileQueue::Handler {
@@ -131,10 +131,21 @@ class ProtocolHandlerImpl
/**
* \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
* message exchange.
*/
explicit ProtocolHandlerImpl(
- transport_manager::TransportManager *transport_manager_param);
+ 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);
/**
* \brief Destructor
@@ -171,6 +182,11 @@ class ProtocolHandlerImpl
#endif // ENABLE_SECURITY
/**
+ * \brief Stop all handling activity
+ */
+ void Stop();
+
+ /**
* \brief Method for sending message to Mobile Application
* \param message Message with params to be sent to Mobile App
*/
@@ -179,7 +195,7 @@ class ProtocolHandlerImpl
/**
* \brief Sends number of processed frames in case of binary nav streaming
- * \param connection_key Id of connection over which message is to be sent
+ * \param connection_key Unique key used by other components as session identifier
* \param number_of_frames Number of frames processed by
* streaming server and displayed to user.
*/
@@ -207,6 +223,10 @@ class ProtocolHandlerImpl
*/
void SendEndSession(int32_t connection_id, uint8_t session_id);
+ void SendEndService(int32_t connection_id,
+ uint8_t session_id,
+ uint8_t service_type);
+
// TODO(Ezamakhov): move Ack/Nack as interface for StartSessionHandler
/**
* \brief Sends acknowledgement of starting session to mobile application
@@ -251,7 +271,7 @@ class ProtocolHandlerImpl
* mobile app for using when ending session.
* \param service_type Type of session: RPC or BULK Data. RPC by default
*/
- void SendEndSessionAck(ConnectionID connection_id ,
+ void SendEndSessionAck(ConnectionID connection_id,
uint8_t session_id,
uint8_t protocol_version,
uint8_t service_type);
@@ -264,12 +284,15 @@ class ProtocolHandlerImpl
* \param protocol_version Version of protocol used for communication
* \param service_type Type of session: RPC or BULK Data. RPC by default
*/
- void SendEndSessionNAck(ConnectionID connection_id ,
+ void SendEndSessionNAck(ConnectionID connection_id,
uint32_t session_id,
uint8_t protocol_version,
uint8_t service_type);
private:
+ void SendEndServicePrivate(int32_t connection_id, uint8_t session_id,
+ uint8_t service_type);
+
/*
* Prepare and send heartbeat acknowledge message
*/
@@ -283,7 +306,7 @@ class ProtocolHandlerImpl
* @param message Received message
**/
virtual void OnTMMessageReceived(
- const RawMessagePtr message);
+ const RawMessagePtr message);
/**
* @brief Notifies about error on receiving message from TM.
@@ -291,7 +314,7 @@ class ProtocolHandlerImpl
* @param error Occurred error
**/
virtual void OnTMMessageReceiveFailed(
- const transport_manager::DataReceiveError &error);
+ const transport_manager::DataReceiveError &error);
/**
* @brief Notifies about successfully sending message.
@@ -307,15 +330,15 @@ class ProtocolHandlerImpl
* @param message Message during sending which error occurred.
**/
virtual void OnTMMessageSendFailed(
- const transport_manager::DataSendError &error,
- const RawMessagePtr message);
+ const transport_manager::DataSendError &error,
+ const RawMessagePtr message);
virtual void OnConnectionEstablished(
- const transport_manager::DeviceInfo &device_info,
- const transport_manager::ConnectionUID &connection_id);
+ const transport_manager::DeviceInfo &device_info,
+ const transport_manager::ConnectionUID &connection_id);
virtual void OnConnectionClosed(
- const transport_manager::ConnectionUID &connection_id);
+ const transport_manager::ConnectionUID &connection_id);
/**
* @brief Notifies subscribers about message
@@ -336,11 +359,11 @@ class ProtocolHandlerImpl
* \param is_final_message if is_final_message = true - it is last message
* \return \saRESULT_CODE Status of operation
*/
- RESULT_CODE SendSingleFrameMessage(ConnectionID connection_id,
+ RESULT_CODE SendSingleFrameMessage(const ConnectionID connection_id,
const uint8_t session_id,
- uint32_t protocol_version,
+ const uint32_t protocol_version,
const uint8_t service_type,
- size_t data_size,
+ const size_t data_size,
const uint8_t *data,
const bool is_final_message);
@@ -357,13 +380,13 @@ class ProtocolHandlerImpl
* \param is_final_message if is_final_message = true - it is last message
* \return \saRESULT_CODE Status of operation
*/
- RESULT_CODE SendMultiFrameMessage(ConnectionID connection_id,
+ RESULT_CODE SendMultiFrameMessage(const ConnectionID connection_id,
const uint8_t session_id,
- uint32_t protocol_version,
+ const uint8_t protocol_version,
const uint8_t service_type,
const size_t data_size,
const uint8_t *data,
- const size_t max_data_size,
+ const size_t max_frame_size,
const bool is_final_message);
/**
@@ -381,8 +404,8 @@ class ProtocolHandlerImpl
* \return \saRESULT_CODE Status of operation
*/
RESULT_CODE HandleMessage(
- ConnectionID connection_id ,
- const ProtocolFramePtr packet);
+ ConnectionID connection_id,
+ const ProtocolFramePtr packet);
/**
* \brief Handles message received in single frame.
@@ -392,8 +415,8 @@ class ProtocolHandlerImpl
* \return \saRESULT_CODE Status of operation
*/
RESULT_CODE HandleSingleFrameMessage(
- ConnectionID connection_id ,
- const ProtocolFramePtr packet);
+ ConnectionID connection_id,
+ const ProtocolFramePtr packet);
/**
* \brief Handles message received in multiple frames. Collects all frames
* of message.
@@ -403,8 +426,8 @@ class ProtocolHandlerImpl
* \return \saRESULT_CODE Status of operation
*/
RESULT_CODE HandleMultiFrameMessage(
- ConnectionID connection_id ,
- const ProtocolFramePtr packet);
+ ConnectionID connection_id,
+ const ProtocolFramePtr packet);
/**
* \brief Handles message received in single frame.
@@ -414,27 +437,20 @@ class ProtocolHandlerImpl
* \return \saRESULT_CODE Status of operation
*/
RESULT_CODE HandleControlMessage(
- ConnectionID connection_id ,
- const ProtocolFramePtr packet);
+ ConnectionID connection_id,
+ const ProtocolFramePtr packet);
RESULT_CODE HandleControlMessageEndSession(
- ConnectionID connection_id ,
- const ProtocolPacket &packet);
+ ConnectionID connection_id,
+ const ProtocolPacket &packet);
RESULT_CODE HandleControlMessageStartSession(
- ConnectionID connection_id ,
- const ProtocolPacket &packet);
+ ConnectionID connection_id,
+ const ProtocolPacket &packet);
RESULT_CODE HandleControlMessageHeartBeat(
- ConnectionID connection_id ,
- const ProtocolPacket &packet);
-
- /**
- * \brief Sends Mobile Navi Ack message
- */
- RESULT_CODE SendMobileNaviAck(
- ConnectionID connection_id ,
- int32_t connection_key);
+ ConnectionID connection_id,
+ const ProtocolPacket &packet);
// threads::MessageLoopThread<*>::Handler implementations
// CALLED ON raw_ford_messages_from_mobile_ thread!
@@ -450,6 +466,12 @@ class ProtocolHandlerImpl
RESULT_CODE EncryptFrame(ProtocolFramePtr packet);
RESULT_CODE DecryptFrame(ProtocolFramePtr packet);
#endif // ENABLE_SECURITY
+
+ bool TrackMessage(const uint32_t &connection_key);
+
+ bool TrackMalformedMessage(const uint32_t &connection_key,
+ const size_t count);
+
private:
/**
*\brief Pointer on instance of class implementing IProtocolObserver
@@ -474,7 +496,7 @@ class ProtocolHandlerImpl
std::map<int32_t, ProtocolFramePtr> incomplete_multi_frame_messages_;
/**
- * \brief Map of messages (frames) recieved over mobile nave session
+ * \brief Map of messages (frames) received over mobile nave session
* for map streaming.
*/
MessagesOverNaviMap message_over_navi_session_;
@@ -487,10 +509,16 @@ class ProtocolHandlerImpl
/**
*\brief Counter of messages sent in each session.
+ * Used ad unique message identifier
*/
std::map<uint8_t, uint32_t> message_counters_;
/**
+ *\brief Counter of messages sent in each session.
+ */
+ std::map<ConnectionID, uint32_t> malformed_message_counters_;
+
+ /**
*\brief map for session last message.
*/
std::map<uint8_t, uint32_t> sessions_last_message_id_;
@@ -500,9 +528,17 @@ class ProtocolHandlerImpl
*/
std::list<uint32_t> ready_to_close_connections_;
-
- class IncomingDataHandler;
- std::auto_ptr<IncomingDataHandler> incoming_data_handler_;
+ 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_;
@@ -520,5 +556,4 @@ class ProtocolHandlerImpl
#endif // TIME_TESTER
};
} // namespace protocol_handler
-
#endif // SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_PROTOCOL_HANDLER_IMPL_H_