microRTPS: agent: only allow to whitelist the localhost when using FastDDS as the rmw

This commit is contained in:
TSC21 2021-06-07 15:35:45 +02:00 committed by Nuno Marques
parent 79f7986715
commit 084a992572
2 changed files with 26 additions and 22 deletions

View File

@ -109,11 +109,17 @@ bool @(topic)_Publisher::init(const std::string &ns)
nodeName.append("@(topic)_publisher");
PParam.rtps.setName(nodeName.c_str());
@[if ros2_distro]@
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use only
// the localhost network for data sharing. If FastRTPS/DDS >= 2.0 and
// RMW_IMPLEMENTATION is FastDDS then the Shared Memory transport is used
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
if (localhost_only && strcmp(localhost_only, "1") == 0) {
const char* rmw_implementation = std::getenv("RMW_IMPLEMENTATION");
const char* ros_distro = std::getenv("ROS_DISTRO");
if (localhost_only && strcmp(localhost_only, "1") == 0
&& ((rmw_implementation && ((strcmp(rmw_implementation, "rmw_fastrtps_cpp") == 0)
|| (strcmp(rmw_implementation, "rmw_fastrtps_dynamic_cpp") == 0)))
|| (!rmw_implementation && ros_distro && strcmp(ros_distro, "foxy") == 0))) {
// Create a custom network UDPv4 transport descriptor
// to whitelist the localhost
auto localhostUdpTransport = std::make_shared<UDPv4TransportDescriptor>();
@ -125,17 +131,13 @@ bool @(topic)_Publisher::init(const std::string &ns)
// Add the descriptor as a custom user transport
PParam.rtps.userTransports.push_back(localhostUdpTransport);
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
const char* rmw_implementation = std::getenv("RMW_IMPLEMENTATION");
const char* ros_distro = std::getenv("RMW_IMPLEMENTATION");
if (((rmw_implementation && (strcmp(rmw_implementation, "rmw_fastrtps_cpp") == 0)) || (strcmp(rmw_implementation, "rmw_fastrtps_dynamic_cpp") == 0)) ||
(!rmw_implementation && strcmp(ros_distro, "foxy") == 0)) {
// Add shared memory transport when available
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
PParam.rtps.userTransports.push_back(shmTransport);
}
@[end if]@
@[ if version.parse(fastrtps_version) >= version.parse('2.0')]@
// Add shared memory transport when available
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
PParam.rtps.userTransports.push_back(shmTransport);
@[ end if]@
}
@[end if]@
mp_participant = Domain::createParticipant(PParam);

View File

@ -115,11 +115,17 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable *t_send
nodeName.append("@(topic)_subscriber");
PParam.rtps.setName(nodeName.c_str());
@[if ros2_distro]@
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use only
// the localhost network for data sharing. If FastRTPS/DDS >= 2.0 and
// RMW_IMPLEMENTATION is FastDDS then the Shared Memory transport is used
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
if (localhost_only && strcmp(localhost_only, "1") == 0) {
const char* rmw_implementation = std::getenv("RMW_IMPLEMENTATION");
const char* ros_distro = std::getenv("ROS_DISTRO");
if (localhost_only && strcmp(localhost_only, "1") == 0
&& ((rmw_implementation && ((strcmp(rmw_implementation, "rmw_fastrtps_cpp") == 0)
|| (strcmp(rmw_implementation, "rmw_fastrtps_dynamic_cpp") == 0)))
|| (!rmw_implementation && ros_distro && strcmp(ros_distro, "foxy") == 0))) {
// Create a custom network UDPv4 transport descriptor
// to whitelist the localhost
auto localhostUdpTransport = std::make_shared<UDPv4TransportDescriptor>();
@ -131,17 +137,13 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable *t_send
// Add the descriptor as a custom user transport
PParam.rtps.userTransports.push_back(localhostUdpTransport);
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
const char* rmw_implementation = std::getenv("RMW_IMPLEMENTATION");
const char* ros_distro = std::getenv("RMW_IMPLEMENTATION");
if (((rmw_implementation && (strcmp(rmw_implementation, "rmw_fastrtps_cpp") == 0)) || (strcmp(rmw_implementation, "rmw_fastrtps_dynamic_cpp") == 0)) ||
(!rmw_implementation && strcmp(ros_distro, "foxy") == 0)) {
// Add shared memory transport when available
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
PParam.rtps.userTransports.push_back(shmTransport);
}
@[end if]@
@[ if version.parse(fastrtps_version) >= version.parse('2.0')]@
// Add shared memory transport when available
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
PParam.rtps.userTransports.push_back(shmTransport);
@[ end if]@
}
@[end if]@
mp_participant = Domain::createParticipant(PParam);