From bc5c9063e2ba86c6bbb761b031aa5822242714a7 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Mon, 3 Jun 2024 11:12:24 +0200 Subject: [PATCH] Refs #21096: Implementation Signed-off-by: Mario Dominguez --- include/fastdds/dds/core/Types.hpp | 2 + .../dds/core/policy/ParameterTypes.hpp | 37 ++++ .../builtin/data/ParticipantProxyData.hpp | 3 + include/fastrtps/qos/ParameterTypes.h | 1 + src/cpp/CMakeLists.txt | 1 + .../core/policy/ParameterSerializer.hpp | 25 +++ .../builtin/data/ParticipantProxyData.cpp | 27 +++ .../builtin/discovery/participant/PDP.cpp | 1 + .../discovery/participant/PDPClient.cpp | 3 +- .../participant/PDPClientListener.cpp | 64 ++++++ .../participant/PDPClientListener.hpp | 62 ++++++ .../discovery/participant/PDPListener.cpp | 31 +++ .../discovery/participant/PDPListener.h | 13 ++ .../participant/PDPServerListener.cpp | 202 ++++++++++-------- .../participant/PDPServerListener.hpp | 6 + 15 files changed, 389 insertions(+), 89 deletions(-) create mode 100644 src/cpp/rtps/builtin/discovery/participant/PDPClientListener.cpp create mode 100644 src/cpp/rtps/builtin/discovery/participant/PDPClientListener.hpp diff --git a/include/fastdds/dds/core/Types.hpp b/include/fastdds/dds/core/Types.hpp index 8f24af6545b..2142681298e 100644 --- a/include/fastdds/dds/core/Types.hpp +++ b/include/fastdds/dds/core/Types.hpp @@ -23,6 +23,8 @@ namespace dds { typedef uint32_t DomainId_t; +const DomainId_t c_DomainId_t_Unknown = 0xFFFFFFFF; + const int32_t LENGTH_UNLIMITED = -1; } // namespace dds diff --git a/include/fastdds/dds/core/policy/ParameterTypes.hpp b/include/fastdds/dds/core/policy/ParameterTypes.hpp index 0d8d273361d..f79ba81a923 100644 --- a/include/fastdds/dds/core/policy/ParameterTypes.hpp +++ b/include/fastdds/dds/core/policy/ParameterTypes.hpp @@ -525,6 +525,43 @@ class ParameterGuid_t : public Parameter_t #define PARAMETER_GUID_LENGTH 16 +/** + * @ingroup PARAMETER_MODULE + */ +class ParameterDomainId_t : public Parameter_t +{ +public: + + //!Domain ID.
By default, 0. + uint32_t domain_id; + + /** + * @brief Constructor without parameters + */ + ParameterDomainId_t() + : domain_id(0) + { + } + + /** + * Constructor using a parameter PID and the parameter length + * + * @param pid Pid of the parameter + * @param in_length Its associated length + */ + ParameterDomainId_t( + ParameterId_t pid, + uint16_t in_length) + : Parameter_t(pid, in_length) + , domain_id(0) + { + domain_id = 0; + } + +}; + +#define PARAMETER_DOMAINID_LENGTH 4 + /** * @ingroup PARAMETER_MODULE */ diff --git a/include/fastdds/rtps/builtin/data/ParticipantProxyData.hpp b/include/fastdds/rtps/builtin/data/ParticipantProxyData.hpp index e2b1987d732..88a18655bee 100644 --- a/include/fastdds/rtps/builtin/data/ParticipantProxyData.hpp +++ b/include/fastdds/rtps/builtin/data/ParticipantProxyData.hpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -77,6 +78,8 @@ class ParticipantProxyData GUID_t m_guid; //!Vendor ID fastdds::rtps::VendorId_t m_VendorId; + //!Domain ID + fastdds::dds::DomainId_t m_domain_id; //!Expects Inline QOS. bool m_expectsInlineQos; //!Available builtin endpoints diff --git a/include/fastrtps/qos/ParameterTypes.h b/include/fastrtps/qos/ParameterTypes.h index 7c712d8a735..6ba7757d3bf 100644 --- a/include/fastrtps/qos/ParameterTypes.h +++ b/include/fastrtps/qos/ParameterTypes.h @@ -53,6 +53,7 @@ using ParameterPort_t = fastdds::dds::ParameterPort_t; using ParameterGuid_t = fastdds::dds::ParameterGuid_t; using ParameterProtocolVersion_t = fastdds::dds::ParameterProtocolVersion_t; using ParameterVendorId_t = fastdds::dds::ParameterVendorId_t; +using ParameterDomainId_t = fastdds::dds::ParameterDomainId_t; using ParameterIP4Address_t = fastdds::dds::ParameterIP4Address_t; using ParameterBool_t = fastdds::dds::ParameterBool_t; using ParameterStatusInfo_t = fastdds::dds::ParameterStatusInfo_t; diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 961379fd038..256e6452e28 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -114,6 +114,7 @@ set(${PROJECT_NAME}_source_files rtps/builtin/discovery/participant/DirectMessageSender.cpp rtps/builtin/discovery/participant/PDP.cpp rtps/builtin/discovery/participant/PDPClient.cpp + rtps/builtin/discovery/participant/PDPClientListener.cpp rtps/builtin/discovery/participant/PDPListener.cpp rtps/builtin/discovery/participant/PDPServer.cpp rtps/builtin/discovery/participant/PDPServerListener.cpp diff --git a/src/cpp/fastdds/core/policy/ParameterSerializer.hpp b/src/cpp/fastdds/core/policy/ParameterSerializer.hpp index eb3664479ba..a7dca57e105 100644 --- a/src/cpp/fastdds/core/policy/ParameterSerializer.hpp +++ b/src/cpp/fastdds/core/policy/ParameterSerializer.hpp @@ -433,6 +433,31 @@ inline bool ParameterSerializer::read_content_from_cdr_mess return valid; } +template<> +inline bool ParameterSerializer::add_content_to_cdr_message( + const ParameterDomainId_t& parameter, + fastrtps::rtps::CDRMessage_t* cdr_message) +{ + bool valid = fastrtps::rtps::CDRMessage::addUInt32(cdr_message, parameter.domain_id); + return valid; +} + +template<> +inline bool ParameterSerializer::read_content_from_cdr_message( + ParameterDomainId_t& parameter, + fastrtps::rtps::CDRMessage_t* cdr_message, + const uint16_t parameter_length) +{ + if (parameter_length != PARAMETER_VENDOR_LENGTH) + { + return false; + } + parameter.length = parameter_length; + bool valid = fastrtps::rtps::CDRMessage::readUInt32(cdr_message, ¶meter.domain_id); + cdr_message->pos += 2; //padding + return valid; +} + template<> inline bool ParameterSerializer::add_content_to_cdr_message( const ParameterIP4Address_t& parameter, diff --git a/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp b/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp index d5cab4a3a13..f135c4e3847 100644 --- a/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp +++ b/src/cpp/rtps/builtin/data/ParticipantProxyData.cpp @@ -52,6 +52,7 @@ ParticipantProxyData::ParticipantProxyData( const RTPSParticipantAllocationAttributes& allocation) : m_protocolVersion(c_ProtocolVersion) , m_VendorId(c_VendorId_Unknown) + , m_domain_id(fastdds::dds::c_DomainId_t_Unknown) , m_expectsInlineQos(false) , m_availableBuiltinEndpoints(0) , m_networkConfiguration(0) @@ -78,6 +79,7 @@ ParticipantProxyData::ParticipantProxyData( : m_protocolVersion(pdata.m_protocolVersion) , m_guid(pdata.m_guid) , m_VendorId(pdata.m_VendorId) + , m_domain_id(pdata.m_domain_id) , m_expectsInlineQos(pdata.m_expectsInlineQos) , m_availableBuiltinEndpoints(pdata.m_availableBuiltinEndpoints) , m_networkConfiguration(pdata.m_networkConfiguration) @@ -151,6 +153,9 @@ uint32_t ParticipantProxyData::get_serialized_size( // PID_VENDORID ret_val += 4 + 4; + // PID_DOMAIN_ID + ret_val += 4 + 4; + if (m_expectsInlineQos) { // PID_EXPECTS_INLINE_QOS @@ -252,6 +257,14 @@ bool ParticipantProxyData::writeToCDRMessage( return false; } } + { + ParameterDomainId_t p(fastdds::dds::PID_DOMAIN_ID, 4); + p.domain_id = this->m_domain_id; + if (!fastdds::dds::ParameterSerializer::add_to_cdr_message(p, msg)) + { + return false; + } + } if (this->m_expectsInlineQos) { ParameterBool_t p(fastdds::dds::PID_EXPECTS_INLINE_QOS, PARAMETER_BOOL_LENGTH, m_expectsInlineQos); @@ -443,6 +456,18 @@ bool ParticipantProxyData::readFromCDRMessage( is_shm_transport_available &= (m_VendorId == c_VendorId_eProsima); break; } + case fastdds::dds::PID_DOMAIN_ID: + { + ParameterDomainId_t p(pid, plength); + if (!fastdds::dds::ParameterSerializer::read_from_cdr_message(p, msg, + plength)) + { + return false; + } + + m_domain_id = p.domain_id; + break; + } case fastdds::dds::PID_EXPECTS_INLINE_QOS: { ParameterBool_t p(pid, plength); @@ -740,6 +765,7 @@ void ParticipantProxyData::clear() m_guid = GUID_t(); //set_VendorId_Unknown(m_VendorId); m_VendorId = c_VendorId_Unknown; + m_domain_id = fastdds::dds::c_DomainId_t_Unknown; m_expectsInlineQos = false; m_availableBuiltinEndpoints = 0; m_networkConfiguration = 0; @@ -771,6 +797,7 @@ void ParticipantProxyData::copy( m_guid = pdata.m_guid; m_VendorId[0] = pdata.m_VendorId[0]; m_VendorId[1] = pdata.m_VendorId[1]; + m_domain_id = pdata.m_domain_id; m_availableBuiltinEndpoints = pdata.m_availableBuiltinEndpoints; m_networkConfiguration = pdata.m_networkConfiguration; metatraffic_locators = pdata.metatraffic_locators; diff --git a/src/cpp/rtps/builtin/discovery/participant/PDP.cpp b/src/cpp/rtps/builtin/discovery/participant/PDP.cpp index 5e8bd017811..2ac57c5286d 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDP.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDP.cpp @@ -232,6 +232,7 @@ void PDP::initializeParticipantProxyData( RTPSParticipantAttributes& attributes = mp_RTPSParticipant->getAttributes(); bool announce_locators = !mp_RTPSParticipant->is_intraprocess_only(); + participant_data->m_domain_id = mp_RTPSParticipant->get_domain_id(); participant_data->m_leaseDuration = attributes.builtin.discovery_config.leaseDuration; //set_VendorId_eProsima(participant_data->m_VendorId); participant_data->m_VendorId = c_VendorId_eProsima; diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp index 87eb052ac72..9ace10ad9ba 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -356,7 +357,7 @@ bool PDPClient::create_ds_pdp_reliable_endpoints( } #endif // HAVE_SECURITY - endpoints.reader.listener_.reset(new PDPListener(this)); + endpoints.reader.listener_.reset(new PDPClientListener(this)); RTPSReader* reader = nullptr; #if HAVE_SECURITY diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClientListener.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPClientListener.cpp new file mode 100644 index 00000000000..a4879dc1d0c --- /dev/null +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClientListener.cpp @@ -0,0 +1,64 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file PDPClientListener.cpp + * + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using ParameterList = eprosima::fastdds::dds::ParameterList; + +namespace eprosima { +namespace fastrtps { +namespace rtps { + +PDPClientListener::PDPClientListener( + PDP* parent_pdp) + : PDPListener(parent_pdp) +{ +} + +bool PDPClientListener::check_discovery_conditions( + ParticipantProxyData& /* participant_data */, + void* /* extra data*/) +{ + /* Do not check PID_VENDOR_ID */ + // In Discovery Server we don't impose + // domain ids to be the same + /* Do not check PID_DOMAIN_ID */ + /* Do not check PARTICIPANT_TYPE */ + return true; +} + +} /* namespace rtps */ +} /* namespace fastrtps */ +} /* namespace eprosima */ diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClientListener.hpp b/src/cpp/rtps/builtin/discovery/participant/PDPClientListener.hpp new file mode 100644 index 00000000000..3e645d9e9f7 --- /dev/null +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClientListener.hpp @@ -0,0 +1,62 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file PDPClientListener.h + * + */ + +#ifndef _FASTDDS_RTPS_PDPCLIENTLISTENER_H_ +#define _FASTDDS_RTPS_PDPCLIENTLISTENER_H_ +#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC + +#include + +namespace eprosima { +namespace fastrtps { +namespace rtps { + +/** + * Class PDPClientListener used by a PDP discovery client. + * This class is implemented in order to use the same structure than with any other RTPSReader. + * @ingroup DISCOVERY_MODULE + */ +class PDPClientListener : public PDPListener +{ + +public: + + /** + * @param parent Pointer to object creating this object + */ + PDPClientListener( + PDP* parent); + + virtual ~PDPClientListener() override = default; + +protected: + + bool check_discovery_conditions( + ParticipantProxyData& pdata, + void* extra_data) override; + +}; + + +} /* namespace rtps */ +} /* namespace fastrtps */ +} /* namespace eprosima */ + +#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC +#endif /* _FASTDDS_RTPS_PDPCLIENTLISTENER_H_ */ diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPListener.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPListener.cpp index 7cb29a8f696..09c87748044 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPListener.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPListener.cpp @@ -114,6 +114,13 @@ void PDPListener::onNewCacheChangeAdded( return; } + void* empty_extra_data = nullptr; + static_cast(empty_extra_data); + if (!check_discovery_conditions(temp_participant_data_, empty_extra_data)) + { + return; + } + // Filter locators const auto& pattr = parent_pdp_->getRTPSParticipant()->getAttributes(); fastdds::rtps::network::external_locators::filter_remote_locators(temp_participant_data_, @@ -274,6 +281,30 @@ void PDPListener::process_alive_data( reader->getMutex().lock(); } +bool PDPListener::check_discovery_conditions( + ParticipantProxyData& participant_data, + void* /*extra_data*/) +{ + bool ret = true; + uint32_t remote_participant_domain_id = participant_data.m_domain_id; + + // In PDPSimple, do not match if the participant is from a different domain. + // If the domain id is unknown, it is assumed to be the same domain + if (remote_participant_domain_id != parent_pdp_->getRTPSParticipant()->get_domain_id() && + remote_participant_domain_id != fastdds::dds::c_DomainId_t_Unknown) + { + EPROSIMA_LOG_INFO(RTPS_PDP_DISCOVERY, "Received participant with different domain id (" + << remote_participant_domain_id << ") than ours (" + << parent_pdp_->getRTPSParticipant()->get_domain_id() << ")"); + std::cout << "Received participant with different domain id (" + << remote_participant_domain_id << ") than ours (" + << parent_pdp_->getRTPSParticipant()->get_domain_id() << ")" << std::endl; + ret = false; + } + + return ret; +} + bool PDPListener::get_key( CacheChange_t* change) { diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPListener.h b/src/cpp/rtps/builtin/discovery/participant/PDPListener.h index ae103f56fc2..cd637070e5a 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPListener.h +++ b/src/cpp/rtps/builtin/discovery/participant/PDPListener.h @@ -80,6 +80,19 @@ class PDPListener : public ReaderListener RTPSReader* reader, std::unique_lock& lock); + /** + * Checks discovery conditions of an incoming DATA(p). + * This method is called from PDPListener::onNewCacheChangeAdded() just right after + * having deserialized the DATA(p) message. + * + * @param [in] pdata ParticipantProxyData from the DATA(p) message. + * @param [in, out] extra_data Additional data that may be needed to check the discovery conditions. + * @remarks Whether discovery routine should continue or discard the participant. + */ + virtual bool check_discovery_conditions( + ParticipantProxyData& participant_data, + void* extra_data); + /** * Get the key of a CacheChange_t * @param change Pointer to the CacheChange_t diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServerListener.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPServerListener.cpp index 2b9e7abbe93..ebc7676fc64 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServerListener.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServerListener.cpp @@ -148,98 +148,16 @@ void PDPServerListener::onNewCacheChangeAdded( return; } - const auto& pattr = pdp_server()->getRTPSParticipant()->getAttributes(); - fastdds::rtps::network::external_locators::filter_remote_locators(participant_data, - pattr.builtin.metatraffic_external_unicast_locators, pattr.default_external_unicast_locators, - pattr.ignore_non_matching_locators); - - /* Check PID_VENDOR_ID */ - if (participant_data.m_VendorId != fastrtps::rtps::c_VendorId_eProsima) + bool is_client = true; + if (!check_discovery_conditions(participant_data, &is_client)) { - EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, - "DATA(p|Up) from different vendor is not supported for Discover-Server operation"); return; } - fastdds::dds::ParameterPropertyList_t properties = participant_data.m_properties; - - /* Check DS_VERSION */ - auto ds_version = std::find_if( - properties.begin(), - properties.end(), - [](const dds::ParameterProperty_t& property) - { - return property.first() == dds::parameter_property_ds_version; - }); - - if (ds_version != properties.end()) - { - if (std::stof(ds_version->second()) < 1.0) - { - EPROSIMA_LOG_ERROR(RTPS_PDP_LISTENER, "Minimum " << dds::parameter_property_ds_version - << " is 1.0, found: " << ds_version->second()); - return; - } - EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, "Participant " << dds::parameter_property_ds_version << ": " - << ds_version->second()); - } - else - { - EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, dds::parameter_property_ds_version << " is not set. Assuming 1.0"); - } - - /* Check PARTICIPANT_TYPE */ - bool is_client = true; - auto participant_type = std::find_if( - properties.begin(), - properties.end(), - [](const dds::ParameterProperty_t& property) - { - return property.first() == dds::parameter_property_participant_type; - }); - - if (participant_type != properties.end()) - { - if (participant_type->second() == ParticipantType::SERVER || - participant_type->second() == ParticipantType::BACKUP || - participant_type->second() == ParticipantType::SUPER_CLIENT) - { - is_client = false; - } - else if (participant_type->second() == ParticipantType::SIMPLE) - { - EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, "Ignoring " << dds::parameter_property_participant_type << ": " - << participant_type->second()); - return; - } - else if (participant_type->second() != ParticipantType::CLIENT) - { - EPROSIMA_LOG_ERROR(RTPS_PDP_LISTENER, "Wrong " << dds::parameter_property_participant_type << ": " - << participant_type->second()); - return; - } - EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, "Participant type " << participant_type->second()); - } - else - { - EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, dds::parameter_property_participant_type << " is not set"); - // Fallback to checking whether participant is a SERVER looking for the persistence GUID - auto persistence_guid = std::find_if( - properties.begin(), - properties.end(), - [](const dds::ParameterProperty_t& property) - { - return property.first() == dds::parameter_property_persistence_guid; - }); - // The presence of persistence GUID property suggests a SERVER. This assumption is made to keep - // backwards compatibility with Discovery Server v1.0. However, any participant that has been configured - // as persistent will have this property. - if (persistence_guid != properties.end()) - { - is_client = false; - } - EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, "Participant is client: " << std::boolalpha << is_client); - } + const auto& pattr = pdp_server()->getRTPSParticipant()->getAttributes(); + fastdds::rtps::network::external_locators::filter_remote_locators(participant_data, + pattr.builtin.metatraffic_external_unicast_locators, pattr.default_external_unicast_locators, + pattr.ignore_non_matching_locators); // Check whether the participant is a client/server of this server or if it has been forwarded from // another entity (server). @@ -443,6 +361,114 @@ void PDPServerListener::onNewCacheChangeAdded( EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, ""); } +bool PDPServerListener::check_discovery_conditions( + ParticipantProxyData& participant_data, + void* extra_data /* bool is_client*/) +{ + bool ret = true; + + /* Check PID_VENDOR_ID */ + if (participant_data.m_VendorId != fastrtps::rtps::c_VendorId_eProsima) + { + EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, + "DATA(p|Up) from different vendor is not supported for Discover-Server operation"); + ret = false; + } + + // In Discovery Server we don't impose + // domain ids to be the same + /* Do not check PID_DOMAIN_ID */ + + fastdds::dds::ParameterPropertyList_t properties = participant_data.m_properties; + + /* Check DS_VERSION */ + if (ret) + { + auto ds_version = std::find_if( + properties.begin(), + properties.end(), + [](const dds::ParameterProperty_t& property) + { + return property.first() == dds::parameter_property_ds_version; + }); + + if (ds_version != properties.end()) + { + if (std::stof(ds_version->second()) < 1.0) + { + EPROSIMA_LOG_ERROR(RTPS_PDP_LISTENER, "Minimum " << dds::parameter_property_ds_version + << " is 1.0, found: " << ds_version->second()); + ret = false; + } + EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, "Participant " << dds::parameter_property_ds_version << ": " + << ds_version->second()); + } + else + { + EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, dds::parameter_property_ds_version << " is not set. Assuming 1.0"); + } + } + + /* Check PARTICIPANT_TYPE */ + if (ret) + { + auto participant_type = std::find_if( + properties.begin(), + properties.end(), + [](const dds::ParameterProperty_t& property) + { + return property.first() == dds::parameter_property_participant_type; + }); + + if (participant_type != properties.end()) + { + if (participant_type->second() == ParticipantType::SERVER || + participant_type->second() == ParticipantType::BACKUP || + participant_type->second() == ParticipantType::SUPER_CLIENT) + { + *static_cast(extra_data) = false; + } + else if (participant_type->second() == ParticipantType::SIMPLE) + { + EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, "Ignoring " << dds::parameter_property_participant_type << ": " + << participant_type->second()); + ret = false; + } + else if (participant_type->second() != ParticipantType::CLIENT) + { + EPROSIMA_LOG_ERROR(RTPS_PDP_LISTENER, "Wrong " << dds::parameter_property_participant_type << ": " + << participant_type->second()); + ret = false; + } + EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, "Participant type " << participant_type->second()); + } + else + { + EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, dds::parameter_property_participant_type << " is not set"); + // Fallback to checking whether participant is a SERVER looking for the persistence GUID + auto persistence_guid = std::find_if( + properties.begin(), + properties.end(), + [](const dds::ParameterProperty_t& property) + { + return property.first() == dds::parameter_property_persistence_guid; + }); + // The presence of persistence GUID property suggests a SERVER. This assumption is made to keep + // backwards compatibility with Discovery Server v1.0. However, any participant that has been configured + // as persistent will have this property. + if (persistence_guid != properties.end()) + { + // is_client = false + *static_cast(extra_data) = false; + } + EPROSIMA_LOG_INFO(RTPS_PDP_LISTENER, + "Participant is client: " << std::boolalpha << *static_cast(extra_data)); + } + } + + return ret; +} + } /* namespace rtps */ } /* namespace fastdds */ } /* namespace eprosima */ diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServerListener.hpp b/src/cpp/rtps/builtin/discovery/participant/PDPServerListener.hpp index b0f96268240..8778ffffb30 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServerListener.hpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServerListener.hpp @@ -58,6 +58,12 @@ class PDPServerListener : public fastrtps::rtps::PDPListener void onNewCacheChangeAdded( fastrtps::rtps::RTPSReader* reader, const fastrtps::rtps::CacheChange_t* const change) override; + +protected: + + bool check_discovery_conditions( + fastrtps::rtps::ParticipantProxyData& participant_data, + void* extra_data) override; };