Skip to content

Commit

Permalink
Refs #7552. Only accepting ALIVE changes from unknown trusted writers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
IkerLuengo committed Feb 13, 2020
1 parent a2c564a commit 4bc6741
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/fastrtps/rtps/reader/StatelessReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
29 changes: 17 additions & 12 deletions src/cpp/rtps/reader/StatelessReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ bool StatelessReader::processDataMsg(CacheChange_t *change)

std::unique_lock<std::recursive_timed_mutex> 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);

Expand Down Expand Up @@ -317,7 +317,7 @@ bool StatelessReader::processDataFragMsg(

std::unique_lock<std::recursive_timed_mutex> lock(mp_mutex);

if (acceptMsgFrom(incomingChange->writerGUID))
if (acceptMsgFrom(incomingChange->writerGUID, incomingChange->kind))
{
if (liveliness_lease_duration_ < c_TimeInfinite)
{
Expand Down Expand Up @@ -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;
}

Expand Down
67 changes: 67 additions & 0 deletions test/blackbox/BlackboxTestsDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,3 +652,70 @@ TEST(Discovery, TwentyParticipantsSeveralEndpoints)
ps->destroy();
}
}

//! Regression test for support case 7552 (CRM #353)
TEST(Discovery, RepeatPubGuid)
{
PubSubReader<HelloWorldType> reader(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> writer(TEST_TOPIC_NAME);
PubSubWriter<HelloWorldType> 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();
}


1 change: 1 addition & 0 deletions test/blackbox/PubSubReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4bc6741

Please sign in to comment.