Skip to content

Commit 82d589f

Browse files
committed
Refs #22056: Avoid sending machine_id in Data(r/w)
Signed-off-by: cferreiragonz <[email protected]>
1 parent 0077886 commit 82d589f

File tree

5 files changed

+128
-133
lines changed

5 files changed

+128
-133
lines changed

src/cpp/rtps/builtin/data/ReaderProxyData.cpp

+49-77
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <fastdds/rtps/common/CDRMessage_t.hpp>
2525
#include <fastdds/rtps/common/VendorId_t.hpp>
2626

27+
#include <rtps/builtin/data/ParticipantProxyData.hpp>
2728
#include <rtps/network/NetworkFactory.hpp>
2829
#include <utils/SystemInfo.hpp>
2930

@@ -192,13 +193,6 @@ uint32_t ReaderProxyData::get_serialized_size(
192193
// PID_NETWORK_CONFIGURATION_SET
193194
ret_val += 4 + PARAMETER_NETWORKCONFIGSET_LENGTH;
194195

195-
if (m_host_id.size() > 0)
196-
{
197-
// PID_HOST_ID
198-
ret_val +=
199-
fastdds::dds::ParameterSerializer<Parameter_t>::cdr_serialized_size(m_host_id);
200-
}
201-
202196
// PID_UNICAST_LOCATOR
203197
ret_val += static_cast<uint32_t>((4 + PARAMETER_LOCATOR_LENGTH) * remote_locators_.unicast.size());
204198

@@ -389,15 +383,6 @@ bool ReaderProxyData::writeToCDRMessage(
389383
}
390384
}
391385

392-
if (m_host_id.size() > 0)
393-
{
394-
ParameterString_t p(fastdds::dds::PID_HOST_ID, 0, m_host_id);
395-
if (!fastdds::dds::ParameterSerializer<ParameterString_t>::add_to_cdr_message(p, msg))
396-
{
397-
return false;
398-
}
399-
}
400-
401386
for (const Locator_t& locator : remote_locators_.unicast)
402387
{
403388
ParameterLocator_t p(fastdds::dds::PID_UNICAST_LOCATOR, PARAMETER_LOCATOR_LENGTH, locator);
@@ -897,33 +882,6 @@ bool ReaderProxyData::readFromCDRMessage(
897882
m_networkConfiguration = p.netconfigSet;
898883
break;
899884
}
900-
case fastdds::dds::PID_HOST_ID:
901-
{
902-
VendorId_t local_vendor_id = source_vendor_id;
903-
if (c_VendorId_Unknown == local_vendor_id)
904-
{
905-
local_vendor_id = ((c_VendorId_Unknown == vendor_id) ? c_VendorId_eProsima : vendor_id);
906-
}
907-
908-
// Ignore custom PID when coming from other vendors
909-
if (c_VendorId_eProsima != local_vendor_id)
910-
{
911-
EPROSIMA_LOG_INFO(RTPS_PROXY_DATA,
912-
"Ignoring custom PID" << pid << " from vendor " << local_vendor_id);
913-
return true;
914-
}
915-
916-
ParameterString_t p(pid, plength);
917-
if (!fastdds::dds::ParameterSerializer<ParameterString_t>::read_from_cdr_message(
918-
p, msg,
919-
plength))
920-
{
921-
return false;
922-
}
923-
924-
m_host_id = p.getName();
925-
break;
926-
}
927885
case fastdds::dds::PID_UNICAST_LOCATOR:
928886
{
929887
ParameterLocator_t p(pid, plength);
@@ -933,23 +891,7 @@ bool ReaderProxyData::readFromCDRMessage(
933891
return false;
934892
}
935893

936-
if (!should_filter_locators)
937-
{
938-
remote_locators_.add_unicast_locator(p.locator);
939-
}
940-
else
941-
{
942-
Locator_t temp_locator;
943-
if (network.transform_remote_locator(p.locator, temp_locator, m_networkConfiguration,
944-
check_same_host()))
945-
{
946-
ProxyDataFilters::filter_locators(
947-
network,
948-
remote_locators_,
949-
temp_locator,
950-
true);
951-
}
952-
}
894+
remote_locators_.add_unicast_locator(p.locator);
953895
break;
954896
}
955897
case fastdds::dds::PID_MULTICAST_LOCATOR:
@@ -961,23 +903,7 @@ bool ReaderProxyData::readFromCDRMessage(
961903
return false;
962904
}
963905

964-
if (!should_filter_locators)
965-
{
966-
remote_locators_.add_multicast_locator(p.locator);
967-
}
968-
else
969-
{
970-
Locator_t temp_locator;
971-
if (network.transform_remote_locator(p.locator, temp_locator, m_networkConfiguration,
972-
check_same_host()))
973-
{
974-
ProxyDataFilters::filter_locators(
975-
network,
976-
remote_locators_,
977-
temp_locator,
978-
false);
979-
}
980-
}
906+
remote_locators_.add_unicast_locator(p.locator);
981907
break;
982908
}
983909
case fastdds::dds::PID_EXPECTS_INLINE_QOS:
@@ -1193,6 +1119,52 @@ bool ReaderProxyData::readFromCDRMessage(
11931119
return false;
11941120
}
11951121

1122+
void ReaderProxyData::setup_locators(
1123+
const ReaderProxyData* rdata,
1124+
NetworkFactory& network,
1125+
const ParticipantProxyData& participant_data)
1126+
{
1127+
if (this == rdata)
1128+
{
1129+
return;
1130+
}
1131+
1132+
machine_id = participant_data.machine_id;
1133+
1134+
if (has_locators())
1135+
{
1136+
// Get the transformed remote locators for the ReaderProxyData received
1137+
remote_locators_.unicast.clear();
1138+
remote_locators_.multicast.clear();
1139+
for (const Locator_t& locator : rdata->remote_locators_.unicast)
1140+
{
1141+
Locator_t temp_locator;
1142+
if (network.transform_remote_locator(locator, temp_locator, m_networkConfiguration,
1143+
is_from_this_host()))
1144+
{
1145+
ProxyDataFilters::filter_locators(network, remote_locators_, temp_locator, true);
1146+
}
1147+
}
1148+
for (const Locator_t& locator : rdata->remote_locators_.multicast)
1149+
{
1150+
Locator_t temp_locator;
1151+
if (network.transform_remote_locator(locator, temp_locator, m_networkConfiguration,
1152+
is_from_this_host()))
1153+
{
1154+
ProxyDataFilters::filter_locators(network, remote_locators_, temp_locator, true);
1155+
}
1156+
}
1157+
auto locators = remote_locators_;
1158+
set_remote_locators(locators, network, true);
1159+
}
1160+
else
1161+
{
1162+
// Get the remote locators from the participant_data
1163+
set_remote_locators(participant_data.default_locators, network, true);
1164+
}
1165+
1166+
}
1167+
11961168
bool ReaderProxyData::is_from_this_host()
11971169
{
11981170
bool same_host = false;

src/cpp/rtps/builtin/data/ReaderProxyData.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace rtps {
3535

3636
struct CDRMessage_t;
3737
class NetworkFactory;
38+
class ParticipantProxyData;
3839

3940
/**
4041
* Class ReaderProxyData, used to represent all the information on a Reader (both local and remote) with the purpose of
@@ -434,6 +435,19 @@ class ReaderProxyData
434435
bool should_filter_locators,
435436
fastdds::rtps::VendorId_t source_vendor_id = c_VendorId_eProsima);
436437

438+
/**
439+
* Transform and set the remote locators from the remote_locators_ of another ReaderProxyData.
440+
* If the received WriterProxyData has no locators, remote locators will be extracted from the
441+
* ParticipantProxyData.
442+
* @param rdata ReaderProxyData to get the locators from
443+
* @param network NetworkFactory to transform locators
444+
* @param participant_data ParticipantProxyData to get the locators from
445+
*/
446+
void setup_locators(
447+
const ReaderProxyData* wdata,
448+
NetworkFactory& network,
449+
const ParticipantProxyData& participant_data);
450+
437451
/**
438452
* Check if the host is the same as the one that sent the data.
439453
* It tries to use the machine_id. If it is not available, it will compare GUIDs.

src/cpp/rtps/builtin/data/WriterProxyData.cpp

+50-51
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <fastdds/dds/log/Log.hpp>
2323
#include <fastdds/rtps/common/VendorId_t.hpp>
2424

25+
#include <rtps/builtin/data/ParticipantProxyData.hpp>
2526
#include <rtps/builtin/data/WriterProxyData.hpp>
2627
#include <rtps/network/NetworkFactory.hpp>
2728
#include <utils/SystemInfo.hpp>
@@ -184,13 +185,6 @@ uint32_t WriterProxyData::get_serialized_size(
184185
// PID_NETWORK_CONFIGURATION_SET
185186
ret_val += 4 + PARAMETER_NETWORKCONFIGSET_LENGTH;
186187

187-
if (m_host_id.size() > 0)
188-
{
189-
// PID_HOST_ID
190-
ret_val +=
191-
fastdds::dds::ParameterSerializer<Parameter_t>::cdr_serialized_size(m_host_id);
192-
}
193-
194188
// PID_UNICAST_LOCATOR
195189
ret_val += static_cast<uint32_t>((4 + PARAMETER_LOCATOR_LENGTH) * remote_locators_.unicast.size());
196190

@@ -371,15 +365,6 @@ bool WriterProxyData::writeToCDRMessage(
371365
}
372366
}
373367

374-
if (m_host_id.size() > 0)
375-
{
376-
ParameterString_t p(fastdds::dds::PID_HOST_ID, 0, m_host_id);
377-
if (!fastdds::dds::ParameterSerializer<ParameterString_t>::add_to_cdr_message(p, msg))
378-
{
379-
return false;
380-
}
381-
}
382-
383368
for (const Locator_t& locator : remote_locators_.unicast)
384369
{
385370
ParameterLocator_t p(fastdds::dds::PID_UNICAST_LOCATOR, PARAMETER_LOCATOR_LENGTH, locator);
@@ -903,23 +888,7 @@ bool WriterProxyData::readFromCDRMessage(
903888
return false;
904889
}
905890

906-
if (!should_filter_locators)
907-
{
908-
remote_locators_.add_unicast_locator(p.locator);
909-
}
910-
else
911-
{
912-
Locator_t temp_locator;
913-
if (network.transform_remote_locator(p.locator, temp_locator, m_networkConfiguration,
914-
check_same_host()))
915-
{
916-
ProxyDataFilters::filter_locators(
917-
network,
918-
remote_locators_,
919-
temp_locator,
920-
true);
921-
}
922-
}
891+
remote_locators_.add_unicast_locator(p.locator);
923892
break;
924893
}
925894
case fastdds::dds::PID_MULTICAST_LOCATOR:
@@ -930,23 +899,7 @@ bool WriterProxyData::readFromCDRMessage(
930899
return false;
931900
}
932901

933-
if (!should_filter_locators)
934-
{
935-
remote_locators_.add_multicast_locator(p.locator);
936-
}
937-
else
938-
{
939-
Locator_t temp_locator;
940-
if (network.transform_remote_locator(p.locator, temp_locator, m_networkConfiguration,
941-
check_same_host()))
942-
{
943-
ProxyDataFilters::filter_locators(
944-
network,
945-
remote_locators_,
946-
temp_locator,
947-
false);
948-
}
949-
}
902+
remote_locators_.add_multicast_locator(p.locator);
950903
break;
951904
}
952905
case fastdds::dds::PID_KEY_HASH:
@@ -1134,7 +1087,53 @@ bool WriterProxyData::readFromCDRMessage(
11341087
return false;
11351088
}
11361089

1137-
bool WriterProxyData::check_same_host()
1090+
void WriterProxyData::setup_locators(
1091+
const WriterProxyData* wdata,
1092+
NetworkFactory& network,
1093+
const ParticipantProxyData& participant_data)
1094+
{
1095+
if (this == wdata)
1096+
{
1097+
return;
1098+
}
1099+
1100+
machine_id = participant_data.machine_id;
1101+
1102+
if (has_locators())
1103+
{
1104+
// Get the transformed remote locators for the WriterProxyData received
1105+
remote_locators_.unicast.clear();
1106+
remote_locators_.multicast.clear();
1107+
for (const Locator_t& locator : wdata->remote_locators_.unicast)
1108+
{
1109+
Locator_t temp_locator;
1110+
if (network.transform_remote_locator(locator, temp_locator, m_networkConfiguration,
1111+
is_from_this_host()))
1112+
{
1113+
ProxyDataFilters::filter_locators(network, remote_locators_, temp_locator, true);
1114+
}
1115+
}
1116+
for (const Locator_t& locator : wdata->remote_locators_.multicast)
1117+
{
1118+
Locator_t temp_locator;
1119+
if (network.transform_remote_locator(locator, temp_locator, m_networkConfiguration,
1120+
is_from_this_host()))
1121+
{
1122+
ProxyDataFilters::filter_locators(network, remote_locators_, temp_locator, true);
1123+
}
1124+
}
1125+
auto locators = remote_locators_;
1126+
set_remote_locators(locators, network, true);
1127+
}
1128+
else
1129+
{
1130+
// Get the remote locators from the participant_data
1131+
set_remote_locators(participant_data.default_locators, network, true);
1132+
}
1133+
1134+
}
1135+
1136+
bool WriterProxyData::is_from_this_host()
11381137
{
11391138
bool same_host = false;
11401139
if (machine_id.size() > 0)

src/cpp/rtps/builtin/data/WriterProxyData.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace rtps {
3737

3838
struct CDRMessage_t;
3939
class NetworkFactory;
40+
class ParticipantProxyData;
4041

4142
/**
4243
**@ingroup BUILTIN_MODULE
@@ -455,6 +456,19 @@ class WriterProxyData
455456
bool should_filter_locators,
456457
fastdds::rtps::VendorId_t source_vendor_id = c_VendorId_eProsima);
457458

459+
/**
460+
* Transform and set the remote locators from the remote_locators_ of another WriterProxyData.
461+
* If the received WriterProxyData has no locators, remote locators will be extracted from the
462+
* ParticipantProxyData.
463+
* @param wdata WriterProxyData to get the locators from
464+
* @param network NetworkFactory to transform locators
465+
* @param participant_data ParticipantProxyData to get the locators from
466+
*/
467+
void setup_locators(
468+
const WriterProxyData* wdata,
469+
NetworkFactory& network,
470+
const ParticipantProxyData& participant_data);
471+
458472
/**
459473
* Check if the host is the same as the one that sent the data.
460474
* It tries to use the machine_id. If it is not available, it will compare GUIDs.

src/cpp/rtps/builtin/discovery/endpoint/EDPSimpleListeners.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ void EDPBasePUBListener::add_writer_from_change(
9595
bool updating,
9696
const ParticipantProxyData& participant_data)
9797
{
98-
if (!temp_writer_data->has_locators())
99-
{
100-
temp_writer_data->set_remote_locators(participant_data.default_locators, network,
101-
true);
102-
}
10398

10499
if (updating && !data->is_update_allowed(*temp_writer_data))
105100
{
@@ -108,6 +103,7 @@ void EDPBasePUBListener::add_writer_from_change(
108103
data->guid());
109104
}
110105
*data = *temp_writer_data;
106+
data->setup_locators(temp_writer_data, network, participant_data);
111107

112108
if (request_ret_status != fastdds::dds::RETCODE_OK)
113109
{

0 commit comments

Comments
 (0)