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.h86
1 files changed, 51 insertions, 35 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 3732e23a4c..94fd0c7c27 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,15 +36,18 @@
#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"
@@ -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;
@@ -131,10 +129,14 @@ 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
* 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);
/**
* \brief Destructor
@@ -171,6 +173,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 +186,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 +214,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 +262,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 +275,14 @@ 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:
+ private:
+ void SendEndServicePrivate(int32_t connection_id, uint8_t session_id, uint8_t service_type);
+
/*
* Prepare and send heartbeat acknowledge message
*/
@@ -336,11 +349,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 +370,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,7 +394,7 @@ class ProtocolHandlerImpl
* \return \saRESULT_CODE Status of operation
*/
RESULT_CODE HandleMessage(
- ConnectionID connection_id ,
+ ConnectionID connection_id,
const ProtocolFramePtr packet);
/**
@@ -392,7 +405,7 @@ class ProtocolHandlerImpl
* \return \saRESULT_CODE Status of operation
*/
RESULT_CODE HandleSingleFrameMessage(
- ConnectionID connection_id ,
+ ConnectionID connection_id,
const ProtocolFramePtr packet);
/**
* \brief Handles message received in multiple frames. Collects all frames
@@ -403,7 +416,7 @@ class ProtocolHandlerImpl
* \return \saRESULT_CODE Status of operation
*/
RESULT_CODE HandleMultiFrameMessage(
- ConnectionID connection_id ,
+ ConnectionID connection_id,
const ProtocolFramePtr packet);
/**
@@ -414,28 +427,21 @@ class ProtocolHandlerImpl
* \return \saRESULT_CODE Status of operation
*/
RESULT_CODE HandleControlMessage(
- ConnectionID connection_id ,
+ ConnectionID connection_id,
const ProtocolFramePtr packet);
RESULT_CODE HandleControlMessageEndSession(
- ConnectionID connection_id ,
+ ConnectionID connection_id,
const ProtocolPacket &packet);
RESULT_CODE HandleControlMessageStartSession(
- ConnectionID connection_id ,
+ ConnectionID connection_id,
const ProtocolPacket &packet);
RESULT_CODE HandleControlMessageHeartBeat(
- ConnectionID connection_id ,
+ ConnectionID connection_id,
const ProtocolPacket &packet);
- /**
- * \brief Sends Mobile Navi Ack message
- */
- RESULT_CODE SendMobileNaviAck(
- ConnectionID connection_id ,
- int32_t connection_key);
-
// threads::MessageLoopThread<*>::Handler implementations
// CALLED ON raw_ford_messages_from_mobile_ thread!
void Handle(const impl::RawFordMessageFromMobile message);
@@ -450,6 +456,9 @@ class ProtocolHandlerImpl
RESULT_CODE EncryptFrame(ProtocolFramePtr packet);
RESULT_CODE DecryptFrame(ProtocolFramePtr packet);
#endif // ENABLE_SECURITY
+
+ bool TrackMessage(const uint32_t& connection_key);
+
private:
/**
*\brief Pointer on instance of class implementing IProtocolObserver
@@ -474,7 +483,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 +496,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 +515,11 @@ 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_;
#ifdef ENABLE_SECURITY
security_manager::SecurityManager *security_manager_;
@@ -520,5 +537,4 @@ class ProtocolHandlerImpl
#endif // TIME_TESTER
};
} // namespace protocol_handler
-
#endif // SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_PROTOCOL_HANDLER_IMPL_H_