From 9725f917a67c37ceb52e543f035674b7339a89f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Mon, 29 Jul 2024 09:50:15 +0200 Subject: [PATCH] Removed deprecated localhost_only (#1169) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alejandro Hernández Cordero --- rcl/CMakeLists.txt | 1 - rcl/include/rcl/localhost.h | 48 ------------ rcl/src/rcl/init.c | 99 +++++++------------------ rcl/src/rcl/localhost.c | 52 ------------- rcl/src/rcl/node.c | 1 - rcl/test/CMakeLists.txt | 6 -- rcl/test/rcl/test_discovery_options.cpp | 23 ------ rcl/test/rcl/test_localhost.cpp | 41 ---------- 8 files changed, 28 insertions(+), 243 deletions(-) delete mode 100644 rcl/include/rcl/localhost.h delete mode 100644 rcl/src/rcl/localhost.c delete mode 100644 rcl/test/rcl/test_localhost.cpp diff --git a/rcl/CMakeLists.txt b/rcl/CMakeLists.txt index f32797648..98df0967a 100644 --- a/rcl/CMakeLists.txt +++ b/rcl/CMakeLists.txt @@ -53,7 +53,6 @@ set(${PROJECT_NAME}_sources src/rcl/init_options.c src/rcl/lexer.c src/rcl/lexer_lookahead.c - src/rcl/localhost.c src/rcl/logging_rosout.c src/rcl/logging.c src/rcl/log_level.c diff --git a/rcl/include/rcl/localhost.h b/rcl/include/rcl/localhost.h deleted file mode 100644 index 2c5123a59..000000000 --- a/rcl/include/rcl/localhost.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2019 Open Source Robotics Foundation, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/// @file - -#ifndef RCL__LOCALHOST_H_ -#define RCL__LOCALHOST_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "rcl/types.h" -#include "rcl/visibility_control.h" -#include "rmw/localhost.h" - -extern const char * const RCL_LOCALHOST_ENV_VAR; - -/// Determine if the user wants to communicate using loopback only. -/** - * Checks if localhost should be used for network communication based on environment. - * - * \param[out] localhost_only Must not be NULL. - * \return #RCL_RET_INVALID_ARGUMENT if an argument is invalid, or - * \return #RCL_RET_ERROR if an unexpected error happened, or - * \return #RCL_RET_OK. - */ -RCL_PUBLIC -rcl_ret_t -rcl_get_localhost_only(rmw_localhost_only_t * localhost_only); - -#ifdef __cplusplus -} -#endif - -#endif // RCL__LOCALHOST_H_ diff --git a/rcl/src/rcl/init.c b/rcl/src/rcl/init.c index ec05b2d62..f3998ee63 100644 --- a/rcl/src/rcl/init.c +++ b/rcl/src/rcl/init.c @@ -31,7 +31,6 @@ extern "C" #include "rcl/discovery_options.h" #include "rcl/domain_id.h" #include "rcl/error_handling.h" -#include "rcl/localhost.h" #include "rcl/logging.h" #include "rcl/security.h" #include "rcl/validate_enclave_name.h" @@ -154,85 +153,43 @@ rcl_init( } } - rmw_localhost_only_t * localhost_only = - &context->impl->init_options.impl->rmw_init_options.localhost_only; - if (RMW_LOCALHOST_ONLY_DEFAULT != *localhost_only) { - RCUTILS_LOG_WARN_NAMED( - ROS_PACKAGE_NAME, - "'localhost_only' init option is deprecated but still honored if it is enabled. " - "Use 'automatic_discovery_range' and 'static_peers' instead."); - } else { - // Get actual localhost_only value based on environment variable, if needed. - ret = rcl_get_localhost_only(localhost_only); - if (RCL_RET_OK != ret) { - fail_ret = ret; - goto fail; - } - if (RMW_LOCALHOST_ONLY_DEFAULT != *localhost_only) { - RCUTILS_LOG_WARN_NAMED( - ROS_PACKAGE_NAME, - "ROS_LOCALHOST_ONLY is deprecated but still honored if it is enabled. " - "Use ROS_AUTOMATIC_DISCOVERY_RANGE and ROS_STATIC_PEERS instead."); - } - } - const rmw_discovery_options_t original_discovery_options = options->impl->rmw_init_options.discovery_options; rmw_discovery_options_t * discovery_options = &context->impl->init_options.impl->rmw_init_options.discovery_options; - // this happens either rmw implementation forces or via environmental variable. - // localhost_only is deprecated but still honored to prevail discovery_options. - // see https://github.com/ros2/ros2_documentation/pull/3519#discussion_r1186541935 - // TODO(fujitatomoya): remove localhost_only completely after deprecation period. - if (*localhost_only == RMW_LOCALHOST_ONLY_ENABLED) { - RCUTILS_LOG_WARN_NAMED( - ROS_PACKAGE_NAME, - "'localhost_only' is enabled, " - "'automatic_discovery_range' and 'static_peers' will be ignored."); - discovery_options->automatic_discovery_range = RMW_AUTOMATIC_DISCOVERY_RANGE_LOCALHOST; - discovery_options->static_peers_count = 0; - } else { - if (*localhost_only == RMW_LOCALHOST_ONLY_DISABLED) { - RCUTILS_LOG_WARN_NAMED( - ROS_PACKAGE_NAME, - "'localhost_only' is disabled, " - "'automatic_discovery_range' and 'static_peers' will be used."); - } - - // Get actual discovery range option based on environment variable, if not given - // to original options passed to function - if ( // NOLINT - RMW_AUTOMATIC_DISCOVERY_RANGE_NOT_SET == original_discovery_options.automatic_discovery_range) - { - ret = rcl_get_automatic_discovery_range(discovery_options); - if (RCL_RET_OK != ret) { - fail_ret = ret; - goto fail; - } + // Get actual discovery range option based on environment variable, if not given + // to original options passed to function + if ( // NOLINT + RMW_AUTOMATIC_DISCOVERY_RANGE_NOT_SET == original_discovery_options.automatic_discovery_range) + { + ret = rcl_get_automatic_discovery_range(discovery_options); + if (RCL_RET_OK != ret) { + fail_ret = ret; + goto fail; } + } - if (0 == discovery_options->static_peers_count && - discovery_options->automatic_discovery_range != RMW_AUTOMATIC_DISCOVERY_RANGE_OFF) - { - // Get static peers. - // If off is set, it makes sense to not get any static peers. - ret = rcl_get_discovery_static_peers(discovery_options, &allocator); - if (RCL_RET_OK != ret) { - fail_ret = ret; - goto fail; - } + if (0 == discovery_options->static_peers_count && + discovery_options->automatic_discovery_range != RMW_AUTOMATIC_DISCOVERY_RANGE_OFF) + { + // Get static peers. + // If off is set, it makes sense to not get any static peers. + ret = rcl_get_discovery_static_peers(discovery_options, &allocator); + if (RCL_RET_OK != ret) { + fail_ret = ret; + goto fail; } + } - if (discovery_options->static_peers_count > 0 && - discovery_options->automatic_discovery_range == RMW_AUTOMATIC_DISCOVERY_RANGE_OFF) - { - RCUTILS_LOG_WARN_NAMED( - ROS_PACKAGE_NAME, - "Note: ROS_AUTOMATIC_DISCOVERY_RANGE is set to OFF, but " - "found static peers in ROS_STATIC_PEERS. " - "ROS_STATIC_PEERS will be ignored."); - } + if (discovery_options->static_peers_count > 0 && + discovery_options->automatic_discovery_range == RMW_AUTOMATIC_DISCOVERY_RANGE_OFF) + { + RCUTILS_LOG_WARN_NAMED( + ROS_PACKAGE_NAME, + "Note: ROS_AUTOMATIC_DISCOVERY_RANGE is set to OFF, but " + "found static peers in ROS_STATIC_PEERS. " + "ROS_STATIC_PEERS will be ignored."); } const char * discovery_range_string = diff --git a/rcl/src/rcl/localhost.c b/rcl/src/rcl/localhost.c deleted file mode 100644 index f3acef544..000000000 --- a/rcl/src/rcl/localhost.c +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2019 Open Source Robotics Foundation, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "rcl/localhost.h" - -#include -#include - -#include "rcutils/env.h" - -#include "rcl/error_handling.h" -#include "rcl/types.h" - -const char * const RCL_LOCALHOST_ENV_VAR = "ROS_LOCALHOST_ONLY"; - -rcl_ret_t -rcl_get_localhost_only(rmw_localhost_only_t * localhost_only) -{ - const char * ros_local_host_env_val = NULL; - const char * get_env_error_str = NULL; - - RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_INVALID_ARGUMENT); - RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_ERROR); - RCL_CHECK_ARGUMENT_FOR_NULL(localhost_only, RCL_RET_INVALID_ARGUMENT); - - get_env_error_str = rcutils_get_env(RCL_LOCALHOST_ENV_VAR, &ros_local_host_env_val); - if (NULL != get_env_error_str) { - RCL_SET_ERROR_MSG_WITH_FORMAT_STRING( - "Error getting env var '" RCUTILS_STRINGIFY(RCL_LOCALHOST_ENV_VAR) "': %s\n", - get_env_error_str); - return RCL_RET_ERROR; - } - if (ros_local_host_env_val == NULL || ros_local_host_env_val[0] == '\0') { - *localhost_only = RMW_LOCALHOST_ONLY_DEFAULT; - } else { - *localhost_only = - strncmp(ros_local_host_env_val, "1", 1) == 0 ? - RMW_LOCALHOST_ONLY_ENABLED : RMW_LOCALHOST_ONLY_DISABLED; - } - return RCL_RET_OK; -} diff --git a/rcl/src/rcl/node.c b/rcl/src/rcl/node.c index 998ce1ab6..f6ec50c1e 100644 --- a/rcl/src/rcl/node.c +++ b/rcl/src/rcl/node.c @@ -22,7 +22,6 @@ #include "rcl/arguments.h" #include "rcl/error_handling.h" #include "rcl/init_options.h" -#include "rcl/localhost.h" #include "rcl/logging.h" #include "rcl/logging_rosout.h" #include "rcl/node_type_cache.h" diff --git a/rcl/test/CMakeLists.txt b/rcl/test/CMakeLists.txt index 789044ff7..d8c9daa63 100644 --- a/rcl/test/CMakeLists.txt +++ b/rcl/test/CMakeLists.txt @@ -474,12 +474,6 @@ rcl_add_custom_gtest(test_domain_id ) ament_add_test_label(test_domain_id mimick) -rcl_add_custom_gtest(test_localhost - SRCS rcl/test_localhost.cpp - APPEND_LIBRARY_DIRS ${extra_lib_dirs} - LIBRARIES ${PROJECT_NAME} -) - rcl_add_custom_gtest(test_logging SRCS rcl/test_logging.cpp APPEND_LIBRARY_DIRS ${extra_lib_dirs} diff --git a/rcl/test/rcl/test_discovery_options.cpp b/rcl/test/rcl/test_discovery_options.cpp index 1e2a806e4..f157e8ecb 100644 --- a/rcl/test/rcl/test_discovery_options.cpp +++ b/rcl/test/rcl/test_discovery_options.cpp @@ -293,29 +293,6 @@ TEST(TestDiscoveryInfo, test_with_localhost_only) { } { - // Only ROS_LOCALHOST_ONLY is enabled - ASSERT_TRUE(rcutils_set_env("ROS_LOCALHOST_ONLY", "1")); - check_discovery(RMW_AUTOMATIC_DISCOVERY_RANGE_LOCALHOST, 0); - } - - { - // ROS_LOCALHOST_ONLY is enabled and prevails over SUBNET. - ASSERT_TRUE(rcutils_set_env("ROS_LOCALHOST_ONLY", "1")); - ASSERT_TRUE(rcutils_set_env("ROS_AUTOMATIC_DISCOVERY_RANGE", "SUBNET")); - ASSERT_TRUE(rcutils_set_env("ROS_STATIC_PEERS", "192.168.0.1;remote.com")); - check_discovery(RMW_AUTOMATIC_DISCOVERY_RANGE_LOCALHOST, 0); - } - - { - // ROS_LOCALHOST_ONLY is enabled and prevails over OFF. - ASSERT_TRUE(rcutils_set_env("ROS_LOCALHOST_ONLY", "1")); - ASSERT_TRUE(rcutils_set_env("ROS_AUTOMATIC_DISCOVERY_RANGE", "OFF")); - check_discovery(RMW_AUTOMATIC_DISCOVERY_RANGE_LOCALHOST, 0); - } - - { - // ROS_LOCALHOST_ONLY is disabled, falls down to use discovery option. - ASSERT_TRUE(rcutils_set_env("ROS_LOCALHOST_ONLY", "0")); ASSERT_TRUE(rcutils_set_env("ROS_AUTOMATIC_DISCOVERY_RANGE", "SUBNET")); ASSERT_TRUE(rcutils_set_env("ROS_STATIC_PEERS", "192.168.0.1;remote.com")); check_discovery(RMW_AUTOMATIC_DISCOVERY_RANGE_SUBNET, 2); diff --git a/rcl/test/rcl/test_localhost.cpp b/rcl/test/rcl/test_localhost.cpp deleted file mode 100644 index e781b759e..000000000 --- a/rcl/test/rcl/test_localhost.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2020 Open Source Robotics Foundation, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#include "rcl/rcl.h" -#include "rcl/localhost.h" -#include "rmw/localhost.h" -#include "rcutils/env.h" - -TEST(TestLocalhost, test_get_localhost_only) { - ASSERT_TRUE(rcutils_set_env("ROS_LOCALHOST_ONLY", "0")); - rmw_localhost_only_t localhost_var; - EXPECT_EQ(RCL_RET_OK, rcl_get_localhost_only(&localhost_var)); - EXPECT_EQ(RMW_LOCALHOST_ONLY_DISABLED, localhost_var); - - ASSERT_TRUE(rcutils_set_env("ROS_LOCALHOST_ONLY", "1")); - EXPECT_EQ(RCL_RET_OK, rcl_get_localhost_only(&localhost_var)); - EXPECT_EQ(RMW_LOCALHOST_ONLY_ENABLED, localhost_var); - - ASSERT_TRUE(rcutils_set_env("ROS_LOCALHOST_ONLY", "2")); - EXPECT_EQ(RCL_RET_OK, rcl_get_localhost_only(&localhost_var)); - EXPECT_EQ(RMW_LOCALHOST_ONLY_DISABLED, localhost_var); - - ASSERT_TRUE(rcutils_set_env("ROS_LOCALHOST_ONLY", "Unexpected")); - EXPECT_EQ(RCL_RET_OK, rcl_get_localhost_only(&localhost_var)); - EXPECT_EQ(RMW_LOCALHOST_ONLY_DISABLED, localhost_var); - - EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_get_localhost_only(nullptr)); -}