Skip to content

Commit 2f954d7

Browse files
authored
Use one participant per context API changes (#189)
Signed-off-by: ivanpauno <[email protected]>
1 parent b3bf0fd commit 2f954d7

File tree

11 files changed

+280
-70
lines changed

11 files changed

+280
-70
lines changed

rmw/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ set(rmw_sources
3232
"src/init_options.c"
3333
"src/loaned_message_sequence.c"
3434
"src/names_and_types.c"
35-
"src/node_security_options.c"
3635
"src/publisher_options.c"
3736
"src/sanity_checks.c"
37+
"src/security_options.c"
3838
"src/subscription_options.c"
3939
"src/topic_endpoint_info_array.c"
4040
"src/topic_endpoint_info.c"
Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 Open Source Robotics Foundation, Inc.
1+
// Copyright 2019 Open Source Robotics Foundation, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,26 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef RMW__NODE_SECURITY_OPTIONS_H_
16-
#define RMW__NODE_SECURITY_OPTIONS_H_
15+
#ifndef RMW__DOMAIN_ID_H_
16+
#define RMW__DOMAIN_ID_H_
1717

18-
#ifdef __cplusplus
19-
extern "C"
20-
{
21-
#endif
18+
/// Default domain id.
19+
#define RMW_DEFAULT_DOMAIN_ID SIZE_MAX
2220

23-
#include "rmw/types.h"
24-
25-
RMW_PUBLIC
26-
rmw_node_security_options_t
27-
rmw_get_zero_initialized_node_security_options();
28-
29-
RMW_PUBLIC
30-
rmw_node_security_options_t
31-
rmw_get_default_node_security_options();
32-
33-
#ifdef __cplusplus
34-
}
35-
#endif
36-
37-
#endif // RMW__NODE_SECURITY_OPTIONS_H_
21+
#endif // RMW__DOMAIN_ID_H_

rmw/include/rmw/init.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ typedef struct RMW_PUBLIC_TYPE rmw_context_t
4040
uint64_t instance_id;
4141
/// Implementation identifier, used to ensure two different implementations are not being mixed.
4242
const char * implementation_identifier;
43+
/// Options used to initialize the context.
44+
rmw_init_options_t options;
4345
/// Implementation defined context information.
4446
/** May be NULL if there is no implementation defined context information. */
4547
rmw_context_impl_t * impl;

rmw/include/rmw/init_options.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ extern "C"
2323
#include <stdint.h>
2424

2525
#include "rcutils/allocator.h"
26+
#include "rmw/domain_id.h"
27+
#include "rmw/localhost.h"
2628
#include "rmw/macros.h"
2729
#include "rmw/ret_types.h"
30+
#include "rmw/security_options.h"
2831
#include "rmw/visibility_control.h"
2932

3033
/// Implementation defined options structure used during rmw_init().
@@ -45,6 +48,15 @@ typedef struct RMW_PUBLIC_TYPE rmw_init_options_t
4548
uint64_t instance_id;
4649
/// Implementation identifier, used to ensure two different implementations are not being mixed.
4750
const char * implementation_identifier;
51+
/// ROS domain id
52+
size_t domain_id;
53+
/// Security options
54+
rmw_security_options_t security_options;
55+
/// Enable localhost only
56+
rmw_localhost_only_t localhost_only;
57+
/// Security context
58+
char * security_context;
59+
4860
// TODO(wjwwood): replace with rmw_allocator_t when that refactor happens
4961
/// Allocator used during internal allocation of init options, if needed.
5062
rcutils_allocator_t allocator;

rmw/include/rmw/localhost.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2019 Open Source Robotics Foundation, Inc.
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+
15+
#ifndef RMW__LOCALHOST_H_
16+
#define RMW__LOCALHOST_H_
17+
18+
#include "rmw/visibility_control.h"
19+
20+
#ifdef __cplusplus
21+
extern "C"
22+
{
23+
#endif
24+
25+
/// Used to specify if the context can only communicate through localhost.
26+
typedef enum RMW_PUBLIC_TYPE rmw_localhost_only_t
27+
{
28+
/// Uses ROS_LOCALHOST_ONLY environment variable.
29+
RMW_LOCALHOST_ONLY_DEFAULT = 0,
30+
/// Forces using only localhost.
31+
RMW_LOCALHOST_ONLY_ENABLED = 1,
32+
/// Forces disabling localhost only.
33+
RMW_LOCALHOST_ONLY_DISABLED = 2,
34+
} rmw_localhost_only_t;
35+
36+
#ifdef __cplusplus
37+
}
38+
#endif
39+
40+
#endif // RMW__LOCALHOST_H_

rmw/include/rmw/rmw.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ rmw_create_node(
173173
const char * name,
174174
const char * namespace_,
175175
size_t domain_id,
176-
const rmw_node_security_options_t * security_options,
177176
bool localhost_only);
178177

179178
/// Finalize a given node handle, reclaim the resources, and deallocate the node handle.
@@ -1049,6 +1048,26 @@ rmw_get_node_names(
10491048
rcutils_string_array_t * node_names,
10501049
rcutils_string_array_t * node_namespaces);
10511050

1051+
/// Return a list of node name and namespaces discovered via a node with its security context.
1052+
/**
1053+
* Similar to \ref rmw_get_node_names, but it also provides the security context name.
1054+
*
1055+
* \param[in] node the handle to the node being used to query the ROS graph
1056+
* \param[out] node_names a list of discovered node names
1057+
* \param[out] node_namespaces a list of discovered node namespaces
1058+
* \param[out] security_contexts list of discovered nodes' security context names
1059+
* \return `RMW_RET_OK` if node the query was made successfully, or
1060+
* \return `RMW_RET_ERROR` if an unspecified error occurs.
1061+
*/
1062+
RMW_PUBLIC
1063+
RMW_WARN_UNUSED
1064+
rmw_ret_t
1065+
rmw_get_node_names_with_security_contexts(
1066+
const rmw_node_t * node,
1067+
rcutils_string_array_t * node_names,
1068+
rcutils_string_array_t * node_namespaces,
1069+
rcutils_string_array_t * security_contexts);
1070+
10521071
RMW_PUBLIC
10531072
RMW_WARN_UNUSED
10541073
rmw_ret_t

rmw/include/rmw/security_options.h

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2020 Open Source Robotics Foundation, Inc.
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+
15+
#ifndef RMW__SECURITY_OPTIONS_H_
16+
#define RMW__SECURITY_OPTIONS_H_
17+
18+
#ifdef __cplusplus
19+
extern "C"
20+
{
21+
#endif
22+
23+
#include <stdbool.h>
24+
25+
#include "rcutils/allocator.h"
26+
27+
#include "rmw/ret_types.h"
28+
#include "rmw/visibility_control.h"
29+
30+
typedef enum RMW_PUBLIC_TYPE rmw_security_enforcement_policy_t
31+
{
32+
RMW_SECURITY_ENFORCEMENT_PERMISSIVE,
33+
RMW_SECURITY_ENFORCEMENT_ENFORCE,
34+
} rmw_security_enforcement_policy_t;
35+
36+
typedef struct RMW_PUBLIC_TYPE rmw_security_options_t
37+
{
38+
enum rmw_security_enforcement_policy_t enforce_security;
39+
char * security_root_path;
40+
} rmw_security_options_t;
41+
42+
/// Get zero initialized security options.
43+
RMW_PUBLIC
44+
rmw_security_options_t
45+
rmw_get_zero_initialized_security_options();
46+
47+
/// Get default initialized security options.
48+
RMW_PUBLIC
49+
rmw_security_options_t
50+
rmw_get_default_security_options();
51+
52+
/// Copy the given security options.
53+
/**
54+
* \param src security options to be copied.
55+
* \param allocator allocator used when copying data to the new security options.
56+
* \param dst security options to be set.
57+
* \returns RMW_RET_BAD_ALLOC, or
58+
* \returns RMW_RET_OK
59+
*/
60+
RMW_PUBLIC
61+
rmw_ret_t
62+
rmw_security_options_copy(
63+
const rmw_security_options_t * src,
64+
const rcutils_allocator_t * allocator,
65+
rmw_security_options_t * dst);
66+
67+
/// Set the security root path for the given security options.
68+
/**
69+
* The provided `security_root_path` will be copied into allocated memory.
70+
*
71+
* \param security_root_path path to be set.
72+
* \param allocator allocator used to allocate the new path.
73+
* \param security_options security options to be set.
74+
* \returns RMW_RET_BAD_ALLOC, or
75+
* \returns RMW_RET_OK
76+
*/
77+
rmw_ret_t
78+
rmw_security_options_set_root_path(
79+
const char * security_root_path,
80+
const rcutils_allocator_t * allocator,
81+
rmw_security_options_t * security_options);
82+
83+
/// Finalize the given security_options.
84+
/**
85+
* \param security_options security options to be finalized.
86+
* \param allocator allocator used to deallocate the root path.
87+
* \returns RMW_RET_ERROR, or
88+
* \returns RMW_RET_OK
89+
*/
90+
RMW_PUBLIC
91+
rmw_ret_t
92+
rmw_security_options_fini(
93+
rmw_security_options_t * security_options,
94+
const rcutils_allocator_t * allocator);
95+
96+
#ifdef __cplusplus
97+
}
98+
#endif
99+
100+
#endif // RMW__SECURITY_OPTIONS_H_

rmw/include/rmw/types.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ extern "C"
2828
#include <rcutils/logging.h>
2929

3030
#include "rmw/init.h"
31+
#include "rmw/init_options.h"
3132
#include "rmw/loaned_message_sequence.h"
3233
#include "rmw/ret_types.h"
34+
#include "rmw/security_options.h"
3335
#include "rmw/serialized_message.h"
3436
#include "rmw/visibility_control.h"
3537

3638
// 24 bytes is the most memory needed to represent the GID by any current
3739
// implementation. It may need to be increased in the future.
38-
#define RMW_GID_STORAGE_SIZE 24
40+
#define RMW_GID_STORAGE_SIZE 24u
3941

4042
typedef struct RMW_PUBLIC_TYPE rmw_node_t
4143
{
@@ -46,7 +48,7 @@ typedef struct RMW_PUBLIC_TYPE rmw_node_t
4648
rmw_context_t * context;
4749
} rmw_node_t;
4850

49-
typedef enum RMW_PUBLIC_TYPE
51+
typedef enum RMW_PUBLIC_TYPE rmw_endpoint_type_t
5052
{
5153
RMW_ENDPOINT_INVALID = 0,
5254
RMW_ENDPOINT_PUBLISHER,
@@ -253,18 +255,6 @@ typedef struct RMW_PUBLIC_TYPE rmw_time_t
253255
uint64_t nsec;
254256
} rmw_time_t;
255257

256-
enum RMW_PUBLIC_TYPE rmw_security_enforcement_policy_t
257-
{
258-
RMW_SECURITY_ENFORCEMENT_PERMISSIVE,
259-
RMW_SECURITY_ENFORCEMENT_ENFORCE,
260-
};
261-
262-
typedef struct RMW_PUBLIC_TYPE rmw_node_security_options_t
263-
{
264-
enum rmw_security_enforcement_policy_t enforce_security;
265-
const char * security_root_path;
266-
} rmw_node_security_options_t;
267-
268258
enum RMW_PUBLIC_TYPE rmw_qos_reliability_policy_t
269259
{
270260
RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT,

rmw/src/init_options.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <stddef.h>
1616

1717
#include "rmw/init_options.h"
18+
#include "rmw/localhost.h"
1819

1920
#ifdef __cplusplus
2021
extern "C"
@@ -25,9 +26,13 @@ rmw_init_options_t
2526
rmw_get_zero_initialized_init_options(void)
2627
{
2728
return (const rmw_init_options_t) {
28-
.instance_id = 0,
29+
.domain_id = RMW_DEFAULT_DOMAIN_ID,
30+
.localhost_only = RMW_LOCALHOST_ONLY_DEFAULT,
2931
.implementation_identifier = NULL,
3032
.impl = NULL,
33+
.instance_id = 0,
34+
.security_context = NULL,
35+
.security_options = rmw_get_default_security_options(),
3136
}; // NOLINT(readability/braces): false positive
3237
}
3338

rmw/src/node_security_options.c

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)