Skip to content

Commit

Permalink
DomainParticipant::ignore_participant implementation (#3412)
Browse files Browse the repository at this point in the history
* Refs #17873: Added tests

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Added implementation

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Modified unsupported test

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Switched default callback calling order

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Reevaluate source ignored status after the reception of an INFO_SRC message

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Added missing callback redirection. Added missing ignore check after callback

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Reintroduced remove_remove_participant into ignore_participant. Applied suggestions

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Changed the ignore_participant return type. Applied more suggestions

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Extended PDPListener modifications to PDPServerListener

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Updated versions.md

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Prevented participants from ignoring their own discovery servers

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Further improved filtering

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

* Refs #17873: Removed unsupported from doxydoc

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>

---------

Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
  • Loading branch information
jsan-rt authored Apr 3, 2023
1 parent 7123d35 commit 924593a
Show file tree
Hide file tree
Showing 18 changed files with 354 additions and 152 deletions.
4 changes: 1 addition & 3 deletions include/fastdds/dds/domain/DomainParticipant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,7 @@ class DomainParticipant : public Entity
* @note This action is not reversible.
*
* @param handle Identifier of the remote participant to ignore
* @return RETURN_OK code if everything correct, error code otherwise
*
* @warning Not supported yet. Currently returns RETCODE_UNSUPPORTED
* @return RETURN_OK code if everything correct, RETCODE_BAD_PARAMENTER otherwise
*
*/
RTPS_DllAPI ReturnCode_t ignore_participant(
Expand Down
5 changes: 2 additions & 3 deletions include/fastdds/dds/domain/DomainParticipantListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ class DomainParticipantListener :
fastrtps::rtps::ParticipantDiscoveryInfo&& info,
bool& should_be_ignored)
{
static_cast<void>(participant);
static_cast<void>(info);
static_cast<void>(should_be_ignored);
on_participant_discovery(participant, std::move(info));
should_be_ignored = false;
}

#if HAVE_SECURITY
Expand Down
5 changes: 4 additions & 1 deletion include/fastdds/rtps/messages/MessageReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class MessageReceiver
* -Return an error if the message is malformed.
* @param[in,out] msg Pointer to the message
* @param[in] smh Pointer to the submessage header
* @param[out] WriterID Writer EntityID (only for DATA messages)
* @return True if correct, false otherwise
*/

Expand All @@ -165,11 +166,13 @@ class MessageReceiver
*
* @param msg
* @param smh
* @param writerID
* @return
*/
bool proc_Submsg_Data(
CDRMessage_t* msg,
SubmessageHeader_t* smh) const;
SubmessageHeader_t* smh,
EntityId_t& writerID) const;
bool proc_Submsg_DataFrag(
CDRMessage_t* msg,
SubmessageHeader_t* smh) const;
Expand Down
5 changes: 2 additions & 3 deletions include/fastdds/rtps/participant/RTPSParticipantListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ class RTPS_DllAPI RTPSParticipantListener
ParticipantDiscoveryInfo&& info,
bool& should_be_ignored)
{
static_cast<void>(participant);
static_cast<void>(info);
static_cast<void>(should_be_ignored);
onParticipantDiscovery(participant, std::move(info));
should_be_ignored = false;
}

#if HAVE_SECURITY
Expand Down
3 changes: 1 addition & 2 deletions src/cpp/fastdds/domain/DomainParticipant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ const Subscriber* DomainParticipant::get_builtin_subscriber() const
ReturnCode_t DomainParticipant::ignore_participant(
const InstanceHandle_t& handle)
{
static_cast<void> (handle);
return ReturnCode_t::RETCODE_UNSUPPORTED;
return impl_->ignore_participant(handle);
}

ReturnCode_t DomainParticipant::ignore_topic(
Expand Down
17 changes: 11 additions & 6 deletions src/cpp/fastdds/domain/DomainParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
*
*/

#include "fastdds/rtps/common/Guid.h"
#include "fastdds/rtps/common/GuidPrefix_t.hpp"
#include <chrono>
#include <fastrtps/types/TypesBase.h>
#include <string>

#include <asio.hpp>
Expand Down Expand Up @@ -827,12 +830,12 @@ PublisherImpl* DomainParticipantImpl::create_publisher_impl(
}
*/

bool DomainParticipantImpl::ignore_participant(
ReturnCode_t DomainParticipantImpl::ignore_participant(
const InstanceHandle_t& handle)
{
static_cast<void>(handle);
EPROSIMA_LOG_ERROR(PARTICIPANT, "Not implemented.");
return false;
return (nullptr == rtps_participant_) ? ReturnCode_t::RETCODE_NOT_ENABLED :
rtps_participant_->ignore_participant(iHandle2GUID(handle).guidPrefix) ? ReturnCode_t::RETCODE_OK :
ReturnCode_t::RETCODE_BAD_PARAMETER;
}

/* TODO
Expand Down Expand Up @@ -1528,12 +1531,14 @@ ReturnCode_t DomainParticipantImpl::unregister_type(

void DomainParticipantImpl::MyRTPSParticipantListener::onParticipantDiscovery(
RTPSParticipant*,
ParticipantDiscoveryInfo&& info)
ParticipantDiscoveryInfo&& info,
bool& should_be_ignored)
{
Sentry sentinel(this);
if (sentinel)
{
participant_->listener_->on_participant_discovery(participant_->participant_, std::move(info));
participant_->listener_->on_participant_discovery(participant_->participant_, std::move(info),
should_be_ignored);
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/cpp/fastdds/domain/DomainParticipantImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,12 @@ class DomainParticipantImpl
* @brief Locally ignore a remote domain participant.
*
* @param[in] handle Identifier of the remote participant to ignore.
* @return true if correctly ignored. False otherwise.
* @return RETCODE_NOT_ENABLED if the participant is not enabled.
* RETCODE_ERROR if unable to ignore.
* RETCODE_OK if successful.
*
*/
bool ignore_participant(
ReturnCode_t ignore_participant(
const InstanceHandle_t& handle);

/* TODO
Expand Down Expand Up @@ -658,7 +661,8 @@ class DomainParticipantImpl

void onParticipantDiscovery(
fastrtps::rtps::RTPSParticipant* participant,
fastrtps::rtps::ParticipantDiscoveryInfo&& info) override;
fastrtps::rtps::ParticipantDiscoveryInfo&& info,
bool& should_be_ignored) override;

#if HAVE_SECURITY
void onParticipantAuthentication(
Expand Down
4 changes: 3 additions & 1 deletion src/cpp/rtps/builtin/discovery/participant/PDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,9 @@ bool PDP::remove_remote_participant(
std::lock_guard<std::mutex> lock(callback_mtx_);
ParticipantDiscoveryInfo info(*pdata);
info.status = reason;
listener->onParticipantDiscovery(mp_RTPSParticipant->getUserRTPSParticipant(), std::move(info));
bool should_be_ignored = false;
listener->onParticipantDiscovery(mp_RTPSParticipant->getUserRTPSParticipant(), std::move(
info), should_be_ignored);
}

this->mp_mutex->lock();
Expand Down
48 changes: 36 additions & 12 deletions src/cpp/rtps/builtin/discovery/participant/PDPListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ void PDPListener::onNewCacheChangeAdded(
change->instanceHandle = temp_participant_data_.m_key;
guid = temp_participant_data_.m_guid;

if (parent_pdp_->getRTPSParticipant()->is_participant_ignored(guid.guidPrefix))
{
return;
}

// Filter locators
const auto& pattr = parent_pdp_->getRTPSParticipant()->getAttributes();
fastdds::rtps::ExternalLocatorsProcessor::filter_remote_locators(temp_participant_data_,
Expand Down Expand Up @@ -147,13 +152,23 @@ void PDPListener::onNewCacheChangeAdded(
RTPSParticipantListener* listener = parent_pdp_->getRTPSParticipant()->getListener();
if (listener != nullptr)
{
std::lock_guard<std::mutex> cb_lock(parent_pdp_->callback_mtx_);
ParticipantDiscoveryInfo info(*pdata);
info.status = status;
bool should_be_ignored = false;
{
std::lock_guard<std::mutex> cb_lock(parent_pdp_->callback_mtx_);
ParticipantDiscoveryInfo info(*pdata);
info.status = status;


listener->onParticipantDiscovery(
parent_pdp_->getRTPSParticipant()->getUserRTPSParticipant(),
std::move(info),
should_be_ignored);
}
if (should_be_ignored)
{
parent_pdp_->getRTPSParticipant()->ignore_participant(guid.guidPrefix);
}

listener->onParticipantDiscovery(
parent_pdp_->getRTPSParticipant()->getUserRTPSParticipant(),
std::move(info));
}

// Assigning remote endpoints implies sending a DATA(p) to all matched and fixed readers, since
Expand Down Expand Up @@ -190,13 +205,22 @@ void PDPListener::onNewCacheChangeAdded(
RTPSParticipantListener* listener = parent_pdp_->getRTPSParticipant()->getListener();
if (listener != nullptr)
{
std::lock_guard<std::mutex> cb_lock(parent_pdp_->callback_mtx_);
ParticipantDiscoveryInfo info(*pdata);
info.status = status;
bool should_be_ignored = false;

{
std::lock_guard<std::mutex> cb_lock(parent_pdp_->callback_mtx_);
ParticipantDiscoveryInfo info(*pdata);
info.status = status;

listener->onParticipantDiscovery(
parent_pdp_->getRTPSParticipant()->getUserRTPSParticipant(),
std::move(info));
listener->onParticipantDiscovery(
parent_pdp_->getRTPSParticipant()->getUserRTPSParticipant(),
std::move(info),
should_be_ignored);
}
if (should_be_ignored)
{
parent_pdp_->getRTPSParticipant()->ignore_participant(temp_participant_data_.m_guid.guidPrefix);
}
}
}

Expand Down
26 changes: 19 additions & 7 deletions src/cpp/rtps/builtin/discovery/participant/PDPServerListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ void PDPServerListener::onNewCacheChangeAdded(
pdp_server()->getRTPSParticipant()->network_factory(),
pdp_server()->getRTPSParticipant()->has_shm_transport()))
{
if (parent_pdp_->getRTPSParticipant()->is_participant_ignored(participant_data.m_guid.guidPrefix))
{
return;
}

const auto& pattr = pdp_server()->getRTPSParticipant()->getAttributes();
fastdds::rtps::ExternalLocatorsProcessor::filter_remote_locators(participant_data,
pattr.builtin.metatraffic_external_unicast_locators, pattr.default_external_unicast_locators,
Expand Down Expand Up @@ -363,13 +368,20 @@ void PDPServerListener::onNewCacheChangeAdded(
RTPSParticipantListener* listener = pdp_server()->getRTPSParticipant()->getListener();
if (listener != nullptr)
{
std::lock_guard<std::mutex> cb_lock(pdp_server()->callback_mtx_);
ParticipantDiscoveryInfo info(*pdata);
info.status = status;

listener->onParticipantDiscovery(
pdp_server()->getRTPSParticipant()->getUserRTPSParticipant(),
std::move(info));
bool should_be_ignored = false;
{
std::lock_guard<std::mutex> cb_lock(pdp_server()->callback_mtx_);
ParticipantDiscoveryInfo info(*pdata);
info.status = status;

listener->onParticipantDiscovery(
pdp_server()->getRTPSParticipant()->getUserRTPSParticipant(),
std::move(info), should_be_ignored);
}
if (should_be_ignored)
{
parent_pdp_->getRTPSParticipant()->ignore_participant(guid.guidPrefix);
}
}
}

Expand Down
Loading

0 comments on commit 924593a

Please sign in to comment.