From 3b1b2cabdcd93e755c594079a1d497d511647def Mon Sep 17 00:00:00 2001 From: ericsalo <93227906+ericsalo@users.noreply.github.com> Date: Thu, 14 Dec 2023 08:30:35 -0800 Subject: [PATCH 1/2] [upb] stop calling hazzers for repeated fields (#35275) The upb gencode is being changed to no longer generate _has_() functions for repeated fields as they are redundant and really only intended for scalar fields with presence. So instead of calling foo_has_bar(msg), one now calls foo_bar(msg, &size) to get the number of elements in the repeated field. Closes #35275 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/35275 from ericsalo:master 90db1ffe0e65101b9d36c8b5fb9a6ce3175f24cc PiperOrigin-RevId: 590948259 --- src/core/ext/xds/xds_common_types.cc | 11 +++++++---- src/core/ext/xds/xds_http_rbac_filter.cc | 6 ++++-- src/core/ext/xds/xds_listener.cc | 14 +++++++++----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/core/ext/xds/xds_common_types.cc b/src/core/ext/xds/xds_common_types.cc index f3d5c087d39..426ee61dc21 100644 --- a/src/core/ext/xds/xds_common_types.cc +++ b/src/core/ext/xds/xds_common_types.cc @@ -385,13 +385,16 @@ CommonTlsContext CommonTlsContext::Parse( CertificateProviderInstanceParse( context, tls_certificate_certificate_provider_instance, errors); } else { - if (envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_has_tls_certificates( - common_tls_context_proto)) { + size_t size; + envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_tls_certificates( + common_tls_context_proto, &size); + if (size != 0) { ValidationErrors::ScopedField field(errors, ".tls_certificates"); errors->AddError("feature unsupported"); } - if (envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_has_tls_certificate_sds_secret_configs( - common_tls_context_proto)) { + envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_tls_certificate_sds_secret_configs( + common_tls_context_proto, &size); + if (size != 0) { ValidationErrors::ScopedField field( errors, ".tls_certificate_sds_secret_configs"); errors->AddError("feature unsupported"); diff --git a/src/core/ext/xds/xds_http_rbac_filter.cc b/src/core/ext/xds/xds_http_rbac_filter.cc index ed107c37a37..9cc8d1890d6 100644 --- a/src/core/ext/xds/xds_http_rbac_filter.cc +++ b/src/core/ext/xds/xds_http_rbac_filter.cc @@ -486,8 +486,10 @@ Json ParseHttpRbacToJson(const XdsResourceType::DecodeContext& context, ValidationErrors::ScopedField field(errors, ".audit_condition"); errors->AddError("invalid audit condition"); } - if (envoy_config_rbac_v3_RBAC_AuditLoggingOptions_has_logger_configs( - audit_logging_options)) { + size_t size; + envoy_config_rbac_v3_RBAC_AuditLoggingOptions_logger_configs( + audit_logging_options, &size); + if (size != 0) { inner_rbac_json.emplace("audit_loggers", ParseAuditLoggerConfigsToJson( context, audit_logging_options, errors)); diff --git a/src/core/ext/xds/xds_listener.cc b/src/core/ext/xds/xds_listener.cc index 08b30ecbc07..29c25537632 100644 --- a/src/core/ext/xds/xds_listener.cc +++ b/src/core/ext/xds/xds_listener.cc @@ -332,11 +332,15 @@ XdsListenerResource::HttpConnectionManager HttpConnectionManagerParse( } // original_ip_detection_extensions -- must be empty as per // https://github.com/grpc/proposal/blob/master/A41-xds-rbac.md - if (envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_original_ip_detection_extensions( - http_connection_manager_proto)) { - ValidationErrors::ScopedField field(errors, - ".original_ip_detection_extensions"); - errors->AddError("must be empty"); + { + size_t size; + envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_original_ip_detection_extensions( + http_connection_manager_proto, &size); + if (size != 0) { + ValidationErrors::ScopedField field(errors, + ".original_ip_detection_extensions"); + errors->AddError("must be empty"); + } } // common_http_protocol_options const envoy_config_core_v3_HttpProtocolOptions* options = From 96ac691531fa513b1fbf914d66032364867447c7 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 14 Dec 2023 10:20:39 -0800 Subject: [PATCH 2/2] [promises] poll_cast improvements (#35302) Make it possible to `poll_cast<>` from a normal non-poll type to a Poll Closes #35302 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/35302 from ctiller:poll-review 216916e7c3fca42ac6e920d3b672a69ce335f4e2 PiperOrigin-RevId: 590979951 --- src/core/lib/promise/poll.h | 51 +++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/src/core/lib/promise/poll.h b/src/core/lib/promise/poll.h index 43509b49dfb..d55174e7441 100644 --- a/src/core/lib/promise/poll.h +++ b/src/core/lib/promise/poll.h @@ -186,19 +186,6 @@ class Poll; template class Poll>; -template -bool operator==(const Poll& a, const Poll& b) { - if (a.pending() && b.pending()) return true; - if (a.ready() && b.ready()) return a.value() == b.value(); - return false; -} - -template -Poll poll_cast(Poll poll) { - if (poll.pending()) return Pending{}; - return static_cast(std::move(poll.value())); -} - // PollTraits tells us whether a type is Poll<> or some other type, and is // leveraged in the PromiseLike/PromiseFactory machinery to select the // appropriate implementation of those concepts based upon the return type of a @@ -214,6 +201,44 @@ struct PollTraits> { static constexpr bool is_poll() { return true; } }; +template +bool operator==(const Poll& a, const Poll& b) { + if (a.pending() && b.pending()) return true; + if (a.ready() && b.ready()) return a.value() == b.value(); + return false; +} + +template +struct PollCastImpl; + +template +struct PollCastImpl> { + static Poll Cast(Poll&& poll) { + if (poll.pending()) return Pending{}; + return static_cast(std::move(poll.value())); + } +}; + +template +struct PollCastImpl::is_poll()>> { + static Poll Cast(U&& poll) { return Poll(T(std::move(poll))); } +}; + +template +struct PollCastImpl { + static Poll Cast(T&& poll) { return Poll(std::move(poll)); } +}; + +template +struct PollCastImpl> { + static Poll Cast(Poll&& poll) { return std::move(poll); } +}; + +template +Poll poll_cast(U poll) { + return PollCastImpl::Cast(std::move(poll)); +} + // Convert a poll to a string template std::string PollToString(