diff --git a/rmw_fastrtps_cpp/src/rmw_node.cpp b/rmw_fastrtps_cpp/src/rmw_node.cpp index 74c6e2e07..5d7492d06 100644 --- a/rmw_fastrtps_cpp/src/rmw_node.cpp +++ b/rmw_fastrtps_cpp/src/rmw_node.cpp @@ -37,7 +37,8 @@ rmw_create_node( const char * name, const char * namespace_, size_t domain_id, - const rmw_node_security_options_t * security_options) + const rmw_node_security_options_t * security_options, + bool localhost_only) { RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, NULL); RMW_CHECK_TYPE_IDENTIFIERS_MATCH( @@ -47,7 +48,7 @@ rmw_create_node( // TODO(wjwwood): replace this with RMW_RET_INCORRECT_RMW_IMPLEMENTATION when refactored return NULL); return rmw_fastrtps_shared_cpp::__rmw_create_node( - eprosima_fastrtps_identifier, name, namespace_, domain_id, security_options); + eprosima_fastrtps_identifier, name, namespace_, domain_id, security_options, localhost_only); } rmw_ret_t diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_node.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_node.cpp index 5bf5072ec..09c6166e9 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_node.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_node.cpp @@ -37,7 +37,8 @@ rmw_create_node( const char * name, const char * namespace_, size_t domain_id, - const rmw_node_security_options_t * security_options) + const rmw_node_security_options_t * security_options, + bool localhost_only) { RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, NULL); RMW_CHECK_TYPE_IDENTIFIERS_MATCH( @@ -47,7 +48,7 @@ rmw_create_node( // TODO(wjwwood): replace this with RMW_RET_INCORRECT_RMW_IMPLEMENTATION when refactored return NULL); return rmw_fastrtps_shared_cpp::__rmw_create_node( - eprosima_fastrtps_identifier, name, namespace_, domain_id, security_options); + eprosima_fastrtps_identifier, name, namespace_, domain_id, security_options, localhost_only); } rmw_ret_t diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp index 1cd1b669b..7c01a6d08 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/rmw_common.hpp @@ -89,7 +89,8 @@ __rmw_create_node( const char * name, const char * namespace_, size_t domain_id, - const rmw_node_security_options_t * security_options); + const rmw_node_security_options_t * security_options, + bool localhost_only); RMW_FASTRTPS_SHARED_CPP_PUBLIC rmw_ret_t diff --git a/rmw_fastrtps_shared_cpp/src/rmw_node.cpp b/rmw_fastrtps_shared_cpp/src/rmw_node.cpp index 983039a32..6ff864883 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_node.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_node.cpp @@ -27,6 +27,7 @@ #include "fastrtps/config.h" #include "fastrtps/Domain.h" +#include "fastrtps/rtps/common/Locator.h" #include "fastrtps/participant/Participant.h" #include "fastrtps/attributes/ParticipantAttributes.h" #include "fastrtps/publisher/Publisher.h" @@ -36,6 +37,7 @@ #include "fastrtps/subscriber/SubscriberListener.h" #include "fastrtps/subscriber/SampleInfo.h" #include "fastrtps/attributes/SubscriberAttributes.h" +#include "fastrtps/utils/IPLocator.h" #include "fastrtps/rtps/RTPSDomain.h" @@ -48,6 +50,8 @@ #include "rmw_fastrtps_shared_cpp/rmw_common.hpp" using Domain = eprosima::fastrtps::Domain; +using IPLocator = eprosima::fastrtps::rtps::IPLocator; +using Locator_t = eprosima::fastrtps::rtps::Locator_t; using Participant = eprosima::fastrtps::Participant; using ParticipantAttributes = eprosima::fastrtps::ParticipantAttributes; using StatefulReader = eprosima::fastrtps::rtps::StatefulReader; @@ -216,7 +220,8 @@ __rmw_create_node( const char * name, const char * namespace_, size_t domain_id, - const rmw_node_security_options_t * security_options) + const rmw_node_security_options_t * security_options, + bool localhost_only) { if (!name) { RMW_SET_ERROR_MSG("name is null"); @@ -236,6 +241,16 @@ __rmw_create_node( // since the participant name is not part of the DDS spec participantAttrs.rtps.setName(name); + if (localhost_only) { + Locator_t local_network_interface_locator; + static const std::string local_ip_name("127.0.0.1"); + local_network_interface_locator.kind = 1; + local_network_interface_locator.port = 0; + IPLocator::setIPv4(local_network_interface_locator, local_ip_name); + participantAttrs.rtps.builtin.metatrafficUnicastLocatorList.push_back( + local_network_interface_locator); + participantAttrs.rtps.builtin.initialPeersList.push_back(local_network_interface_locator); + } bool leave_middleware_default_qos = false; const char * env_var = "RMW_FASTRTPS_USE_QOS_FROM_XML"; // Check if the configuration from XML has been enabled from