Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[22056] Transform locators using new machine_id PID #5382

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8652e3a
Refs #22056: compute_machine_id() method
cferreiragonz Nov 4, 2024
f8a4473
Refs #22056: Add PID_HOST_ID in private header
cferreiragonz Nov 4, 2024
6f81660
Refs #22056: ParticipantProxyData
cferreiragonz Nov 4, 2024
8224525
Refs #22056: ReaderProxyData
cferreiragonz Nov 4, 2024
4d7c379
Refs #22056: WriterProxyData
cferreiragonz Nov 4, 2024
a68af8f
Refs #22056: Disable builtin transports in DS CLI
cferreiragonz Nov 4, 2024
73ecd36
Refs #22056: Add Serialization test
cferreiragonz Nov 4, 2024
82f7f00
Refs #22056: Add machine_id() getter test
cferreiragonz Nov 4, 2024
f2c9a0a
Refs #22056: Add PID_HOST_ID to ParameterTypes.hpp
cferreiragonz Nov 4, 2024
4eba658
Refs #22056: Uncrustify
cferreiragonz Nov 5, 2024
ce9dca0
Refs #22056: Add Host.cpp to avoid exporting Mac dependencies in .hpp
cferreiragonz Nov 5, 2024
30bb855
Refs #22056: Add Host.cpp to tests CMakeLists.txt
cferreiragonz Nov 5, 2024
4caaa1d
Refs #22056: Add localhost to channel_resources if local interface
cferreiragonz Nov 5, 2024
f95d1a6
Refs #22056: Support allowlist & rm comment
cferreiragonz Nov 6, 2024
6f96fae
Refs #22056: Only disable builtin_transports when UDP server is not i…
cferreiragonz Nov 6, 2024
23309ba
Refs #22056: Link ALL local interfaces to the same channel
cferreiragonz Nov 7, 2024
3b6a17f
Refs #22056: Avoid clearing same channel multiple times
cferreiragonz Nov 7, 2024
0fffe5a
Refs #22056: Tests CMakeLists.txt
cferreiragonz Nov 7, 2024
f59b0da
Refs #22056: Apply review suggestions
cferreiragonz Nov 12, 2024
18a3ca2
Refs #22056: Avoid sending machine_id in Data(r/w)
cferreiragonz Nov 12, 2024
d26642b
Refs #22056: Review - readFromCDRMessage
cferreiragonz Nov 12, 2024
59af586
Refs #22056: Review - setup_locators
cferreiragonz Nov 12, 2024
9466b31
Refs #22056: Review - Update tests
cferreiragonz Nov 12, 2024
b8a1aa8
Refs #22056: Review - change return type
cferreiragonz Nov 12, 2024
37f1ac7
Refs #22056: Review - Doxydoc & minor fixes
cferreiragonz Nov 12, 2024
a1cd60b
Refs #22056: Review - Return buffer & udp_server_initialized fix
cferreiragonz Nov 13, 2024
57ed4f4
Refs #22056: Fix Tests with new Channel behavior
cferreiragonz Nov 13, 2024
ee6dc53
Refs #22056: Remove initial peers in Security & Refuse bind_socket in…
cferreiragonz Nov 13, 2024
fa8f97d
Refs #22056: Review - Use map::insert and std::set in test
cferreiragonz Nov 14, 2024
217e9ae
Refs #22056: Update versions.md
cferreiragonz Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/fastdds/dds/core/policy/ParameterTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ enum ParameterId_t : uint16_t
/* eProsima Fast DDS extensions */
PID_PRODUCT_VERSION = 0x8000,
PID_PERSISTENCE_GUID = 0x8002,
PID_MACHINE_ID = 0x8003,
PID_DISABLE_POSITIVE_ACKS = 0x8005,
PID_DATASHARING = 0x8006,
PID_NETWORK_CONFIGURATION_SET = 0x8007,
Expand Down
9 changes: 9 additions & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ set(${PROJECT_NAME}_source_files
statistics/fastdds/domain/DomainParticipant.cpp
statistics/fastdds/publisher/qos/DataWriterQos.cpp
statistics/fastdds/subscriber/qos/DataReaderQos.cpp
utils/Host.cpp
utils/IPFinder.cpp
utils/IPLocator.cpp
utils/md5.cpp
Expand Down Expand Up @@ -507,6 +508,14 @@ target_link_libraries(${PROJECT_NAME}
eProsima_atomic
)

if (APPLE)
target_link_libraries(${PROJECT_NAME}
${PRIVACY}
"-framework CoreFoundation"
"-framework IOKit"
)
endif()

if(MSVC OR MSVC_IDE)
# On installed binaries use manifest to specify dependencies
if(INSTALLER_PLATFORM AND OPENSSL_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ bool TypeLookupManager::assign_remote_endpoints(

temp_writer_proxy_data_->guid().guidPrefix = pdata.m_guid.guidPrefix;
temp_writer_proxy_data_->persistence_guid().guidPrefix = pdata.m_guid.guidPrefix;
temp_writer_proxy_data_->set_remote_locators(pdata.metatraffic_locators, network, true);
temp_writer_proxy_data_->set_remote_locators(pdata.metatraffic_locators, network, true, pdata.is_from_this_host());
temp_writer_proxy_data_->topicKind(NO_KEY);
temp_writer_proxy_data_->m_qos.m_durability.kind = fastdds::dds::VOLATILE_DURABILITY_QOS;
temp_writer_proxy_data_->m_qos.m_reliability.kind = fastdds::dds::RELIABLE_RELIABILITY_QOS;

temp_reader_proxy_data_->clear();
temp_reader_proxy_data_->m_expectsInlineQos = false;
temp_reader_proxy_data_->guid().guidPrefix = pdata.m_guid.guidPrefix;
temp_reader_proxy_data_->set_remote_locators(pdata.metatraffic_locators, network, true);
temp_reader_proxy_data_->set_remote_locators(pdata.metatraffic_locators, network, true, pdata.is_from_this_host());
temp_reader_proxy_data_->topicKind(NO_KEY);
temp_reader_proxy_data_->m_qos.m_durability.kind = fastdds::dds::VOLATILE_DURABILITY_QOS;
temp_reader_proxy_data_->m_qos.m_reliability.kind = fastdds::dds::RELIABLE_RELIABILITY_QOS;
Expand Down
63 changes: 59 additions & 4 deletions src/cpp/rtps/builtin/data/ParticipantProxyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <rtps/resources/TimedEvent.h>
#include <rtps/transport/shared_mem/SHMLocator.hpp>
#include <utils/TimeConversion.hpp>
#include <utils/SystemInfo.hpp>

#include "ProxyDataFilters.hpp"
#include "ProxyHashTables.hpp"
Expand Down Expand Up @@ -80,6 +81,7 @@ ParticipantProxyData::ParticipantProxyData(
const ParticipantProxyData& pdata)
: m_protocolVersion(pdata.m_protocolVersion)
, m_guid(pdata.m_guid)
, machine_id(pdata.machine_id)
, m_VendorId(pdata.m_VendorId)
, product_version(pdata.product_version)
, m_domain_id(pdata.m_domain_id)
Expand Down Expand Up @@ -174,6 +176,13 @@ uint32_t ParticipantProxyData::get_serialized_size(
// PID_NETWORK_CONFIGURATION_SET
ret_val += 4 + PARAMETER_NETWORKCONFIGSET_LENGTH;

if (machine_id.size() > 0)
{
// PID_MACHINE_ID
ret_val +=
fastdds::dds::ParameterSerializer<Parameter_t>::cdr_serialized_size(machine_id);
}

// PID_METATRAFFIC_MULTICAST_LOCATOR
ret_val +=
static_cast<uint32_t>((4 + PARAMETER_LOCATOR_LENGTH) *
Expand Down Expand Up @@ -322,6 +331,14 @@ bool ParticipantProxyData::writeToCDRMessage(
return false;
}
}
if (machine_id.size() > 0)
{
ParameterString_t p(fastdds::dds::PID_MACHINE_ID, 0, machine_id);
if (!fastdds::dds::ParameterSerializer<ParameterString_t>::add_to_cdr_message(p, msg))
{
return false;
}
}
for (const Locator_t& it : metatraffic_locators.multicast)
{
ParameterLocator_t p(fastdds::dds::PID_METATRAFFIC_MULTICAST_LOCATOR, PARAMETER_LOCATOR_LENGTH,
Expand Down Expand Up @@ -589,6 +606,28 @@ bool ParticipantProxyData::readFromCDRMessage(
m_networkConfiguration = p.netconfigSet;
break;
}
case fastdds::dds::PID_MACHINE_ID:
{
// Ignore custom PID when coming from other vendors
if (c_VendorId_eProsima != m_VendorId)
{
EPROSIMA_LOG_INFO(
RTPS_PROXY_DATA,
"Ignoring custom PID" << pid << " from vendor " << source_vendor_id);
return true;
}

ParameterString_t p(pid, plength);
if (!fastdds::dds::ParameterSerializer<ParameterString_t>::read_from_cdr_message(
p, msg,
plength))
{
return false;
}

machine_id = p.getName();
break;
}
case fastdds::dds::PID_METATRAFFIC_MULTICAST_LOCATOR:
{
ParameterLocator_t p(pid, plength);
Expand All @@ -608,7 +647,7 @@ bool ParticipantProxyData::readFromCDRMessage(
Locator_t temp_locator;
if (network.transform_remote_locator(
p.locator, temp_locator, m_networkConfiguration,
m_guid.is_from_this_host()))
is_from_this_host()))
{
ProxyDataFilters::filter_locators(
network,
Expand Down Expand Up @@ -638,7 +677,7 @@ bool ParticipantProxyData::readFromCDRMessage(
Locator_t temp_locator;
if (network.transform_remote_locator(
p.locator, temp_locator, m_networkConfiguration,
m_guid.is_from_this_host()))
is_from_this_host()))
{
ProxyDataFilters::filter_locators(
network,
Expand Down Expand Up @@ -668,7 +707,7 @@ bool ParticipantProxyData::readFromCDRMessage(
Locator_t temp_locator;
if (network.transform_remote_locator(
p.locator, temp_locator, m_networkConfiguration,
m_guid.is_from_this_host()))
is_from_this_host()))
{
ProxyDataFilters::filter_locators(
network,
Expand Down Expand Up @@ -698,7 +737,7 @@ bool ParticipantProxyData::readFromCDRMessage(
Locator_t temp_locator;
if (network.transform_remote_locator(
p.locator, temp_locator, m_networkConfiguration,
m_guid.is_from_this_host()))
is_from_this_host()))
{
ProxyDataFilters::filter_locators(
network,
Expand Down Expand Up @@ -854,10 +893,25 @@ bool ParticipantProxyData::readFromCDRMessage(
}
}

bool ParticipantProxyData::is_from_this_host() const
{
bool same_host = false;
if (machine_id.size() > 0)
{
same_host = machine_id == SystemInfo::instance().machine_id();
}
else
{
same_host = m_guid.is_from_this_host();
}
return same_host;
}

void ParticipantProxyData::clear()
{
m_protocolVersion = ProtocolVersion_t();
m_guid = GUID_t();
machine_id = "";
//set_VendorId_Unknown(m_VendorId);
m_VendorId = c_VendorId_Unknown;
product_version = {};
Expand Down Expand Up @@ -891,6 +945,7 @@ void ParticipantProxyData::copy(
{
m_protocolVersion = pdata.m_protocolVersion;
m_guid = pdata.m_guid;
machine_id = pdata.machine_id;
m_VendorId[0] = pdata.m_VendorId[0];
m_VendorId[1] = pdata.m_VendorId[1];
product_version = pdata.product_version;
Expand Down
9 changes: 9 additions & 0 deletions src/cpp/rtps/builtin/data/ParticipantProxyData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class ParticipantProxyData
ProtocolVersion_t m_protocolVersion;
//!GUID
GUID_t m_guid;
//!Machine ID
fastcdr::string_255 machine_id;
//!Vendor ID
fastdds::rtps::VendorId_t m_VendorId;
//! Product version
Expand Down Expand Up @@ -163,6 +165,13 @@ class ParticipantProxyData
bool should_filter_locators,
fastdds::rtps::VendorId_t source_vendor_id = c_VendorId_eProsima);

/**
* Check if the host where the current process is running is the same as the one that sent the data.
* It tries to use the machine_id. If it is not available, it will compare GUIDs.
* @return True if the host is the same
*/
bool is_from_this_host() const;

//! Clear the data (restore to default state).
void clear();

Expand Down
100 changes: 56 additions & 44 deletions src/cpp/rtps/builtin/data/ReaderProxyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#include <fastdds/rtps/common/CDRMessage_t.hpp>
#include <fastdds/rtps/common/VendorId_t.hpp>

#include <rtps/builtin/data/ParticipantProxyData.hpp>
#include <rtps/network/NetworkFactory.hpp>
#include <utils/SystemInfo.hpp>

#include "ProxyDataFilters.hpp"

Expand Down Expand Up @@ -647,11 +649,9 @@ bool ReaderProxyData::writeToCDRMessage(

bool ReaderProxyData::readFromCDRMessage(
CDRMessage_t* msg,
NetworkFactory& network,
bool should_filter_locators,
fastdds::rtps::VendorId_t source_vendor_id)
{
auto param_process = [this, &network, &should_filter_locators, source_vendor_id](
auto param_process = [this, source_vendor_id](
CDRMessage_t* msg, const ParameterId_t& pid, uint16_t plength)
{
VendorId_t vendor_id = source_vendor_id;
Expand Down Expand Up @@ -889,23 +889,7 @@ bool ReaderProxyData::readFromCDRMessage(
return false;
}

if (!should_filter_locators)
MiguelCompany marked this conversation as resolved.
Show resolved Hide resolved
{
remote_locators_.add_unicast_locator(p.locator);
}
else
{
Locator_t temp_locator;
if (network.transform_remote_locator(p.locator, temp_locator, m_networkConfiguration,
m_guid.is_from_this_host()))
{
ProxyDataFilters::filter_locators(
network,
remote_locators_,
temp_locator,
true);
}
}
remote_locators_.add_unicast_locator(p.locator);
break;
}
case fastdds::dds::PID_MULTICAST_LOCATOR:
Expand All @@ -917,23 +901,7 @@ bool ReaderProxyData::readFromCDRMessage(
return false;
}

if (!should_filter_locators)
{
remote_locators_.add_multicast_locator(p.locator);
}
else
{
Locator_t temp_locator;
if (network.transform_remote_locator(p.locator, temp_locator, m_networkConfiguration,
m_guid.is_from_this_host()))
{
ProxyDataFilters::filter_locators(
network,
remote_locators_,
temp_locator,
false);
}
}
remote_locators_.add_unicast_locator(p.locator);
break;
}
case fastdds::dds::PID_EXPECTS_INLINE_QOS:
Expand Down Expand Up @@ -1149,6 +1117,47 @@ bool ReaderProxyData::readFromCDRMessage(
return false;
}

void ReaderProxyData::setup_locators(
const ReaderProxyData& rdata,
NetworkFactory& network,
const ParticipantProxyData& participant_data)
{
if (this == &rdata)
{
return;
}

bool from_this_host = participant_data.is_from_this_host();

if (rdata.has_locators())
{
// Get the transformed remote locators for the ReaderProxyData received
remote_locators_.unicast.clear();
remote_locators_.multicast.clear();
for (const Locator_t& locator : rdata.remote_locators_.unicast)
{
Locator_t temp_locator;
if (network.transform_remote_locator(locator, temp_locator, m_networkConfiguration, from_this_host))
{
ProxyDataFilters::filter_locators(network, remote_locators_, temp_locator, true);
}
}
for (const Locator_t& locator : rdata.remote_locators_.multicast)
{
Locator_t temp_locator;
if (network.transform_remote_locator(locator, temp_locator, m_networkConfiguration, from_this_host))
{
ProxyDataFilters::filter_locators(network, remote_locators_, temp_locator, false);
}
}
}
else
{
// Get the remote locators from the participant_data
set_remote_locators(participant_data.default_locators, network, true, from_this_host);
}
}

void ReaderProxyData::clear()
{
m_expectsInlineQos = false;
Expand Down Expand Up @@ -1284,12 +1293,13 @@ void ReaderProxyData::set_announced_unicast_locators(

void ReaderProxyData::set_remote_unicast_locators(
const LocatorList_t& locators,
const NetworkFactory& network)
const NetworkFactory& network,
bool from_this_host)
{
remote_locators_.unicast.clear();
for (const Locator_t& locator : locators)
{
if (network.is_locator_remote_or_allowed(locator, m_guid.is_from_this_host()))
if (network.is_locator_remote_or_allowed(locator, from_this_host))
{
remote_locators_.add_unicast_locator(locator);
}
Expand All @@ -1304,12 +1314,13 @@ void ReaderProxyData::add_multicast_locator(

void ReaderProxyData::set_multicast_locators(
const LocatorList_t& locators,
const NetworkFactory& network)
const NetworkFactory& network,
bool from_this_host)
{
remote_locators_.multicast.clear();
for (const Locator_t& locator : locators)
{
if (network.is_locator_remote_or_allowed(locator, m_guid.is_from_this_host()))
if (network.is_locator_remote_or_allowed(locator, from_this_host))
{
remote_locators_.add_multicast_locator(locator);
}
Expand All @@ -1325,14 +1336,15 @@ void ReaderProxyData::set_locators(
void ReaderProxyData::set_remote_locators(
const RemoteLocatorList& locators,
const NetworkFactory& network,
bool use_multicast_locators)
bool use_multicast_locators,
bool from_this_host)
{
remote_locators_.unicast.clear();
remote_locators_.multicast.clear();

for (const Locator_t& locator : locators.unicast)
{
if (network.is_locator_remote_or_allowed(locator, m_guid.is_from_this_host()))
if (network.is_locator_remote_or_allowed(locator, from_this_host))
{
remote_locators_.add_unicast_locator(locator);
}
Expand All @@ -1342,7 +1354,7 @@ void ReaderProxyData::set_remote_locators(
{
for (const Locator_t& locator : locators.multicast)
{
if (network.is_locator_remote_or_allowed(locator, m_guid.is_from_this_host()))
if (network.is_locator_remote_or_allowed(locator, from_this_host))
{
remote_locators_.add_multicast_locator(locator);
}
Expand Down
Loading
Loading