Skip to content

Commit 330add8

Browse files
Transform locators using new machine_id PID (#5382)
* Refs #22056: compute_machine_id() method Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Add PID_HOST_ID in private header Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: ParticipantProxyData Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: ReaderProxyData Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: WriterProxyData Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Disable builtin transports in DS CLI Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Add Serialization test Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Add machine_id() getter test Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Add PID_HOST_ID to ParameterTypes.hpp Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Uncrustify Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Add Host.cpp to avoid exporting Mac dependencies in .hpp Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Add Host.cpp to tests CMakeLists.txt Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Add localhost to channel_resources if local interface Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Support allowlist & rm comment Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Only disable builtin_transports when UDP server is not initialized Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Link ALL local interfaces to the same channel Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Avoid clearing same channel multiple times Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Tests CMakeLists.txt Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Apply review suggestions Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Avoid sending machine_id in Data(r/w) Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Review - readFromCDRMessage Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Review - setup_locators Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Review - Update tests Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Review - change return type Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Review - Doxydoc & minor fixes Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Review - Return buffer & udp_server_initialized fix Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Fix Tests with new Channel behavior Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Remove initial peers in Security & Refuse bind_socket in existing channel Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Review - Use map::insert and std::set in test Signed-off-by: cferreiragonz <[email protected]> * Refs #22056: Update versions.md Signed-off-by: cferreiragonz <[email protected]> --------- Signed-off-by: cferreiragonz <[email protected]>
1 parent 579ea58 commit 330add8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+759
-239
lines changed

include/fastdds/dds/core/policy/ParameterTypes.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ enum ParameterId_t : uint16_t
168168
/* eProsima Fast DDS extensions */
169169
PID_PRODUCT_VERSION = 0x8000,
170170
PID_PERSISTENCE_GUID = 0x8002,
171+
PID_MACHINE_ID = 0x8003,
171172
PID_DISABLE_POSITIVE_ACKS = 0x8005,
172173
PID_DATASHARING = 0x8006,
173174
PID_NETWORK_CONFIGURATION_SET = 0x8007,

src/cpp/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ set(${PROJECT_NAME}_source_files
229229
statistics/fastdds/domain/DomainParticipant.cpp
230230
statistics/fastdds/publisher/qos/DataWriterQos.cpp
231231
statistics/fastdds/subscriber/qos/DataReaderQos.cpp
232+
utils/Host.cpp
232233
utils/IPFinder.cpp
233234
utils/IPLocator.cpp
234235
utils/md5.cpp
@@ -507,6 +508,14 @@ target_link_libraries(${PROJECT_NAME}
507508
eProsima_atomic
508509
)
509510

511+
if (APPLE)
512+
target_link_libraries(${PROJECT_NAME}
513+
${PRIVACY}
514+
"-framework CoreFoundation"
515+
"-framework IOKit"
516+
)
517+
endif()
518+
510519
if(MSVC OR MSVC_IDE)
511520
# On installed binaries use manifest to specify dependencies
512521
if(INSTALLER_PLATFORM AND OPENSSL_FOUND)

src/cpp/fastdds/builtin/type_lookup_service/TypeLookupManager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ bool TypeLookupManager::assign_remote_endpoints(
165165

166166
temp_writer_proxy_data_->guid().guidPrefix = pdata.m_guid.guidPrefix;
167167
temp_writer_proxy_data_->persistence_guid().guidPrefix = pdata.m_guid.guidPrefix;
168-
temp_writer_proxy_data_->set_remote_locators(pdata.metatraffic_locators, network, true);
168+
temp_writer_proxy_data_->set_remote_locators(pdata.metatraffic_locators, network, true, pdata.is_from_this_host());
169169
temp_writer_proxy_data_->topicKind(NO_KEY);
170170
temp_writer_proxy_data_->m_qos.m_durability.kind = fastdds::dds::VOLATILE_DURABILITY_QOS;
171171
temp_writer_proxy_data_->m_qos.m_reliability.kind = fastdds::dds::RELIABLE_RELIABILITY_QOS;
172172

173173
temp_reader_proxy_data_->clear();
174174
temp_reader_proxy_data_->m_expectsInlineQos = false;
175175
temp_reader_proxy_data_->guid().guidPrefix = pdata.m_guid.guidPrefix;
176-
temp_reader_proxy_data_->set_remote_locators(pdata.metatraffic_locators, network, true);
176+
temp_reader_proxy_data_->set_remote_locators(pdata.metatraffic_locators, network, true, pdata.is_from_this_host());
177177
temp_reader_proxy_data_->topicKind(NO_KEY);
178178
temp_reader_proxy_data_->m_qos.m_durability.kind = fastdds::dds::VOLATILE_DURABILITY_QOS;
179179
temp_reader_proxy_data_->m_qos.m_reliability.kind = fastdds::dds::RELIABLE_RELIABILITY_QOS;

src/cpp/rtps/builtin/data/ParticipantProxyData.cpp

+59-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <rtps/resources/TimedEvent.h>
3737
#include <rtps/transport/shared_mem/SHMLocator.hpp>
3838
#include <utils/TimeConversion.hpp>
39+
#include <utils/SystemInfo.hpp>
3940

4041
#include "ProxyDataFilters.hpp"
4142
#include "ProxyHashTables.hpp"
@@ -80,6 +81,7 @@ ParticipantProxyData::ParticipantProxyData(
8081
const ParticipantProxyData& pdata)
8182
: m_protocolVersion(pdata.m_protocolVersion)
8283
, m_guid(pdata.m_guid)
84+
, machine_id(pdata.machine_id)
8385
, m_VendorId(pdata.m_VendorId)
8486
, product_version(pdata.product_version)
8587
, m_domain_id(pdata.m_domain_id)
@@ -174,6 +176,13 @@ uint32_t ParticipantProxyData::get_serialized_size(
174176
// PID_NETWORK_CONFIGURATION_SET
175177
ret_val += 4 + PARAMETER_NETWORKCONFIGSET_LENGTH;
176178

179+
if (machine_id.size() > 0)
180+
{
181+
// PID_MACHINE_ID
182+
ret_val +=
183+
fastdds::dds::ParameterSerializer<Parameter_t>::cdr_serialized_size(machine_id);
184+
}
185+
177186
// PID_METATRAFFIC_MULTICAST_LOCATOR
178187
ret_val +=
179188
static_cast<uint32_t>((4 + PARAMETER_LOCATOR_LENGTH) *
@@ -322,6 +331,14 @@ bool ParticipantProxyData::writeToCDRMessage(
322331
return false;
323332
}
324333
}
334+
if (machine_id.size() > 0)
335+
{
336+
ParameterString_t p(fastdds::dds::PID_MACHINE_ID, 0, machine_id);
337+
if (!fastdds::dds::ParameterSerializer<ParameterString_t>::add_to_cdr_message(p, msg))
338+
{
339+
return false;
340+
}
341+
}
325342
for (const Locator_t& it : metatraffic_locators.multicast)
326343
{
327344
ParameterLocator_t p(fastdds::dds::PID_METATRAFFIC_MULTICAST_LOCATOR, PARAMETER_LOCATOR_LENGTH,
@@ -589,6 +606,28 @@ bool ParticipantProxyData::readFromCDRMessage(
589606
m_networkConfiguration = p.netconfigSet;
590607
break;
591608
}
609+
case fastdds::dds::PID_MACHINE_ID:
610+
{
611+
// Ignore custom PID when coming from other vendors
612+
if (c_VendorId_eProsima != m_VendorId)
613+
{
614+
EPROSIMA_LOG_INFO(
615+
RTPS_PROXY_DATA,
616+
"Ignoring custom PID" << pid << " from vendor " << source_vendor_id);
617+
return true;
618+
}
619+
620+
ParameterString_t p(pid, plength);
621+
if (!fastdds::dds::ParameterSerializer<ParameterString_t>::read_from_cdr_message(
622+
p, msg,
623+
plength))
624+
{
625+
return false;
626+
}
627+
628+
machine_id = p.getName();
629+
break;
630+
}
592631
case fastdds::dds::PID_METATRAFFIC_MULTICAST_LOCATOR:
593632
{
594633
ParameterLocator_t p(pid, plength);
@@ -608,7 +647,7 @@ bool ParticipantProxyData::readFromCDRMessage(
608647
Locator_t temp_locator;
609648
if (network.transform_remote_locator(
610649
p.locator, temp_locator, m_networkConfiguration,
611-
m_guid.is_from_this_host()))
650+
is_from_this_host()))
612651
{
613652
ProxyDataFilters::filter_locators(
614653
network,
@@ -638,7 +677,7 @@ bool ParticipantProxyData::readFromCDRMessage(
638677
Locator_t temp_locator;
639678
if (network.transform_remote_locator(
640679
p.locator, temp_locator, m_networkConfiguration,
641-
m_guid.is_from_this_host()))
680+
is_from_this_host()))
642681
{
643682
ProxyDataFilters::filter_locators(
644683
network,
@@ -668,7 +707,7 @@ bool ParticipantProxyData::readFromCDRMessage(
668707
Locator_t temp_locator;
669708
if (network.transform_remote_locator(
670709
p.locator, temp_locator, m_networkConfiguration,
671-
m_guid.is_from_this_host()))
710+
is_from_this_host()))
672711
{
673712
ProxyDataFilters::filter_locators(
674713
network,
@@ -698,7 +737,7 @@ bool ParticipantProxyData::readFromCDRMessage(
698737
Locator_t temp_locator;
699738
if (network.transform_remote_locator(
700739
p.locator, temp_locator, m_networkConfiguration,
701-
m_guid.is_from_this_host()))
740+
is_from_this_host()))
702741
{
703742
ProxyDataFilters::filter_locators(
704743
network,
@@ -854,10 +893,25 @@ bool ParticipantProxyData::readFromCDRMessage(
854893
}
855894
}
856895

896+
bool ParticipantProxyData::is_from_this_host() const
897+
{
898+
bool same_host = false;
899+
if (machine_id.size() > 0)
900+
{
901+
same_host = machine_id == SystemInfo::instance().machine_id();
902+
}
903+
else
904+
{
905+
same_host = m_guid.is_from_this_host();
906+
}
907+
return same_host;
908+
}
909+
857910
void ParticipantProxyData::clear()
858911
{
859912
m_protocolVersion = ProtocolVersion_t();
860913
m_guid = GUID_t();
914+
machine_id = "";
861915
//set_VendorId_Unknown(m_VendorId);
862916
m_VendorId = c_VendorId_Unknown;
863917
product_version = {};
@@ -891,6 +945,7 @@ void ParticipantProxyData::copy(
891945
{
892946
m_protocolVersion = pdata.m_protocolVersion;
893947
m_guid = pdata.m_guid;
948+
machine_id = pdata.machine_id;
894949
m_VendorId[0] = pdata.m_VendorId[0];
895950
m_VendorId[1] = pdata.m_VendorId[1];
896951
product_version = pdata.product_version;

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

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class ParticipantProxyData
7777
ProtocolVersion_t m_protocolVersion;
7878
//!GUID
7979
GUID_t m_guid;
80+
//!Machine ID
81+
fastcdr::string_255 machine_id;
8082
//!Vendor ID
8183
fastdds::rtps::VendorId_t m_VendorId;
8284
//! Product version
@@ -163,6 +165,13 @@ class ParticipantProxyData
163165
bool should_filter_locators,
164166
fastdds::rtps::VendorId_t source_vendor_id = c_VendorId_eProsima);
165167

168+
/**
169+
* Check if the host where the current process is running is the same as the one that sent the data.
170+
* It tries to use the machine_id. If it is not available, it will compare GUIDs.
171+
* @return True if the host is the same
172+
*/
173+
bool is_from_this_host() const;
174+
166175
//! Clear the data (restore to default state).
167176
void clear();
168177

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

+56-44
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
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>
29+
#include <utils/SystemInfo.hpp>
2830

2931
#include "ProxyDataFilters.hpp"
3032

@@ -647,11 +649,9 @@ bool ReaderProxyData::writeToCDRMessage(
647649

648650
bool ReaderProxyData::readFromCDRMessage(
649651
CDRMessage_t* msg,
650-
NetworkFactory& network,
651-
bool should_filter_locators,
652652
fastdds::rtps::VendorId_t source_vendor_id)
653653
{
654-
auto param_process = [this, &network, &should_filter_locators, source_vendor_id](
654+
auto param_process = [this, source_vendor_id](
655655
CDRMessage_t* msg, const ParameterId_t& pid, uint16_t plength)
656656
{
657657
VendorId_t vendor_id = source_vendor_id;
@@ -889,23 +889,7 @@ bool ReaderProxyData::readFromCDRMessage(
889889
return false;
890890
}
891891

892-
if (!should_filter_locators)
893-
{
894-
remote_locators_.add_unicast_locator(p.locator);
895-
}
896-
else
897-
{
898-
Locator_t temp_locator;
899-
if (network.transform_remote_locator(p.locator, temp_locator, m_networkConfiguration,
900-
m_guid.is_from_this_host()))
901-
{
902-
ProxyDataFilters::filter_locators(
903-
network,
904-
remote_locators_,
905-
temp_locator,
906-
true);
907-
}
908-
}
892+
remote_locators_.add_unicast_locator(p.locator);
909893
break;
910894
}
911895
case fastdds::dds::PID_MULTICAST_LOCATOR:
@@ -917,23 +901,7 @@ bool ReaderProxyData::readFromCDRMessage(
917901
return false;
918902
}
919903

920-
if (!should_filter_locators)
921-
{
922-
remote_locators_.add_multicast_locator(p.locator);
923-
}
924-
else
925-
{
926-
Locator_t temp_locator;
927-
if (network.transform_remote_locator(p.locator, temp_locator, m_networkConfiguration,
928-
m_guid.is_from_this_host()))
929-
{
930-
ProxyDataFilters::filter_locators(
931-
network,
932-
remote_locators_,
933-
temp_locator,
934-
false);
935-
}
936-
}
904+
remote_locators_.add_unicast_locator(p.locator);
937905
break;
938906
}
939907
case fastdds::dds::PID_EXPECTS_INLINE_QOS:
@@ -1149,6 +1117,47 @@ bool ReaderProxyData::readFromCDRMessage(
11491117
return false;
11501118
}
11511119

1120+
void ReaderProxyData::setup_locators(
1121+
const ReaderProxyData& rdata,
1122+
NetworkFactory& network,
1123+
const ParticipantProxyData& participant_data)
1124+
{
1125+
if (this == &rdata)
1126+
{
1127+
return;
1128+
}
1129+
1130+
bool from_this_host = participant_data.is_from_this_host();
1131+
1132+
if (rdata.has_locators())
1133+
{
1134+
// Get the transformed remote locators for the ReaderProxyData received
1135+
remote_locators_.unicast.clear();
1136+
remote_locators_.multicast.clear();
1137+
for (const Locator_t& locator : rdata.remote_locators_.unicast)
1138+
{
1139+
Locator_t temp_locator;
1140+
if (network.transform_remote_locator(locator, temp_locator, m_networkConfiguration, from_this_host))
1141+
{
1142+
ProxyDataFilters::filter_locators(network, remote_locators_, temp_locator, true);
1143+
}
1144+
}
1145+
for (const Locator_t& locator : rdata.remote_locators_.multicast)
1146+
{
1147+
Locator_t temp_locator;
1148+
if (network.transform_remote_locator(locator, temp_locator, m_networkConfiguration, from_this_host))
1149+
{
1150+
ProxyDataFilters::filter_locators(network, remote_locators_, temp_locator, false);
1151+
}
1152+
}
1153+
}
1154+
else
1155+
{
1156+
// Get the remote locators from the participant_data
1157+
set_remote_locators(participant_data.default_locators, network, true, from_this_host);
1158+
}
1159+
}
1160+
11521161
void ReaderProxyData::clear()
11531162
{
11541163
m_expectsInlineQos = false;
@@ -1284,12 +1293,13 @@ void ReaderProxyData::set_announced_unicast_locators(
12841293

12851294
void ReaderProxyData::set_remote_unicast_locators(
12861295
const LocatorList_t& locators,
1287-
const NetworkFactory& network)
1296+
const NetworkFactory& network,
1297+
bool from_this_host)
12881298
{
12891299
remote_locators_.unicast.clear();
12901300
for (const Locator_t& locator : locators)
12911301
{
1292-
if (network.is_locator_remote_or_allowed(locator, m_guid.is_from_this_host()))
1302+
if (network.is_locator_remote_or_allowed(locator, from_this_host))
12931303
{
12941304
remote_locators_.add_unicast_locator(locator);
12951305
}
@@ -1304,12 +1314,13 @@ void ReaderProxyData::add_multicast_locator(
13041314

13051315
void ReaderProxyData::set_multicast_locators(
13061316
const LocatorList_t& locators,
1307-
const NetworkFactory& network)
1317+
const NetworkFactory& network,
1318+
bool from_this_host)
13081319
{
13091320
remote_locators_.multicast.clear();
13101321
for (const Locator_t& locator : locators)
13111322
{
1312-
if (network.is_locator_remote_or_allowed(locator, m_guid.is_from_this_host()))
1323+
if (network.is_locator_remote_or_allowed(locator, from_this_host))
13131324
{
13141325
remote_locators_.add_multicast_locator(locator);
13151326
}
@@ -1325,14 +1336,15 @@ void ReaderProxyData::set_locators(
13251336
void ReaderProxyData::set_remote_locators(
13261337
const RemoteLocatorList& locators,
13271338
const NetworkFactory& network,
1328-
bool use_multicast_locators)
1339+
bool use_multicast_locators,
1340+
bool from_this_host)
13291341
{
13301342
remote_locators_.unicast.clear();
13311343
remote_locators_.multicast.clear();
13321344

13331345
for (const Locator_t& locator : locators.unicast)
13341346
{
1335-
if (network.is_locator_remote_or_allowed(locator, m_guid.is_from_this_host()))
1347+
if (network.is_locator_remote_or_allowed(locator, from_this_host))
13361348
{
13371349
remote_locators_.add_unicast_locator(locator);
13381350
}
@@ -1342,7 +1354,7 @@ void ReaderProxyData::set_remote_locators(
13421354
{
13431355
for (const Locator_t& locator : locators.multicast)
13441356
{
1345-
if (network.is_locator_remote_or_allowed(locator, m_guid.is_from_this_host()))
1357+
if (network.is_locator_remote_or_allowed(locator, from_this_host))
13461358
{
13471359
remote_locators_.add_multicast_locator(locator);
13481360
}

0 commit comments

Comments
 (0)