Browse Source

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

release/1.12
TSC21 4 years ago committed by Nuno Marques
parent
commit
084a992572
  1. 14
      msg/templates/urtps/Publisher.cpp.em
  2. 14
      msg/templates/urtps/Subscriber.cpp.em

14
msg/templates/urtps/Publisher.cpp.em

@ -109,11 +109,17 @@ bool @(topic)_Publisher::init(const std::string &ns) @@ -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>();
@ -126,16 +132,12 @@ bool @(topic)_Publisher::init(const std::string &ns) @@ -126,16 +132,12 @@ bool @(topic)_Publisher::init(const std::string &ns)
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]@
}
@[end if]@
mp_participant = Domain::createParticipant(PParam);

14
msg/templates/urtps/Subscriber.cpp.em

@ -115,11 +115,17 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable *t_send @@ -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>();
@ -132,16 +138,12 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable *t_send @@ -132,16 +138,12 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable *t_send
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]@
}
@[end if]@
mp_participant = Domain::createParticipant(PParam);

Loading…
Cancel
Save