Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
API changes to sync with one Participant per Context change in rmw_fa…
Browse files Browse the repository at this point in the history
…strtps (#392)

Signed-off-by: Ivan Santiago Paunovic <[email protected]>
  • Loading branch information
ivanpauno authored Apr 3, 2020
1 parent 587a96a commit 1b26f31
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 20 deletions.
32 changes: 30 additions & 2 deletions rmw_connext_cpp/src/rmw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "rmw/init.h"

#include "rcutils/strdup.h"

#include "rmw/impl/cpp/macros.hpp"
#include "rmw_connext_shared_cpp/init.hpp"

Expand All @@ -34,6 +36,10 @@ rmw_init_options_init(rmw_init_options_t * init_options, rcutils_allocator_t all
init_options->implementation_identifier = rti_connext_identifier;
init_options->allocator = allocator;
init_options->impl = nullptr;
init_options->security_options = rmw_get_zero_initialized_security_options();
init_options->domain_id = RMW_DEFAULT_DOMAIN_ID;
init_options->localhost_only = RMW_LOCALHOST_ONLY_DEFAULT;
init_options->security_context = NULL;
return RMW_RET_OK;
}

Expand All @@ -51,20 +57,38 @@ rmw_init_options_copy(const rmw_init_options_t * src, rmw_init_options_t * dst)
RMW_SET_ERROR_MSG("expected zero-initialized dst");
return RMW_RET_INVALID_ARGUMENT;
}
const rcutils_allocator_t * allocator = &src->allocator;
rmw_ret_t ret = RMW_RET_OK;

allocator->deallocate(dst->security_context, allocator->state);
*dst = *src;
return RMW_RET_OK;
dst->security_context = NULL;
dst->security_options = rmw_get_zero_initialized_security_options();

dst->security_context = rcutils_strdup(src->security_context, *allocator);
if (src->security_context && !dst->security_context) {
ret = RMW_RET_BAD_ALLOC;
goto fail;
}
return rmw_security_options_copy(&src->security_options, allocator, &dst->security_options);
fail:
allocator->deallocate(dst->security_context, allocator->state);
return ret;
}

rmw_ret_t
rmw_init_options_fini(rmw_init_options_t * init_options)
{
RMW_CHECK_ARGUMENT_FOR_NULL(init_options, RMW_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ALLOCATOR(&(init_options->allocator), return RMW_RET_INVALID_ARGUMENT);
rcutils_allocator_t & allocator = init_options->allocator;
RCUTILS_CHECK_ALLOCATOR(&allocator, return RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
init_options,
init_options->implementation_identifier,
rti_connext_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
allocator.deallocate(init_options->security_context, allocator.state);
rmw_security_options_fini(&init_options->security_options, &allocator);
*init_options = rmw_get_zero_initialized_init_options();
return RMW_RET_OK;
}
Expand All @@ -82,6 +106,10 @@ rmw_init(const rmw_init_options_t * options, rmw_context_t * context)
context->instance_id = options->instance_id;
context->implementation_identifier = rti_connext_identifier;
context->impl = nullptr;
rmw_ret_t ret = rmw_init_options_copy(options, &context->options);
if (RMW_RET_OK != ret) {
return ret;
}
return init();
}

Expand Down
4 changes: 1 addition & 3 deletions rmw_connext_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ rmw_create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options,
bool localhost_only)
{
return create_node(
rti_connext_identifier, context, name, namespace_, domain_id, security_options,
localhost_only);
rti_connext_identifier, context, name, namespace_, domain_id, localhost_only);
}

rmw_ret_t
Expand Down
11 changes: 11 additions & 0 deletions rmw_connext_cpp/src/rmw_node_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ rmw_get_node_names(
{
return get_node_names(rti_connext_identifier, node, node_names, node_namespaces);
}

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)
{
return get_node_names_with_security_contexts(
rti_connext_identifier, node, node_names, node_namespaces, security_contexts);
}
} // extern "C"
2 changes: 1 addition & 1 deletion rmw_connext_dynamic_cpp/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ rmw_create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options,
const rmw_security_options_t * security_options,
bool localhost_only)
{
return create_node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * options,
bool localhost_only);

RMW_CONNEXT_SHARED_CPP_PUBLIC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ get_node_names(
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces);

RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_ret_t
get_node_names_with_security_contexts(
const char * implementation_identifier,
const rmw_node_t * node,
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces,
rcutils_string_array_t * security_contexts);

RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_ret_t
count_publishers(
Expand Down
24 changes: 13 additions & 11 deletions rmw_connext_shared_cpp/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <cstring>
#include <string>

#include "rcutils/filesystem.h"
Expand All @@ -32,7 +33,6 @@ create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options,
bool localhost_only)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, NULL);
Expand All @@ -42,10 +42,6 @@ create_node(
implementation_identifier,
// TODO(wjwwood): replace this with RMW_RET_INCORRECT_RMW_IMPLEMENTATION when refactored
return NULL);
if (!security_options) {
RMW_SET_ERROR_MSG("security_options is null");
return nullptr;
}
DDS::DomainParticipantFactory * dpf_ = DDS::DomainParticipantFactory::get_instance();
if (!dpf_) {
RMW_SET_ERROR_MSG("failed to get participant factory");
Expand Down Expand Up @@ -77,17 +73,22 @@ create_node(
participant_qos.participant_name.name = DDS::String_dup(name);
// since the participant name is not part of the DDS spec
// the node name is also set in the user_data
size_t length = strlen(name) + strlen("name=;") +
strlen(namespace_) + strlen("namespace=;") + 1;
size_t length = std::snprintf(
nullptr,
0,
"name=%s;namespace=%s;securitycontext=%s;",
name, namespace_, context->options.security_context) + 1;
bool success = participant_qos.user_data.value.length(static_cast<DDS::Long>(length));
if (!success) {
RMW_SET_ERROR_MSG("failed to resize participant user_data");
return NULL;
}

int written = snprintf(
int written = std::snprintf(
reinterpret_cast<char *>(participant_qos.user_data.value.get_contiguous_buffer()),
length, "name=%s;namespace=%s;", name, namespace_);
length,
"name=%s;namespace=%s;securitycontext=%s;",
name, namespace_, context->options.security_context);
if (written < 0 || written > static_cast<int>(length) - 1) {
RMW_SET_ERROR_MSG("failed to populate user_data buffer");
return NULL;
Expand Down Expand Up @@ -153,7 +154,7 @@ create_node(
char * gov_fn = nullptr;
char * perm_fn = nullptr;

if (security_options->security_root_path) {
if (context->options.security_options.security_root_path) {
// enable some security stuff
status = DDS::PropertyQosPolicyHelper::add_property(
participant_qos.property,
Expand Down Expand Up @@ -183,7 +184,7 @@ create_node(
return NULL;
}

srp = security_options->security_root_path; // save some typing
srp = context->options.security_options.security_root_path; // save some typing
identity_ca_cert_fn = rcutils_join_path(srp, "identity_ca.cert.pem", allocator);
if (!identity_ca_cert_fn) {
RMW_SET_ERROR_MSG("failed to allocate memory for 'identity_ca_cert_fn'");
Expand Down Expand Up @@ -374,6 +375,7 @@ create_node(

node_handle->implementation_identifier = implementation_identifier;
node_handle->data = node_info;
node_handle->context = context;
return node_handle;
fail:
status = dpf_->delete_participant(participant);
Expand Down
Loading

0 comments on commit 1b26f31

Please sign in to comment.