Skip to content

Commit 9186400

Browse files
AAlonclalancette
authored andcommitted
Consistent node naming (#158)
* Support for easy integration with ros2 security features by starting CLI nodes with a consistent prefix. * Removing unneeded comment * Making DirectNode visible (removing hidden node prefix) to have consistent node naming for ros2cli. * Start all CLI nodes as hidden. * Shortening the default CLI node name prefix from '_ros2cli_node' to '_ros2cli' * Importing HIDDEN_NODE_PREFIX from rclpy, renaming CLI_NODE_NAME_PREFIX -> NODE_NAME_PREFIX. * ros2node - Importing HIDDEN_NODE_PREFIX from rclpy * Linter fixes. Signed-off-by: Chris Lalancette <[email protected]>
1 parent 7a65e1e commit 9186400

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

ros2cli/ros2cli/node/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from rclpy.node import HIDDEN_NODE_PREFIX
15+
NODE_NAME_PREFIX = HIDDEN_NODE_PREFIX + 'ros2cli'

ros2cli/ros2cli/node/direct.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
import rclpy
1818

19-
# TODO(mikaelarguedas) revisit this once it's specified
20-
HIDDEN_NODE_PREFIX = '_'
21-
19+
from ros2cli.node import NODE_NAME_PREFIX
2220
DEFAULT_TIMEOUT = 0.5
2321

2422

@@ -35,7 +33,7 @@ def timer_callback():
3533

3634
node_name_suffix = getattr(
3735
args, 'node_name_suffix', '_%d' % os.getpid())
38-
self.node = rclpy.create_node(HIDDEN_NODE_PREFIX + 'ros2cli_node' + node_name_suffix)
36+
self.node = rclpy.create_node(NODE_NAME_PREFIX + node_name_suffix)
3937
timeout = getattr(args, 'spin_time', DEFAULT_TIMEOUT)
4038
timer = self.node.create_timer(timeout, timer_callback)
4139

ros2node/ros2node/api/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414

1515
from collections import namedtuple
1616

17+
from rclpy.node import HIDDEN_NODE_PREFIX
1718
from ros2cli.node.strategy import NodeStrategy
1819

19-
# TODO(mikaelarguedas) revisit this once it's specified
20-
HIDDEN_NODE_PREFIX = '_'
21-
2220
NodeName = namedtuple('NodeName', ('name', 'namespace', 'full_name'))
2321
TopicInfo = namedtuple('Topic', ('name', 'types'))
2422

ros2service/ros2service/verb/call.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import time
1717

1818
import rclpy
19+
from ros2cli.node import NODE_NAME_PREFIX
1920
from ros2service.api import ServiceNameCompleter
2021
from ros2service.api import ServiceTypeCompleter
2122
from ros2service.verb import VerbExtension
@@ -76,7 +77,7 @@ def requester(service_type, service_name, values, period):
7677

7778
rclpy.init()
7879

79-
node = rclpy.create_node('requester_%s_%s' % (package_name, srv_name))
80+
node = rclpy.create_node(NODE_NAME_PREFIX + '_requester_%s_%s' % (package_name, srv_name))
8081

8182
cli = node.create_client(srv_module, service_name)
8283

ros2topic/ros2topic/verb/pub.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import time
1616

1717
import rclpy
18+
from ros2cli.node import NODE_NAME_PREFIX
1819
from ros2topic.api import import_message_type
1920
from ros2topic.api import set_msg_fields
2021
from ros2topic.api import SetFieldError
@@ -77,7 +78,7 @@ def publisher(
7778
if not isinstance(values_dictionary, dict):
7879
return 'The passed value needs to be a dictionary in YAML format'
7980
if not node_name:
80-
node_name = 'publisher_%s' % (message_type.replace('/', '_'),)
81+
node_name = NODE_NAME_PREFIX + '_publisher_%s' % (message_type.replace('/', '_'), )
8182
rclpy.init()
8283

8384
node = rclpy.create_node(node_name)

0 commit comments

Comments
 (0)