diff --git a/rmw_zenoh_cpp/src/detail/graph_cache.cpp b/rmw_zenoh_cpp/src/detail/graph_cache.cpp index 63cca99e..e9a5e416 100644 --- a/rmw_zenoh_cpp/src/detail/graph_cache.cpp +++ b/rmw_zenoh_cpp/src/detail/graph_cache.cpp @@ -1038,7 +1038,7 @@ rmw_ret_t GraphCache::get_entity_names_and_types_by_node( // Check if namespace exists. NamespaceMap::const_iterator ns_it = graph_.find(node_namespace); if (ns_it == graph_.end()) { - return RMW_RET_OK; + return RMW_RET_NODE_NAME_NON_EXISTENT; } // Check if node exists. @@ -1046,7 +1046,7 @@ rmw_ret_t GraphCache::get_entity_names_and_types_by_node( // name that is found. NodeMap::const_iterator node_it = ns_it->second.find(node_name); if (node_it == ns_it->second.end()) { - return RMW_RET_OK; + return RMW_RET_NODE_NAME_NON_EXISTENT; } // TODO(Yadunund): Support service and client when ready. @@ -1059,10 +1059,8 @@ rmw_ret_t GraphCache::get_entity_names_and_types_by_node( } else if (entity_type == EntityType::Client) { return fill_names_and_types(node_it->second->clients_, allocator, names_and_types); } else { - return RMW_RET_OK; + return RMW_RET_UNSUPPORTED; } - - return RMW_RET_OK; } diff --git a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp index 1b6a3098..c74fae92 100644 --- a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp +++ b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp @@ -70,6 +70,7 @@ enum KeyexprIndex Nid, Id, EntityStr, + Enclave, Namespace, NodeName, TopicName, @@ -263,6 +264,7 @@ Entity::Entity( // An empty namespace from rcl will contain "/" but zenoh does not allow keys with "//". // Hence we mangle the empty namespace such that splitting the key // will always result in 5 parts. + keyexpr_parts[KeyexprIndex::Enclave] = mangle_name(node_info_.enclave_); keyexpr_parts[KeyexprIndex::Namespace] = mangle_name(node_info_.ns_); keyexpr_parts[KeyexprIndex::NodeName] = mangle_name(node_info_.name_); // If this entity has a topic info, append it to the token. @@ -336,14 +338,16 @@ std::shared_ptr Entity::make(const std::string & keyexpr) if (parts.size() < KEYEXPR_INDEX_MIN + 1) { RCUTILS_LOG_ERROR_NAMED( "rmw_zenoh_cpp", - "Received invalid liveliness token"); + "Received invalid liveliness token with %lu/%d parts: %s", + parts.size(), + KEYEXPR_INDEX_MIN + 1, keyexpr.c_str()); return nullptr; } for (const std::string & p : parts) { if (p.empty()) { RCUTILS_LOG_ERROR_NAMED( "rmw_zenoh_cpp", - "Received invalid liveliness token"); + "Received invalid liveliness token with empty parts: %s", keyexpr.c_str()); return nullptr; } } @@ -371,6 +375,7 @@ std::shared_ptr Entity::make(const std::string & keyexpr) std::string & zid = parts[KeyexprIndex::Zid]; std::string & nid = parts[KeyexprIndex::Nid]; std::string & id = parts[KeyexprIndex::Id]; + std::string enclave = demangle_name(std::move(parts[KeyexprIndex::Enclave])); std::string ns = demangle_name(std::move(parts[KeyexprIndex::Namespace])); std::string node_name = demangle_name(std::move(parts[KeyexprIndex::NodeName])); std::optional topic_info = std::nullopt; @@ -403,7 +408,7 @@ std::shared_ptr Entity::make(const std::string & keyexpr) std::move(nid), std::move(id), std::move(entity_type), - NodeInfo{std::move(domain_id), std::move(ns), std::move(node_name), ""}, + NodeInfo{std::move(domain_id), std::move(ns), std::move(node_name), std::move(enclave)}, std::move(topic_info)}); } diff --git a/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp b/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp index a43af5d3..1c3c48e2 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp +++ b/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp @@ -43,6 +43,9 @@ class rmw_context_impl_s final { public: + // Enclave, name used to find security artifacts in a sros2 keystore. + char * enclave; + // An owned session. z_owned_session_t session; diff --git a/rmw_zenoh_cpp/src/rmw_init.cpp b/rmw_zenoh_cpp/src/rmw_init.cpp index b70c0aa7..4ec46e21 100644 --- a/rmw_zenoh_cpp/src/rmw_init.cpp +++ b/rmw_zenoh_cpp/src/rmw_init.cpp @@ -144,6 +144,9 @@ rmw_init(const rmw_init_options_t * options, rmw_context_t * context) } }); + // Set the enclave. + context->impl->enclave = options->enclave; + // Initialize context's implementation context->impl->is_shutdown = false; diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index 7d2e1716..a9d0515b 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -195,6 +195,10 @@ rmw_create_node( context->impl, "expected initialized context", return nullptr); + RMW_CHECK_FOR_NULL_WITH_MSG( + context->impl->enclave, + "expected initialized enclave", + return nullptr); if (context->impl->is_shutdown) { RCUTILS_SET_ERROR_MSG("context has been shutdown"); return nullptr; @@ -279,7 +283,8 @@ rmw_create_node( std::to_string(node_data->id), std::to_string(node_data->id), rmw_zenoh_cpp::liveliness::EntityType::Node, - rmw_zenoh_cpp::liveliness::NodeInfo{context->actual_domain_id, namespace_, name, ""}); + rmw_zenoh_cpp::liveliness::NodeInfo{context->actual_domain_id, namespace_, name, + context->impl->enclave}); if (node_data->entity == nullptr) { RCUTILS_LOG_ERROR_NAMED( "rmw_zenoh_cpp", @@ -470,6 +475,10 @@ rmw_create_publisher( context_impl, "unable to get rmw_context_impl_s", return nullptr); + RMW_CHECK_FOR_NULL_WITH_MSG( + context_impl->enclave, + "expected initialized enclave", + return nullptr); if (!z_check(context_impl->session)) { RMW_SET_ERROR_MSG("zenoh session is invalid"); return nullptr; @@ -630,7 +639,7 @@ rmw_create_publisher( context_impl->get_next_entity_id()), rmw_zenoh_cpp::liveliness::EntityType::Publisher, rmw_zenoh_cpp::liveliness::NodeInfo{ - node->context->actual_domain_id, node->namespace_, node->name, ""}, + node->context->actual_domain_id, node->namespace_, node->name, context_impl->enclave}, rmw_zenoh_cpp::liveliness::TopicInfo{rmw_publisher->topic_name, publisher_data->type_support->get_name(), publisher_data->adapted_qos_profile} ); @@ -1258,6 +1267,10 @@ rmw_create_subscription( context_impl, "unable to get rmw_context_impl_s", return nullptr); + RMW_CHECK_FOR_NULL_WITH_MSG( + context_impl->enclave, + "expected initialized enclave", + return nullptr); if (!z_check(context_impl->session)) { RMW_SET_ERROR_MSG("zenoh session is invalid"); return nullptr; @@ -1440,7 +1453,7 @@ rmw_create_subscription( context_impl->get_next_entity_id()), rmw_zenoh_cpp::liveliness::EntityType::Subscription, rmw_zenoh_cpp::liveliness::NodeInfo{ - node->context->actual_domain_id, node->namespace_, node->name, ""}, + node->context->actual_domain_id, node->namespace_, node->name, context_impl->enclave}, rmw_zenoh_cpp::liveliness::TopicInfo{rmw_subscription->topic_name, sub_data->type_support->get_name(), sub_data->adapted_qos_profile} ); @@ -1902,6 +1915,10 @@ rmw_create_client( context_impl, "unable to get rmw_context_impl_s", return nullptr); + RMW_CHECK_FOR_NULL_WITH_MSG( + context_impl->enclave, + "expected initialized enclave", + return nullptr); if (!z_check(context_impl->session)) { RMW_SET_ERROR_MSG("zenoh session is invalid"); return nullptr; @@ -2087,7 +2104,7 @@ rmw_create_client( context_impl->get_next_entity_id()), rmw_zenoh_cpp::liveliness::EntityType::Client, rmw_zenoh_cpp::liveliness::NodeInfo{ - node->context->actual_domain_id, node->namespace_, node->name, ""}, + node->context->actual_domain_id, node->namespace_, node->name, context_impl->enclave}, rmw_zenoh_cpp::liveliness::TopicInfo{rmw_client->service_name, std::move(service_type), client_data->adapted_qos_profile} ); @@ -2464,6 +2481,10 @@ rmw_create_service( context_impl, "unable to get rmw_context_impl_s", return nullptr); + RMW_CHECK_FOR_NULL_WITH_MSG( + context_impl->enclave, + "expected initialized enclave", + return nullptr); if (!z_check(context_impl->session)) { RMW_SET_ERROR_MSG("zenoh session is invalid"); return nullptr; @@ -2645,7 +2666,7 @@ rmw_create_service( context_impl->get_next_entity_id()), rmw_zenoh_cpp::liveliness::EntityType::Service, rmw_zenoh_cpp::liveliness::NodeInfo{ - node->context->actual_domain_id, node->namespace_, node->name, ""}, + node->context->actual_domain_id, node->namespace_, node->name, context_impl->enclave}, rmw_zenoh_cpp::liveliness::TopicInfo{rmw_service->service_name, std::move(service_type), service_data->adapted_qos_profile} );