mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
microRTPS: agent: only allow to whitelist the localhost when using FastDDS as the rmw
This commit is contained in:
@@ -109,11 +109,17 @@ bool @(topic)_Publisher::init(const std::string &ns)
|
|||||||
nodeName.append("@(topic)_publisher");
|
nodeName.append("@(topic)_publisher");
|
||||||
PParam.rtps.setName(nodeName.c_str());
|
PParam.rtps.setName(nodeName.c_str());
|
||||||
|
|
||||||
|
@[if ros2_distro]@
|
||||||
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use only
|
// 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
|
// the localhost network for data sharing. If FastRTPS/DDS >= 2.0 and
|
||||||
// RMW_IMPLEMENTATION is FastDDS then the Shared Memory transport is used
|
// RMW_IMPLEMENTATION is FastDDS then the Shared Memory transport is used
|
||||||
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
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
|
// Create a custom network UDPv4 transport descriptor
|
||||||
// to whitelist the localhost
|
// to whitelist the localhost
|
||||||
auto localhostUdpTransport = std::make_shared<UDPv4TransportDescriptor>();
|
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
|
// Add the descriptor as a custom user transport
|
||||||
PParam.rtps.userTransports.push_back(localhostUdpTransport);
|
PParam.rtps.userTransports.push_back(localhostUdpTransport);
|
||||||
|
|
||||||
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
@[ if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
||||||
const char* rmw_implementation = std::getenv("RMW_IMPLEMENTATION");
|
// Add shared memory transport when available
|
||||||
const char* ros_distro = std::getenv("RMW_IMPLEMENTATION");
|
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
|
||||||
if (((rmw_implementation && (strcmp(rmw_implementation, "rmw_fastrtps_cpp") == 0)) || (strcmp(rmw_implementation, "rmw_fastrtps_dynamic_cpp") == 0)) ||
|
PParam.rtps.userTransports.push_back(shmTransport);
|
||||||
(!rmw_implementation && strcmp(ros_distro, "foxy") == 0)) {
|
@[ end if]@
|
||||||
// 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);
|
mp_participant = Domain::createParticipant(PParam);
|
||||||
|
|
||||||
|
|||||||
@@ -115,11 +115,17 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable *t_send
|
|||||||
nodeName.append("@(topic)_subscriber");
|
nodeName.append("@(topic)_subscriber");
|
||||||
PParam.rtps.setName(nodeName.c_str());
|
PParam.rtps.setName(nodeName.c_str());
|
||||||
|
|
||||||
|
@[if ros2_distro]@
|
||||||
// Check if ROS_LOCALHOST_ONLY is set. This means that one wants to use only
|
// 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
|
// the localhost network for data sharing. If FastRTPS/DDS >= 2.0 and
|
||||||
// RMW_IMPLEMENTATION is FastDDS then the Shared Memory transport is used
|
// RMW_IMPLEMENTATION is FastDDS then the Shared Memory transport is used
|
||||||
const char* localhost_only = std::getenv("ROS_LOCALHOST_ONLY");
|
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
|
// Create a custom network UDPv4 transport descriptor
|
||||||
// to whitelist the localhost
|
// to whitelist the localhost
|
||||||
auto localhostUdpTransport = std::make_shared<UDPv4TransportDescriptor>();
|
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
|
// Add the descriptor as a custom user transport
|
||||||
PParam.rtps.userTransports.push_back(localhostUdpTransport);
|
PParam.rtps.userTransports.push_back(localhostUdpTransport);
|
||||||
|
|
||||||
@[if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
@[ if version.parse(fastrtps_version) >= version.parse('2.0')]@
|
||||||
const char* rmw_implementation = std::getenv("RMW_IMPLEMENTATION");
|
// Add shared memory transport when available
|
||||||
const char* ros_distro = std::getenv("RMW_IMPLEMENTATION");
|
auto shmTransport = std::make_shared<SharedMemTransportDescriptor>();
|
||||||
if (((rmw_implementation && (strcmp(rmw_implementation, "rmw_fastrtps_cpp") == 0)) || (strcmp(rmw_implementation, "rmw_fastrtps_dynamic_cpp") == 0)) ||
|
PParam.rtps.userTransports.push_back(shmTransport);
|
||||||
(!rmw_implementation && strcmp(ros_distro, "foxy") == 0)) {
|
@[ end if]@
|
||||||
// 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);
|
mp_participant = Domain::createParticipant(PParam);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user