diff --git a/include/fastdds/dds/core/policy/ParameterList.hpp b/include/fastdds/dds/core/policy/ParameterList.hpp index 6a2a269bfef..46ad3ccc5d8 100644 --- a/include/fastdds/dds/core/policy/ParameterList.hpp +++ b/include/fastdds/dds/core/policy/ParameterList.hpp @@ -49,18 +49,6 @@ class ParameterList static bool writeEncapsulationToCDRMsg( fastrtps::rtps::CDRMessage_t* msg); - /** - * Update the CDRMessage of a parameterList. - * @param msg Pointer to the message (the pos should be correct, otherwise the behaviour is undefined). - * @param plist Pointer to the parameterList. - * @param use_encapsulation Flag to apply encapsulation. - * @return True if correct. - */ - static bool writeParameterListToCDRMsg( - fastrtps::rtps::CDRMessage_t* msg, - ParameterList* plist, - bool use_encapsulation); - /** * Update the information of a cache change parsing the inline qos from a CDRMessage * @param[inout] change Reference to the cache change to be updated. @@ -77,31 +65,43 @@ class ParameterList * Read a parameterList from a CDRMessage * @param[in] msg Reference to the message (the pos should be correct, otherwise the behaviour is undefined). * @param[in] processor Function to process each of the parameters in the list. - * @param[in] use_encapsulation Wether encapsulation field should be read. + * @param[in] use_encapsulation Whether encapsulation field should be read. * @param[out] qos_size Number of bytes processed. * @return true if parsing was correct, false otherwise. */ static bool readParameterListfromCDRMsg( fastrtps::rtps::CDRMessage_t& msg, - std::function processor, + std::function processor, bool use_encapsulation, uint32_t& qos_size); + /** + * Read guid from the KEY_HASH or another specific PID parameter of a CDRMessage + * @param[in,out] msg Reference to the message (pos should be correct, otherwise the behaviour is undefined). + * @param[in] search_pid Specific PID to search + * @param[out] guid Reference where the guid will be written. + * @return true if a guid is returned, false otherwise. + */ + static bool read_guid_from_cdr_msg( + fastrtps::rtps::CDRMessage_t& msg, + uint16_t search_pid, + fastrtps::rtps::GUID_t& guid); /** * Read change instanceHandle from the KEY_HASH or another specific PID parameter of a CDRMessage * @param[in,out] change Pointer to the cache change. - * @param[in] pid Specific PID to search + * @param[in] search_pid Specific PID to search * @return True when instanceHandle is updated. */ static bool readInstanceHandleFromCDRMsg( fastrtps::rtps::CacheChange_t* change, - const uint16_t pid); + const uint16_t search_pid); }; } // namespace dds } // namespace fastdds } // namespace eprosima + #endif #endif // _FASTDDS_DDS_QOS_PARAMETERLIST_HPP_ diff --git a/include/fastdds/dds/core/policy/ParameterTypes.hpp b/include/fastdds/dds/core/policy/ParameterTypes.hpp index 659a4acb73b..7c842437b9d 100644 --- a/include/fastdds/dds/core/policy/ParameterTypes.hpp +++ b/include/fastdds/dds/core/policy/ParameterTypes.hpp @@ -18,7 +18,9 @@ #ifndef _FASTDDS_DDS_QOS_PARAMETERTYPES_HPP_ #define _FASTDDS_DDS_QOS_PARAMETERTYPES_HPP_ + #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + #include #include @@ -48,7 +50,7 @@ namespace dds { * @{ */ -enum ParameterId_t : uint16_t +enum ParameterId_t : uint16_t { PID_PAD = 0x0000, PID_SENTINEL = 0x0001, @@ -165,6 +167,16 @@ class Parameter_t RTPS_DllAPI virtual bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) = 0; + /** + * Virtual method used to get the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + RTPS_DllAPI virtual bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) = 0; + public: //!Parameter ID @@ -214,6 +226,17 @@ class ParameterKey_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_KEY_HASH_LENGTH 16 @@ -259,6 +282,17 @@ class ParameterLocator_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_LOCATOR_LENGTH 24 @@ -302,7 +336,7 @@ class ParameterString_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; - inline const char* getName()const + inline const char* getName() const { return string_.c_str(); } @@ -313,6 +347,16 @@ class ParameterString_t : public Parameter_t string_ = name; } + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + private: fastrtps::string_255 string_; @@ -360,6 +404,17 @@ class ParameterPort_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_PORT_LENGTH 4 @@ -423,6 +478,17 @@ class ParameterGuid_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_GUID_LENGTH 16 @@ -460,6 +526,17 @@ class ParameterProtocolVersion_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_PROTOCOL_LENGTH 4 @@ -497,6 +574,17 @@ class ParameterVendorId_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_VENDOR_LENGTH 4 @@ -534,6 +622,17 @@ class ParameterIP4Address_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + void setIP4Address( fastrtps::rtps::octet o1, fastrtps::rtps::octet o2, @@ -585,6 +684,17 @@ class ParameterBool_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_BOOL_LENGTH 4 @@ -631,6 +741,17 @@ class ParameterStatusInfo_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_STATUS_INFO_LENGTH 4 @@ -668,6 +789,17 @@ class ParameterCount_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_COUNT_LENGTH 4 @@ -705,6 +837,17 @@ class ParameterEntityId_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_ENTITYID_LENGTH 4 @@ -740,6 +883,17 @@ class ParameterTime_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_TIME_LENGTH 8 @@ -777,22 +931,305 @@ class ParameterBuiltinEndpointSet_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_BUILTINENDPOINTSET_LENGTH 4 +class ParameterProperty_t +{ + + friend class ParameterPropertyList_t; + +private: + + fastrtps::rtps::octet* data; + +public: + + ParameterProperty_t() + { + data = nullptr; + } + + explicit ParameterProperty_t( + void* ptr) + { + data = (fastrtps::rtps::octet*)ptr; + } + + std::string first() const + { + //Skip the size and return the string + return std::string((char*)data + 4); + } + + std::string second() const + { + //Skip the first element + uint32_t size1 = ParameterProperty_t::element_size(data); + + //Skip the size of the second element and return the string + return std::string((char*)data + size1 + 4); + } + + bool modify( + const std::pair& new_value) + { + uint32_t old_size = size(); + + uint32_t first_size = (uint32_t)new_value.first.size() + 1; + uint32_t first_alignment = ((first_size + 3) & ~3) - first_size; + uint32_t second_size = (uint32_t)new_value.second.size() + 1; + uint32_t second_alignment = ((second_size + 3) & ~3) - second_size; + uint32_t new_size = first_size + first_alignment + second_size + second_alignment + 8; + + if (old_size != new_size) + { + return false; + } + + fastrtps::rtps::octet* current = data; + memcpy(current, &first_size, 4); + memcpy(current + 4, new_value.first.c_str(), first_size); + memset(current + 4 + first_size, 0, first_alignment); + + current = data + 4 + first_size + first_alignment; + memcpy(current, &second_size, 4); + memcpy(current + 4, new_value.second.c_str(), second_size); + memset(current + 4 + second_size, 0, second_alignment); + + return true; + } + + std::pair pair() const + { + return std::make_pair(std::string(first()), std::string(second())); + } + + uint32_t size() const + { + //Size of the first element (with alignment) + uint32_t size1 = ParameterProperty_t::element_size(data); + + //Size of the second element (with alignment) + uint32_t size2 = ParameterProperty_t::element_size(data + size1); + return size1 + size2; + } + + bool operator ==( + const ParameterProperty_t& b) const + { + return (first() == b.first()) && + (second() == b.second()); + } + + bool operator !=( + const ParameterProperty_t& b) const + { + return !(*this == b); + } + +private: + + static uint32_t element_size( + const fastrtps::rtps::octet* ptr) + { + //Size of the element (with alignment) + uint32_t size = *(uint32_t*)ptr; + return (4 + ((size + 3) & ~3)); + } + +}; + /** * */ class ParameterPropertyList_t : public Parameter_t { +private: + + fastrtps::rtps::SerializedPayload_t properties_; + uint32_t Nproperties_ = 0; + bool limit_size_ = false; + +public: + + class iterator + { +public: + + typedef iterator self_type; + typedef ParameterProperty_t value_type; + typedef ParameterProperty_t reference; + typedef ParameterProperty_t* pointer; + typedef size_t difference_type; + typedef std::forward_iterator_tag iterator_category; + + iterator( + fastrtps::rtps::octet* ptr) + : ptr_(ptr) + , value_(ptr) + { + } + + self_type operator ++() + { + self_type i = *this; + advance(); + return i; + } + + self_type operator ++( + int) + { + advance(); + return *this; + } + + reference operator *() + { + return value_; + } + + pointer operator ->() + { + return &value_; + } + + bool operator ==( + const self_type& rhs) + { + return ptr_ == rhs.ptr_; + } + + bool operator !=( + const self_type& rhs) + { + return ptr_ != rhs.ptr_; + } + +protected: + + void advance() + { + ptr_ += value_.size(); + value_ = ParameterProperty_t(ptr_); + } + + fastrtps::rtps::octet* address() const + { + return ptr_; + } + +private: + + fastrtps::rtps::octet* ptr_; + ParameterProperty_t value_; + }; + + class const_iterator + { public: - std::vector > properties; + typedef const_iterator self_type; + typedef const ParameterProperty_t value_type; + typedef const ParameterProperty_t reference; + typedef const ParameterProperty_t* pointer; + typedef size_t difference_type; + typedef std::forward_iterator_tag iterator_category; + + const_iterator( + const fastrtps::rtps::octet* ptr) + : ptr_(ptr) + , value_(const_cast(ptr)) + { + } + + self_type operator ++() + { + self_type i = *this; + advance(); + return i; + } + + self_type operator ++( + int) + { + advance(); + return *this; + } + + reference operator *() + { + return value_; + } + + pointer operator ->() + { + return &value_; + } + + bool operator ==( + const self_type& rhs) + { + return ptr_ == rhs.ptr_; + } + + bool operator !=( + const self_type& rhs) + { + return ptr_ != rhs.ptr_; + } + +protected: + + void advance() + { + ptr_ += value_.size(); + value_ = ParameterProperty_t(const_cast(ptr_)); + } + + const fastrtps::rtps::octet* address() const + { + return ptr_; + } + +private: + + const fastrtps::rtps::octet* ptr_; + ParameterProperty_t value_; + }; + +public: ParameterPropertyList_t() : Parameter_t(PID_PROPERTY_LIST, 0) + , Nproperties_ (0) + , limit_size_ (false) + { + } + + /** + * Constructor with a defined maximum size + */ + ParameterPropertyList_t( + uint32_t size) + : Parameter_t(PID_PROPERTY_LIST, 0) + , properties_(size) + , Nproperties_ (0) + , limit_size_ (size == 0 ? false : true) { } @@ -804,14 +1241,111 @@ class ParameterPropertyList_t : public Parameter_t ParameterId_t /*pid*/, uint16_t in_length) : Parameter_t(PID_PROPERTY_LIST, in_length) + , Nproperties_ (0) + , limit_size_ (false) { } ParameterPropertyList_t( const ParameterPropertyList_t& parameter_properties) - : Parameter_t(PID_PROPERTY_LIST, 0) + : Parameter_t(PID_PROPERTY_LIST, parameter_properties.length) + , properties_(parameter_properties.limit_size_ ? + parameter_properties.properties_.max_size : + parameter_properties.properties_.length) + , Nproperties_ (parameter_properties.Nproperties_) + , limit_size_ (parameter_properties.limit_size_) + { + properties_.copy(¶meter_properties.properties_, parameter_properties.limit_size_); + } + + ParameterPropertyList_t& operator = ( + const ParameterPropertyList_t& parameter_properties) { - properties.assign(parameter_properties.properties.begin(), parameter_properties.properties.end()); + length = parameter_properties.length; + limit_size_ = parameter_properties.limit_size_; + properties_.reserve(limit_size_ ? + parameter_properties.properties_.max_size : + parameter_properties.properties_.length); + properties_.copy(¶meter_properties.properties_, parameter_properties.limit_size_); + Nproperties_ = parameter_properties.Nproperties_; + return *this; + } + + iterator begin() + { + return iterator(properties_.data); + } + + iterator end() + { + return iterator(properties_.data + properties_.length); + } + + const_iterator begin() const + { + return const_iterator(properties_.data); + } + + const_iterator end() const + { + return const_iterator(properties_.data + properties_.length); + } + + bool push_back( + std::pair p) + { + + //Realloc if needed; + uint32_t size1 = (uint32_t) p.first.length() + 1; + uint32_t alignment1 = ((size1 + 3) & ~3) - size1; + + uint32_t size2 = (uint32_t) p.second.length() + 1; + uint32_t alignment2 = ((size2 + 3) & ~3) - size2; + + if (limit_size_ && (properties_.max_size < properties_.length + + size1 + alignment1 + 4 + + size2 + alignment2 + 4)) + { + return false; + } + properties_.reserve(properties_.length + + size1 + alignment1 + 4 + + size2 + alignment2 + 4); + + push_back_helper((fastrtps::rtps::octet*)p.first.c_str(), size1, alignment1); + push_back_helper((fastrtps::rtps::octet*)p.second.c_str(), size2, alignment2); + ++Nproperties_; + return true; + } + + bool set_property ( + iterator pos, + const std::pair& new_value) + { + return pos->modify(new_value); + } + + void clear() + { + properties_.length = 0; + Nproperties_ = 0; + } + + uint32_t size() const + { + return Nproperties_; + } + + void set_max_size ( + uint32_t size) + { + properties_.reserve(size); + limit_size_ = true; + } + + uint32_t max_size () + { + return (limit_size_ ? properties_.max_size : 0); } /** @@ -821,8 +1355,41 @@ class ParameterPropertyList_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + +protected: + + void push_back_helper ( + const fastrtps::rtps::octet* data, + uint32_t size, + uint32_t alignment) + { + fastrtps::rtps::octet* o = (fastrtps::rtps::octet*)&size; + memcpy(properties_.data + properties_.length, o, 4); + properties_.length += 4; + + memcpy(properties_.data + properties_.length, data, size); + properties_.length += size; + + for (uint32_t i = 0; i < alignment; ++i) + { + properties_.data[properties_.length + i] = '\0'; + } + properties_.length += alignment; + } + }; + /** * */ @@ -857,8 +1424,22 @@ class ParameterSampleIdentity_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; +#define PARAMETER_SAMPLEIDENTITY_LENGTH 24 + + #if HAVE_SECURITY /** @@ -893,6 +1474,17 @@ class ParameterToken_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; class ParameterParticipantSecurityInfo_t : public Parameter_t @@ -926,6 +1518,17 @@ class ParameterParticipantSecurityInfo_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_PARTICIPANT_SECURITY_INFO_LENGTH 8 @@ -961,6 +1564,17 @@ class ParameterEndpointSecurityInfo_t : public Parameter_t */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Read the parameter from a CDRMessage_t message. + * @param[in,out] msg Pointer to the message from where the parameter should be taken. + * @param size Size of the parameter field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; #define PARAMETER_ENDPOINT_SECURITY_INFO_LENGTH 8 diff --git a/include/fastdds/dds/core/policy/QosPolicies.hpp b/include/fastdds/dds/core/policy/QosPolicies.hpp index 817400b394c..acf306e79be 100644 --- a/include/fastdds/dds/core/policy/QosPolicies.hpp +++ b/include/fastdds/dds/core/policy/QosPolicies.hpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace eprosima { @@ -79,6 +80,8 @@ class QosPolicy return send_always_; } + virtual inline void clear() = 0; + protected: bool send_always_; @@ -159,6 +162,12 @@ class DurabilityQosPolicy : public Parameter_t, public QosPolicy } + inline void clear() override + { + DurabilityQosPolicy reset = DurabilityQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -167,6 +176,16 @@ class DurabilityQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: DurabilityQosPolicyKind_t kind; @@ -202,6 +221,12 @@ class DeadlineQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + DeadlineQosPolicy reset = DeadlineQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -210,6 +235,16 @@ class DeadlineQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: fastrtps::Duration_t period; @@ -245,6 +280,12 @@ class LatencyBudgetQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + LatencyBudgetQosPolicy reset = LatencyBudgetQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -253,6 +294,16 @@ class LatencyBudgetQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: fastrtps::Duration_t duration; @@ -307,6 +358,12 @@ class LivelinessQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + LivelinessQosPolicy reset = LivelinessQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -315,6 +372,16 @@ class LivelinessQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: LivelinessQosPolicyKind kind; @@ -361,6 +428,12 @@ class ReliabilityQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + ReliabilityQosPolicy reset = ReliabilityQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -369,6 +442,16 @@ class ReliabilityQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: /*! @@ -429,6 +512,12 @@ class OwnershipQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + OwnershipQosPolicy reset = OwnershipQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -437,6 +526,16 @@ class OwnershipQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: OwnershipQosPolicyKind kind; @@ -483,6 +582,12 @@ class DestinationOrderQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + DestinationOrderQosPolicy reset = DestinationOrderQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -491,6 +596,16 @@ class DestinationOrderQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: DestinationOrderQosPolicyKind kind; @@ -500,31 +615,156 @@ class DestinationOrderQosPolicy : public Parameter_t, public QosPolicy /** * Class UserDataQosPolicy, to transmit user data during the discovery phase. */ -class UserDataQosPolicy : public Parameter_t, public QosPolicy +class UserDataQosPolicy : public Parameter_t, public QosPolicy, + public fastrtps::ResourceLimitedVector { friend class ParameterList; + using ResourceLimitedOctetVector = fastrtps::ResourceLimitedVector; public: RTPS_DllAPI UserDataQosPolicy() : Parameter_t(PID_USER_DATA, 0) , QosPolicy(false) - , data_vec_{} + , ResourceLimitedOctetVector() + { + } + + RTPS_DllAPI UserDataQosPolicy( + uint16_t in_length) + : Parameter_t(PID_USER_DATA, in_length) + , QosPolicy(false) + , ResourceLimitedOctetVector() + { + } + + /** + * Construct from another UserDataQosPolicy. + * + * The resulting UserDataQosPolicy will have the same size limits + * as the input attribute + * + * @param data data to copy in the newly created object + */ + RTPS_DllAPI UserDataQosPolicy( + const UserDataQosPolicy& data) + : Parameter_t(PID_USER_DATA, data.length) + , QosPolicy(false) + , ResourceLimitedOctetVector(data) { } + /** + * Construct from underlying collection type. + * + * Useful to easy integration on old APIs where a traditional container was used. + * The resulting UserDataQosPolicy will always be unlimited in size + * + * @param data data to copy in the newly created object + */ + RTPS_DllAPI UserDataQosPolicy( + const collection_type& data) + : Parameter_t(PID_USER_DATA, 0) + , QosPolicy(false) + , ResourceLimitedOctetVector() + { + assign(data.begin(), data.end()); + } + virtual RTPS_DllAPI ~UserDataQosPolicy() { } + /** + * Copies data from underlying collection type. + * + * Useful to easy integration on old APIs where a traditional container was used. + * The resulting UserDataQosPolicy will keep the current size limit. + * If the input data is larger than the current limit size, the elements exceeding + * that maximum will be silently discarded. + * + * @param b object to be copied + * @return reference to the current object. + */ + UserDataQosPolicy& operator =( + const collection_type& b) + { + if (collection_ != b) + { + //If the object is size limited, already has max_size() allocated + //assign() will always stop copying when reaching max_size() + assign(b.begin(), b.end()); + hasChanged = true; + } + return *this; + } + + /** + * Copies another UserDataQosPolicy. + * + * The resulting UserDataQosPolicy will have the same size limit + * as the input parameter, so all data in the input will be copied. + * + * @param b object to be copied + * @return reference to the current object. + */ + UserDataQosPolicy& operator =( + const UserDataQosPolicy& b) + { + QosPolicy::operator =(b); + Parameter_t::operator =(b); + configuration_ = b.configuration_; + collection_.reserve(b.collection_.capacity()); + collection_.assign(b.collection_.begin(), b.collection_.end()); + return *this; + } + bool operator ==( const UserDataQosPolicy& b) const { - return (this->data_vec_ == b.data_vec_) && + return collection_ == b.collection_ && Parameter_t::operator ==(b) && QosPolicy::operator ==(b); } + bool operator ==( + const collection_type& b) const + { + return collection_ == b; + } + + /** + * Set the maximum size of the user data and reserves memory for that much. + * @param size new maximum size of the user data + */ + void set_max_size ( + size_t size) + { + if (size > 0) + { + configuration_ = fastrtps::ResourceLimitedContainerConfig::fixed_size_configuration(size); + collection_.reserve(configuration_.maximum); + } + else + { + configuration_ = fastrtps::ResourceLimitedContainerConfig::dynamic_allocation_configuration(); + } + } + + /** + * @return const reference to the internal raw data. + * */ + inline const std::vector& dataVec() const + { + return collection_; + } + + inline void clear() override + { + ResourceLimitedOctetVector::clear(); + hasChanged = false; + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -533,13 +773,23 @@ class UserDataQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + /** * Returns raw data vector. * @return raw data as vector of octets. * */ RTPS_DllAPI inline std::vector data_vec() const { - return data_vec_; + return collection_; } /** @@ -549,12 +799,9 @@ class UserDataQosPolicy : public Parameter_t, public QosPolicy RTPS_DllAPI inline void data_vec( const std::vector& vec) { - data_vec_ = vec; + assign(vec.begin(), vec.end()); } -private: - - std::vector data_vec_; }; /** @@ -587,6 +834,12 @@ class TimeBasedFilterQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + TimeBasedFilterQosPolicy reset = TimeBasedFilterQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -595,6 +848,16 @@ class TimeBasedFilterQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: fastrtps::Duration_t minimum_separation; @@ -648,6 +911,12 @@ class PresentationQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + PresentationQosPolicy reset = PresentationQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -656,6 +925,16 @@ class PresentationQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: PresentationQosPolicyAccessScopeKind access_scope; @@ -664,6 +943,55 @@ class PresentationQosPolicy : public Parameter_t, public QosPolicy }; +class Partition_t +{ + + friend class PartitionQosPolicy; + +private: + + const char* partition_; + +private: + + Partition_t() + { + partition_ = nullptr; + } + +public: + + explicit Partition_t( + const void* ptr) + { + partition_ = (char*)ptr; + } + + bool operator ==( + const Partition_t& rhs) const + { + return (size() == rhs.size() && + (size() == 0 || strcmp(partition_ + 4, rhs.partition_ + 4))); + } + + bool operator !=( + const Partition_t& rhs) const + { + return !(*this == rhs); + } + + uint32_t size() const + { + return *(uint32_t*)partition_; + } + + const char* name() const + { + return partition_ + 4; + } + +}; + /** * Class PartitionQosPolicy, to indicate the Partition Qos. */ @@ -672,15 +1000,112 @@ class PartitionQosPolicy : public Parameter_t, public QosPolicy friend class ParameterList; friend class fastrtps::rtps::EDP; +public: + + class const_iterator + { +public: + + typedef const_iterator self_type; + typedef const Partition_t value_type; + typedef const Partition_t reference; + typedef const Partition_t* pointer; + typedef size_t difference_type; + typedef std::forward_iterator_tag iterator_category; + + const_iterator( + const fastrtps::rtps::octet* ptr) + : ptr_(ptr) + , value_ (ptr_) + { + } + + self_type operator ++() + { + self_type tmp = *this; + advance(); + return tmp; + } + + self_type operator ++( + int) + { + advance(); + return *this; + } + + reference operator *() + { + return value_; + } + + pointer operator ->() + { + return &value_; + } + + bool operator ==( + const self_type& rhs) + { + return ptr_ == rhs.ptr_; + } + + bool operator !=( + const self_type& rhs) + { + return ptr_ != rhs.ptr_; + } + +protected: + + void advance() + { + //Size of the element (with alignment) + uint32_t size = *(uint32_t*)ptr_; + ptr_ += (4 + ((size + 3) & ~3)); + value_ = Partition_t(ptr_); + } + +private: + + const fastrtps::rtps::octet* ptr_; + Partition_t value_; + + }; + public: RTPS_DllAPI PartitionQosPolicy() : Parameter_t(PID_PARTITION, 0) , QosPolicy(false) - , names_{} + , max_size_ (0) + , Npartitions_ (0) { } + RTPS_DllAPI PartitionQosPolicy( + uint16_t in_length) + : Parameter_t(PID_PARTITION, in_length) + , QosPolicy(false) + , max_size_ (in_length) + , partitions_(in_length) + , Npartitions_ (0) + { + } + + RTPS_DllAPI PartitionQosPolicy( + const PartitionQosPolicy& b) + : Parameter_t(b) + , QosPolicy(b) + , max_size_ (b.max_size_) + , partitions_(b.max_size_ != 0 ? + b.partitions_.max_size : + b.partitions_.length) + , Npartitions_ (b.Npartitions_) + { + partitions_.copy(&b.partitions_, b.max_size_ != 0); + } + virtual RTPS_DllAPI ~PartitionQosPolicy() { } @@ -688,11 +1113,60 @@ class PartitionQosPolicy : public Parameter_t, public QosPolicy bool operator ==( const PartitionQosPolicy& b) const { - return (this->names_ == b.names_) && + return (this->max_size_ == b.max_size_) && + (this->Npartitions_ == b.Npartitions_) && + (this->partitions_ == b.partitions_) && Parameter_t::operator ==(b) && QosPolicy::operator ==(b); } + PartitionQosPolicy& operator =( + const PartitionQosPolicy& b) + { + QosPolicy::operator=(b); + Parameter_t::operator=(b); + max_size_ = b.max_size_; + partitions_.reserve(max_size_ != 0 ? + b.partitions_.max_size : + b.partitions_.length); + partitions_.copy(&b.partitions_, b.max_size_ != 0); + Npartitions_ = b.Npartitions_; + + return *this; + } + + const_iterator begin() const + { + return const_iterator(partitions_.data); + } + + const_iterator end() const + { + return const_iterator(partitions_.data + partitions_.length); + } + + uint32_t size() const + { + return Npartitions_; + } + + uint32_t empty() const + { + return Npartitions_ == 0; + } + + void set_max_size ( + uint32_t size) + { + partitions_.reserve(size); + max_size_ = size; + } + + uint32_t max_size () const + { + return max_size_; + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -701,6 +1175,16 @@ class PartitionQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + /** * Appends a name to the list of partition names. * @param name Name to append. @@ -708,24 +1192,57 @@ class PartitionQosPolicy : public Parameter_t, public QosPolicy RTPS_DllAPI inline void push_back( const char* name) { - names_.push_back(std::string(name)); hasChanged = true; + //Realloc if needed; + uint32_t size = (uint32_t)strlen(name) + 1; + uint32_t alignment = ((size + 3) & ~3) - size; + + if (max_size_ != 0 && (partitions_.max_size < partitions_.length + + size + alignment + 4)) + { + return; + } + + partitions_.reserve(partitions_.length + size + alignment + 4); + + fastrtps::rtps::octet* o = (fastrtps::rtps::octet*)&size; + memcpy(partitions_.data + partitions_.length, o, 4); + partitions_.length += 4; + + memcpy(partitions_.data + partitions_.length, name, size); + partitions_.length += size; + + memset(partitions_.data + partitions_.length, 0, alignment); + partitions_.length += alignment; + + ++Npartitions_; + hasChanged = true; } /** * Clears list of partition names */ - RTPS_DllAPI inline void clear() + RTPS_DllAPI inline void clear() override { - names_.clear(); + partitions_.length = 0; + Npartitions_ = 0; + hasChanged = false; } /** * Returns partition names. * @return Vector of partition name strings. */ - RTPS_DllAPI inline std::vector names() const + RTPS_DllAPI inline const std::vector names() const { - return names_; + std::vector names; + if (Npartitions_ > 0) + { + for (auto it = begin(); it != end(); ++it) + { + names.push_back(it->name()); + } + } + return names; } /** @@ -735,13 +1252,19 @@ class PartitionQosPolicy : public Parameter_t, public QosPolicy RTPS_DllAPI inline void names( std::vector& nam) { - names_ = nam; + clear(); + for (auto it = nam.begin(); it != nam.end(); ++it) + { + push_back(it->c_str()); + } hasChanged = true; } private: - std::vector names_; + uint32_t max_size_; + fastrtps::rtps::SerializedPayload_t partitions_; + uint32_t Npartitions_; }; @@ -780,6 +1303,16 @@ class TopicDataQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + /** * Appends topic data. * @param oc Data octet. @@ -793,7 +1326,7 @@ class TopicDataQosPolicy : public Parameter_t, public QosPolicy /** * Clears all topic data. */ - RTPS_DllAPI inline void clear() + RTPS_DllAPI inline void clear() override { value.clear(); } @@ -858,6 +1391,16 @@ class GroupDataQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + /** * Appends group data. * @param oc Data octet. @@ -871,7 +1414,7 @@ class GroupDataQosPolicy : public Parameter_t, public QosPolicy /** * Clears all group data. */ - RTPS_DllAPI inline void clear() + RTPS_DllAPI inline void clear() override { value.clear(); } @@ -941,6 +1484,12 @@ class HistoryQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + HistoryQosPolicy reset = HistoryQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -949,6 +1498,16 @@ class HistoryQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: HistoryQosPolicyKind kind; @@ -998,6 +1557,12 @@ class ResourceLimitsQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + ResourceLimitsQosPolicy reset = ResourceLimitsQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1005,6 +1570,17 @@ class ResourceLimitsQosPolicy : public Parameter_t, public QosPolicy */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; @@ -1052,6 +1628,12 @@ class DurabilityServiceQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + DurabilityServiceQosPolicy reset = DurabilityServiceQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1060,6 +1642,16 @@ class DurabilityServiceQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: fastrtps::Duration_t service_cleanup_delay; @@ -1100,6 +1692,12 @@ class LifespanQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + LifespanQosPolicy reset = LifespanQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1108,6 +1706,16 @@ class LifespanQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: fastrtps::Duration_t duration; @@ -1142,6 +1750,12 @@ class OwnershipStrengthQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + OwnershipStrengthQosPolicy reset = OwnershipStrengthQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1150,6 +1764,16 @@ class OwnershipStrengthQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: uint32_t value; @@ -1188,6 +1812,12 @@ class TransportPriorityQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + TransportPriorityQosPolicy reset = TransportPriorityQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1195,6 +1825,17 @@ class TransportPriorityQosPolicy : public Parameter_t, public QosPolicy */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; /** @@ -1224,6 +1865,12 @@ class PublishModeQosPolicy : public QosPolicy { } + inline void clear() override + { + PublishModeQosPolicy reset = PublishModeQosPolicy(); + std::swap(*this, reset); + } + }; /** @@ -1269,6 +1916,12 @@ class DataRepresentationQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + DataRepresentationQosPolicy reset = DataRepresentationQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1276,6 +1929,17 @@ class DataRepresentationQosPolicy : public Parameter_t, public QosPolicy */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; enum TypeConsistencyKind : uint16_t @@ -1329,13 +1993,25 @@ class TypeConsistencyEnforcementQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } - /** - * Appends QoS to the specified CDR message. - * @param msg Message to append the QoS Policy to. - * @return True if the modified CDRMessage is valid. - */ + inline void clear() override + { + TypeConsistencyEnforcementQosPolicy reset = TypeConsistencyEnforcementQosPolicy(); + std::swap(*this, reset); + } + bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + }; /** @@ -1368,6 +2044,12 @@ class DisablePositiveACKsQosPolicy : public Parameter_t, public QosPolicy QosPolicy::operator ==(b); } + inline void clear() override + { + DisablePositiveACKsQosPolicy reset = DisablePositiveACKsQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1376,6 +2058,16 @@ class DisablePositiveACKsQosPolicy : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* msg, + uint16_t size) override; + public: //! True if this QoS is enabled @@ -1447,6 +2139,11 @@ class TypeIdV1 : public Parameter_t, public QosPolicy { } + inline void clear() override + { + *this = TypeIdV1(); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1454,9 +2151,16 @@ class TypeIdV1 : public Parameter_t, public QosPolicy */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ bool readFromCDRMessage( fastrtps::rtps::CDRMessage_t* msg, - uint32_t size); + uint16_t size) override; RTPS_DllAPI TypeIdV1& operator =( const fastrtps::types::TypeIdentifier& type_id) @@ -1534,6 +2238,11 @@ class TypeObjectV1 : public Parameter_t, public QosPolicy { } + inline void clear() override + { + *this = TypeObjectV1(); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1541,9 +2250,16 @@ class TypeObjectV1 : public Parameter_t, public QosPolicy */ bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ bool readFromCDRMessage( fastrtps::rtps::CDRMessage_t* msg, - uint32_t size); + uint16_t size) override; RTPS_DllAPI TypeObjectV1& operator =( const fastrtps::types::TypeObject& type_object) @@ -1626,6 +2342,11 @@ class TypeInformation : public Parameter_t, public QosPolicy { } + inline void clear() override + { + *this = TypeInformation(); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1634,9 +2355,15 @@ class TypeInformation : public Parameter_t, public QosPolicy bool addToCDRMessage( fastrtps::rtps::CDRMessage_t* msg) override; + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ bool readFromCDRMessage( fastrtps::rtps::CDRMessage_t* msg, - uint32_t size); + uint16_t size) override; RTPS_DllAPI bool assigned() const { diff --git a/include/fastdds/dds/topic/qos/ReaderQos.hpp b/include/fastdds/dds/topic/qos/ReaderQos.hpp index 72ee8d2078c..d9aba58c607 100644 --- a/include/fastdds/dds/topic/qos/ReaderQos.hpp +++ b/include/fastdds/dds/topic/qos/ReaderQos.hpp @@ -37,10 +37,15 @@ class ReaderQos { public: - RTPS_DllAPI ReaderQos() {} - RTPS_DllAPI virtual ~ReaderQos() {} + RTPS_DllAPI ReaderQos() + { + } + + RTPS_DllAPI virtual ~ReaderQos() + { + } - bool operator==( + bool operator ==( const ReaderQos& b) const { return (this->m_durability == b.m_durability) && @@ -139,6 +144,8 @@ class ReaderQos */ RTPS_DllAPI bool canQosBeUpdated( const ReaderQos& qos) const; + + void clear(); }; RTPS_DllAPI extern const ReaderQos DATAREADER_QOS_DEFAULT; diff --git a/include/fastdds/dds/topic/qos/WriterQos.hpp b/include/fastdds/dds/topic/qos/WriterQos.hpp index 7e452d4f972..c7488bd1ea4 100644 --- a/include/fastdds/dds/topic/qos/WriterQos.hpp +++ b/include/fastdds/dds/topic/qos/WriterQos.hpp @@ -40,7 +40,7 @@ class WriterQos RTPS_DllAPI WriterQos(); RTPS_DllAPI virtual ~WriterQos(); - bool operator==( + bool operator ==( const WriterQos& b) const { return (this->m_durability == b.m_durability) && @@ -138,6 +138,8 @@ class WriterQos RTPS_DllAPI bool canQosBeUpdated( const WriterQos& qos) const; + + void clear(); }; RTPS_DllAPI extern const WriterQos DATAWRITER_QOS_DEFAULT; diff --git a/include/fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp b/include/fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp index 6144e3ae179..acf9c7b7b11 100644 --- a/include/fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp +++ b/include/fastdds/rtps/attributes/RTPSParticipantAllocationAttributes.hpp @@ -72,6 +72,19 @@ struct SendBuffersAllocationAttributes bool dynamic = false; }; +/** + * @brief Holds limits for variable-length data. + */ +struct VariableLengthDataLimits +{ + //! Defines the maximum size (in octets) of properties data in the local or remote participant + size_t max_properties = 0; + //! Defines the maximum size (in octets) of user data in the local or remote participant + size_t max_user_data = 0; + //! Defines the maximum size (in octets) of partitions data + size_t max_partitions = 0; +}; + /** * @brief Holds allocation limits affecting collections managed by a participant. */ @@ -87,6 +100,8 @@ struct RTPSParticipantAllocationAttributes ResourceLimitedContainerConfig writers; //! Defines the allocation behaviour for the send buffer manager. SendBuffersAllocationAttributes send_buffers; + //! Holds limits for variable-length data + VariableLengthDataLimits data_limits; //! @return the allocation config for the total of readers in the system (participants * readers) ResourceLimitedContainerConfig total_readers() const @@ -101,7 +116,9 @@ struct RTPSParticipantAllocationAttributes } private: - ResourceLimitedContainerConfig total_endpoints(const ResourceLimitedContainerConfig& endpoints) const + + ResourceLimitedContainerConfig total_endpoints( + const ResourceLimitedContainerConfig& endpoints) const { constexpr size_t max = std::numeric_limits::max(); size_t initial; @@ -110,15 +127,16 @@ struct RTPSParticipantAllocationAttributes initial = participants.initial * endpoints.initial; maximum = (participants.maximum == max || endpoints.maximum == max) - ? max : participants.maximum * endpoints.maximum; + ? max : participants.maximum * endpoints.maximum; increment = std::max(participants.increment, endpoints.increment); return { initial, maximum, increment }; } + }; const RTPSParticipantAllocationAttributes c_default_RTPSParticipantAllocationAttributes - = RTPSParticipantAllocationAttributes(); + = RTPSParticipantAllocationAttributes(); } /* namespace rtps */ } /* namespace fastrtps */ diff --git a/include/fastdds/rtps/builtin/data/ParticipantProxyData.h b/include/fastdds/rtps/builtin/data/ParticipantProxyData.h index edd3f5a7741..0221a8826b8 100644 --- a/include/fastdds/rtps/builtin/data/ParticipantProxyData.h +++ b/include/fastdds/rtps/builtin/data/ParticipantProxyData.h @@ -22,6 +22,7 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC #include +#include #include #include @@ -68,7 +69,7 @@ #define DISC_BUILTIN_ENDPOINT_PARTICIPANT_SECURE_DETECTOR (0x00000001 << 27) namespace eprosima { -namespace fastrtps{ +namespace fastrtps { namespace rtps { struct CDRMessage_t; @@ -84,128 +85,135 @@ template class ProxyHashTable; /** -* ParticipantProxyData class is used to store and convert the information Participants send to each other during the PDP phase. -*@ingroup BUILTIN_MODULE -*/ + * ParticipantProxyData class is used to store and convert the information Participants send to each other during the PDP phase. + *@ingroup BUILTIN_MODULE + */ class ParticipantProxyData { - public: - - ParticipantProxyData(const RTPSParticipantAllocationAttributes& allocation); - - ParticipantProxyData(const ParticipantProxyData& pdata); - - virtual ~ParticipantProxyData(); - - //!Protocol version - ProtocolVersion_t m_protocolVersion; - //!GUID - GUID_t m_guid; - //!Vendor ID - VendorId_t m_VendorId; - //!Expects Inline QOS. - bool m_expectsInlineQos; - //!Available builtin endpoints - BuiltinEndpointSet_t m_availableBuiltinEndpoints; - //!Metatraffic locators - RemoteLocatorList metatraffic_locators; - //!Default locators - RemoteLocatorList default_locators; - //!Manual liveliness count - Count_t m_manualLivelinessCount; - //!Participant name - string_255 m_participantName; - //! - InstanceHandle_t m_key; - //! - Duration_t m_leaseDuration; +public: + + ParticipantProxyData( + const RTPSParticipantAllocationAttributes& allocation); + + ParticipantProxyData( + const ParticipantProxyData& pdata); + + virtual ~ParticipantProxyData(); + + //!Protocol version + ProtocolVersion_t m_protocolVersion; + //!GUID + GUID_t m_guid; + //!Vendor ID + VendorId_t m_VendorId; + //!Expects Inline QOS. + bool m_expectsInlineQos; + //!Available builtin endpoints + BuiltinEndpointSet_t m_availableBuiltinEndpoints; + //!Metatraffic locators + RemoteLocatorList metatraffic_locators; + //!Default locators + RemoteLocatorList default_locators; + //!Manual liveliness count + Count_t m_manualLivelinessCount; + //!Participant name + string_255 m_participantName; + //! + InstanceHandle_t m_key; + //! + Duration_t m_leaseDuration; #if HAVE_SECURITY - //! - IdentityToken identity_token_; - //! - PermissionsToken permissions_token_; - //! - security::ParticipantSecurityAttributesMask security_attributes_; - //! - security::PluginParticipantSecurityAttributesMask plugin_security_attributes_; + //! + IdentityToken identity_token_; + //! + PermissionsToken permissions_token_; + //! + security::ParticipantSecurityAttributesMask security_attributes_; + //! + security::PluginParticipantSecurityAttributesMask plugin_security_attributes_; #endif - //! - bool isAlive; - //! - ParameterPropertyList_t m_properties; - //! - std::vector m_userData; - //! - TimedEvent* lease_duration_event; - //! - bool should_check_lease_duration; - //! - ProxyHashTable * m_readers = nullptr; - //! - ProxyHashTable * m_writers = nullptr; - - /** - * Update the data. - * @param pdata Object to copy the data from - * @return True on success - */ - bool updateData(ParticipantProxyData& pdata); - - /** - * Write as a parameter list on a CDRMessage_t - * @return True on success - */ - bool writeToCDRMessage(CDRMessage_t* msg, bool write_encapsulation); - - /** - * Read the parameter list from a recevied CDRMessage_t - * @return True on success - */ - bool readFromCDRMessage( - CDRMessage_t* msg, - bool use_encapsulation, - const NetworkFactory& network); - - //! Clear the data (restore to default state). - void clear(); - - /** - * Copy the data from another object. - * @param pdata Object to copy the data from - */ - void copy(const ParticipantProxyData& pdata); - - /** - * Set participant persistent GUID_t - * @param guid valid GUID_t - */ - void set_persistence_guid(const GUID_t & guid); - - /** - * Retrieve participant persistent GUID_t - * @return guid persistent GUID_t or c_Guid_Unknown - */ - GUID_t get_persistence_guid() const; - - void assert_liveliness(); - - const std::chrono::steady_clock::time_point& last_received_message_tm() const - { - return last_received_message_tm_; - } - - const std::chrono::microseconds& lease_duration() const - { - return lease_duration_; - } - - private: - - //! Store the last timestamp it was received a RTPS message from the remote participant. - std::chrono::steady_clock::time_point last_received_message_tm_; - - //! Remote participant lease duration in microseconds. - std::chrono::microseconds lease_duration_; + //! + bool isAlive; + //! + ParameterPropertyList_t m_properties; + //! + UserDataQosPolicy m_userData; + //! + TimedEvent* lease_duration_event; + //! + bool should_check_lease_duration; + //! + ProxyHashTable* m_readers = nullptr; + //! + ProxyHashTable* m_writers = nullptr; + + /** + * Update the data. + * @param pdata Object to copy the data from + * @return True on success + */ + bool updateData( + ParticipantProxyData& pdata); + + /** + * Write as a parameter list on a CDRMessage_t + * @return True on success + */ + bool writeToCDRMessage( + CDRMessage_t* msg, + bool write_encapsulation); + + /** + * Read the parameter list from a recevied CDRMessage_t + * @return True on success + */ + bool readFromCDRMessage( + CDRMessage_t* msg, + bool use_encapsulation, + const NetworkFactory& network); + + //! Clear the data (restore to default state). + void clear(); + + /** + * Copy the data from another object. + * @param pdata Object to copy the data from + */ + void copy( + const ParticipantProxyData& pdata); + + /** + * Set participant persistent GUID_t + * @param guid valid GUID_t + */ + void set_persistence_guid( + const GUID_t& guid); + + /** + * Retrieve participant persistent GUID_t + * @return guid persistent GUID_t or c_Guid_Unknown + */ + GUID_t get_persistence_guid() const; + + void assert_liveliness(); + + const std::chrono::steady_clock::time_point& last_received_message_tm() const + { + return last_received_message_tm_; + } + + const std::chrono::microseconds& lease_duration() const + { + return lease_duration_; + } + +private: + + //! Store the last timestamp it was received a RTPS message from the remote participant. + std::chrono::steady_clock::time_point last_received_message_tm_; + + //! Remote participant lease duration in microseconds. + std::chrono::microseconds lease_duration_; }; } /* namespace rtps */ diff --git a/include/fastdds/rtps/builtin/data/ReaderProxyData.h b/include/fastdds/rtps/builtin/data/ReaderProxyData.h index a70672ea92e..b80a8da73ed 100644 --- a/include/fastdds/rtps/builtin/data/ReaderProxyData.h +++ b/include/fastdds/rtps/builtin/data/ReaderProxyData.h @@ -26,6 +26,7 @@ #include #include +#include #if HAVE_SECURITY #include @@ -53,6 +54,11 @@ class ReaderProxyData const size_t max_unicast_locators, const size_t max_multicast_locators); + RTPS_DllAPI ReaderProxyData( + const size_t max_unicast_locators, + const size_t max_multicast_locators, + const VariableLengthDataLimits& data_limits); + RTPS_DllAPI virtual ~ReaderProxyData(); RTPS_DllAPI ReaderProxyData( diff --git a/include/fastdds/rtps/builtin/data/WriterProxyData.h b/include/fastdds/rtps/builtin/data/WriterProxyData.h index c5f40d894e4..218febc2ed0 100644 --- a/include/fastdds/rtps/builtin/data/WriterProxyData.h +++ b/include/fastdds/rtps/builtin/data/WriterProxyData.h @@ -26,6 +26,7 @@ #include #include +#include #if HAVE_SECURITY #include @@ -52,6 +53,11 @@ class WriterProxyData const size_t max_unicast_locators, const size_t max_multicast_locators); + RTPS_DllAPI WriterProxyData( + const size_t max_unicast_locators, + const size_t max_multicast_locators, + const VariableLengthDataLimits& data_limits); + virtual RTPS_DllAPI ~WriterProxyData(); RTPS_DllAPI WriterProxyData( diff --git a/include/fastdds/rtps/common/SerializedPayload.h b/include/fastdds/rtps/common/SerializedPayload.h index 96b681d4606..902ea221a9a 100644 --- a/include/fastdds/rtps/common/SerializedPayload.h +++ b/include/fastdds/rtps/common/SerializedPayload.h @@ -31,130 +31,153 @@ * With those 536 bytes (RTPSMESSAGE_COMMON_RTPS_PAYLOAD_SIZE) bytes is posible to send RTPS Header plus RTPS Data submessage plus RTPS Heartbeat submessage. */ -namespace eprosima{ - namespace fastrtps{ - namespace rtps{ +namespace eprosima { +namespace fastrtps { +namespace rtps { - //Pre define data encapsulation schemes +//Pre define data encapsulation schemes #define CDR_BE 0x0000 #define CDR_LE 0x0001 #define PL_CDR_BE 0x0002 #define PL_CDR_LE 0x0003 - //!@brief Structure SerializedPayload_t. - //!@ingroup COMMON_MODULE - struct RTPS_DllAPI SerializedPayload_t +//!@brief Structure SerializedPayload_t. +//!@ingroup COMMON_MODULE +struct RTPS_DllAPI SerializedPayload_t +{ + //!Encapsulation of the data as suggested in the RTPS 2.1 specification chapter 10. + uint16_t encapsulation; + //!Actual length of the data + uint32_t length; + //!Pointer to the data. + octet* data; + //!Maximum size of the payload + uint32_t max_size; + //!Position when reading + uint32_t pos; + + //!Default constructor + SerializedPayload_t() + : encapsulation(CDR_BE) + , length(0) + , data(nullptr) + , max_size(0) + , pos(0) + { + } + + /** + * @param len Maximum size of the payload + */ + SerializedPayload_t( + uint32_t len) + : SerializedPayload_t() + { + this->reserve(len); + } + + ~SerializedPayload_t() + { + this->empty(); + } + + bool operator == ( + const SerializedPayload_t& other) const + { + return ((encapsulation == other.encapsulation) && + (length == other.length) && + (0 == memcmp(data, other.data, length))); + } + + /*! + * Copy another structure (including allocating new space for the data.) + * @param[in] serData Pointer to the structure to copy + * @param with_limit if true, the function will fail when providing a payload too big + * @return True if correct + */ + bool copy( + const SerializedPayload_t* serData, + bool with_limit = true) + { + length = serData->length; + + if (serData->length > max_size) + { + if (with_limit) + { + return false; + } + else { - //!Encapsulation of the data as suggested in the RTPS 2.1 specification chapter 10. - uint16_t encapsulation; - //!Actual length of the data - uint32_t length; - //!Pointer to the data. - octet* data; - //!Maximum size of the payload - uint32_t max_size; - //!Position when reading - uint32_t pos; - - //!Default constructor - SerializedPayload_t() : encapsulation(CDR_BE), - length(0), data(nullptr), max_size(0), - pos(0) - { - } - - /** - * @param len Maximum size of the payload - */ - SerializedPayload_t(uint32_t len) - : SerializedPayload_t() - { - this->reserve(len); - } - - ~SerializedPayload_t() - { - this->empty(); - } - - /*! - * Copy another structure (including allocating new space for the data.) - * @param[in] serData Pointer to the structure to copy - * @param with_limit if true, the function will fail when providing a payload too big - * @return True if correct - */ - bool copy(const SerializedPayload_t* serData, bool with_limit = true) - { - length = serData->length; - - if(serData->length > max_size) - { - if(with_limit) - return false; - else - this->reserve(serData->length); - } - encapsulation = serData->encapsulation; - memcpy(data, serData->data, length); - return true; - } - - - /*! - * Allocate new space for fragmented data - * @param[in] serData Pointer to the structure to copy - * @return True if correct - */ - bool reserve_fragmented(SerializedPayload_t* serData) - { - length = serData->length; - max_size = serData->length; - encapsulation = serData->encapsulation; - data = (octet*)calloc(length, sizeof(octet)); - return true; - } - - //! Empty the payload - void empty() - { - length= 0; - encapsulation = CDR_BE; - max_size = 0; - if(data!=nullptr) - free(data); - data = nullptr; - } - - void reserve(uint32_t new_size) - { - if (new_size <= this->max_size) { - return; - } - if(data == nullptr) - { - data = (octet*)calloc(new_size, sizeof(octet)); - if (!data) - { - throw std::bad_alloc(); - } - } - else - { - void * old_data = data; - data = (octet*)realloc(data, new_size); - if (!data) - { - free(old_data); - throw std::bad_alloc(); - } - } - max_size = new_size; - } - - }; + this->reserve(serData->length); + } } + encapsulation = serData->encapsulation; + memcpy(data, serData->data, length); + return true; } -} + + /*! + * Allocate new space for fragmented data + * @param[in] serData Pointer to the structure to copy + * @return True if correct + */ + bool reserve_fragmented( + SerializedPayload_t* serData) + { + length = serData->length; + max_size = serData->length; + encapsulation = serData->encapsulation; + data = (octet*)calloc(length, sizeof(octet)); + return true; + } + + //! Empty the payload + void empty() + { + length = 0; + encapsulation = CDR_BE; + max_size = 0; + if (data != nullptr) + { + free(data); + } + data = nullptr; + } + + void reserve( + uint32_t new_size) + { + if (new_size <= this->max_size) + { + return; + } + if (data == nullptr) + { + data = (octet*)calloc(new_size, sizeof(octet)); + if (!data) + { + throw std::bad_alloc(); + } + } + else + { + void* old_data = data; + data = (octet*)realloc(data, new_size); + if (!data) + { + free(old_data); + throw std::bad_alloc(); + } + } + max_size = new_size; + } + +}; + +} /* namespace rtps */ +} /* namespace fastrtps */ +} /* namespace eprosima */ #endif /* _FASTDDS_RTPS_SERIALIZEDPAYLOAD_H_ */ diff --git a/include/fastdds/rtps/messages/CDRMessage.h b/include/fastdds/rtps/messages/CDRMessage.h index 1157b7b7828..6529f78f780 100644 --- a/include/fastdds/rtps/messages/CDRMessage.h +++ b/include/fastdds/rtps/messages/CDRMessage.h @@ -28,283 +28,300 @@ #include namespace eprosima { -namespace fastrtps{ +namespace fastrtps { namespace rtps { /** * Namespace CDRMessage, contains inline methods to initialize CDRMessage_t and add or read different data types. - @ingroup COMMON_MODULE + @ingroup COMMON_MODULE */ -namespace CDRMessage{ - - /** @name Read from a CDRMessage_t. - * Methods to read different data types from a CDR message. Pointers to the message and to the data types are provided. - * The read position is updated in the message. It fails if you attempt to read outside the - * boundaries of the message. - * @param[in] msg Pointer to message. - * @param[out] data_ptr Pointer to data. - * @param[in] size Number of bytes (if necessary). - * @return True if correct. - */ - /// @{ - inline bool readEntityId( - CDRMessage_t* msg, - EntityId_t*id); - - inline bool readData( - CDRMessage_t* msg, - octet* o, - uint32_t length); - - inline bool readDataReversed( - CDRMessage_t* msg, - octet* o, - uint32_t length); - - inline bool readInt32( - CDRMessage_t* msg, - int32_t* lo); - - inline bool readUInt32( - CDRMessage_t* msg, - uint32_t* ulo); - - inline bool readInt64( - CDRMessage_t* msg, - int64_t* lolo); - - inline bool readSequenceNumber( - CDRMessage_t* msg, - SequenceNumber_t* sn); - - inline bool readInt16( - CDRMessage_t* msg, - int16_t* i16); - - inline bool readUInt16( - CDRMessage_t* msg, - uint16_t* i16); - - inline bool readLocator( - CDRMessage_t* msg, - Locator_t* loc); - - inline bool readOctet( - CDRMessage_t* msg, - octet* o); - - inline SequenceNumberSet_t readSequenceNumberSet( - CDRMessage_t* msg); - - inline bool readFragmentNumberSet( - CDRMessage_t* msg, - FragmentNumberSet_t* snset); - - inline bool readTimestamp( - CDRMessage_t*msg, - Time_t* ts); - - inline bool readString( - CDRMessage_t*msg, - std::string* p_str); - inline bool readString( - CDRMessage_t*msg, - string_255* stri); - - inline bool readOctetVector( - CDRMessage_t*msg, - std::vector* ocvec); - - inline bool readProperty( - CDRMessage_t* msg, - Property& property); - - inline bool readBinaryProperty( - CDRMessage_t* msg, - BinaryProperty& binary_property); - - inline bool readPropertySeq( - CDRMessage_t* msg, - PropertySeq& properties); - - inline bool readBinaryPropertySeq( - CDRMessage_t* msg, - BinaryPropertySeq& binary_properties); - - inline bool readDataHolder( - CDRMessage_t* msg, - DataHolder& data_holder); - - inline bool readDataHolderSeq( - CDRMessage_t* msg, - DataHolderSeq& data_holders); - - inline bool readMessageIdentity( - CDRMessage_t* msg, - security::MessageIdentity& message_identity); - - inline bool readParticipantGenericMessage( - CDRMessage_t* msg, - security::ParticipantGenericMessage& message); - ///@} - - - /** - * Initialize given CDR message with default size. It frees the memory already allocated and reserves new one. - * @param[in,out] msg Pointer to the message to initialize. - * @param data_size Size of the data the message is suppose to carry - * @return True if correct. - */ - inline bool initCDRMsg( - CDRMessage_t* msg, - uint32_t data_size = RTPSMESSAGE_COMMON_DATA_PAYLOAD_SIZE); - - inline bool wrapVector( - CDRMessage_t* msg, - std::vector& vectorToWrap); - - /** - * Append given CDRMessage to existing CDR Message. Joins two messages into the first one if it has space. - * @param[out] first Pointer to first message. - * @param[in] second Pointer to second message. - ** @return True if correct. - */ - inline bool appendMsg( - CDRMessage_t* first, - CDRMessage_t* second); - - - /** @name Add to a CDRMessage_t. - * Methods to add different data types to a CDR message. Pointers to the message and to the data types are provided. - * The write position is updated in the message. It fails if you attempt to write outside the - * boundaries of the message. - * @param[in,out] Pointer to message. - * @param[in] data Data to add (might be a pointer). - * @param[in] byteSize Number of bytes (if necessary). - * @return True if correct. - */ - /// @{ - - inline bool addData( - CDRMessage_t*, - const octet*, - const uint32_t number_bytes); - inline bool addDataReversed( - CDRMessage_t*, - const octet*, - const uint32_t byte_number); - - inline bool addOctet( - CDRMessage_t*msg, - octet o); - - inline bool addUInt16( - CDRMessage_t*msg, - uint16_t us); - - inline bool addInt32( - CDRMessage_t*msg, - int32_t lo); - - inline bool addUInt32( - CDRMessage_t*msg, - uint32_t lo); - - inline bool addInt64( - CDRMessage_t*msg, - int64_t lo); - - inline bool addEntityId( - CDRMessage_t*msg, - const EntityId_t* id); - - inline bool addSequenceNumber( - CDRMessage_t*msg, - const SequenceNumber_t* sn); - - inline bool addSequenceNumberSet( - CDRMessage_t*msg, - const SequenceNumberSet_t* sns); - - inline bool addFragmentNumberSet( - CDRMessage_t*msg, - FragmentNumberSet_t* fns); - - inline bool addLocator( - CDRMessage_t*msg, - Locator_t*loc); - - inline bool addParameterStatus( - CDRMessage_t*msg, - octet status); - - inline bool addParameterKey( - CDRMessage_t*msg, - const InstanceHandle_t* iHandle); - - inline bool addParameterSentinel( - CDRMessage_t*msg); - - inline bool addParameterId( - CDRMessage_t*msg, - ParameterId_t pid); - - inline bool addString( - CDRMessage_t*msg, - const std::string& in_str); - - inline bool addOctetVector( - CDRMessage_t*msg, - const std::vector* ocvec, - bool add_final_padding = true); - - inline bool addParameterSampleIdentity( - CDRMessage_t *msg, - const SampleIdentity &sample_id); - ///@} - - inline bool addProperty( - CDRMessage_t* msg, - const Property& property); - - inline bool addBinaryProperty( - CDRMessage_t* msg, - const BinaryProperty& binary_property, - bool add_final_padding=true); - - inline bool addPropertySeq( - CDRMessage_t* msg, - const PropertySeq& properties); - - inline bool addBinaryPropertySeq( - CDRMessage_t* msg, - const BinaryPropertySeq& binary_properties, - bool add_final_padding); - - inline bool addBinaryPropertySeq(CDRMessage_t* msg, - const BinaryPropertySeq& binary_properties, - const std::string& name_start, - bool add_final_padding); - - inline bool addDataHolder( - CDRMessage_t* msg, - const DataHolder& data_holder); - - inline bool addDataHolderSeq( - CDRMessage_t* msg, - const DataHolderSeq& data_holders); +namespace CDRMessage { + +/** @name Read from a CDRMessage_t. + * Methods to read different data types from a CDR message. Pointers to the message and to the data types are provided. + * The read position is updated in the message. It fails if you attempt to read outside the + * boundaries of the message. + * @param[in] msg Pointer to message. + * @param[out] data_ptr Pointer to data. + * @param[in] size Number of bytes (if necessary). + * @return True if correct. + */ +/// @{ +inline bool readEntityId( + CDRMessage_t* msg, + EntityId_t* id); + +inline bool readData( + CDRMessage_t* msg, + octet* o, + uint32_t length); + +inline bool read_array_with_max_size( + CDRMessage_t* msg, + octet* arr, + size_t max_size); + +inline bool readDataReversed( + CDRMessage_t* msg, + octet* o, + uint32_t length); + +inline bool readInt32( + CDRMessage_t* msg, + int32_t* lo); + +inline bool readUInt32( + CDRMessage_t* msg, + uint32_t* ulo); + +inline bool readInt64( + CDRMessage_t* msg, + int64_t* lolo); + +inline bool readSequenceNumber( + CDRMessage_t* msg, + SequenceNumber_t* sn); + +inline bool readInt16( + CDRMessage_t* msg, + int16_t* i16); + +inline bool readUInt16( + CDRMessage_t* msg, + uint16_t* i16); + +inline bool readLocator( + CDRMessage_t* msg, + Locator_t* loc); + +inline bool readOctet( + CDRMessage_t* msg, + octet* o); + +inline SequenceNumberSet_t readSequenceNumberSet( + CDRMessage_t* msg); + +inline bool readFragmentNumberSet( + CDRMessage_t* msg, + FragmentNumberSet_t* snset); + +inline bool readTimestamp( + CDRMessage_t* msg, + Time_t* ts); + +inline bool readString( + CDRMessage_t* msg, + std::string* p_str); + +inline bool readString( + CDRMessage_t* msg, + string_255* stri); + +inline bool readOctetVector( + CDRMessage_t* msg, + std::vector* ocvec); + +inline bool readProperty( + CDRMessage_t* msg, + Property& property); + +inline bool readBinaryProperty( + CDRMessage_t* msg, + BinaryProperty& binary_property); + +inline bool readPropertySeq( + CDRMessage_t* msg, + PropertySeq& properties); + +inline bool readBinaryPropertySeq( + CDRMessage_t* msg, + BinaryPropertySeq& binary_properties); + +inline bool readDataHolder( + CDRMessage_t* msg, + DataHolder& data_holder); + +inline bool readDataHolderSeq( + CDRMessage_t* msg, + DataHolderSeq& data_holders); + +inline bool readMessageIdentity( + CDRMessage_t* msg, + security::MessageIdentity& message_identity); + +inline bool readParticipantGenericMessage( + CDRMessage_t* msg, + security::ParticipantGenericMessage& message); +///@} + + +/** + * Initialize given CDR message with default size. It frees the memory already allocated and reserves new one. + * @param[in,out] msg Pointer to the message to initialize. + * @param data_size Size of the data the message is suppose to carry + * @return True if correct. + */ +inline bool initCDRMsg( + CDRMessage_t* msg, + uint32_t data_size = RTPSMESSAGE_COMMON_DATA_PAYLOAD_SIZE); + +inline bool wrapVector( + CDRMessage_t* msg, + std::vector& vectorToWrap); + +/** + * Append given CDRMessage to existing CDR Message. Joins two messages into the first one if it has space. + * @param[out] first Pointer to first message. + * @param[in] second Pointer to second message. + ** @return True if correct. + */ +inline bool appendMsg( + CDRMessage_t* first, + CDRMessage_t* second); + + +/** @name Add to a CDRMessage_t. + * Methods to add different data types to a CDR message. Pointers to the message and to the data types are provided. + * The write position is updated in the message. It fails if you attempt to write outside the + * boundaries of the message. + * @param[in,out] Pointer to message. + * @param[in] data Data to add (might be a pointer). + * @param[in] byteSize Number of bytes (if necessary). + * @return True if correct. + */ +/// @{ + +inline bool addData( + CDRMessage_t*, + const octet*, + const uint32_t number_bytes); +inline bool addDataReversed( + CDRMessage_t*, + const octet*, + const uint32_t byte_number); + +inline bool addOctet( + CDRMessage_t* msg, + octet o); + +inline bool addUInt16( + CDRMessage_t* msg, + uint16_t us); + +inline bool addInt32( + CDRMessage_t* msg, + int32_t lo); + +inline bool addUInt32( + CDRMessage_t* msg, + uint32_t lo); + +inline bool addInt64( + CDRMessage_t* msg, + int64_t lo); + +inline bool addEntityId( + CDRMessage_t* msg, + const EntityId_t* id); + +inline bool addSequenceNumber( + CDRMessage_t* msg, + const SequenceNumber_t* sn); + +inline bool addSequenceNumberSet( + CDRMessage_t* msg, + const SequenceNumberSet_t* sns); + +inline bool addFragmentNumberSet( + CDRMessage_t* msg, + FragmentNumberSet_t* fns); + +inline bool addLocator( + CDRMessage_t* msg, + Locator_t* loc); + +inline bool addParameterStatus( + CDRMessage_t* msg, + octet status); + +inline bool addParameterKey( + CDRMessage_t* msg, + const InstanceHandle_t* iHandle); + +inline bool addParameterSentinel( + CDRMessage_t* msg); + +inline bool addParameterId( + CDRMessage_t* msg, + ParameterId_t pid); + +inline bool add_string( + CDRMessage_t* msg, + const char* in_str); + +inline bool add_string( + CDRMessage_t* msg, + const std::string& in_str); + +inline bool add_string( + CDRMessage_t* msg, + const string_255& in_str); + +inline bool addOctetVector( + CDRMessage_t* msg, + const std::vector* ocvec, + bool add_final_padding = true); + +inline bool addParameterSampleIdentity( + CDRMessage_t* msg, + const SampleIdentity& sample_id); + +inline bool addProperty( + CDRMessage_t* msg, + const Property& property); + +inline bool addBinaryProperty( + CDRMessage_t* msg, + const BinaryProperty& binary_property, + bool add_final_padding = true); + +inline bool addPropertySeq( + CDRMessage_t* msg, + const PropertySeq& properties); + +inline bool addBinaryPropertySeq( + CDRMessage_t* msg, + const BinaryPropertySeq& binary_properties, + bool add_final_padding); + +inline bool addBinaryPropertySeq( + CDRMessage_t* msg, + const BinaryPropertySeq& binary_properties, + const std::string& name_start, + bool add_final_padding); + +inline bool addDataHolder( + CDRMessage_t* msg, + const DataHolder& data_holder); + +inline bool addDataHolderSeq( + CDRMessage_t* msg, + const DataHolderSeq& data_holders); + +inline bool addMessageIdentity( + CDRMessage_t* msg, + const security::MessageIdentity& message_identity); + +inline bool addParticipantGenericMessage( + CDRMessage_t* msg, + const security::ParticipantGenericMessage& message); + +///@} - inline bool addMessageIdentity( - CDRMessage_t* msg, - const security::MessageIdentity& message_identity); +} /* namespace CDRMessage */ - inline bool addParticipantGenericMessage( - CDRMessage_t* msg, - const security::ParticipantGenericMessage& message); -} - -} } /* namespace rtps */ +} /* namespace fastrtps */ } /* namespace eprosima */ #ifndef DOXYGEN_SHOULD_SKIP_THIS diff --git a/include/fastdds/rtps/messages/CDRMessage.hpp b/include/fastdds/rtps/messages/CDRMessage.hpp index 54e15a5f9a8..568514b5af7 100644 --- a/include/fastdds/rtps/messages/CDRMessage.hpp +++ b/include/fastdds/rtps/messages/CDRMessage.hpp @@ -25,15 +25,17 @@ #include namespace eprosima { -namespace fastrtps{ +namespace fastrtps { namespace rtps { -inline bool CDRMessage::initCDRMsg(CDRMessage_t*msg,uint32_t payload_size) +inline bool CDRMessage::initCDRMsg( + CDRMessage_t* msg, + uint32_t payload_size) { - if(msg->buffer==NULL) + if (msg->buffer == nullptr) { - msg->buffer = (octet*)malloc(payload_size+RTPSMESSAGE_COMMON_RTPS_PAYLOAD_SIZE); - msg->max_size = payload_size+RTPSMESSAGE_COMMON_RTPS_PAYLOAD_SIZE; + msg->buffer = (octet*)malloc(payload_size + RTPSMESSAGE_COMMON_RTPS_PAYLOAD_SIZE); + msg->max_size = payload_size + RTPSMESSAGE_COMMON_RTPS_PAYLOAD_SIZE; } msg->pos = 0; msg->length = 0; @@ -45,10 +47,14 @@ inline bool CDRMessage::initCDRMsg(CDRMessage_t*msg,uint32_t payload_size) return true; } -inline bool CDRMessage::wrapVector(CDRMessage_t* msg, std::vector& vectorToWrap) +inline bool CDRMessage::wrapVector( + CDRMessage_t* msg, + std::vector& vectorToWrap) { if (msg->buffer && !msg->wraps) + { free(msg->buffer); + } msg->wraps = true; msg->buffer = vectorToWrap.data(); @@ -62,79 +68,139 @@ inline bool CDRMessage::wrapVector(CDRMessage_t* msg, std::vector& vector return true; } -inline bool CDRMessage::appendMsg(CDRMessage_t*first, CDRMessage_t*second) { - return(CDRMessage::addData(first,second->buffer,second->length)); +inline bool CDRMessage::appendMsg( + CDRMessage_t* first, + CDRMessage_t* second) +{ + return(CDRMessage::addData(first, second->buffer, second->length)); } - -inline bool CDRMessage::readEntityId(CDRMessage_t* msg, EntityId_t* id) { - if(msg->pos+4>msg->length) +inline bool CDRMessage::readEntityId( + CDRMessage_t* msg, + EntityId_t* id) +{ + if (msg->pos + 4 > msg->length) + { return false; + } memcpy(id->value, &msg->buffer[msg->pos], id->size); - msg->pos+=4; + msg->pos += 4; return true; } -inline bool CDRMessage::readData(CDRMessage_t* msg, octet* o, uint32_t length) { - if(msg->pos+length > msg->length){ +inline bool CDRMessage::readData( + CDRMessage_t* msg, + octet* o, + uint32_t length) +{ + if (msg->pos + length > msg->length) + { return false; } - memcpy(o,&msg->buffer[msg->pos],length); - msg->pos+=length; + memcpy(o, &msg->buffer[msg->pos], length); + msg->pos += length; return true; } -inline bool CDRMessage::readDataReversed(CDRMessage_t* msg, octet* o, uint32_t length) { - for(uint32_t i=0;ipos + 4 > msg->length) + { + return false; + } + uint32_t datasize; + bool valid = CDRMessage::readUInt32(msg, &datasize); + if (max_size < datasize) + { + return false; + } + valid &= CDRMessage::readData(msg, arr, datasize); + msg->pos = (msg->pos + 3) & ~3; + return valid; +} + +inline bool CDRMessage::readDataReversed( + CDRMessage_t* msg, + octet* o, + uint32_t length) +{ + for (uint32_t i = 0; i < length; i++) { - *(o+i)=*(msg->buffer+msg->pos+length-1-i); + *(o + i) = *(msg->buffer + msg->pos + length - 1 - i); } - msg->pos+=length; + msg->pos += length; return true; } -inline bool CDRMessage::readInt32(CDRMessage_t* msg,int32_t* lo) { - if(msg->pos+4>msg->length) +inline bool CDRMessage::readInt32( + CDRMessage_t* msg, + int32_t* lo) +{ + if (msg->pos + 4 > msg->length) + { return false; + } octet* dest = (octet*)lo; - if(msg->msg_endian == DEFAULT_ENDIAN){ - for(uint8_t i =0;i<4;i++) - dest[i] = msg->buffer[msg->pos+i]; - msg->pos+=4; + if (msg->msg_endian == DEFAULT_ENDIAN) + { + for (uint8_t i = 0; i < 4; i++) + { + dest[i] = msg->buffer[msg->pos + i]; + } + msg->pos += 4; } - else{ - readDataReversed(msg,dest,4); + else + { + readDataReversed(msg, dest, 4); } return true; } -inline bool CDRMessage::readUInt32(CDRMessage_t* msg,uint32_t* ulo) { - if(msg->pos+4>msg->length) +inline bool CDRMessage::readUInt32( + CDRMessage_t* msg, + uint32_t* ulo) +{ + if (msg->pos + 4 > msg->length) + { return false; + } octet* dest = (octet*)ulo; - if(msg->msg_endian == DEFAULT_ENDIAN){ - for(uint8_t i =0;i<4;i++) - dest[i] = msg->buffer[msg->pos+i]; - msg->pos+=4; + if (msg->msg_endian == DEFAULT_ENDIAN) + { + for (uint8_t i = 0; i < 4; i++) + { + dest[i] = msg->buffer[msg->pos + i]; + } + msg->pos += 4; } - else{ - readDataReversed(msg,dest,4); + else + { + readDataReversed(msg, dest, 4); } return true; } -inline bool CDRMessage::readInt64(CDRMessage_t* msg, int64_t* lolo) +inline bool CDRMessage::readInt64( + CDRMessage_t* msg, + int64_t* lolo) { - if(msg->pos+8 > msg->length) + if (msg->pos + 8 > msg->length) + { return false; + } octet* dest = (octet*)lolo; - if(msg->msg_endian == DEFAULT_ENDIAN) + if (msg->msg_endian == DEFAULT_ENDIAN) { - for(uint8_t i = 0; i < 8; ++i) - dest[i] = msg->buffer[msg->pos+i]; + for (uint8_t i = 0; i < 8; ++i) + { + dest[i] = msg->buffer[msg->pos + i]; + } - msg->pos+=8; + msg->pos += 8; } else { @@ -144,35 +210,46 @@ inline bool CDRMessage::readInt64(CDRMessage_t* msg, int64_t* lolo) return true; } -inline bool CDRMessage::readSequenceNumber(CDRMessage_t* msg,SequenceNumber_t* sn) { - if(msg->pos+8>msg->length) +inline bool CDRMessage::readSequenceNumber( + CDRMessage_t* msg, + SequenceNumber_t* sn) +{ + if (msg->pos + 8 > msg->length) + { return false; - bool valid=readInt32(msg,&sn->high); - valid&=readUInt32(msg,&sn->low); + } + bool valid = readInt32(msg, &sn->high); + valid &= readUInt32(msg, &sn->low); return true; } -inline SequenceNumberSet_t CDRMessage::readSequenceNumberSet(CDRMessage_t* msg) +inline SequenceNumberSet_t CDRMessage::readSequenceNumberSet( + CDRMessage_t* msg) { bool valid = true; SequenceNumber_t seqNum; - valid &=CDRMessage::readSequenceNumber(msg,&seqNum); + valid &= CDRMessage::readSequenceNumber(msg, &seqNum); SequenceNumberSet_t sns(seqNum); uint32_t numBits = 0; - valid &=CDRMessage::readUInt32(msg,&numBits); + valid &= CDRMessage::readUInt32(msg, &numBits); uint32_t n_longs = (numBits + 31ul) / 32ul; uint32_t bitmap[8]; - for(uint32_t i=0;ibitmap_set(numBits, bitmap); + if (valid) + { + fns->bitmap_set(numBits, bitmap); + } return valid; } -inline bool CDRMessage::readTimestamp(CDRMessage_t* msg, rtps::Time_t* ts) +inline bool CDRMessage::readTimestamp( + CDRMessage_t* msg, + rtps::Time_t* ts) { bool valid = true; valid &= CDRMessage::readInt32(msg, &ts->seconds()); @@ -200,10 +282,11 @@ inline bool CDRMessage::readTimestamp(CDRMessage_t* msg, rtps::Time_t* ts) return valid; } - -inline bool CDRMessage::readLocator(CDRMessage_t* msg, Locator_t* loc) +inline bool CDRMessage::readLocator( + CDRMessage_t* msg, + Locator_t* loc) { - if(msg->pos + 24 > msg->length) + if (msg->pos + 24 > msg->length) { return false; } @@ -215,93 +298,111 @@ inline bool CDRMessage::readLocator(CDRMessage_t* msg, Locator_t* loc) return valid; } -inline bool CDRMessage::readInt16(CDRMessage_t* msg,int16_t* i16) +inline bool CDRMessage::readInt16( + CDRMessage_t* msg, + int16_t* i16) { - if(msg->pos+2>msg->length) + if (msg->pos + 2 > msg->length) + { return false; + } octet* o = (octet*)i16; - if(msg->msg_endian == DEFAULT_ENDIAN) + if (msg->msg_endian == DEFAULT_ENDIAN) { *o = msg->buffer[msg->pos]; - *(o+1) = msg->buffer[msg->pos+1]; + *(o + 1) = msg->buffer[msg->pos + 1]; } - else{ - *o = msg->buffer[msg->pos+1]; - *(o+1) = msg->buffer[msg->pos]; + else + { + *o = msg->buffer[msg->pos + 1]; + *(o + 1) = msg->buffer[msg->pos]; } - msg->pos+=2; + msg->pos += 2; return true; } -inline bool CDRMessage::readUInt16(CDRMessage_t* msg,uint16_t* i16) +inline bool CDRMessage::readUInt16( + CDRMessage_t* msg, + uint16_t* i16) { - if(msg->pos+2>msg->length) + if (msg->pos + 2 > msg->length) + { return false; + } octet* o = (octet*)i16; - if(msg->msg_endian == DEFAULT_ENDIAN){ + if (msg->msg_endian == DEFAULT_ENDIAN) + { *o = msg->buffer[msg->pos]; - *(o+1) = msg->buffer[msg->pos+1]; + *(o + 1) = msg->buffer[msg->pos + 1]; } - else{ - *o = msg->buffer[msg->pos+1]; - *(o+1) = msg->buffer[msg->pos]; + else + { + *o = msg->buffer[msg->pos + 1]; + *(o + 1) = msg->buffer[msg->pos]; } - msg->pos+=2; + msg->pos += 2; return true; } - - -inline bool CDRMessage::readOctet(CDRMessage_t* msg, octet* o) { - if(msg->pos+1>msg->length) +inline bool CDRMessage::readOctet( + CDRMessage_t* msg, + octet* o) +{ + if (msg->pos + 1 > msg->length) + { return false; + } *o = msg->buffer[msg->pos]; msg->pos++; return true; } -inline bool CDRMessage::readOctetVector(CDRMessage_t*msg,std::vector* ocvec) +inline bool CDRMessage::readOctetVector( + CDRMessage_t* msg, + std::vector* ocvec) { - if(msg->pos+4>msg->length) + if (msg->pos + 4 > msg->length) + { return false; + } uint32_t vecsize; - bool valid = CDRMessage::readUInt32(msg,&vecsize); + bool valid = CDRMessage::readUInt32(msg, &vecsize); ocvec->resize(vecsize); - valid &= CDRMessage::readData(msg,ocvec->data(),vecsize); - int rest = (vecsize) % 4; - rest = rest== 0 ? 0 : 4-rest; - msg->pos+=rest; + valid &= CDRMessage::readData(msg, ocvec->data(), vecsize); + msg->pos = (msg->pos + 3) & ~3; return valid; } - -inline bool CDRMessage::readString(CDRMessage_t*msg, std::string* stri) +inline bool CDRMessage::readString( + CDRMessage_t* msg, + std::string* stri) { uint32_t str_size = 1; bool valid = true; - valid&=CDRMessage::readUInt32(msg,&str_size); - if(msg->pos+str_size > msg->length){ + valid &= CDRMessage::readUInt32(msg, &str_size); + if (msg->pos + str_size > msg->length) + { return false; } stri->clear(); - if(str_size>1) + if (str_size > 1) { - stri->resize(str_size-1); + stri->resize(str_size - 1); for (uint32_t i = 0; i < str_size - 1; i++) { stri->at(i) = msg->buffer[msg->pos + i]; } } msg->pos += str_size; - int rest = (str_size) % 4; - rest = rest==0 ? 0 : 4-rest; - msg->pos+=rest; + msg->pos = (msg->pos + 3) & ~3; return valid; } -inline bool CDRMessage::readString(CDRMessage_t*msg, string_255* stri) +inline bool CDRMessage::readString( + CDRMessage_t* msg, + string_255* stri) { uint32_t str_size = 1; bool valid = true; @@ -324,37 +425,45 @@ inline bool CDRMessage::readString(CDRMessage_t*msg, string_255* stri) return valid; } -inline bool CDRMessage::addData(CDRMessage_t*msg, const octet *data, const uint32_t length) +inline bool CDRMessage::addData( + CDRMessage_t* msg, + const octet* data, + const uint32_t length) { - if(msg->pos + length > msg->max_size) + if (msg->pos + length > msg->max_size) { return false; } - memcpy(&msg->buffer[msg->pos],data,length); - msg->pos +=length; - msg->length+=length; + memcpy(&msg->buffer[msg->pos], data, length); + msg->pos += length; + msg->length += length; return true; } -inline bool CDRMessage::addDataReversed(CDRMessage_t*msg, const octet *data, const uint32_t length) +inline bool CDRMessage::addDataReversed( + CDRMessage_t* msg, + const octet* data, + const uint32_t length) { - if(msg->pos + length > msg->max_size) + if (msg->pos + length > msg->max_size) { return false; } - for(uint32_t i = 0;ibuffer[msg->pos+i] = *(data+length-1-i); + msg->buffer[msg->pos + i] = *(data + length - 1 - i); } - msg->pos +=length; - msg->length+=length; + msg->pos += length; + msg->length += length; return true; } -inline bool CDRMessage::addOctet(CDRMessage_t*msg, octet O) +inline bool CDRMessage::addOctet( + CDRMessage_t* msg, + octet O) { - if(msg->pos + 1 > msg->max_size) + if (msg->pos + 1 > msg->max_size) { return false; } @@ -365,124 +474,138 @@ inline bool CDRMessage::addOctet(CDRMessage_t*msg, octet O) return true; } -inline bool CDRMessage::addUInt16(CDRMessage_t*msg,uint16_t us) +inline bool CDRMessage::addUInt16( + CDRMessage_t* msg, + uint16_t us) { - if(msg->pos + 2 > msg->max_size) + if (msg->pos + 2 > msg->max_size) { return false; } - octet* o= (octet*)&us; - if(msg->msg_endian == DEFAULT_ENDIAN) + octet* o = (octet*)&us; + if (msg->msg_endian == DEFAULT_ENDIAN) { msg->buffer[msg->pos] = *(o); - msg->buffer[msg->pos+1] = *(o+1); + msg->buffer[msg->pos + 1] = *(o + 1); } else { - msg->buffer[msg->pos] = *(o+1); - msg->buffer[msg->pos+1] = *(o); + msg->buffer[msg->pos] = *(o + 1); + msg->buffer[msg->pos + 1] = *(o); } - msg->pos+=2; - msg->length+=2; + msg->pos += 2; + msg->length += 2; return true; } - -inline bool CDRMessage::addParameterId(CDRMessage_t* msg, ParameterId_t pid) +inline bool CDRMessage::addParameterId( + CDRMessage_t* msg, + ParameterId_t pid) { - return CDRMessage::addUInt16(msg,(uint16_t)pid); + return CDRMessage::addUInt16(msg, (uint16_t)pid); } - - -inline bool CDRMessage::addInt32(CDRMessage_t* msg, int32_t lo) { - octet* o= (octet*)&lo; - if(msg->pos + 4 > msg->max_size) +inline bool CDRMessage::addInt32( + CDRMessage_t* msg, + int32_t lo) +{ + octet* o = (octet*)&lo; + if (msg->pos + 4 > msg->max_size) { return false; } - if(msg->msg_endian == DEFAULT_ENDIAN) + if (msg->msg_endian == DEFAULT_ENDIAN) { - for(uint8_t i=0;i<4;i++) + for (uint8_t i = 0; i < 4; i++) { - msg->buffer[msg->pos+i] = *(o+i); + msg->buffer[msg->pos + i] = *(o + i); } } else { - for(uint8_t i=0;i<4;i++) + for (uint8_t i = 0; i < 4; i++) { - msg->buffer[msg->pos+i] = *(o+3-i); + msg->buffer[msg->pos + i] = *(o + 3 - i); } } - msg->pos+=4; - msg->length+=4; + msg->pos += 4; + msg->length += 4; return true; } - - -inline bool CDRMessage::addUInt32(CDRMessage_t* msg, uint32_t ulo) { - octet* o= (octet*)&ulo; - if(msg->pos + 4 > msg->max_size) +inline bool CDRMessage::addUInt32( + CDRMessage_t* msg, + uint32_t ulo) +{ + octet* o = (octet*)&ulo; + if (msg->pos + 4 > msg->max_size) { return false; } - if(msg->msg_endian == DEFAULT_ENDIAN) + if (msg->msg_endian == DEFAULT_ENDIAN) { - for(uint8_t i=0;i<4;i++) + for (uint8_t i = 0; i < 4; i++) { - msg->buffer[msg->pos+i] = *(o+i); + msg->buffer[msg->pos + i] = *(o + i); } } else { - for(uint8_t i=0;i<4;i++) + for (uint8_t i = 0; i < 4; i++) { - msg->buffer[msg->pos+i] = *(o+3-i); + msg->buffer[msg->pos + i] = *(o + 3 - i); } } - msg->pos+=4; - msg->length+=4; + msg->pos += 4; + msg->length += 4; return true; } -inline bool CDRMessage::addInt64(CDRMessage_t* msg, int64_t lolo) { - octet* o= (octet*)&lolo; - if(msg->pos + 8 > msg->max_size) +inline bool CDRMessage::addInt64( + CDRMessage_t* msg, + int64_t lolo) +{ + octet* o = (octet*)&lolo; + if (msg->pos + 8 > msg->max_size) { return false; } - if(msg->msg_endian == DEFAULT_ENDIAN) + if (msg->msg_endian == DEFAULT_ENDIAN) { - for(uint8_t i=0;i<8;i++) + for (uint8_t i = 0; i < 8; i++) { - msg->buffer[msg->pos+i] = *(o+i); + msg->buffer[msg->pos + i] = *(o + i); } } else { - for(uint8_t i=0;i<8;i++) + for (uint8_t i = 0; i < 8; i++) { - msg->buffer[msg->pos+i] = *(o+7-i); + msg->buffer[msg->pos + i] = *(o + 7 - i); } } - msg->pos+=8; - msg->length+=8; + msg->pos += 8; + msg->length += 8; return true; } -inline bool CDRMessage::addOctetVector(CDRMessage_t*msg, const std::vector* ocvec, bool add_final_padding) +inline bool CDRMessage::addOctetVector( + CDRMessage_t* msg, + const std::vector* ocvec, + bool add_final_padding) { // TODO Calculate without padding auto final_size = msg->pos + ocvec->size(); - if (add_final_padding) final_size += 4; - if(final_size>=msg->max_size) + if (add_final_padding) + { + final_size += 4; + } + if (final_size >= msg->max_size) { return false; } - bool valid = CDRMessage::addUInt32(msg,(uint32_t)ocvec->size()); - valid &= CDRMessage::addData(msg,(octet*)ocvec->data(),(uint32_t)ocvec->size()); + bool valid = CDRMessage::addUInt32(msg, (uint32_t)ocvec->size()); + valid &= CDRMessage::addData(msg, (octet*)ocvec->data(), (uint32_t)ocvec->size()); if (add_final_padding) { @@ -502,63 +625,68 @@ inline bool CDRMessage::addOctetVector(CDRMessage_t*msg, const std::vectorpos+4>=msg->max_size) +inline bool CDRMessage::addEntityId( + CDRMessage_t* msg, + const EntityId_t* ID) +{ + if (msg->pos + 4 >= msg->max_size) { return false; } memcpy(&msg->buffer[msg->pos], ID->value, ID->size); - msg->pos +=4; - msg->length+=4; + msg->pos += 4; + msg->length += 4; return true; } - - - - -inline bool CDRMessage::addSequenceNumber(CDRMessage_t* msg, +inline bool CDRMessage::addSequenceNumber( + CDRMessage_t* msg, const SequenceNumber_t* sn) { - addInt32(msg,sn->high); - addUInt32(msg,sn->low); + addInt32(msg, sn->high); + addUInt32(msg, sn->low); return true; } -inline bool CDRMessage::addSequenceNumberSet(CDRMessage_t* msg, +inline bool CDRMessage::addSequenceNumberSet( + CDRMessage_t* msg, const SequenceNumberSet_t* sns) { SequenceNumber_t base = sns->base(); CDRMessage::addSequenceNumber(msg, &base); //Add set - if(sns->empty()) + if (sns->empty()) { - addUInt32(msg,0); //numbits 0 + addUInt32(msg, 0); //numbits 0 return true; } uint32_t numBits; uint32_t n_longs; - std::array bitmap; + std::array bitmap; sns->bitmap_get(numBits, bitmap, n_longs); addUInt32(msg, numBits); - for(uint32_t i= 0;ibase(); if (base == 0) + { return false; + } CDRMessage::addUInt32(msg, base); @@ -576,84 +704,102 @@ inline bool CDRMessage::addFragmentNumberSet(CDRMessage_t* msg, addUInt32(msg, numBits); - for (uint32_t i = 0; ikind); addUInt32(msg, loc->port); addData(msg, loc->address, 16); return true; } -inline bool CDRMessage::addParameterStatus(CDRMessage_t* msg, octet status) +inline bool CDRMessage::addParameterStatus( + CDRMessage_t* msg, + octet status) { - if(msg->pos+8>=msg->max_size) + if (msg->pos + 8 >= msg->max_size) { return false; } CDRMessage::addUInt16(msg, fastdds::dds::PID_STATUS_INFO); - CDRMessage::addUInt16(msg,4); - CDRMessage::addOctet(msg,0); - CDRMessage::addOctet(msg,0); - CDRMessage::addOctet(msg,0); - CDRMessage::addOctet(msg,status); + CDRMessage::addUInt16(msg, 4); + CDRMessage::addOctet(msg, 0); + CDRMessage::addOctet(msg, 0); + CDRMessage::addOctet(msg, 0); + CDRMessage::addOctet(msg, status); return true; } - -inline bool CDRMessage::addParameterKey(CDRMessage_t* msg, const InstanceHandle_t* iHandle) +inline bool CDRMessage::addParameterKey( + CDRMessage_t* msg, + const InstanceHandle_t* iHandle) { - if(msg->pos+20>=msg->max_size) + if (msg->pos + 20 >= msg->max_size) { return false; } CDRMessage::addUInt16(msg, fastdds::dds::PID_KEY_HASH); - CDRMessage::addUInt16(msg,16); - for(uint8_t i=0;i<16;i++) - msg->buffer[msg->pos+i] = iHandle->value[i]; - msg->pos+=16; - msg->length+=16; + CDRMessage::addUInt16(msg, 16); + CDRMessage::addData(msg, iHandle->value, 16); return true; } -inline bool CDRMessage::addParameterSentinel(CDRMessage_t* msg) +inline bool CDRMessage::addParameterSentinel( + CDRMessage_t* msg) { - if(msg->pos+4>=msg->max_size) + if (msg->pos + 4 >= msg->max_size) { return false; } - CDRMessage::addUInt16(msg, fastdds::dds::PID_SENTINEL); + CDRMessage::addUInt16(msg, static_cast(fastdds::dds::PID_SENTINEL)); CDRMessage::addUInt16(msg, 0); return true; } -inline bool CDRMessage::addString(CDRMessage_t*msg, const std::string& in_str) +inline bool CDRMessage::add_string( + CDRMessage_t* msg, + const char* in_str) { - auto data = in_str.c_str(); - uint32_t str_siz = (uint32_t)strlen(data); - int rest = (str_siz+1) % 4; - if (rest != 0) - rest = 4 - rest; //how many you have to add - - bool valid = CDRMessage::addUInt32(msg, str_siz+1); - valid &= CDRMessage::addData(msg, (unsigned char*) data, str_siz+1); - if (rest != 0) { - octet oc = '\0'; - for (int i = 0; i < rest; i++) { - valid &= CDRMessage::addOctet(msg, oc); - } + uint32_t str_siz = static_cast(strlen(in_str) + 1); + bool valid = CDRMessage::addUInt32(msg, str_siz); + valid &= CDRMessage::addData(msg, (unsigned char*) in_str, str_siz); + octet oc = '\0'; + for (; str_siz & 3; ++str_siz) + { + valid &= CDRMessage::addOctet(msg, oc); } return valid; } -inline bool CDRMessage::addParameterSampleIdentity(CDRMessage_t *msg, const SampleIdentity &sample_id) +inline bool CDRMessage::add_string( + CDRMessage_t* msg, + const std::string& in_str) { - if(msg->pos + 28 > msg->max_size) + return add_string(msg, in_str.c_str()); +} + +inline bool CDRMessage::add_string( + CDRMessage_t* msg, + const string_255& in_str) +{ + return add_string(msg, in_str.c_str()); +} + +inline bool CDRMessage::addParameterSampleIdentity( + CDRMessage_t* msg, + const SampleIdentity& sample_id) +{ + if (msg->pos + 28 > msg->max_size) { return false; } @@ -667,147 +813,205 @@ inline bool CDRMessage::addParameterSampleIdentity(CDRMessage_t *msg, const Samp return true; } -inline bool CDRMessage::addProperty(CDRMessage_t* msg, const Property& property) +inline bool CDRMessage::addProperty( + CDRMessage_t* msg, + const Property& property) { assert(msg); - if(property.propagate()) + if (property.propagate()) { - if(!CDRMessage::addString(msg, property.name())) + if (!CDRMessage::add_string(msg, property.name())) + { return false; - if(!CDRMessage::addString(msg, property.value())) + } + if (!CDRMessage::add_string(msg, property.value())) + { return false; + } } return true; } -inline bool CDRMessage::readProperty(CDRMessage_t* msg, Property& property) +inline bool CDRMessage::readProperty( + CDRMessage_t* msg, + Property& property) { assert(msg); - if(!CDRMessage::readString(msg, &property.name())) + if (!CDRMessage::readString(msg, &property.name())) + { return false; - if(!CDRMessage::readString(msg, &property.value())) + } + if (!CDRMessage::readString(msg, &property.value())) + { return false; + } return true; } -inline bool CDRMessage::addBinaryProperty(CDRMessage_t* msg, const BinaryProperty& binary_property, bool add_final_padding) +inline bool CDRMessage::addBinaryProperty( + CDRMessage_t* msg, + const BinaryProperty& binary_property, + bool add_final_padding) { assert(msg); - if(binary_property.propagate()) + if (binary_property.propagate()) { - if(!CDRMessage::addString(msg, binary_property.name())) + if (!CDRMessage::add_string(msg, binary_property.name())) + { return false; + } if (!CDRMessage::addOctetVector(msg, &binary_property.value(), add_final_padding)) + { return false; + } } return true; } -inline bool CDRMessage::readBinaryProperty(CDRMessage_t* msg, BinaryProperty& binary_property) +inline bool CDRMessage::readBinaryProperty( + CDRMessage_t* msg, + BinaryProperty& binary_property) { assert(msg); - if(!CDRMessage::readString(msg, &binary_property.name())) + if (!CDRMessage::readString(msg, &binary_property.name())) + { return false; - if(!CDRMessage::readOctetVector(msg, &binary_property.value())) + } + if (!CDRMessage::readOctetVector(msg, &binary_property.value())) + { return false; + } binary_property.propagate(true); return true; } -inline bool CDRMessage::addPropertySeq(CDRMessage_t* msg, const PropertySeq& properties) +inline bool CDRMessage::addPropertySeq( + CDRMessage_t* msg, + const PropertySeq& properties) { assert(msg); bool returnedValue = false; - if(msg->pos + 4 <= msg->max_size) + if (msg->pos + 4 <= msg->max_size) { uint32_t number_to_serialize = 0; - for(auto it = properties.begin(); it != properties.end(); ++it) - if(it->propagate()) + for (auto it = properties.begin(); it != properties.end(); ++it) + { + if (it->propagate()) + { ++number_to_serialize; + } + } - if(CDRMessage::addUInt32(msg, number_to_serialize)) + if (CDRMessage::addUInt32(msg, number_to_serialize)) { returnedValue = true; - for(auto it = properties.begin(); returnedValue && it != properties.end(); ++it) - if(it->propagate()) + for (auto it = properties.begin(); returnedValue && it != properties.end(); ++it) + { + if (it->propagate()) + { returnedValue = CDRMessage::addProperty(msg, *it); + } + } } } return returnedValue; } -inline bool CDRMessage::readPropertySeq(CDRMessage_t* msg, PropertySeq& properties) +inline bool CDRMessage::readPropertySeq( + CDRMessage_t* msg, + PropertySeq& properties) { assert(msg); uint32_t length = 0; - if(!CDRMessage::readUInt32(msg, &length)) + if (!CDRMessage::readUInt32(msg, &length)) + { return false; + } properties.resize(length); bool returnedValue = true; - for(uint32_t i = 0; returnedValue && i < length; ++i) + for (uint32_t i = 0; returnedValue && i < length; ++i) + { returnedValue = CDRMessage::readProperty(msg, properties.at(i)); + } return returnedValue; } -inline bool CDRMessage::addBinaryPropertySeq(CDRMessage_t* msg, const BinaryPropertySeq& binary_properties, bool add_final_padding) +inline bool CDRMessage::addBinaryPropertySeq( + CDRMessage_t* msg, + const BinaryPropertySeq& binary_properties, + bool add_final_padding) { assert(msg); bool returnedValue = false; - if(msg->pos + 4 <= msg->max_size) + if (msg->pos + 4 <= msg->max_size) { uint32_t number_to_serialize = 0; - for(auto it = binary_properties.begin(); it != binary_properties.end(); ++it) - if(it->propagate()) + for (auto it = binary_properties.begin(); it != binary_properties.end(); ++it) + { + if (it->propagate()) + { ++number_to_serialize; + } + } - if(CDRMessage::addUInt32(msg, number_to_serialize)) + if (CDRMessage::addUInt32(msg, number_to_serialize)) { returnedValue = true; - for(auto it = binary_properties.begin(); returnedValue && it != binary_properties.end(); ++it) + for (auto it = binary_properties.begin(); returnedValue && it != binary_properties.end(); ++it) + { if (it->propagate()) { --number_to_serialize; - returnedValue = CDRMessage::addBinaryProperty(msg, *it, add_final_padding || (number_to_serialize != 0) ); + returnedValue = + CDRMessage::addBinaryProperty(msg, *it, + add_final_padding || (number_to_serialize != 0) ); } + } } } return returnedValue; } -inline bool CDRMessage::addBinaryPropertySeq(CDRMessage_t* msg, const BinaryPropertySeq& binary_properties, const std::string& name_start, bool add_final_padding) +inline bool CDRMessage::addBinaryPropertySeq( + CDRMessage_t* msg, + const BinaryPropertySeq& binary_properties, + const std::string& name_start, + bool add_final_padding) { assert(msg); bool returnedValue = false; - if(msg->pos + 4 <= msg->max_size) + if (msg->pos + 4 <= msg->max_size) { uint32_t number_to_serialize = 0; - for(auto it = binary_properties.begin(); it != binary_properties.end(); ++it) + for (auto it = binary_properties.begin(); it != binary_properties.end(); ++it) { - if(it->name().find(name_start) == 0) + if (it->name().find(name_start) == 0) + { ++number_to_serialize; + } } - if(CDRMessage::addUInt32(msg, number_to_serialize)) + if (CDRMessage::addUInt32(msg, number_to_serialize)) { returnedValue = true; for (auto it = binary_properties.begin(); returnedValue && it != binary_properties.end(); ++it) @@ -815,7 +1019,9 @@ inline bool CDRMessage::addBinaryPropertySeq(CDRMessage_t* msg, const BinaryProp if (it->name().find(name_start) == 0) { --number_to_serialize; - returnedValue = CDRMessage::addBinaryProperty(msg, *it, add_final_padding || (number_to_serialize != 0) ); + returnedValue = + CDRMessage::addBinaryProperty(msg, *it, + add_final_padding || (number_to_serialize != 0) ); } } } @@ -824,166 +1030,259 @@ inline bool CDRMessage::addBinaryPropertySeq(CDRMessage_t* msg, const BinaryProp return returnedValue; } -inline bool CDRMessage::readBinaryPropertySeq(CDRMessage_t* msg, BinaryPropertySeq& binary_properties) +inline bool CDRMessage::readBinaryPropertySeq( + CDRMessage_t* msg, + BinaryPropertySeq& binary_properties) { assert(msg); uint32_t length = 0; - if(!CDRMessage::readUInt32(msg, &length)) + if (!CDRMessage::readUInt32(msg, &length)) + { return false; + } binary_properties.resize(length); bool returnedValue = true; - for(uint32_t i = 0; returnedValue && i < length; ++i) + for (uint32_t i = 0; returnedValue && i < length; ++i) + { returnedValue = CDRMessage::readBinaryProperty(msg, binary_properties.at(i)); + } return returnedValue; } -inline bool CDRMessage::addDataHolder(CDRMessage_t* msg, const DataHolder& data_holder) +inline bool CDRMessage::addDataHolder( + CDRMessage_t* msg, + const DataHolder& data_holder) { assert(msg); - if(!CDRMessage::addString(msg, data_holder.class_id())) + if (!CDRMessage::add_string(msg, data_holder.class_id())) + { return false; - if(!CDRMessage::addPropertySeq(msg, data_holder.properties())) + } + if (!CDRMessage::addPropertySeq(msg, data_holder.properties())) + { return false; - if(!CDRMessage::addBinaryPropertySeq(msg, data_holder.binary_properties(),true)) + } + if (!CDRMessage::addBinaryPropertySeq(msg, data_holder.binary_properties(), true)) + { return false; + } return true; } -inline bool CDRMessage::readDataHolder(CDRMessage_t* msg, DataHolder& data_holder) +inline bool CDRMessage::readDataHolder( + CDRMessage_t* msg, + DataHolder& data_holder) { assert(msg); - if(!CDRMessage::readString(msg, &data_holder.class_id())) + if (!CDRMessage::readString(msg, &data_holder.class_id())) + { return false; - if(!CDRMessage::readPropertySeq(msg, data_holder.properties())) + } + if (!CDRMessage::readPropertySeq(msg, data_holder.properties())) + { return false; - if(!CDRMessage::readBinaryPropertySeq(msg, data_holder.binary_properties())) + } + if (!CDRMessage::readBinaryPropertySeq(msg, data_holder.binary_properties())) + { return false; + } return true; } -inline bool CDRMessage::addDataHolderSeq(CDRMessage_t* msg, const DataHolderSeq& data_holders) +inline bool CDRMessage::addDataHolderSeq( + CDRMessage_t* msg, + const DataHolderSeq& data_holders) { assert(msg); bool returnedValue = false; - if(msg->pos + 4 <= msg->max_size) + if (msg->pos + 4 <= msg->max_size) { - if(CDRMessage::addUInt32(msg, static_cast(data_holders.size()))) + if (CDRMessage::addUInt32(msg, static_cast(data_holders.size()))) { returnedValue = true; - for(auto data_holder = data_holders.begin(); returnedValue && data_holder != data_holders.end(); ++data_holder) + for (auto data_holder = data_holders.begin(); returnedValue && data_holder != data_holders.end(); + ++data_holder) + { returnedValue = CDRMessage::addDataHolder(msg, *data_holder); + } } } return returnedValue; } -inline bool CDRMessage::readDataHolderSeq(CDRMessage_t* msg, DataHolderSeq& data_holders) +inline bool CDRMessage::readDataHolderSeq( + CDRMessage_t* msg, + DataHolderSeq& data_holders) { assert(msg); uint32_t length = 0; - if(!CDRMessage::readUInt32(msg, &length)) + if (!CDRMessage::readUInt32(msg, &length)) + { return false; + } data_holders.resize(length); bool returnedValue = true; - for(uint32_t i = 0; returnedValue && i < length; ++i) + for (uint32_t i = 0; returnedValue && i < length; ++i) + { returnedValue = CDRMessage::readDataHolder(msg, data_holders.at(i)); + } return returnedValue; } -inline bool CDRMessage::addMessageIdentity(CDRMessage_t* msg, const security::MessageIdentity& message_identity) +inline bool CDRMessage::addMessageIdentity( + CDRMessage_t* msg, + const security::MessageIdentity& message_identity) { assert(msg); - if(!CDRMessage::addData(msg, message_identity.source_guid().guidPrefix.value, GuidPrefix_t::size)) + if (!CDRMessage::addData(msg, message_identity.source_guid().guidPrefix.value, GuidPrefix_t::size)) + { return false; - if(!CDRMessage::addData(msg, message_identity.source_guid().entityId.value, EntityId_t::size)) + } + if (!CDRMessage::addData(msg, message_identity.source_guid().entityId.value, EntityId_t::size)) + { return false; - if(!CDRMessage::addInt64(msg, message_identity.sequence_number())) + } + if (!CDRMessage::addInt64(msg, message_identity.sequence_number())) + { return false; + } return true; } -inline bool CDRMessage::readMessageIdentity(CDRMessage_t* msg, security::MessageIdentity& message_identity) +inline bool CDRMessage::readMessageIdentity( + CDRMessage_t* msg, + security::MessageIdentity& message_identity) { assert(msg); - if(!CDRMessage::readData(msg, message_identity.source_guid().guidPrefix.value, GuidPrefix_t::size)) + if (!CDRMessage::readData(msg, message_identity.source_guid().guidPrefix.value, GuidPrefix_t::size)) + { return false; - if(!CDRMessage::readData(msg, message_identity.source_guid().entityId.value, EntityId_t::size)) + } + if (!CDRMessage::readData(msg, message_identity.source_guid().entityId.value, EntityId_t::size)) + { return false; - if(!CDRMessage::readInt64(msg, &message_identity.sequence_number())) + } + if (!CDRMessage::readInt64(msg, &message_identity.sequence_number())) + { return false; + } return true; } -inline bool CDRMessage::addParticipantGenericMessage(CDRMessage_t* msg, const security::ParticipantGenericMessage& message) +inline bool CDRMessage::addParticipantGenericMessage( + CDRMessage_t* msg, + const security::ParticipantGenericMessage& message) { assert(msg); - if(!CDRMessage::addMessageIdentity(msg, message.message_identity())) + if (!CDRMessage::addMessageIdentity(msg, message.message_identity())) + { return false; - if(!CDRMessage::addMessageIdentity(msg, message.related_message_identity())) + } + if (!CDRMessage::addMessageIdentity(msg, message.related_message_identity())) + { return false; - if(!CDRMessage::addData(msg, message.destination_participant_key().guidPrefix.value, GuidPrefix_t::size)) + } + if (!CDRMessage::addData(msg, message.destination_participant_key().guidPrefix.value, GuidPrefix_t::size)) + { return false; - if(!CDRMessage::addData(msg, message.destination_participant_key().entityId.value, EntityId_t::size)) + } + if (!CDRMessage::addData(msg, message.destination_participant_key().entityId.value, EntityId_t::size)) + { return false; - if(!CDRMessage::addData(msg, message.destination_endpoint_key().guidPrefix.value, GuidPrefix_t::size)) + } + if (!CDRMessage::addData(msg, message.destination_endpoint_key().guidPrefix.value, GuidPrefix_t::size)) + { return false; - if(!CDRMessage::addData(msg, message.destination_endpoint_key().entityId.value, EntityId_t::size)) + } + if (!CDRMessage::addData(msg, message.destination_endpoint_key().entityId.value, EntityId_t::size)) + { return false; - if(!CDRMessage::addData(msg, message.source_endpoint_key().guidPrefix.value, GuidPrefix_t::size)) + } + if (!CDRMessage::addData(msg, message.source_endpoint_key().guidPrefix.value, GuidPrefix_t::size)) + { return false; - if(!CDRMessage::addData(msg, message.source_endpoint_key().entityId.value, EntityId_t::size)) + } + if (!CDRMessage::addData(msg, message.source_endpoint_key().entityId.value, EntityId_t::size)) + { return false; - if(!CDRMessage::addString(msg, message.message_class_id())) + } + if (!CDRMessage::add_string(msg, message.message_class_id())) + { return false; - if(!CDRMessage::addDataHolderSeq(msg, message.message_data())) + } + if (!CDRMessage::addDataHolderSeq(msg, message.message_data())) + { return false; + } return true; } -inline bool CDRMessage::readParticipantGenericMessage(CDRMessage_t* msg, security::ParticipantGenericMessage& message) +inline bool CDRMessage::readParticipantGenericMessage( + CDRMessage_t* msg, + security::ParticipantGenericMessage& message) { assert(msg); - if(!CDRMessage::readMessageIdentity(msg, message.message_identity())) + if (!CDRMessage::readMessageIdentity(msg, message.message_identity())) + { return false; - if(!CDRMessage::readMessageIdentity(msg, message.related_message_identity())) + } + if (!CDRMessage::readMessageIdentity(msg, message.related_message_identity())) + { return false; - if(!CDRMessage::readData(msg, message.destination_participant_key().guidPrefix.value, GuidPrefix_t::size)) + } + if (!CDRMessage::readData(msg, message.destination_participant_key().guidPrefix.value, GuidPrefix_t::size)) + { return false; - if(!CDRMessage::readData(msg, message.destination_participant_key().entityId.value, EntityId_t::size)) + } + if (!CDRMessage::readData(msg, message.destination_participant_key().entityId.value, EntityId_t::size)) + { return false; - if(!CDRMessage::readData(msg, message.destination_endpoint_key().guidPrefix.value, GuidPrefix_t::size)) + } + if (!CDRMessage::readData(msg, message.destination_endpoint_key().guidPrefix.value, GuidPrefix_t::size)) + { return false; - if(!CDRMessage::readData(msg, message.destination_endpoint_key().entityId.value, EntityId_t::size)) + } + if (!CDRMessage::readData(msg, message.destination_endpoint_key().entityId.value, EntityId_t::size)) + { return false; - if(!CDRMessage::readData(msg, message.source_endpoint_key().guidPrefix.value, GuidPrefix_t::size)) + } + if (!CDRMessage::readData(msg, message.source_endpoint_key().guidPrefix.value, GuidPrefix_t::size)) + { return false; - if(!CDRMessage::readData(msg, message.source_endpoint_key().entityId.value, EntityId_t::size)) + } + if (!CDRMessage::readData(msg, message.source_endpoint_key().entityId.value, EntityId_t::size)) + { return false; - if(!CDRMessage::readString(msg, &message.message_class_id())) + } + if (!CDRMessage::readString(msg, &message.message_class_id())) + { return false; - if(!CDRMessage::readDataHolderSeq(msg, message.message_data())) + } + if (!CDRMessage::readDataHolderSeq(msg, message.message_data())) + { return false; + } return true; } diff --git a/include/fastrtps/utils/collections/ResourceLimitedVector.hpp b/include/fastrtps/utils/collections/ResourceLimitedVector.hpp index c12c1a72e0a..3ecca21adcc 100644 --- a/include/fastrtps/utils/collections/ResourceLimitedVector.hpp +++ b/include/fastrtps/utils/collections/ResourceLimitedVector.hpp @@ -104,7 +104,10 @@ class ResourceLimitedVector collection_.assign(other.collection_.begin(), other.collection_.end()); } - ResourceLimitedVector& operator = (const ResourceLimitedVector& other) + virtual ~ResourceLimitedVector () = default; + + ResourceLimitedVector& operator = ( + const ResourceLimitedVector& other) { clear(); for (const_reference item : other) @@ -126,7 +129,8 @@ class ResourceLimitedVector * * @return pointer to the new element, nullptr if resource limit is reached. */ - pointer push_back(const value_type& val) + pointer push_back( + const value_type& val) { return emplace_back(val); } @@ -141,7 +145,8 @@ class ResourceLimitedVector * * @return pointer to the new element, nullptr if resource limit is reached. */ - pointer push_back(value_type&& val) + pointer push_back( + value_type&& val) { return emplace_back(std::move(val)); } @@ -157,7 +162,8 @@ class ResourceLimitedVector * @return pointer to the new element, nullptr if resource limit is reached. */ template - pointer emplace_back(Args&& ... args) + pointer emplace_back( + Args&& ... args) { if (!ensure_capacity()) { @@ -166,7 +172,7 @@ class ResourceLimitedVector } // Construct new element at the end of the collection - collection_.emplace_back(args...); + collection_.emplace_back(args ...); // Return pointer to newly created element return &collection_.back(); @@ -182,7 +188,8 @@ class ResourceLimitedVector * * @return true if an element was removed, false otherwise. */ - bool remove(const value_type& val) + bool remove( + const value_type& val) { iterator it = std::find(collection_.begin(), collection_.end(), val); if (it != collection_.end()) @@ -209,7 +216,8 @@ class ResourceLimitedVector * @return true if an element was removed, false otherwise. */ template - bool remove_if(UnaryPredicate pred) + bool remove_if( + UnaryPredicate pred) { iterator it = std::find_if(collection_.begin(), collection_.end(), pred); if (it != collection_.end()) @@ -235,7 +243,9 @@ class ResourceLimitedVector * discarded. */ template - void assign(InputIterator first, InputIterator last) + void assign( + InputIterator first, + InputIterator last) { size_type n = std::distance(first, last); n = std::min(n, configuration_.maximum); @@ -252,7 +262,9 @@ class ResourceLimitedVector * @param val Value to fill the container with. * Each of the n elements in the container will be initialized to a copy of this value. */ - void assign(size_type n, const value_type& val) + void assign( + size_type n, + const value_type& val) { n = std::min(n, configuration_.maximum); collection_.assign(n, val); @@ -269,7 +281,8 @@ class ResourceLimitedVector * If the size of this list is greater than the maximum number of elements allowed on the * resource limits configuration, the elements exceeding that maximum will be silently discarded. */ - void assign(std::initializer_list il) + void assign( + std::initializer_list il) { size_type n = std::min(il.size(), configuration_.maximum); collection_.assign(il.begin(), il.begin() + n); @@ -280,41 +293,153 @@ class ResourceLimitedVector * Please refer to https://en.cppreference.com/w/cpp/container/vector */ ///@{ - reference at(size_type pos) { return collection_.at(pos); } - const_reference at(size_type pos) const { return collection_.at(pos); } - reference operator[](size_type pos) { return collection_[pos]; } - const_reference operator[](size_type pos) const { return collection_[pos]; } - - reference front() { return collection_.front(); } - const_reference front() const { return collection_.front(); } - reference back() { return collection_.back(); } - const_reference back() const { return collection_.back(); } - - iterator begin() noexcept { return collection_.begin(); } - const_iterator begin() const noexcept { return collection_.begin(); } - const_iterator cbegin() const noexcept { return collection_.cbegin(); } - - iterator end() noexcept { return collection_.end(); } - const_iterator end() const noexcept { return collection_.end(); } - const_iterator cend() const noexcept { return collection_.cend(); } - - reverse_iterator rbegin() noexcept { return collection_.rbegin(); } - const_reverse_iterator rbegin() const noexcept { return collection_.rbegin(); } - const_reverse_iterator crbegin() const noexcept { return collection_.crbegin(); } - - reverse_iterator rend() noexcept { return collection_.rend(); } - const_reverse_iterator rend() const noexcept { return collection_.rend(); } - const_reverse_iterator crend() const noexcept { return collection_.crend(); } - - bool empty() const noexcept { return collection_.empty(); } - size_type size() const noexcept { return collection_.size(); } - size_type capacity() const noexcept { return collection_.capacity(); } - size_type max_size() const noexcept { return std::min(configuration_.maximum, collection_.max_size()); } - - void clear() { collection_.clear(); } - iterator erase(const_iterator pos) { return collection_.erase(pos); } - iterator erase(const_iterator first, const_iterator last) { return collection_.erase(first, last); } - void pop_back() { collection_.pop_back(); } + reference at( + size_type pos) + { + return collection_.at(pos); + } + + const_reference at( + size_type pos) const + { + return collection_.at(pos); + } + + reference operator []( + size_type pos) + { + return collection_[pos]; + } + + const_reference operator []( + size_type pos) const + { + return collection_[pos]; + } + + reference front() + { + return collection_.front(); + } + + const_reference front() const + { + return collection_.front(); + } + + reference back() + { + return collection_.back(); + } + + const_reference back() const + { + return collection_.back(); + } + + iterator begin() noexcept + { + return collection_.begin(); + } + + const_iterator begin() const noexcept + { + return collection_.begin(); + } + + const_iterator cbegin() const noexcept + { + return collection_.cbegin(); + } + + iterator end() noexcept + { + return collection_.end(); + } + + const_iterator end() const noexcept + { + return collection_.end(); + } + + const_iterator cend() const noexcept + { + return collection_.cend(); + } + + reverse_iterator rbegin() noexcept + { + return collection_.rbegin(); + } + + const_reverse_iterator rbegin() const noexcept + { + return collection_.rbegin(); + } + + const_reverse_iterator crbegin() const noexcept + { + return collection_.crbegin(); + } + + reverse_iterator rend() noexcept + { + return collection_.rend(); + } + + const_reverse_iterator rend() const noexcept + { + return collection_.rend(); + } + + const_reverse_iterator crend() const noexcept + { + return collection_.crend(); + } + + bool empty() const noexcept + { + return collection_.empty(); + } + + size_type size() const noexcept + { + return collection_.size(); + } + + size_type capacity() const noexcept + { + return collection_.capacity(); + } + + size_type max_size() const noexcept + { + return std::min(configuration_.maximum, collection_.max_size()); + } + + void clear() + { + collection_.clear(); + } + + iterator erase( + const_iterator pos) + { + return collection_.erase(pos); + } + + iterator erase( + const_iterator first, + const_iterator last) + { + return collection_.erase(first, last); + } + + void pop_back() + { + collection_.pop_back(); + } + ///@} /** @@ -326,7 +451,8 @@ class ResourceLimitedVector */ operator const collection_type& () const noexcept { return collection_; } -private: +protected: + configuration_type configuration_; collection_type collection_; @@ -371,7 +497,8 @@ class ResourceLimitedVector * @param it Iterator pointing to the item to be removed. */ template - typename std::enable_if::type do_remove(iterator it) + typename std::enable_if::type do_remove( + iterator it) { // Copy last element into the element being removed if (it != --collection_.end()) @@ -394,10 +521,12 @@ class ResourceLimitedVector * @param it Iterator pointing to the item to be removed. */ template - typename std::enable_if::type do_remove(iterator it) + typename std::enable_if::type do_remove( + iterator it) { collection_.erase(it); } + }; } // namespace fastrtps diff --git a/include/fastrtps/xmlparser/XMLParserCommon.h b/include/fastrtps/xmlparser/XMLParserCommon.h index 1cc9999b2e6..917458f78c5 100644 --- a/include/fastrtps/xmlparser/XMLParserCommon.h +++ b/include/fastrtps/xmlparser/XMLParserCommon.h @@ -117,6 +117,9 @@ extern const char* TOTAL_WRITERS; extern const char* SEND_BUFFERS; extern const char* PREALLOCATED_NUMBER; extern const char* DYNAMIC_LC; +extern const char* MAX_PROPERTIES; +extern const char* MAX_USER_DATA; +extern const char* MAX_PARTITIONS; /// Publisher-subscriber attributes extern const char* TOPIC; diff --git a/resources/xsd/fastRTPS_profiles.xsd b/resources/xsd/fastRTPS_profiles.xsd index 828bb8dde41..2bc2ad23a3a 100644 --- a/resources/xsd/fastRTPS_profiles.xsd +++ b/resources/xsd/fastRTPS_profiles.xsd @@ -397,6 +397,9 @@ + + + diff --git a/src/cpp/dds/core/policy/ParameterList.cpp b/src/cpp/dds/core/policy/ParameterList.cpp index 4b2f538f4d8..7cd8f19822a 100644 --- a/src/cpp/dds/core/policy/ParameterList.cpp +++ b/src/cpp/dds/core/policy/ParameterList.cpp @@ -26,110 +26,120 @@ namespace eprosima { namespace fastdds { namespace dds { -using namespace fastrtps::rtps; -#define IF_VALID_CALL() { \ - if(valid) \ - { \ - qos_size += plength; \ - if(!processor(&p)) \ - return false; \ - } \ - else \ - { \ - return false; \ - } \ - break; \ - } - -bool ParameterList::writeEncapsulationToCDRMsg(fastrtps::rtps::CDRMessage_t* msg) +bool ParameterList::writeEncapsulationToCDRMsg( + fastrtps::rtps::CDRMessage_t* msg) { - bool valid = CDRMessage::addOctet(msg, 0); - if (msg->msg_endian == BIGEND) + bool valid = fastrtps::rtps::CDRMessage::addOctet(msg, 0); + if (msg->msg_endian == fastrtps::rtps::Endianness_t::BIGEND) { - valid &= CDRMessage::addOctet(msg, PL_CDR_BE); + valid &= fastrtps::rtps::CDRMessage::addOctet(msg, PL_CDR_BE); } else { - valid &= CDRMessage::addOctet(msg, PL_CDR_LE); + valid &= fastrtps::rtps::CDRMessage::addOctet(msg, PL_CDR_LE); } - valid &= CDRMessage::addUInt16(msg, 0); + valid &= fastrtps::rtps::CDRMessage::addUInt16(msg, 0); return valid; } -bool ParameterList::updateCacheChangeFromInlineQos(CacheChange_t& change, CDRMessage_t* msg, uint32_t& qos_size) +bool ParameterList::updateCacheChangeFromInlineQos( + fastrtps::rtps::CacheChange_t& change, + fastrtps::rtps::CDRMessage_t* msg, + uint32_t& qos_size) { - auto parameter_process = [&](const Parameter_t* p) - { - switch (p->Pid) - { - case PID_KEY_HASH: + auto parameter_process = [&](fastrtps::rtps::CDRMessage_t* msg, const ParameterId_t pid, uint16_t plength) { - const ParameterKey_t* p_key = dynamic_cast(p); - assert(p_key != nullptr); - change.instanceHandle = p_key->key; - break; - } + switch (pid) + { + case PID_KEY_HASH: + { + ParameterKey_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } - case PID_RELATED_SAMPLE_IDENTITY: - { - const ParameterSampleIdentity_t* p_id = dynamic_cast(p); - assert(p_id != nullptr); - change.write_params.sample_identity(p_id->sample_id); - break; - } + change.instanceHandle = p.key; + break; + } - case PID_STATUS_INFO: - { - const ParameterStatusInfo_t* p_status = dynamic_cast(p); - assert(p_status != nullptr); - if (p_status->status == 1) - { - change.kind = NOT_ALIVE_DISPOSED; - } - else if (p_status->status == 2) - { - change.kind = NOT_ALIVE_UNREGISTERED; - } - else if (p_status->status == 3) - { - change.kind = NOT_ALIVE_DISPOSED_UNREGISTERED; - } - break; - } + case PID_RELATED_SAMPLE_IDENTITY: + { + if (plength >= 24) + { + ParameterSampleIdentity_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } - default: - break; - } + change.write_params.sample_identity(p.sample_id); + } + break; + } - return true; - }; + case PID_STATUS_INFO: + { + ParameterStatusInfo_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + if (p.status == 1) + { + change.kind = fastrtps::rtps::ChangeKind_t::NOT_ALIVE_DISPOSED; + } + else if (p.status == 2) + { + change.kind = fastrtps::rtps::ChangeKind_t::NOT_ALIVE_UNREGISTERED; + } + else if (p.status == 3) + { + change.kind = fastrtps::rtps::ChangeKind_t::NOT_ALIVE_DISPOSED_UNREGISTERED; + } + break; + } - return readParameterListfromCDRMsg(*msg, parameter_process, false, qos_size); + default: + break; + } + + return true; + }; + try + { + return readParameterListfromCDRMsg(*msg, parameter_process, false, qos_size); + } + catch (std::bad_alloc& ba) + { + std::cerr << "bad_alloc caught: " << ba.what() << '\n'; + return false; + } } -bool ParameterList::readParameterListfromCDRMsg(CDRMessage_t& msg, std::function processor, - bool use_encapsulation, uint32_t& qos_size) +bool ParameterList::readParameterListfromCDRMsg( + fastrtps::rtps::CDRMessage_t& msg, + std::function processor, + bool use_encapsulation, + uint32_t& qos_size) { - bool is_sentinel = false; - bool valid = true; - ParameterId_t pid; - uint16_t plength; qos_size = 0; if (use_encapsulation) { // Read encapsulation msg.pos += 1; - octet encapsulation = 0; - CDRMessage::readOctet(&msg, &encapsulation); + fastrtps::rtps::octet encapsulation = 0; + fastrtps::rtps::CDRMessage::readOctet(&msg, &encapsulation); if (encapsulation == PL_CDR_BE) { - msg.msg_endian = BIGEND; + msg.msg_endian = fastrtps::rtps::Endianness_t::BIGEND; } else if (encapsulation == PL_CDR_LE) { - msg.msg_endian = LITTLEEND; + msg.msg_endian = fastrtps::rtps::Endianness_t::LITTLEEND; } else { @@ -140,697 +150,76 @@ bool ParameterList::readParameterListfromCDRMsg(CDRMessage_t& msg, std::function } uint32_t original_pos = msg.pos; + bool is_sentinel = false; while (!is_sentinel) { - // Align to 4 byte boundary - qos_size = (qos_size + 3) & ~3; msg.pos = original_pos + qos_size; - valid = true; - valid &= CDRMessage::readUInt16(&msg, (uint16_t*)&pid); - valid &= CDRMessage::readUInt16(&msg, &plength); - qos_size += 4; + ParameterId_t pid; + uint16_t plength = 0; + bool valid = true; + valid &= fastrtps::rtps::CDRMessage::readUInt16(&msg, (uint16_t*)&pid); + valid &= fastrtps::rtps::CDRMessage::readUInt16(&msg, &plength); + qos_size += (4 + plength); + + // Align to 4 byte boundary and prepare for next iteration + qos_size = (qos_size + 3) & ~3; + if (!valid || ((msg.pos + plength) > msg.length)) { return false; } - try + if (pid == PID_SENTINEL) { - switch (pid) - { - case PID_UNICAST_LOCATOR: - case PID_MULTICAST_LOCATOR: - case PID_DEFAULT_UNICAST_LOCATOR: - case PID_DEFAULT_MULTICAST_LOCATOR: - case PID_METATRAFFIC_UNICAST_LOCATOR: - case PID_METATRAFFIC_MULTICAST_LOCATOR: - { - ParameterLocator_t p(pid, plength); - valid &= CDRMessage::readLocator(&msg, &p.locator); - valid &= (plength == PARAMETER_LOCATOR_LENGTH); - IF_VALID_CALL() - } - case PID_DEFAULT_UNICAST_PORT: - case PID_METATRAFFIC_UNICAST_PORT: - case PID_METATRAFFIC_MULTICAST_PORT: - { - ParameterPort_t p(pid, plength); - valid &= CDRMessage::readUInt32(&msg, &p.port); - valid &= (plength == PARAMETER_LOCATOR_LENGTH); - IF_VALID_CALL() - } - case PID_PROTOCOL_VERSION: - { - ParameterProtocolVersion_t p(pid, plength); - valid &= CDRMessage::readOctet(&msg, &p.protocolVersion.m_major); - valid &= CDRMessage::readOctet(&msg, &p.protocolVersion.m_minor); - valid &= (plength == PARAMETER_PROTOCOL_LENGTH); - IF_VALID_CALL() - } - case PID_EXPECTS_INLINE_QOS: - { - if (plength != PARAMETER_BOOL_LENGTH) - { - return false; - } - ParameterBool_t p(PID_EXPECTS_INLINE_QOS, plength); - valid &= CDRMessage::readOctet(&msg, (octet*)&p.value); - IF_VALID_CALL() - } - case PID_VENDORID: - { - ParameterVendorId_t p(pid, plength); - valid &= CDRMessage::readOctet(&msg, &p.vendorId[0]); - valid &= CDRMessage::readOctet(&msg, &p.vendorId[1]); - valid &= (plength == PARAMETER_VENDOR_LENGTH); - IF_VALID_CALL() - } - case PID_MULTICAST_IPADDRESS: - case PID_DEFAULT_UNICAST_IPADDRESS: - case PID_METATRAFFIC_UNICAST_IPADDRESS: - case PID_METATRAFFIC_MULTICAST_IPADDRESS: - { - if (plength != PARAMETER_IP4_LENGTH) - { - return false; - } - ParameterIP4Address_t p(pid, plength); - valid &= CDRMessage::readData(&msg, p.address, 4); - IF_VALID_CALL() - } - case PID_PARTICIPANT_GUID: - case PID_GROUP_GUID: - case PID_ENDPOINT_GUID: - case PID_PERSISTENCE_GUID: - { - if (plength != PARAMETER_GUID_LENGTH) - { - return false; - } - ParameterGuid_t p(pid, plength); - valid &= CDRMessage::readData(&msg, p.guid.guidPrefix.value, 12); - valid &= CDRMessage::readData(&msg, p.guid.entityId.value, 4); - IF_VALID_CALL() - } - case PID_TOPIC_NAME: - case PID_TYPE_NAME: - case PID_ENTITY_NAME: - { - if (plength > 256) - { - return false; - } - ParameterString_t p(pid, plength); - fastrtps::string_255 aux; - valid &= CDRMessage::readString(&msg, &aux); - p.setName(aux.c_str()); - // cout << "READ: "<< p.m_string< pair; - for (uint32_t n_prop = 0; n_prop < num_properties; ++n_prop) - { - pos_ref = msg.pos; - pair.first.clear(); - valid &= CDRMessage::readString(&msg, &pair.first); - if (!valid) - { - return false; - } - length_diff += msg.pos - pos_ref; - pos_ref = msg.pos; - pair.second.clear(); - valid &= CDRMessage::readString(&msg, &pair.second); - if (!valid) - { - return false; - } - length_diff += msg.pos - pos_ref; - p.properties.push_back(pair); - } - qos_size += plength; - if (plength == length_diff) - { - if(!processor(&p)) return false; - } - break; - } - case PID_STATUS_INFO: - { - if (plength != PARAMETER_STATUS_INFO_LENGTH) - { - return false; - } - octet status = msg.buffer[msg.pos + 3]; - ParameterStatusInfo_t p(pid, plength, status); - qos_size += plength; - if(!processor(&p)) return false; - break; - } - case PID_KEY_HASH: - { - if (plength != 16) - { - return false; - } - ParameterKey_t p(PID_KEY_HASH, 16); - valid &= CDRMessage::readData(&msg, p.key.value, 16); - IF_VALID_CALL() - } - case PID_SENTINEL: - { - is_sentinel = true; - break; - } - case PID_DURABILITY: - { - if (plength != PARAMETER_KIND_LENGTH) - { - return false; - } - DurabilityQosPolicy p; - valid &= CDRMessage::readOctet(&msg, (octet*)&p.kind); - IF_VALID_CALL() - } - case PID_DEADLINE: - { - if (plength != PARAMETER_TIME_LENGTH) - { - return false; - } - DeadlineQosPolicy p; - valid &= CDRMessage::readInt32(&msg, &p.period.seconds); - uint32_t frac(0); - valid &= CDRMessage::readUInt32(&msg, &frac); - p.period.fraction(frac); - IF_VALID_CALL() - } - case PID_LATENCY_BUDGET: - { - if (plength != PARAMETER_TIME_LENGTH) - { - return false; - } - LatencyBudgetQosPolicy p; - valid &= CDRMessage::readInt32(&msg, &p.duration.seconds); - uint32_t frac(0); - valid &= CDRMessage::readUInt32(&msg, &frac); - p.duration.fraction(frac); - IF_VALID_CALL() - } - case PID_LIVELINESS: - { - if (plength != PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH) - { - return false; - } - LivelinessQosPolicy p; - valid &= CDRMessage::readOctet(&msg, (octet*)&p.kind); - msg.pos += 3; - valid &= CDRMessage::readInt32(&msg, &p.lease_duration.seconds); - uint32_t frac(0); - valid &= CDRMessage::readUInt32(&msg, &frac); - p.lease_duration.fraction(frac); - IF_VALID_CALL() - } - case PID_OWNERSHIP: - { - if (plength != PARAMETER_KIND_LENGTH) - { - return false; - } - OwnershipQosPolicy p; - valid &= CDRMessage::readOctet(&msg, (octet*)&p.kind); - IF_VALID_CALL() - } - case PID_RELIABILITY: - { - if (plength != PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH) - { - return false; - } - ReliabilityQosPolicy p; - valid &= CDRMessage::readOctet(&msg, (octet*)&p.kind); - msg.pos += 3; - valid &= CDRMessage::readInt32(&msg, &p.max_blocking_time.seconds); - uint32_t frac(0); - valid &= CDRMessage::readUInt32(&msg, &frac); - p.max_blocking_time.fraction(frac); - IF_VALID_CALL() - } - case PID_DESTINATION_ORDER: - { - if (plength != PARAMETER_KIND_LENGTH) - { - return false; - } - DestinationOrderQosPolicy p; - valid &= CDRMessage::readOctet(&msg, (octet*)&p.kind); - IF_VALID_CALL() - } - case PID_USER_DATA: - { - uint32_t length_diff = 0; - uint32_t pos_ref = 0; - UserDataQosPolicy p; - p.length = plength; - uint32_t vec_size = 0; - valid &= CDRMessage::readUInt32(&msg, &vec_size); - if (!valid || msg.pos + vec_size > msg.length) - { - return false; - } - length_diff += 4; - p.data_vec_.resize(vec_size); - pos_ref = msg.pos; - valid &= CDRMessage::readData(&msg, p.data_vec_.data(), vec_size); - if (valid) - { - msg.pos += (plength - 4 - vec_size); - length_diff += msg.pos - pos_ref; - if (plength != length_diff) - { - return false; - } - qos_size += plength; - if(!processor(&p)) return false; - } - else - { - return false; - } - break; - } - case PID_TIME_BASED_FILTER: - { - if (plength != PARAMETER_TIME_LENGTH) - { - return false; - } - TimeBasedFilterQosPolicy p; - valid &= CDRMessage::readInt32(&msg, &p.minimum_separation.seconds); - uint32_t frac(0); - valid &= CDRMessage::readUInt32(&msg, &frac); - p.minimum_separation.fraction(frac); - IF_VALID_CALL() - } - case PID_PRESENTATION: - { - if (plength != PARAMETER_PRESENTATION_LENGTH) - { - return false; - } - PresentationQosPolicy p; - valid &= CDRMessage::readOctet(&msg, (octet*)&p.access_scope); - msg.pos += 3; - valid &= CDRMessage::readOctet(&msg, (octet*)&p.coherent_access); - valid &= CDRMessage::readOctet(&msg, (octet*)&p.ordered_access); - IF_VALID_CALL() - } - case PID_PARTITION: - { - uint32_t pos_ref = msg.pos; - PartitionQosPolicy p; - p.length = plength; - uint32_t namessize = 0; - valid &= CDRMessage::readUInt32(&msg, &namessize); - for (uint32_t i = 1; i <= namessize; ++i) - { - std::string auxstr; - valid &= CDRMessage::readString(&msg, &auxstr); - - if (plength < msg.pos - pos_ref) - { - return false; - } - - p.names_.push_back(auxstr); - } - - IF_VALID_CALL() - } - case PID_TOPIC_DATA: - { - uint32_t length_diff = 0; - uint32_t pos_ref = 0; - TopicDataQosPolicy p; - p.length = plength; - pos_ref = msg.pos; - valid &= CDRMessage::readOctetVector(&msg, &p.value); - length_diff += msg.pos - pos_ref; - if (plength != length_diff) - { - return false; - } - IF_VALID_CALL() - } - case PID_GROUP_DATA: - { - uint32_t length_diff = 0; - uint32_t pos_ref = 0; - GroupDataQosPolicy p; - p.length = plength; - pos_ref = msg.pos; - valid &= CDRMessage::readOctetVector(&msg, &p.value); - length_diff += msg.pos - pos_ref; - if (plength != length_diff) - { - return false; - } - IF_VALID_CALL() - } - case PID_HISTORY: - { - if (plength != PARAMETER_KIND_LENGTH + 4) - { - return false; - } - HistoryQosPolicy p; - valid &= CDRMessage::readOctet(&msg, (octet*)&p.kind); - msg.pos += 3; - valid &= CDRMessage::readInt32(&msg, &p.depth); - IF_VALID_CALL() - } - case PID_DURABILITY_SERVICE: - { - if (plength != PARAMETER_TIME_LENGTH + PARAMETER_KIND_LENGTH + 16) - { - return false; - } - DurabilityServiceQosPolicy p; - valid &= CDRMessage::readInt32(&msg, &p.service_cleanup_delay.seconds); - uint32_t frac(0); - valid &= CDRMessage::readUInt32(&msg, &frac); - p.service_cleanup_delay.fraction(frac); - valid &= CDRMessage::readOctet(&msg, (octet*)&p.history_kind); - msg.pos += 3; - valid &= CDRMessage::readInt32(&msg, &p.history_depth); - valid &= CDRMessage::readInt32(&msg, &p.max_samples); - valid &= CDRMessage::readInt32(&msg, &p.max_instances); - valid &= CDRMessage::readInt32(&msg, &p.max_samples_per_instance); - IF_VALID_CALL() - } - case PID_LIFESPAN: - { - if (plength != PARAMETER_TIME_LENGTH) - { - return false; - } - LifespanQosPolicy p; - valid &= CDRMessage::readInt32(&msg, &p.duration.seconds); - uint32_t frac(0); - valid &= CDRMessage::readUInt32(&msg, &frac); - p.duration.fraction(frac); - IF_VALID_CALL() - } - case PID_OWNERSHIP_STRENGTH: - { - if (plength != 4) - { - return false; - } - OwnershipStrengthQosPolicy p; - valid &= CDRMessage::readUInt32(&msg, &p.value); - IF_VALID_CALL() - } - case PID_RESOURCE_LIMITS: - { - if (plength != 12) - { - return false; - } - ResourceLimitsQosPolicy p; - valid &= CDRMessage::readInt32(&msg, &p.max_samples); - valid &= CDRMessage::readInt32(&msg, &p.max_instances); - valid &= CDRMessage::readInt32(&msg, &p.max_samples_per_instance); - IF_VALID_CALL() - } - case PID_TRANSPORT_PRIORITY: - { - if (plength != 4) - { - return false; - } - TransportPriorityQosPolicy p; - valid &= CDRMessage::readUInt32(&msg, &p.value); - IF_VALID_CALL() - } - case PID_PARTICIPANT_MANUAL_LIVELINESS_COUNT: - { - if (plength != 4) - { - return false; - } - ParameterCount_t p(PID_PARTICIPANT_MANUAL_LIVELINESS_COUNT, plength); - valid &= CDRMessage::readUInt32(&msg, &p.count); - IF_VALID_CALL() - } - case PID_PARTICIPANT_BUILTIN_ENDPOINTS: - case PID_BUILTIN_ENDPOINT_SET: - { - if (plength != 4) - { - return false; - } - ParameterBuiltinEndpointSet_t p(pid, plength); - valid &= CDRMessage::readUInt32(&msg, &p.endpointSet); - IF_VALID_CALL() - } - case PID_PARTICIPANT_LEASE_DURATION: - { - if (plength != PARAMETER_TIME_LENGTH) - { - return false; - } - ParameterTime_t p(PID_PARTICIPANT_LEASE_DURATION, plength); - int32_t sec(0); - valid &= CDRMessage::readInt32(&msg, &sec); - p.time.seconds(sec); - uint32_t frac(0); - valid &= CDRMessage::readUInt32(&msg, &frac); - p.time.fraction(frac); - IF_VALID_CALL() - } - case PID_CONTENT_FILTER_PROPERTY: - { - qos_size += plength; - break; - } - case PID_PARTICIPANT_ENTITYID: - case PID_GROUP_ENTITYID: - { - if (plength != 4) - { - return false; - } - ParameterEntityId_t p(pid, plength); - valid &= CDRMessage::readEntityId(&msg, &p.entityId); - IF_VALID_CALL() - } - case PID_TYPE_MAX_SIZE_SERIALIZED: - { - if (plength != 4) - { - return false; - } - ParameterCount_t p(pid, plength); - valid &= CDRMessage::readUInt32(&msg, &p.count); - IF_VALID_CALL() - } - case PID_RELATED_SAMPLE_IDENTITY: - { - if (plength == 24) - { - ParameterSampleIdentity_t p(pid, plength); - valid &= CDRMessage::readData(&msg, p.sample_id.writer_guid().guidPrefix.value, GuidPrefix_t::size); - valid &= CDRMessage::readData(&msg, p.sample_id.writer_guid().entityId.value, EntityId_t::size); - valid &= CDRMessage::readInt32(&msg, &p.sample_id.sequence_number().high); - valid &= CDRMessage::readUInt32(&msg, &p.sample_id.sequence_number().low); - IF_VALID_CALL() - } - else if (plength > 24) - { - return false; - } - else - { - qos_size += plength; - break; - } - } - - case PID_DATA_REPRESENTATION: - { - DataRepresentationQosPolicy p; - int16_t temp(0); - uint32_t size(0); - valid &= CDRMessage::readUInt32(&msg, &size); - for (uint32_t i = 0; i < size; ++i) - { - valid &= CDRMessage::readInt16(&msg, &temp); - p.m_value.push_back(static_cast(temp)); - - } - if (size % 2 == 1) // Odd, we must read the alignment - { - valid &= CDRMessage::readInt16(&msg, &temp); - } - IF_VALID_CALL() - } - case PID_TYPE_CONSISTENCY_ENFORCEMENT: - { - if (plength < 2) - { - return false; - } - - uint16_t uKind(0); - octet temp(0); - TypeConsistencyEnforcementQosPolicy p; - p.m_ignore_sequence_bounds = false; - p.m_ignore_string_bounds = false; - p.m_ignore_member_names = false; - p.m_prevent_type_widening = false; - p.m_force_type_validation = false; - - valid &= CDRMessage::readUInt16(&msg, &uKind); - p.m_kind = static_cast(uKind); - - if (valid && plength >= 3) - { - valid &= CDRMessage::readOctet(&msg, &temp); - p.m_ignore_sequence_bounds = temp == 0 ? false : true; - } - - if (valid && plength >= 4) - { - valid &= CDRMessage::readOctet(&msg, &temp); - p.m_ignore_string_bounds = temp == 0 ? false : true; - } - - if (valid && plength >= 5) - { - valid &= CDRMessage::readOctet(&msg, &temp); - p.m_ignore_member_names = temp == 0 ? false : true; - } - - if (valid && plength >= 6) - { - valid &= CDRMessage::readOctet(&msg, &temp); - p.m_prevent_type_widening = temp == 0 ? false : true; - } - - if (valid && plength >= 7) - { - valid &= CDRMessage::readOctet(&msg, &temp); - p.m_force_type_validation = temp == 0 ? false : true; - } - - IF_VALID_CALL() - } - case PID_TYPE_IDV1: - { - TypeIdV1 p; - valid &= p.readFromCDRMessage(&msg, plength); - IF_VALID_CALL() - } - case PID_TYPE_OBJECTV1: - { - TypeObjectV1 p; - valid &= p.readFromCDRMessage(&msg, plength); - IF_VALID_CALL() - } - case PID_TYPE_INFORMATION: - { - xtypes::TypeInformation p; - valid &= p.readFromCDRMessage(&msg, plength); - IF_VALID_CALL() - } - -#if HAVE_SECURITY - case PID_IDENTITY_TOKEN: - case PID_PERMISSIONS_TOKEN: - { - ParameterToken_t p(pid, plength); - valid &= CDRMessage::readDataHolder(&msg, p.token); - IF_VALID_CALL() - } - - case PID_PARTICIPANT_SECURITY_INFO: - { - if (plength != PARAMETER_PARTICIPANT_SECURITY_INFO_LENGTH) - { - return false; - } - ParameterParticipantSecurityInfo_t p(pid, plength); - valid &= CDRMessage::readUInt32(&msg, &p.security_attributes); - valid &= CDRMessage::readUInt32(&msg, &p.plugin_security_attributes); - IF_VALID_CALL() - } - - case PID_ENDPOINT_SECURITY_INFO: - { - if (plength != PARAMETER_ENDPOINT_SECURITY_INFO_LENGTH) - { - return false; - } - ParameterEndpointSecurityInfo_t p(pid, plength); - valid &= CDRMessage::readUInt32(&msg, &p.security_attributes); - valid &= CDRMessage::readUInt32(&msg, &p.plugin_security_attributes); - IF_VALID_CALL() - } -#endif - case PID_DISABLE_POSITIVE_ACKS: - { - if (plength != PARAMETER_BOOL_LENGTH) - { - return false; - } - octet value(0); - octet tmp(0); - valid &= CDRMessage::readOctet(&msg, &value); - valid &= CDRMessage::readOctet(&msg, &tmp); - valid &= CDRMessage::readOctet(&msg, &tmp); - valid &= CDRMessage::readOctet(&msg, &tmp); - - DisablePositiveACKsQosPolicy p; - p.enabled = (value == 0) ? false : true; - IF_VALID_CALL() - } - - case PID_PAD: - default: - { - qos_size += plength; - break; - } - } + is_sentinel = true; } - catch (std::bad_alloc& ba) + else if (!processor(&msg, pid, plength)) { - std::cerr << "bad_alloc caught: " << ba.what() << '\n'; return false; } } return true; } -bool ParameterList::readInstanceHandleFromCDRMsg(CacheChange_t* change, const uint16_t search_pid) +bool ParameterList::read_guid_from_cdr_msg( + fastrtps::rtps::CDRMessage_t& msg, + uint16_t search_pid, + fastrtps::rtps::GUID_t& guid) +{ + bool valid = false; + uint16_t pid; + uint16_t plength; + while (msg.pos < msg.length) + { + valid = true; + valid &= fastrtps::rtps::CDRMessage::readUInt16(&msg, &pid); + valid &= fastrtps::rtps::CDRMessage::readUInt16(&msg, &plength); + if ((pid == PID_SENTINEL) || !valid) + { + break; + } + if (pid == PID_KEY_HASH) + { + valid &= fastrtps::rtps::CDRMessage::readData(&msg, guid.guidPrefix.value, + fastrtps::rtps::GuidPrefix_t::size); + valid &= fastrtps::rtps::CDRMessage::readData(&msg, guid.entityId.value, fastrtps::rtps::EntityId_t::size); + return valid; + } + if (pid == search_pid) + { + valid &= fastrtps::rtps::CDRMessage::readData(&msg, guid.guidPrefix.value, + fastrtps::rtps::GuidPrefix_t::size); + valid &= fastrtps::rtps::CDRMessage::readData(&msg, guid.entityId.value, fastrtps::rtps::EntityId_t::size); + return valid; + } + msg.pos += (plength + 3) & ~3; + } + return false; +} + +bool ParameterList::readInstanceHandleFromCDRMsg( + fastrtps::rtps::CacheChange_t* change, + const uint16_t search_pid) { assert(change != nullptr); @@ -841,19 +230,19 @@ bool ParameterList::readInstanceHandleFromCDRMsg(CacheChange_t* change, const ui } // Use a temporary wraping message - CDRMessage_t msg(change->serializedPayload); + fastrtps::rtps::CDRMessage_t msg(change->serializedPayload); // Read encapsulation msg.pos += 1; - octet encapsulation = 0; - CDRMessage::readOctet(&msg, &encapsulation); + fastrtps::rtps::octet encapsulation = 0; + fastrtps::rtps::CDRMessage::readOctet(&msg, &encapsulation); if (encapsulation == PL_CDR_BE) { - msg.msg_endian = BIGEND; + msg.msg_endian = fastrtps::rtps::Endianness_t::BIGEND; } else if (encapsulation == PL_CDR_LE) { - msg.msg_endian = LITTLEEND; + msg.msg_endian = fastrtps::rtps::Endianness_t::LITTLEEND; } else { @@ -871,23 +260,23 @@ bool ParameterList::readInstanceHandleFromCDRMsg(CacheChange_t* change, const ui while (msg.pos < msg.length) { valid = true; - valid &= CDRMessage::readUInt16(&msg, (uint16_t*)&pid); - valid &= CDRMessage::readUInt16(&msg, &plength); + valid &= fastrtps::rtps::CDRMessage::readUInt16(&msg, (uint16_t*)&pid); + valid &= fastrtps::rtps::CDRMessage::readUInt16(&msg, &plength); if ((pid == PID_SENTINEL) || !valid) { break; } if (pid == PID_KEY_HASH) { - valid &= CDRMessage::readData(&msg, change->instanceHandle.value, 16); + valid &= fastrtps::rtps::CDRMessage::readData(&msg, change->instanceHandle.value, 16); return valid; } if (pid == search_pid) { - valid &= CDRMessage::readData(&msg, change->instanceHandle.value, 16); + valid &= fastrtps::rtps::CDRMessage::readData(&msg, change->instanceHandle.value, 16); return valid; } - msg.pos += plength; + msg.pos += (plength + 3) & ~3; } return false; } diff --git a/src/cpp/dds/core/policy/ParameterTypes.cpp b/src/cpp/dds/core/policy/ParameterTypes.cpp index b3eeff16cc5..97634f25981 100644 --- a/src/cpp/dds/core/policy/ParameterTypes.cpp +++ b/src/cpp/dds/core/policy/ParameterTypes.cpp @@ -31,11 +31,23 @@ bool ParameterLocator_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_LOCATOR_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_LOCATOR_LENGTH); valid &= CDRMessage::addLocator(msg, &this->locator); return valid; } +bool ParameterLocator_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_LOCATOR_LENGTH) + { + return false; + } + length = size; + return CDRMessage::readLocator(msg, &locator); +} + //PARAMTERKEY bool ParameterKey_t::addToCDRMessage( CDRMessage_t* msg) @@ -44,6 +56,18 @@ bool ParameterKey_t::addToCDRMessage( } +bool ParameterKey_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_KEY_HASH_LENGTH) + { + return false; + } + length = size; + return CDRMessage::readData(msg, key.value, PARAMETER_KEY_HASH_LENGTH); +} + // PARAMETER_ STRING bool ParameterString_t::addToCDRMessage( CDRMessage_t* msg) @@ -54,24 +78,26 @@ bool ParameterString_t::addToCDRMessage( } bool valid = CDRMessage::addUInt16(msg, this->Pid); //Str size - uint32_t str_siz = (uint32_t)this->string_.size(); - int rest = (str_siz + 1) % 4; - if (rest != 0) - { - rest = 4 - rest; //how many you have to add - } - this->length = (uint16_t)(str_siz + 1 + 4 + rest); + uint32_t str_siz = (uint32_t)this->string_.size() + 1; + this->length = (uint16_t)(str_siz + 4 + 3) & ~3; valid &= CDRMessage::addUInt16(msg, this->length); - valid &= CDRMessage::addUInt32(msg, str_siz + 1); - valid &= CDRMessage::addData(msg, (unsigned char*) this->string_.c_str(), str_siz + 1); - if (rest != 0) + valid &= CDRMessage::add_string(msg, this->string_); + return valid; +} + +bool ParameterString_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size > 256) { - octet oc = '\0'; - for (int i = 0; i < rest; i++) - { - valid &= CDRMessage::addOctet(msg, oc); - } + return false; } + + length = size; + fastrtps::string_255 aux; + bool valid = CDRMessage::readString(msg, &aux); + setName(aux.c_str()); return valid; } @@ -80,55 +106,124 @@ bool ParameterPort_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_PORT_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_PORT_LENGTH); valid &= CDRMessage::addUInt32(msg, this->port); return valid; } +bool ParameterPort_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_PORT_LENGTH) + { + return false; + } + length = size; + return CDRMessage::readUInt32(msg, &port); +} + //PARAMETER_ GUID bool ParameterGuid_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_GUID_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_GUID_LENGTH); valid &= CDRMessage::addData(msg, this->guid.guidPrefix.value, 12); valid &= CDRMessage::addData(msg, this->guid.entityId.value, 4); return valid; } +bool ParameterGuid_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_GUID_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readData(msg, guid.guidPrefix.value, 12); + valid &= CDRMessage::readData(msg, guid.entityId.value, 4); + return valid; +} + //PARAMETER_ PROTOCOL VERSION bool ParameterProtocolVersion_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_PROTOCOL_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_PROTOCOL_LENGTH); valid &= CDRMessage::addOctet(msg, protocolVersion.m_major); valid &= CDRMessage::addOctet(msg, protocolVersion.m_minor); valid &= CDRMessage::addUInt16(msg, 0); return valid; } +bool ParameterProtocolVersion_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_PROTOCOL_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readOctet(msg, &protocolVersion.m_major); + valid &= CDRMessage::readOctet(msg, &protocolVersion.m_minor); + msg->pos += 2; //padding + return valid; +} + +//PARAMETER_ VENDORID bool ParameterVendorId_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_VENDOR_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_VENDOR_LENGTH); valid &= CDRMessage::addOctet(msg, vendorId[0]); valid &= CDRMessage::addOctet(msg, vendorId[1]); valid &= CDRMessage::addUInt16(msg, 0); return valid; } +bool ParameterVendorId_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_VENDOR_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readOctet(msg, &vendorId[0]); + valid &= CDRMessage::readOctet(msg, &vendorId[1]); + msg->pos += 2; //padding + return valid; +} + //PARAMETER_ IP4ADDRESS bool ParameterIP4Address_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_IP4_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_IP4_LENGTH); valid &= CDRMessage::addData(msg, this->address, 4); return valid; } +bool ParameterIP4Address_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_IP4_LENGTH) + { + return false; + } + length = size; + return CDRMessage::readData(msg, address, 4); +} + void ParameterIP4Address_t::setIP4Address( octet o1, octet o2, @@ -145,7 +240,7 @@ bool ParameterBool_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_BOOL_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_BOOL_LENGTH); octet val = value ? 1 : 0; valid &= CDRMessage::addOctet(msg, val); valid &= CDRMessage::addOctet(msg, 0); @@ -153,86 +248,214 @@ bool ParameterBool_t::addToCDRMessage( return valid; } +bool ParameterBool_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_BOOL_LENGTH) + { + return false; + } + + length = size; + bool valid = CDRMessage::readOctet(msg, (octet*)&value); + msg->pos += 3; //padding + return valid; +} + bool ParameterStatusInfo_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_STATUS_INFO_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_STATUS_INFO_LENGTH); valid &= CDRMessage::addUInt16(msg, 0); valid &= CDRMessage::addOctet(msg, 0); valid &= CDRMessage::addOctet(msg, status); return valid; } +bool ParameterStatusInfo_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_STATUS_INFO_LENGTH) + { + return false; + } + length = size; + //octet status = msg.buffer[msg.pos + 3]; + bool valid = true; + octet tmp; + //Remove the front three octets, take the fourth + valid &= CDRMessage::readOctet(msg, &tmp); + valid &= CDRMessage::readOctet(msg, &tmp); + valid &= CDRMessage::readOctet(msg, &tmp); + return CDRMessage::readOctet(msg, &status); +} + bool ParameterCount_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_COUNT_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_COUNT_LENGTH); valid &= CDRMessage::addUInt32(msg, count); return valid; } +bool ParameterCount_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_COUNT_LENGTH) + { + return false; + } + length = size; + return CDRMessage::readUInt32(msg, &count); +} + bool ParameterEntityId_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_ENTITYID_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_ENTITYID_LENGTH); valid &= CDRMessage::addEntityId(msg, &entityId); return valid; } +bool ParameterEntityId_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_ENTITYID_LENGTH) + { + return false; + } + length = size; + return CDRMessage::readEntityId(msg, &entityId); +} + bool ParameterTime_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_TIME_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_TIME_LENGTH); valid &= CDRMessage::addInt32(msg, time.seconds()); valid &= CDRMessage::addInt32(msg, time.fraction()); return valid; } +bool ParameterTime_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_TIME_LENGTH) + { + return false; + } + length = size; + int32_t sec(0); + bool valid = CDRMessage::readInt32(msg, &sec); + time.seconds(sec); + uint32_t frac(0); + valid &= CDRMessage::readUInt32(msg, &frac); + time.fraction(frac); + return valid; +} + bool ParameterBuiltinEndpointSet_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_BUILTINENDPOINTSET_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_BUILTINENDPOINTSET_LENGTH); valid &= CDRMessage::addUInt32(msg, this->endpointSet); return valid; } +bool ParameterBuiltinEndpointSet_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_BUILTINENDPOINTSET_LENGTH) + { + return false; + } + length = size; + return CDRMessage::readUInt32(msg, &endpointSet); +} + bool ParameterPropertyList_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); uint16_t pos_str = (uint16_t)msg->pos; - valid &= CDRMessage::addUInt16(msg, this->length);//this->length); - valid &= CDRMessage::addUInt32(msg, (uint32_t)this->properties.size()); - for (std::vector >::iterator it = this->properties.begin(); - it != this->properties.end(); ++it) - { - valid &= CDRMessage::addString(msg, it->first); - valid &= CDRMessage::addString(msg, it->second); - } - uint32_t align = (4 - msg->pos % 4) & 3; //align - for (uint32_t count = 0; count < align; ++count) + valid &= CDRMessage::addUInt16(msg, this->length); + valid &= CDRMessage::addUInt32(msg, (uint32_t)this->size()); + for (ParameterPropertyList_t::iterator it = this->begin(); + it != this->end(); ++it) { - valid &= CDRMessage::addOctet(msg, 0); + valid &= CDRMessage::add_string(msg, it->first()); + valid &= CDRMessage::add_string(msg, it->second()); } uint16_t pos_param_end = (uint16_t)msg->pos; this->length = pos_param_end - pos_str - 2; msg->pos = pos_str; - valid &= CDRMessage::addUInt16(msg, this->length);//this->length); + valid &= CDRMessage::addUInt16(msg, this->length); msg->pos = pos_param_end; msg->length -= 2; return valid; } +bool ParameterPropertyList_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (limit_size_ && size > properties_.max_size + 4) + { + return false; + } + length = size; + + uint32_t pos_ref = msg->pos; + uint32_t num_properties; + bool valid = CDRMessage::readUInt32(msg, &num_properties); + + properties_.reserve(size - 4); + + for (size_t i = 0; i < num_properties; ++i) + { + uint32_t property_size, alignment; + + valid &= CDRMessage::readUInt32(msg, &property_size); + if (!valid) + { + return false; + } + alignment = ((property_size + 3) & ~3) - property_size; + push_back_helper (&msg->buffer[msg->pos], property_size, alignment); + msg->pos += (property_size + alignment); + + valid &= CDRMessage::readUInt32(msg, &property_size); + if (!valid) + { + return false; + } + alignment = ((property_size + 3) & ~3) - property_size; + push_back_helper (&msg->buffer[msg->pos], property_size, alignment); + msg->pos += (property_size + alignment); + } + Nproperties_ = num_properties; + + uint32_t length_diff = msg->pos - pos_ref; + valid &= (size == length_diff); + return valid; +} + bool ParameterSampleIdentity_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, this->length);//this->length); + valid &= CDRMessage::addUInt16(msg, this->length); valid &= CDRMessage::addData(msg, sample_id.writer_guid().guidPrefix.value, GuidPrefix_t::size); valid &= CDRMessage::addData(msg, sample_id.writer_guid().entityId.value, EntityId_t::size); valid &= CDRMessage::addInt32(msg, sample_id.sequence_number().high); @@ -240,6 +463,22 @@ bool ParameterSampleIdentity_t::addToCDRMessage( return valid; } +bool ParameterSampleIdentity_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_SAMPLEIDENTITY_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readData(msg, sample_id.writer_guid().guidPrefix.value, GuidPrefix_t::size); + valid &= CDRMessage::readData(msg, sample_id.writer_guid().entityId.value, EntityId_t::size); + valid &= CDRMessage::readInt32(msg, &sample_id.sequence_number().high); + valid &= CDRMessage::readUInt32(msg, &sample_id.sequence_number().low); + return valid; +} + #if HAVE_SECURITY bool ParameterToken_t::addToCDRMessage( @@ -257,32 +496,73 @@ bool ParameterToken_t::addToCDRMessage( uint16_t pos_param_end = (uint16_t)msg->pos; this->length = pos_param_end - pos_str - 2; msg->pos = pos_str; - valid &= CDRMessage::addUInt16(msg, this->length);//this->length); + valid &= CDRMessage::addUInt16(msg, this->length); msg->pos = pos_param_end; msg->length -= 2; return valid; } +bool ParameterToken_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + + length = size; + uint32_t pos_ref = msg->pos; + bool valid = CDRMessage::readDataHolder(msg, token); + uint32_t length_diff = msg->pos - pos_ref; + valid &= (size == length_diff); + return valid; +} + bool ParameterParticipantSecurityInfo_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_PARTICIPANT_SECURITY_INFO_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_PARTICIPANT_SECURITY_INFO_LENGTH); valid &= CDRMessage::addUInt32(msg, this->security_attributes); valid &= CDRMessage::addUInt32(msg, this->plugin_security_attributes); return valid; } +bool ParameterParticipantSecurityInfo_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_PARTICIPANT_SECURITY_INFO_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readUInt32(msg, &security_attributes); + valid &= CDRMessage::readUInt32(msg, &plugin_security_attributes); + return valid; +} + bool ParameterEndpointSecurityInfo_t::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); - valid &= CDRMessage::addUInt16(msg, PARAMETER_ENDPOINT_SECURITY_INFO_LENGTH);//this->length); + valid &= CDRMessage::addUInt16(msg, PARAMETER_ENDPOINT_SECURITY_INFO_LENGTH); valid &= CDRMessage::addUInt32(msg, this->security_attributes); valid &= CDRMessage::addUInt32(msg, this->plugin_security_attributes); return valid; } +bool ParameterEndpointSecurityInfo_t::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_ENDPOINT_SECURITY_INFO_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readUInt32(msg, &security_attributes); + valid &= CDRMessage::readUInt32(msg, &plugin_security_attributes); + return valid; +} + #endif } //namespace dds diff --git a/src/cpp/dds/core/policy/QosPolicies.cpp b/src/cpp/dds/core/policy/QosPolicies.cpp index 201c028d432..ca33641df1c 100644 --- a/src/cpp/dds/core/policy/QosPolicies.cpp +++ b/src/cpp/dds/core/policy/QosPolicies.cpp @@ -41,6 +41,20 @@ bool DurabilityQosPolicy::addToCDRMessage( return valid; } +bool DurabilityQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_KIND_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readOctet(msg, (octet*)&kind); + msg->pos += 3; //padding + return valid; +} + bool DeadlineQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -51,6 +65,22 @@ bool DeadlineQosPolicy::addToCDRMessage( return valid; } +bool DeadlineQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_TIME_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readInt32(msg, &period.seconds); + uint32_t frac(0); + valid &= CDRMessage::readUInt32(msg, &frac); + period.fraction(frac); + return valid; +} + bool LatencyBudgetQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -61,6 +91,22 @@ bool LatencyBudgetQosPolicy::addToCDRMessage( return valid; } +bool LatencyBudgetQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_TIME_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readInt32(msg, &duration.seconds); + uint32_t frac(0); + valid &= CDRMessage::readUInt32(msg, &frac); + duration.fraction(frac); + return valid; +} + bool LivelinessQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -75,6 +121,24 @@ bool LivelinessQosPolicy::addToCDRMessage( return valid; } +bool LivelinessQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readOctet(msg, (octet*)&kind); + msg->pos += 3; //padding + valid &= CDRMessage::readInt32(msg, &lease_duration.seconds); + uint32_t frac(0); + valid &= CDRMessage::readUInt32(msg, &frac); + lease_duration.fraction(frac); + return valid; +} + bool OwnershipQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -87,6 +151,20 @@ bool OwnershipQosPolicy::addToCDRMessage( return valid; } +bool OwnershipQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_KIND_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readOctet(msg, (octet*)&kind); + msg->pos += 3; //padding + return valid; +} + bool ReliabilityQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -101,6 +179,24 @@ bool ReliabilityQosPolicy::addToCDRMessage( return valid; } +bool ReliabilityQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readOctet(msg, (octet*)&kind); + msg->pos += 3; //padding + valid &= CDRMessage::readInt32(msg, &max_blocking_time.seconds); + uint32_t frac(0); + valid &= CDRMessage::readUInt32(msg, &frac); + max_blocking_time.fraction(frac); + return valid; +} + bool DestinationOrderQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -113,6 +209,20 @@ bool DestinationOrderQosPolicy::addToCDRMessage( return valid; } +bool DestinationOrderQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_KIND_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readOctet(msg, (octet*)&kind); + msg->pos += 3; //padding + return valid; +} + bool TimeBasedFilterQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -123,6 +233,22 @@ bool TimeBasedFilterQosPolicy::addToCDRMessage( return valid; } +bool TimeBasedFilterQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_TIME_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readInt32(msg, &minimum_separation.seconds); + uint32_t frac(0); + valid &= CDRMessage::readUInt32(msg, &frac); + minimum_separation.fraction(frac); + return valid; +} + bool PresentationQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -141,47 +267,124 @@ bool PresentationQosPolicy::addToCDRMessage( return valid; } +bool PresentationQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_PRESENTATION_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readOctet(msg, (octet*)&access_scope); + msg->pos += 3; //padding + valid &= CDRMessage::readOctet(msg, (octet*)&coherent_access); + valid &= CDRMessage::readOctet(msg, (octet*)&ordered_access); + msg->pos += 2; //padding + return valid; +} + bool PartitionQosPolicy::addToCDRMessage( CDRMessage_t* msg) { bool valid = CDRMessage::addUInt16(msg, this->Pid); //Obtain Length: - this->length = 0; - this->length += 4; - uint16_t rest; - for (std::vector::iterator it = names_.begin(); it != names_.end(); ++it) + uint16_t pos_str = (uint16_t)msg->pos; + valid &= CDRMessage::addUInt16(msg, this->length);//this->length); + valid &= CDRMessage::addUInt32(msg, (uint32_t)this->size()); + + for (PartitionQosPolicy::const_iterator it = this->begin(); + it != this->end(); ++it) { - this->length += 4; - this->length += (uint16_t)it->size() + 1; - rest = ((uint16_t)it->size() + 1 ) % 4; - this->length += rest != 0 ? 4 - rest : 0; + uint32_t size = it->size(); //Already accounts for null char + valid &= CDRMessage::addUInt32(msg, size); + valid &= CDRMessage::addData(msg, (unsigned char*)it->name(), size); + uint32_t align = ((size + 3) & ~3) - size; + for (uint32_t count = 0; count < align; ++count) + { + valid &= CDRMessage::addOctet(msg, 0); + } } + + uint16_t pos_param_end = (uint16_t)msg->pos; + this->length = pos_param_end - pos_str - 2; + msg->pos = pos_str; valid &= CDRMessage::addUInt16(msg, this->length); - valid &= CDRMessage::addUInt32(msg, (uint32_t)this->names_.size()); - for (std::vector::iterator it = names_.begin(); it != names_.end(); ++it) + msg->pos = pos_param_end; + msg->length -= 2; + + return valid; +} + +bool PartitionQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (max_size_ != 0 && size > partitions_.max_size + 4) { - valid &= CDRMessage::addString(msg, *it); + return false; + } + length = size; + + uint32_t pos_ref = msg->pos; + uint32_t num_partitions; + bool valid = CDRMessage::readUInt32(msg, &num_partitions); + partitions_.reserve(size - 4); + + for (size_t i = 0; i < num_partitions; ++i) + { + uint32_t partition_size, alignment; + + valid &= CDRMessage::readUInt32(msg, &partition_size); + if (!valid) + { + return false; + } + + push_back ((const char*)&msg->buffer[msg->pos]); + alignment = ((partition_size + 3) & ~3) - partition_size; + msg->pos += (partition_size + alignment); } - //valid &= CDRMessage::addOctetVector(msg,&name); + Npartitions_ = num_partitions; + + uint32_t length_diff = msg->pos - pos_ref; + valid &= (size == length_diff); return valid; } bool UserDataQosPolicy::addToCDRMessage( CDRMessage_t* msg) { - bool valid = CDRMessage::addUInt16(msg, this->Pid); - uint32_t align = (4 - (msg->pos + 6 + data_vec_.size()) % 4) & 3; //align - this->length = (uint16_t)(4 + this->data_vec_.size() + align); - valid &= CDRMessage::addUInt16(msg, this->length); - valid &= CDRMessage::addUInt32(msg, (uint32_t)this->data_vec_.size()); - valid &= CDRMessage::addData(msg, this->data_vec_.data(), (uint32_t)this->data_vec_.size()); + bool valid = CDRMessage::addUInt16(msg, Pid); + uint32_t siz = (uint32_t)size(); + uint32_t align = ((siz + 3) & ~3) - siz; + length = (uint16_t)(4 + siz); + valid &= CDRMessage::addUInt16(msg, length); + valid &= CDRMessage::addUInt32(msg, siz); + valid &= CDRMessage::addData(msg, collection_.data(), siz); for (uint32_t count = 0; count < align; ++count) { valid &= CDRMessage::addOctet(msg, 0); } + return valid; } +bool UserDataQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size > max_size()) + { + return false; + } + length = size; + + //Either the data is size limited and already has max_size() allocated + // or it is not limited and readOctedVector will resize if needed + return CDRMessage::readOctetVector(msg, &collection_); +} + bool TopicDataQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -191,6 +394,19 @@ bool TopicDataQosPolicy::addToCDRMessage( return valid; } +bool TopicDataQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + length = size; + + uint32_t pos_ref = msg->pos; + bool valid = CDRMessage::readOctetVector(msg, &value); + uint32_t length_diff = msg->pos - pos_ref; + valid &= (size == length_diff); + return valid; +} + bool GroupDataQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -200,6 +416,19 @@ bool GroupDataQosPolicy::addToCDRMessage( return valid; } +bool GroupDataQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + length = size; + + uint32_t pos_ref = msg->pos; + bool valid = CDRMessage::readOctetVector(msg, &value); + uint32_t length_diff = msg->pos - pos_ref; + valid &= (size == length_diff); + return valid; +} + bool HistoryQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -213,6 +442,21 @@ bool HistoryQosPolicy::addToCDRMessage( return valid; } +bool HistoryQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_KIND_LENGTH + 4) + { + return false; + } + length = size; + bool valid = CDRMessage::readOctet(msg, (octet*)&kind); + msg->pos += 3; //padding + valid &= CDRMessage::readInt32(msg, &depth); + return valid; +} + bool DurabilityServiceQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -231,6 +475,28 @@ bool DurabilityServiceQosPolicy::addToCDRMessage( return valid; } +bool DurabilityServiceQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_TIME_LENGTH + PARAMETER_KIND_LENGTH + 16) + { + return false; + } + length = size; + bool valid = CDRMessage::readInt32(msg, &service_cleanup_delay.seconds); + uint32_t frac(0); + valid &= CDRMessage::readUInt32(msg, &frac); + service_cleanup_delay.fraction(frac); + valid &= CDRMessage::readOctet(msg, (octet*)&history_kind); + msg->pos += 3; //padding + valid &= CDRMessage::readInt32(msg, &history_depth); + valid &= CDRMessage::readInt32(msg, &max_samples); + valid &= CDRMessage::readInt32(msg, &max_instances); + valid &= CDRMessage::readInt32(msg, &max_samples_per_instance); + return valid; +} + bool LifespanQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -241,6 +507,22 @@ bool LifespanQosPolicy::addToCDRMessage( return valid; } +bool LifespanQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_TIME_LENGTH) + { + return false; + } + length = size; + bool valid = CDRMessage::readInt32(msg, &duration.seconds); + uint32_t frac(0); + valid &= CDRMessage::readUInt32(msg, &frac); + duration.fraction(frac); + return valid; +} + bool OwnershipStrengthQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -250,6 +532,18 @@ bool OwnershipStrengthQosPolicy::addToCDRMessage( return valid; } +bool OwnershipStrengthQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != 4) + { + return false; + } + length = size; + return CDRMessage::readUInt32(msg, &value); +} + bool ResourceLimitsQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -262,6 +556,21 @@ bool ResourceLimitsQosPolicy::addToCDRMessage( return valid; } +bool ResourceLimitsQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != 12) + { + return false; + } + length = size; + bool valid = CDRMessage::readInt32(msg, &max_samples); + valid &= CDRMessage::readInt32(msg, &max_instances); + valid &= CDRMessage::readInt32(msg, &max_samples_per_instance); + return valid; +} + bool TransportPriorityQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -271,6 +580,18 @@ bool TransportPriorityQosPolicy::addToCDRMessage( return valid; } +bool TransportPriorityQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != 4) + { + return false; + } + length = size; + return CDRMessage::readUInt32(msg, &value); +} + bool DataRepresentationQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -290,6 +611,23 @@ bool DataRepresentationQosPolicy::addToCDRMessage( return valid; } +bool DataRepresentationQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + length = size; + + int16_t temp(0); + uint32_t datasize(0); + bool valid = CDRMessage::readUInt32(msg, &datasize); + for (uint32_t i = 0; i < datasize; ++i) + { + valid &= CDRMessage::readInt16(msg, &temp); + m_value.push_back(static_cast(temp)); + } + return valid; +} + bool TypeConsistencyEnforcementQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -305,6 +643,59 @@ bool TypeConsistencyEnforcementQosPolicy::addToCDRMessage( return valid; } +bool TypeConsistencyEnforcementQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size < 2) + { + return false; + } + + uint16_t uKind(0); + octet temp(0); + m_ignore_sequence_bounds = false; + m_ignore_string_bounds = false; + m_ignore_member_names = false; + m_prevent_type_widening = false; + m_force_type_validation = false; + + bool valid = CDRMessage::readUInt16(msg, &uKind); + m_kind = static_cast(uKind); + + if (size >= 3) + { + valid &= CDRMessage::readOctet(msg, &temp); + m_ignore_sequence_bounds = temp == 0 ? false : true; + } + + if (valid && size >= 4) + { + valid &= CDRMessage::readOctet(msg, &temp); + m_ignore_string_bounds = temp == 0 ? false : true; + } + + if (valid && size >= 5) + { + valid &= CDRMessage::readOctet(msg, &temp); + m_ignore_member_names = temp == 0 ? false : true; + } + + if (valid && size >= 6) + { + valid &= CDRMessage::readOctet(msg, &temp); + m_prevent_type_widening = temp == 0 ? false : true; + } + + if (valid && size >= 7) + { + valid &= CDRMessage::readOctet(msg, &temp); + m_force_type_validation = temp == 0 ? false : true; + } + + return valid; +} + bool DisablePositiveACKsQosPolicy::addToCDRMessage( CDRMessage_t* msg) { @@ -322,6 +713,22 @@ bool DisablePositiveACKsQosPolicy::addToCDRMessage( return true; } +bool DisablePositiveACKsQosPolicy::readFromCDRMessage( + CDRMessage_t* msg, + uint16_t size) +{ + if (size != PARAMETER_BOOL_LENGTH) + { + return false; + } + length = size; + octet value(0); + bool valid = CDRMessage::readOctet(msg, &value); + enabled = (value == 0) ? false : true; + msg->pos += 3; //padding + return valid; +} + bool TypeIdV1::addToCDRMessage( CDRMessage_t* msg) { @@ -354,7 +761,7 @@ bool TypeIdV1::addToCDRMessage( bool TypeIdV1::readFromCDRMessage( CDRMessage_t* msg, - uint32_t size) + uint16_t size) { SerializedPayload_t payload(size); eprosima::fastcdr::FastBuffer fastbuffer((char*)payload.data, size); @@ -405,7 +812,7 @@ bool TypeObjectV1::addToCDRMessage( bool TypeObjectV1::readFromCDRMessage( CDRMessage_t* msg, - uint32_t size) + uint16_t size) { SerializedPayload_t payload(size); eprosima::fastcdr::FastBuffer fastbuffer((char*)payload.data, size); @@ -456,7 +863,7 @@ bool xtypes::TypeInformation::addToCDRMessage( bool xtypes::TypeInformation::readFromCDRMessage( CDRMessage_t* msg, - uint32_t size) + uint16_t size) { SerializedPayload_t payload(size); eprosima::fastcdr::FastBuffer fastbuffer((char*)payload.data, size); diff --git a/src/cpp/dds/topic/qos/ReaderQos.cpp b/src/cpp/dds/topic/qos/ReaderQos.cpp index 60de9358b3f..6a831ca669b 100644 --- a/src/cpp/dds/topic/qos/ReaderQos.cpp +++ b/src/cpp/dds/topic/qos/ReaderQos.cpp @@ -205,6 +205,28 @@ bool ReaderQos::canQosBeUpdated( return updatable; } +void ReaderQos::clear() +{ + m_durability.clear(); + m_deadline.clear(); + m_latencyBudget.clear(); + m_liveliness.clear(); + m_reliability.clear(); + m_ownership.clear(); + m_destinationOrder.clear(); + m_userData.clear(); + m_timeBasedFilter.clear(); + m_presentation.clear(); + m_partition.clear(); + m_topicData.clear(); + m_groupData.clear(); + m_durabilityService.clear(); + m_lifespan.clear(); + m_disablePositiveACKs.clear(); + representation.clear(); + type_consistency.clear(); +} + } //namespace dds } //namespace fastdds } //namespace eprosima diff --git a/src/cpp/dds/topic/qos/WriterQos.cpp b/src/cpp/dds/topic/qos/WriterQos.cpp index a0b9f432462..017d6d26455 100644 --- a/src/cpp/dds/topic/qos/WriterQos.cpp +++ b/src/cpp/dds/topic/qos/WriterQos.cpp @@ -224,6 +224,32 @@ bool WriterQos::canQosBeUpdated( } +void WriterQos::clear() +{ + m_durability.clear(); + m_deadline.clear(); + m_latencyBudget.clear(); + m_liveliness.clear(); + m_reliability.clear(); + m_ownership.clear(); + m_destinationOrder.clear(); + m_userData.clear(); + m_timeBasedFilter.clear(); + m_presentation.clear(); + m_partition.clear(); + m_topicData.clear(); + m_groupData.clear(); + m_durabilityService.clear(); + m_lifespan.clear(); + m_disablePositiveACKs.clear(); + m_ownershipStrength.clear(); + m_publishMode.clear(); + representation.clear(); + + m_reliability.kind = RELIABLE_RELIABILITY_QOS; + m_durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS; +} + } //namespace dds } //namespace fastdds } //namespace eprosima diff --git a/src/cpp/fastrtps_deprecated/security/authentication/PKIDH.cpp b/src/cpp/fastrtps_deprecated/security/authentication/PKIDH.cpp index e2302b010a7..f785de7c5c1 100644 --- a/src/cpp/fastrtps_deprecated/security/authentication/PKIDH.cpp +++ b/src/cpp/fastrtps_deprecated/security/authentication/PKIDH.cpp @@ -159,7 +159,7 @@ static X509_STORE* load_identity_ca( { if (BIO_read_filename(in, identity_ca.substr(7).c_str()) > 0) { - STACK_OF(X509_INFO)* inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); + STACK_OF(X509_INFO) * inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); if (inf != nullptr) { @@ -598,7 +598,6 @@ static bool check_sign_sha256( return returnedValue; } - static X509_CRL* load_crl( const std::string& identity_crl, SecurityException& exception) @@ -1512,39 +1511,14 @@ ValidationResult_t PKIDH::begin_handshake_reply( } GUID_t participant_guid; - auto param_process = [&participant_guid](const Parameter_t* param) - { - switch (param->Pid) - { - case fastdds::dds::PID_KEY_HASH: - { - const ParameterKey_t* p = dynamic_cast(param); - assert(p != nullptr); - iHandle2GUID(participant_guid, p->key); - break; - } - case fastdds::dds::PID_PARTICIPANT_GUID: - { - const ParameterGuid_t* p = dynamic_cast(param); - assert(p != nullptr); - participant_guid = p->guid; - break; - } - - default: break; - } - - return true; - }; - CDRMessage_t cdr_pdata(0); cdr_pdata.wraps = true; cdr_pdata.msg_endian = BIGEND; cdr_pdata.length = (uint32_t)pdata->size(); cdr_pdata.max_size = (uint32_t)pdata->size(); cdr_pdata.buffer = (octet*)pdata->data(); - uint32_t qos_size; - if (!ParameterList::readParameterListfromCDRMsg(cdr_pdata, param_process, false, qos_size)) + + if (!ParameterList::read_guid_from_cdr_msg(cdr_pdata, fastdds::dds::PID_PARTICIPANT_GUID, participant_guid)) { logWarning(SECURITY_AUTHENTICATION, "Cannot deserialize ParticipantProxyData in property c.pdata"); return ValidationResult_t::VALIDATION_FAILED; @@ -1958,39 +1932,14 @@ ValidationResult_t PKIDH::process_handshake_request( } GUID_t participant_guid; - auto param_process = [&participant_guid](const Parameter_t* param) - { - switch (param->Pid) - { - case fastdds::dds::PID_KEY_HASH: - { - const ParameterKey_t* p = dynamic_cast(param); - assert(p != nullptr); - iHandle2GUID(participant_guid, p->key); - break; - } - case fastdds::dds::PID_PARTICIPANT_GUID: - { - const ParameterGuid_t* p = dynamic_cast(param); - assert(p != nullptr); - participant_guid = p->guid; - break; - } - - default: break; - } - - return true; - }; - CDRMessage_t cdr_pdata(0); cdr_pdata.wraps = true; cdr_pdata.msg_endian = BIGEND; cdr_pdata.length = (uint32_t)pdata->size(); cdr_pdata.max_size = (uint32_t)pdata->size(); cdr_pdata.buffer = (octet*)pdata->data(); - uint32_t qos_size; - if (!ParameterList::readParameterListfromCDRMsg(cdr_pdata, param_process, false, qos_size)) + + if (!ParameterList::read_guid_from_cdr_msg(cdr_pdata, fastdds::dds::PID_PARTICIPANT_GUID, participant_guid)) { logWarning(SECURITY_AUTHENTICATION, "Cannot deserialize ParticipantProxyData in property c.pdata"); return ValidationResult_t::VALIDATION_FAILED; diff --git a/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp b/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp index cc8701f5574..060544441a5 100644 --- a/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp +++ b/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp @@ -49,19 +49,21 @@ ParticipantProxyData::ParticipantProxyData( , m_availableBuiltinEndpoints(0) , metatraffic_locators(allocation.locators.max_unicast_locators, allocation.locators.max_multicast_locators) , default_locators(allocation.locators.max_unicast_locators, allocation.locators.max_multicast_locators) + , m_manualLivelinessCount () #if HAVE_SECURITY , security_attributes_(0UL) , plugin_security_attributes_(0UL) #endif , isAlive(false) + , m_properties(static_cast(allocation.data_limits.max_properties)) , lease_duration_event(nullptr) , should_check_lease_duration(false) , m_readers(new ProxyHashTable(allocation.readers)) , m_writers(new ProxyHashTable(allocation.writers)) { + m_userData.set_max_size(static_cast(allocation.data_limits.max_user_data)); } - ParticipantProxyData::ParticipantProxyData( const ParticipantProxyData& pdata) : m_protocolVersion(pdata.m_protocolVersion) @@ -71,6 +73,7 @@ ParticipantProxyData::ParticipantProxyData( , m_availableBuiltinEndpoints(pdata.m_availableBuiltinEndpoints) , metatraffic_locators(pdata.metatraffic_locators) , default_locators(pdata.default_locators) + , m_manualLivelinessCount () , m_participantName(pdata.m_participantName) , m_key(pdata.m_key) , m_leaseDuration(pdata.m_leaseDuration) @@ -94,15 +97,14 @@ ParticipantProxyData::ParticipantProxyData( { } - ParticipantProxyData::~ParticipantProxyData() { logInfo(RTPS_PARTICIPANT, m_guid); - // delete all reader proxies - if(m_readers) + // delete all reader proxies + if (m_readers) { - for(ProxyHashTable::value_type val : *m_readers) + for (ProxyHashTable::value_type val : *m_readers) { delete val.second; } @@ -111,9 +113,9 @@ ParticipantProxyData::~ParticipantProxyData() } // delete all writers proxies - if(m_writers) + if (m_writers) { - for(ProxyHashTable::value_type val : *m_writers) + for (ProxyHashTable::value_type val : *m_writers) { delete val.second; } @@ -121,7 +123,7 @@ ParticipantProxyData::~ParticipantProxyData() delete m_writers; } - if(lease_duration_event != nullptr) + if (lease_duration_event != nullptr) { delete lease_duration_event; } @@ -229,27 +231,24 @@ bool ParticipantProxyData::writeToCDRMessage( } } - if (this->m_userData.size() > 0) + if (m_userData.size() > 0) { - UserDataQosPolicy p; - p.data_vec(m_userData); - if (!p.addToCDRMessage(msg)) + if (!m_userData.addToCDRMessage(msg)) { return false; } } - if (this->m_properties.properties.size() > 0) + if (m_properties.size() > 0) { - ParameterPropertyList_t p(m_properties); - if (!p.addToCDRMessage(msg)) + if (!m_properties.addToCDRMessage(msg)) { return false; } } #if HAVE_SECURITY - if (!this->identity_token_.class_id().empty()) + if (!identity_token_.class_id().empty()) { ParameterToken_t p(fastdds::dds::PID_IDENTITY_TOKEN, 0); p.token = identity_token_; @@ -259,7 +258,7 @@ bool ParticipantProxyData::writeToCDRMessage( } } - if (!this->permissions_token_.class_id().empty()) + if (!permissions_token_.class_id().empty()) { ParameterToken_t p(fastdds::dds::PID_PERMISSIONS_TOKEN, 0); p.token = permissions_token_; @@ -269,11 +268,11 @@ bool ParticipantProxyData::writeToCDRMessage( } } - if ((this->security_attributes_ != 0UL) || (this->plugin_security_attributes_ != 0UL)) + if ((security_attributes_ != 0UL) || (plugin_security_attributes_ != 0UL)) { ParameterParticipantSecurityInfo_t p; - p.security_attributes = this->security_attributes_; - p.plugin_security_attributes = this->plugin_security_attributes_; + p.security_attributes = security_attributes_; + p.plugin_security_attributes = plugin_security_attributes_; if (!p.addToCDRMessage(msg)) { return false; @@ -289,60 +288,84 @@ bool ParticipantProxyData::readFromCDRMessage( bool use_encapsulation, const NetworkFactory& network) { - auto param_process = [this, &network](const Parameter_t* param) + auto param_process = [this, &network](CDRMessage_t* msg, const ParameterId_t& pid, uint16_t plength) { - switch (param->Pid) + switch (pid) { case fastdds::dds::PID_KEY_HASH: { - const ParameterKey_t* p = dynamic_cast(param); - assert(p != nullptr); + ParameterKey_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + GUID_t guid; - iHandle2GUID(guid, p->key); - this->m_guid = guid; - this->m_key = p->key; + iHandle2GUID(guid, p.key); + m_guid = guid; + m_key = p.key; break; } case fastdds::dds::PID_PROTOCOL_VERSION: { - const ParameterProtocolVersion_t* p = dynamic_cast(param); - assert(p != nullptr); - if (p->protocolVersion.m_major < c_ProtocolVersion.m_major) + ParameterProtocolVersion_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + if (p.protocolVersion.m_major < c_ProtocolVersion.m_major) { return false; } - this->m_protocolVersion = p->protocolVersion; + m_protocolVersion = p.protocolVersion; break; } case fastdds::dds::PID_VENDORID: { - const ParameterVendorId_t* p = dynamic_cast(param); - assert(p != nullptr); - this->m_VendorId[0] = p->vendorId[0]; - this->m_VendorId[1] = p->vendorId[1]; + ParameterVendorId_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_VendorId[0] = p.vendorId[0]; + m_VendorId[1] = p.vendorId[1]; break; } case fastdds::dds::PID_EXPECTS_INLINE_QOS: { - const ParameterBool_t* p = dynamic_cast(param); - assert(p != nullptr); - this->m_expectsInlineQos = p->value; + ParameterBool_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_expectsInlineQos = p.value; break; } case fastdds::dds::PID_PARTICIPANT_GUID: { - const ParameterGuid_t* p = dynamic_cast(param); - assert(p != nullptr); - this->m_guid = p->guid; - this->m_key = p->guid; + ParameterGuid_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_guid = p.guid; + m_key = p.guid; break; } case fastdds::dds::PID_METATRAFFIC_MULTICAST_LOCATOR: { - const ParameterLocator_t* p = dynamic_cast(param); - assert(p != nullptr); + ParameterLocator_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + Locator_t temp_locator; - if (network.transform_remote_locator(p->locator, temp_locator)) + if (network.transform_remote_locator(p.locator, temp_locator)) { metatraffic_locators.add_multicast_locator(temp_locator); } @@ -350,10 +373,14 @@ bool ParticipantProxyData::readFromCDRMessage( } case fastdds::dds::PID_METATRAFFIC_UNICAST_LOCATOR: { - const ParameterLocator_t* p = dynamic_cast(param); - assert(p != nullptr); + ParameterLocator_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + Locator_t temp_locator; - if (network.transform_remote_locator(p->locator, temp_locator)) + if (network.transform_remote_locator(p.locator, temp_locator)) { metatraffic_locators.add_unicast_locator(temp_locator); } @@ -361,10 +388,14 @@ bool ParticipantProxyData::readFromCDRMessage( } case fastdds::dds::PID_DEFAULT_UNICAST_LOCATOR: { - const ParameterLocator_t* p = dynamic_cast(param); - assert(p != nullptr); + ParameterLocator_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + Locator_t temp_locator; - if (network.transform_remote_locator(p->locator, temp_locator)) + if (network.transform_remote_locator(p.locator, temp_locator)) { default_locators.add_unicast_locator(temp_locator); } @@ -372,10 +403,14 @@ bool ParticipantProxyData::readFromCDRMessage( } case fastdds::dds::PID_DEFAULT_MULTICAST_LOCATOR: { - const ParameterLocator_t* p = dynamic_cast(param); - assert(p != nullptr); + ParameterLocator_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + Locator_t temp_locator; - if (network.transform_remote_locator(p->locator, temp_locator)) + if (network.transform_remote_locator(p.locator, temp_locator)) { default_locators.add_multicast_locator(temp_locator); } @@ -383,48 +418,66 @@ bool ParticipantProxyData::readFromCDRMessage( } case fastdds::dds::PID_PARTICIPANT_LEASE_DURATION: { - const ParameterTime_t* p = dynamic_cast(param); - assert(p != nullptr); - this->m_leaseDuration = p->time.to_duration_t(); + ParameterTime_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_leaseDuration = p.time.to_duration_t(); lease_duration_ = - std::chrono::microseconds(TimeConv::Duration_t2MicroSecondsInt64(m_leaseDuration)); + std::chrono::microseconds(TimeConv::Duration_t2MicroSecondsInt64( + m_leaseDuration)); break; } case fastdds::dds::PID_BUILTIN_ENDPOINT_SET: { - const ParameterBuiltinEndpointSet_t* p = - dynamic_cast(param); - assert(p != nullptr); - this->m_availableBuiltinEndpoints = p->endpointSet; + ParameterBuiltinEndpointSet_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_availableBuiltinEndpoints = p.endpointSet; break; } case fastdds::dds::PID_ENTITY_NAME: { - const ParameterString_t* p = dynamic_cast(param); - assert(p != nullptr); - this->m_participantName = p->getName(); + ParameterString_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_participantName = p.getName(); break; } case fastdds::dds::PID_PROPERTY_LIST: { - const ParameterPropertyList_t* p = dynamic_cast(param); - assert(p != nullptr); - this->m_properties = *p; + if (!m_properties.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_USER_DATA: { - const UserDataQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - this->m_userData = p->data_vec(); + if (!m_userData.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_IDENTITY_TOKEN: { #if HAVE_SECURITY - const ParameterToken_t* p = dynamic_cast(param); - assert(p != nullptr); - this->identity_token_ = std::move(p->token); + ParameterToken_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + identity_token_ = std::move(p.token); #else logWarning(RTPS_PARTICIPANT, "Received PID_IDENTITY_TOKEN but security is disabled"); #endif @@ -433,29 +486,40 @@ bool ParticipantProxyData::readFromCDRMessage( case fastdds::dds::PID_PERMISSIONS_TOKEN: { #if HAVE_SECURITY - const ParameterToken_t* p = dynamic_cast(param); - assert(p != nullptr); - this->permissions_token_ = std::move(p->token); + ParameterToken_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + permissions_token_ = std::move(p.token); #else logWarning(RTPS_PARTICIPANT, "Received PID_PERMISSIONS_TOKEN but security is disabled"); #endif break; } + case fastdds::dds::PID_PARTICIPANT_SECURITY_INFO: { #if HAVE_SECURITY - const ParameterParticipantSecurityInfo_t* p = - dynamic_cast(param); - assert(p != nullptr); - this->security_attributes_ = p->security_attributes; - this->plugin_security_attributes_ = p->plugin_security_attributes; + ParameterParticipantSecurityInfo_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + security_attributes_ = p.security_attributes; + plugin_security_attributes_ = p.plugin_security_attributes; #else - logWarning(RTPS_PARTICIPANT, "Received PID_PARTICIPANT_SECURITY_INFO but security is disabled"); + logWarning(RTPS_PARTICIPANT, + "Received PID_PARTICIPANT_SECURITY_INFO but security is disabled"); #endif break; } - - default: break; + default: + { + break; + } } return true; @@ -463,7 +527,15 @@ bool ParticipantProxyData::readFromCDRMessage( uint32_t qos_size; clear(); - return ParameterList::readParameterListfromCDRMsg(*msg, param_process, use_encapsulation, qos_size); + try + { + return ParameterList::readParameterListfromCDRMsg(*msg, param_process, use_encapsulation, qos_size); + } + catch (std::bad_alloc& ba) + { + std::cerr << "bad_alloc caught: " << ba.what() << '\n'; + return false; + } } void ParticipantProxyData::clear() @@ -489,9 +561,10 @@ void ParticipantProxyData::clear() security_attributes_ = 0UL; plugin_security_attributes_ = 0UL; #endif - m_properties.properties.clear(); + m_properties.clear(); m_properties.length = 0; m_userData.clear(); + m_userData.length = 0; } void ParticipantProxyData::copy( @@ -509,8 +582,8 @@ void ParticipantProxyData::copy( lease_duration_ = std::chrono::microseconds(TimeConv::Duration_t2MicroSecondsInt64(pdata.m_leaseDuration)); m_key = pdata.m_key; isAlive = pdata.isAlive; - m_properties = pdata.m_properties; m_userData = pdata.m_userData; + m_properties = pdata.m_properties; // This method is only called when a new participant is discovered.The destination of the copy // will always be a new ParticipantProxyData or one from the pool, so there is no need for @@ -529,10 +602,10 @@ bool ParticipantProxyData::updateData( { metatraffic_locators = pdata.metatraffic_locators; default_locators = pdata.default_locators; - m_properties = pdata.m_properties; m_leaseDuration = pdata.m_leaseDuration; - m_userData = pdata.m_userData; isAlive = true; + m_userData = pdata.m_userData; + m_properties = pdata.m_properties; #if HAVE_SECURITY identity_token_ = pdata.identity_token_; permissions_token_ = pdata.permissions_token_; @@ -540,7 +613,7 @@ bool ParticipantProxyData::updateData( plugin_security_attributes_ = pdata.plugin_security_attributes_; #endif auto new_lease_duration = std::chrono::microseconds(TimeConv::Duration_t2MicroSecondsInt64(m_leaseDuration)); - if (this->lease_duration_event != nullptr) + if (lease_duration_event != nullptr) { if (new_lease_duration < lease_duration_) { @@ -575,25 +648,27 @@ void ParticipantProxyData::set_persistence_guid( persistent_guid.second = data.str(); // if exists replace - std::vector >& props = m_properties.properties; - - std::vector >::iterator it = - std::find_if( - props.begin(), - props.end(), - [&persistent_guid](const std::pair& p) + ParameterPropertyList_t::iterator it = std::find_if( + m_properties.begin(), + m_properties.end(), + [&persistent_guid](const fastdds::dds::ParameterProperty_t& p) { - return persistent_guid.first == p.first; + return persistent_guid.first == p.first(); }); - if (it != props.end()) + if (it != m_properties.end()) { - *it = std::move(persistent_guid); + if (!it->modify(persistent_guid)) + { + logError(RTPS_PARTICIPANT, "Failed to change property <" + << it->first() << " | " << it->second() << "> to <" + << persistent_guid.first << " | " << persistent_guid.second << ">"); + } } else { // if not exists add - m_properties.properties.push_back(std::move(persistent_guid)); + m_properties.push_back(persistent_guid); } } @@ -601,20 +676,17 @@ GUID_t ParticipantProxyData::get_persistence_guid() const { GUID_t persistent(c_Guid_Unknown); - const std::vector >& props = m_properties.properties; - - std::vector >::const_iterator it = - std::find_if( - props.cbegin(), - props.cend(), - [](const std::pair& p) + ParameterPropertyList_t::const_iterator it = std::find_if( + m_properties.begin(), + m_properties.end(), + [](const fastdds::dds::ParameterProperty_t p) { - return "PID_PERSISTENCE_GUID" == p.first; + return "PID_PERSISTENCE_GUID" == p.first(); }); - if (it != props.end()) + if (it != m_properties.end()) { - std::istringstream in(it->second); + std::istringstream in(it->second()); in >> persistent; } diff --git a/src/cpp/rtps/builtin/data/ReaderProxyData.cpp b/src/cpp/rtps/builtin/data/ReaderProxyData.cpp index 93aaf8e8866..d90a5673f67 100644 --- a/src/cpp/rtps/builtin/data/ReaderProxyData.cpp +++ b/src/cpp/rtps/builtin/data/ReaderProxyData.cpp @@ -48,13 +48,23 @@ ReaderProxyData::ReaderProxyData ( m_qos.type_consistency.m_kind = DISALLOW_TYPE_COERCION; } +ReaderProxyData::ReaderProxyData ( + const size_t max_unicast_locators, + const size_t max_multicast_locators, + const VariableLengthDataLimits& data_limits) + : ReaderProxyData(max_unicast_locators, max_multicast_locators) +{ + m_qos.m_userData.set_max_size(static_cast(data_limits.max_user_data)); + m_qos.m_partition.set_max_size(static_cast(data_limits.max_partitions)); +} + ReaderProxyData::~ReaderProxyData() { delete m_type; delete m_type_id; delete m_type_information; - logInfo(RTPS_PROXY_DATA, "ReaderProxyData destructor: " << this->m_guid; ); + logInfo(RTPS_PROXY_DATA, "ReaderProxyData destructor: " << m_guid; ); } ReaderProxyData::ReaderProxyData( @@ -369,7 +379,7 @@ bool ReaderProxyData::writeToCDRMessage( } #if HAVE_SECURITY - if ((this->security_attributes_ != 0UL) || (this->plugin_security_attributes_ != 0UL)) + if ((security_attributes_ != 0UL) || (plugin_security_attributes_ != 0UL)) { ParameterEndpointSecurityInfo_t p; p.security_attributes = security_attributes_; @@ -411,171 +421,187 @@ bool ReaderProxyData::readFromCDRMessage( CDRMessage_t* msg, const NetworkFactory& network) { - auto param_process = [this, &network](const Parameter_t* param) + auto param_process = [this, &network](CDRMessage_t* msg, const ParameterId_t& pid, uint16_t plength) { - switch (param->Pid) + switch (pid) { case fastdds::dds::PID_DURABILITY: { - const DurabilityQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_durability = *p; + if (!m_qos.m_durability.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_DURABILITY_SERVICE: { - const DurabilityServiceQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_durabilityService = *p; + if (!m_qos.m_durabilityService.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_DEADLINE: { - const DeadlineQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_deadline = *p; + if (!m_qos.m_deadline.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_LATENCY_BUDGET: { - const LatencyBudgetQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_latencyBudget = *p; + if (!m_qos.m_latencyBudget.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_LIVELINESS: { - const LivelinessQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_liveliness = *p; + if (!m_qos.m_liveliness.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_RELIABILITY: { - const ReliabilityQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_reliability = *p; + if (!m_qos.m_reliability.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_LIFESPAN: { - const LifespanQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_lifespan = *p; + if (!m_qos.m_lifespan.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_USER_DATA: { - const UserDataQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_userData = *p; + if (!m_qos.m_userData.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TIME_BASED_FILTER: { - const TimeBasedFilterQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_timeBasedFilter = *p; + if (!m_qos.m_timeBasedFilter.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_OWNERSHIP: { - const OwnershipQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_ownership = *p; + if (!m_qos.m_ownership.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_DESTINATION_ORDER: { - const DestinationOrderQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_destinationOrder = *p; + if (!m_qos.m_destinationOrder.readFromCDRMessage(msg, plength)) + { + return false; + } break; } - case fastdds::dds::PID_PRESENTATION: { - const PresentationQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_presentation = *p; + if (!m_qos.m_presentation.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_PARTITION: { - const PartitionQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_partition = *p; + if (!m_qos.m_partition.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TOPIC_DATA: { - const TopicDataQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_topicData = *p; + if (!m_qos.m_topicData.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_GROUP_DATA: { - const GroupDataQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_groupData = *p; + if (!m_qos.m_groupData.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TOPIC_NAME: { - const ParameterString_t* p = dynamic_cast(param); - assert(p != nullptr); - m_topicName = p->getName(); + ParameterString_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_topicName = p.getName(); break; } case fastdds::dds::PID_TYPE_NAME: { - const ParameterString_t* p = dynamic_cast(param); - assert(p != nullptr); - m_typeName = p->getName(); + ParameterString_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_typeName = p.getName(); break; } case fastdds::dds::PID_PARTICIPANT_GUID: { - const ParameterGuid_t* p = dynamic_cast(param); - assert(p != nullptr); - for (uint8_t i = 0; i < 16; ++i) - { - if (i < 12) - { - m_RTPSParticipantKey.value[i] = p->guid.guidPrefix.value[i]; - } - else - { - m_RTPSParticipantKey.value[i] = p->guid.entityId.value[i - 12]; - } + ParameterGuid_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; } + + memcpy(m_RTPSParticipantKey.value, p.guid.guidPrefix.value, 12); + memcpy(m_RTPSParticipantKey.value + 12, p.guid.entityId.value, 4); break; } case fastdds::dds::PID_ENDPOINT_GUID: { - const ParameterGuid_t* p = dynamic_cast(param); - assert(p != nullptr); - m_guid = p->guid; - for (uint8_t i = 0; i < 16; ++i) - { - if (i < 12) - { - m_key.value[i] = p->guid.guidPrefix.value[i]; - } - else - { - m_key.value[i] = p->guid.entityId.value[i - 12]; - } + ParameterGuid_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; } + + m_guid = p.guid; + memcpy(m_key.value, p.guid.guidPrefix.value, 12); + memcpy(m_key.value + 12, p.guid.entityId.value, 4); break; } case fastdds::dds::PID_UNICAST_LOCATOR: { - const ParameterLocator_t* p = dynamic_cast(param); - assert(p != nullptr); + ParameterLocator_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + Locator_t temp_locator; - if (network.transform_remote_locator(p->locator, temp_locator)) + if (network.transform_remote_locator(p.locator, temp_locator)) { remote_locators_.add_unicast_locator(temp_locator); } @@ -583,10 +609,14 @@ bool ReaderProxyData::readFromCDRMessage( } case fastdds::dds::PID_MULTICAST_LOCATOR: { - const ParameterLocator_t* p = dynamic_cast(param); - assert(p != nullptr); + ParameterLocator_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + Locator_t temp_locator; - if (network.transform_remote_locator(p->locator, temp_locator)) + if (network.transform_remote_locator(p.locator, temp_locator)) { remote_locators_.add_multicast_locator(temp_locator); } @@ -594,96 +624,120 @@ bool ReaderProxyData::readFromCDRMessage( } case fastdds::dds::PID_EXPECTS_INLINE_QOS: { - const ParameterBool_t* p = dynamic_cast(param); - assert(p != nullptr); - m_expectsInlineQos = p->value; + ParameterBool_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_expectsInlineQos = p.value; break; } case fastdds::dds::PID_KEY_HASH: { - const ParameterKey_t* p = dynamic_cast(param); - assert(p != nullptr); - m_key = p->key; + ParameterKey_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_key = p.key; iHandle2GUID(m_guid, m_key); break; } case fastdds::dds::PID_DATA_REPRESENTATION: { - const DataRepresentationQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.representation = *p; + if (!m_qos.representation.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TYPE_CONSISTENCY_ENFORCEMENT: { - const TypeConsistencyEnforcementQosPolicy* p = - dynamic_cast(param); - assert(p != nullptr); - m_qos.type_consistency = *p; + if (!m_qos.type_consistency.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TYPE_IDV1: { - const TypeIdV1* p = dynamic_cast(param); - assert(p != nullptr); - type_id(*p); + if (!type_id().readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TYPE_OBJECTV1: { - const TypeObjectV1* p = dynamic_cast(param); - assert(p != nullptr); - type(*p); + if (!type().readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TYPE_INFORMATION: { - const xtypes::TypeInformation* p = dynamic_cast(param); - assert(p != nullptr); - type_information(*p); + if (!type_information().readFromCDRMessage(msg, plength)) + { + return false; + } break; } + case fastdds::dds::PID_DISABLE_POSITIVE_ACKS: { - const DisablePositiveACKsQosPolicy* p = - dynamic_cast(param); - assert(p != nullptr); - m_qos.m_disablePositiveACKs = *p; + if (!m_qos.m_disablePositiveACKs.readFromCDRMessage(msg, plength)) + { + return false; + } break; } #if HAVE_SECURITY case fastdds::dds::PID_ENDPOINT_SECURITY_INFO: { - const ParameterEndpointSecurityInfo_t* p = - dynamic_cast(param); - assert(p != nullptr); - security_attributes_ = p->security_attributes; - plugin_security_attributes_ = p->plugin_security_attributes; + ParameterEndpointSecurityInfo_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + security_attributes_ = p.security_attributes; + plugin_security_attributes_ = p.plugin_security_attributes; + break; } #endif default: { - //logInfo(RTPS_PROXY_DATA,"Parameter with ID: " <<(uint16_t)(param)->Pid << " NOT CONSIDERED"); break; } } + return true; }; uint32_t qos_size; clear(); - if (ParameterList::readParameterListfromCDRMsg(*msg, param_process, true, qos_size)) + try { - if (m_guid.entityId.value[3] == 0x04) + if (ParameterList::readParameterListfromCDRMsg(*msg, param_process, true, qos_size)) { - m_topicKind = NO_KEY; - } - else if (m_guid.entityId.value[3] == 0x07) - { - m_topicKind = WITH_KEY; - } + if (m_guid.entityId.value[3] == 0x04) + { + m_topicKind = NO_KEY; + } + else if (m_guid.entityId.value[3] == 0x07) + { + m_topicKind = WITH_KEY; + } - return true; + return true; + } + } + catch (std::bad_alloc& ba) + { + std::cerr << "bad_alloc caught: " << ba.what() << '\n'; } return false; @@ -706,7 +760,7 @@ void ReaderProxyData::clear() m_userDefinedId = 0; m_isAlive = true; m_topicKind = NO_KEY; - m_qos = ReaderQos(); + m_qos.clear(); if (m_type_id) { @@ -759,7 +813,6 @@ void ReaderProxyData::copy( m_topicName = rdata->m_topicName; m_userDefinedId = rdata->m_userDefinedId; m_qos = rdata->m_qos; - //cout << "COPYING DATA: expects inlineQOS : " << rdata->m_expectsInlineQos << endl; m_expectsInlineQos = rdata->m_expectsInlineQos; m_isAlive = rdata->m_isAlive; m_topicKind = rdata->m_topicKind; diff --git a/src/cpp/rtps/builtin/data/WriterProxyData.cpp b/src/cpp/rtps/builtin/data/WriterProxyData.cpp index 94229c549fd..87668384dd9 100644 --- a/src/cpp/rtps/builtin/data/WriterProxyData.cpp +++ b/src/cpp/rtps/builtin/data/WriterProxyData.cpp @@ -49,6 +49,16 @@ WriterProxyData::WriterProxyData( { } +WriterProxyData::WriterProxyData( + const size_t max_unicast_locators, + const size_t max_multicast_locators, + const VariableLengthDataLimits& data_limits) + : WriterProxyData(max_unicast_locators, max_multicast_locators) +{ + m_qos.m_userData.set_max_size(static_cast(data_limits.max_user_data)); + m_qos.m_partition.set_max_size(static_cast(data_limits.max_partitions)); +} + WriterProxyData::WriterProxyData( const WriterProxyData& writerInfo) #if HAVE_SECURITY @@ -95,7 +105,7 @@ WriterProxyData::~WriterProxyData() delete m_type_id; delete m_type_information; - logInfo(RTPS_PROXY_DATA, this->m_guid); + logInfo(RTPS_PROXY_DATA, m_guid); } WriterProxyData& WriterProxyData::operator =( @@ -379,7 +389,7 @@ bool WriterProxyData::writeToCDRMessage( } #if HAVE_SECURITY - if ((this->security_attributes_ != 0UL) || (this->plugin_security_attributes_ != 0UL)) + if ((security_attributes_ != 0UL) || (plugin_security_attributes_ != 0UL)) { ParameterEndpointSecurityInfo_t p; p.security_attributes = security_attributes_; @@ -413,185 +423,206 @@ bool WriterProxyData::readFromCDRMessage( CDRMessage_t* msg, const NetworkFactory& network) { - auto param_process = [this, &network](const Parameter_t* param) + auto param_process = [this, &network](CDRMessage_t* msg, const ParameterId_t& pid, uint16_t plength) { - switch (param->Pid) + switch (pid) { case fastdds::dds::PID_DURABILITY: { - const DurabilityQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_durability = *p; + if (!m_qos.m_durability.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_DURABILITY_SERVICE: { - const DurabilityServiceQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_durabilityService = *p; + if (!m_qos.m_durabilityService.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_DEADLINE: { - const DeadlineQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_deadline = *p; + if (!m_qos.m_deadline.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_LATENCY_BUDGET: { - const LatencyBudgetQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_latencyBudget = *p; + if (!m_qos.m_latencyBudget.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_LIVELINESS: { - const LivelinessQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_liveliness = *p; + if (!m_qos.m_liveliness.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_RELIABILITY: { - const ReliabilityQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_reliability = *p; + if (!m_qos.m_reliability.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_LIFESPAN: { - const LifespanQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_lifespan = *p; + if (!m_qos.m_lifespan.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_USER_DATA: { - const UserDataQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_userData = *p; + if (!m_qos.m_userData.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TIME_BASED_FILTER: { - const TimeBasedFilterQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_timeBasedFilter = *p; + if (!m_qos.m_timeBasedFilter.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_OWNERSHIP: { - const OwnershipQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_ownership = *p; + if (!m_qos.m_ownership.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_OWNERSHIP_STRENGTH: { - const OwnershipStrengthQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_ownershipStrength = *p; + if (!m_qos.m_ownershipStrength.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_DESTINATION_ORDER: { - const DestinationOrderQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_destinationOrder = *p; + if (!m_qos.m_destinationOrder.readFromCDRMessage(msg, plength)) + { + return false; + } break; } - case fastdds::dds::PID_PRESENTATION: { - const PresentationQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_presentation = *p; + if (!m_qos.m_presentation.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_PARTITION: { - const PartitionQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_partition = *p; + if (!m_qos.m_partition.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TOPIC_DATA: { - const TopicDataQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_topicData = *p; + if (!m_qos.m_topicData.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_GROUP_DATA: { - const GroupDataQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.m_groupData = *p; + if (!m_qos.m_groupData.readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TOPIC_NAME: { - const ParameterString_t* p = dynamic_cast(param); - assert(p != nullptr); - m_topicName = p->getName(); + ParameterString_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_topicName = p.getName(); break; } case fastdds::dds::PID_TYPE_NAME: { - const ParameterString_t* p = dynamic_cast(param); - assert(p != nullptr); - m_typeName = p->getName(); + ParameterString_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_typeName = p.getName(); break; } case fastdds::dds::PID_PARTICIPANT_GUID: { - const ParameterGuid_t* p = dynamic_cast(param); - assert(p != nullptr); - for (uint8_t i = 0; i < 16; ++i) + ParameterGuid_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) { - if (i < 12) - { - m_RTPSParticipantKey.value[i] = p->guid.guidPrefix.value[i]; - } - else - { - m_RTPSParticipantKey.value[i] = p->guid.entityId.value[i - 12]; - } + return false; } + + m_guid = p.guid; + memcpy(m_RTPSParticipantKey.value, p.guid.guidPrefix.value, 12); + memcpy(m_RTPSParticipantKey.value + 12, p.guid.entityId.value, 4); break; } case fastdds::dds::PID_ENDPOINT_GUID: { - const ParameterGuid_t* p = dynamic_cast(param); - assert(p != nullptr); - m_guid = p->guid; - for (uint8_t i = 0; i < 16; ++i) + ParameterGuid_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) { - if (i < 12) - { - m_key.value[i] = p->guid.guidPrefix.value[i]; - } - else - { - m_key.value[i] = p->guid.entityId.value[i - 12]; - } + return false; } + + memcpy(m_key.value, p.guid.guidPrefix.value, 12); + memcpy(m_key.value + 12, p.guid.entityId.value, 4); break; } case fastdds::dds::PID_PERSISTENCE_GUID: { - const ParameterGuid_t* p = dynamic_cast(param); - assert(p != nullptr); - persistence_guid_ = p->guid; + ParameterGuid_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + persistence_guid_ = p.guid; + break; } - break; case fastdds::dds::PID_UNICAST_LOCATOR: { - const ParameterLocator_t* p = dynamic_cast(param); - assert(p != nullptr); + ParameterLocator_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + Locator_t temp_locator; - if (network.transform_remote_locator(p->locator, temp_locator)) + if (network.transform_remote_locator(p.locator, temp_locator)) { remote_locators_.add_unicast_locator(temp_locator); } @@ -599,10 +630,14 @@ bool WriterProxyData::readFromCDRMessage( } case fastdds::dds::PID_MULTICAST_LOCATOR: { - const ParameterLocator_t* p = dynamic_cast(param); - assert(p != nullptr); + ParameterLocator_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + Locator_t temp_locator; - if (network.transform_remote_locator(p->locator, temp_locator)) + if (network.transform_remote_locator(p.locator, temp_locator)) { remote_locators_.add_multicast_locator(temp_locator); } @@ -610,91 +645,105 @@ bool WriterProxyData::readFromCDRMessage( } case fastdds::dds::PID_KEY_HASH: { - const ParameterKey_t* p = dynamic_cast(param); - assert(p != nullptr); - m_key = p->key; + ParameterKey_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + m_key = p.key; iHandle2GUID(m_guid, m_key); break; } case fastdds::dds::PID_TYPE_IDV1: { - const TypeIdV1* p = dynamic_cast(param); - assert(p != nullptr); - type_id(*p); + if (!type_id().readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TYPE_OBJECTV1: { - const TypeObjectV1* p = dynamic_cast(param); - assert(p != nullptr); - type(*p); + if (!type().readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_TYPE_INFORMATION: { - const xtypes::TypeInformation* p = dynamic_cast(param); - assert(p != nullptr); - type_information(*p); + if (!type_information().readFromCDRMessage(msg, plength)) + { + return false; + } break; } case fastdds::dds::PID_DISABLE_POSITIVE_ACKS: { - const DisablePositiveACKsQosPolicy* p = - dynamic_cast(param); - assert(p != nullptr); - m_qos.m_disablePositiveACKs = *p; + if (!m_qos.m_disablePositiveACKs.readFromCDRMessage(msg, plength)) + { + return false; + } break; } #if HAVE_SECURITY case fastdds::dds::PID_ENDPOINT_SECURITY_INFO: { - const ParameterEndpointSecurityInfo_t* p = - dynamic_cast(param); - assert(p != nullptr); - security_attributes_ = p->security_attributes; - plugin_security_attributes_ = p->plugin_security_attributes; + ParameterEndpointSecurityInfo_t p(pid, plength); + if (!p.readFromCDRMessage(msg, plength)) + { + return false; + } + + security_attributes_ = p.security_attributes; + plugin_security_attributes_ = p.plugin_security_attributes; break; } #endif - case fastdds::dds::PID_DATA_REPRESENTATION: { - const DataRepresentationQosPolicy* p = dynamic_cast(param); - assert(p != nullptr); - m_qos.representation = *p; + if (!m_qos.representation.readFromCDRMessage(msg, plength)) + { + return false; + } break; } - case fastdds::dds::PID_TYPE_CONSISTENCY_ENFORCEMENT: { logError(RTPS_PROXY_DATA, "Received TypeConsistencyEnforcementQos from a writer, but they haven't."); break; } - default: { - //logInfo(RTPS_PROXY_DATA,"Parameter with ID: " << (uint16_t)(param)->Pid <<" NOT CONSIDERED"); break; } } + return true; }; uint32_t qos_size; clear(); - if (ParameterList::readParameterListfromCDRMsg(*msg, param_process, true, qos_size)) + try { - if (m_guid.entityId.value[3] == 0x03) - { - m_topicKind = NO_KEY; - } - else if (m_guid.entityId.value[3] == 0x02) + if (ParameterList::readParameterListfromCDRMsg(*msg, param_process, true, qos_size)) { - m_topicKind = WITH_KEY; + if (m_guid.entityId.value[3] == 0x03) + { + m_topicKind = NO_KEY; + } + else if (m_guid.entityId.value[3] == 0x02) + { + m_topicKind = WITH_KEY; + } + return true; } - - return true; + } + catch (std::bad_alloc& ba) + { + std::cerr << "bad_alloc caught: " << ba.what() << '\n'; } return false; @@ -710,7 +759,7 @@ void WriterProxyData::clear() m_typeName = ""; m_topicName = ""; m_userDefinedId = 0; - m_qos = WriterQos(); + m_qos.clear(); m_typeMaxSerialized = 0; m_topicKind = NO_KEY; persistence_guid_ = c_Guid_Unknown; diff --git a/src/cpp/rtps/builtin/discovery/endpoint/EDP.cpp b/src/cpp/rtps/builtin/discovery/endpoint/EDP.cpp index 07b9cebb07d..883f66eebb8 100644 --- a/src/cpp/rtps/builtin/discovery/endpoint/EDP.cpp +++ b/src/cpp/rtps/builtin/discovery/endpoint/EDP.cpp @@ -59,10 +59,12 @@ EDP::EDP( , mp_RTPSParticipant(part) , temp_reader_proxy_data_( part->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, - part->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators) + part->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators, + part->getRTPSParticipantAttributes().allocation.data_limits) , temp_writer_proxy_data_( part->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, - part->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators) + part->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators, + part->getRTPSParticipantAttributes().allocation.data_limits) { } @@ -620,14 +622,14 @@ bool EDP::validMatching( //Partition check: bool matched = false; - if (wdata->m_qos.m_partition.names_.empty() && rdata->m_qos.m_partition.names_.empty()) + if (wdata->m_qos.m_partition.empty() && rdata->m_qos.m_partition.empty()) { matched = true; } - else if (wdata->m_qos.m_partition.names_.empty() && rdata->m_qos.m_partition.names_.size() > 0) + else if (wdata->m_qos.m_partition.empty() && rdata->m_qos.m_partition.size() > 0) { - for (std::vector::const_iterator rnameit = rdata->m_qos.m_partition.names_.begin(); - rnameit != rdata->m_qos.m_partition.names_.end(); ++rnameit) + for (auto rnameit = rdata->m_qos.m_partition.begin(); + rnameit != rdata->m_qos.m_partition.end(); ++rnameit) { if (rnameit->size() == 0) { @@ -636,10 +638,10 @@ bool EDP::validMatching( } } } - else if (wdata->m_qos.m_partition.names_.size() > 0 && rdata->m_qos.m_partition.names_.empty() ) + else if (wdata->m_qos.m_partition.size() > 0 && rdata->m_qos.m_partition.empty() ) { - for (std::vector::const_iterator wnameit = wdata->m_qos.m_partition.names_.begin(); - wnameit != wdata->m_qos.m_partition.names_.end(); ++wnameit) + for (auto wnameit = wdata->m_qos.m_partition.begin(); + wnameit != wdata->m_qos.m_partition.end(); ++wnameit) { if (wnameit->size() == 0) { @@ -650,13 +652,13 @@ bool EDP::validMatching( } else { - for (std::vector::const_iterator wnameit = wdata->m_qos.m_partition.names_.begin(); - wnameit != wdata->m_qos.m_partition.names_.end(); ++wnameit) + for (auto wnameit = wdata->m_qos.m_partition.begin(); + wnameit != wdata->m_qos.m_partition.end(); ++wnameit) { - for (std::vector::const_iterator rnameit = rdata->m_qos.m_partition.names_.begin(); - rnameit != rdata->m_qos.m_partition.names_.end(); ++rnameit) + for (auto rnameit = rdata->m_qos.m_partition.begin(); + rnameit != rdata->m_qos.m_partition.end(); ++rnameit) { - if (StringMatching::matchString(wnameit->c_str(), rnameit->c_str())) + if (StringMatching::matchString(wnameit->name(), rnameit->name())) { matched = true; break; @@ -819,14 +821,14 @@ bool EDP::validMatching( //Partition check: bool matched = false; - if (rdata->m_qos.m_partition.names_.empty() && wdata->m_qos.m_partition.names_.empty()) + if (rdata->m_qos.m_partition.empty() && wdata->m_qos.m_partition.empty()) { matched = true; } - else if (rdata->m_qos.m_partition.names_.empty() && wdata->m_qos.m_partition.names_.size() > 0) + else if (rdata->m_qos.m_partition.empty() && wdata->m_qos.m_partition.size() > 0) { - for (std::vector::const_iterator rnameit = wdata->m_qos.m_partition.names_.begin(); - rnameit != wdata->m_qos.m_partition.names_.end(); ++rnameit) + for (auto rnameit = wdata->m_qos.m_partition.begin(); + rnameit != wdata->m_qos.m_partition.end(); ++rnameit) { if (rnameit->size() == 0) { @@ -835,10 +837,10 @@ bool EDP::validMatching( } } } - else if (rdata->m_qos.m_partition.names_.size() > 0 && wdata->m_qos.m_partition.names_.empty() ) + else if (rdata->m_qos.m_partition.size() > 0 && wdata->m_qos.m_partition.empty() ) { - for (std::vector::const_iterator wnameit = rdata->m_qos.m_partition.names_.begin(); - wnameit != rdata->m_qos.m_partition.names_.end(); ++wnameit) + for (auto wnameit = rdata->m_qos.m_partition.begin(); + wnameit != rdata->m_qos.m_partition.end(); ++wnameit) { if (wnameit->size() == 0) { @@ -849,13 +851,13 @@ bool EDP::validMatching( } else { - for (std::vector::const_iterator wnameit = rdata->m_qos.m_partition.names_.begin(); - wnameit != rdata->m_qos.m_partition.names_.end(); ++wnameit) + for (auto wnameit = rdata->m_qos.m_partition.begin(); + wnameit != rdata->m_qos.m_partition.end(); ++wnameit) { - for (std::vector::const_iterator rnameit = wdata->m_qos.m_partition.names_.begin(); - rnameit != wdata->m_qos.m_partition.names_.end(); ++rnameit) + for (auto rnameit = wdata->m_qos.m_partition.begin(); + rnameit != wdata->m_qos.m_partition.end(); ++rnameit) { - if (StringMatching::matchString(wnameit->c_str(), rnameit->c_str())) + if (StringMatching::matchString(wnameit->name(), rnameit->name())) { matched = true; break; @@ -892,7 +894,7 @@ bool EDP::pairingReader( for (ResourceLimitedVector::const_iterator pit = mp_PDP->ParticipantProxiesBegin(); pit != mp_PDP->ParticipantProxiesEnd(); ++pit) { - for(auto & pair : *(*pit)->m_writers) + for (auto& pair : *(*pit)->m_writers) { WriterProxyData* wdatait = pair.second; bool valid = validMatching(&rdata, wdatait); @@ -970,7 +972,7 @@ bool EDP::pairingWriter( for (ResourceLimitedVector::const_iterator pit = mp_PDP->ParticipantProxiesBegin(); pit != mp_PDP->ParticipantProxiesEnd(); ++pit) { - for(auto & pair : *(*pit)->m_readers) + for (auto& pair : *(*pit)->m_readers) { ReaderProxyData* rdatait = pair.second; const GUID_t& reader_guid = rdatait->guid(); @@ -1003,7 +1005,7 @@ bool EDP::pairingWriter( const GUID_t& writer_guid = W->getGuid(); const PublicationMatchedStatus& pub_info = - update_publication_matched_status(reader_guid, writer_guid, 1); + update_publication_matched_status(reader_guid, writer_guid, 1); W->getListener()->onWriterMatched(W, pub_info); } } diff --git a/src/cpp/rtps/builtin/discovery/endpoint/EDPServerListeners.cpp b/src/cpp/rtps/builtin/discovery/endpoint/EDPServerListeners.cpp index bd22b3b7576..565849675eb 100644 --- a/src/cpp/rtps/builtin/discovery/endpoint/EDPServerListeners.cpp +++ b/src/cpp/rtps/builtin/discovery/endpoint/EDPServerListeners.cpp @@ -37,23 +37,27 @@ #include namespace eprosima { -namespace fastrtps{ +namespace fastrtps { namespace rtps { -EDPServerPUBListener::EDPServerPUBListener(EDPServer* sedp) - : EDPBasePUBListener(sedp->mp_RTPSParticipant->getAttributes().allocation.locators) +EDPServerPUBListener::EDPServerPUBListener( + EDPServer* sedp) + : EDPBasePUBListener(sedp->mp_RTPSParticipant->getAttributes().allocation.locators, + sedp->mp_RTPSParticipant->getAttributes().allocation.data_limits) , sedp_(sedp) { } -void EDPServerPUBListener::onNewCacheChangeAdded(RTPSReader* reader, const CacheChange_t* const change_in) +void EDPServerPUBListener::onNewCacheChangeAdded( + RTPSReader* reader, + const CacheChange_t* const change_in) { CacheChange_t* change = (CacheChange_t*)change_in; //std::lock_guard guard(*this->sedp_->publications_reader_.first->getMutex()); - logInfo(RTPS_EDP,""); - if(!computeKey(change)) + logInfo(RTPS_EDP, ""); + if (!computeKey(change)) { - logWarning(RTPS_EDP,"Received change with no Key"); + logWarning(RTPS_EDP, "Received change with no Key"); } ReaderHistory* reader_history = sedp_->publications_reader_.second; @@ -65,14 +69,14 @@ void EDPServerPUBListener::onNewCacheChangeAdded(RTPSReader* reader, const Cache return; // already there } - if(change->kind == ALIVE) + if (change->kind == ALIVE) { add_writer_from_change(reader, change, sedp_); } else { //REMOVE WRITER FROM OUR READERS: - logInfo(RTPS_EDP,"Disposed Remote Writer, removing..."); + logInfo(RTPS_EDP, "Disposed Remote Writer, removing..."); GUID_t auxGUID = iHandle2GUID(change->instanceHandle); this->sedp_->mp_PDP->removeWriterProxyData(auxGUID); @@ -86,8 +90,8 @@ void EDPServerPUBListener::onNewCacheChangeAdded(RTPSReader* reader, const Cache } void EDPServerPUBListener::onWriterChangeReceivedByAll( - RTPSWriter *writer, - CacheChange_t *change) + RTPSWriter* writer, + CacheChange_t* change) { (void)writer; @@ -95,29 +99,33 @@ void EDPServerPUBListener::onWriterChangeReceivedByAll( { WriterHistory* writer_history = #if HAVE_SECURITY - writer == sedp_->publications_secure_writer_.first ? - sedp_->publications_secure_writer_.second : + writer == sedp_->publications_secure_writer_.first ? + sedp_->publications_secure_writer_.second : #endif - sedp_->publications_writer_.second; + sedp_->publications_writer_.second; writer_history->remove_change(change); } } -EDPServerSUBListener::EDPServerSUBListener(EDPServer* sedp) - : EDPBaseSUBListener(sedp->mp_RTPSParticipant->getAttributes().allocation.locators) +EDPServerSUBListener::EDPServerSUBListener( + EDPServer* sedp) + : EDPBaseSUBListener(sedp->mp_RTPSParticipant->getAttributes().allocation.locators, + sedp->mp_RTPSParticipant->getAttributes().allocation.data_limits) , sedp_(sedp) { } -void EDPServerSUBListener::onNewCacheChangeAdded(RTPSReader* reader, const CacheChange_t* const change_in) +void EDPServerSUBListener::onNewCacheChangeAdded( + RTPSReader* reader, + const CacheChange_t* const change_in) { CacheChange_t* change = (CacheChange_t*)change_in; //std::lock_guard guard(*this->sedp_->subscriptions_reader_.first->getMutex()); - logInfo(RTPS_EDP,""); - if(!computeKey(change)) + logInfo(RTPS_EDP, ""); + if (!computeKey(change)) { - logWarning(RTPS_EDP,"Received change with no Key"); + logWarning(RTPS_EDP, "Received change with no Key"); } ReaderHistory* reader_history = sedp_->subscriptions_reader_.second; @@ -129,14 +137,14 @@ void EDPServerSUBListener::onNewCacheChangeAdded(RTPSReader* reader, const Cache return; // already there } - if(change->kind == ALIVE) + if (change->kind == ALIVE) { add_reader_from_change(reader, change, sedp_); } else { //REMOVE WRITER FROM OUR READERS: - logInfo(RTPS_EDP,"Disposed Remote Reader, removing..."); + logInfo(RTPS_EDP, "Disposed Remote Reader, removing..."); GUID_t auxGUID = iHandle2GUID(change->instanceHandle); this->sedp_->mp_PDP->removeReaderProxyData(auxGUID); @@ -149,7 +157,6 @@ void EDPServerSUBListener::onNewCacheChangeAdded(RTPSReader* reader, const Cache return; } - void EDPServerSUBListener::onWriterChangeReceivedByAll( RTPSWriter* writer, CacheChange_t* change) @@ -160,10 +167,10 @@ void EDPServerSUBListener::onWriterChangeReceivedByAll( { WriterHistory* writer_history = #if HAVE_SECURITY - writer == sedp_->subscriptions_secure_writer_.first ? - sedp_->subscriptions_secure_writer_.second : + writer == sedp_->subscriptions_secure_writer_.first ? + sedp_->subscriptions_secure_writer_.second : #endif - sedp_->subscriptions_writer_.second; + sedp_->subscriptions_writer_.second; writer_history->remove_change(change); } diff --git a/src/cpp/rtps/builtin/discovery/endpoint/EDPSimple.cpp b/src/cpp/rtps/builtin/discovery/endpoint/EDPSimple.cpp index c7ff9ef19cf..78a119ed23c 100644 --- a/src/cpp/rtps/builtin/discovery/endpoint/EDPSimple.cpp +++ b/src/cpp/rtps/builtin/discovery/endpoint/EDPSimple.cpp @@ -45,8 +45,8 @@ namespace rtps { // Default configuration values for EDP entities. static const Duration_t edp_heartbeat_period{1, 0}; // 1 second static const Duration_t edp_nack_response_delay{0, 100 * 1000 }; // 100 milliseconds -static const Duration_t edp_nack_supression_duration{0, 10*1000}; // 10 milliseconds -static const Duration_t edp_heartbeat_response_delay{0, 10*1000}; // 10 milliseconds +static const Duration_t edp_nack_supression_duration{0, 10 * 1000}; // 10 milliseconds +static const Duration_t edp_heartbeat_response_delay{0, 10 * 1000}; // 10 milliseconds static const int32_t edp_initial_reserved_caches = 20; @@ -54,94 +54,96 @@ static const int32_t edp_initial_reserved_caches = 20; EDPSimple::EDPSimple( PDP* p, RTPSParticipantImpl* part) - : EDP(p,part) + : EDP(p, part) , publications_listener_(nullptr) , subscriptions_listener_(nullptr) , temp_reader_proxy_data_( - part->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, - part->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators) + part->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, + part->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators, + part->getRTPSParticipantAttributes().allocation.data_limits) , temp_writer_proxy_data_( part->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, - part->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators) + part->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators, + part->getRTPSParticipantAttributes().allocation.data_limits) { } EDPSimple::~EDPSimple() { #if HAVE_SECURITY - if(this->publications_secure_writer_.first !=nullptr) + if (this->publications_secure_writer_.first != nullptr) { this->mp_RTPSParticipant->deleteUserEndpoint(publications_secure_writer_.first); delete(publications_secure_writer_.second); } - if(this->publications_secure_reader_.first !=nullptr) + if (this->publications_secure_reader_.first != nullptr) { this->mp_RTPSParticipant->deleteUserEndpoint(publications_secure_reader_.first); delete(publications_secure_reader_.second); } - if(this->subscriptions_secure_writer_.first !=nullptr) + if (this->subscriptions_secure_writer_.first != nullptr) { this->mp_RTPSParticipant->deleteUserEndpoint(subscriptions_secure_writer_.first); delete(subscriptions_secure_writer_.second); } - if(this->subscriptions_secure_reader_.first !=nullptr) + if (this->subscriptions_secure_reader_.first != nullptr) { this->mp_RTPSParticipant->deleteUserEndpoint(subscriptions_secure_reader_.first); delete(subscriptions_secure_reader_.second); } #endif - if(this->publications_reader_.first !=nullptr) + if (this->publications_reader_.first != nullptr) { this->mp_RTPSParticipant->deleteUserEndpoint(publications_reader_.first); delete(publications_reader_.second); } - if(this->subscriptions_reader_.first !=nullptr) + if (this->subscriptions_reader_.first != nullptr) { this->mp_RTPSParticipant->deleteUserEndpoint(subscriptions_reader_.first); delete(subscriptions_reader_.second); } - if(this->publications_writer_.first !=nullptr) + if (this->publications_writer_.first != nullptr) { this->mp_RTPSParticipant->deleteUserEndpoint(publications_writer_.first); delete(publications_writer_.second); } - if(this->subscriptions_writer_.first !=nullptr) + if (this->subscriptions_writer_.first != nullptr) { this->mp_RTPSParticipant->deleteUserEndpoint(subscriptions_writer_.first); delete(subscriptions_writer_.second); } - if(nullptr != publications_listener_) + if (nullptr != publications_listener_) { delete(publications_listener_); } - if(nullptr != subscriptions_listener_) + if (nullptr != subscriptions_listener_) { delete(subscriptions_listener_); } } - -bool EDPSimple::initEDP(BuiltinAttributes& attributes) +bool EDPSimple::initEDP( + BuiltinAttributes& attributes) { - logInfo(RTPS_EDP,"Beginning Simple Endpoint Discovery Protocol"); + logInfo(RTPS_EDP, "Beginning Simple Endpoint Discovery Protocol"); m_discovery = attributes; - if(!createSEDPEndpoints()) + if (!createSEDPEndpoints()) { - logError(RTPS_EDP,"Problem creation SimpleEDP endpoints"); + logError(RTPS_EDP, "Problem creation SimpleEDP endpoints"); return false; } #if HAVE_SECURITY - if(mp_RTPSParticipant->is_secure() && !create_sedp_secure_endpoints()) + if (mp_RTPSParticipant->is_secure() && !create_sedp_secure_endpoints()) { - logError(RTPS_EDP,"Problem creation SimpleEDP endpoints"); + logError(RTPS_EDP, "Problem creation SimpleEDP endpoints"); return false; } #endif @@ -149,25 +151,28 @@ bool EDPSimple::initEDP(BuiltinAttributes& attributes) return true; } -void EDPSimple::set_builtin_reader_history_attributes(HistoryAttributes& attributes) +void EDPSimple::set_builtin_reader_history_attributes( + HistoryAttributes& attributes) { attributes.initialReservedCaches = edp_initial_reserved_caches; attributes.payloadMaxSize = DISCOVERY_SUBSCRIPTION_DATA_MAX_SIZE; attributes.memoryPolicy = mp_PDP->builtin_attributes().readerHistoryMemoryPolicy; } -void EDPSimple::set_builtin_writer_history_attributes(HistoryAttributes& attributes) +void EDPSimple::set_builtin_writer_history_attributes( + HistoryAttributes& attributes) { attributes.initialReservedCaches = edp_initial_reserved_caches; attributes.payloadMaxSize = DISCOVERY_PUBLICATION_DATA_MAX_SIZE; attributes.memoryPolicy = mp_PDP->builtin_attributes().writerHistoryMemoryPolicy; } -void EDPSimple::set_builtin_reader_attributes(ReaderAttributes& attributes) +void EDPSimple::set_builtin_reader_attributes( + ReaderAttributes& attributes) { // Matched writers will depend on total number of participants attributes.matched_writers_allocation = - mp_PDP->getRTPSParticipant()->getRTPSParticipantAttributes().allocation.participants; + mp_PDP->getRTPSParticipant()->getRTPSParticipantAttributes().allocation.participants; // As participants allocation policy includes the local participant, one has to be substracted if (attributes.matched_writers_allocation.initial > 1) @@ -175,7 +180,7 @@ void EDPSimple::set_builtin_reader_attributes(ReaderAttributes& attributes) attributes.matched_writers_allocation.initial--; } if ((attributes.matched_writers_allocation.maximum > 1) && - (attributes.matched_writers_allocation.maximum < std::numeric_limits::max())) + (attributes.matched_writers_allocation.maximum < std::numeric_limits::max())) { attributes.matched_writers_allocation.maximum--; } @@ -204,11 +209,12 @@ void EDPSimple::set_builtin_reader_attributes(ReaderAttributes& attributes) attributes.expectsInlineQos = false; } -void EDPSimple::set_builtin_writer_attributes(WriterAttributes& attributes) +void EDPSimple::set_builtin_writer_attributes( + WriterAttributes& attributes) { // Matched readers will depend on total number of participants attributes.matched_readers_allocation = - mp_PDP->getRTPSParticipant()->getRTPSParticipantAttributes().allocation.participants; + mp_PDP->getRTPSParticipant()->getRTPSParticipantAttributes().allocation.participants; // As participants allocation policy includes the local participant, one has to be substracted if (attributes.matched_readers_allocation.initial > 1) @@ -216,7 +222,7 @@ void EDPSimple::set_builtin_writer_attributes(WriterAttributes& attributes) attributes.matched_readers_allocation.initial--; } if ((attributes.matched_readers_allocation.maximum > 1) && - (attributes.matched_readers_allocation.maximum < std::numeric_limits::max())) + (attributes.matched_readers_allocation.maximum < std::numeric_limits::max())) { attributes.matched_readers_allocation.maximum--; } @@ -245,7 +251,7 @@ void EDPSimple::set_builtin_writer_attributes(WriterAttributes& attributes) // Set as asynchronous if there is a throughput controller installed if (mp_RTPSParticipant->getRTPSParticipantAttributes().throughputController.bytesPerPeriod != UINT32_MAX && - mp_RTPSParticipant->getRTPSParticipantAttributes().throughputController.periodMillisecs != 0) + mp_RTPSParticipant->getRTPSParticipantAttributes().throughputController.periodMillisecs != 0) { attributes.mode = ASYNCHRONOUS_WRITER; } @@ -269,16 +275,16 @@ bool EDPSimple::createSEDPEndpoints() publications_listener_ = new EDPSimplePUBListener(this); subscriptions_listener_ = new EDPSimpleSUBListener(this); - if(m_discovery.discovery_config.m_simpleEDP.use_PublicationWriterANDSubscriptionReader) + if (m_discovery.discovery_config.m_simpleEDP.use_PublicationWriterANDSubscriptionReader) { publications_writer_.second = new WriterHistory(writer_history_att); - created &=this->mp_RTPSParticipant->createWriter(&waux, watt, publications_writer_.second, - publications_listener_, c_EntityId_SEDPPubWriter, true); + created &= this->mp_RTPSParticipant->createWriter(&waux, watt, publications_writer_.second, + publications_listener_, c_EntityId_SEDPPubWriter, true); - if(created) + if (created) { publications_writer_.first = dynamic_cast(waux); - logInfo(RTPS_EDP,"SEDP Publication Writer created"); + logInfo(RTPS_EDP, "SEDP Publication Writer created"); } else { @@ -287,13 +293,13 @@ bool EDPSimple::createSEDPEndpoints() } subscriptions_reader_.second = new ReaderHistory(reader_history_att); - created &=this->mp_RTPSParticipant->createReader(&raux, ratt, subscriptions_reader_.second, - subscriptions_listener_, c_EntityId_SEDPSubReader, true); + created &= this->mp_RTPSParticipant->createReader(&raux, ratt, subscriptions_reader_.second, + subscriptions_listener_, c_EntityId_SEDPSubReader, true); - if(created) + if (created) { subscriptions_reader_.first = dynamic_cast(raux); - logInfo(RTPS_EDP,"SEDP Subscription Reader created"); + logInfo(RTPS_EDP, "SEDP Subscription Reader created"); } else { @@ -301,16 +307,16 @@ bool EDPSimple::createSEDPEndpoints() subscriptions_reader_.second = nullptr; } } - if(m_discovery.discovery_config.m_simpleEDP.use_PublicationReaderANDSubscriptionWriter) + if (m_discovery.discovery_config.m_simpleEDP.use_PublicationReaderANDSubscriptionWriter) { publications_reader_.second = new ReaderHistory(reader_history_att); - created &=this->mp_RTPSParticipant->createReader(&raux, ratt, publications_reader_.second, - publications_listener_, c_EntityId_SEDPPubReader, true); + created &= this->mp_RTPSParticipant->createReader(&raux, ratt, publications_reader_.second, + publications_listener_, c_EntityId_SEDPPubReader, true); - if(created) + if (created) { publications_reader_.first = dynamic_cast(raux); - logInfo(RTPS_EDP,"SEDP Publication Reader created"); + logInfo(RTPS_EDP, "SEDP Publication Reader created"); } else @@ -320,13 +326,13 @@ bool EDPSimple::createSEDPEndpoints() } subscriptions_writer_.second = new WriterHistory(writer_history_att); - created &=this->mp_RTPSParticipant->createWriter(&waux, watt, subscriptions_writer_.second, - subscriptions_listener_, c_EntityId_SEDPSubWriter, true); + created &= this->mp_RTPSParticipant->createWriter(&waux, watt, subscriptions_writer_.second, + subscriptions_listener_, c_EntityId_SEDPSubWriter, true); - if(created) + if (created) { subscriptions_writer_.first = dynamic_cast(waux); - logInfo(RTPS_EDP,"SEDP Subscription Writer created"); + logInfo(RTPS_EDP, "SEDP Subscription Writer created"); } else @@ -335,7 +341,7 @@ bool EDPSimple::createSEDPEndpoints() subscriptions_writer_.second = nullptr; } } - logInfo(RTPS_EDP,"Creation finished"); + logInfo(RTPS_EDP, "Creation finished"); return created; } @@ -370,29 +376,29 @@ bool EDPSimple::create_sedp_secure_endpoints() if (plugin_part_attr.is_discovery_encrypted) { ratt.endpoint.security_attributes().plugin_endpoint_attributes |= - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; watt.endpoint.security_attributes().plugin_endpoint_attributes |= - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; } if (plugin_part_attr.is_discovery_origin_authenticated) { ratt.endpoint.security_attributes().plugin_endpoint_attributes |= - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ORIGIN_AUTHENTICATED; + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ORIGIN_AUTHENTICATED; watt.endpoint.security_attributes().plugin_endpoint_attributes |= - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ORIGIN_AUTHENTICATED; + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ORIGIN_AUTHENTICATED; } } - if(m_discovery.discovery_config.m_simpleEDP.enable_builtin_secure_publications_writer_and_subscriptions_reader) + if (m_discovery.discovery_config.m_simpleEDP.enable_builtin_secure_publications_writer_and_subscriptions_reader) { publications_secure_writer_.second = new WriterHistory(writer_history_att); - created &=this->mp_RTPSParticipant->createWriter(&waux, watt, publications_secure_writer_.second, - publications_listener_, sedp_builtin_publications_secure_writer, true); + created &= this->mp_RTPSParticipant->createWriter(&waux, watt, publications_secure_writer_.second, + publications_listener_, sedp_builtin_publications_secure_writer, true); - if(created) + if (created) { publications_secure_writer_.first = dynamic_cast(waux); - logInfo(RTPS_EDP,"SEDP Publication Writer created"); + logInfo(RTPS_EDP, "SEDP Publication Writer created"); } else { @@ -400,13 +406,13 @@ bool EDPSimple::create_sedp_secure_endpoints() publications_secure_writer_.second = nullptr; } subscriptions_secure_reader_.second = new ReaderHistory(reader_history_att); - created &=this->mp_RTPSParticipant->createReader(&raux, ratt, subscriptions_secure_reader_.second, - subscriptions_listener_, sedp_builtin_subscriptions_secure_reader, true); + created &= this->mp_RTPSParticipant->createReader(&raux, ratt, subscriptions_secure_reader_.second, + subscriptions_listener_, sedp_builtin_subscriptions_secure_reader, true); - if(created) + if (created) { subscriptions_secure_reader_.first = dynamic_cast(raux); - logInfo(RTPS_EDP,"SEDP Subscription Reader created"); + logInfo(RTPS_EDP, "SEDP Subscription Reader created"); } else { @@ -415,16 +421,16 @@ bool EDPSimple::create_sedp_secure_endpoints() } } - if(m_discovery.discovery_config.m_simpleEDP.enable_builtin_secure_subscriptions_writer_and_publications_reader) + if (m_discovery.discovery_config.m_simpleEDP.enable_builtin_secure_subscriptions_writer_and_publications_reader) { publications_secure_reader_.second = new ReaderHistory(reader_history_att); - created &=this->mp_RTPSParticipant->createReader(&raux, ratt, publications_secure_reader_.second, - publications_listener_, sedp_builtin_publications_secure_reader, true); + created &= this->mp_RTPSParticipant->createReader(&raux, ratt, publications_secure_reader_.second, + publications_listener_, sedp_builtin_publications_secure_reader, true); - if(created) + if (created) { publications_secure_reader_.first = dynamic_cast(raux); - logInfo(RTPS_EDP,"SEDP Publication Reader created"); + logInfo(RTPS_EDP, "SEDP Publication Reader created"); } else @@ -434,13 +440,13 @@ bool EDPSimple::create_sedp_secure_endpoints() } subscriptions_secure_writer_.second = new WriterHistory(writer_history_att); - created &=this->mp_RTPSParticipant->createWriter(&waux, watt, subscriptions_secure_writer_.second, - subscriptions_listener_, sedp_builtin_subscriptions_secure_writer, true); + created &= this->mp_RTPSParticipant->createWriter(&waux, watt, subscriptions_secure_writer_.second, + subscriptions_listener_, sedp_builtin_subscriptions_secure_writer, true); - if(created) + if (created) { subscriptions_secure_writer_.first = dynamic_cast(waux); - logInfo(RTPS_EDP,"SEDP Subscription Writer created"); + logInfo(RTPS_EDP, "SEDP Subscription Writer created"); } else @@ -449,32 +455,37 @@ bool EDPSimple::create_sedp_secure_endpoints() subscriptions_secure_writer_.second = nullptr; } } - logInfo(RTPS_EDP,"Creation finished"); + logInfo(RTPS_EDP, "Creation finished"); return created; } + #endif -bool EDPSimple::processLocalReaderProxyData(RTPSReader* local_reader, ReaderProxyData* rdata) +bool EDPSimple::processLocalReaderProxyData( + RTPSReader* local_reader, + ReaderProxyData* rdata) { - logInfo(RTPS_EDP,rdata->guid().entityId); + logInfo(RTPS_EDP, rdata->guid().entityId); (void)local_reader; auto* writer = &subscriptions_writer_; #if HAVE_SECURITY - if(local_reader->getAttributes().security_attributes().is_discovery_protected) + if (local_reader->getAttributes().security_attributes().is_discovery_protected) { writer = &subscriptions_secure_writer_; } #endif - if(writer->first != nullptr) + if (writer->first != nullptr) { // TODO(Ricardo) Write a getCdrSerializedPayload for ReaderProxyData. - CacheChange_t* change = writer->first->new_change([]() -> uint32_t {return DISCOVERY_SUBSCRIPTION_DATA_MAX_SIZE;}, - ALIVE,rdata->key()); + CacheChange_t* change = writer->first->new_change([]() -> uint32_t { + return DISCOVERY_SUBSCRIPTION_DATA_MAX_SIZE; + }, + ALIVE, rdata->key()); - if(change !=nullptr) + if (change != nullptr) { CDRMessage_t aux_msg(change->serializedPayload); @@ -491,9 +502,9 @@ bool EDPSimple::processLocalReaderProxyData(RTPSReader* local_reader, ReaderProx { std::unique_lock lock(*writer->second->getMutex()); - for(auto ch = writer->second->changesBegin(); ch != writer->second->changesEnd(); ++ch) + for (auto ch = writer->second->changesBegin(); ch != writer->second->changesEnd(); ++ch) { - if((*ch)->instanceHandle == change->instanceHandle) + if ((*ch)->instanceHandle == change->instanceHandle) { writer->second->remove_change(*ch); break; @@ -512,7 +523,9 @@ bool EDPSimple::processLocalReaderProxyData(RTPSReader* local_reader, ReaderProx return true; } -bool EDPSimple::processLocalWriterProxyData(RTPSWriter* local_writer, WriterProxyData* wdata) +bool EDPSimple::processLocalWriterProxyData( + RTPSWriter* local_writer, + WriterProxyData* wdata) { logInfo(RTPS_EDP, wdata->guid().entityId); (void)local_writer; @@ -520,17 +533,19 @@ bool EDPSimple::processLocalWriterProxyData(RTPSWriter* local_writer, WriterProx auto* writer = &publications_writer_; #if HAVE_SECURITY - if(local_writer->getAttributes().security_attributes().is_discovery_protected) + if (local_writer->getAttributes().security_attributes().is_discovery_protected) { writer = &publications_secure_writer_; } #endif - if(writer->first !=nullptr) + if (writer->first != nullptr) { - CacheChange_t* change = writer->first->new_change([]() -> uint32_t {return DISCOVERY_PUBLICATION_DATA_MAX_SIZE;}, - ALIVE, wdata->key()); - if(change != nullptr) + CacheChange_t* change = writer->first->new_change([]() -> uint32_t { + return DISCOVERY_PUBLICATION_DATA_MAX_SIZE; + }, + ALIVE, wdata->key()); + if (change != nullptr) { CDRMessage_t aux_msg(change->serializedPayload); @@ -547,9 +562,9 @@ bool EDPSimple::processLocalWriterProxyData(RTPSWriter* local_writer, WriterProx { std::unique_lock lock(*writer->second->getMutex()); - for(auto ch = writer->second->changesBegin(); ch != writer->second->changesEnd(); ++ch) + for (auto ch = writer->second->changesBegin(); ch != writer->second->changesEnd(); ++ch) { - if((*ch)->instanceHandle == change->instanceHandle) + if ((*ch)->instanceHandle == change->instanceHandle) { writer->second->remove_change(*ch); break; @@ -566,32 +581,35 @@ bool EDPSimple::processLocalWriterProxyData(RTPSWriter* local_writer, WriterProx return true; } -bool EDPSimple::removeLocalWriter(RTPSWriter* W) +bool EDPSimple::removeLocalWriter( + RTPSWriter* W) { - logInfo(RTPS_EDP,W->getGuid().entityId); + logInfo(RTPS_EDP, W->getGuid().entityId); auto* writer = &publications_writer_; #if HAVE_SECURITY - if(W->getAttributes().security_attributes().is_discovery_protected) + if (W->getAttributes().security_attributes().is_discovery_protected) { writer = &publications_secure_writer_; } #endif - if(writer->first!=nullptr) + if (writer->first != nullptr) { InstanceHandle_t iH; iH = W->getGuid(); - CacheChange_t* change = writer->first->new_change([]() -> uint32_t {return DISCOVERY_PUBLICATION_DATA_MAX_SIZE;}, - NOT_ALIVE_DISPOSED_UNREGISTERED,iH); - if(change != nullptr) + CacheChange_t* change = writer->first->new_change([]() -> uint32_t { + return DISCOVERY_PUBLICATION_DATA_MAX_SIZE; + }, + NOT_ALIVE_DISPOSED_UNREGISTERED, iH); + if (change != nullptr) { { std::lock_guard guard(*writer->second->getMutex()); - for(auto ch = writer->second->changesBegin(); ch != writer->second->changesEnd(); ++ch) + for (auto ch = writer->second->changesBegin(); ch != writer->second->changesEnd(); ++ch) { - if((*ch)->instanceHandle == change->instanceHandle) + if ((*ch)->instanceHandle == change->instanceHandle) { writer->second->remove_change(*ch); break; @@ -606,32 +624,35 @@ bool EDPSimple::removeLocalWriter(RTPSWriter* W) return mp_PDP->removeWriterProxyData(W->getGuid()); } -bool EDPSimple::removeLocalReader(RTPSReader* R) +bool EDPSimple::removeLocalReader( + RTPSReader* R) { - logInfo(RTPS_EDP,R->getGuid().entityId); + logInfo(RTPS_EDP, R->getGuid().entityId); auto* writer = &subscriptions_writer_; #if HAVE_SECURITY - if(R->getAttributes().security_attributes().is_discovery_protected) + if (R->getAttributes().security_attributes().is_discovery_protected) { writer = &subscriptions_secure_writer_; } #endif - if(writer->first!=nullptr) + if (writer->first != nullptr) { InstanceHandle_t iH; iH = (R->getGuid()); - CacheChange_t* change = writer->first->new_change([]() -> uint32_t {return DISCOVERY_SUBSCRIPTION_DATA_MAX_SIZE;}, - NOT_ALIVE_DISPOSED_UNREGISTERED,iH); - if(change != nullptr) + CacheChange_t* change = writer->first->new_change([]() -> uint32_t { + return DISCOVERY_SUBSCRIPTION_DATA_MAX_SIZE; + }, + NOT_ALIVE_DISPOSED_UNREGISTERED, iH); + if (change != nullptr) { { std::lock_guard guard(*writer->second->getMutex()); - for(auto ch = writer->second->changesBegin(); ch != writer->second->changesEnd(); ++ch) + for (auto ch = writer->second->changesBegin(); ch != writer->second->changesEnd(); ++ch) { - if((*ch)->instanceHandle == change->instanceHandle) + if ((*ch)->instanceHandle == change->instanceHandle) { writer->second->remove_change(*ch); break; @@ -645,15 +666,16 @@ bool EDPSimple::removeLocalReader(RTPSReader* R) return mp_PDP->removeReaderProxyData(R->getGuid()); } -void EDPSimple::assignRemoteEndpoints(const ParticipantProxyData& pdata) +void EDPSimple::assignRemoteEndpoints( + const ParticipantProxyData& pdata) { - logInfo(RTPS_EDP,"New DPD received, adding remote endpoints to our SimpleEDP endpoints"); + logInfo(RTPS_EDP, "New DPD received, adding remote endpoints to our SimpleEDP endpoints"); const NetworkFactory& network = mp_RTPSParticipant->network_factory(); uint32_t endp = pdata.m_availableBuiltinEndpoints; uint32_t auxendp = endp; bool use_multicast_locators = !mp_PDP->getRTPSParticipant()->getAttributes().builtin.avoid_builtin_multicast || - pdata.metatraffic_locators.unicast.empty(); - auxendp &=DISC_BUILTIN_ENDPOINT_PUBLICATION_ANNOUNCER; + pdata.metatraffic_locators.unicast.empty(); + auxendp &= DISC_BUILTIN_ENDPOINT_PUBLICATION_ANNOUNCER; std::lock_guard data_guard(temp_data_lock_); @@ -673,20 +695,20 @@ void EDPSimple::assignRemoteEndpoints(const ParticipantProxyData& pdata) //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp!=0 && publications_reader_.first!=nullptr) //Exist Pub Writer and i have pub reader + if (auxendp != 0 && publications_reader_.first != nullptr) //Exist Pub Writer and i have pub reader { - logInfo(RTPS_EDP,"Adding SEDP Pub Writer to my Pub Reader"); + logInfo(RTPS_EDP, "Adding SEDP Pub Writer to my Pub Reader"); temp_writer_proxy_data_.guid().entityId = c_EntityId_SEDPPubWriter; temp_writer_proxy_data_.set_persistence_entity_id(c_EntityId_SEDPPubWriter); publications_reader_.first->matched_writer_add(temp_writer_proxy_data_); } auxendp = endp; - auxendp &=DISC_BUILTIN_ENDPOINT_PUBLICATION_DETECTOR; + auxendp &= DISC_BUILTIN_ENDPOINT_PUBLICATION_DETECTOR; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp!=0 && publications_writer_.first!=nullptr) //Exist Pub Detector + if (auxendp != 0 && publications_writer_.first != nullptr) //Exist Pub Detector { - logInfo(RTPS_EDP,"Adding SEDP Pub Reader to my Pub Writer"); + logInfo(RTPS_EDP, "Adding SEDP Pub Reader to my Pub Writer"); temp_reader_proxy_data_.guid().entityId = c_EntityId_SEDPPubReader; publications_writer_.first->matched_reader_add(temp_reader_proxy_data_); } @@ -694,9 +716,9 @@ void EDPSimple::assignRemoteEndpoints(const ParticipantProxyData& pdata) auxendp &= DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_ANNOUNCER; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp!=0 && subscriptions_reader_.first!=nullptr) //Exist Pub Announcer + if (auxendp != 0 && subscriptions_reader_.first != nullptr) //Exist Pub Announcer { - logInfo(RTPS_EDP,"Adding SEDP Sub Writer to my Sub Reader"); + logInfo(RTPS_EDP, "Adding SEDP Sub Writer to my Sub Reader"); temp_writer_proxy_data_.guid().entityId = c_EntityId_SEDPSubWriter; temp_writer_proxy_data_.set_persistence_entity_id(c_EntityId_SEDPSubWriter); subscriptions_reader_.first->matched_writer_add(temp_writer_proxy_data_); @@ -705,9 +727,9 @@ void EDPSimple::assignRemoteEndpoints(const ParticipantProxyData& pdata) auxendp &= DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_DETECTOR; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp!=0 && subscriptions_writer_.first!=nullptr) //Exist Pub Announcer + if (auxendp != 0 && subscriptions_writer_.first != nullptr) //Exist Pub Announcer { - logInfo(RTPS_EDP,"Adding SEDP Sub Reader to my Sub Writer"); + logInfo(RTPS_EDP, "Adding SEDP Sub Reader to my Sub Writer"); temp_reader_proxy_data_.guid().entityId = c_EntityId_SEDPSubReader; subscriptions_writer_.first->matched_reader_add(temp_reader_proxy_data_); } @@ -717,12 +739,12 @@ void EDPSimple::assignRemoteEndpoints(const ParticipantProxyData& pdata) auxendp &= DISC_BUILTIN_ENDPOINT_PUBLICATION_SECURE_ANNOUNCER; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp != 0 && publications_secure_reader_.first != nullptr) + if (auxendp != 0 && publications_secure_reader_.first != nullptr) { temp_writer_proxy_data_.guid().entityId = sedp_builtin_publications_secure_writer; temp_writer_proxy_data_.set_persistence_entity_id(sedp_builtin_publications_secure_writer); - if(!mp_RTPSParticipant->security_manager().discovered_builtin_writer( + if (!mp_RTPSParticipant->security_manager().discovered_builtin_writer( publications_secure_reader_.first->getGuid(), pdata.m_guid, temp_writer_proxy_data_, publications_secure_reader_.first->getAttributes().security_attributes())) { @@ -735,10 +757,10 @@ void EDPSimple::assignRemoteEndpoints(const ParticipantProxyData& pdata) auxendp &= DISC_BUILTIN_ENDPOINT_PUBLICATION_SECURE_DETECTOR; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp != 0 && publications_secure_writer_.first!=nullptr) + if (auxendp != 0 && publications_secure_writer_.first != nullptr) { temp_reader_proxy_data_.guid().entityId = sedp_builtin_publications_secure_reader; - if(!mp_RTPSParticipant->security_manager().discovered_builtin_reader( + if (!mp_RTPSParticipant->security_manager().discovered_builtin_reader( publications_secure_writer_.first->getGuid(), pdata.m_guid, temp_reader_proxy_data_, publications_secure_writer_.first->getAttributes().security_attributes())) { @@ -751,12 +773,12 @@ void EDPSimple::assignRemoteEndpoints(const ParticipantProxyData& pdata) auxendp &= DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_SECURE_ANNOUNCER; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp != 0 && subscriptions_secure_reader_.first != nullptr) + if (auxendp != 0 && subscriptions_secure_reader_.first != nullptr) { temp_writer_proxy_data_.guid().entityId = sedp_builtin_subscriptions_secure_writer; temp_writer_proxy_data_.set_persistence_entity_id(sedp_builtin_subscriptions_secure_writer); - if(!mp_RTPSParticipant->security_manager().discovered_builtin_writer( + if (!mp_RTPSParticipant->security_manager().discovered_builtin_writer( subscriptions_secure_reader_.first->getGuid(), pdata.m_guid, temp_writer_proxy_data_, subscriptions_secure_reader_.first->getAttributes().security_attributes())) { @@ -769,11 +791,11 @@ void EDPSimple::assignRemoteEndpoints(const ParticipantProxyData& pdata) auxendp &= DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_SECURE_DETECTOR; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp != 0 && subscriptions_secure_writer_.first!=nullptr) + if (auxendp != 0 && subscriptions_secure_writer_.first != nullptr) { - logInfo(RTPS_EDP,"Adding SEDP Sub Reader to my Sub Writer"); + logInfo(RTPS_EDP, "Adding SEDP Sub Reader to my Sub Writer"); temp_reader_proxy_data_.guid().entityId = sedp_builtin_subscriptions_secure_reader; - if(!mp_RTPSParticipant->security_manager().discovered_builtin_reader( + if (!mp_RTPSParticipant->security_manager().discovered_builtin_reader( subscriptions_secure_writer_.first->getGuid(), pdata.m_guid, temp_reader_proxy_data_, subscriptions_secure_writer_.first->getAttributes().security_attributes())) { @@ -784,28 +806,29 @@ void EDPSimple::assignRemoteEndpoints(const ParticipantProxyData& pdata) #endif } -void EDPSimple::removeRemoteEndpoints(ParticipantProxyData* pdata) +void EDPSimple::removeRemoteEndpoints( + ParticipantProxyData* pdata) { - logInfo(RTPS_EDP,"For RTPSParticipant: "<m_guid); + logInfo(RTPS_EDP, "For RTPSParticipant: " << pdata->m_guid); GUID_t tmp_guid; tmp_guid.guidPrefix = pdata->m_guid.guidPrefix; uint32_t endp = pdata->m_availableBuiltinEndpoints; uint32_t auxendp = endp; - auxendp &=DISC_BUILTIN_ENDPOINT_PUBLICATION_ANNOUNCER; + auxendp &= DISC_BUILTIN_ENDPOINT_PUBLICATION_ANNOUNCER; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp!=0 && publications_reader_.first!=nullptr) //Exist Pub Writer and i have pub reader + if (auxendp != 0 && publications_reader_.first != nullptr) //Exist Pub Writer and i have pub reader { tmp_guid.entityId = c_EntityId_SEDPPubWriter; publications_reader_.first->matched_writer_remove(tmp_guid); } auxendp = endp; - auxendp &=DISC_BUILTIN_ENDPOINT_PUBLICATION_DETECTOR; + auxendp &= DISC_BUILTIN_ENDPOINT_PUBLICATION_DETECTOR; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp!=0 && publications_writer_.first!=nullptr) //Exist Pub Detector + if (auxendp != 0 && publications_writer_.first != nullptr) //Exist Pub Detector { tmp_guid.entityId = c_EntityId_SEDPPubReader; publications_writer_.first->matched_reader_remove(tmp_guid); @@ -814,9 +837,9 @@ void EDPSimple::removeRemoteEndpoints(ParticipantProxyData* pdata) auxendp &= DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_ANNOUNCER; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp!=0 && subscriptions_reader_.first!=nullptr) //Exist Pub Announcer + if (auxendp != 0 && subscriptions_reader_.first != nullptr) //Exist Pub Announcer { - logInfo(RTPS_EDP,"Adding SEDP Sub Writer to my Sub Reader"); + logInfo(RTPS_EDP, "Adding SEDP Sub Writer to my Sub Reader"); tmp_guid.entityId = c_EntityId_SEDPSubWriter; subscriptions_reader_.first->matched_writer_remove(tmp_guid); } @@ -824,9 +847,9 @@ void EDPSimple::removeRemoteEndpoints(ParticipantProxyData* pdata) auxendp &= DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_DETECTOR; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp!=0 && subscriptions_writer_.first!=nullptr) //Exist Pub Announcer + if (auxendp != 0 && subscriptions_writer_.first != nullptr) //Exist Pub Announcer { - logInfo(RTPS_EDP,"Adding SEDP Sub Reader to my Sub Writer"); + logInfo(RTPS_EDP, "Adding SEDP Sub Reader to my Sub Writer"); tmp_guid.entityId = c_EntityId_SEDPSubReader; subscriptions_writer_.first->matched_reader_remove(tmp_guid); } @@ -836,13 +859,13 @@ void EDPSimple::removeRemoteEndpoints(ParticipantProxyData* pdata) auxendp &= DISC_BUILTIN_ENDPOINT_PUBLICATION_SECURE_ANNOUNCER; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp != 0 && publications_secure_reader_.first != nullptr) + if (auxendp != 0 && publications_secure_reader_.first != nullptr) { tmp_guid.entityId = sedp_builtin_publications_secure_writer; - if(publications_secure_reader_.first->matched_writer_remove(tmp_guid)) + if (publications_secure_reader_.first->matched_writer_remove(tmp_guid)) { mp_RTPSParticipant->security_manager().remove_writer( - publications_secure_reader_.first->getGuid(), pdata->m_guid, tmp_guid); + publications_secure_reader_.first->getGuid(), pdata->m_guid, tmp_guid); } } @@ -850,13 +873,13 @@ void EDPSimple::removeRemoteEndpoints(ParticipantProxyData* pdata) auxendp &= DISC_BUILTIN_ENDPOINT_PUBLICATION_SECURE_DETECTOR; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp != 0 && publications_secure_writer_.first != nullptr) + if (auxendp != 0 && publications_secure_writer_.first != nullptr) { tmp_guid.entityId = sedp_builtin_publications_secure_reader; - if(publications_secure_writer_.first->matched_reader_remove(tmp_guid)) + if (publications_secure_writer_.first->matched_reader_remove(tmp_guid)) { mp_RTPSParticipant->security_manager().remove_reader( - publications_secure_writer_.first->getGuid(), pdata->m_guid, tmp_guid); + publications_secure_writer_.first->getGuid(), pdata->m_guid, tmp_guid); } } @@ -864,34 +887,35 @@ void EDPSimple::removeRemoteEndpoints(ParticipantProxyData* pdata) auxendp &= DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_SECURE_ANNOUNCER; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp != 0 && subscriptions_secure_reader_.first != nullptr) + if (auxendp != 0 && subscriptions_secure_reader_.first != nullptr) { - logInfo(RTPS_EDP,"Adding SEDP Sub Writer to my Sub Reader"); + logInfo(RTPS_EDP, "Adding SEDP Sub Writer to my Sub Reader"); tmp_guid.entityId = sedp_builtin_subscriptions_secure_writer; - if(subscriptions_secure_reader_.first->matched_writer_remove(tmp_guid)) + if (subscriptions_secure_reader_.first->matched_writer_remove(tmp_guid)) { mp_RTPSParticipant->security_manager().remove_writer( - subscriptions_secure_reader_.first->getGuid(), pdata->m_guid, tmp_guid); + subscriptions_secure_reader_.first->getGuid(), pdata->m_guid, tmp_guid); } } auxendp = endp; auxendp &= DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_SECURE_DETECTOR; //FIXME: FIX TO NOT FAIL WITH BAD BUILTIN ENDPOINT SET //auxendp = 1; - if(auxendp != 0 && subscriptions_secure_writer_.first!=nullptr) + if (auxendp != 0 && subscriptions_secure_writer_.first != nullptr) { - logInfo(RTPS_EDP,"Adding SEDP Sub Reader to my Sub Writer"); + logInfo(RTPS_EDP, "Adding SEDP Sub Reader to my Sub Writer"); tmp_guid.entityId = sedp_builtin_subscriptions_secure_reader; - if(subscriptions_secure_writer_.first->matched_reader_remove(tmp_guid)) + if (subscriptions_secure_writer_.first->matched_reader_remove(tmp_guid)) { mp_RTPSParticipant->security_manager().remove_reader( - subscriptions_secure_writer_.first->getGuid(), pdata->m_guid, tmp_guid); + subscriptions_secure_writer_.first->getGuid(), pdata->m_guid, tmp_guid); } } #endif } -bool EDPSimple::areRemoteEndpointsMatched(const ParticipantProxyData* pdata) +bool EDPSimple::areRemoteEndpointsMatched( + const ParticipantProxyData* pdata) { uint32_t endp = pdata->m_availableBuiltinEndpoints; @@ -904,7 +928,9 @@ bool EDPSimple::areRemoteEndpointsMatched(const ParticipantProxyData* pdata) wguid.entityId = c_EntityId_SEDPPubWriter; if (!publications_reader_.first->matched_writer_is_matched(wguid)) + { return false; + } } auxendp = endp; @@ -916,7 +942,9 @@ bool EDPSimple::areRemoteEndpointsMatched(const ParticipantProxyData* pdata) rguid.entityId = c_EntityId_SEDPPubReader; if (!publications_writer_.first->matched_reader_is_matched(rguid)) + { return false; + } } auxendp = endp; @@ -928,7 +956,9 @@ bool EDPSimple::areRemoteEndpointsMatched(const ParticipantProxyData* pdata) wguid.entityId = c_EntityId_SEDPSubWriter; if (!subscriptions_reader_.first->matched_writer_is_matched(wguid)) + { return false; + } } auxendp = endp; @@ -940,24 +970,27 @@ bool EDPSimple::areRemoteEndpointsMatched(const ParticipantProxyData* pdata) rguid.entityId = c_EntityId_SEDPSubReader; if (!subscriptions_writer_.first->matched_reader_is_matched(rguid)) + { return false; + } } return true; } #if HAVE_SECURITY -bool EDPSimple::pairing_remote_writer_with_local_builtin_reader_after_security(const GUID_t& local_reader, +bool EDPSimple::pairing_remote_writer_with_local_builtin_reader_after_security( + const GUID_t& local_reader, const WriterProxyData& remote_writer_data) { bool returned_value = false; - if(local_reader.entityId == sedp_builtin_publications_secure_reader) + if (local_reader.entityId == sedp_builtin_publications_secure_reader) { publications_secure_reader_.first->matched_writer_add(remote_writer_data); returned_value = true; } - else if(local_reader.entityId == sedp_builtin_subscriptions_secure_reader) + else if (local_reader.entityId == sedp_builtin_subscriptions_secure_reader) { subscriptions_secure_reader_.first->matched_writer_add(remote_writer_data); returned_value = true; @@ -966,17 +999,18 @@ bool EDPSimple::pairing_remote_writer_with_local_builtin_reader_after_security(c return returned_value; } -bool EDPSimple::pairing_remote_reader_with_local_builtin_writer_after_security(const GUID_t& local_writer, +bool EDPSimple::pairing_remote_reader_with_local_builtin_writer_after_security( + const GUID_t& local_writer, const ReaderProxyData& remote_reader_data) { bool returned_value = false; - if(local_writer.entityId == sedp_builtin_publications_secure_writer) + if (local_writer.entityId == sedp_builtin_publications_secure_writer) { publications_secure_writer_.first->matched_reader_add(remote_reader_data); returned_value = true; } - else if(local_writer.entityId == sedp_builtin_subscriptions_secure_writer) + else if (local_writer.entityId == sedp_builtin_subscriptions_secure_writer) { subscriptions_secure_writer_.first->matched_reader_add(remote_reader_data); returned_value = true; @@ -984,6 +1018,7 @@ bool EDPSimple::pairing_remote_reader_with_local_builtin_writer_after_security(c return returned_value; } + #endif } /* namespace rtps */ diff --git a/src/cpp/rtps/builtin/discovery/endpoint/EDPSimpleListeners.h b/src/cpp/rtps/builtin/discovery/endpoint/EDPSimpleListeners.h index 462e8e3436a..5761e861ab7 100644 --- a/src/cpp/rtps/builtin/discovery/endpoint/EDPSimpleListeners.h +++ b/src/cpp/rtps/builtin/discovery/endpoint/EDPSimpleListeners.h @@ -45,10 +45,12 @@ struct CacheChange_t; class EDPListener : public ReaderListener, public WriterListener { public: + /** * @param change */ - bool computeKey(CacheChange_t* change); + bool computeKey( + CacheChange_t* change); }; /** @@ -58,10 +60,14 @@ class EDPListener : public ReaderListener, public WriterListener class EDPBasePUBListener : public EDPListener { public: - EDPBasePUBListener(const RemoteLocatorsAllocationAttributes& locators_allocation) + + EDPBasePUBListener( + const RemoteLocatorsAllocationAttributes& locators_allocation, + const VariableLengthDataLimits& data_limits) : temp_writer_data_( locators_allocation.max_unicast_locators, - locators_allocation.max_multicast_locators) + locators_allocation.max_multicast_locators, + data_limits) { } @@ -85,10 +91,14 @@ class EDPBasePUBListener : public EDPListener class EDPBaseSUBListener : public EDPListener { public: - EDPBaseSUBListener(const RemoteLocatorsAllocationAttributes& locators_allocation) + + EDPBaseSUBListener( + const RemoteLocatorsAllocationAttributes& locators_allocation, + const VariableLengthDataLimits& data_limits) : temp_reader_data_( locators_allocation.max_unicast_locators, - locators_allocation.max_multicast_locators) + locators_allocation.max_multicast_locators, + data_limits) { } @@ -97,9 +107,9 @@ class EDPBaseSUBListener : public EDPListener protected: void add_reader_from_change( - RTPSReader* reader, - CacheChange_t* change, - EDP* edp); + RTPSReader* reader, + CacheChange_t* change, + EDP* edp); //!Temporary structure to avoid allocations ReaderProxyData temp_reader_data_; @@ -111,43 +121,46 @@ class EDPBaseSUBListener : public EDPListener */ class EDPSimplePUBListener : public EDPBasePUBListener { - public: - - /*! - Constructor - * @param sedp Pointer to the EDPSimple associated with this listener. - */ - EDPSimplePUBListener(EDPSimple* sedp) - : EDPBasePUBListener(sedp->mp_RTPSParticipant->getAttributes().allocation.locators) - , sedp_(sedp) - {} - - virtual ~EDPSimplePUBListener() = default; - - /** - * Virtual method, - * @param reader - * @param change - */ - void onNewCacheChangeAdded( - RTPSReader* reader, - const CacheChange_t* const change) override; - - - /*! - * This method is called when all the readers matched with this Writer acknowledge that a cache - * change has been received. - * @param writer Pointer to the RTPSWriter. - * @param change Pointer to the affected CacheChange_t. - */ - void onWriterChangeReceivedByAll( - RTPSWriter* writer, - CacheChange_t* change) override; - - protected: - - //!Pointer to the EDPSimple - EDPSimple* sedp_; +public: + + /*! + Constructor + * @param sedp Pointer to the EDPSimple associated with this listener. + */ + EDPSimplePUBListener( + EDPSimple* sedp) + : EDPBasePUBListener(sedp->mp_RTPSParticipant->getAttributes().allocation.locators, + sedp->mp_RTPSParticipant->getAttributes().allocation.data_limits) + , sedp_(sedp) + { + } + + virtual ~EDPSimplePUBListener() = default; + + /** + * Virtual method, + * @param reader + * @param change + */ + void onNewCacheChangeAdded( + RTPSReader* reader, + const CacheChange_t* const change) override; + + + /*! + * This method is called when all the readers matched with this Writer acknowledge that a cache + * change has been received. + * @param writer Pointer to the RTPSWriter. + * @param change Pointer to the affected CacheChange_t. + */ + void onWriterChangeReceivedByAll( + RTPSWriter* writer, + CacheChange_t* change) override; + +protected: + + //!Pointer to the EDPSimple + EDPSimple* sedp_; }; /*! @@ -156,42 +169,44 @@ class EDPSimplePUBListener : public EDPBasePUBListener */ class EDPSimpleSUBListener : public EDPBaseSUBListener { - public: - - /*! - Constructor - * @param sedp Pointer to the EDPSimple associated with this listener. - */ - EDPSimpleSUBListener(EDPSimple* sedp) - : EDPBaseSUBListener(sedp->mp_RTPSParticipant->getAttributes().allocation.locators) - , sedp_(sedp) - { - } - - virtual ~EDPSimpleSUBListener() = default; - - /** - * @param reader - * @param change - */ - void onNewCacheChangeAdded( - RTPSReader* reader, - const CacheChange_t* const change) override; - - /*! - * This method is called when all the readers matched with this Writer acknowledge that a cache - * change has been received. - * @param writer Pointer to the RTPSWriter. - * @param change Pointer to the affected CacheChange_t. - */ - void onWriterChangeReceivedByAll( - RTPSWriter* writer, - CacheChange_t* change) override; - - private: - - //!Pointer to the EDPSimple - EDPSimple* sedp_; +public: + + /*! + Constructor + * @param sedp Pointer to the EDPSimple associated with this listener. + */ + EDPSimpleSUBListener( + EDPSimple* sedp) + : EDPBaseSUBListener(sedp->mp_RTPSParticipant->getAttributes().allocation.locators, + sedp->mp_RTPSParticipant->getAttributes().allocation.data_limits) + , sedp_(sedp) + { + } + + virtual ~EDPSimpleSUBListener() = default; + + /** + * @param reader + * @param change + */ + void onNewCacheChangeAdded( + RTPSReader* reader, + const CacheChange_t* const change) override; + + /*! + * This method is called when all the readers matched with this Writer acknowledge that a cache + * change has been received. + * @param writer Pointer to the RTPSWriter. + * @param change Pointer to the affected CacheChange_t. + */ + void onWriterChangeReceivedByAll( + RTPSWriter* writer, + CacheChange_t* change) override; + +private: + + //!Pointer to the EDPSimple + EDPSimple* sedp_; }; } /* namespace rtps */ diff --git a/src/cpp/rtps/builtin/discovery/endpoint/EDPStatic.cpp b/src/cpp/rtps/builtin/discovery/endpoint/EDPStatic.cpp index 642a21f9679..2c97730ca66 100644 --- a/src/cpp/rtps/builtin/discovery/endpoint/EDPStatic.cpp +++ b/src/cpp/rtps/builtin/discovery/endpoint/EDPStatic.cpp @@ -37,178 +37,207 @@ #include namespace eprosima { -namespace fastrtps{ +namespace fastrtps { namespace rtps { -EDPStatic::EDPStatic(PDP* p,RTPSParticipantImpl* part): - EDP(p,part), - mp_edpXML(nullptr) +EDPStatic::EDPStatic( + PDP* p, + RTPSParticipantImpl* part) + : EDP(p, part) + , mp_edpXML(nullptr) { } EDPStatic::~EDPStatic() { - if(mp_edpXML != nullptr) + if (mp_edpXML != nullptr) + { delete(mp_edpXML); + } } -bool EDPStatic::initEDP(BuiltinAttributes& attributes) +bool EDPStatic::initEDP( + BuiltinAttributes& attributes) { - logInfo(RTPS_EDP,"Beginning STATIC EndpointDiscoveryProtocol"); + logInfo(RTPS_EDP, "Beginning STATIC EndpointDiscoveryProtocol"); m_attributes = attributes; mp_edpXML = new xmlparser::XMLEndpointParser(); std::string filename(m_attributes.discovery_config.getStaticEndpointXMLFilename()); return (this->mp_edpXML->loadXMLFile(filename) == xmlparser::XMLP_ret::XML_OK); } -std::pair EDPStaticProperty::toProperty(std::string type,std::string status,uint16_t id,const EntityId_t& ent) +std::pair EDPStaticProperty::toProperty( + std::string type, + std::string status, + uint16_t id, + const EntityId_t& ent) { - std::pair prop; + std::pair prop; std::stringstream ss; - ss << "eProsimaEDPStatic_"< prop) +bool EDPStaticProperty::fromProperty( + std::pair prop) { - if(prop.first.substr(0,17) == "eProsimaEDPStatic" && prop.first.substr(31,2) == "ID") + if (prop.first.substr(0, 17) == "eProsimaEDPStatic" && prop.first.substr(31, 2) == "ID") { - this->m_endpointType = prop.first.substr(18,6); - this->m_status = prop.first.substr(25,5); - this->m_userIdStr = prop.first.substr(34,100); + this->m_endpointType = prop.first.substr(18, 6); + this->m_status = prop.first.substr(25, 5); + this->m_userIdStr = prop.first.substr(34, 100); std::stringstream ss; ss << m_userIdStr; ss >> m_userId; ss.clear(); ss.str(std::string()); ss << prop.second; - int a,b,c,d; + int a, b, c, d; char ch; - ss >> a >> ch >> b >> ch >> c >>ch >> d; - m_entityId.value[0] = (octet)a;m_entityId.value[1] = (octet)b; - m_entityId.value[2] = (octet)c;m_entityId.value[3] = (octet)d; + ss >> a >> ch >> b >> ch >> c >> ch >> d; + m_entityId.value[0] = (octet)a; m_entityId.value[1] = (octet)b; + m_entityId.value[2] = (octet)c; m_entityId.value[3] = (octet)d; return true; } return false; } - - -bool EDPStatic::processLocalReaderProxyData(RTPSReader*, ReaderProxyData* rdata) +bool EDPStatic::processLocalReaderProxyData( + RTPSReader*, + ReaderProxyData* rdata) { - logInfo(RTPS_EDP,rdata->guid().entityId<< " in topic: " <topicName()); + logInfo(RTPS_EDP, rdata->guid().entityId << " in topic: " << rdata->topicName()); mp_PDP->getMutex()->lock(); //Add the property list entry to our local pdp ParticipantProxyData* localpdata = this->mp_PDP->getLocalParticipantProxyData(); - localpdata->m_properties.properties.push_back(EDPStaticProperty::toProperty("Reader","ALIVE", rdata->userDefinedId(), rdata->guid().entityId)); + localpdata->m_properties.push_back(EDPStaticProperty::toProperty("Reader", "ALIVE", rdata->userDefinedId(), + rdata->guid().entityId)); mp_PDP->getMutex()->unlock(); this->mp_PDP->announceParticipantState(true); return true; } -bool EDPStatic::processLocalWriterProxyData(RTPSWriter*, WriterProxyData* wdata) +bool EDPStatic::processLocalWriterProxyData( + RTPSWriter*, + WriterProxyData* wdata) { - logInfo(RTPS_EDP ,wdata->guid().entityId << " in topic: " << wdata->topicName()); + logInfo(RTPS_EDP, wdata->guid().entityId << " in topic: " << wdata->topicName()); mp_PDP->getMutex()->lock(); //Add the property list entry to our local pdp ParticipantProxyData* localpdata = this->mp_PDP->getLocalParticipantProxyData(); - localpdata->m_properties.properties.push_back(EDPStaticProperty::toProperty("Writer","ALIVE", - wdata->userDefinedId(), wdata->guid().entityId)); + localpdata->m_properties.push_back(EDPStaticProperty::toProperty("Writer", "ALIVE", + wdata->userDefinedId(), wdata->guid().entityId)); mp_PDP->getMutex()->unlock(); this->mp_PDP->announceParticipantState(true); return true; } -bool EDPStatic::removeLocalReader(RTPSReader* R) +bool EDPStatic::removeLocalReader( + RTPSReader* R) { std::lock_guard guard(*mp_PDP->getMutex()); ParticipantProxyData* localpdata = this->mp_PDP->getLocalParticipantProxyData(); - for(std::vector>::iterator pit = localpdata->m_properties.properties.begin(); - pit!=localpdata->m_properties.properties.end();++pit) + for (ParameterPropertyList_t::iterator pit = localpdata->m_properties.begin(); + pit != localpdata->m_properties.end(); ++pit) { EDPStaticProperty staticproperty; - if(staticproperty.fromProperty(*pit)) + if (staticproperty.fromProperty((*pit).pair())) { - if(staticproperty.m_entityId == R->getGuid().entityId) + if (staticproperty.m_entityId == R->getGuid().entityId) { - *pit = EDPStaticProperty::toProperty("Reader","ENDED",R->getAttributes().getUserDefinedID(), - R->getGuid().entityId); + auto new_property = EDPStaticProperty::toProperty("Reader", "ENDED", + R->getAttributes().getUserDefinedID(), R->getGuid().entityId); + if (!pit->modify(new_property)) + { + logError(RTPS_EDP, "Failed to change property <" + << pit->first() << " | " << pit->second() << "> to <" + << new_property.first << " | " << new_property.second << ">"); + } } } } return false; } -bool EDPStatic::removeLocalWriter(RTPSWriter*W) +bool EDPStatic::removeLocalWriter( + RTPSWriter* W) { std::lock_guard guard(*mp_PDP->getMutex()); ParticipantProxyData* localpdata = this->mp_PDP->getLocalParticipantProxyData(); - for(std::vector>::iterator pit = localpdata->m_properties.properties.begin(); - pit!=localpdata->m_properties.properties.end();++pit) + for (ParameterPropertyList_t::iterator pit = localpdata->m_properties.begin(); + pit != localpdata->m_properties.end(); ++pit) { EDPStaticProperty staticproperty; - if(staticproperty.fromProperty(*pit)) + if (staticproperty.fromProperty((*pit).pair())) { - if(staticproperty.m_entityId == W->getGuid().entityId) + if (staticproperty.m_entityId == W->getGuid().entityId) { - *pit = EDPStaticProperty::toProperty("Writer","ENDED",W->getAttributes().getUserDefinedID(), - W->getGuid().entityId); + auto new_property = EDPStaticProperty::toProperty("Writer", "ENDED", + W->getAttributes().getUserDefinedID(), W->getGuid().entityId); + if (!pit->modify(new_property)) + { + logError(RTPS_EDP, "Failed to change property <" + << pit->first() << " | " << pit->second() << "> to <" + << new_property.first << " | " << new_property.second << ">"); + } } } } return false; } -void EDPStatic::assignRemoteEndpoints(const ParticipantProxyData& pdata) +void EDPStatic::assignRemoteEndpoints( + const ParticipantProxyData& pdata) { - for(std::vector>::const_iterator pit = pdata.m_properties.properties.begin(); - pit!=pdata.m_properties.properties.end();++pit) + for (ParameterPropertyList_t::const_iterator pit = pdata.m_properties.begin(); + pit != pdata.m_properties.end(); ++pit) { //cout << "STATIC EDP READING PROPERTY " << pit->first << "// " << pit->second << endl; EDPStaticProperty staticproperty; - if(staticproperty.fromProperty(*pit)) + if (staticproperty.fromProperty((*pit).pair())) { - if(staticproperty.m_endpointType == "Reader" && staticproperty.m_status=="ALIVE") + if (staticproperty.m_endpointType == "Reader" && staticproperty.m_status == "ALIVE") { - GUID_t guid(pdata.m_guid.guidPrefix,staticproperty.m_entityId); - if(!this->mp_PDP->has_reader_proxy_data(guid))//IF NOT FOUND, we CREATE AND PAIR IT + GUID_t guid(pdata.m_guid.guidPrefix, staticproperty.m_entityId); + if (!this->mp_PDP->has_reader_proxy_data(guid))//IF NOT FOUND, we CREATE AND PAIR IT { newRemoteReader(pdata.m_guid, pdata.m_participantName, - staticproperty.m_userId, staticproperty.m_entityId); + staticproperty.m_userId, staticproperty.m_entityId); } } - else if(staticproperty.m_endpointType == "Writer" && staticproperty.m_status == "ALIVE") + else if (staticproperty.m_endpointType == "Writer" && staticproperty.m_status == "ALIVE") { - GUID_t guid(pdata.m_guid.guidPrefix,staticproperty.m_entityId); - if(!this->mp_PDP->has_writer_proxy_data(guid))//IF NOT FOUND, we CREATE AND PAIR IT + GUID_t guid(pdata.m_guid.guidPrefix, staticproperty.m_entityId); + if (!this->mp_PDP->has_writer_proxy_data(guid))//IF NOT FOUND, we CREATE AND PAIR IT { newRemoteWriter(pdata.m_guid, pdata.m_participantName, - staticproperty.m_userId, staticproperty.m_entityId); + staticproperty.m_userId, staticproperty.m_entityId); } } - else if(staticproperty.m_endpointType == "Reader" && staticproperty.m_status == "ENDED") + else if (staticproperty.m_endpointType == "Reader" && staticproperty.m_status == "ENDED") { - GUID_t guid(pdata.m_guid.guidPrefix,staticproperty.m_entityId); + GUID_t guid(pdata.m_guid.guidPrefix, staticproperty.m_entityId); this->mp_PDP->removeReaderProxyData(guid); } - else if(staticproperty.m_endpointType == "Writer" && staticproperty.m_status == "ENDED") + else if (staticproperty.m_endpointType == "Writer" && staticproperty.m_status == "ENDED") { - GUID_t guid(pdata.m_guid.guidPrefix,staticproperty.m_entityId); + GUID_t guid(pdata.m_guid.guidPrefix, staticproperty.m_entityId); this->mp_PDP->removeWriterProxyData(guid); } else { - logWarning(RTPS_EDP,"Property with type: "<lookforReader(participant_name, user_id, &rpd) == xmlparser::XMLP_ret::XML_OK) + if (mp_edpXML->lookforReader(participant_name, user_id, &rpd) == xmlparser::XMLP_ret::XML_OK) { logInfo(RTPS_EDP, "Activating: " << rpd->guid().entityId << " in topic " << rpd->topicName()); GUID_t reader_guid(participant_guid.guidPrefix, ent_id != c_EntityId_Unknown ? ent_id : rpd->guid().entityId); auto init_fun = [this, participant_guid, reader_guid, rpd]( - ReaderProxyData* newRPD, - bool updating, - const ParticipantProxyData& participant_data) + ReaderProxyData* newRPD, + bool updating, + const ParticipantProxyData& participant_data) { // Should be a new reader (void)updating; @@ -244,7 +273,7 @@ bool EDPStatic::newRemoteReader( if (!checkEntityId(newRPD)) { logError(RTPS_EDP, "The provided entityId for Reader with ID: " - << newRPD->userDefinedId() << " does not match the topic Kind"); + << newRPD->userDefinedId() << " does not match the topic Kind"); return false; } newRPD->key() = newRPD->guid(); @@ -260,7 +289,7 @@ bool EDPStatic::newRemoteReader( GUID_t temp_participant_guid; ReaderProxyData* reader_data = this->mp_PDP->addReaderProxyData(reader_guid, temp_participant_guid, init_fun); - if(reader_data != nullptr) + if (reader_data != nullptr) { this->pairing_reader_proxy_with_any_local_writer(participant_guid, reader_data); return true; @@ -276,9 +305,9 @@ bool EDPStatic::newRemoteWriter( EntityId_t ent_id) { WriterProxyData* wpd = NULL; - if(mp_edpXML->lookforWriter(participant_name,user_id,&wpd) == xmlparser::XMLP_ret::XML_OK) + if (mp_edpXML->lookforWriter(participant_name, user_id, &wpd) == xmlparser::XMLP_ret::XML_OK) { - logInfo(RTPS_EDP,"Activating: " << wpd->guid().entityId << " in topic " << wpd->topicName()); + logInfo(RTPS_EDP, "Activating: " << wpd->guid().entityId << " in topic " << wpd->topicName()); GUID_t writer_guid(participant_guid.guidPrefix, ent_id != c_EntityId_Unknown ? ent_id : wpd->guid().entityId); auto init_fun = [this, participant_guid, writer_guid, wpd]( @@ -295,7 +324,7 @@ bool EDPStatic::newRemoteWriter( if (!checkEntityId(newWPD)) { logError(RTPS_EDP, "The provided entityId for Writer with User ID: " - << newWPD->userDefinedId() << " does not match the topic Kind"); + << newWPD->userDefinedId() << " does not match the topic Kind"); return false; } newWPD->key() = newWPD->guid(); @@ -319,23 +348,34 @@ bool EDPStatic::newRemoteWriter( return false; } -bool EDPStatic::checkEntityId(ReaderProxyData* rdata) +bool EDPStatic::checkEntityId( + ReaderProxyData* rdata) { - if(rdata->topicKind() == WITH_KEY && rdata->guid().entityId.value[3] == 0x07) + if (rdata->topicKind() == WITH_KEY && rdata->guid().entityId.value[3] == 0x07) + { return true; - if(rdata->topicKind() == NO_KEY && rdata->guid().entityId.value[3] == 0x04) + } + if (rdata->topicKind() == NO_KEY && rdata->guid().entityId.value[3] == 0x04) + { return true; + } return false; } -bool EDPStatic::checkEntityId(WriterProxyData* wdata) +bool EDPStatic::checkEntityId( + WriterProxyData* wdata) { - if(wdata->topicKind() == WITH_KEY && wdata->guid().entityId.value[3] == 0x02) + if (wdata->topicKind() == WITH_KEY && wdata->guid().entityId.value[3] == 0x02) + { return true; - if(wdata->topicKind() == NO_KEY && wdata->guid().entityId.value[3] == 0x03) + } + if (wdata->topicKind() == NO_KEY && wdata->guid().entityId.value[3] == 0x03) + { return true; + } return false; } + } /* namespace rtps */ } /* namespace fastrtps */ } /* namespace eprosima */ diff --git a/src/cpp/rtps/builtin/discovery/participant/PDP.cpp b/src/cpp/rtps/builtin/discovery/participant/PDP.cpp index a4e60de2c6a..167dbd51f08 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDP.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDP.cpp @@ -95,8 +95,10 @@ PDP::PDP ( , mp_listener(nullptr) , mp_PDPWriterHistory(nullptr) , mp_PDPReaderHistory(nullptr) - , temp_reader_data_(allocation.locators.max_unicast_locators, allocation.locators.max_multicast_locators) - , temp_writer_data_(allocation.locators.max_unicast_locators, allocation.locators.max_multicast_locators) + , temp_reader_data_(allocation.locators.max_unicast_locators, allocation.locators.max_multicast_locators, + allocation.data_limits) + , temp_writer_data_(allocation.locators.max_unicast_locators, allocation.locators.max_multicast_locators, + allocation.data_limits) , mp_mutex(new std::recursive_mutex()) , resend_participant_info_event_(nullptr) { @@ -110,12 +112,14 @@ PDP::PDP ( for (size_t i = 0; i < allocation.total_readers().initial; ++i) { - reader_proxies_pool_.push_back(new ReaderProxyData(max_unicast_locators, max_multicast_locators)); + reader_proxies_pool_.push_back(new ReaderProxyData(max_unicast_locators, max_multicast_locators, + allocation.data_limits)); } for (size_t i = 0; i < allocation.total_writers().initial; ++i) { - writer_proxies_pool_.push_back(new WriterProxyData(max_unicast_locators, max_multicast_locators)); + writer_proxies_pool_.push_back(new WriterProxyData(max_unicast_locators, max_multicast_locators, + allocation.data_limits)); } } @@ -130,7 +134,7 @@ PDP::~PDP() delete mp_PDPReaderHistory; delete mp_listener; - for(ParticipantProxyData* it : participant_proxies_) + for (ParticipantProxyData* it : participant_proxies_) { delete it; } @@ -181,7 +185,7 @@ ParticipantProxyData* PDP::add_participant_proxy_data( else { logWarning(RTPS_PDP, "Maximum number of participant proxies (" << max_proxies << \ - ") reached for participant " << mp_RTPSParticipant->getGuid() << std::endl); + ") reached for participant " << mp_RTPSParticipant->getGuid() << std::endl); return nullptr; } } @@ -200,7 +204,8 @@ ParticipantProxyData* PDP::add_participant_proxy_data( return ret_val; } -void PDP::initializeParticipantProxyData(ParticipantProxyData* participant_data) +void PDP::initializeParticipantProxyData( + ParticipantProxyData* participant_data) { participant_data->m_leaseDuration = mp_RTPSParticipant->getAttributes().builtin.discovery_config.leaseDuration; //set_VendorId_eProsima(participant_data->m_VendorId); @@ -214,7 +219,7 @@ void PDP::initializeParticipantProxyData(ParticipantProxyData* participant_data) participant_data->m_availableBuiltinEndpoints |= DISC_BUILTIN_ENDPOINT_PARTICIPANT_SECURE_DETECTOR; #endif - if(mp_RTPSParticipant->getAttributes().builtin.use_WriterLivelinessProtocol) + if (mp_RTPSParticipant->getAttributes().builtin.use_WriterLivelinessProtocol) { participant_data->m_availableBuiltinEndpoints |= BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_WRITER; participant_data->m_availableBuiltinEndpoints |= BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_READER; @@ -251,19 +256,14 @@ void PDP::initializeParticipantProxyData(ParticipantProxyData* participant_data) } participant_data->m_expectsInlineQos = false; participant_data->m_guid = mp_RTPSParticipant->getGuid(); - for(uint8_t i = 0; i<16; ++i) - { - if(i<12) - participant_data->m_key.value[i] = participant_data->m_guid.guidPrefix.value[i]; - else - participant_data->m_key.value[i] = participant_data->m_guid.entityId.value[i - 12]; - } + memcpy( participant_data->m_key.value, participant_data->m_guid.guidPrefix.value, 12); + memcpy( participant_data->m_key.value + 12, participant_data->m_guid.entityId.value, 4); // Keep persistence Guid_Prefix_t in a specific property. This info must be propagated to all builtin endpoints { GuidPrefix_t persistent = mp_RTPSParticipant->getAttributes().prefix; - if(persistent != c_GuidPrefix_Unknown) + if (persistent != c_GuidPrefix_Unknown) { participant_data->set_persistence_guid( GUID_t( @@ -281,7 +281,7 @@ void PDP::initializeParticipantProxyData(ParticipantProxyData* participant_data) participant_data->metatraffic_locators.multicast.clear(); if (!m_discovery.avoid_builtin_multicast || participant_data->metatraffic_locators.unicast.empty()) { - for(const Locator_t& loc: this->mp_builtin->m_metatrafficMulticastLocatorList) + for (const Locator_t& loc: this->mp_builtin->m_metatrafficMulticastLocatorList) { participant_data->metatraffic_locators.add_multicast_locator(loc); } @@ -293,15 +293,15 @@ void PDP::initializeParticipantProxyData(ParticipantProxyData* participant_data) #if HAVE_SECURITY IdentityToken* identity_token = nullptr; - if(mp_RTPSParticipant->security_manager().get_identity_token(&identity_token) && identity_token != nullptr) + if (mp_RTPSParticipant->security_manager().get_identity_token(&identity_token) && identity_token != nullptr) { participant_data->identity_token_ = std::move(*identity_token); mp_RTPSParticipant->security_manager().return_identity_token(identity_token); } PermissionsToken* permissions_token = nullptr; - if(mp_RTPSParticipant->security_manager().get_permissions_token(&permissions_token) - && permissions_token != nullptr) + if (mp_RTPSParticipant->security_manager().get_permissions_token(&permissions_token) + && permissions_token != nullptr) { participant_data->permissions_token_ = std::move(*permissions_token); mp_RTPSParticipant->security_manager().return_permissions_token(permissions_token); @@ -309,7 +309,7 @@ void PDP::initializeParticipantProxyData(ParticipantProxyData* participant_data) if (mp_RTPSParticipant->is_secure()) { - const security::ParticipantSecurityAttributes & sec_attrs = mp_RTPSParticipant->security_attributes(); + const security::ParticipantSecurityAttributes& sec_attrs = mp_RTPSParticipant->security_attributes(); participant_data->security_attributes_ = sec_attrs.mask(); participant_data->plugin_security_attributes_ = sec_attrs.plugin_participant_attributes; } @@ -322,9 +322,9 @@ void PDP::initializeParticipantProxyData(ParticipantProxyData* participant_data) } bool PDP::initPDP( - RTPSParticipantImpl* part) + RTPSParticipantImpl* part) { - logInfo(RTPS_PDP,"Beginning"); + logInfo(RTPS_PDP, "Beginning"); mp_RTPSParticipant = part; m_discovery = mp_RTPSParticipant->getAttributes().builtin; initial_announcements_ = m_discovery.discovery_config.initial_announcements; @@ -377,16 +377,16 @@ bool PDP::enable() } void PDP::announceParticipantState( - bool new_change, - bool dispose, - WriteParams& wparams) + bool new_change, + bool dispose, + WriteParams& wparams) { - logInfo(RTPS_PDP,"Announcing RTPSParticipant State (new change: "<< new_change <<")"); + logInfo(RTPS_PDP, "Announcing RTPSParticipant State (new change: " << new_change << ")"); CacheChange_t* change = nullptr; - if(!dispose) + if (!dispose) { - if(m_hasChangedLocalPDP.exchange(false) || new_change) + if (m_hasChangedLocalPDP.exchange(false) || new_change) { this->mp_mutex->lock(); ParticipantProxyData* local_participant_data = getLocalParticipantProxyData(); @@ -394,16 +394,19 @@ void PDP::announceParticipantState( ParticipantProxyData proxy_data_copy(*local_participant_data); this->mp_mutex->unlock(); - if(mp_PDPWriterHistory->getHistorySize() > 0) + if (mp_PDPWriterHistory->getHistorySize() > 0) + { mp_PDPWriterHistory->remove_min_change(); + } // TODO(Ricardo) Change DISCOVERY_PARTICIPANT_DATA_MAX_SIZE with getLocalParticipantProxyData()->size(). - change = mp_PDPWriter->new_change([]() -> uint32_t - { - return DISCOVERY_PARTICIPANT_DATA_MAX_SIZE; - } - , ALIVE, key); + change = mp_PDPWriter->new_change( + []() -> uint32_t + { + return DISCOVERY_PARTICIPANT_DATA_MAX_SIZE; + } + , ALIVE, key); - if(change != nullptr) + if (change != nullptr) { CDRMessage_t aux_msg(change->serializedPayload); @@ -419,7 +422,7 @@ void PDP::announceParticipantState( { change->serializedPayload.length = (uint16_t)aux_msg.length; - mp_PDPWriterHistory->add_change(change, wparams); + mp_PDPWriterHistory->add_change(change, wparams); } else { @@ -435,15 +438,18 @@ void PDP::announceParticipantState( ParticipantProxyData proxy_data_copy(*getLocalParticipantProxyData()); this->mp_mutex->unlock(); - if(mp_PDPWriterHistory->getHistorySize() > 0) + if (mp_PDPWriterHistory->getHistorySize() > 0) + { mp_PDPWriterHistory->remove_min_change(); - change = mp_PDPWriter->new_change([]() -> uint32_t - { - return DISCOVERY_PARTICIPANT_DATA_MAX_SIZE; - } - , NOT_ALIVE_DISPOSED_UNREGISTERED, getLocalParticipantProxyData()->m_key); + } + change = mp_PDPWriter->new_change( + []() -> uint32_t + { + return DISCOVERY_PARTICIPANT_DATA_MAX_SIZE; + } + , NOT_ALIVE_DISPOSED_UNREGISTERED, getLocalParticipantProxyData()->m_key); - if(change != nullptr) + if (change != nullptr) { CDRMessage_t aux_msg(change->serializedPayload); @@ -480,21 +486,24 @@ void PDP::resetParticipantAnnouncement() resend_participant_info_event_->restart_timer(); } -bool PDP::has_reader_proxy_data(const GUID_t& reader) +bool PDP::has_reader_proxy_data( + const GUID_t& reader) { std::lock_guard guardPDP(*this->mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { if (pit->m_guid.guidPrefix == reader.guidPrefix) { - ProxyHashTable & readers = *pit->m_readers; + ProxyHashTable& readers = *pit->m_readers; return readers.find(reader.entityId) != readers.end(); } } return false; } -bool PDP::lookupReaderProxyData(const GUID_t& reader, ReaderProxyData& rdata) +bool PDP::lookupReaderProxyData( + const GUID_t& reader, + ReaderProxyData& rdata) { std::lock_guard guardPDP(*this->mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) @@ -502,7 +511,7 @@ bool PDP::lookupReaderProxyData(const GUID_t& reader, ReaderProxyData& rdata) if (pit->m_guid.guidPrefix == reader.guidPrefix) { auto rit = pit->m_readers->find(reader.entityId); - if(rit != pit->m_readers->end()) + if (rit != pit->m_readers->end()) { rdata.copy(rit->second); return true; @@ -512,21 +521,24 @@ bool PDP::lookupReaderProxyData(const GUID_t& reader, ReaderProxyData& rdata) return false; } -bool PDP::has_writer_proxy_data(const GUID_t& writer) +bool PDP::has_writer_proxy_data( + const GUID_t& writer) { std::lock_guard guardPDP(*this->mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) { if (pit->m_guid.guidPrefix == writer.guidPrefix) { - ProxyHashTable & writers = *pit->m_writers; + ProxyHashTable& writers = *pit->m_writers; return writers.find(writer.entityId) != writers.end(); } } return false; } -bool PDP::lookupWriterProxyData(const GUID_t& writer, WriterProxyData& wdata) +bool PDP::lookupWriterProxyData( + const GUID_t& writer, + WriterProxyData& wdata) { std::lock_guard guardPDP(*this->mp_mutex); for (ParticipantProxyData* pit : participant_proxies_) @@ -544,7 +556,8 @@ bool PDP::lookupWriterProxyData(const GUID_t& writer, WriterProxyData& wdata) return false; } -bool PDP::removeReaderProxyData(const GUID_t& reader_guid) +bool PDP::removeReaderProxyData( + const GUID_t& reader_guid) { logInfo(RTPS_PDP, "Removing reader proxy data " << reader_guid); std::lock_guard guardPDP(*this->mp_mutex); @@ -557,7 +570,7 @@ bool PDP::removeReaderProxyData(const GUID_t& reader_guid) if (rit != pit->m_readers->end()) { - ReaderProxyData * pR = rit->second; + ReaderProxyData* pR = rit->second; mp_EDP->unpairReaderProxy(pit->m_guid, reader_guid); RTPSParticipantListener* listener = mp_RTPSParticipant->getListener(); @@ -580,7 +593,8 @@ bool PDP::removeReaderProxyData(const GUID_t& reader_guid) return false; } -bool PDP::removeWriterProxyData(const GUID_t& writer_guid) +bool PDP::removeWriterProxyData( + const GUID_t& writer_guid) { logInfo(RTPS_PDP, "Removing writer proxy data " << writer_guid); std::lock_guard guardPDP(*this->mp_mutex); @@ -593,7 +607,7 @@ bool PDP::removeWriterProxyData(const GUID_t& writer_guid) if (wit != pit->m_writers->end()) { - WriterProxyData *pW = wit->second; + WriterProxyData* pW = wit->second; mp_EDP->unpairWriterProxy(pit->m_guid, writer_guid); RTPSParticipantListener* listener = mp_RTPSParticipant->getListener(); @@ -659,9 +673,9 @@ ReaderProxyData* PDP::addReaderProxyData( std::lock_guard guardPDP(*this->mp_mutex); - for(ParticipantProxyData* pit : participant_proxies_) + for (ParticipantProxyData* pit : participant_proxies_) { - if(pit->m_guid.guidPrefix == reader_guid.guidPrefix) + if (pit->m_guid.guidPrefix == reader_guid.guidPrefix) { // Copy participant data to be used outside. participant_guid = pit->m_guid; @@ -669,7 +683,7 @@ ReaderProxyData* PDP::addReaderProxyData( // Check that it is not already there: auto rpi = pit->m_readers->find(reader_guid.entityId); - if( rpi != pit->m_readers->end()) + if ( rpi != pit->m_readers->end()) { ret_val = rpi->second; @@ -679,7 +693,7 @@ ReaderProxyData* PDP::addReaderProxyData( } RTPSParticipantListener* listener = mp_RTPSParticipant->getListener(); - if(listener) + if (listener) { ReaderDiscoveryInfo info(*ret_val); info.status = ReaderDiscoveryInfo::CHANGED_QOS_READER; @@ -700,12 +714,13 @@ ReaderProxyData* PDP::addReaderProxyData( ++reader_proxies_number_; ret_val = new ReaderProxyData( mp_RTPSParticipant->getAttributes().allocation.locators.max_unicast_locators, - mp_RTPSParticipant->getAttributes().allocation.locators.max_multicast_locators); + mp_RTPSParticipant->getAttributes().allocation.locators.max_multicast_locators, + mp_RTPSParticipant->getAttributes().allocation.data_limits); } else { logWarning(RTPS_PDP, "Maximum number of reader proxies (" << max_proxies << - ") reached for participant " << mp_RTPSParticipant->getGuid() << std::endl); + ") reached for participant " << mp_RTPSParticipant->getGuid() << std::endl); return nullptr; } } @@ -725,7 +740,7 @@ ReaderProxyData* PDP::addReaderProxyData( } RTPSParticipantListener* listener = mp_RTPSParticipant->getListener(); - if(listener) + if (listener) { ReaderDiscoveryInfo info(*ret_val); info.status = ReaderDiscoveryInfo::DISCOVERED_READER; @@ -791,12 +806,13 @@ WriterProxyData* PDP::addWriterProxyData( ++writer_proxies_number_; ret_val = new WriterProxyData( mp_RTPSParticipant->getAttributes().allocation.locators.max_unicast_locators, - mp_RTPSParticipant->getAttributes().allocation.locators.max_multicast_locators); + mp_RTPSParticipant->getAttributes().allocation.locators.max_multicast_locators, + mp_RTPSParticipant->getAttributes().allocation.data_limits); } else { logWarning(RTPS_PDP, "Maximum number of writer proxies (" << max_proxies << - ") reached for participant " << mp_RTPSParticipant->getGuid() << std::endl); + ") reached for participant " << mp_RTPSParticipant->getGuid() << std::endl); return nullptr; } } @@ -840,15 +856,15 @@ bool PDP::remove_remote_participant( return false; } - logInfo(RTPS_PDP,partGUID ); + logInfo(RTPS_PDP, partGUID ); ParticipantProxyData* pdata = nullptr; //Remove it from our vector or RTPSParticipantProxies: this->mp_mutex->lock(); - for(ResourceLimitedVector::iterator pit = participant_proxies_.begin(); - pit!=participant_proxies_.end();++pit) + for (ResourceLimitedVector::iterator pit = participant_proxies_.begin(); + pit != participant_proxies_.end(); ++pit) { - if((*pit)->m_guid == partGUID) + if ((*pit)->m_guid == partGUID) { pdata = *pit; participant_proxies_.erase(pit); @@ -857,13 +873,13 @@ bool PDP::remove_remote_participant( } this->mp_mutex->unlock(); - if(pdata !=nullptr) + if (pdata != nullptr) { - if(mp_EDP!=nullptr) + if (mp_EDP != nullptr) { RTPSParticipantListener* listener = mp_RTPSParticipant->getListener(); - for(auto pit : *pdata->m_readers) + for (auto pit : *pdata->m_readers) { ReaderProxyData* rit = pit.second; GUID_t reader_guid(rit->guid()); @@ -879,7 +895,7 @@ bool PDP::remove_remote_participant( } } } - for(auto pit : *pdata->m_writers) + for (auto pit : *pdata->m_writers) { WriterProxyData* wit = pit.second; GUID_t writer_guid(wit->guid()); @@ -915,10 +931,10 @@ bool PDP::remove_remote_participant( #endif this->mp_PDPReaderHistory->getMutex()->lock(); - for(std::vector::iterator it=this->mp_PDPReaderHistory->changesBegin(); - it!=this->mp_PDPReaderHistory->changesEnd();++it) + for (std::vector::iterator it = this->mp_PDPReaderHistory->changesBegin(); + it != this->mp_PDPReaderHistory->changesEnd(); ++it) { - if((*it)->instanceHandle == pdata->m_key) + if ((*it)->instanceHandle == pdata->m_key) { this->mp_PDPReaderHistory->remove_change(*it); break; @@ -980,7 +996,7 @@ void PDP::assert_remote_participant_liveliness( for (ParticipantProxyData* it : this->participant_proxies_) { - if(it->m_guid.guidPrefix == remote_guid) + if (it->m_guid.guidPrefix == remote_guid) { // TODO Ricardo: Study if isAlive attribute is necessary. it->isAlive = true; @@ -990,7 +1006,8 @@ void PDP::assert_remote_participant_liveliness( } } -CDRMessage_t PDP::get_participant_proxy_data_serialized(Endianness_t endian) +CDRMessage_t PDP::get_participant_proxy_data_serialized( + Endianness_t endian) { std::lock_guard guardPDP(*this->mp_mutex); CDRMessage_t cdr_msg(RTPSMESSAGE_DEFAULT_SIZE); @@ -1010,7 +1027,7 @@ void PDP::check_remote_participant_liveliness( { std::unique_lock guard(*this->mp_mutex); - if(GUID_t::unknown() != remote_participant->m_guid) + if (GUID_t::unknown() != remote_participant->m_guid) { // Check last received message's time_point plus lease duration time doesn't overcome now(). // If overcame, remove participant. @@ -1027,7 +1044,7 @@ void PDP::check_remote_participant_liveliness( // Calculate next trigger. auto next_trigger = real_lease_tm - now; remote_participant->lease_duration_event->update_interval_millisec( - (double)std::chrono::duration_cast(next_trigger).count()); + (double)std::chrono::duration_cast(next_trigger).count()); remote_participant->lease_duration_event->restart_timer(); } } @@ -1081,7 +1098,7 @@ void PDP::check_and_notify_type_discovery( type_name.to_string(), type_id, type_obj); } else if (type_id && type_id->_d() != static_cast(0x00) - && type_id->_d() < types::EK_MINIMAL) // Writer shares a TypeIdentifier that doesn't need TypeObject + && type_id->_d() < types::EK_MINIMAL) // Writer shares a TypeIdentifier that doesn't need TypeObject { dyn_type = types::TypeObjectFactory::get_instance()->build_dynamic_type( type_name.to_string(), type_id); diff --git a/src/cpp/rtps/builtin/liveliness/WLP.cpp b/src/cpp/rtps/builtin/liveliness/WLP.cpp index ea33304d728..30716ed3fe7 100644 --- a/src/cpp/rtps/builtin/liveliness/WLP.cpp +++ b/src/cpp/rtps/builtin/liveliness/WLP.cpp @@ -43,11 +43,12 @@ #include namespace eprosima { -namespace fastrtps{ +namespace fastrtps { namespace rtps { -WLP::WLP(BuiltinProtocols* p) +WLP::WLP( + BuiltinProtocols* p) : min_automatic_ms_(std::numeric_limits::max()) , min_manual_by_participant_ms_(std::numeric_limits::max()) , mp_participant(nullptr) @@ -73,14 +74,16 @@ WLP::WLP(BuiltinProtocols* p) , mp_builtinReaderSecureHistory(nullptr) #endif , temp_reader_proxy_data_( - p->mp_participantImpl->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, - p->mp_participantImpl->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators) + p->mp_participantImpl->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, + p->mp_participantImpl->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators, + p->mp_participantImpl->getRTPSParticipantAttributes().allocation.data_limits) , temp_writer_proxy_data_( - p->mp_participantImpl->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, - p->mp_participantImpl->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators) + p->mp_participantImpl->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, + p->mp_participantImpl->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators, + p->mp_participantImpl->getRTPSParticipantAttributes().allocation.data_limits) { automatic_instance_handle_ = p->mp_participantImpl->getGuid(); - automatic_instance_handle_.value[12] = automatic_instance_handle_.value[13] = automatic_instance_handle_.value[14] = 0; + memset(&automatic_instance_handle_.value[12], 0, 3); manual_by_participant_instance_handle_ = automatic_instance_handle_; automatic_instance_handle_.value[15] = AUTOMATIC_LIVELINESS_QOS + 0x01; @@ -116,44 +119,45 @@ WLP::~WLP() delete sub_liveliness_manager_; } -bool WLP::initWL(RTPSParticipantImpl* p) +bool WLP::initWL( + RTPSParticipantImpl* p) { - logInfo(RTPS_LIVELINESS,"Initializing Liveliness Protocol"); + logInfo(RTPS_LIVELINESS, "Initializing Liveliness Protocol"); mp_participant = p; pub_liveliness_manager_ = new LivelinessManager( - [&](const GUID_t& guid, - const LivelinessQosPolicyKind& kind, - const Duration_t& lease_duration, - int alive_count, - int not_alive_count) -> void - { - pub_liveliness_changed( - guid, - kind, - lease_duration, - alive_count, - not_alive_count); - }, - mp_participant->getEventResource(), - false); + [&](const GUID_t& guid, + const LivelinessQosPolicyKind& kind, + const Duration_t& lease_duration, + int alive_count, + int not_alive_count) -> void + { + pub_liveliness_changed( + guid, + kind, + lease_duration, + alive_count, + not_alive_count); + }, + mp_participant->getEventResource(), + false); sub_liveliness_manager_ = new LivelinessManager( - [&](const GUID_t& guid, - const LivelinessQosPolicyKind& kind, - const Duration_t& lease_duration, - int alive_count, - int not_alive_count) -> void - { - sub_liveliness_changed( - guid, - kind, - lease_duration, - alive_count, - not_alive_count); - }, - mp_participant->getEventResource()); + [&](const GUID_t& guid, + const LivelinessQosPolicyKind& kind, + const Duration_t& lease_duration, + int alive_count, + int not_alive_count) -> void + { + sub_liveliness_changed( + guid, + kind, + lease_duration, + alive_count, + not_alive_count); + }, + mp_participant->getEventResource()); bool retVal = createEndpoints(); #if HAVE_SECURITY @@ -200,11 +204,11 @@ bool WLP::createEndpoints() true)) { mp_builtinWriter = dynamic_cast(wout); - logInfo(RTPS_LIVELINESS,"Builtin Liveliness Writer created"); + logInfo(RTPS_LIVELINESS, "Builtin Liveliness Writer created"); } else { - logError(RTPS_LIVELINESS,"Liveliness Writer Creation failed "); + logError(RTPS_LIVELINESS, "Liveliness Writer Creation failed "); delete(mp_builtinWriterHistory); mp_builtinWriterHistory = nullptr; return false; @@ -243,11 +247,11 @@ bool WLP::createEndpoints() true)) { mp_builtinReader = dynamic_cast(rout); - logInfo(RTPS_LIVELINESS,"Builtin Liveliness Reader created"); + logInfo(RTPS_LIVELINESS, "Builtin Liveliness Reader created"); } else { - logError(RTPS_LIVELINESS,"Liveliness Reader Creation failed."); + logError(RTPS_LIVELINESS, "Liveliness Reader Creation failed."); delete(mp_builtinReaderHistory); mp_builtinReaderHistory = nullptr; delete(mp_listener); @@ -278,8 +282,10 @@ bool WLP::createSecureEndpoints() watt.endpoint.durabilityKind = TRANSIENT_LOCAL; watt.endpoint.reliabilityKind = RELIABLE; if (mp_participant->getRTPSParticipantAttributes().throughputController.bytesPerPeriod != UINT32_MAX && - mp_participant->getRTPSParticipantAttributes().throughputController.periodMillisecs != 0) + mp_participant->getRTPSParticipantAttributes().throughputController.periodMillisecs != 0) + { watt.mode = ASYNCHRONOUS_WRITER; + } const security::ParticipantSecurityAttributes& part_attrs = mp_participant->security_attributes(); security::PluginParticipantSecurityAttributes plugin_attrs(part_attrs.plugin_participant_attributes); @@ -289,13 +295,19 @@ bool WLP::createSecureEndpoints() { sec_attrs->plugin_endpoint_attributes |= PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID; if (plugin_attrs.is_liveliness_encrypted) + { sec_attrs->plugin_endpoint_attributes |= PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; + } if (plugin_attrs.is_liveliness_origin_authenticated) - sec_attrs->plugin_endpoint_attributes |= PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ORIGIN_AUTHENTICATED; + { + sec_attrs->plugin_endpoint_attributes |= + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ORIGIN_AUTHENTICATED; + } } RTPSWriter* wout; - if (mp_participant->createWriter(&wout, watt, mp_builtinWriterSecureHistory, nullptr, c_EntityId_WriterLivelinessSecure, true)) + if (mp_participant->createWriter(&wout, watt, mp_builtinWriterSecureHistory, nullptr, + c_EntityId_WriterLivelinessSecure, true)) { mp_builtinWriterSecure = dynamic_cast(wout); logInfo(RTPS_LIVELINESS, "Builtin Secure Liveliness Writer created"); @@ -328,9 +340,14 @@ bool WLP::createSecureEndpoints() { sec_attrs->plugin_endpoint_attributes |= PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID; if (plugin_attrs.is_liveliness_encrypted) + { sec_attrs->plugin_endpoint_attributes |= PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; + } if (plugin_attrs.is_liveliness_origin_authenticated) - sec_attrs->plugin_endpoint_attributes |= PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ORIGIN_AUTHENTICATED; + { + sec_attrs->plugin_endpoint_attributes |= + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ORIGIN_AUTHENTICATED; + } } RTPSReader* rout; if (mp_participant->createReader( @@ -355,8 +372,9 @@ bool WLP::createSecureEndpoints() return true; } -bool WLP::pairing_remote_reader_with_local_writer_after_security(const GUID_t& local_writer, - const ReaderProxyData& remote_reader_data) +bool WLP::pairing_remote_reader_with_local_writer_after_security( + const GUID_t& local_writer, + const ReaderProxyData& remote_reader_data) { if (local_writer.entityId == c_EntityId_WriterLivelinessSecure) { @@ -367,8 +385,9 @@ bool WLP::pairing_remote_reader_with_local_writer_after_security(const GUID_t& l return false; } -bool WLP::pairing_remote_writer_with_local_reader_after_security(const GUID_t& local_reader, - const WriterProxyData& remote_writer_data) +bool WLP::pairing_remote_writer_with_local_reader_after_security( + const GUID_t& local_reader, + const WriterProxyData& remote_writer_data) { if (local_reader.entityId == c_EntityId_ReaderLivelinessSecure) { @@ -381,14 +400,15 @@ bool WLP::pairing_remote_writer_with_local_reader_after_security(const GUID_t& l #endif -bool WLP::assignRemoteEndpoints(const ParticipantProxyData& pdata) +bool WLP::assignRemoteEndpoints( + const ParticipantProxyData& pdata) { const NetworkFactory& network = mp_participant->network_factory(); uint32_t endp = pdata.m_availableBuiltinEndpoints; uint32_t partdet = endp; uint32_t auxendp = endp; bool use_multicast_locators = !mp_participant->getAttributes().builtin.avoid_builtin_multicast || - pdata.metatraffic_locators.unicast.empty(); + pdata.metatraffic_locators.unicast.empty(); std::lock_guard data_guard(temp_data_lock_); @@ -410,18 +430,18 @@ bool WLP::assignRemoteEndpoints(const ParticipantProxyData& pdata) partdet &= DISC_BUILTIN_ENDPOINT_PARTICIPANT_DETECTOR; //Habria que quitar esta linea que comprueba si tiene PDP. auxendp &= BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_WRITER; - if ((auxendp!=0 || partdet!=0) && this->mp_builtinReader!=nullptr) + if ((auxendp != 0 || partdet != 0) && this->mp_builtinReader != nullptr) { - logInfo(RTPS_LIVELINESS,"Adding remote writer to my local Builtin Reader"); + logInfo(RTPS_LIVELINESS, "Adding remote writer to my local Builtin Reader"); temp_writer_proxy_data_.guid().entityId = c_EntityId_WriterLiveliness; temp_writer_proxy_data_.set_persistence_entity_id(c_EntityId_WriterLiveliness); mp_builtinReader->matched_writer_add(temp_writer_proxy_data_); } auxendp = endp; - auxendp &=BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_READER; - if ((auxendp!=0 || partdet!=0) && this->mp_builtinWriter!=nullptr) + auxendp &= BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_READER; + if ((auxendp != 0 || partdet != 0) && this->mp_builtinWriter != nullptr) { - logInfo(RTPS_LIVELINESS,"Adding remote reader to my local Builtin Writer"); + logInfo(RTPS_LIVELINESS, "Adding remote reader to my local Builtin Writer"); temp_reader_proxy_data_.guid().entityId = c_EntityId_ReaderLiveliness; mp_builtinWriter->matched_reader_add(temp_reader_proxy_data_); } @@ -436,11 +456,11 @@ bool WLP::assignRemoteEndpoints(const ParticipantProxyData& pdata) temp_writer_proxy_data_.set_persistence_entity_id(c_EntityId_WriterLivelinessSecure); if (!mp_participant->security_manager().discovered_builtin_writer( - mp_builtinReaderSecure->getGuid(), pdata.m_guid, temp_writer_proxy_data_, - mp_builtinReaderSecure->getAttributes().security_attributes())) + mp_builtinReaderSecure->getGuid(), pdata.m_guid, temp_writer_proxy_data_, + mp_builtinReaderSecure->getAttributes().security_attributes())) { logError(RTPS_EDP, "Security manager returns an error for reader " << - mp_builtinReaderSecure->getGuid()); + mp_builtinReaderSecure->getGuid()); } } auxendp = endp; @@ -450,11 +470,11 @@ bool WLP::assignRemoteEndpoints(const ParticipantProxyData& pdata) logInfo(RTPS_LIVELINESS, "Adding remote reader to my local Builtin Secure Writer"); temp_reader_proxy_data_.guid().entityId = c_EntityId_ReaderLivelinessSecure; if (!mp_participant->security_manager().discovered_builtin_reader( - mp_builtinWriterSecure->getGuid(), pdata.m_guid, temp_reader_proxy_data_, - mp_builtinWriterSecure->getAttributes().security_attributes())) + mp_builtinWriterSecure->getGuid(), pdata.m_guid, temp_reader_proxy_data_, + mp_builtinWriterSecure->getAttributes().security_attributes())) { logError(RTPS_EDP, "Security manager returns an error for writer " << - mp_builtinWriterSecure->getGuid()); + mp_builtinWriterSecure->getGuid()); } } #endif @@ -462,29 +482,30 @@ bool WLP::assignRemoteEndpoints(const ParticipantProxyData& pdata) return true; } -void WLP::removeRemoteEndpoints(ParticipantProxyData* pdata) +void WLP::removeRemoteEndpoints( + ParticipantProxyData* pdata) { GUID_t tmp_guid; tmp_guid.guidPrefix = pdata->m_guid.guidPrefix; - logInfo(RTPS_LIVELINESS,"for RTPSParticipant: "<m_guid); + logInfo(RTPS_LIVELINESS, "for RTPSParticipant: " << pdata->m_guid); uint32_t endp = pdata->m_availableBuiltinEndpoints; uint32_t partdet = endp; uint32_t auxendp = endp; partdet &= DISC_BUILTIN_ENDPOINT_PARTICIPANT_DETECTOR; //Habria que quitar esta linea que comprueba si tiene PDP. auxendp &= BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_WRITER; - if ((auxendp!=0 || partdet!=0) && this->mp_builtinReader!=nullptr) + if ((auxendp != 0 || partdet != 0) && this->mp_builtinReader != nullptr) { - logInfo(RTPS_LIVELINESS,"Removing remote writer from my local Builtin Reader"); + logInfo(RTPS_LIVELINESS, "Removing remote writer from my local Builtin Reader"); tmp_guid.entityId = c_EntityId_WriterLiveliness; mp_builtinReader->matched_writer_remove(tmp_guid); } auxendp = endp; - auxendp &=BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_READER; - if ((auxendp!=0 || partdet!=0) && this->mp_builtinWriter!=nullptr) + auxendp &= BUILTIN_ENDPOINT_PARTICIPANT_MESSAGE_DATA_READER; + if ((auxendp != 0 || partdet != 0) && this->mp_builtinWriter != nullptr) { - logInfo(RTPS_LIVELINESS,"Removing remote reader from my local Builtin Writer"); + logInfo(RTPS_LIVELINESS, "Removing remote reader from my local Builtin Writer"); tmp_guid.entityId = c_EntityId_ReaderLiveliness; mp_builtinWriter->matched_reader_remove(tmp_guid); } @@ -517,7 +538,9 @@ void WLP::removeRemoteEndpoints(ParticipantProxyData* pdata) #endif } -bool WLP::add_local_writer(RTPSWriter* W, const WriterQos& wqos) +bool WLP::add_local_writer( + RTPSWriter* W, + const WriterQos& wqos) { std::lock_guard guard(*mp_builtinProtocols->mp_PDP->getMutex()); logInfo(RTPS_LIVELINESS, W->getGuid().entityId << " to Liveliness Protocol"); @@ -553,7 +576,7 @@ bool WLP::add_local_writer(RTPSWriter* W, const WriterQos& wqos) } else if (wqos.m_liveliness.kind == MANUAL_BY_PARTICIPANT_LIVELINESS_QOS) { - if(manual_liveliness_assertion_ == nullptr) + if (manual_liveliness_assertion_ == nullptr) { manual_liveliness_assertion_ = new TimedEvent(mp_participant->getEventResource(), [&]() -> bool @@ -604,18 +627,19 @@ bool WLP::add_local_writer(RTPSWriter* W, const WriterQos& wqos) typedef std::vector::iterator t_WIT; -bool WLP::remove_local_writer(RTPSWriter* W) +bool WLP::remove_local_writer( + RTPSWriter* W) { std::lock_guard guard(*mp_builtinProtocols->mp_PDP->getMutex()); - logInfo(RTPS_LIVELINESS, W->getGuid().entityId <<" from Liveliness Protocol"); + logInfo(RTPS_LIVELINESS, W->getGuid().entityId << " from Liveliness Protocol"); if (W->get_liveliness_kind() == AUTOMATIC_LIVELINESS_QOS) { auto it = std::find( - automatic_writers_.begin(), - automatic_writers_.end(), - W); + automatic_writers_.begin(), + automatic_writers_.end(), + W); if (it == automatic_writers_.end()) { @@ -633,7 +657,7 @@ bool WLP::remove_local_writer(RTPSWriter* W) // There are still some writers. Calculate the new minimum announcement period - min_automatic_ms_ =std::numeric_limits::max(); + min_automatic_ms_ = std::numeric_limits::max(); for (const auto& w : automatic_writers_) { auto announcement_period = TimeConv::Duration_t2MilliSecondsDouble(w->get_liveliness_announcement_period()); @@ -647,9 +671,9 @@ bool WLP::remove_local_writer(RTPSWriter* W) else if (W->get_liveliness_kind() == MANUAL_BY_PARTICIPANT_LIVELINESS_QOS) { auto it = std::find( - manual_by_participant_writers_.begin(), - manual_by_participant_writers_.end(), - W); + manual_by_participant_writers_.begin(), + manual_by_participant_writers_.end(), + W); if (it == manual_by_participant_writers_.end()) { @@ -675,7 +699,7 @@ bool WLP::remove_local_writer(RTPSWriter* W) // There are still some writers. Calculate the new minimum announcement period - min_manual_by_participant_ms_ =std::numeric_limits::max(); + min_manual_by_participant_ms_ = std::numeric_limits::max(); for (const auto& w : manual_by_participant_writers_) { auto announcement_period = TimeConv::Duration_t2MilliSecondsDouble(w->get_liveliness_announcement_period()); @@ -690,9 +714,9 @@ bool WLP::remove_local_writer(RTPSWriter* W) else if (W->get_liveliness_kind() == MANUAL_BY_TOPIC_LIVELINESS_QOS) { auto it = std::find( - manual_by_topic_writers_.begin(), - manual_by_topic_writers_.end(), - W); + manual_by_topic_writers_.begin(), + manual_by_topic_writers_.end(), + W); if (it == manual_by_topic_writers_.end()) { @@ -712,11 +736,13 @@ bool WLP::remove_local_writer(RTPSWriter* W) return true; } - logWarning(RTPS_LIVELINESS, "Writer "<< W->getGuid() << " not found."); + logWarning(RTPS_LIVELINESS, "Writer " << W->getGuid() << " not found."); return false; } -bool WLP::add_local_reader(RTPSReader* reader, const ReaderQos &rqos) +bool WLP::add_local_reader( + RTPSReader* reader, + const ReaderQos& rqos) { std::lock_guard guard(*mp_builtinProtocols->mp_PDP->getMutex()); @@ -730,12 +756,13 @@ bool WLP::add_local_reader(RTPSReader* reader, const ReaderQos &rqos) return true; } -bool WLP::remove_local_reader(RTPSReader* reader) +bool WLP::remove_local_reader( + RTPSReader* reader) { auto it = std::find( - readers_.begin(), - readers_.end(), - reader); + readers_.begin(), + readers_.end(), + reader); if (it != readers_.end()) { readers_.erase(it); @@ -773,7 +800,8 @@ bool WLP::participant_liveliness_assertion() return false; } -bool WLP::send_liveliness_message(const InstanceHandle_t& instance) +bool WLP::send_liveliness_message( + const InstanceHandle_t& instance) { StatefulWriter* writer = builtin_writer(); WriterHistory* history = builtin_writer_history(); @@ -781,7 +809,10 @@ bool WLP::send_liveliness_message(const InstanceHandle_t& instance) std::lock_guard wguard(writer->getMutex()); CacheChange_t* change = writer->new_change( - []() -> uint32_t { return BUILTIN_PARTICIPANT_DATA_MAX_SIZE; }, + []() -> uint32_t + { + return BUILTIN_PARTICIPANT_DATA_MAX_SIZE; + }, ALIVE, instance); @@ -857,9 +888,9 @@ bool WLP::assert_liveliness( Duration_t lease_duration) { return pub_liveliness_manager_->assert_liveliness( - writer, - kind, - lease_duration); + writer, + kind, + lease_duration); } bool WLP::assert_liveliness_manual_by_participant() @@ -966,10 +997,10 @@ void WLP::sub_liveliness_changed( if (reader->matched_writer_is_matched(writer)) { update_liveliness_changed_status( - writer, - reader, - alive_change, - not_alive_change); + writer, + reader, + alive_change, + not_alive_change); } } } diff --git a/src/cpp/rtps/security/SecurityManager.cpp b/src/cpp/rtps/security/SecurityManager.cpp index 115c070c02c..b094324f6ff 100644 --- a/src/cpp/rtps/security/SecurityManager.cpp +++ b/src/cpp/rtps/security/SecurityManager.cpp @@ -73,7 +73,8 @@ bool usleep_bool() return true; } -SecurityManager::SecurityManager(RTPSParticipantImpl *participant) +SecurityManager::SecurityManager( + RTPSParticipantImpl* participant) : participant_stateless_message_listener_(*this) , participant_volatile_message_secure_listener_(*this) , participant_(participant) @@ -95,17 +96,21 @@ SecurityManager::SecurityManager(RTPSParticipantImpl *participant) , auth_last_sequence_number_(1) , crypto_last_sequence_number_(1) , temp_stateless_reader_proxy_data_( - participant->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, - participant->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators) + participant->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, + participant->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators, + participant->getRTPSParticipantAttributes().allocation.data_limits) , temp_stateless_writer_proxy_data_( - participant->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, - participant->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators) + participant->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, + participant->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators, + participant->getRTPSParticipantAttributes().allocation.data_limits) , temp_volatile_reader_proxy_data_( - participant->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, - participant->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators) + participant->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, + participant->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators, + participant->getRTPSParticipantAttributes().allocation.data_limits) , temp_volatile_writer_proxy_data_( - participant->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, - participant->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators) + participant->getRTPSParticipantAttributes().allocation.locators.max_unicast_locators, + participant->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators, + participant->getRTPSParticipantAttributes().allocation.data_limits) { assert(participant != nullptr); } @@ -136,11 +141,11 @@ bool SecurityManager::init( do { ret = authentication_plugin_->validate_local_identity(&local_identity_handle_, - adjusted_participant_key, - domain_id_, - participant_->getRTPSParticipantAttributes(), - participant_->getGuid(), - exception); + adjusted_participant_key, + domain_id_, + participant_->getRTPSParticipantAttributes(), + participant_->getGuid(), + exception); } while (ret == VALIDATION_PENDING_RETRY && usleep_bool()); if (ret == VALIDATION_OK) @@ -166,8 +171,8 @@ bool SecurityManager::init( if (!local_permissions_handle_->nil()) { if (access_plugin_->check_create_participant(*local_permissions_handle_, - domain_id_, - participant_->getRTPSParticipantAttributes(), exception)) + domain_id_, + participant_->getRTPSParticipantAttributes(), exception)) { // Set credentials. PermissionsCredentialToken* token = nullptr; @@ -179,7 +184,7 @@ bool SecurityManager::init( *local_identity_handle_, *token, exception)) { if (!access_plugin_->get_participant_sec_attributes(*local_permissions_handle_, - attributes, exception)) + attributes, exception)) { logError(SECURITY, "Error getting participant security attributes. (" << exception.what() << ")"); @@ -190,7 +195,7 @@ bool SecurityManager::init( else { logError(SECURITY, "Error setting permissions credential token. (" - << exception.what() << ")"); + << exception.what() << ")"); access_plugin_->return_permissions_handle(local_permissions_handle_, exception); local_permissions_handle_ = nullptr; } @@ -200,7 +205,7 @@ bool SecurityManager::init( else { logError(SECURITY, "Error getting permissions credential token. (" - << exception.what() << ")"); + << exception.what() << ")"); access_plugin_->return_permissions_handle(local_permissions_handle_, exception); local_permissions_handle_ = nullptr; } @@ -208,7 +213,7 @@ bool SecurityManager::init( else { logError(SECURITY, "Error checking creation of local participant. (" - << exception.what() << ")"); + << exception.what() << ")"); access_plugin_->return_permissions_handle(local_permissions_handle_, exception); local_permissions_handle_ = nullptr; } @@ -216,7 +221,7 @@ bool SecurityManager::init( else { logError(SECURITY, "Error validating the local participant permissions. (" - << exception.what() << ")"); + << exception.what() << ")"); access_plugin_->return_permissions_handle(local_permissions_handle_, exception); local_permissions_handle_ = nullptr; } @@ -224,7 +229,7 @@ bool SecurityManager::init( else { logError(SECURITY, "Error validating the local participant permissions. (" - << exception.what() << ")"); + << exception.what() << ")"); } } @@ -232,13 +237,13 @@ bool SecurityManager::init( { // Read participant properties. const std::string* property_value = PropertyPolicyHelper::find_property(participant_properties, - "rtps.participant.rtps_protection_kind"); + "rtps.participant.rtps_protection_kind"); if (property_value != nullptr && property_value->compare("ENCRYPT") == 0) { attributes.is_rtps_protected = true; attributes.plugin_participant_attributes |= - PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_VALID | - PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_ENCRYPTED; + PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_VALID | + PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_ENCRYPTED; } } @@ -262,7 +267,7 @@ bool SecurityManager::init( else { logError(SECURITY, "Cannot register local participant in crypto plugin. (" - << exception.what() << ")"); + << exception.what() << ")"); } } else @@ -371,7 +376,7 @@ void SecurityManager::destroy() ParticipantCryptoHandle* participant_crypto_handle = dp_it.second.get_participant_crypto(); if (participant_crypto_handle != nullptr) { - crypto_plugin_->cryptokeyfactory()->unregister_participant(participant_crypto_handle, exception); + crypto_plugin_->cryptokeyfactory()->unregister_participant(participant_crypto_handle, exception); } PermissionsHandle* permissions_handle = dp_it.second.get_permissions_handle(); @@ -501,9 +506,9 @@ bool SecurityManager::discovered_participant( // Create or find information mutex_.lock(); auto map_ret = discovered_participants_.emplace( - std::piecewise_construct, - std::forward_as_tuple(participant_data.m_guid), - std::forward_as_tuple(auth_status, participant_data)); + std::piecewise_construct, + std::forward_as_tuple(participant_data.m_guid), + std::forward_as_tuple(auth_status, participant_data)); DiscoveredParticipantInfo::AuthUniquePtr remote_participant_info = map_ret.first->second.get_auth(); mutex_.unlock(); @@ -519,7 +524,7 @@ bool SecurityManager::discovered_participant( participant_data.identity_token_, participant_data.m_guid, exception); - switch(validation_ret) + switch (validation_ret) { case VALIDATION_OK: assert(remote_identity_handle != nullptr); @@ -534,7 +539,7 @@ bool SecurityManager::discovered_participant( auth_status = AUTHENTICATION_WAITING_REQUEST; break; case VALIDATION_PENDING_RETRY: - // TODO(Ricardo) Send event. + // TODO(Ricardo) Send event. default: if (strlen(exception.what()) > 0) { @@ -561,7 +566,7 @@ bool SecurityManager::discovered_participant( //TODO(Ricardo) cryptograhy registration in AUTHENTICAITON_OK return false; - }; + } logInfo(SECURITY, "Discovered participant " << participant_data.m_guid); @@ -596,7 +601,7 @@ bool SecurityManager::discovered_participant( { // Maybe send request. returnedValue = on_process_handshake(participant_data, remote_participant_info, - MessageIdentity(), HandshakeMessageToken()); + MessageIdentity(), HandshakeMessageToken()); } restore_discovered_participant_info(participant_data.m_guid, remote_participant_info); @@ -619,7 +624,7 @@ void SecurityManager::remove_participant( auto auth_ptr = dp_it->second.get_auth(); ParticipantCryptoHandle* participant_crypto_handle = - dp_it->second.get_participant_crypto(); + dp_it->second.get_participant_crypto(); if (participant_crypto_handle != nullptr) { crypto_plugin_->cryptokeyfactory()->unregister_participant(participant_crypto_handle, @@ -741,14 +746,14 @@ bool SecurityManager::on_process_handshake( // Create message ParticipantGenericMessage message = generate_authentication_message(std::move(message_identity), - participant_data.m_guid, *handshake_message); + participant_data.m_guid, *handshake_message); CacheChange_t* change = participant_stateless_message_writer_->new_change([&message]() -> uint32_t - { - return static_cast(ParticipantGenericMessageHelper::serialized_size(message) - + 4 /*encapsulation*/); - } - , ALIVE, c_InstanceHandle_Unknown); + { + return static_cast(ParticipantGenericMessageHelper::serialized_size(message) + + 4 /*encapsulation*/); + } + , ALIVE, c_InstanceHandle_Unknown); if (change != nullptr) { @@ -807,60 +812,60 @@ bool SecurityManager::on_process_handshake( if (handshake_message_send) { - switch(ret) + switch (ret) { case VALIDATION_OK: case VALIDATION_OK_WITH_FINAL_MESSAGE: case VALIDATION_PENDING_HANDSHAKE_MESSAGE: + { + remote_participant_info->auth_status_ = AUTHENTICATION_OK; + if (ret == VALIDATION_PENDING_HANDSHAKE_MESSAGE) { - remote_participant_info->auth_status_ = AUTHENTICATION_OK; - if (ret == VALIDATION_PENDING_HANDSHAKE_MESSAGE) + if (pre_auth_status == AUTHENTICATION_REQUEST_NOT_SEND) { - if (pre_auth_status == AUTHENTICATION_REQUEST_NOT_SEND) - { - remote_participant_info->auth_status_ = AUTHENTICATION_WAITING_REPLY; - } - else if (pre_auth_status == AUTHENTICATION_WAITING_REQUEST) - { - remote_participant_info->auth_status_ = AUTHENTICATION_WAITING_FINAL; - } + remote_participant_info->auth_status_ = AUTHENTICATION_WAITING_REPLY; } - - // if authentication was finished, starts encryption. - if (remote_participant_info->auth_status_ == AUTHENTICATION_OK) + else if (pre_auth_status == AUTHENTICATION_WAITING_REQUEST) { - SharedSecretHandle* shared_secret_handle = authentication_plugin_->get_shared_secret( - *remote_participant_info->handshake_handle_, exception); - if (!participant_authorized(participant_data, remote_participant_info, - shared_secret_handle)) - { - authentication_plugin_->return_sharedsecret_handle(shared_secret_handle, exception); - } - + remote_participant_info->auth_status_ = AUTHENTICATION_WAITING_FINAL; } + } - if (ret == VALIDATION_PENDING_HANDSHAKE_MESSAGE) + // if authentication was finished, starts encryption. + if (remote_participant_info->auth_status_ == AUTHENTICATION_OK) + { + SharedSecretHandle* shared_secret_handle = authentication_plugin_->get_shared_secret( + *remote_participant_info->handshake_handle_, exception); + if (!participant_authorized(participant_data, remote_participant_info, + shared_secret_handle)) { - remote_participant_info->expected_sequence_number_ = expected_sequence_number; - const GUID_t guid = participant_data.m_guid; - remote_participant_info->event_ = new TimedEvent(participant_->getEventResource(), - [&, guid]() -> bool - { - resend_handshake_message_token(guid); - return true; - }, - 500); // TODO (Ricardo) Configurable - remote_participant_info->event_->restart_timer(); + authentication_plugin_->return_sharedsecret_handle(shared_secret_handle, exception); } - returnedValue = true; } - break; + + if (ret == VALIDATION_PENDING_HANDSHAKE_MESSAGE) + { + remote_participant_info->expected_sequence_number_ = expected_sequence_number; + const GUID_t guid = participant_data.m_guid; + remote_participant_info->event_ = new TimedEvent(participant_->getEventResource(), + [&, guid]() -> bool + { + resend_handshake_message_token(guid); + return true; + }, + 500); // TODO (Ricardo) Configurable + remote_participant_info->event_->restart_timer(); + } + + returnedValue = true; + } + break; case VALIDATION_PENDING_RETRY: - // TODO(Ricardo) Send event. + // TODO(Ricardo) Send event. default: break; - }; + } } return returnedValue; @@ -924,11 +929,13 @@ bool SecurityManager::create_participant_stateless_message_writer() if (participant_->getRTPSParticipantAttributes().throughputController.bytesPerPeriod != UINT32_MAX && participant_->getRTPSParticipantAttributes().throughputController.periodMillisecs != 0) + { watt.mode = ASYNCHRONOUS_WRITER; + } RTPSWriter* wout = nullptr; if (participant_->createWriter(&wout, watt, participant_stateless_message_writer_history_, - nullptr, participant_stateless_message_writer_entity_id, true)) + nullptr, participant_stateless_message_writer_entity_id, true)) { participant_->set_endpoint_rtps_protection_supports(wout, false); participant_stateless_message_writer_ = dynamic_cast(wout); @@ -938,7 +945,7 @@ bool SecurityManager::create_participant_stateless_message_writer() return true; } - logError(SECURITY,"Participant Stateless Message Writer creation failed"); + logError(SECURITY, "Participant Stateless Message Writer creation failed"); delete(participant_stateless_message_writer_history_); participant_stateless_message_writer_history_ = nullptr; @@ -973,17 +980,17 @@ bool SecurityManager::create_participant_stateless_message_reader() if (!participant_->getRTPSParticipantAttributes().builtin.avoid_builtin_multicast) { ratt.endpoint.multicastLocatorList = - participant_->getRTPSParticipantAttributes().builtin.metatrafficMulticastLocatorList; + participant_->getRTPSParticipantAttributes().builtin.metatrafficMulticastLocatorList; } ratt.endpoint.unicastLocatorList = - participant_->getRTPSParticipantAttributes().builtin.metatrafficUnicastLocatorList; + participant_->getRTPSParticipantAttributes().builtin.metatrafficUnicastLocatorList; ratt.endpoint.remoteLocatorList = participant_->getRTPSParticipantAttributes().builtin.initialPeersList; ratt.matched_writers_allocation = participant_->getRTPSParticipantAttributes().allocation.participants; RTPSReader* rout = nullptr; if (participant_->createReader(&rout, ratt, participant_stateless_message_reader_history_, - &participant_stateless_message_listener_, - participant_stateless_message_reader_entity_id, true, true)) + &participant_stateless_message_listener_, + participant_stateless_message_reader_entity_id, true, true)) { participant_->set_endpoint_rtps_protection_supports(rout, false); participant_stateless_message_reader_ = dynamic_cast(rout); @@ -991,7 +998,7 @@ bool SecurityManager::create_participant_stateless_message_reader() return true; } - logError(SECURITY,"Participant Stateless Message Reader creation failed"); + logError(SECURITY, "Participant Stateless Message Reader creation failed"); delete(participant_stateless_message_reader_history_); participant_stateless_message_reader_history_ = nullptr; return false; @@ -1046,21 +1053,23 @@ bool SecurityManager::create_participant_volatile_message_secure_writer() watt.endpoint.topicKind = NO_KEY; watt.endpoint.durabilityKind = VOLATILE; watt.endpoint.unicastLocatorList = - participant_->getRTPSParticipantAttributes().builtin.metatrafficUnicastLocatorList; + participant_->getRTPSParticipantAttributes().builtin.metatrafficUnicastLocatorList; watt.endpoint.remoteLocatorList = participant_->getRTPSParticipantAttributes().builtin.initialPeersList; watt.endpoint.security_attributes().is_submessage_protected = true; watt.endpoint.security_attributes().plugin_endpoint_attributes = - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; watt.matched_readers_allocation = participant_->getRTPSParticipantAttributes().allocation.participants; // TODO(Ricardo) Study keep_all if (participant_->getRTPSParticipantAttributes().throughputController.bytesPerPeriod != UINT32_MAX && participant_->getRTPSParticipantAttributes().throughputController.periodMillisecs != 0) + { watt.mode = ASYNCHRONOUS_WRITER; + } RTPSWriter* wout = nullptr; if (participant_->createWriter(&wout, watt, participant_volatile_message_secure_writer_history_, - nullptr, participant_volatile_message_secure_writer_entity_id, true)) + nullptr, participant_volatile_message_secure_writer_entity_id, true)) { participant_->set_endpoint_rtps_protection_supports(wout, false); participant_volatile_message_secure_writer_ = dynamic_cast(wout); @@ -1068,7 +1077,7 @@ bool SecurityManager::create_participant_volatile_message_secure_writer() return true; } - logError(SECURITY,"Participant Volatile Message Writer creation failed"); + logError(SECURITY, "Participant Volatile Message Writer creation failed"); delete(participant_volatile_message_secure_writer_history_); participant_volatile_message_secure_writer_history_ = nullptr; @@ -1102,17 +1111,17 @@ bool SecurityManager::create_participant_volatile_message_secure_reader() ratt.endpoint.reliabilityKind = RELIABLE; ratt.endpoint.durabilityKind = VOLATILE; ratt.endpoint.unicastLocatorList = - participant_->getRTPSParticipantAttributes().builtin.metatrafficUnicastLocatorList; + participant_->getRTPSParticipantAttributes().builtin.metatrafficUnicastLocatorList; ratt.endpoint.remoteLocatorList = participant_->getRTPSParticipantAttributes().builtin.initialPeersList; ratt.endpoint.security_attributes().is_submessage_protected = true; ratt.endpoint.security_attributes().plugin_endpoint_attributes = - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; ratt.matched_writers_allocation = participant_->getRTPSParticipantAttributes().allocation.participants; RTPSReader* rout = nullptr; if (participant_->createReader(&rout, ratt, participant_volatile_message_secure_reader_history_, - &participant_volatile_message_secure_listener_, - participant_volatile_message_secure_reader_entity_id, true, true)) + &participant_volatile_message_secure_listener_, + participant_volatile_message_secure_reader_entity_id, true, true)) { participant_->set_endpoint_rtps_protection_supports(rout, false); participant_volatile_message_secure_reader_ = dynamic_cast(rout); @@ -1120,7 +1129,7 @@ bool SecurityManager::create_participant_volatile_message_secure_reader() return true; } - logError(SECURITY,"Participant Volatile Message Reader creation failed"); + logError(SECURITY, "Participant Volatile Message Reader creation failed"); delete(participant_volatile_message_secure_reader_history_); participant_volatile_message_secure_reader_history_ = nullptr; return false; @@ -1241,7 +1250,7 @@ void SecurityManager::process_participant_stateless_message( return; } - aux_msg.pos +=2; + aux_msg.pos += 2; CDRMessage::readParticipantGenericMessage(&aux_msg, message); @@ -1269,7 +1278,7 @@ void SecurityManager::process_participant_stateless_message( } const GUID_t remote_participant_key(message.message_identity().source_guid().guidPrefix, - c_EntityId_RTPSParticipant); + c_EntityId_RTPSParticipant); DiscoveredParticipantInfo::AuthUniquePtr remote_participant_info; const ParticipantProxyData* participant_data = nullptr; @@ -1297,7 +1306,7 @@ void SecurityManager::process_participant_stateless_message( if (message.related_message_identity().source_guid() != GUID_t::unknown()) { logInfo(SECURITY, - "Bad ParticipantGenericMessage. related_message_identity.source_guid is not GUID_t::unknown()"); + "Bad ParticipantGenericMessage. related_message_identity.source_guid is not GUID_t::unknown()"); restore_discovered_participant_info(remote_participant_key, remote_participant_info); return; } @@ -1321,8 +1330,8 @@ void SecurityManager::process_participant_stateless_message( { // Remove previous change and send a new one. CacheChange_t* p_change = - participant_stateless_message_writer_history_->remove_change_and_reuse( - remote_participant_info->change_sequence_number_); + participant_stateless_message_writer_history_->remove_change_and_reuse( + remote_participant_info->change_sequence_number_); remote_participant_info->change_sequence_number_ = SequenceNumber_t::unknown(); if (p_change != nullptr) @@ -1341,18 +1350,18 @@ void SecurityManager::process_participant_stateless_message( // Preconditions if (message.related_message_identity().source_guid() - != participant_stateless_message_writer_->getGuid()) + != participant_stateless_message_writer_->getGuid()) { logInfo(SECURITY, - "Bad ParticipantGenericMessage. related_message_identity.source_guid is not mine"); + "Bad ParticipantGenericMessage. related_message_identity.source_guid is not mine"); restore_discovered_participant_info(remote_participant_key, remote_participant_info); return; } if (message.related_message_identity().sequence_number() - != remote_participant_info->expected_sequence_number_) + != remote_participant_info->expected_sequence_number_) { logInfo(SECURITY, - "Bad ParticipantGenericMessage. related_message_identity.sequence_number is not expected"); + "Bad ParticipantGenericMessage. related_message_identity.sequence_number is not expected"); restore_discovered_participant_info(remote_participant_key, remote_participant_info); return; } @@ -1367,18 +1376,18 @@ void SecurityManager::process_participant_stateless_message( { // Preconditions if (message.related_message_identity().source_guid() - != participant_stateless_message_writer_->getGuid()) + != participant_stateless_message_writer_->getGuid()) { logInfo(SECURITY, - "Bad ParticipantGenericMessage. related_message_identity.source_guid is not mine"); + "Bad ParticipantGenericMessage. related_message_identity.source_guid is not mine"); restore_discovered_participant_info(remote_participant_key, remote_participant_info); return; } if (message.related_message_identity().sequence_number() - != remote_participant_info->expected_sequence_number_) + != remote_participant_info->expected_sequence_number_) { logInfo(SECURITY, - "Bad ParticipantGenericMessage. related_message_identity.sequence_number is not expected"); + "Bad ParticipantGenericMessage. related_message_identity.sequence_number is not expected"); restore_discovered_participant_info(remote_participant_key, remote_participant_info); return; } @@ -1394,7 +1403,7 @@ void SecurityManager::process_participant_stateless_message( { // Remove previous change and send a new one. CacheChange_t* p_change = participant_stateless_message_writer_history_->remove_change_and_reuse( - remote_participant_info->change_sequence_number_); + remote_participant_info->change_sequence_number_); remote_participant_info->change_sequence_number_ = SequenceNumber_t::unknown(); if (p_change != nullptr) @@ -1458,7 +1467,7 @@ void SecurityManager::process_participant_volatile_message_secure( return; } - aux_msg.pos +=2; + aux_msg.pos += 2; CDRMessage::readParticipantGenericMessage(&aux_msg, message); @@ -1486,7 +1495,7 @@ void SecurityManager::process_participant_volatile_message_secure( } const GUID_t remote_participant_key(message.message_identity().source_guid().guidPrefix, - c_EntityId_RTPSParticipant); + c_EntityId_RTPSParticipant); ParticipantCryptoHandle* remote_participant_crypto = nullptr; // Search remote participant crypto handle. @@ -1496,7 +1505,9 @@ void SecurityManager::process_participant_volatile_message_secure( if (dp_it != discovered_participants_.end()) { if (dp_it->second.get_participant_crypto() == nullptr) + { return; + } remote_participant_crypto = dp_it->second.get_participant_crypto(); } @@ -1520,7 +1531,9 @@ void SecurityManager::process_participant_volatile_message_secure( } } else + { remote_participant_pending_messages_.emplace(remote_participant_key, std::move(message.message_data())); + } } else if (message.message_class_id().compare(GMCLASSID_SECURITY_READER_CRYPTO_TOKENS) == 0) { @@ -1560,10 +1573,10 @@ void SecurityManager::process_participant_volatile_message_secure( SecurityException exception; if (crypto_plugin_->cryptkeyexchange()->set_remote_datareader_crypto_tokens( - *wr_it->second.writer_handle, - *std::get<1>(rd_it->second), - message.message_data(), - exception)) + *wr_it->second.writer_handle, + *std::get<1>(rd_it->second), + message.message_data(), + exception)) { writer_guid = wr_it->first; reader_data = &(std::get<0>(rd_it->second)); @@ -1575,8 +1588,10 @@ void SecurityManager::process_participant_volatile_message_secure( } } else + { remote_reader_pending_messages_.emplace(message.source_endpoint_key(), - std::move(message.message_data())); + std::move(message.message_data())); + } } else { @@ -1630,10 +1645,10 @@ void SecurityManager::process_participant_volatile_message_secure( SecurityException exception; if (crypto_plugin_->cryptkeyexchange()->set_remote_datawriter_crypto_tokens( - *rd_it->second.reader_handle, - *std::get<1>(wr_it->second), - message.message_data(), - exception)) + *rd_it->second.reader_handle, + *std::get<1>(wr_it->second), + message.message_data(), + exception)) { reader_guid = rd_it->first; writer_data = &(std::get<0>(wr_it->second)); @@ -1645,8 +1660,10 @@ void SecurityManager::process_participant_volatile_message_secure( } } else + { remote_writer_pending_messages_.emplace(message.source_endpoint_key(), - std::move(message.message_data())); + std::move(message.message_data())); + } } else { @@ -1673,7 +1690,7 @@ void SecurityManager::ParticipantStatelessMessageListener::onNewCacheChangeAdded { manager_.process_participant_stateless_message(change); - ReaderHistory *history = reader->getHistory(); + ReaderHistory* history = reader->getHistory(); assert(history); history->remove_change(const_cast(change)); } @@ -1684,7 +1701,7 @@ void SecurityManager::ParticipantVolatileMessageListener::onNewCacheChangeAdded( { manager_.process_participant_volatile_message_secure(change); - ReaderHistory *history = reader->getHistory(); + ReaderHistory* history = reader->getHistory(); assert(history); history->remove_change(const_cast(change)); } @@ -1698,7 +1715,7 @@ bool SecurityManager::get_identity_token( { SecurityException exception; return authentication_plugin_->get_identity_token(identity_token, - *local_identity_handle_, exception); + *local_identity_handle_, exception); } return false; @@ -1708,13 +1725,15 @@ bool SecurityManager::return_identity_token( IdentityToken* identity_token) { if (identity_token == nullptr) + { return true; + } if (authentication_plugin_) { SecurityException exception; return authentication_plugin_->return_identity_token(identity_token, - exception); + exception); } return false; @@ -1729,7 +1748,7 @@ bool SecurityManager::get_permissions_token( { SecurityException exception; return access_plugin_->get_permissions_token(permissions_token, - *local_permissions_handle_, exception); + *local_permissions_handle_, exception); } return false; @@ -1739,13 +1758,15 @@ bool SecurityManager::return_permissions_token( PermissionsToken* permissions_token) { if (permissions_token == nullptr) + { return true; + } if (access_plugin_) { SecurityException exception; return access_plugin_->return_permissions_token(permissions_token, - exception); + exception); } return false; @@ -1756,13 +1777,21 @@ uint32_t SecurityManager::builtin_endpoints() uint32_t be = 0; if (participant_stateless_message_reader_ != nullptr) + { be |= BUILTIN_ENDPOINT_PARTICIPANT_STATELESS_MESSAGE_READER; + } if (participant_stateless_message_writer_ != nullptr) + { be |= BUILTIN_ENDPOINT_PARTICIPANT_STATELESS_MESSAGE_WRITER; + } if (participant_volatile_message_secure_reader_ != nullptr) + { be |= BUILTIN_ENDPOINT_PARTICIPANT_VOLATILE_MESSAGE_SECURE_READER; + } if (participant_volatile_message_secure_writer_ != nullptr) + { be |= BUILTIN_ENDPOINT_PARTICIPANT_VOLATILE_MESSAGE_SECURE_WRITER; + } return be; } @@ -1774,7 +1803,7 @@ void SecurityManager::match_builtin_endpoints( const NetworkFactory& network = participant_->network_factory(); if (participant_stateless_message_reader_ != nullptr && - builtin_endpoints & BUILTIN_ENDPOINT_PARTICIPANT_STATELESS_MESSAGE_WRITER) + builtin_endpoints & BUILTIN_ENDPOINT_PARTICIPANT_STATELESS_MESSAGE_WRITER) { std::lock_guard data_guard(temp_stateless_data_lock_); temp_stateless_writer_proxy_data_.clear(); @@ -1789,7 +1818,7 @@ void SecurityManager::match_builtin_endpoints( } if (participant_stateless_message_writer_ != nullptr && - builtin_endpoints & BUILTIN_ENDPOINT_PARTICIPANT_STATELESS_MESSAGE_READER) + builtin_endpoints & BUILTIN_ENDPOINT_PARTICIPANT_STATELESS_MESSAGE_READER) { std::lock_guard data_guard(temp_stateless_data_lock_); temp_stateless_reader_proxy_data_.clear(); @@ -1886,18 +1915,19 @@ void SecurityManager::exchange_participant_crypto( // Get participant crypto tokens. ParticipantCryptoTokenSeq local_participant_crypto_tokens; if (crypto_plugin_->cryptkeyexchange()->create_local_participant_crypto_tokens(local_participant_crypto_tokens, - *local_participant_crypto_handle_, *remote_participant_crypto, exception)) + *local_participant_crypto_handle_, *remote_participant_crypto, exception)) { ParticipantGenericMessage message = generate_participant_crypto_token_message(remote_participant_guid, - local_participant_crypto_tokens); + local_participant_crypto_tokens); - CacheChange_t* change = participant_volatile_message_secure_writer_->new_change([&message]() -> uint32_t - { - return static_cast(ParticipantGenericMessageHelper::serialized_size(message) - + 4 /*encapsulation*/); - } - , ALIVE, c_InstanceHandle_Unknown); + CacheChange_t* change = participant_volatile_message_secure_writer_->new_change( + [&message]() -> uint32_t + { + return static_cast(ParticipantGenericMessageHelper::serialized_size(message) + + 4 /*encapsulation*/); + } + , ALIVE, c_InstanceHandle_Unknown); if (change != nullptr) { @@ -1955,15 +1985,17 @@ ParticipantCryptoHandle* SecurityManager::register_and_match_crypto_endpoint( SharedSecretHandle& shared_secret) { if (crypto_plugin_ == nullptr) + { return nullptr; + } NilHandle nil_handle; SecurityException exception; // Register remote participant into crypto plugin. ParticipantCryptoHandle* remote_participant_crypto = - crypto_plugin_->cryptokeyfactory()->register_matched_remote_participant(*local_participant_crypto_handle_, - remote_participant_identity, nil_handle, shared_secret, exception); + crypto_plugin_->cryptokeyfactory()->register_matched_remote_participant(*local_participant_crypto_handle_, + remote_participant_identity, nil_handle, shared_secret, exception); if (remote_participant_crypto != nullptr) { @@ -1980,7 +2012,7 @@ ParticipantCryptoHandle* SecurityManager::register_and_match_crypto_endpoint( bool SecurityManager::encode_rtps_message( const CDRMessage_t& input_message, CDRMessage_t& output_message, - const std::vector &receiving_list) + const std::vector& receiving_list) { if (crypto_plugin_ == nullptr) { @@ -2018,8 +2050,8 @@ bool SecurityManager::encode_rtps_message( SecurityException exception; return crypto_plugin_->cryptotransform()->encode_rtps_message(output_message, - input_message, *local_participant_crypto_handle_, receiving_crypto_list, - exception); + input_message, *local_participant_crypto_handle_, receiving_crypto_list, + exception); } int SecurityManager::decode_rtps_message( @@ -2028,10 +2060,14 @@ int SecurityManager::decode_rtps_message( const GuidPrefix_t& remote_participant) { if (message.buffer[message.pos] != SRTPS_PREFIX) + { return 1; + } if (crypto_plugin_ == nullptr) + { return 0; + } // Init output buffer CDRMessage::initCDRMsg(&out_message); @@ -2099,7 +2135,7 @@ bool SecurityManager::register_local_writer( std::string topic_name, partitions_str; std::vector partitions; const std::string* property_value = PropertyPolicyHelper::find_property(writer_properties, - "topic_name"); + "topic_name"); if (property_value != nullptr) { @@ -2107,7 +2143,7 @@ bool SecurityManager::register_local_writer( } property_value = PropertyPolicyHelper::find_property(writer_properties, - "partitions"); + "partitions"); if (property_value != nullptr) { @@ -2128,10 +2164,10 @@ bool SecurityManager::register_local_writer( if (!topic_name.empty()) { if (access_plugin_->check_create_datawriter(*local_permissions_handle_, - domain_id_, topic_name, partitions, exception)) + domain_id_, topic_name, partitions, exception)) { if ((returned_value = access_plugin_->get_datawriter_sec_attributes(*local_permissions_handle_, - topic_name, partitions, security_attributes, exception)) == false) + topic_name, partitions, security_attributes, exception)) == false) { logError(SECURITY, "Error getting security attributes of local writer " << writer_guid << " (" << exception.what() << ")" << std::endl); @@ -2139,49 +2175,49 @@ bool SecurityManager::register_local_writer( } else { - logError(SECURITY, "Error checking creation of local writer " << writer_guid << - " (" << exception.what() << ")" << std::endl); - returned_value = false; + logError(SECURITY, "Error checking creation of local writer " << writer_guid << + " (" << exception.what() << ")" << std::endl); + returned_value = false; } } else { - logError(SECURITY, "Error. No topic_name." << std::endl); - returned_value = false; + logError(SECURITY, "Error. No topic_name." << std::endl); + returned_value = false; } } else { // Get properties. const std::string* property_value = PropertyPolicyHelper::find_property(writer_properties, - "rtps.endpoint.submessage_protection_kind"); + "rtps.endpoint.submessage_protection_kind"); if (property_value != nullptr && property_value->compare("ENCRYPT") == 0) { security_attributes.is_submessage_protected = true; security_attributes.plugin_endpoint_attributes |= - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID | - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID | + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; } property_value = PropertyPolicyHelper::find_property(writer_properties, - "rtps.endpoint.payload_protection_kind"); + "rtps.endpoint.payload_protection_kind"); if (property_value != nullptr && property_value->compare("ENCRYPT") == 0) { security_attributes.is_payload_protected = true; security_attributes.is_key_protected = true; security_attributes.plugin_endpoint_attributes |= - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID | - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_PAYLOAD_ENCRYPTED; + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID | + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_PAYLOAD_ENCRYPTED; } } if (returned_value && crypto_plugin_ != nullptr && (security_attributes.is_submessage_protected || - security_attributes.is_payload_protected)) + security_attributes.is_payload_protected)) { DatawriterCryptoHandle* writer_handle = crypto_plugin_->cryptokeyfactory()->register_local_datawriter( - *local_participant_crypto_handle_, writer_properties.properties(), security_attributes, exception); + *local_participant_crypto_handle_, writer_properties.properties(), security_attributes, exception); if (writer_handle != nullptr && !writer_handle->nil()) { @@ -2206,11 +2242,11 @@ bool SecurityManager::register_local_builtin_writer( SecurityException exception; if (crypto_plugin_ != nullptr && security_attributes.is_submessage_protected && - writer_guid.entityId != participant_volatile_message_secure_writer_entity_id) + writer_guid.entityId != participant_volatile_message_secure_writer_entity_id) { PropertySeq auxProps; DatawriterCryptoHandle* writer_handle = crypto_plugin_->cryptokeyfactory()->register_local_datawriter( - *local_participant_crypto_handle_, auxProps, security_attributes, exception); + *local_participant_crypto_handle_, auxProps, security_attributes, exception); if (writer_handle != nullptr && !writer_handle->nil()) { @@ -2231,7 +2267,9 @@ bool SecurityManager::unregister_local_writer( const GUID_t& writer_guid) { if (crypto_plugin_ == nullptr) + { return false; + } std::unique_lock lock(mutex_); auto local_writer = writer_handles_.find(writer_guid); @@ -2270,7 +2308,7 @@ bool SecurityManager::register_local_reader( std::string topic_name, partitions_str; std::vector partitions; const std::string* property_value = PropertyPolicyHelper::find_property(reader_properties, - "topic_name"); + "topic_name"); if (property_value != nullptr) { @@ -2278,7 +2316,7 @@ bool SecurityManager::register_local_reader( } property_value = PropertyPolicyHelper::find_property(reader_properties, - "partitions"); + "partitions"); if (property_value != nullptr) { @@ -2299,10 +2337,10 @@ bool SecurityManager::register_local_reader( if (!topic_name.empty()) { if (access_plugin_->check_create_datareader( *local_permissions_handle_, - domain_id_, topic_name, partitions, exception)) + domain_id_, topic_name, partitions, exception)) { if ((returned_value = access_plugin_->get_datareader_sec_attributes(*local_permissions_handle_, - topic_name, partitions, security_attributes, exception)) == false) + topic_name, partitions, security_attributes, exception)) == false) { logError(SECURITY, "Error getting security attributes of local reader " << reader_guid << " (" << exception.what() << ")" << std::endl); @@ -2317,8 +2355,8 @@ bool SecurityManager::register_local_reader( } else { - logError(SECURITY, "Error. No topic_name." << std::endl); - returned_value = false; + logError(SECURITY, "Error. No topic_name." << std::endl); + returned_value = false; } } else @@ -2331,8 +2369,8 @@ bool SecurityManager::register_local_reader( { security_attributes.is_submessage_protected = true; security_attributes.plugin_endpoint_attributes |= - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID | - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID | + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED; } property_value = PropertyPolicyHelper::find_property(reader_properties, @@ -2343,17 +2381,17 @@ bool SecurityManager::register_local_reader( security_attributes.is_payload_protected = true; security_attributes.is_key_protected = true; security_attributes.plugin_endpoint_attributes |= - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID | - PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_PAYLOAD_ENCRYPTED; + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID | + PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_PAYLOAD_ENCRYPTED; } } if (returned_value && crypto_plugin_ != nullptr && (security_attributes.is_submessage_protected || - security_attributes.is_payload_protected)) + security_attributes.is_payload_protected)) { DatareaderCryptoHandle* reader_handle = crypto_plugin_->cryptokeyfactory()->register_local_datareader( - *local_participant_crypto_handle_, reader_properties.properties(), security_attributes, exception); + *local_participant_crypto_handle_, reader_properties.properties(), security_attributes, exception); if (reader_handle != nullptr && !reader_handle->nil()) { @@ -2378,11 +2416,11 @@ bool SecurityManager::register_local_builtin_reader( SecurityException exception; if (crypto_plugin_ != nullptr && security_attributes.is_submessage_protected && - reader_guid.entityId != participant_volatile_message_secure_reader_entity_id) + reader_guid.entityId != participant_volatile_message_secure_reader_entity_id) { PropertySeq auxProps; DatareaderCryptoHandle* reader_handle = crypto_plugin_->cryptokeyfactory()->register_local_datareader( - *local_participant_crypto_handle_, auxProps, security_attributes, exception); + *local_participant_crypto_handle_, auxProps, security_attributes, exception); if (reader_handle != nullptr && !reader_handle->nil()) { @@ -2403,7 +2441,9 @@ bool SecurityManager::unregister_local_reader( const GUID_t& reader_guid) { if (crypto_plugin_ == nullptr) + { return false; + } std::unique_lock lock(mutex_); auto local_reader = reader_handles_.find(reader_guid); @@ -2443,7 +2483,9 @@ void SecurityManager::remove_reader( const GUID_t& remote_reader_guid) { if (crypto_plugin_ == nullptr) + { return; + } std::unique_lock lock(mutex_); @@ -2489,7 +2531,7 @@ bool SecurityManager::discovered_reader( SharedSecretHandle* shared_secret_handle = &SharedSecretHandle::nil_handle; if (!security_attributes.match(remote_reader_data.security_attributes_, - remote_reader_data.plugin_security_attributes_)) + remote_reader_data.plugin_security_attributes_)) { return false; } @@ -2520,18 +2562,18 @@ bool SecurityManager::discovered_reader( if (!is_builtin && access_plugin_ != nullptr && remote_permissions != nullptr) { if ((returned_value = access_plugin_->check_remote_datareader( - *remote_permissions, domain_id_, remote_reader_data, relay_only, exception)) == false) + *remote_permissions, domain_id_, remote_reader_data, relay_only, exception)) == false) { logError(SECURITY, "Error checking create remote reader " << remote_reader_data.guid() - << " (" << exception.what() << ")"); + << " (" << exception.what() << ")"); } } if (returned_value && crypto_plugin_ != nullptr && (security_attributes.is_submessage_protected || - security_attributes.is_payload_protected)) + security_attributes.is_payload_protected)) { bool is_key_exchange = (remote_reader_data.guid().entityId - == participant_volatile_message_secure_reader_entity_id); + == participant_volatile_message_secure_reader_entity_id); auto local_writer = writer_handles_.find(writer_guid); returned_value = false; @@ -2550,7 +2592,7 @@ bool SecurityManager::discovered_reader( { logInfo(SECURITY, "Process successful discovering local reader " << remote_reader_data.guid()); local_writer->second.associated_readers.emplace(remote_reader_data.guid(), - std::make_tuple(remote_reader_data, remote_reader_handle)); + std::make_tuple(remote_reader_data, remote_reader_handle)); lock.unlock(); participant_->pairing_remote_reader_with_local_writer_after_security( writer_guid, remote_reader_data); @@ -2564,17 +2606,17 @@ bool SecurityManager::discovered_reader( if (pending != remote_reader_pending_messages_.end()) { if (crypto_plugin_->cryptkeyexchange()->set_remote_datareader_crypto_tokens( - *local_writer->second.writer_handle, - *remote_reader_handle, - pending->second, - exception)) + *local_writer->second.writer_handle, + *remote_reader_handle, + pending->second, + exception)) { pairing_cause_pending_message = true; } else { logError(SECURITY, "Cannot set remote reader crypto tokens (" - << remote_reader_data.guid() << ") - (" << exception.what() << ")"); + << remote_reader_data.guid() << ") - (" << exception.what() << ")"); } remote_reader_pending_messages_.erase(pending); @@ -2593,11 +2635,11 @@ bool SecurityManager::discovered_reader( if (remote_participant_key == participant_->getGuid()) { logInfo(SECURITY, "Process successful discovering local reader " - << remote_reader_data.guid()); + << remote_reader_data.guid()); local_writer->second.associated_readers.emplace(remote_reader_data.guid(), - std::make_tuple(remote_reader_data, remote_reader_handle)); + std::make_tuple(remote_reader_data, remote_reader_handle)); - // Search local reader. + // Search local reader. auto local_reader = reader_handles_.find(remote_reader_data.guid()); if (local_reader != reader_handles_.end()) @@ -2608,10 +2650,10 @@ bool SecurityManager::discovered_reader( if (remote_writer != local_reader->second.associated_writers.end()) { if (crypto_plugin_->cryptkeyexchange()->set_remote_datawriter_crypto_tokens( - *local_reader->second.reader_handle, - *std::get<1>(remote_writer->second), - local_writer_crypto_tokens, - exception)) + *local_reader->second.reader_handle, + *std::get<1>(remote_writer->second), + local_writer_crypto_tokens, + exception)) { local_reader_guid = local_reader->first; writer_data = &(std::get<0>(remote_writer->second)); @@ -2619,7 +2661,7 @@ bool SecurityManager::discovered_reader( else { logError(SECURITY, "Cannot set local reader crypto tokens (" - << remote_reader_data.guid() << ") - (" << exception.what() << ")"); + << remote_reader_data.guid() << ") - (" << exception.what() << ")"); } } else @@ -2633,27 +2675,27 @@ bool SecurityManager::discovered_reader( else { logError(SECURITY, "Cannot find local reader (" - << remote_reader_data.guid() << ") - (" << exception.what() << ")"); + << remote_reader_data.guid() << ") - (" << exception.what() << ")"); } } else { ParticipantGenericMessage message = - generate_writer_crypto_token_message(remote_participant_key, - remote_reader_data.guid(), writer_guid, local_writer_crypto_tokens); + generate_writer_crypto_token_message(remote_participant_key, + remote_reader_data.guid(), writer_guid, local_writer_crypto_tokens); local_writer->second.associated_readers.emplace(remote_reader_data.guid(), - std::make_tuple(remote_reader_data, remote_reader_handle)); + std::make_tuple(remote_reader_data, remote_reader_handle)); lock.unlock(); CacheChange_t* change = participant_volatile_message_secure_writer_->new_change( [&message]() -> uint32_t - { - return static_cast( + { + return static_cast( ParticipantGenericMessageHelper::serialized_size(message) + 4 /*encapsulation*/); - } - , ALIVE, c_InstanceHandle_Unknown); + } + , ALIVE, c_InstanceHandle_Unknown); if (change != nullptr) { @@ -2685,7 +2727,7 @@ bool SecurityManager::discovered_reader( if (participant_volatile_message_secure_writer_history_->add_change(change)) { logInfo(SECURITY, "Process successful discovering remote reader " - << remote_reader_data.guid()); + << remote_reader_data.guid()); returned_value = true; } else @@ -2722,7 +2764,7 @@ bool SecurityManager::discovered_reader( if (local_reader_guid != GUID_t::unknown()) { participant_->pairing_remote_writer_with_local_reader_after_security( - local_reader_guid, *writer_data); + local_reader_guid, *writer_data); } // If writer was found and setting of crypto tokens works, @@ -2730,7 +2772,7 @@ bool SecurityManager::discovered_reader( if (pairing_cause_pending_message) { participant_->pairing_remote_reader_with_local_writer_after_security( - writer_guid, remote_reader_data); + writer_guid, remote_reader_data); } } } @@ -2746,7 +2788,7 @@ bool SecurityManager::discovered_reader( " of participant " << remote_participant_key << " on pendings"); remote_reader_pending_discovery_messages_.push_back(std::make_tuple(remote_reader_data, - remote_participant_key, writer_guid)); + remote_participant_key, writer_guid)); } } else @@ -2758,7 +2800,7 @@ bool SecurityManager::discovered_reader( { lock.unlock(); participant_->pairing_remote_reader_with_local_writer_after_security( - writer_guid, remote_reader_data); + writer_guid, remote_reader_data); } return returned_value; @@ -2827,7 +2869,7 @@ bool SecurityManager::discovered_writer( SharedSecretHandle* shared_secret_handle = &SharedSecretHandle::nil_handle; if (!security_attributes.match(remote_writer_data.security_attributes_, - remote_writer_data.plugin_security_attributes_)) + remote_writer_data.plugin_security_attributes_)) { return false; } @@ -2857,18 +2899,18 @@ bool SecurityManager::discovered_writer( if (!is_builtin && access_plugin_ != nullptr && remote_permissions != nullptr) { if ((returned_value = access_plugin_->check_remote_datawriter( - *remote_permissions, domain_id_, remote_writer_data, exception)) == false) + *remote_permissions, domain_id_, remote_writer_data, exception)) == false) { logError(SECURITY, "Error checking create remote writer " << remote_writer_data.guid() - << " (" << exception.what() << ")"); + << " (" << exception.what() << ")"); } } if (returned_value && crypto_plugin_ != nullptr && (security_attributes.is_submessage_protected || - security_attributes.is_payload_protected)) + security_attributes.is_payload_protected)) { bool is_key_exchange = (remote_writer_data.guid().entityId - == participant_volatile_message_secure_writer_entity_id); + == participant_volatile_message_secure_writer_entity_id); auto local_reader = reader_handles_.find(reader_guid); returned_value = false; @@ -2887,7 +2929,7 @@ bool SecurityManager::discovered_writer( { logInfo(SECURITY, "Process successful discovering local writer " << remote_writer_data.guid()); local_reader->second.associated_writers.emplace(remote_writer_data.guid(), - std::make_tuple(remote_writer_data, remote_writer_handle)); + std::make_tuple(remote_writer_data, remote_writer_handle)); lock.unlock(); participant_->pairing_remote_writer_with_local_reader_after_security( reader_guid, remote_writer_data); @@ -2901,10 +2943,10 @@ bool SecurityManager::discovered_writer( if (pending != remote_writer_pending_messages_.end()) { if (crypto_plugin_->cryptkeyexchange()->set_remote_datawriter_crypto_tokens( - *local_reader->second.reader_handle, - *remote_writer_handle, - pending->second, - exception)) + *local_reader->second.reader_handle, + *remote_writer_handle, + pending->second, + exception)) { pairing_cause_pending_message = true; } @@ -2931,9 +2973,9 @@ bool SecurityManager::discovered_writer( if (remote_participant_key == participant_->getGuid()) { logInfo(SECURITY, "Process successful discovering local writer " - << remote_writer_data.guid()); + << remote_writer_data.guid()); local_reader->second.associated_writers.emplace(remote_writer_data.guid(), - std::make_tuple(remote_writer_data, remote_writer_handle)); + std::make_tuple(remote_writer_data, remote_writer_handle)); // Search local writer. auto local_writer = writer_handles_.find(remote_writer_data.guid()); @@ -2946,10 +2988,10 @@ bool SecurityManager::discovered_writer( if (remote_reader != local_writer->second.associated_readers.end()) { if (crypto_plugin_->cryptkeyexchange()->set_remote_datareader_crypto_tokens( - *local_writer->second.writer_handle, - *std::get<1>(remote_reader->second), - local_reader_crypto_tokens, - exception)) + *local_writer->second.writer_handle, + *std::get<1>(remote_reader->second), + local_reader_crypto_tokens, + exception)) { local_writer_guid = local_writer->first; reader_data = &(std::get<0>(remote_reader->second)); @@ -2957,7 +2999,7 @@ bool SecurityManager::discovered_writer( else { logError(SECURITY, "Cannot set local writer crypto tokens (" - << remote_writer_data.guid() << ") - (" << exception.what() << ")"); + << remote_writer_data.guid() << ") - (" << exception.what() << ")"); } } else @@ -2970,27 +3012,27 @@ bool SecurityManager::discovered_writer( else { logError(SECURITY, "Cannot find local writer (" - << remote_writer_data.guid() << ") - (" << exception.what() << ")"); + << remote_writer_data.guid() << ") - (" << exception.what() << ")"); } } else { ParticipantGenericMessage message = - generate_reader_crypto_token_message(remote_participant_key, - remote_writer_data.guid(), reader_guid, local_reader_crypto_tokens); + generate_reader_crypto_token_message(remote_participant_key, + remote_writer_data.guid(), reader_guid, local_reader_crypto_tokens); local_reader->second.associated_writers.emplace(remote_writer_data.guid(), - std::make_tuple(remote_writer_data, remote_writer_handle)); + std::make_tuple(remote_writer_data, remote_writer_handle)); lock.unlock(); CacheChange_t* change = participant_volatile_message_secure_writer_->new_change( [&message]() -> uint32_t { return static_cast( - ParticipantGenericMessageHelper::serialized_size(message) - + 4 /*encapsulation*/); + ParticipantGenericMessageHelper::serialized_size(message) + + 4 /*encapsulation*/); } - , ALIVE, c_InstanceHandle_Unknown); + , ALIVE, c_InstanceHandle_Unknown); if (change != nullptr) { @@ -3022,7 +3064,7 @@ bool SecurityManager::discovered_writer( if (participant_volatile_message_secure_writer_history_->add_change(change)) { logInfo(SECURITY, "Process successful discovering remote writer " - << remote_writer_data.guid()); + << remote_writer_data.guid()); returned_value = true; } else @@ -3060,7 +3102,7 @@ bool SecurityManager::discovered_writer( if (local_writer_guid != GUID_t::unknown()) { participant_->pairing_remote_reader_with_local_writer_after_security( - local_writer_guid, *reader_data); + local_writer_guid, *reader_data); } // If reader was found and setting of crypto tokens works, @@ -3068,7 +3110,7 @@ bool SecurityManager::discovered_writer( if (pairing_cause_pending_message) { participant_->pairing_remote_writer_with_local_reader_after_security( - reader_guid, remote_writer_data); + reader_guid, remote_writer_data); } } } @@ -3084,7 +3126,7 @@ bool SecurityManager::discovered_writer( " of participant " << remote_participant_key << "on pendings"); remote_writer_pending_discovery_messages_.push_back(std::make_tuple(remote_writer_data, - remote_participant_key, reader_guid)); + remote_participant_key, reader_guid)); } } else @@ -3096,7 +3138,7 @@ bool SecurityManager::discovered_writer( { lock.unlock(); participant_->pairing_remote_writer_with_local_reader_after_security( - reader_guid, remote_writer_data); + reader_guid, remote_writer_data); } return returned_value; @@ -3134,8 +3176,8 @@ bool SecurityManager::encode_writer_submessage( auxProps.emplace_back( Property("dds.sec.builtin_endpoint_name", "BuiltinParticipantVolatileMessageSecureWriter")); auto wHandle = - crypto_plugin_->cryptokeyfactory()->register_local_datawriter( - *pCrypto, auxProps, attr, exception); + crypto_plugin_->cryptokeyfactory()->register_local_datawriter( + *pCrypto, auxProps, attr, exception); std::vector receiving_crypto_list; if (wHandle != nullptr) { @@ -3160,7 +3202,9 @@ bool SecurityManager::encode_writer_submessage( const auto rd_it_handle = wr_it->second.associated_readers.find(rd_it); if (rd_it_handle != wr_it->second.associated_readers.end()) + { receiving_datareader_crypto_list.push_back(std::get<1>(rd_it_handle->second)); + } else { logError(SECURITY, "Cannot find remote reader " << rd_it); @@ -3172,10 +3216,10 @@ bool SecurityManager::encode_writer_submessage( SecurityException exception; if (crypto_plugin_->cryptotransform()->encode_datawriter_submessage(output_message, - input_message, - *wr_it->second.writer_handle, - receiving_datareader_crypto_list, - exception)) + input_message, + *wr_it->second.writer_handle, + receiving_datareader_crypto_list, + exception)) { return true; } @@ -3222,8 +3266,8 @@ bool SecurityManager::encode_reader_submessage( auxProps.emplace_back( Property("dds.sec.builtin_endpoint_name", "BuiltinParticipantVolatileMessageSecureReader")); auto rHandle = - crypto_plugin_->cryptokeyfactory()->register_local_datareader( - *pCrypto, auxProps, attr, exception); + crypto_plugin_->cryptokeyfactory()->register_local_datareader( + *pCrypto, auxProps, attr, exception); std::vector receiving_crypto_list; if (rHandle != nullptr) { @@ -3248,7 +3292,9 @@ bool SecurityManager::encode_reader_submessage( const auto wr_it_handle = rd_it->second.associated_writers.find(wr_it); if (wr_it_handle != rd_it->second.associated_writers.end()) + { receiving_datawriter_crypto_list.push_back(std::get<1>(wr_it_handle->second)); + } else { logError(SECURITY, "Cannot find remote writer " << wr_it); @@ -3260,10 +3306,10 @@ bool SecurityManager::encode_reader_submessage( SecurityException exception; if (crypto_plugin_->cryptotransform()->encode_datareader_submessage(output_message, - input_message, - *rd_it->second.reader_handle, - receiving_datawriter_crypto_list, - exception)) + input_message, + *rd_it->second.reader_handle, + receiving_datawriter_crypto_list, + exception)) { return true; } @@ -3319,14 +3365,14 @@ int SecurityManager::decode_rtps_submessage( SecurityException exception; if (crypto_plugin_->cryptotransform()->preprocess_secure_submsg(&writer_handle, &reader_handle, - category, message, *local_participant_crypto_handle_, - *remote_participant_crypto_handle, exception)) + category, message, *local_participant_crypto_handle_, + *remote_participant_crypto_handle, exception)) { // TODO (Ricardo) Category INFO if (category == DATAWRITER_SUBMESSAGE) { if (crypto_plugin_->cryptotransform()->decode_datawriter_submessage(out_message, message, - *reader_handle, *writer_handle, exception)) + *reader_handle, *writer_handle, exception)) { return 0; } @@ -3338,7 +3384,7 @@ int SecurityManager::decode_rtps_submessage( else if (category == DATAREADER_SUBMESSAGE) { if (crypto_plugin_->cryptotransform()->decode_datareader_submessage(out_message, message, - *writer_handle, *reader_handle, exception)) + *writer_handle, *reader_handle, exception)) { return 0; } @@ -3381,10 +3427,10 @@ bool SecurityManager::encode_serialized_payload( std::vector extra_inline_qos; if (crypto_plugin_->cryptotransform()->encode_serialized_payload(output_payload, - extra_inline_qos, - payload, - *wr_it->second.writer_handle, - exception)) + extra_inline_qos, + payload, + *wr_it->second.writer_handle, + exception)) { return true; } @@ -3426,8 +3472,8 @@ bool SecurityManager::decode_serialized_payload( SecurityException exception; if (crypto_plugin_->cryptotransform()->decode_serialized_payload(payload, - secure_payload, inline_qos, *rd_it->second.reader_handle, - *std::get<1>(wr_it_handle->second), exception)) + secure_payload, inline_qos, *rd_it->second.reader_handle, + *std::get<1>(wr_it_handle->second), exception)) { return true; } @@ -3466,7 +3512,7 @@ bool SecurityManager::participant_authorized( *remote_participant_info->identity_handle_, exception)) { remote_permissions = - access_plugin_->validate_remote_permissions(*authentication_plugin_, + access_plugin_->validate_remote_permissions(*authentication_plugin_, *local_identity_handle_, *local_permissions_handle_, *remote_participant_info->identity_handle_, @@ -3476,7 +3522,7 @@ bool SecurityManager::participant_authorized( if (remote_permissions != nullptr && !remote_permissions->nil()) { if (!access_plugin_->check_remote_participant(*remote_permissions, domain_id_, - participant_data, exception)) + participant_data, exception)) { logError(SECURITY, "Error checking remote participant " << participant_data.m_guid << " (" << exception.what() << ")."); @@ -3487,7 +3533,7 @@ bool SecurityManager::participant_authorized( else { logError(SECURITY, "Error validating remote permissions for " << - participant_data.m_guid << " (" << exception.what() << ")."); + participant_data.m_guid << " (" << exception.what() << ")."); if (remote_permissions != nullptr) { @@ -3509,8 +3555,8 @@ bool SecurityManager::participant_authorized( if (access_plugin_ == nullptr || remote_permissions != nullptr) { - std::list> temp_readers; - std::list> temp_writers; + std::list > temp_readers; + std::list > temp_writers; if (crypto_plugin_ != nullptr) { @@ -3523,8 +3569,8 @@ bool SecurityManager::participant_authorized( // Starts cryptography mechanism ParticipantCryptoHandle* participant_crypto_handle = - register_and_match_crypto_endpoint(*remote_participant_info->identity_handle_, - *shared_secret_handle); + register_and_match_crypto_endpoint(*remote_participant_info->identity_handle_, + *shared_secret_handle); // Store cryptography info if (participant_crypto_handle != nullptr && !participant_crypto_handle->nil()) @@ -3537,10 +3583,10 @@ bool SecurityManager::participant_authorized( if (pending != remote_participant_pending_messages_.end()) { if (!crypto_plugin_->cryptkeyexchange()->set_remote_participant_crypto_tokens( - *local_participant_crypto_handle_, - *participant_crypto_handle, - pending->second, - exception)) + *local_participant_crypto_handle_, + *participant_crypto_handle, + pending->second, + exception)) { logError(SECURITY, "Cannot set remote participant crypto tokens (" << participant_data.m_guid << ") - (" << exception.what() << ")"); @@ -3729,7 +3775,7 @@ void SecurityManager::resend_handshake_message_token( if (remote_participant_info->change_sequence_number_ != SequenceNumber_t::unknown()) { CacheChange_t* p_change = participant_stateless_message_writer_history_->remove_change_and_reuse( - remote_participant_info->change_sequence_number_); + remote_participant_info->change_sequence_number_); remote_participant_info->change_sequence_number_ = SequenceNumber_t::unknown(); if (p_change != nullptr) diff --git a/src/cpp/rtps/xmlparser/XMLElementParser.cpp b/src/cpp/rtps/xmlparser/XMLElementParser.cpp index 2ce468a7eaa..0ec66ba544d 100644 --- a/src/cpp/rtps/xmlparser/XMLElementParser.cpp +++ b/src/cpp/rtps/xmlparser/XMLElementParser.cpp @@ -38,12 +38,16 @@ XMLP_ret XMLParser::getXMLParticipantAllocationAttributes( + + + */ tinyxml2::XMLElement* p_aux0 = nullptr; const char* name = nullptr; + uint32_t tmp; for (p_aux0 = elem->FirstChildElement(); p_aux0 != NULL; p_aux0 = p_aux0->NextSiblingElement()) { name = p_aux0->Name(); @@ -87,6 +91,33 @@ XMLP_ret XMLParser::getXMLParticipantAllocationAttributes( return XMLP_ret::XML_ERROR; } } + else if (strcmp(name, MAX_PROPERTIES) == 0) + { + // max number of properties in incomming message - uint32Type + if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &tmp, ident)) + { + return XMLP_ret::XML_ERROR; + } + allocation.data_limits.max_properties = tmp; + } + else if (strcmp(name, MAX_USER_DATA) == 0) + { + // max number of user data in incomming message - uint32Type + if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &tmp, ident)) + { + return XMLP_ret::XML_ERROR; + } + allocation.data_limits.max_user_data = tmp; + } + else if (strcmp(name, MAX_PARTITIONS) == 0) + { + // max number of user data in incomming message - uint32Type + if (XMLP_ret::XML_OK != getXMLUint(p_aux0, &tmp, ident)) + { + return XMLP_ret::XML_ERROR; + } + allocation.data_limits.max_partitions = tmp; + } else { logError(XMLPARSER, "Invalid element found into 'rtpsParticipantAllocationAttributesType'. Name: " << name); @@ -228,11 +259,13 @@ XMLP_ret XMLParser::getXMLDiscoverySettings( return XMLP_ret::XML_ERROR; } } - else if(strcmp(name, IGNORE_PARTICIPANT_FLAGS) == 0) + else if (strcmp(name, IGNORE_PARTICIPANT_FLAGS) == 0) { // ignoreParticipantFlags - ParticipantFlags - if(XMLP_ret::XML_OK != getXMLEnum(p_aux0, &settings.ignoreParticipantFlags, ident)) + if (XMLP_ret::XML_OK != getXMLEnum(p_aux0, &settings.ignoreParticipantFlags, ident)) + { return XMLP_ret::XML_ERROR; + } } else if (strcmp(name, _EDP) == 0) { @@ -3063,7 +3096,10 @@ XMLP_ret XMLParser::getXMLEnum( return XMLP_ret::XML_OK; } -XMLP_ret XMLParser::getXMLEnum(tinyxml2::XMLElement *elem, ParticipantFilteringFlags_t * e, uint8_t /*ident*/) +XMLP_ret XMLParser::getXMLEnum( + tinyxml2::XMLElement* elem, + ParticipantFilteringFlags_t* e, + uint8_t /*ident*/) { /* @@ -3071,16 +3107,16 @@ XMLP_ret XMLParser::getXMLEnum(tinyxml2::XMLElement *elem, ParticipantFilteringF - */ + */ const char* text = nullptr; - if(nullptr == elem || nullptr == e) + if (nullptr == elem || nullptr == e) { logError(XMLPARSER, "nullptr when getXMLEnum XML_ERROR!"); return XMLP_ret::XML_ERROR; } - else if(nullptr == (text = elem->GetText())) + else if (nullptr == (text = elem->GetText())) { logError(XMLPARSER, "<" << elem->Value() << "> getXMLEnum XML_ERROR!"); return XMLP_ret::XML_ERROR; @@ -3089,7 +3125,7 @@ XMLP_ret XMLParser::getXMLEnum(tinyxml2::XMLElement *elem, ParticipantFilteringF // First we check if it matches the schema pattern std::regex schema("((FILTER_DIFFERENT_HOST|FILTER_DIFFERENT_PROCESS|FILTER_SAME_PROCESS|NO_FILTER)*(\\||\\s)*)*"); - if(!std::regex_match(text, schema)) + if (!std::regex_match(text, schema)) { logError(XMLPARSER, "provided flags doesn't match expected ParticipantFilteringFlags!"); return XMLP_ret::XML_ERROR; @@ -3097,22 +3133,22 @@ XMLP_ret XMLParser::getXMLEnum(tinyxml2::XMLElement *elem, ParticipantFilteringF // Lets parse the flags, we assume the flags argument has been already flushed std::regex flags("FILTER_DIFFERENT_HOST|FILTER_DIFFERENT_PROCESS|FILTER_SAME_PROCESS"); - std::cregex_iterator it(text,text+strlen(text),flags); + std::cregex_iterator it(text, text + strlen(text), flags); uint32_t newflags = *e; - while(it != std::cregex_iterator()) + while (it != std::cregex_iterator()) { std::string flag(it++->str()); - if(flag == FILTER_DIFFERENT_HOST ) + if (flag == FILTER_DIFFERENT_HOST ) { newflags |= ParticipantFilteringFlags_t::FILTER_DIFFERENT_HOST; } - else if(flag == FILTER_DIFFERENT_PROCESS ) + else if (flag == FILTER_DIFFERENT_PROCESS ) { newflags |= ParticipantFilteringFlags_t::FILTER_DIFFERENT_PROCESS; } - else if(flag == FILTER_SAME_PROCESS ) + else if (flag == FILTER_SAME_PROCESS ) { newflags |= ParticipantFilteringFlags_t::FILTER_SAME_PROCESS; } diff --git a/src/cpp/rtps/xmlparser/XMLParserCommon.cpp b/src/cpp/rtps/xmlparser/XMLParserCommon.cpp index 365d336bb89..062c4fa4252 100644 --- a/src/cpp/rtps/xmlparser/XMLParserCommon.cpp +++ b/src/cpp/rtps/xmlparser/XMLParserCommon.cpp @@ -98,6 +98,9 @@ const char* TOTAL_WRITERS = "total_writers"; const char* SEND_BUFFERS = "send_buffers"; const char* PREALLOCATED_NUMBER = "preallocated_number"; const char* DYNAMIC_LC = "dynamic"; +const char* MAX_PROPERTIES = "max_properties"; +const char* MAX_USER_DATA = "max_user_data"; +const char* MAX_PARTITIONS = "max_partitions"; /// Publisher-subscriber attributes const char* TOPIC = "topic"; diff --git a/test/blackbox/BlackboxTestsPubSubBasic.cpp b/test/blackbox/BlackboxTestsPubSubBasic.cpp index 410527ff1b3..da08642f47f 100644 --- a/test/blackbox/BlackboxTestsPubSubBasic.cpp +++ b/test/blackbox/BlackboxTestsPubSubBasic.cpp @@ -288,6 +288,357 @@ TEST_P(PubSubBasic, PubSubAsReliableHelloworldMulticastDisabled) reader.block_for_all(); } +TEST_P(PubSubBasic, ReceivedDynamicDataWithNoSizeLimit) +{ + PubSubReader reader(TEST_TOPIC_NAME); + PubSubWriter writer(TEST_TOPIC_NAME); + + writer.history_depth(100) + .partition("A").partition("B").partition("C") + .userData({'a', 'b', 'c', 'd'}).init(); + + + ASSERT_TRUE(writer.isInitialized()); + + reader.history_depth(100) + .partition("A") + .reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS).init(); + + ASSERT_TRUE(reader.isInitialized()); + + reader.wait_discovery(std::chrono::seconds(3)); + writer.wait_discovery(std::chrono::seconds(3)); + + auto data = default_helloworld_data_generator(); + + reader.startReception(data); + + // Send data + writer.send(data); + // In this test all data should be sent. + ASSERT_TRUE(data.empty()); + // Block reader until reception finished or timeout. + reader.block_for_all(); +} + +TEST_P(PubSubBasic, ReceivedDynamicDataWithinSizeLimit) +{ + PubSubReader reader(TEST_TOPIC_NAME); + PubSubWriter writer(TEST_TOPIC_NAME); + + writer.history_depth(100) + .partition("A").partition("B").partition("C") + .userData({'a', 'b', 'c', 'd'}).init(); + + + ASSERT_TRUE(writer.isInitialized()); + + const std::string xml = + R"( + + + 8 + 28 + + + )"; + + reader.load_participant_attr(xml) + .history_depth(100) + .partition("A") + .reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS).init(); + + ASSERT_TRUE(reader.isInitialized()); + + reader.wait_discovery(std::chrono::seconds(3)); + writer.wait_discovery(std::chrono::seconds(3)); + + auto data = default_helloworld_data_generator(); + + reader.startReception(data); + + // Send data + writer.send(data); + // In this test all data should be sent. + ASSERT_TRUE(data.empty()); + // Block reader until reception finished or timeout. + reader.block_for_all(); +} + +TEST_P(PubSubBasic, ReceivedUserDataExceedsSizeLimit) +{ + PubSubReader reader(TEST_TOPIC_NAME); + PubSubWriter writer(TEST_TOPIC_NAME); + + writer.history_depth(100) + .userData({'a', 'b', 'c', 'd', 'e', 'f'}).init(); + + ASSERT_TRUE(writer.isInitialized()); + + const std::string xml = + R"( + + + 8 + + + )"; + + reader.load_participant_attr(xml) + .history_depth(100) + .reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS).init(); + + ASSERT_TRUE(reader.isInitialized()); + + reader.wait_discovery(std::chrono::seconds(3)); + writer.wait_discovery(std::chrono::seconds(3)); + + ASSERT_FALSE(writer.is_matched()); + ASSERT_FALSE(reader.is_matched()); +} + +TEST_P(PubSubBasic, ReceivedPartitionDataExceedsSizeLimit) +{ + PubSubReader reader(TEST_TOPIC_NAME); + PubSubWriter writer(TEST_TOPIC_NAME); + + writer.history_depth(100) + .partition("A").partition("B").partition("C") + .init(); + + ASSERT_TRUE(writer.isInitialized()); + + const std::string xml = + R"( + + + 20 + + + )"; + + reader.load_participant_attr(xml) + .history_depth(100) + .partition("A") + .reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS).init(); + + ASSERT_TRUE(reader.isInitialized()); + + reader.wait_discovery(std::chrono::seconds(3)); + writer.wait_discovery(std::chrono::seconds(3)); + + ASSERT_TRUE(writer.is_matched()); + ASSERT_FALSE(reader.is_matched()); +} + +TEST_P(PubSubBasic, ReceivedPropertiesDataWithinSizeLimit) +{ + char* value = nullptr; + std::string TOPIC_RANDOM_NUMBER; + std::string W_UNICAST_PORT_RANDOM_NUMBER_STR; + std::string R_UNICAST_PORT_RANDOM_NUMBER_STR; + std::string MULTICAST_PORT_RANDOM_NUMBER_STR; + + // Get environment variables. + value = std::getenv("TOPIC_RANDOM_NUMBER"); + if (value != nullptr) + { + TOPIC_RANDOM_NUMBER = value; + } + else + { + TOPIC_RANDOM_NUMBER = "1"; + } + value = std::getenv("W_UNICAST_PORT_RANDOM_NUMBER"); + if (value != nullptr) + { + W_UNICAST_PORT_RANDOM_NUMBER_STR = value; + } + else + { + W_UNICAST_PORT_RANDOM_NUMBER_STR = "7411"; + } + int32_t W_UNICAST_PORT_RANDOM_NUMBER = stoi(W_UNICAST_PORT_RANDOM_NUMBER_STR); + value = std::getenv("R_UNICAST_PORT_RANDOM_NUMBER"); + if (value != nullptr) + { + R_UNICAST_PORT_RANDOM_NUMBER_STR = value; + } + else + { + R_UNICAST_PORT_RANDOM_NUMBER_STR = "7421"; + } + int32_t R_UNICAST_PORT_RANDOM_NUMBER = stoi(R_UNICAST_PORT_RANDOM_NUMBER_STR); + value = std::getenv("MULTICAST_PORT_RANDOM_NUMBER"); + if (value != nullptr) + { + MULTICAST_PORT_RANDOM_NUMBER_STR = value; + } + else + { + MULTICAST_PORT_RANDOM_NUMBER_STR = "7400"; + } + int32_t MULTICAST_PORT_RANDOM_NUMBER = stoi(MULTICAST_PORT_RANDOM_NUMBER_STR); + + Locator_t LocatorBuffer; + + PubSubWriter writer(TEST_TOPIC_NAME); + + LocatorList_t WriterUnicastLocators; + LocatorBuffer.kind = LOCATOR_KIND_UDPv4; + LocatorBuffer.port = static_cast(W_UNICAST_PORT_RANDOM_NUMBER); + IPLocator::setIPv4(LocatorBuffer, 127, 0, 0, 1); + WriterUnicastLocators.push_back(LocatorBuffer); + + LocatorList_t WriterMulticastLocators; + LocatorBuffer.port = static_cast(MULTICAST_PORT_RANDOM_NUMBER); + WriterMulticastLocators.push_back(LocatorBuffer); + + writer.static_discovery("PubSubWriter.xml"). + unicastLocatorList(WriterUnicastLocators).multicastLocatorList(WriterMulticastLocators). + setPublisherIDs(1, 2).setManualTopicName(std::string("BlackBox_StaticDiscovery_") + TOPIC_RANDOM_NUMBER).init(); + + ASSERT_TRUE(writer.isInitialized()); + + PubSubReader reader(TEST_TOPIC_NAME); + + LocatorList_t ReaderUnicastLocators; + LocatorBuffer.port = static_cast(R_UNICAST_PORT_RANDOM_NUMBER); + ReaderUnicastLocators.push_back(LocatorBuffer); + + LocatorList_t ReaderMulticastLocators; + LocatorBuffer.port = static_cast(MULTICAST_PORT_RANDOM_NUMBER); + ReaderMulticastLocators.push_back(LocatorBuffer); + + //Expected properties have exactly size 52 + const std::string xml = + R"( + + + 52 + + + )"; + + reader.load_participant_attr(xml). + static_discovery("PubSubReader.xml"). + unicastLocatorList(ReaderUnicastLocators).multicastLocatorList(ReaderMulticastLocators). + setSubscriberIDs(3, 4).setManualTopicName(std::string("BlackBox_StaticDiscovery_") + TOPIC_RANDOM_NUMBER).init(); + + ASSERT_TRUE(reader.isInitialized()); + + // Wait for discovery. + writer.wait_discovery(std::chrono::seconds(3)); + reader.wait_discovery(std::chrono::seconds(3)); + + ASSERT_TRUE(writer.is_matched()); + ASSERT_TRUE(reader.is_matched()); +} + +TEST_P(PubSubBasic, ReceivedPropertiesDataExceedsSizeLimit) +{ + char* value = nullptr; + std::string TOPIC_RANDOM_NUMBER; + std::string W_UNICAST_PORT_RANDOM_NUMBER_STR; + std::string R_UNICAST_PORT_RANDOM_NUMBER_STR; + std::string MULTICAST_PORT_RANDOM_NUMBER_STR; + + // Get environment variables. + value = std::getenv("TOPIC_RANDOM_NUMBER"); + if (value != nullptr) + { + TOPIC_RANDOM_NUMBER = value; + } + else + { + TOPIC_RANDOM_NUMBER = "1"; + } + value = std::getenv("W_UNICAST_PORT_RANDOM_NUMBER"); + if (value != nullptr) + { + W_UNICAST_PORT_RANDOM_NUMBER_STR = value; + } + else + { + W_UNICAST_PORT_RANDOM_NUMBER_STR = "7411"; + } + int32_t W_UNICAST_PORT_RANDOM_NUMBER = stoi(W_UNICAST_PORT_RANDOM_NUMBER_STR); + value = std::getenv("R_UNICAST_PORT_RANDOM_NUMBER"); + if (value != nullptr) + { + R_UNICAST_PORT_RANDOM_NUMBER_STR = value; + } + else + { + R_UNICAST_PORT_RANDOM_NUMBER_STR = "7421"; + } + int32_t R_UNICAST_PORT_RANDOM_NUMBER = stoi(R_UNICAST_PORT_RANDOM_NUMBER_STR); + value = std::getenv("MULTICAST_PORT_RANDOM_NUMBER"); + if (value != nullptr) + { + MULTICAST_PORT_RANDOM_NUMBER_STR = value; + } + else + { + MULTICAST_PORT_RANDOM_NUMBER_STR = "7400"; + } + int32_t MULTICAST_PORT_RANDOM_NUMBER = stoi(MULTICAST_PORT_RANDOM_NUMBER_STR); + + Locator_t LocatorBuffer; + + PubSubWriter writer(TEST_TOPIC_NAME); + + LocatorList_t WriterUnicastLocators; + LocatorBuffer.kind = LOCATOR_KIND_UDPv4; + LocatorBuffer.port = static_cast(W_UNICAST_PORT_RANDOM_NUMBER); + IPLocator::setIPv4(LocatorBuffer, 127, 0, 0, 1); + WriterUnicastLocators.push_back(LocatorBuffer); + + LocatorList_t WriterMulticastLocators; + LocatorBuffer.port = static_cast(MULTICAST_PORT_RANDOM_NUMBER); + WriterMulticastLocators.push_back(LocatorBuffer); + + writer.static_discovery("PubSubWriter.xml"). + unicastLocatorList(WriterUnicastLocators).multicastLocatorList(WriterMulticastLocators). + setPublisherIDs(1, 2).setManualTopicName(std::string("BlackBox_StaticDiscovery_") + TOPIC_RANDOM_NUMBER).init(); + + ASSERT_TRUE(writer.isInitialized()); + + PubSubReader reader(TEST_TOPIC_NAME); + + LocatorList_t ReaderUnicastLocators; + LocatorBuffer.port = static_cast(R_UNICAST_PORT_RANDOM_NUMBER); + ReaderUnicastLocators.push_back(LocatorBuffer); + + LocatorList_t ReaderMulticastLocators; + LocatorBuffer.port = static_cast(MULTICAST_PORT_RANDOM_NUMBER); + ReaderMulticastLocators.push_back(LocatorBuffer); + + //Expected properties have size 52 + const std::string xml = + R"( + + + 50 + + + )"; + + reader.load_participant_attr(xml). + static_discovery("PubSubReader.xml"). + unicastLocatorList(ReaderUnicastLocators).multicastLocatorList(ReaderMulticastLocators). + setSubscriberIDs(3, 4).setManualTopicName(std::string("BlackBox_StaticDiscovery_") + TOPIC_RANDOM_NUMBER).init(); + + ASSERT_TRUE(reader.isInitialized()); + + // Wait for discovery. + writer.wait_discovery(std::chrono::seconds(3)); + reader.wait_discovery(std::chrono::seconds(3)); + + ASSERT_FALSE(writer.is_matched()); + ASSERT_FALSE(reader.is_matched()); +} + INSTANTIATE_TEST_CASE_P(PubSubBasic, PubSubBasic, testing::Values(false, true), diff --git a/test/mock/dds/QosPolicies/fastdds/dds/core/policy/QosPolicies.hpp b/test/mock/dds/QosPolicies/fastdds/dds/core/policy/QosPolicies.hpp index 71c587af417..103ef926762 100644 --- a/test/mock/dds/QosPolicies/fastdds/dds/core/policy/QosPolicies.hpp +++ b/test/mock/dds/QosPolicies/fastdds/dds/core/policy/QosPolicies.hpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace eprosima { @@ -70,6 +71,8 @@ class QosPolicy return m_sendAlways; } + virtual inline void clear() = 0; + protected: bool m_sendAlways; @@ -143,6 +146,12 @@ class DurabilityQosPolicy : public Parameter_t, public QosPolicy } + inline void clear() override + { + DurabilityQosPolicy reset = DurabilityQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -154,6 +163,18 @@ class DurabilityQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** @@ -178,6 +199,12 @@ class DeadlineQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + DeadlineQosPolicy reset = DeadlineQosPolicy(); + std::swap(*this, reset); + } + fastrtps::Duration_t period; /** * Appends QoS to the specified CDR message. @@ -190,6 +217,18 @@ class DeadlineQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** @@ -214,6 +253,12 @@ class LatencyBudgetQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + LatencyBudgetQosPolicy reset = LatencyBudgetQosPolicy(); + std::swap(*this, reset); + } + fastrtps::Duration_t duration; /** * Appends QoS to the specified CDR message. @@ -226,6 +271,18 @@ class LatencyBudgetQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** @@ -267,6 +324,12 @@ class LivelinessQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + LivelinessQosPolicy reset = LivelinessQosPolicy(); + std::swap(*this, reset); + } + LivelinessQosPolicyKind kind; fastrtps::Duration_t lease_duration; fastrtps::Duration_t announcement_period; @@ -281,6 +344,18 @@ class LivelinessQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** @@ -317,6 +392,12 @@ class ReliabilityQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + ReliabilityQosPolicy reset = ReliabilityQosPolicy(); + std::swap(*this, reset); + } + ReliabilityQosPolicyKind kind; fastrtps::Duration_t max_blocking_time; /** @@ -330,6 +411,18 @@ class ReliabilityQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; @@ -364,6 +457,12 @@ class OwnershipQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + OwnershipQosPolicy reset = OwnershipQosPolicy(); + std::swap(*this, reset); + } + OwnershipQosPolicyKind kind; /** * Appends QoS to the specified CDR message. @@ -376,6 +475,18 @@ class OwnershipQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** @@ -412,6 +523,12 @@ class DestinationOrderQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + DestinationOrderQosPolicy reset = DestinationOrderQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -423,28 +540,96 @@ class DestinationOrderQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** * Class UserDataQosPolicy, to transmit user data during the discovery phase. */ -class UserDataQosPolicy : public Parameter_t, public QosPolicy +class UserDataQosPolicy : public Parameter_t, public QosPolicy, public fastrtps::ResourceLimitedVector { friend class ParameterList; + using ResourceLimitedOctetVector = ResourceLimitedVector; + using collection_type = std::vector; public: RTPS_DllAPI UserDataQosPolicy() : Parameter_t(PID_USER_DATA, 0) , QosPolicy(false) + , ResourceLimitedOctetVector() + { + } + + RTPS_DllAPI UserDataQosPolicy(uint16_t in_length) + : Parameter_t(PID_USER_DATA, in_length) + , QosPolicy(false) + , ResourceLimitedOctetVector() + { + } + + RTPS_DllAPI UserDataQosPolicy(const UserDataQosPolicy& data) + : Parameter_t(PID_USER_DATA, data.length) + , QosPolicy(false) + , ResourceLimitedOctetVector(data) + { + } + + RTPS_DllAPI UserDataQosPolicy( + const collection_type& data) + : Parameter_t(PID_USER_DATA, 0) + , QosPolicy(false) + , ResourceLimitedOctetVector() { + assign(data.begin(), data.end()); } virtual RTPS_DllAPI ~UserDataQosPolicy() { } + UserDataQosPolicy& operator =( + const collection_type& b) + { + if (collection_ != b) + { + //If the object is size limited, already has max_size() allocated + //assign() will always stop copying when reaching max_size() + assign(b.begin(), b.end()); + hasChanged = true; + } + return *this; + } + + /** + * Const cast to underlying collection. + * + * Useful to easy integration on old APIs where a traditional container was used. + * + * @return const reference to the underlying collection. + */ + operator const collection_type& () const noexcept + { + return collection_; + } + + inline void clear() override + { + ResourceLimitedOctetVector::clear(); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -456,13 +641,25 @@ class UserDataQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + /** * Returns raw data vector. * @return raw data as vector of octets. * */ RTPS_DllAPI inline std::vector data_vec() const { - return data_vec_; + return collection_; } /** @@ -472,12 +669,26 @@ class UserDataQosPolicy : public Parameter_t, public QosPolicy RTPS_DllAPI inline void data_vec( const std::vector& vec) { - data_vec_ = vec; + collection_ = vec; } -private: + /** + * Set the maximum size of the user data and reserves memory for that much. + * @param size new maximum size of the user data + */ + void set_max_size (size_t size) + { + configuration_.maximum = size; + } + + /** + * @return const reference to the internal raw data. + * */ + inline const std::vector& dataVec() const + { + return collection_; + } - std::vector data_vec_; }; /** @@ -502,6 +713,12 @@ class TimeBasedFilterQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + TimeBasedFilterQosPolicy reset = TimeBasedFilterQosPolicy(); + std::swap(*this, reset); + } + fastrtps::Duration_t minimum_separation; /** * Appends QoS to the specified CDR message. @@ -514,6 +731,18 @@ class TimeBasedFilterQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** @@ -557,6 +786,12 @@ class PresentationQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + PresentationQosPolicy reset = PresentationQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -568,6 +803,18 @@ class PresentationQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; @@ -587,10 +834,27 @@ class PartitionQosPolicy : public Parameter_t, public QosPolicy { } + RTPS_DllAPI PartitionQosPolicy(uint16_t in_length) + : Parameter_t(PID_PARTITION, in_length) + , QosPolicy(false) + , names_{} + { + } + virtual RTPS_DllAPI ~PartitionQosPolicy() { } + void set_max_size (uint32_t size) + { + max_size_ = size; + } + + uint32_t max_size () const + { + return max_size_; + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -602,6 +866,18 @@ class PartitionQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + /** * Appends a name to the list of partition names. * @param name Name to append. @@ -615,7 +891,7 @@ class PartitionQosPolicy : public Parameter_t, public QosPolicy /** * Clears list of partition names */ - RTPS_DllAPI inline void clear() + RTPS_DllAPI inline void clear() override { names_.clear(); } @@ -642,6 +918,7 @@ class PartitionQosPolicy : public Parameter_t, public QosPolicy private: std::vector names_; + uint32_t max_size_ = 0; }; @@ -675,6 +952,18 @@ class TopicDataQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + /** * Appends topic data. * @param oc Data octet. @@ -688,7 +977,7 @@ class TopicDataQosPolicy : public Parameter_t, public QosPolicy /** * Clears all topic data. */ - RTPS_DllAPI inline void clear() + RTPS_DllAPI inline void clear() override { value.clear(); } @@ -732,6 +1021,13 @@ class GroupDataQosPolicy : public Parameter_t, public QosPolicy { } + RTPS_DllAPI GroupDataQosPolicy(uint16_t in_length) + : Parameter_t(PID_GROUP_DATA, in_length) + , QosPolicy(false) + , value{} + { + } + virtual RTPS_DllAPI ~GroupDataQosPolicy() { } @@ -747,6 +1043,18 @@ class GroupDataQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + /** * Appends group data. * @param oc Data octet. @@ -760,7 +1068,7 @@ class GroupDataQosPolicy : public Parameter_t, public QosPolicy /** * Clears all group data. */ - RTPS_DllAPI inline void clear() + RTPS_DllAPI inline void clear() override { value.clear(); } @@ -823,6 +1131,12 @@ class HistoryQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + HistoryQosPolicy reset = HistoryQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -834,6 +1148,18 @@ class HistoryQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** @@ -867,6 +1193,12 @@ class ResourceLimitsQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + ResourceLimitsQosPolicy reset = ResourceLimitsQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -878,6 +1210,18 @@ class ResourceLimitsQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; @@ -919,6 +1263,12 @@ class DurabilityServiceQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + DurabilityServiceQosPolicy reset = DurabilityServiceQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -930,6 +1280,18 @@ class DurabilityServiceQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** @@ -954,6 +1316,12 @@ class LifespanQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + LifespanQosPolicy reset = LifespanQosPolicy(); + std::swap(*this, reset); + } + fastrtps::Duration_t duration; /** * Appends QoS to the specified CDR message. @@ -966,6 +1334,18 @@ class LifespanQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** @@ -990,6 +1370,12 @@ class OwnershipStrengthQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + OwnershipStrengthQosPolicy reset = OwnershipStrengthQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1001,6 +1387,18 @@ class OwnershipStrengthQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; @@ -1028,6 +1426,12 @@ class TransportPriorityQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + TransportPriorityQosPolicy reset = TransportPriorityQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1039,6 +1443,18 @@ class TransportPriorityQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** @@ -1074,6 +1490,11 @@ class PublishModeQosPolicy : public QosPolicy return other.kind == kind; } + inline void clear() override + { + PublishModeQosPolicy reset = PublishModeQosPolicy(); + std::swap(*this, reset); + } }; /** @@ -1104,6 +1525,12 @@ class DataRepresentationQosPolicy : public Parameter_t, public QosPolicy { } + inline void clear() override + { + DataRepresentationQosPolicy reset = DataRepresentationQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1115,6 +1542,18 @@ class DataRepresentationQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; enum TypeConsistencyKind : uint32_t @@ -1141,12 +1580,24 @@ class TypeConsistencyEnforcementQosPolicy : public Parameter_t, public QosPolicy RTPS_DllAPI TypeConsistencyEnforcementQosPolicy() { + m_kind = ALLOW_TYPE_COERCION; + m_ignore_sequence_bounds = true; + m_ignore_string_bounds = true; + m_ignore_member_names = false; + m_prevent_type_widening = false; + m_force_type_validation = false; } virtual RTPS_DllAPI ~TypeConsistencyEnforcementQosPolicy() { } + inline void clear() override + { + TypeConsistencyEnforcementQosPolicy reset = TypeConsistencyEnforcementQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1158,6 +1609,18 @@ class TypeConsistencyEnforcementQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + }; /** @@ -1184,6 +1647,12 @@ class DisablePositiveACKsQosPolicy : public Parameter_t, public QosPolicy return enabled == b.enabled; } + inline void clear() override + { + DisablePositiveACKsQosPolicy reset = DisablePositiveACKsQosPolicy(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1196,6 +1665,18 @@ class DisablePositiveACKsQosPolicy : public Parameter_t, public QosPolicy return true; } + /** + * Reads QoS from the specified CDR message + * @param msg Message from where the QoS Policy has to be taken. + * @param size Size of the QoS Policy field to read + * @return True if the parameter was correctly taken. + */ + bool readFromCDRMessage( + fastrtps::rtps::CDRMessage_t* /*msg*/, uint16_t /*size*/) override + { + return true; + } + public: //! True if this QoS is enabled @@ -1256,6 +1737,12 @@ class TypeIdV1 : public Parameter_t, public QosPolicy { } + inline void clear() override + { + TypeIdV1 reset = TypeIdV1(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1269,7 +1756,7 @@ class TypeIdV1 : public Parameter_t, public QosPolicy bool readFromCDRMessage( fastrtps::rtps::CDRMessage_t* /*msg*/, - uint32_t /*size*/) + uint16_t /*size*/) override { return true; } @@ -1329,6 +1816,12 @@ class TypeObjectV1 : public Parameter_t, public QosPolicy { } + inline void clear() override + { + TypeObjectV1 reset = TypeObjectV1(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1342,7 +1835,7 @@ class TypeObjectV1 : public Parameter_t, public QosPolicy bool readFromCDRMessage( fastrtps::rtps::CDRMessage_t* /*msg*/, - uint32_t /*size*/) + uint16_t /*size*/) override { return true; } @@ -1395,6 +1888,12 @@ class TypeInformation : public Parameter_t, public QosPolicy { } + inline void clear() override + { + TypeInformation reset = TypeInformation(); + std::swap(*this, reset); + } + /** * Appends QoS to the specified CDR message. * @param msg Message to append the QoS Policy to. @@ -1408,7 +1907,7 @@ class TypeInformation : public Parameter_t, public QosPolicy bool readFromCDRMessage( fastrtps::rtps::CDRMessage_t*, - uint32_t) + uint16_t /*size*/) override { return true; } diff --git a/test/mock/rtps/ReaderProxyData/fastdds/rtps/builtin/data/ReaderProxyData.h b/test/mock/rtps/ReaderProxyData/fastdds/rtps/builtin/data/ReaderProxyData.h index 2bbf62e591a..eeab8c9962e 100644 --- a/test/mock/rtps/ReaderProxyData/fastdds/rtps/builtin/data/ReaderProxyData.h +++ b/test/mock/rtps/ReaderProxyData/fastdds/rtps/builtin/data/ReaderProxyData.h @@ -22,6 +22,7 @@ #include #include #include +#include #if HAVE_SECURITY #include @@ -43,6 +44,13 @@ class ReaderProxyData : remote_locators_(max_unicast_locators, max_multicast_locators) { } + ReaderProxyData( + size_t max_unicast_locators, + size_t max_multicast_locators, + const VariableLengthDataLimits& data_limits) + : remote_locators_(max_unicast_locators, max_multicast_locators) + { m_qos.m_userData.set_max_size(data_limits.max_user_data); } + const GUID_t& guid() const { return m_guid; } GUID_t& guid() { return m_guid; } diff --git a/test/mock/rtps/WriterProxyData/fastdds/rtps/builtin/data/WriterProxyData.h b/test/mock/rtps/WriterProxyData/fastdds/rtps/builtin/data/WriterProxyData.h index f7b0c91265e..94d04e04c53 100644 --- a/test/mock/rtps/WriterProxyData/fastdds/rtps/builtin/data/WriterProxyData.h +++ b/test/mock/rtps/WriterProxyData/fastdds/rtps/builtin/data/WriterProxyData.h @@ -22,6 +22,7 @@ #include #include #include +#include #if HAVE_SECURITY #include @@ -41,7 +42,20 @@ class WriterProxyData size_t max_unicast_locators, size_t max_multicast_locators) : remote_locators_(max_unicast_locators, max_multicast_locators) - { } + { + m_qos.m_userData.set_max_size(0); + m_qos.m_partition.set_max_size(0); + } + + WriterProxyData( + size_t max_unicast_locators, + size_t max_multicast_locators, + const VariableLengthDataLimits& data_limits) + : remote_locators_(max_unicast_locators, max_multicast_locators) + { + m_qos.m_userData.set_max_size((uint32_t)data_limits.max_user_data); + m_qos.m_partition.set_max_size((uint32_t)data_limits.max_partitions); + } const GUID_t& guid() const { return m_guid; }