Skip to content

Commit

Permalink
Use one participant per context API changes (#189)
Browse files Browse the repository at this point in the history
Signed-off-by: ivanpauno <[email protected]>
  • Loading branch information
ivanpauno authored Apr 3, 2020
1 parent b3bf0fd commit 2f954d7
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 70 deletions.
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"
"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 @@ -1049,6 +1048,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.
/**
* \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

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

0 comments on commit 2f954d7

Please sign in to comment.