Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to one participant per context #189

Merged
merged 23 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e3e034c
Switch to one participant per context.
ivanpauno Sep 23, 2019
2d8f8d6
Reorganize headers. Correct get_default_init_options functions
ivanpauno Nov 26, 2019
1a741a6
Addressed per review comments
ivanpauno Dec 13, 2019
cd1b326
Correct rmw_get_zero_initialized_init_options
ivanpauno Dec 18, 2019
ee0b354
Store init options in context
ivanpauno Jan 22, 2020
52c5a4c
Add rmw_security_options_fini and setter for secure_root
ivanpauno Jan 22, 2020
a90c367
Add context name and namespace
ivanpauno Jan 24, 2020
df2fee1
Correct rebasing error
ivanpauno Jan 28, 2020
bcffc6e
Use const rcutils_allocator_t *
ivanpauno Feb 4, 2020
9dbd91c
Delete duplicated source file from CMakeLists.txt
ivanpauno Feb 4, 2020
ad17a56
Improve documentation in security_options.h
ivanpauno Feb 4, 2020
46bff30
Modify localhost_only default value
ivanpauno Feb 17, 2020
9f10c0b
Address peer review comments
ivanpauno Feb 28, 2020
73d4f1f
Improve error handling in rmw_security_options_set_root_path
ivanpauno Feb 28, 2020
4f74f6e
Delete const qualifier
ivanpauno Feb 28, 2020
d6a9a46
Latest update after discussion about supporting sros2
ivanpauno Mar 12, 2020
ea3648c
Delete unused function
ivanpauno Mar 13, 2020
27dcc25
Naming: replace context_name with security_context
ivanpauno Mar 17, 2020
54e0a68
Fix linkage problem
ivanpauno Mar 23, 2020
49613b2
Fix build problem on Windows
ivanpauno Mar 24, 2020
3a2b9ef
More windows build errors
ivanpauno Mar 24, 2020
4747320
Address peer review comments
ivanpauno Mar 26, 2020
cbb5fc0
Address peer review comment
ivanpauno Mar 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rmw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ set(rmw_sources
"src/init_options.c"
"src/loaned_message_sequence.c"
"src/names_and_types.c"
"src/node_security_options.c"
"src/publisher_options.c"
"src/sanity_checks.c"
"src/security_options.c"
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
"src/subscription_options.c"
"src/topic_endpoint_info_array.c"
"src/topic_endpoint_info.c"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 Open Source Robotics Foundation, Inc.
// 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.
Expand All @@ -12,26 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RMW__NODE_SECURITY_OPTIONS_H_
#define RMW__NODE_SECURITY_OPTIONS_H_
#ifndef RMW__DOMAIN_ID_H_
#define RMW__DOMAIN_ID_H_

#ifdef __cplusplus
extern "C"
{
#endif
/// Default domain id.
#define RMW_DEFAULT_DOMAIN_ID SIZE_MAX

#include "rmw/types.h"

RMW_PUBLIC
rmw_node_security_options_t
rmw_get_zero_initialized_node_security_options();

RMW_PUBLIC
rmw_node_security_options_t
rmw_get_default_node_security_options();

#ifdef __cplusplus
}
#endif

#endif // RMW__NODE_SECURITY_OPTIONS_H_
#endif // RMW__DOMAIN_ID_H_
2 changes: 2 additions & 0 deletions rmw/include/rmw/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ typedef struct RMW_PUBLIC_TYPE rmw_context_t
uint64_t instance_id;
/// Implementation identifier, used to ensure two different implementations are not being mixed.
const char * implementation_identifier;
/// Options used to initialize the context.
rmw_init_options_t options;
/// Implementation defined context information.
/** May be NULL if there is no implementation defined context information. */
rmw_context_impl_t * impl;
Expand Down
12 changes: 12 additions & 0 deletions rmw/include/rmw/init_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ extern "C"
#include <stdint.h>

#include "rcutils/allocator.h"
#include "rmw/domain_id.h"
#include "rmw/localhost.h"
#include "rmw/macros.h"
#include "rmw/ret_types.h"
#include "rmw/security_options.h"
#include "rmw/visibility_control.h"

/// Implementation defined options structure used during rmw_init().
Expand All @@ -45,6 +48,15 @@ typedef struct RMW_PUBLIC_TYPE rmw_init_options_t
uint64_t instance_id;
/// Implementation identifier, used to ensure two different implementations are not being mixed.
const char * implementation_identifier;
/// ROS domain id
size_t domain_id;
/// Security options
rmw_security_options_t security_options;
/// Enable localhost only
rmw_localhost_only_t localhost_only;
/// Security context
char * security_context;

// TODO(wjwwood): replace with rmw_allocator_t when that refactor happens
/// Allocator used during internal allocation of init options, if needed.
rcutils_allocator_t allocator;
Expand Down
40 changes: 40 additions & 0 deletions rmw/include/rmw/localhost.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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.

#ifndef RMW__LOCALHOST_H_
#define RMW__LOCALHOST_H_

#include "rmw/visibility_control.h"

#ifdef __cplusplus
extern "C"
{
#endif

/// Used to specify if the context can only communicate through localhost.
typedef enum RMW_PUBLIC_TYPE rmw_localhost_only_t
{
/// Uses ROS_LOCALHOST_ONLY environment variable.
RMW_LOCALHOST_ONLY_DEFAULT = 0,
/// Forces using only localhost.
RMW_LOCALHOST_ONLY_ENABLED = 1,
/// Forces disabling localhost only.
RMW_LOCALHOST_ONLY_DISABLED = 2,
} rmw_localhost_only_t;

#ifdef __cplusplus
}
#endif

#endif // RMW__LOCALHOST_H_
21 changes: 20 additions & 1 deletion rmw/include/rmw/rmw.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ rmw_create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options,
bool localhost_only);

/// Finalize a given node handle, reclaim the resources, and deallocate the node handle.
Expand Down Expand Up @@ -1044,6 +1043,26 @@ rmw_get_node_names(
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces);

/// Return a list of node name and namespaces discovered via a node with its security context.
/**
* Similar to \ref rmw_get_node_names, but it also provides the security context name.
*
* \param[in] node the handle to the node being used to query the ROS graph
* \param[out] node_names a list of discovered node names
* \param[out] node_namespaces a list of discovered node namespaces
* \param[out] security_contexts list of discovered nodes' security context names
* \return `RMW_RET_OK` if node the query was made successfully, or
* \return `RMW_RET_ERROR` if an unspecified error occurs.
*/
RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
rmw_get_node_names_with_security_contexts(
const rmw_node_t * node,
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces,
rcutils_string_array_t * security_contexts);

RMW_PUBLIC
RMW_WARN_UNUSED
rmw_ret_t
Expand Down
100 changes: 100 additions & 0 deletions rmw/include/rmw/security_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// 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.

#ifndef RMW__SECURITY_OPTIONS_H_
#define RMW__SECURITY_OPTIONS_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdbool.h>

#include "rcutils/allocator.h"

#include "rmw/ret_types.h"
#include "rmw/visibility_control.h"

typedef enum RMW_PUBLIC_TYPE rmw_security_enforcement_policy_t
{
RMW_SECURITY_ENFORCEMENT_PERMISSIVE,
RMW_SECURITY_ENFORCEMENT_ENFORCE,
} rmw_security_enforcement_policy_t;

typedef struct RMW_PUBLIC_TYPE rmw_security_options_t
{
enum rmw_security_enforcement_policy_t enforce_security;
char * security_root_path;
} rmw_security_options_t;

/// Get zero initialized security options.
RMW_PUBLIC
rmw_security_options_t
rmw_get_zero_initialized_security_options();

/// Get default initialized security options.
RMW_PUBLIC
rmw_security_options_t
rmw_get_default_security_options();

/// Copy the given security options.
/**
* \param src security options to be copied.
* \param allocator allocator used when copying data to the new security options.
* \param dst security options to be set.
* \returns RMW_RET_BAD_ALLOC, or
* \returns RMW_RET_OK
*/
RMW_PUBLIC
rmw_ret_t
rmw_security_options_copy(
const rmw_security_options_t * src,
const rcutils_allocator_t * allocator,
rmw_security_options_t * dst);

/// Set the security root path for the given security options.
/**
* The provided `security_root_path` will be copied into allocated memory.
*
* \param security_root_path path to be set.
* \param allocator allocator used to allocate the new path.
* \param security_options security options to be set.
* \returns RMW_RET_BAD_ALLOC, or
* \returns RMW_RET_OK
*/
rmw_ret_t
rmw_security_options_set_root_path(
const char * security_root_path,
const rcutils_allocator_t * allocator,
rmw_security_options_t * security_options);

/// Finalize the given security_options.
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
/**
* \param security_options security options to be finalized.
* \param allocator allocator used to deallocate the root path.
* \returns RMW_RET_ERROR, or
* \returns RMW_RET_OK
*/
RMW_PUBLIC
rmw_ret_t
rmw_security_options_fini(
rmw_security_options_t * security_options,
const rcutils_allocator_t * allocator);

#ifdef __cplusplus
}
#endif

#endif // RMW__SECURITY_OPTIONS_H_
18 changes: 4 additions & 14 deletions rmw/include/rmw/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ extern "C"
#include <rcutils/logging.h>

#include "rmw/init.h"
#include "rmw/init_options.h"
#include "rmw/loaned_message_sequence.h"
#include "rmw/ret_types.h"
#include "rmw/security_options.h"
#include "rmw/serialized_message.h"
#include "rmw/visibility_control.h"

// 24 bytes is the most memory needed to represent the GID by any current
// implementation. It may need to be increased in the future.
#define RMW_GID_STORAGE_SIZE 24
#define RMW_GID_STORAGE_SIZE 24u

ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
typedef struct RMW_PUBLIC_TYPE rmw_node_t
{
Expand All @@ -46,7 +48,7 @@ typedef struct RMW_PUBLIC_TYPE rmw_node_t
rmw_context_t * context;
} rmw_node_t;

typedef enum RMW_PUBLIC_TYPE
typedef enum RMW_PUBLIC_TYPE rmw_endpoint_type_t
{
RMW_ENDPOINT_INVALID = 0,
RMW_ENDPOINT_PUBLISHER,
Expand Down Expand Up @@ -253,18 +255,6 @@ typedef struct RMW_PUBLIC_TYPE rmw_time_t
uint64_t nsec;
} rmw_time_t;

enum RMW_PUBLIC_TYPE rmw_security_enforcement_policy_t
{
RMW_SECURITY_ENFORCEMENT_PERMISSIVE,
RMW_SECURITY_ENFORCEMENT_ENFORCE,
};

typedef struct RMW_PUBLIC_TYPE rmw_node_security_options_t
{
enum rmw_security_enforcement_policy_t enforce_security;
const char * security_root_path;
} rmw_node_security_options_t;

enum RMW_PUBLIC_TYPE rmw_qos_reliability_policy_t
{
RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT,
Expand Down
7 changes: 6 additions & 1 deletion rmw/src/init_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <stddef.h>

#include "rmw/init_options.h"
#include "rmw/localhost.h"

#ifdef __cplusplus
extern "C"
Expand All @@ -25,9 +26,13 @@ rmw_init_options_t
rmw_get_zero_initialized_init_options(void)
{
return (const rmw_init_options_t) {
.instance_id = 0,
.domain_id = RMW_DEFAULT_DOMAIN_ID,
.localhost_only = RMW_LOCALHOST_ONLY_DEFAULT,
.implementation_identifier = NULL,
.impl = NULL,
.instance_id = 0,
.security_context = NULL,
.security_options = rmw_get_default_security_options(),
}; // NOLINT(readability/braces): false positive
}

Expand Down
31 changes: 0 additions & 31 deletions rmw/src/node_security_options.c

This file was deleted.

Loading