diff --git a/rmw_zenoh_cpp/src/detail/graph_cache.cpp b/rmw_zenoh_cpp/src/detail/graph_cache.cpp index 9ab7a0e0..f23b910e 100644 --- a/rmw_zenoh_cpp/src/detail/graph_cache.cpp +++ b/rmw_zenoh_cpp/src/detail/graph_cache.cpp @@ -1040,7 +1040,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. @@ -1048,7 +1048,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. @@ -1061,10 +1061,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 ceaf4ef5..914f6203 100644 --- a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp +++ b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp @@ -72,6 +72,7 @@ enum KeyexprIndex Nid, Id, EntityStr, + Enclave, Namespace, NodeName, TopicName, @@ -266,6 +267,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. @@ -340,14 +342,15 @@ 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; } } @@ -375,6 +378,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; @@ -408,7 +412,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 70630b66..1ae8b736 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp +++ b/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp @@ -45,6 +45,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 bd0be6a5..a7feb545 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -218,6 +218,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; @@ -302,7 +306,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", @@ -493,6 +498,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; @@ -673,7 +682,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(), @@ -1304,6 +1313,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; @@ -1505,7 +1518,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(), @@ -1970,6 +1983,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; @@ -2176,7 +2193,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), @@ -2556,6 +2573,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; @@ -2759,7 +2780,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),