From 4bc674127f88a737ed8313453f5a2ee1221e1572 Mon Sep 17 00:00:00 2001 From: Iker Luengo Date: Thu, 13 Feb 2020 08:25:22 +0100 Subject: [PATCH] Refs #7552. Only accepting ALIVE changes from unknown trusted writers This is a port of #1005 from 1.9.x * Refs #7552. Only accepting changes from unknown writers when they are ALIVE. * Refs #7552. Added blackbox test. --- .../fastrtps/rtps/reader/StatelessReader.h | 2 +- src/cpp/rtps/reader/StatelessReader.cpp | 29 ++++---- test/blackbox/BlackboxTestsDiscovery.cpp | 67 +++++++++++++++++++ test/blackbox/PubSubReader.hpp | 1 + 4 files changed, 86 insertions(+), 13 deletions(-) diff --git a/include/fastrtps/rtps/reader/StatelessReader.h b/include/fastrtps/rtps/reader/StatelessReader.h index 9881bb437c1..8d0f5478fb2 100644 --- a/include/fastrtps/rtps/reader/StatelessReader.h +++ b/include/fastrtps/rtps/reader/StatelessReader.h @@ -165,7 +165,7 @@ class StatelessReader: public RTPSReader private: - bool acceptMsgFrom(GUID_t& entityId); + bool acceptMsgFrom(GUID_t& entityId, ChangeKind_t change_kind); bool thereIsUpperRecordOf(GUID_t& guid, SequenceNumber_t& seq); diff --git a/src/cpp/rtps/reader/StatelessReader.cpp b/src/cpp/rtps/reader/StatelessReader.cpp index 9e9a28f039d..c273913678a 100644 --- a/src/cpp/rtps/reader/StatelessReader.cpp +++ b/src/cpp/rtps/reader/StatelessReader.cpp @@ -216,7 +216,7 @@ bool StatelessReader::processDataMsg(CacheChange_t *change) std::unique_lock lock(mp_mutex); - if(acceptMsgFrom(change->writerGUID)) + if (acceptMsgFrom(change->writerGUID, change->kind)) { logInfo(RTPS_MSG_IN,IDSTRING"Trying to add change " << change->sequenceNumber <<" TO reader: "<< getGuid().entityId); @@ -317,7 +317,7 @@ bool StatelessReader::processDataFragMsg( std::unique_lock lock(mp_mutex); - if (acceptMsgFrom(incomingChange->writerGUID)) + if (acceptMsgFrom(incomingChange->writerGUID, incomingChange->kind)) { if (liveliness_lease_duration_ < c_TimeInfinite) { @@ -431,28 +431,33 @@ bool StatelessReader::processGapMsg( return true; } -bool StatelessReader::acceptMsgFrom(GUID_t& writerId) +bool StatelessReader::acceptMsgFrom( + GUID_t& writerId, + ChangeKind_t change_kind) { - if(this->m_acceptMessagesFromUnknownWriters) + if (change_kind == ChangeKind_t::ALIVE) { - return true; - } - else - { - if(writerId.entityId == this->m_trustedWriterEntityId) + if(this->m_acceptMessagesFromUnknownWriters) { return true; } - - for(auto it = m_matched_writers.begin();it!=m_matched_writers.end();++it) + else { - if((*it).guid == writerId) + if(writerId.entityId == this->m_trustedWriterEntityId) { return true; } } } + for(auto it = m_matched_writers.begin();it!=m_matched_writers.end();++it) + { + if((*it).guid == writerId) + { + return true; + } + } + return false; } diff --git a/test/blackbox/BlackboxTestsDiscovery.cpp b/test/blackbox/BlackboxTestsDiscovery.cpp index 9d2217de888..00f11ae5391 100644 --- a/test/blackbox/BlackboxTestsDiscovery.cpp +++ b/test/blackbox/BlackboxTestsDiscovery.cpp @@ -652,3 +652,70 @@ TEST(Discovery, TwentyParticipantsSeveralEndpoints) ps->destroy(); } } + +//! Regression test for support case 7552 (CRM #353) +TEST(Discovery, RepeatPubGuid) +{ + PubSubReader reader(TEST_TOPIC_NAME); + PubSubWriter writer(TEST_TOPIC_NAME); + PubSubWriter writer2(TEST_TOPIC_NAME); + + reader + .history_kind(eprosima::fastrtps::KEEP_LAST_HISTORY_QOS) + .history_depth(10) + .reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS) + .participant_id(2) + .init(); + + writer + .history_kind(eprosima::fastrtps::KEEP_LAST_HISTORY_QOS) + .history_depth(10) + .reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS) + .participant_id(1) + .init(); + + ASSERT_TRUE(reader.isInitialized()); + ASSERT_TRUE(writer.isInitialized()); + + // Wait for discovery. + writer.wait_discovery(); + reader.wait_discovery(); + + 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(); + + writer.destroy(); + reader.wait_writer_undiscovery(); + reader.wait_participant_undiscovery(); + + writer2 + .history_kind(eprosima::fastrtps::KEEP_LAST_HISTORY_QOS) + .history_depth(10) + .reliability(eprosima::fastrtps::RELIABLE_RELIABILITY_QOS) + .participant_id(1) + .init(); + + ASSERT_TRUE(writer2.isInitialized()); + + writer2.wait_discovery(); + reader.wait_discovery(); + + data = default_helloworld_data_generator(); + reader.startReception(data); + + // Send data + writer2.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(); +} + + diff --git a/test/blackbox/PubSubReader.hpp b/test/blackbox/PubSubReader.hpp index efc7c85a107..249782985bc 100644 --- a/test/blackbox/PubSubReader.hpp +++ b/test/blackbox/PubSubReader.hpp @@ -293,6 +293,7 @@ class PubSubReader total_msgs_ = msgs; number_samples_expected_ = total_msgs_.size(); current_received_count_ = 0; + last_seq = eprosima::fastrtps::rtps::SequenceNumber_t(); mutex_.unlock(); bool ret = false;