diff options
| author | heretic <[email protected]> | 2022-03-25 12:34:53 +0300 |
|---|---|---|
| committer | heretic <[email protected]> | 2022-03-25 12:34:53 +0300 |
| commit | a41f3739eed6fceb6f62056a7620d220958a47e7 (patch) | |
| tree | 278103258b510cb4a96761ea79d6ccd397ca05a0 /contrib/libs/grpc/src/cpp | |
| parent | 73d3613a82e5c217fcbe0ab8bbf8120c1ed1af55 (diff) | |
Update grpc to 1.43.2 DTCC-864
ref:50a492c335cda70f458797cf945e49fe739c2715
Diffstat (limited to 'contrib/libs/grpc/src/cpp')
49 files changed, 635 insertions, 546 deletions
diff --git a/contrib/libs/grpc/src/cpp/README.md b/contrib/libs/grpc/src/cpp/README.md index 134f4db56c7..5c1c40acf7f 100755 --- a/contrib/libs/grpc/src/cpp/README.md +++ b/contrib/libs/grpc/src/cpp/README.md @@ -9,6 +9,39 @@ This section describes how to add gRPC as a dependency to your C++ project. In the C++ world, there's no universally accepted standard for managing project dependencies. Therefore, gRPC supports several major build systems, which should satisfy most users. +## Supported Platforms + +* Officially Supported: These platforms are officially supported. We test our + code on these platform and have automated continuous integration tests for + them. + +* Best Effort: We do not have continous integration tests for these, but we are + fairly confident that gRPC C++ would work on them. We will make our best + effort to support them, and we welcome patches for such platforms, but we + might need to declare bankruptcy on some issues. + +* Community Supported: These platforms are supported by contributions from the + open source community, there is no official support for them. Breakages on + these platforms may go unnoticed, and the community is responsible for all + maintenance. Unmaintained code for these platforms may be deleted. + +| Operating System | Architectures | Versions | Support Level | +|------------------|---------------|----------|---------------| +| Linux - Debian, Ubuntu, CentOS | x86, x64 | clang 4+, GCC 4.9+ | Officially Supported | +| Windows 10+ | x86, x64 | Visual Studio 2015+ | Officially Supported | +| MacOS | x86, x64 | XCode 7.2+ | Officially Supported | +| Linux - Others | x86, x64 | clang 4+, GCC 4.9+ | Best Effort | +| Linux | ARM | | Best Effort | +| iOS | | | Best Effort | +| Android | | | Best Effort | +| Asylo | | | Best Effort | +| FreeBSD | | | Community Supported | +| OpenBSD | | | Community Supported | +| AIX | | | Community Supported | +| Solaris | | | Community Supported | +| NaCL | | | Community Supported | +| Fuchsia | | | Community Supported | + ## Bazel Bazel is the primary build system used by the core gRPC development team. Bazel @@ -122,6 +155,13 @@ first install gRPC C++ using CMake, and have your non-CMake project rely on the `pkgconfig` files which are provided by gRPC installation. [Example](../../test/distrib/cpp/run_distrib_test_cmake_pkgconfig.sh) +**Note for CentOS 7 users** + +CentOS-7 ships with `pkg-config` 0.27.1, which has a +[bug](https://bugs.freedesktop.org/show_bug.cgi?id=54716) that can make +invocations take extremely long to complete. If you plan to use `pkg-config`, +you'll want to upgrade it to something newer. + ## make (deprecated) The default choice for building on UNIX based systems used to be `make`, but we are no longer recommending it. @@ -147,11 +187,16 @@ gRPC is available using the [vcpkg](https://github.com/Microsoft/vcpkg) dependen # install vcpkg package manager on your system using the official instructions git clone https://github.com/Microsoft/vcpkg.git cd vcpkg + +# Bootstrap on Linux: ./bootstrap-vcpkg.sh +# Bootstrap on Windows instead: +# ./bootstrap-vcpkg.bat + ./vcpkg integrate install # install gRPC using vcpkg package manager -vcpkg install grpc +./vcpkg install grpc ``` The gRPC port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. diff --git a/contrib/libs/grpc/src/cpp/client/channel_cc.cc b/contrib/libs/grpc/src/cpp/client/channel_cc.cc index 1793161d6ce..280537bbbd0 100644 --- a/contrib/libs/grpc/src/cpp/client/channel_cc.cc +++ b/contrib/libs/grpc/src/cpp/client/channel_cc.cc @@ -16,8 +16,6 @@ * */ -#include <grpcpp/channel.h> - #include <cstring> #include <memory> @@ -27,6 +25,7 @@ #include <grpc/support/log.h> #include <grpc/support/sync.h> #include <grpc/support/time.h> +#include <grpcpp/channel.h> #include <grpcpp/client_context.h> #include <grpcpp/completion_queue.h> #include <grpcpp/impl/call.h> @@ -57,12 +56,13 @@ Channel::Channel(const TString& host, grpc_channel* channel, Channel::~Channel() { grpc_channel_destroy(c_channel_); - if (callback_cq_ != nullptr) { + CompletionQueue* callback_cq = callback_cq_.load(std::memory_order_relaxed); + if (callback_cq != nullptr) { if (grpc_iomgr_run_in_background()) { // gRPC-core provides the backing needed for the preferred CQ type - callback_cq_->Shutdown(); + callback_cq->Shutdown(); } else { - CompletionQueue::ReleaseCallbackAlternativeCQ(callback_cq_); + CompletionQueue::ReleaseCallbackAlternativeCQ(callback_cq); } } } @@ -146,9 +146,9 @@ void ChannelResetConnectionBackoff(Channel* channel) { // ClientRpcInfo should be set before call because set_call also checks // whether the call has been cancelled, and if the call was cancelled, we // should notify the interceptors too. - auto* info = - context->set_client_rpc_info(method.name(), method.method_type(), this, - interceptor_creators_, interceptor_pos); + auto* info = context->set_client_rpc_info( + method.name(), method.suffix_for_stats(), method.method_type(), this, + interceptor_creators_, interceptor_pos); context->set_call(c_call, shared_from_this()); return ::grpc::internal::Call(c_call, this, cq, info); @@ -213,7 +213,7 @@ bool Channel::WaitForStateChangeImpl(grpc_connectivity_state last_observed, } namespace { -class ShutdownCallback : public grpc_experimental_completion_queue_functor { +class ShutdownCallback : public grpc_completion_queue_functor { public: ShutdownCallback() { functor_run = &ShutdownCallback::Run; @@ -229,7 +229,7 @@ class ShutdownCallback : public grpc_experimental_completion_queue_functor { // The Run function will get invoked by the completion queue library // when the shutdown is actually complete - static void Run(grpc_experimental_completion_queue_functor* cb, int) { + static void Run(grpc_completion_queue_functor* cb, int) { auto* callback = static_cast<ShutdownCallback*>(cb); delete callback->cq_; delete callback; @@ -243,25 +243,33 @@ class ShutdownCallback : public grpc_experimental_completion_queue_functor { ::grpc::CompletionQueue* Channel::CallbackCQ() { // TODO(vjpai): Consider using a single global CQ for the default CQ // if there is no explicit per-channel CQ registered + CompletionQueue* callback_cq = callback_cq_.load(std::memory_order_acquire); + if (callback_cq != nullptr) { + return callback_cq; + } + // The callback_cq_ wasn't already set, so grab a lock and set it up exactly + // once for this channel. grpc::internal::MutexLock l(&mu_); - if (callback_cq_ == nullptr) { + callback_cq = callback_cq_.load(std::memory_order_relaxed); + if (callback_cq == nullptr) { if (grpc_iomgr_run_in_background()) { // gRPC-core provides the backing needed for the preferred CQ type auto* shutdown_callback = new ShutdownCallback; - callback_cq_ = + callback_cq = new ::grpc::CompletionQueue(grpc_completion_queue_attributes{ GRPC_CQ_CURRENT_VERSION, GRPC_CQ_CALLBACK, GRPC_CQ_DEFAULT_POLLING, shutdown_callback}); // Transfer ownership of the new cq to its own shutdown callback - shutdown_callback->TakeCQ(callback_cq_); + shutdown_callback->TakeCQ(callback_cq); } else { // Otherwise we need to use the alternative CQ variant - callback_cq_ = CompletionQueue::CallbackAlternativeCQ(); + callback_cq = CompletionQueue::CallbackAlternativeCQ(); } + callback_cq_.store(callback_cq, std::memory_order_release); } - return callback_cq_; + return callback_cq; } } // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/client/client_callback.cc b/contrib/libs/grpc/src/cpp/client/client_callback.cc index a05761ad063..9e4ebbb3f82 100644 --- a/contrib/libs/grpc/src/cpp/client/client_callback.cc +++ b/contrib/libs/grpc/src/cpp/client/client_callback.cc @@ -20,6 +20,7 @@ #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/executor.h" +#include "src/core/lib/surface/call.h" namespace grpc { namespace internal { @@ -36,7 +37,7 @@ void ClientReactor::InternalScheduleOnDone(grpc::Status s) { : reactor(reactor_arg), status(std::move(s)) { GRPC_CLOSURE_INIT( &closure, - [](void* void_arg, grpc_error*) { + [](void* void_arg, grpc_error_handle) { ClosureWithArg* arg = static_cast<ClosureWithArg*>(void_arg); arg->reactor->OnDone(arg->status); delete arg; @@ -48,5 +49,9 @@ void ClientReactor::InternalScheduleOnDone(grpc::Status s) { grpc_core::Executor::Run(&arg->closure, GRPC_ERROR_NONE); } +bool ClientReactor::InternalTrailersOnly(const grpc_call* call) const { + return grpc_call_is_trailers_only(call); +} + } // namespace internal } // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/client/client_context.cc b/contrib/libs/grpc/src/cpp/client/client_context.cc index 8f18bfe7245..fd4a52c88ed 100644 --- a/contrib/libs/grpc/src/cpp/client/client_context.cc +++ b/contrib/libs/grpc/src/cpp/client/client_context.cc @@ -16,14 +16,12 @@ * */ -#include <grpcpp/client_context.h> - #include <grpc/compression.h> #include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> - +#include <grpcpp/client_context.h> #include <grpcpp/impl/codegen/interceptor_common.h> #include <grpcpp/impl/codegen/sync.h> #include <grpcpp/impl/grpc_library.h> @@ -98,7 +96,7 @@ std::unique_ptr<ClientContext> ClientContext::FromInternalServerContext( } std::unique_ptr<ClientContext> ClientContext::FromServerContext( - const grpc::ServerContext& server_context, PropagationOptions options) { + const grpc::ServerContextBase& server_context, PropagationOptions options) { return FromInternalServerContext(server_context, options); } diff --git a/contrib/libs/grpc/src/cpp/client/create_channel_internal.cc b/contrib/libs/grpc/src/cpp/client/create_channel_internal.cc index da2a878a227..77ab7ac8b56 100644 --- a/contrib/libs/grpc/src/cpp/client/create_channel_internal.cc +++ b/contrib/libs/grpc/src/cpp/client/create_channel_internal.cc @@ -16,7 +16,12 @@ * */ +#include "src/cpp/client/create_channel_internal.h" + #include <memory> +#include <util/generic/string.h> +#include <utility> +#include <vector> #include <grpcpp/channel.h> diff --git a/contrib/libs/grpc/src/cpp/client/create_channel_internal.h b/contrib/libs/grpc/src/cpp/client/create_channel_internal.h index 09d4e56b023..730051694bf 100644 --- a/contrib/libs/grpc/src/cpp/client/create_channel_internal.h +++ b/contrib/libs/grpc/src/cpp/client/create_channel_internal.h @@ -20,6 +20,8 @@ #define GRPC_INTERNAL_CPP_CLIENT_CREATE_CHANNEL_INTERNAL_H #include <memory> +#include <util/generic/string.h> +#include <vector> #include <grpcpp/channel.h> #include <grpcpp/impl/codegen/client_interceptor.h> diff --git a/contrib/libs/grpc/src/cpp/client/insecure_credentials.cc b/contrib/libs/grpc/src/cpp/client/insecure_credentials.cc index b7036e541c9..d266e214352 100644 --- a/contrib/libs/grpc/src/cpp/client/insecure_credentials.cc +++ b/contrib/libs/grpc/src/cpp/client/insecure_credentials.cc @@ -15,13 +15,13 @@ * limitations under the License. * */ -#include <grpcpp/security/credentials.h> - #include <grpc/grpc.h> #include <grpc/support/log.h> #include <grpcpp/channel.h> +#include <grpcpp/security/credentials.h> #include <grpcpp/support/channel_arguments.h> #include <grpcpp/support/config.h> + #include "src/cpp/client/create_channel_internal.h" namespace grpc { diff --git a/contrib/libs/grpc/src/cpp/client/secure_credentials.cc b/contrib/libs/grpc/src/cpp/client/secure_credentials.cc index 109b50448df..ee3bde2eb24 100644 --- a/contrib/libs/grpc/src/cpp/client/secure_credentials.cc +++ b/contrib/libs/grpc/src/cpp/client/secure_credentials.cc @@ -18,6 +18,8 @@ #include "src/cpp/client/secure_credentials.h" +#include "y_absl/strings/str_join.h" + #include <grpc/impl/codegen/slice.h> #include <grpc/slice.h> #include <grpc/support/alloc.h> @@ -28,8 +30,6 @@ #include <grpcpp/impl/grpc_library.h> #include <grpcpp/support/channel_arguments.h> -#include "y_absl/strings/str_join.h" - // TODO(yashykt): We shouldn't be including "src/core" headers. #include "src/core/lib/gpr/env.h" #include "src/core/lib/iomgr/error.h" @@ -157,7 +157,7 @@ grpc::Status StsCredentialsOptionsFromJson(const TString& json_string, "options cannot be nullptr."); } ClearStsCredentialsOptions(options); - grpc_error* error = GRPC_ERROR_NONE; + grpc_error_handle error = GRPC_ERROR_NONE; grpc_core::Json json = grpc_core::Json::Parse(json_string.c_str(), &error); if (error != GRPC_ERROR_NONE || json.type() != grpc_core::Json::Type::OBJECT) { @@ -215,8 +215,9 @@ grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options) { ClearStsCredentialsOptions(options); grpc_slice json_string = grpc_empty_slice(); char* sts_creds_path = gpr_getenv("STS_CREDENTIALS"); - grpc_error* error = GRPC_ERROR_NONE; + grpc_error_handle error = GRPC_ERROR_NONE; grpc::Status status; + // NOLINTNEXTLINE(clang-diagnostic-unused-lambda-capture) auto cleanup = [&json_string, &sts_creds_path, &error, &status]() { grpc_slice_unref_internal(json_string); gpr_free(sts_creds_path); @@ -232,7 +233,7 @@ grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options) { error = grpc_load_file(sts_creds_path, 1, &json_string); if (error != GRPC_ERROR_NONE) { status = - grpc::Status(grpc::StatusCode::NOT_FOUND, grpc_error_string(error)); + grpc::Status(grpc::StatusCode::NOT_FOUND, grpc_error_std_string(error)); return cleanup(); } status = StsCredentialsOptionsFromJson( @@ -406,7 +407,7 @@ std::shared_ptr<CallCredentials> MetadataCredentialsFromPlugin( } namespace { -void DeleteWrapper(void* wrapper, grpc_error* /*ignored*/) { +void DeleteWrapper(void* wrapper, grpc_error_handle /*ignored*/) { MetadataCredentialsPluginWrapper* w = static_cast<MetadataCredentialsPluginWrapper*>(wrapper); delete w; @@ -492,7 +493,6 @@ void MetadataCredentialsPluginWrapper::InvokePlugin( grpc_metadata md_entry; md_entry.key = SliceFromCopiedString(metadatum.first); md_entry.value = SliceFromCopiedString(metadatum.second); - md_entry.flags = 0; md.push_back(md_entry); } if (creds_md != nullptr) { @@ -507,7 +507,6 @@ void MetadataCredentialsPluginWrapper::InvokePlugin( for (const auto& elem : md) { creds_md[*num_creds_md].key = elem.key; creds_md[*num_creds_md].value = elem.value; - creds_md[*num_creds_md].flags = elem.flags; ++(*num_creds_md); } *status_code = static_cast<grpc_status_code>(status.error_code()); @@ -525,6 +524,10 @@ void MetadataCredentialsPluginWrapper::InvokePlugin( MetadataCredentialsPluginWrapper::MetadataCredentialsPluginWrapper( std::unique_ptr<MetadataCredentialsPlugin> plugin) - : thread_pool_(CreateDefaultThreadPool()), plugin_(std::move(plugin)) {} + : plugin_(std::move(plugin)) { + if (plugin_->IsBlocking()) { + thread_pool_.reset(CreateDefaultThreadPool()); + } +} } // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/client/secure_credentials.h b/contrib/libs/grpc/src/cpp/client/secure_credentials.h index 9325f365b1e..d6f1c89c2c1 100644 --- a/contrib/libs/grpc/src/cpp/client/secure_credentials.h +++ b/contrib/libs/grpc/src/cpp/client/secure_credentials.h @@ -19,13 +19,12 @@ #ifndef GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H #define GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H -#include <grpc/grpc_security.h> +#include "y_absl/strings/str_cat.h" +#include <grpc/grpc_security.h> #include <grpcpp/security/credentials.h> #include <grpcpp/security/tls_credentials_options.h> #include <grpcpp/support/config.h> - -#include "y_absl/strings/str_cat.h" // TODO(yashykt): We shouldn't be including "src/core" headers. #include "src/core/lib/security/credentials/credentials.h" #include "src/cpp/server/thread_pool_interface.h" diff --git a/contrib/libs/grpc/src/cpp/client/xds_credentials.cc b/contrib/libs/grpc/src/cpp/client/xds_credentials.cc index 63b48837ef0..d5446a02fe5 100644 --- a/contrib/libs/grpc/src/cpp/client/xds_credentials.cc +++ b/contrib/libs/grpc/src/cpp/client/xds_credentials.cc @@ -19,7 +19,6 @@ #include "src/cpp/client/secure_credentials.h" namespace grpc { -namespace experimental { std::shared_ptr<ChannelCredentials> XdsCredentials( const std::shared_ptr<ChannelCredentials>& fallback_creds) { @@ -37,5 +36,12 @@ std::shared_ptr<ChannelCredentials> XdsCredentials( } } +namespace experimental { + +std::shared_ptr<ChannelCredentials> XdsCredentials( + const std::shared_ptr<ChannelCredentials>& fallback_creds) { + return grpc::XdsCredentials(fallback_creds); +} + } // namespace experimental } // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/common/.yandex_meta/licenses.list.txt b/contrib/libs/grpc/src/cpp/common/.yandex_meta/licenses.list.txt index ed4a3efa9f4..b042e4af0c0 100644 --- a/contrib/libs/grpc/src/cpp/common/.yandex_meta/licenses.list.txt +++ b/contrib/libs/grpc/src/cpp/common/.yandex_meta/licenses.list.txt @@ -39,8 +39,12 @@ ====================COPYRIGHT==================== + * Copyright 2019 gRPC authors. + + +====================COPYRIGHT==================== * Copyright 2020 gRPC authors. ====================COPYRIGHT==================== -# Copyright 2019 gRPC authors. +// Copyright 2021 gRPC authors. diff --git a/contrib/libs/grpc/src/cpp/common/alarm.cc b/contrib/libs/grpc/src/cpp/common/alarm.cc index ac1b747b493..a367b53d3a2 100644 --- a/contrib/libs/grpc/src/cpp/common/alarm.cc +++ b/contrib/libs/grpc/src/cpp/common/alarm.cc @@ -15,23 +15,22 @@ * */ -#include <grpcpp/alarm.h> +#include <grpc/support/port_platform.h> #include <memory> #include <grpc/support/log.h> -#include <grpc/support/port_platform.h> +#include <grpcpp/alarm.h> #include <grpcpp/completion_queue.h> #include <grpcpp/impl/grpc_library.h> #include <grpcpp/support/time.h> + +#include "src/core/lib/debug/trace.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/surface/completion_queue.h" -#include <grpc/support/log.h> -#include "src/core/lib/debug/trace.h" - namespace grpc { namespace internal { @@ -56,7 +55,7 @@ class AlarmImpl : public ::grpc::internal::CompletionQueueTag { GPR_ASSERT(grpc_cq_begin_op(cq_, this)); GRPC_CLOSURE_INIT( &on_alarm_, - [](void* arg, grpc_error* error) { + [](void* arg, grpc_error_handle error) { // queue the op on the completion queue AlarmImpl* alarm = static_cast<AlarmImpl*>(arg); alarm->Ref(); @@ -82,10 +81,10 @@ class AlarmImpl : public ::grpc::internal::CompletionQueueTag { Ref(); GRPC_CLOSURE_INIT( &on_alarm_, - [](void* arg, grpc_error* error) { + [](void* arg, grpc_error_handle error) { grpc_core::Executor::Run( GRPC_CLOSURE_CREATE( - [](void* arg, grpc_error* error) { + [](void* arg, grpc_error_handle error) { AlarmImpl* alarm = static_cast<AlarmImpl*>(arg); alarm->callback_(error == GRPC_ERROR_NONE); alarm->Unref(); diff --git a/contrib/libs/grpc/src/cpp/common/auth_property_iterator.cc b/contrib/libs/grpc/src/cpp/common/auth_property_iterator.cc index 0f380b09507..1334ea99663 100644 --- a/contrib/libs/grpc/src/cpp/common/auth_property_iterator.cc +++ b/contrib/libs/grpc/src/cpp/common/auth_property_iterator.cc @@ -16,9 +16,8 @@ * */ -#include <grpcpp/security/auth_context.h> - #include <grpc/grpc_security.h> +#include <grpcpp/security/auth_context.h> namespace grpc { diff --git a/contrib/libs/grpc/src/cpp/common/channel_arguments.cc b/contrib/libs/grpc/src/cpp/common/channel_arguments.cc index 5a5dd91b5ec..4950a800bb5 100644 --- a/contrib/libs/grpc/src/cpp/common/channel_arguments.cc +++ b/contrib/libs/grpc/src/cpp/common/channel_arguments.cc @@ -15,14 +15,14 @@ * limitations under the License. * */ -#include <grpcpp/support/channel_arguments.h> - #include <sstream> #include <grpc/impl/codegen/grpc_types.h> #include <grpc/support/log.h> #include <grpcpp/grpcpp.h> #include <grpcpp/resource_quota.h> +#include <grpcpp/support/channel_arguments.h> + #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/socket_mutator.h" @@ -66,9 +66,9 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other) } ChannelArguments::~ChannelArguments() { - grpc_core::ExecCtx exec_ctx; for (auto& arg : args_) { if (arg.type == GRPC_ARG_POINTER) { + grpc_core::ExecCtx exec_ctx; arg.value.pointer.vtable->destroy(arg.value.pointer.p); } } diff --git a/contrib/libs/grpc/src/cpp/common/channel_filter.cc b/contrib/libs/grpc/src/cpp/common/channel_filter.cc index ab56d6073fe..373aebf61b7 100644 --- a/contrib/libs/grpc/src/cpp/common/channel_filter.cc +++ b/contrib/libs/grpc/src/cpp/common/channel_filter.cc @@ -16,13 +16,16 @@ * */ -#include <string.h> - -#include "src/core/lib/channel/channel_stack.h" #include "src/cpp/common/channel_filter.h" +#include <string.h> + #include <grpcpp/impl/codegen/slice.h> +#include "src/core/lib/channel/channel_stack.h" +#include "src/core/lib/channel/channel_stack_builder.h" +#include "src/core/lib/config/core_configuration.h" + namespace grpc { // MetadataBatch @@ -32,8 +35,7 @@ grpc_linked_mdelem* MetadataBatch::AddMetadata(const string& key, grpc_linked_mdelem* storage = new grpc_linked_mdelem; storage->md = grpc_mdelem_from_slices(SliceFromCopiedString(key), SliceFromCopiedString(value)); - GRPC_LOG_IF_ERROR("MetadataBatch::AddMetadata", - grpc_metadata_batch_link_head(batch_, storage)); + GRPC_LOG_IF_ERROR("MetadataBatch::AddMetadata", batch_->LinkHead(storage)); return storage; } @@ -61,38 +63,30 @@ void CallData::SetPollsetOrPollsetSet(grpc_call_element* elem, grpc_call_stack_ignore_set_pollset_or_pollset_set(elem, pollent); } -// internal code used by RegisterChannelFilter() - namespace internal { -// Note: Implicitly initialized to nullptr due to static lifetime. -std::vector<FilterRecord>* channel_filters; - -namespace { - -bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* arg) { - const FilterRecord& filter = *static_cast<FilterRecord*>(arg); - if (filter.include_filter) { - const grpc_channel_args* args = - grpc_channel_stack_builder_get_channel_arguments(builder); - if (!filter.include_filter(*args)) return true; - } - return grpc_channel_stack_builder_prepend_filter(builder, &filter.filter, - nullptr, nullptr); +void RegisterChannelFilter( + grpc_channel_stack_type stack_type, int priority, + std::function<bool(const grpc_channel_args&)> include_filter, + const grpc_channel_filter* filter) { + auto maybe_add_filter = [include_filter, + filter](grpc_channel_stack_builder* builder) { + if (include_filter != nullptr) { + const grpc_channel_args* args = + grpc_channel_stack_builder_get_channel_arguments(builder); + if (!include_filter(*args)) return true; + } + return grpc_channel_stack_builder_prepend_filter(builder, filter, nullptr, + nullptr); + }; + grpc_core::CoreConfiguration::RegisterBuilder( + [stack_type, priority, + maybe_add_filter](grpc_core::CoreConfiguration::Builder* builder) { + builder->channel_init()->RegisterStage(stack_type, priority, + maybe_add_filter); + }); } -} // namespace - -void ChannelFilterPluginInit() { - for (size_t i = 0; i < channel_filters->size(); ++i) { - FilterRecord& filter = (*channel_filters)[i]; - grpc_channel_init_register_stage(filter.stack_type, filter.priority, - MaybeAddFilter, &filter); - } -} - -void ChannelFilterPluginShutdown() {} - } // namespace internal } // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/common/channel_filter.h b/contrib/libs/grpc/src/cpp/common/channel_filter.h index b16f06bddcf..5364895e844 100644 --- a/contrib/libs/grpc/src/cpp/common/channel_filter.h +++ b/contrib/libs/grpc/src/cpp/common/channel_filter.h @@ -19,13 +19,13 @@ #ifndef GRPCXX_CHANNEL_FILTER_H #define GRPCXX_CHANNEL_FILTER_H +#include <functional> +#include <vector> + #include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpcpp/impl/codegen/config.h> -#include <functional> -#include <vector> - #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/surface/channel_init.h" #include "src/core/lib/transport/metadata_batch.h" @@ -56,48 +56,6 @@ class MetadataBatch { /// lifetime of the gRPC call. grpc_linked_mdelem* AddMetadata(const string& key, const string& value); - class const_iterator : public std::iterator<std::bidirectional_iterator_tag, - const grpc_mdelem> { - public: - const grpc_mdelem& operator*() const { return elem_->md; } - grpc_mdelem operator->() const { return elem_->md; } - - const_iterator& operator++() { - elem_ = elem_->next; - return *this; - } - const_iterator operator++(int) { - const_iterator tmp(*this); - operator++(); - return tmp; - } - const_iterator& operator--() { - elem_ = elem_->prev; - return *this; - } - const_iterator operator--(int) { - const_iterator tmp(*this); - operator--(); - return tmp; - } - - bool operator==(const const_iterator& other) const { - return elem_ == other.elem_; - } - bool operator!=(const const_iterator& other) const { - return elem_ != other.elem_; - } - - private: - friend class MetadataBatch; - explicit const_iterator(grpc_linked_mdelem* elem) : elem_(elem) {} - - grpc_linked_mdelem* elem_; - }; - - const_iterator begin() const { return const_iterator(batch_->list.head); } - const_iterator end() const { return const_iterator(nullptr); } - private: grpc_metadata_batch* batch_; // Not owned. }; @@ -113,7 +71,7 @@ class TransportOp { grpc_transport_op* op() const { return op_; } // TODO(roth): Add a C++ wrapper for grpc_error? - grpc_error* disconnect_with_error() const { + grpc_error_handle disconnect_with_error() const { return op_->disconnect_with_error; } bool send_goaway() const { return op_->goaway_error != GRPC_ERROR_NONE; } @@ -236,8 +194,8 @@ class ChannelData { // TODO(roth): Come up with a more C++-like API for the channel element. /// Initializes the channel data. - virtual grpc_error* Init(grpc_channel_element* /*elem*/, - grpc_channel_element_args* /*args*/) { + virtual grpc_error_handle Init(grpc_channel_element* /*elem*/, + grpc_channel_element_args* /*args*/) { return GRPC_ERROR_NONE; } @@ -259,8 +217,8 @@ class CallData { // TODO(roth): Come up with a more C++-like API for the call element. /// Initializes the call data. - virtual grpc_error* Init(grpc_call_element* /*elem*/, - const grpc_call_element_args* /*args*/) { + virtual grpc_error_handle Init(grpc_call_element* /*elem*/, + const grpc_call_element_args* /*args*/) { return GRPC_ERROR_NONE; } @@ -288,8 +246,8 @@ class ChannelFilter final { public: static const size_t channel_data_size = sizeof(ChannelDataType); - static grpc_error* InitChannelElement(grpc_channel_element* elem, - grpc_channel_element_args* args) { + static grpc_error_handle InitChannelElement(grpc_channel_element* elem, + grpc_channel_element_args* args) { // Construct the object in the already-allocated memory. ChannelDataType* channel_data = new (elem->channel_data) ChannelDataType(); return channel_data->Init(elem, args); @@ -319,8 +277,8 @@ class ChannelFilter final { static const size_t call_data_size = sizeof(CallDataType); - static grpc_error* InitCallElement(grpc_call_element* elem, - const grpc_call_element_args* args) { + static grpc_error_handle InitCallElement(grpc_call_element* elem, + const grpc_call_element_args* args) { // Construct the object in the already-allocated memory. CallDataType* call_data = new (elem->call_data) CallDataType(); return call_data->Init(elem, args); @@ -348,16 +306,10 @@ class ChannelFilter final { } }; -struct FilterRecord { - grpc_channel_stack_type stack_type; - int priority; - std::function<bool(const grpc_channel_args&)> include_filter; - grpc_channel_filter filter; -}; -extern std::vector<FilterRecord>* channel_filters; - -void ChannelFilterPluginInit(); -void ChannelFilterPluginShutdown(); +void RegisterChannelFilter( + grpc_channel_stack_type stack_type, int priority, + std::function<bool(const grpc_channel_args&)> include_filter, + const grpc_channel_filter* filter); } // namespace internal @@ -375,26 +327,21 @@ template <typename ChannelDataType, typename CallDataType> void RegisterChannelFilter( const char* name, grpc_channel_stack_type stack_type, int priority, std::function<bool(const grpc_channel_args&)> include_filter) { - // If we haven't been called before, initialize channel_filters and - // call grpc_register_plugin(). - if (internal::channel_filters == nullptr) { - grpc_register_plugin(internal::ChannelFilterPluginInit, - internal::ChannelFilterPluginShutdown); - internal::channel_filters = new std::vector<internal::FilterRecord>(); - } - // Add an entry to channel_filters. The filter will be added when the - // C-core initialization code calls ChannelFilterPluginInit(). - typedef internal::ChannelFilter<ChannelDataType, CallDataType> FilterType; - internal::FilterRecord filter_record = { - stack_type, - priority, - include_filter, - {FilterType::StartTransportStreamOpBatch, FilterType::StartTransportOp, - FilterType::call_data_size, FilterType::InitCallElement, - FilterType::SetPollsetOrPollsetSet, FilterType::DestroyCallElement, - FilterType::channel_data_size, FilterType::InitChannelElement, - FilterType::DestroyChannelElement, FilterType::GetChannelInfo, name}}; - internal::channel_filters->push_back(filter_record); + using FilterType = internal::ChannelFilter<ChannelDataType, CallDataType>; + static const grpc_channel_filter filter = { + FilterType::StartTransportStreamOpBatch, + FilterType::StartTransportOp, + FilterType::call_data_size, + FilterType::InitCallElement, + FilterType::SetPollsetOrPollsetSet, + FilterType::DestroyCallElement, + FilterType::channel_data_size, + FilterType::InitChannelElement, + FilterType::DestroyChannelElement, + FilterType::GetChannelInfo, + name}; + grpc::internal::RegisterChannelFilter(stack_type, priority, + std::move(include_filter), &filter); } } // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc b/contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc index 67745590745..f4834214d0d 100644 --- a/contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc +++ b/contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc @@ -15,13 +15,12 @@ * */ -#include <grpcpp/completion_queue.h> - #include <memory> #include <grpc/grpc.h> #include <grpc/support/cpu.h> #include <grpc/support/log.h> +#include <grpcpp/completion_queue.h> #include <grpcpp/impl/grpc_library.h> #include <grpcpp/support/time.h> @@ -53,7 +52,8 @@ struct CallbackAlternativeCQ { refs++; if (refs == 1) { cq = new CompletionQueue; - int num_nexting_threads = GPR_CLAMP(gpr_cpu_num_cores() / 2, 2, 16); + int num_nexting_threads = + grpc_core::Clamp(gpr_cpu_num_cores() / 2, 2u, 16u); nexting_threads = new std::vector<grpc_core::Thread>; for (int i = 0; i < num_nexting_threads; i++) { nexting_threads->emplace_back( @@ -89,8 +89,7 @@ struct CallbackAlternativeCQ { // hold any application locks before executing the callback, // and cannot be entered recursively. auto* functor = - static_cast<grpc_experimental_completion_queue_functor*>( - ev.tag); + static_cast<grpc_completion_queue_functor*>(ev.tag); functor->functor_run(functor, ev.success); } }, diff --git a/contrib/libs/grpc/src/cpp/common/core_codegen.cc b/contrib/libs/grpc/src/cpp/common/core_codegen.cc index 75383ed5110..da964f66628 100644 --- a/contrib/libs/grpc/src/cpp/common/core_codegen.cc +++ b/contrib/libs/grpc/src/cpp/common/core_codegen.cc @@ -16,7 +16,7 @@ * */ -#include <grpcpp/impl/codegen/core_codegen.h> +#include <grpc/support/port_platform.h> #include <stdlib.h> @@ -27,8 +27,8 @@ #include <grpc/slice_buffer.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include <grpc/support/port_platform.h> #include <grpc/support/sync.h> +#include <grpcpp/impl/codegen/core_codegen.h> #include <grpcpp/support/config.h> #include "src/core/lib/profiling/timers.h" @@ -118,6 +118,10 @@ grpc_call_error CoreCodegen::grpc_call_cancel_with_status( void* reserved) { return ::grpc_call_cancel_with_status(call, status, description, reserved); } + +int CoreCodegen::grpc_call_failed_before_recv_message(const grpc_call* c) { + return ::grpc_call_failed_before_recv_message(c); +} void CoreCodegen::grpc_call_ref(grpc_call* call) { ::grpc_call_ref(call); } void CoreCodegen::grpc_call_unref(grpc_call* call) { ::grpc_call_unref(call); } void* CoreCodegen::grpc_call_arena_alloc(grpc_call* call, size_t length) { diff --git a/contrib/libs/grpc/src/cpp/common/secure_channel_arguments.cc b/contrib/libs/grpc/src/cpp/common/secure_channel_arguments.cc index 844bc627ab3..c9b1d4ab3bd 100644 --- a/contrib/libs/grpc/src/cpp/common/secure_channel_arguments.cc +++ b/contrib/libs/grpc/src/cpp/common/secure_channel_arguments.cc @@ -16,9 +16,9 @@ * */ +#include <grpc/grpc_security.h> #include <grpcpp/support/channel_arguments.h> -#include <grpc/grpc_security.h> #include "src/core/lib/channel/channel_args.h" namespace grpc { diff --git a/contrib/libs/grpc/src/cpp/common/secure_create_auth_context.cc b/contrib/libs/grpc/src/cpp/common/secure_create_auth_context.cc index 908c46629e6..6633374b65b 100644 --- a/contrib/libs/grpc/src/cpp/common/secure_create_auth_context.cc +++ b/contrib/libs/grpc/src/cpp/common/secure_create_auth_context.cc @@ -20,6 +20,7 @@ #include <grpc/grpc.h> #include <grpc/grpc_security.h> #include <grpcpp/security/auth_context.h> + #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/cpp/common/secure_auth_context.h" diff --git a/contrib/libs/grpc/src/cpp/common/tls_certificate_provider.cc b/contrib/libs/grpc/src/cpp/common/tls_certificate_provider.cc index 8e99b571a18..073abae7d52 100644 --- a/contrib/libs/grpc/src/cpp/common/tls_certificate_provider.cc +++ b/contrib/libs/grpc/src/cpp/common/tls_certificate_provider.cc @@ -14,12 +14,12 @@ // limitations under the License. // +#include "y_absl/container/inlined_vector.h" + #include <grpc/grpc_security.h> #include <grpc/support/alloc.h> #include <grpcpp/security/tls_certificate_provider.h> -#include "y_absl/container/inlined_vector.h" - namespace grpc { namespace experimental { diff --git a/contrib/libs/grpc/src/cpp/common/tls_certificate_verifier.cc b/contrib/libs/grpc/src/cpp/common/tls_certificate_verifier.cc new file mode 100644 index 00000000000..7e51934e01c --- /dev/null +++ b/contrib/libs/grpc/src/cpp/common/tls_certificate_verifier.cc @@ -0,0 +1,244 @@ +// +// Copyright 2021 gRPC authors. +// +// 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. +// + +#include "y_absl/container/inlined_vector.h" +#include "y_absl/status/status.h" + +#include <grpc/grpc_security.h> +#include <grpc/support/alloc.h> +#include <grpc/support/string_util.h> +#include <grpcpp/security/tls_certificate_verifier.h> + +namespace grpc { +namespace experimental { + +static internal::GrpcLibraryInitializer g_gli_initializer; + +TlsCustomVerificationCheckRequest::TlsCustomVerificationCheckRequest( + grpc_tls_custom_verification_check_request* request) + : c_request_(request) { + GPR_ASSERT(c_request_ != nullptr); +} + +grpc::string_ref TlsCustomVerificationCheckRequest::target_name() const { + return c_request_->target_name != nullptr ? c_request_->target_name : ""; +} + +grpc::string_ref TlsCustomVerificationCheckRequest::peer_cert() const { + return c_request_->peer_info.peer_cert != nullptr + ? c_request_->peer_info.peer_cert + : ""; +} + +grpc::string_ref TlsCustomVerificationCheckRequest::peer_cert_full_chain() + const { + return c_request_->peer_info.peer_cert_full_chain != nullptr + ? c_request_->peer_info.peer_cert_full_chain + : ""; +} + +grpc::string_ref TlsCustomVerificationCheckRequest::common_name() const { + return c_request_->peer_info.common_name != nullptr + ? c_request_->peer_info.common_name + : ""; +} + +std::vector<grpc::string_ref> TlsCustomVerificationCheckRequest::uri_names() + const { + std::vector<grpc::string_ref> uri_names; + for (size_t i = 0; i < c_request_->peer_info.san_names.uri_names_size; ++i) { + uri_names.emplace_back(c_request_->peer_info.san_names.uri_names[i]); + } + return uri_names; +} + +std::vector<grpc::string_ref> TlsCustomVerificationCheckRequest::dns_names() + const { + std::vector<grpc::string_ref> dns_names; + for (size_t i = 0; i < c_request_->peer_info.san_names.dns_names_size; ++i) { + dns_names.emplace_back(c_request_->peer_info.san_names.dns_names[i]); + } + return dns_names; +} + +std::vector<grpc::string_ref> TlsCustomVerificationCheckRequest::email_names() + const { + std::vector<grpc::string_ref> email_names; + for (size_t i = 0; i < c_request_->peer_info.san_names.email_names_size; + ++i) { + email_names.emplace_back(c_request_->peer_info.san_names.email_names[i]); + } + return email_names; +} + +std::vector<grpc::string_ref> TlsCustomVerificationCheckRequest::ip_names() + const { + std::vector<grpc::string_ref> ip_names; + for (size_t i = 0; i < c_request_->peer_info.san_names.ip_names_size; ++i) { + ip_names.emplace_back(c_request_->peer_info.san_names.ip_names[i]); + } + return ip_names; +} + +CertificateVerifier::CertificateVerifier(grpc_tls_certificate_verifier* v) + : verifier_(v) { + g_gli_initializer.summon(); +} + +CertificateVerifier::~CertificateVerifier() { + grpc_tls_certificate_verifier_release(verifier_); +} + +bool CertificateVerifier::Verify(TlsCustomVerificationCheckRequest* request, + std::function<void(grpc::Status)> callback, + grpc::Status* sync_status) { + GPR_ASSERT(request != nullptr); + GPR_ASSERT(request->c_request() != nullptr); + { + internal::MutexLock lock(&mu_); + request_map_.emplace(request->c_request(), std::move(callback)); + } + grpc_status_code status_code = GRPC_STATUS_OK; + char* error_details = nullptr; + bool is_done = grpc_tls_certificate_verifier_verify( + verifier_, request->c_request(), &AsyncCheckDone, this, &status_code, + &error_details); + if (is_done) { + if (status_code != GRPC_STATUS_OK) { + *sync_status = grpc::Status(static_cast<grpc::StatusCode>(status_code), + error_details); + } + internal::MutexLock lock(&mu_); + request_map_.erase(request->c_request()); + } + gpr_free(error_details); + return is_done; +} + +void CertificateVerifier::Cancel(TlsCustomVerificationCheckRequest* request) { + GPR_ASSERT(request != nullptr); + GPR_ASSERT(request->c_request() != nullptr); + grpc_tls_certificate_verifier_cancel(verifier_, request->c_request()); +} + +void CertificateVerifier::AsyncCheckDone( + grpc_tls_custom_verification_check_request* request, void* callback_arg, + grpc_status_code status, const char* error_details) { + auto* self = static_cast<CertificateVerifier*>(callback_arg); + std::function<void(grpc::Status)> callback; + { + internal::MutexLock lock(&self->mu_); + auto it = self->request_map_.find(request); + if (it != self->request_map_.end()) { + callback = std::move(it->second); + self->request_map_.erase(it); + } + } + if (callback != nullptr) { + grpc::Status return_status; + if (status != GRPC_STATUS_OK) { + return_status = + grpc::Status(static_cast<grpc::StatusCode>(status), error_details); + } + callback(return_status); + } +} + +ExternalCertificateVerifier::ExternalCertificateVerifier() { + base_ = new grpc_tls_certificate_verifier_external(); + base_->user_data = this; + base_->verify = VerifyInCoreExternalVerifier; + base_->cancel = CancelInCoreExternalVerifier; + base_->destruct = DestructInCoreExternalVerifier; +} + +ExternalCertificateVerifier::~ExternalCertificateVerifier() { delete base_; } + +int ExternalCertificateVerifier::VerifyInCoreExternalVerifier( + void* user_data, grpc_tls_custom_verification_check_request* request, + grpc_tls_on_custom_verification_check_done_cb callback, void* callback_arg, + grpc_status_code* sync_status, char** sync_error_details) { + auto* self = static_cast<ExternalCertificateVerifier*>(user_data); + TlsCustomVerificationCheckRequest* cpp_request = nullptr; + { + internal::MutexLock lock(&self->mu_); + auto pair = self->request_map_.emplace( + request, AsyncRequestState(callback, callback_arg, request)); + GPR_ASSERT(pair.second); + cpp_request = &pair.first->second.cpp_request; + } + grpc::Status sync_current_verifier_status; + bool is_done = self->Verify( + cpp_request, + [self, request](grpc::Status status) { + grpc_tls_on_custom_verification_check_done_cb callback = nullptr; + void* callback_arg = nullptr; + { + internal::MutexLock lock(&self->mu_); + auto it = self->request_map_.find(request); + if (it != self->request_map_.end()) { + callback = it->second.callback; + callback_arg = it->second.callback_arg; + self->request_map_.erase(it); + } + } + if (callback != nullptr) { + callback(request, callback_arg, + static_cast<grpc_status_code>(status.error_code()), + status.error_message().c_str()); + } + }, + &sync_current_verifier_status); + if (is_done) { + if (!sync_current_verifier_status.ok()) { + *sync_status = static_cast<grpc_status_code>( + sync_current_verifier_status.error_code()); + *sync_error_details = + gpr_strdup(sync_current_verifier_status.error_message().c_str()); + } + internal::MutexLock lock(&self->mu_); + self->request_map_.erase(request); + } + return is_done; +} + +void ExternalCertificateVerifier::CancelInCoreExternalVerifier( + void* user_data, grpc_tls_custom_verification_check_request* request) { + auto* self = static_cast<ExternalCertificateVerifier*>(user_data); + TlsCustomVerificationCheckRequest* cpp_request = nullptr; + { + internal::MutexLock lock(&self->mu_); + auto it = self->request_map_.find(request); + if (it != self->request_map_.end()) { + cpp_request = &it->second.cpp_request; + } + } + if (cpp_request != nullptr) { + self->Cancel(cpp_request); + } +} + +void ExternalCertificateVerifier::DestructInCoreExternalVerifier( + void* user_data) { + auto* self = static_cast<ExternalCertificateVerifier*>(user_data); + delete self; +} + +HostNameCertificateVerifier::HostNameCertificateVerifier() + : CertificateVerifier(grpc_tls_certificate_verifier_host_name_create()) {} + +} // namespace experimental +} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/common/tls_credentials_options.cc b/contrib/libs/grpc/src/cpp/common/tls_credentials_options.cc index d612bd062eb..e669f600b5e 100644 --- a/contrib/libs/grpc/src/cpp/common/tls_credentials_options.cc +++ b/contrib/libs/grpc/src/cpp/common/tls_credentials_options.cc @@ -16,114 +16,15 @@ * */ +#include "y_absl/container/inlined_vector.h" + #include <grpc/grpc_security.h> #include <grpc/support/alloc.h> #include <grpcpp/security/tls_credentials_options.h> -#include "y_absl/container/inlined_vector.h" -#include "src/cpp/common/tls_credentials_options_util.h" - namespace grpc { namespace experimental { -/** gRPC TLS server authorization check arg API implementation **/ -TlsServerAuthorizationCheckArg::TlsServerAuthorizationCheckArg( - grpc_tls_server_authorization_check_arg* arg) - : c_arg_(arg) { - GPR_ASSERT(c_arg_ != nullptr); - if (c_arg_->context != nullptr) { - gpr_log(GPR_ERROR, "c_arg context has already been set"); - } - c_arg_->context = static_cast<void*>(this); - c_arg_->destroy_context = &TlsServerAuthorizationCheckArgDestroyContext; -} - -TlsServerAuthorizationCheckArg::~TlsServerAuthorizationCheckArg() {} - -void* TlsServerAuthorizationCheckArg::cb_user_data() const { - return c_arg_->cb_user_data; -} - -int TlsServerAuthorizationCheckArg::success() const { return c_arg_->success; } - -TString TlsServerAuthorizationCheckArg::target_name() const { - TString cpp_target_name(c_arg_->target_name); - return cpp_target_name; -} - -TString TlsServerAuthorizationCheckArg::peer_cert() const { - TString cpp_peer_cert(c_arg_->peer_cert); - return cpp_peer_cert; -} - -TString TlsServerAuthorizationCheckArg::peer_cert_full_chain() const { - TString cpp_peer_cert_full_chain(c_arg_->peer_cert_full_chain); - return cpp_peer_cert_full_chain; -} - -grpc_status_code TlsServerAuthorizationCheckArg::status() const { - return c_arg_->status; -} - -TString TlsServerAuthorizationCheckArg::error_details() const { - return c_arg_->error_details->error_details(); -} - -void TlsServerAuthorizationCheckArg::set_cb_user_data(void* cb_user_data) { - c_arg_->cb_user_data = cb_user_data; -} - -void TlsServerAuthorizationCheckArg::set_success(int success) { - c_arg_->success = success; -} - -void TlsServerAuthorizationCheckArg::set_target_name( - const TString& target_name) { - c_arg_->target_name = gpr_strdup(target_name.c_str()); -} - -void TlsServerAuthorizationCheckArg::set_peer_cert( - const TString& peer_cert) { - c_arg_->peer_cert = gpr_strdup(peer_cert.c_str()); -} - -void TlsServerAuthorizationCheckArg::set_peer_cert_full_chain( - const TString& peer_cert_full_chain) { - c_arg_->peer_cert_full_chain = gpr_strdup(peer_cert_full_chain.c_str()); -} - -void TlsServerAuthorizationCheckArg::set_status(grpc_status_code status) { - c_arg_->status = status; -} - -void TlsServerAuthorizationCheckArg::set_error_details( - const TString& error_details) { - c_arg_->error_details->set_error_details(error_details.c_str()); -} - -void TlsServerAuthorizationCheckArg::OnServerAuthorizationCheckDoneCallback() { - if (c_arg_->cb == nullptr) { - gpr_log(GPR_ERROR, "server authorizaton check arg callback API is nullptr"); - return; - } - c_arg_->cb(c_arg_); -} - -TlsServerAuthorizationCheckConfig::TlsServerAuthorizationCheckConfig( - std::shared_ptr<TlsServerAuthorizationCheckInterface> - server_authorization_check_interface) - : server_authorization_check_interface_( - std::move(server_authorization_check_interface)) { - c_config_ = grpc_tls_server_authorization_check_config_create( - nullptr, &TlsServerAuthorizationCheckConfigCSchedule, - &TlsServerAuthorizationCheckConfigCCancel, nullptr); - c_config_->set_context(static_cast<void*>(this)); -} - -TlsServerAuthorizationCheckConfig::~TlsServerAuthorizationCheckConfig() { - grpc_tls_server_authorization_check_config_release(c_config_); -} - TlsCredentialsOptions::TlsCredentialsOptions() { c_credentials_options_ = grpc_tls_credentials_options_create(); } @@ -158,22 +59,27 @@ void TlsCredentialsOptions::set_identity_cert_name( c_credentials_options_, identity_cert_name.c_str()); } -void TlsChannelCredentialsOptions::set_server_verification_option( - grpc_tls_server_verification_option server_verification_option) { +void TlsCredentialsOptions::set_certificate_verifier( + std::shared_ptr<CertificateVerifier> certificate_verifier) { + certificate_verifier_ = std::move(certificate_verifier); + if (certificate_verifier_ != nullptr) { + grpc_tls_credentials_options_set_certificate_verifier( + c_credentials_options_, certificate_verifier_->c_verifier()); + } +} + +void TlsCredentialsOptions::set_check_call_host(bool check_call_host) { grpc_tls_credentials_options* options = c_credentials_options(); GPR_ASSERT(options != nullptr); - grpc_tls_credentials_options_set_server_verification_option( - options, server_verification_option); + grpc_tls_credentials_options_set_check_call_host(options, check_call_host); } -void TlsChannelCredentialsOptions::set_server_authorization_check_config( - std::shared_ptr<TlsServerAuthorizationCheckConfig> config) { +void TlsChannelCredentialsOptions::set_verify_server_certs( + bool verify_server_certs) { grpc_tls_credentials_options* options = c_credentials_options(); GPR_ASSERT(options != nullptr); - if (config != nullptr) { - grpc_tls_credentials_options_set_server_authorization_check_config( - options, config->c_config()); - } + grpc_tls_credentials_options_set_verify_server_cert(options, + verify_server_certs); } void TlsServerCredentialsOptions::set_cert_request_type( diff --git a/contrib/libs/grpc/src/cpp/common/tls_credentials_options_util.cc b/contrib/libs/grpc/src/cpp/common/tls_credentials_options_util.cc deleted file mode 100644 index 920f897bd73..00000000000 --- a/contrib/libs/grpc/src/cpp/common/tls_credentials_options_util.cc +++ /dev/null @@ -1,76 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * 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. - * - */ - -#include "y_absl/container/inlined_vector.h" - -#include <grpcpp/security/tls_credentials_options.h> - -#include "src/cpp/common/tls_credentials_options_util.h" - -namespace grpc { -namespace experimental { - -/** The C schedule and cancel functions for the server authorization check - * config. They populate a C server authorization check arg with the result - * of a C++ server authorization check schedule/cancel API. **/ -int TlsServerAuthorizationCheckConfigCSchedule( - void* /*config_user_data*/, grpc_tls_server_authorization_check_arg* arg) { - if (arg == nullptr || arg->config == nullptr || - arg->config->context() == nullptr) { - gpr_log(GPR_ERROR, - "server authorization check arg was not properly initialized"); - return 1; - } - TlsServerAuthorizationCheckConfig* cpp_config = - static_cast<TlsServerAuthorizationCheckConfig*>(arg->config->context()); - TlsServerAuthorizationCheckArg* cpp_arg = - new TlsServerAuthorizationCheckArg(arg); - int schedule_result = cpp_config->Schedule(cpp_arg); - return schedule_result; -} - -void TlsServerAuthorizationCheckConfigCCancel( - void* /*config_user_data*/, grpc_tls_server_authorization_check_arg* arg) { - if (arg == nullptr || arg->config == nullptr || - arg->config->context() == nullptr) { - gpr_log(GPR_ERROR, - "server authorization check arg was not properly initialized"); - return; - } - if (arg->context == nullptr) { - gpr_log(GPR_ERROR, - "server authorization check arg schedule has already completed"); - return; - } - TlsServerAuthorizationCheckConfig* cpp_config = - static_cast<TlsServerAuthorizationCheckConfig*>(arg->config->context()); - TlsServerAuthorizationCheckArg* cpp_arg = - static_cast<TlsServerAuthorizationCheckArg*>(arg->context); - cpp_config->Cancel(cpp_arg); -} - -void TlsServerAuthorizationCheckArgDestroyContext(void* context) { - if (context != nullptr) { - TlsServerAuthorizationCheckArg* cpp_arg = - static_cast<TlsServerAuthorizationCheckArg*>(context); - delete cpp_arg; - } -} - -} // namespace experimental -} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/common/tls_credentials_options_util.h b/contrib/libs/grpc/src/cpp/common/tls_credentials_options_util.h deleted file mode 100644 index d6247219fb7..00000000000 --- a/contrib/libs/grpc/src/cpp/common/tls_credentials_options_util.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * 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 GRPC_INTERNAL_CPP_COMMON_TLS_CREDENTIALS_OPTIONS_UTIL_H -#define GRPC_INTERNAL_CPP_COMMON_TLS_CREDENTIALS_OPTIONS_UTIL_H - -#include <grpc/grpc_security.h> -#include <grpcpp/security/tls_credentials_options.h> - -#include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" - -namespace grpc { -namespace experimental { - -/** The following 2 functions convert the user-provided schedule or cancel - * functions into C style schedule or cancel functions. These are internal - * functions, not meant to be accessed by the user. **/ -int TlsServerAuthorizationCheckConfigCSchedule( - void* config_user_data, grpc_tls_server_authorization_check_arg* arg); - -void TlsServerAuthorizationCheckConfigCCancel( - void* config_user_data, grpc_tls_server_authorization_check_arg* arg); - -void TlsServerAuthorizationCheckArgDestroyContext(void* context); - -} // namespace experimental -} // namespace grpc - -#endif // GRPC_INTERNAL_CPP_COMMON_TLS_CREDENTIALS_OPTIONS_UTIL_H diff --git a/contrib/libs/grpc/src/cpp/common/validate_service_config.cc b/contrib/libs/grpc/src/cpp/common/validate_service_config.cc index f63cfbc68c9..fa0c3937924 100644 --- a/contrib/libs/grpc/src/cpp/common/validate_service_config.cc +++ b/contrib/libs/grpc/src/cpp/common/validate_service_config.cc @@ -19,18 +19,18 @@ #include <grpc/grpc.h> #include <grpcpp/support/validate_service_config.h> -#include "src/core/ext/filters/client_channel/service_config.h" +#include "src/core/ext/service_config/service_config.h" namespace grpc { namespace experimental { TString ValidateServiceConfigJSON(const TString& service_config_json) { grpc_init(); - grpc_error* error = GRPC_ERROR_NONE; + grpc_error_handle error = GRPC_ERROR_NONE; grpc_core::ServiceConfig::Create(/*args=*/nullptr, service_config_json.c_str(), &error); TString return_value; if (error != GRPC_ERROR_NONE) { - return_value = grpc_error_string(error); + return_value = grpc_error_std_string(error); GRPC_ERROR_UNREF(error); } grpc_shutdown(); diff --git a/contrib/libs/grpc/src/cpp/common/version_cc.cc b/contrib/libs/grpc/src/cpp/common/version_cc.cc index cb9895b58f8..8054bda78bc 100644 --- a/contrib/libs/grpc/src/cpp/common/version_cc.cc +++ b/contrib/libs/grpc/src/cpp/common/version_cc.cc @@ -22,5 +22,5 @@ #include <grpcpp/grpcpp.h> namespace grpc { -TString Version() { return "1.37.1"; } +TString Version() { return "1.43.2"; } } // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.cc b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.cc index 2a610ff8a92..6c13a0c9cfc 100644 --- a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.cc +++ b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.cc @@ -16,13 +16,13 @@ * */ +#include "src/cpp/ext/proto_server_reflection.h" + #include <unordered_set> #include <vector> #include <grpcpp/grpcpp.h> -#include "src/cpp/ext/proto_server_reflection.h" - using grpc::Status; using grpc::StatusCode; using grpc::reflection::v1alpha::ErrorResponse; diff --git a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.h b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.h index 2d17eed95a8..86982f3ffa2 100644 --- a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.h +++ b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.h @@ -23,6 +23,7 @@ #include <vector> #include <grpcpp/grpcpp.h> + #include "src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.h" namespace grpc { diff --git a/contrib/libs/grpc/src/cpp/server/async_generic_service.cc b/contrib/libs/grpc/src/cpp/server/async_generic_service.cc index 07697a52d1f..fdb3da830c5 100644 --- a/contrib/libs/grpc/src/cpp/server/async_generic_service.cc +++ b/contrib/libs/grpc/src/cpp/server/async_generic_service.cc @@ -17,7 +17,6 @@ */ #include <grpcpp/generic/async_generic_service.h> - #include <grpcpp/server.h> namespace grpc { diff --git a/contrib/libs/grpc/src/cpp/server/channelz/channelz_service.h b/contrib/libs/grpc/src/cpp/server/channelz/channelz_service.h index b4a66ba1c66..824f0a9fe17 100644 --- a/contrib/libs/grpc/src/cpp/server/channelz/channelz_service.h +++ b/contrib/libs/grpc/src/cpp/server/channelz/channelz_service.h @@ -22,6 +22,7 @@ #include <grpc/support/port_platform.h> #include <grpcpp/grpcpp.h> + #include "src/proto/grpc/channelz/channelz.grpc.pb.h" namespace grpc { diff --git a/contrib/libs/grpc/src/cpp/server/health/default_health_check_service.cc b/contrib/libs/grpc/src/cpp/server/health/default_health_check_service.cc index f39270924b0..52341c1612d 100644 --- a/contrib/libs/grpc/src/cpp/server/health/default_health_check_service.cc +++ b/contrib/libs/grpc/src/cpp/server/health/default_health_check_service.cc @@ -16,6 +16,8 @@ * */ +#include "src/cpp/server/health/default_health_check_service.h" + #include <memory> #include "y_absl/memory/memory.h" @@ -26,9 +28,7 @@ #include <grpc/support/log.h> #include <grpcpp/impl/codegen/method_handler.h> -#include "src/cpp/server/health/default_health_check_service.h" #include "src/proto/grpc/health/v1/health.upb.h" -#include "upb/upb.hpp" #define MAX_SERVICE_NAME_LENGTH 200 @@ -202,28 +202,16 @@ void DefaultHealthCheckService::HealthCheckServiceImpl::Serve(void* arg) { bool DefaultHealthCheckService::HealthCheckServiceImpl::DecodeRequest( const ByteBuffer& request, TString* service_name) { - std::vector<Slice> slices; - if (!request.Dump(&slices).ok()) return false; + Slice slice; + if (!request.DumpToSingleSlice(&slice).ok()) return false; uint8_t* request_bytes = nullptr; size_t request_size = 0; - if (slices.size() == 1) { - request_bytes = const_cast<uint8_t*>(slices[0].begin()); - request_size = slices[0].size(); - } else if (slices.size() > 1) { - request_bytes = static_cast<uint8_t*>(gpr_malloc(request.Length())); - uint8_t* copy_to = request_bytes; - for (size_t i = 0; i < slices.size(); i++) { - memcpy(copy_to, slices[i].begin(), slices[i].size()); - copy_to += slices[i].size(); - } - } + request_bytes = const_cast<uint8_t*>(slice.begin()); + request_size = slice.size(); upb::Arena arena; grpc_health_v1_HealthCheckRequest* request_struct = grpc_health_v1_HealthCheckRequest_parse( reinterpret_cast<char*>(request_bytes), request_size, arena.ptr()); - if (slices.size() > 1) { - gpr_free(request_bytes); - } if (request_struct == nullptr) { return false; } diff --git a/contrib/libs/grpc/src/cpp/server/insecure_server_credentials.cc b/contrib/libs/grpc/src/cpp/server/insecure_server_credentials.cc index 4eb492e0732..133647a5ed1 100644 --- a/contrib/libs/grpc/src/cpp/server/insecure_server_credentials.cc +++ b/contrib/libs/grpc/src/cpp/server/insecure_server_credentials.cc @@ -16,10 +16,9 @@ * */ -#include <grpcpp/security/server_credentials.h> - #include <grpc/grpc.h> #include <grpc/support/log.h> +#include <grpcpp/security/server_credentials.h> namespace grpc { namespace { diff --git a/contrib/libs/grpc/src/cpp/server/load_reporter/get_cpu_stats_linux.cc b/contrib/libs/grpc/src/cpp/server/load_reporter/get_cpu_stats_linux.cc index 561d4f50482..f778b137855 100644 --- a/contrib/libs/grpc/src/cpp/server/load_reporter/get_cpu_stats_linux.cc +++ b/contrib/libs/grpc/src/cpp/server/load_reporter/get_cpu_stats_linux.cc @@ -20,6 +20,8 @@ #ifdef GPR_LINUX +#include <inttypes.h> + #include <cstdio> #include "src/cpp/server/load_reporter/get_cpu_stats.h" @@ -32,7 +34,8 @@ std::pair<uint64_t, uint64_t> GetCpuStatsImpl() { FILE* fp; fp = fopen("/proc/stat", "r"); uint64_t user, nice, system, idle; - if (fscanf(fp, "cpu %lu %lu %lu %lu", &user, &nice, &system, &idle) != 4) { + if (fscanf(fp, "cpu %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, &user, + &nice, &system, &idle) != 4) { // Something bad happened with the information, so assume it's all invalid user = nice = system = idle = 0; } diff --git a/contrib/libs/grpc/src/cpp/server/load_reporter/get_cpu_stats_windows.cc b/contrib/libs/grpc/src/cpp/server/load_reporter/get_cpu_stats_windows.cc index 0a98e848a2c..c03daddb35b 100644 --- a/contrib/libs/grpc/src/cpp/server/load_reporter/get_cpu_stats_windows.cc +++ b/contrib/libs/grpc/src/cpp/server/load_reporter/get_cpu_stats_windows.cc @@ -21,6 +21,7 @@ #ifdef GPR_WINDOWS #include <windows.h> + #include <cstdint> #include "src/cpp/server/load_reporter/get_cpu_stats.h" diff --git a/contrib/libs/grpc/src/cpp/server/load_reporter/load_data_store.cc b/contrib/libs/grpc/src/cpp/server/load_reporter/load_data_store.cc index 16542bfddf6..78e6c328644 100644 --- a/contrib/libs/grpc/src/cpp/server/load_reporter/load_data_store.cc +++ b/contrib/libs/grpc/src/cpp/server/load_reporter/load_data_store.cc @@ -18,14 +18,16 @@ #include <grpc/impl/codegen/port_platform.h> +#include "src/cpp/server/load_reporter/load_data_store.h" + #include <stdio.h> + #include <cstdlib> #include <set> #include <unordered_map> #include <vector> #include "src/core/lib/iomgr/socket_utils.h" -#include "src/cpp/server/load_reporter/load_data_store.h" namespace grpc { namespace load_reporter { diff --git a/contrib/libs/grpc/src/cpp/server/load_reporter/util.cc b/contrib/libs/grpc/src/cpp/server/load_reporter/util.cc index 24ad9f3f248..4b4e778a62e 100644 --- a/contrib/libs/grpc/src/cpp/server/load_reporter/util.cc +++ b/contrib/libs/grpc/src/cpp/server/load_reporter/util.cc @@ -18,11 +18,10 @@ #include <grpc/impl/codegen/port_platform.h> -#include <grpcpp/ext/server_load_reporting.h> - #include <cmath> #include <grpc/support/log.h> +#include <grpcpp/ext/server_load_reporting.h> namespace grpc { namespace load_reporter { diff --git a/contrib/libs/grpc/src/cpp/server/secure_server_credentials.cc b/contrib/libs/grpc/src/cpp/server/secure_server_credentials.cc index b6ea87f4fe1..819a12e294c 100644 --- a/contrib/libs/grpc/src/cpp/server/secure_server_credentials.cc +++ b/contrib/libs/grpc/src/cpp/server/secure_server_credentials.cc @@ -16,6 +16,8 @@ * */ +#include "src/cpp/server/secure_server_credentials.h" + #include <functional> #include <map> #include <memory> @@ -25,7 +27,6 @@ #include <grpcpp/security/auth_metadata_processor.h> #include "src/cpp/common/secure_auth_context.h" -#include "src/cpp/server/secure_server_credentials.h" namespace grpc { @@ -74,7 +75,6 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( grpc_metadata md_entry; md_entry.key = SliceReferencingString(consumed.first); md_entry.value = SliceReferencingString(consumed.second); - md_entry.flags = 0; consumed_md.push_back(md_entry); } std::vector<grpc_metadata> response_md; @@ -82,7 +82,6 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( grpc_metadata md_entry; md_entry.key = SliceReferencingString(response.first); md_entry.value = SliceReferencingString(response.second); - md_entry.flags = 0; response_md.push_back(md_entry); } auto consumed_md_data = consumed_md.empty() ? nullptr : &consumed_md[0]; diff --git a/contrib/libs/grpc/src/cpp/server/secure_server_credentials.h b/contrib/libs/grpc/src/cpp/server/secure_server_credentials.h index f2b65c28646..95b4cab9587 100644 --- a/contrib/libs/grpc/src/cpp/server/secure_server_credentials.h +++ b/contrib/libs/grpc/src/cpp/server/secure_server_credentials.h @@ -21,11 +21,10 @@ #include <memory> +#include <grpc/grpc_security.h> #include <grpcpp/security/server_credentials.h> #include <grpcpp/security/tls_credentials_options.h> -#include <grpc/grpc_security.h> - #include "src/cpp/server/thread_pool_interface.h" namespace grpc { diff --git a/contrib/libs/grpc/src/cpp/server/server_builder.cc b/contrib/libs/grpc/src/cpp/server/server_builder.cc index 502d4f20ae6..abe95fd8343 100644 --- a/contrib/libs/grpc/src/cpp/server/server_builder.cc +++ b/contrib/libs/grpc/src/cpp/server/server_builder.cc @@ -16,15 +16,14 @@ * */ -#include <grpcpp/server_builder.h> +#include <utility> #include <grpc/support/cpu.h> #include <grpc/support/log.h> #include <grpcpp/impl/service_type.h> #include <grpcpp/resource_quota.h> #include <grpcpp/server.h> - -#include <utility> +#include <grpcpp/server_builder.h> #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gpr/string.h" @@ -102,38 +101,23 @@ ServerBuilder& ServerBuilder::RegisterAsyncGenericService( return *this; } -#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL ServerBuilder& ServerBuilder::RegisterCallbackGenericService( CallbackGenericService* service) { if (generic_service_ || callback_generic_service_) { gpr_log(GPR_ERROR, "Adding multiple generic services is unsupported for now. " "Dropping the service %p", - (void*)service); + service); } else { callback_generic_service_ = service; } return *this; } -#else -ServerBuilder& ServerBuilder::experimental_type::RegisterCallbackGenericService( - experimental::CallbackGenericService* service) { - if (builder_->generic_service_ || builder_->callback_generic_service_) { - gpr_log(GPR_ERROR, - "Adding multiple generic services is unsupported for now. " - "Dropping the service %p", - service); - } else { - builder_->callback_generic_service_ = service; - } - return *builder_; -} -#endif -ServerBuilder& ServerBuilder::experimental_type::SetContextAllocator( +ServerBuilder& ServerBuilder::SetContextAllocator( std::unique_ptr<grpc::ContextAllocator> context_allocator) { - builder_->context_allocator_ = std::move(context_allocator); - return *builder_; + context_allocator_ = std::move(context_allocator); + return *this; } std::unique_ptr<grpc::experimental::ExternalConnectionAcceptor> @@ -149,6 +133,12 @@ ServerBuilder::experimental_type::AddExternalConnectionAcceptor( return builder_->acceptors_.back()->GetAcceptor(); } +void ServerBuilder::experimental_type::SetAuthorizationPolicyProvider( + std::shared_ptr<experimental::AuthorizationPolicyProviderInterface> + provider) { + builder_->authorization_provider_ = std::move(provider); +} + ServerBuilder& ServerBuilder::SetOption( std::unique_ptr<ServerBuilderOption> option) { options_.push_back(std::move(option)); @@ -177,9 +167,9 @@ ServerBuilder& ServerBuilder::SetSyncServerOption( ServerBuilder& ServerBuilder::SetCompressionAlgorithmSupportStatus( grpc_compression_algorithm algorithm, bool enabled) { if (enabled) { - GPR_BITSET(&enabled_compression_algorithms_bitset_, algorithm); + grpc_core::SetBit(&enabled_compression_algorithms_bitset_, algorithm); } else { - GPR_BITCLEAR(&enabled_compression_algorithms_bitset_, algorithm); + grpc_core::ClearBit(&enabled_compression_algorithms_bitset_, algorithm); } return *this; } @@ -223,8 +213,8 @@ ServerBuilder& ServerBuilder::AddListeningPort( return *this; } -std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { - grpc::ChannelArguments args; +ChannelArguments ServerBuilder::BuildChannelArgs() { + ChannelArguments args; if (max_receive_message_size_ >= -1) { args.SetInt(GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH, max_receive_message_size_); } @@ -245,16 +235,24 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { args.SetInt(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, maybe_default_compression_algorithm_.algorithm); } - if (resource_quota_ != nullptr) { args.SetPointerWithVtable(GRPC_ARG_RESOURCE_QUOTA, resource_quota_, grpc_resource_quota_arg_vtable()); } - for (const auto& plugin : plugins_) { plugin->UpdateServerBuilder(this); plugin->UpdateChannelArguments(&args); } + if (authorization_provider_ != nullptr) { + args.SetPointerWithVtable(GRPC_ARG_AUTHORIZATION_POLICY_PROVIDER, + authorization_provider_->c_provider(), + grpc_authorization_policy_provider_arg_vtable()); + } + return args; +} + +std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { + ChannelArguments args = BuildChannelArgs(); // == Determine if the server has any syncrhonous methods == bool has_sync_methods = false; @@ -304,6 +302,10 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { } } + if (callback_generic_service_ != nullptr) { + has_frequently_polled_cqs = true; + } + const bool is_hybrid_server = has_sync_methods && has_frequently_polled_cqs; if (has_sync_methods) { @@ -375,12 +377,7 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { return nullptr; } -#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL server->RegisterContextAllocator(std::move(context_allocator_)); -#else - server->experimental_registration()->RegisterContextAllocator( - std::move(context_allocator_)); -#endif for (const auto& value : services_) { if (!server->RegisterService(value->host.get(), value->service)) { diff --git a/contrib/libs/grpc/src/cpp/server/server_callback.cc b/contrib/libs/grpc/src/cpp/server/server_callback.cc index f6b72c0fcce..5b2d328b81b 100644 --- a/contrib/libs/grpc/src/cpp/server/server_callback.cc +++ b/contrib/libs/grpc/src/cpp/server/server_callback.cc @@ -37,7 +37,7 @@ void ServerCallbackCall::ScheduleOnDone(bool inline_ondone) { explicit ClosureWithArg(ServerCallbackCall* call_arg) : call(call_arg) { GRPC_CLOSURE_INIT( &closure, - [](void* void_arg, grpc_error*) { + [](void* void_arg, grpc_error_handle) { ClosureWithArg* arg = static_cast<ClosureWithArg*>(void_arg); arg->call->CallOnDone(); delete arg; @@ -66,7 +66,7 @@ void ServerCallbackCall::CallOnCancel(ServerReactor* reactor) { : call(call_arg), reactor(reactor_arg) { GRPC_CLOSURE_INIT( &closure, - [](void* void_arg, grpc_error*) { + [](void* void_arg, grpc_error_handle) { ClosureWithArg* arg = static_cast<ClosureWithArg*>(void_arg); arg->reactor->OnCancel(); arg->call->MaybeDone(); diff --git a/contrib/libs/grpc/src/cpp/server/server_cc.cc b/contrib/libs/grpc/src/cpp/server/server_cc.cc index dab7f488a7d..edb1fe4d1d7 100644 --- a/contrib/libs/grpc/src/cpp/server/server_cc.cc +++ b/contrib/libs/grpc/src/cpp/server/server_cc.cc @@ -15,13 +15,13 @@ * */ -#include <grpcpp/server.h> - #include <cstdlib> #include <sstream> #include <type_traits> #include <utility> +#include "y_absl/memory/memory.h" + #include <grpc/grpc.h> #include <grpc/impl/codegen/grpc_types.h> #include <grpc/support/alloc.h> @@ -39,11 +39,10 @@ #include <grpcpp/impl/server_initializer.h> #include <grpcpp/impl/service_type.h> #include <grpcpp/security/server_credentials.h> +#include <grpcpp/server.h> #include <grpcpp/server_context.h> #include <grpcpp/support/time.h> -#include "y_absl/memory/memory.h" - #include "src/core/ext/transport/inproc/inproc_transport.h" #include "src/core/lib/gprpp/manual_constructor.h" #include "src/core/lib/iomgr/exec_ctx.h" @@ -69,6 +68,15 @@ namespace { // max-threads set) to the server builder. #define DEFAULT_MAX_SYNC_SERVER_THREADS INT_MAX +// Give a useful status error message if the resource is exhausted specifically +// because the server threadpool is full. +const char* kServerThreadpoolExhausted = "Server Threadpool Exhausted"; + +// Although we might like to give a useful status error message on unimplemented +// RPCs, it's not always possible since that also would need to be added across +// languages and isn't actually required by the spec. +const char* kUnknownRpcMethod = ""; + class DefaultGlobalCallbacks final : public Server::GlobalCallbacks { public: ~DefaultGlobalCallbacks() override {} @@ -107,15 +115,6 @@ class UnimplementedAsyncRequestContext { GenericServerAsyncReaderWriter generic_stream_; }; -// TODO(vjpai): Just for this file, use some contents of the experimental -// namespace here to make the code easier to read below. Remove this when -// de-experimentalized fully. -#ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL -using ::grpc::experimental::CallbackGenericService; -using ::grpc::experimental::CallbackServerContext; -using ::grpc::experimental::GenericCallbackServerContext; -#endif - } // namespace ServerInterface::BaseAsyncRequest::BaseAsyncRequest( @@ -266,7 +265,7 @@ bool ServerInterface::GenericAsyncRequest::FinalizeResult(void** tag, } namespace { -class ShutdownCallback : public grpc_experimental_completion_queue_functor { +class ShutdownCallback : public grpc_completion_queue_functor { public: ShutdownCallback() { functor_run = &ShutdownCallback::Run; @@ -282,7 +281,7 @@ class ShutdownCallback : public grpc_experimental_completion_queue_functor { // The Run function will get invoked by the completion queue library // when the shutdown is actually complete - static void Run(grpc_experimental_completion_queue_functor* cb, int) { + static void Run(grpc_completion_queue_functor* cb, int) { auto* callback = static_cast<ShutdownCallback*>(cb); delete callback->cq_; delete callback; @@ -410,7 +409,9 @@ class Server::SyncRequest final : public grpc::internal::CompletionQueueTag { : server_->resource_exhausted_handler_.get(); deserialized_request_ = handler->Deserialize(call_, request_payload_, &request_status_, nullptr); - + if (!request_status_.ok()) { + gpr_log(GPR_DEBUG, "Failed to deserialize message."); + } request_payload_ = nullptr; interceptor_methods_.AddInterceptionHookPoint( grpc::experimental::InterceptionHookPoints::POST_RECV_MESSAGE); @@ -576,7 +577,7 @@ class Server::CallbackRequest final // method_name needs to be specialized between named method and generic const char* method_name() const; - class CallbackCallTag : public grpc_experimental_completion_queue_functor { + class CallbackCallTag : public grpc_completion_queue_functor { public: explicit CallbackCallTag(Server::CallbackRequest<ServerContextType>* req) : req_(req) { @@ -599,8 +600,7 @@ class Server::CallbackRequest final Server::CallbackRequest<ServerContextType>* req_; grpc::internal::Call* call_; - static void StaticRun(grpc_experimental_completion_queue_functor* cb, - int ok) { + static void StaticRun(grpc_completion_queue_functor* cb, int ok) { static_cast<CallbackCallTag*>(cb)->Run(static_cast<bool>(ok)); } void Run(bool ok) { @@ -650,6 +650,9 @@ class Server::CallbackRequest final req_->request_ = req_->method_->handler()->Deserialize( req_->call_, req_->request_payload_, &req_->request_status_, &req_->handler_data_); + if (!(req_->request_status_.ok())) { + gpr_log(GPR_DEBUG, "Failed to deserialize message."); + } req_->request_payload_ = nullptr; req_->interceptor_methods_.AddInterceptionHookPoint( grpc::experimental::InterceptionHookPoints::POST_RECV_MESSAGE); @@ -791,8 +794,8 @@ class Server::SyncRequestThreadManager : public grpc::ThreadManager { } void AddSyncMethod(grpc::internal::RpcServiceMethod* method, void* tag) { - server_->server()->core_server->SetRegisteredMethodAllocator( - server_cq_->cq(), tag, [this, method] { + grpc_core::Server::FromC(server_->server()) + ->SetRegisteredMethodAllocator(server_cq_->cq(), tag, [this, method] { grpc_core::Server::RegisteredCallAllocation result; new SyncRequest(server_, method, &result); return result; @@ -804,9 +807,9 @@ class Server::SyncRequestThreadManager : public grpc::ThreadManager { if (has_sync_method_) { unknown_method_ = y_absl::make_unique<grpc::internal::RpcServiceMethod>( "unknown", grpc::internal::RpcMethod::BIDI_STREAMING, - new grpc::internal::UnknownMethodHandler); - server_->server()->core_server->SetBatchMethodAllocator( - server_cq_->cq(), [this] { + new grpc::internal::UnknownMethodHandler(kUnknownRpcMethod)); + grpc_core::Server::FromC(server_->server()) + ->SetBatchMethodAllocator(server_cq_->cq(), [this] { grpc_core::Server::BatchCallAllocation result; new SyncRequest(server_, unknown_method_.get(), &result); return result; @@ -932,14 +935,16 @@ Server::~Server() { for (const auto& value : sync_req_mgrs_) { value->Shutdown(); } - if (callback_cq_ != nullptr) { + CompletionQueue* callback_cq = + callback_cq_.load(std::memory_order_relaxed); + if (callback_cq != nullptr) { if (grpc_iomgr_run_in_background()) { // gRPC-core provides the backing needed for the preferred CQ type - callback_cq_->Shutdown(); + callback_cq->Shutdown(); } else { - CompletionQueue::ReleaseCallbackAlternativeCQ(callback_cq_); + CompletionQueue::ReleaseCallbackAlternativeCQ(callback_cq); } - callback_cq_ = nullptr; + callback_cq_.store(nullptr, std::memory_order_release); } } } @@ -1028,7 +1033,7 @@ bool Server::RegisterService(const TString* addr, grpc::Service* service) { has_callback_methods_ = true; grpc::internal::RpcServiceMethod* method_value = method.get(); grpc::CompletionQueue* cq = CallbackCQ(); - server_->core_server->SetRegisteredMethodAllocator( + grpc_core::Server::FromC(server_)->SetRegisteredMethodAllocator( cq->cq(), method_registration_tag, [this, cq, method_value] { grpc_core::Server::RegisteredCallAllocation result; new CallbackRequest<grpc::CallbackServerContext>(this, method_value, @@ -1069,7 +1074,8 @@ void Server::RegisterCallbackGenericService( generic_handler_.reset(service->Handler()); grpc::CompletionQueue* cq = CallbackCQ(); - server_->core_server->SetBatchMethodAllocator(cq->cq(), [this, cq] { + grpc_core::Server::FromC(server_)->SetBatchMethodAllocator(cq->cq(), [this, + cq] { grpc_core::Server::BatchCallAllocation result; new CallbackRequest<grpc::GenericCallbackServerContext>(this, cq, &result); return result; @@ -1106,9 +1112,9 @@ void Server::UnrefAndWaitLocked() { shutdown_done_ = true; return; // no need to wait on CV since done condition already set } - grpc::internal::WaitUntil( - &shutdown_done_cv_, &mu_, - [this]() Y_ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_) { return shutdown_done_; }); + while (!shutdown_done_) { + shutdown_done_cv_.Wait(&mu_); + } } void Server::Start(grpc::ServerCompletionQueue** cqs, size_t num_cqs) { @@ -1194,7 +1200,8 @@ void Server::Start(grpc::ServerCompletionQueue** cqs, size_t num_cqs) { // to deal with the case of thread exhaustion if (sync_server_cqs_ != nullptr && !sync_server_cqs_->empty()) { resource_exhausted_handler_ = - y_absl::make_unique<grpc::internal::ResourceExhaustedHandler>(); + y_absl::make_unique<grpc::internal::ResourceExhaustedHandler>( + kServerThreadpoolExhausted); } for (const auto& value : sync_req_mgrs_) { @@ -1258,14 +1265,15 @@ void Server::ShutdownInternal(gpr_timespec deadline) { // Shutdown the callback CQ. The CQ is owned by its own shutdown tag, so it // will delete itself at true shutdown. - if (callback_cq_ != nullptr) { + CompletionQueue* callback_cq = callback_cq_.load(std::memory_order_relaxed); + if (callback_cq != nullptr) { if (grpc_iomgr_run_in_background()) { // gRPC-core provides the backing needed for the preferred CQ type - callback_cq_->Shutdown(); + callback_cq->Shutdown(); } else { - CompletionQueue::ReleaseCallbackAlternativeCQ(callback_cq_); + CompletionQueue::ReleaseCallbackAlternativeCQ(callback_cq); } - callback_cq_ = nullptr; + callback_cq_.store(nullptr, std::memory_order_release); } // Drain the shutdown queue (if the previous call to AsyncNext() timed out @@ -1320,8 +1328,9 @@ bool Server::UnimplementedAsyncRequest::FinalizeResult(void** tag, Server::UnimplementedAsyncResponse::UnimplementedAsyncResponse( UnimplementedAsyncRequest* request) : request_(request) { - grpc::Status status(grpc::StatusCode::UNIMPLEMENTED, ""); - grpc::internal::UnknownMethodHandler::FillOps(request_->context(), this); + grpc::Status status(grpc::StatusCode::UNIMPLEMENTED, kUnknownRpcMethod); + grpc::internal::UnknownMethodHandler::FillOps(request_->context(), + kUnknownRpcMethod, this); request_->stream()->call_.PerformOps(this); } @@ -1332,25 +1341,33 @@ grpc::ServerInitializer* Server::initializer() { grpc::CompletionQueue* Server::CallbackCQ() { // TODO(vjpai): Consider using a single global CQ for the default CQ // if there is no explicit per-server CQ registered + CompletionQueue* callback_cq = callback_cq_.load(std::memory_order_acquire); + if (callback_cq != nullptr) { + return callback_cq; + } + // The callback_cq_ wasn't already set, so grab a lock and set it up exactly + // once for this server. grpc::internal::MutexLock l(&mu_); - if (callback_cq_ != nullptr) { - return callback_cq_; + callback_cq = callback_cq_.load(std::memory_order_relaxed); + if (callback_cq != nullptr) { + return callback_cq; } if (grpc_iomgr_run_in_background()) { // gRPC-core provides the backing needed for the preferred CQ type auto* shutdown_callback = new grpc::ShutdownCallback; - callback_cq_ = new grpc::CompletionQueue(grpc_completion_queue_attributes{ + callback_cq = new grpc::CompletionQueue(grpc_completion_queue_attributes{ GRPC_CQ_CURRENT_VERSION, GRPC_CQ_CALLBACK, GRPC_CQ_DEFAULT_POLLING, shutdown_callback}); // Transfer ownership of the new cq to its own shutdown callback - shutdown_callback->TakeCQ(callback_cq_); + shutdown_callback->TakeCQ(callback_cq); } else { // Otherwise we need to use the alternative CQ variant - callback_cq_ = CompletionQueue::CallbackAlternativeCQ(); + callback_cq = CompletionQueue::CallbackAlternativeCQ(); } - return callback_cq_; + callback_cq_.store(callback_cq, std::memory_order_release); + return callback_cq; } } // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/server/server_context.cc b/contrib/libs/grpc/src/cpp/server/server_context.cc index df82c69ed8e..c8ace3d9142 100644 --- a/contrib/libs/grpc/src/cpp/server/server_context.cc +++ b/contrib/libs/grpc/src/cpp/server/server_context.cc @@ -16,9 +16,8 @@ * */ -#include <grpcpp/impl/codegen/server_context.h> - #include <algorithm> +#include <atomic> #include <utility> #include <grpc/compression.h> @@ -28,6 +27,7 @@ #include <grpc/support/log.h> #include <grpcpp/impl/call.h> #include <grpcpp/impl/codegen/completion_queue.h> +#include <grpcpp/impl/codegen/server_context.h> #include <grpcpp/impl/grpc_library.h> #include <grpcpp/support/server_callback.h> #include <grpcpp/support/time.h> @@ -327,14 +327,16 @@ void ServerContextBase::TryCancel() const { bool ServerContextBase::IsCancelled() const { if (completion_tag_) { // When using callback API, this result is always valid. - return completion_op_->CheckCancelledAsync(); + return marked_cancelled_.load(std::memory_order_acquire) || + completion_op_->CheckCancelledAsync(); } else if (has_notify_when_done_tag_) { // When using async API, the result is only valid // if the tag has already been delivered at the completion queue return completion_op_ && completion_op_->CheckCancelledAsync(); } else { // when using sync API, the result is always valid - return completion_op_ && completion_op_->CheckCancelled(cq_); + return marked_cancelled_.load(std::memory_order_acquire) || + (completion_op_ && completion_op_->CheckCancelled(cq_)); } } diff --git a/contrib/libs/grpc/src/cpp/server/server_credentials.cc b/contrib/libs/grpc/src/cpp/server/server_credentials.cc index 36b5a52dc7c..454e8b4e9d6 100644 --- a/contrib/libs/grpc/src/cpp/server/server_credentials.cc +++ b/contrib/libs/grpc/src/cpp/server/server_credentials.cc @@ -16,9 +16,8 @@ * */ -#include <grpcpp/security/server_credentials.h> - #include <grpcpp/impl/grpc_library.h> +#include <grpcpp/security/server_credentials.h> namespace grpc { diff --git a/contrib/libs/grpc/src/cpp/server/server_posix.cc b/contrib/libs/grpc/src/cpp/server/server_posix.cc index c3d40d4fa2d..f2452cc3261 100644 --- a/contrib/libs/grpc/src/cpp/server/server_posix.cc +++ b/contrib/libs/grpc/src/cpp/server/server_posix.cc @@ -16,9 +16,8 @@ * */ -#include <grpcpp/server_posix.h> - #include <grpc/grpc_posix.h> +#include <grpcpp/server_posix.h> namespace grpc { diff --git a/contrib/libs/grpc/src/cpp/server/xds_server_credentials.cc b/contrib/libs/grpc/src/cpp/server/xds_server_credentials.cc index b543f3f172d..f1842389066 100644 --- a/contrib/libs/grpc/src/cpp/server/xds_server_credentials.cc +++ b/contrib/libs/grpc/src/cpp/server/xds_server_credentials.cc @@ -19,7 +19,6 @@ #include "src/cpp/server/secure_server_credentials.h" namespace grpc { -namespace experimental { std::shared_ptr<ServerCredentials> XdsServerCredentials( const std::shared_ptr<ServerCredentials>& fallback_credentials) { @@ -37,5 +36,12 @@ std::shared_ptr<ServerCredentials> XdsServerCredentials( fallback_credentials->AsSecureServerCredentials()->c_creds())); } +namespace experimental { + +std::shared_ptr<ServerCredentials> XdsServerCredentials( + const std::shared_ptr<ServerCredentials>& fallback_credentials) { + return grpc::XdsServerCredentials(fallback_credentials); +} + } // namespace experimental } // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/thread_manager/thread_manager.cc b/contrib/libs/grpc/src/cpp/thread_manager/thread_manager.cc index 5155f610a8c..25c065588ee 100644 --- a/contrib/libs/grpc/src/cpp/thread_manager/thread_manager.cc +++ b/contrib/libs/grpc/src/cpp/thread_manager/thread_manager.cc @@ -21,6 +21,7 @@ #include <climits> #include <grpc/support/log.h> + #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/exec_ctx.h" @@ -49,17 +50,16 @@ ThreadManager::WorkerThread::~WorkerThread() { thd_.Join(); } -ThreadManager::ThreadManager(const char* name, - grpc_resource_quota* resource_quota, +ThreadManager::ThreadManager(const char*, grpc_resource_quota* resource_quota, int min_pollers, int max_pollers) : shutdown_(false), + thread_quota_( + grpc_core::ResourceQuota::FromC(resource_quota)->thread_quota()), num_pollers_(0), min_pollers_(min_pollers), max_pollers_(max_pollers == -1 ? INT_MAX : max_pollers), num_threads_(0), - max_active_threads_sofar_(0) { - resource_user_ = grpc_resource_user_create(resource_quota, name); -} + max_active_threads_sofar_(0) {} ThreadManager::~ThreadManager() { { @@ -67,8 +67,6 @@ ThreadManager::~ThreadManager() { GPR_ASSERT(num_threads_ == 0); } - grpc_core::ExecCtx exec_ctx; // grpc_resource_user_unref needs an exec_ctx - grpc_resource_user_unref(resource_user_); CleanupCompletedThreads(); } @@ -109,7 +107,7 @@ void ThreadManager::MarkAsCompleted(WorkerThread* thd) { } // Give a thread back to the resource quota - grpc_resource_user_free_threads(resource_user_, 1); + thread_quota_->Release(1); } void ThreadManager::CleanupCompletedThreads() { @@ -124,7 +122,7 @@ void ThreadManager::CleanupCompletedThreads() { } void ThreadManager::Initialize() { - if (!grpc_resource_user_allocate_threads(resource_user_, min_pollers_)) { + if (!thread_quota_->Reserve(min_pollers_)) { gpr_log(GPR_ERROR, "No thread quota available to even create the minimum required " "polling threads (i.e %d). Unable to start the thread manager", @@ -171,7 +169,7 @@ void ThreadManager::MainWorkLoop() { // quota available to create a new thread, start a new poller thread bool resource_exhausted = false; if (!shutdown_ && num_pollers_ < min_pollers_) { - if (grpc_resource_user_allocate_threads(resource_user_, 1)) { + if (thread_quota_->Reserve(1)) { // We can allocate a new poller thread num_pollers_++; num_threads_++; diff --git a/contrib/libs/grpc/src/cpp/thread_manager/thread_manager.h b/contrib/libs/grpc/src/cpp/thread_manager/thread_manager.h index aae24177873..4c49854d32e 100644 --- a/contrib/libs/grpc/src/cpp/thread_manager/thread_manager.h +++ b/contrib/libs/grpc/src/cpp/thread_manager/thread_manager.h @@ -22,11 +22,12 @@ #include <list> #include <memory> +#include <grpc/grpc.h> #include <grpcpp/support/config.h> #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/thd.h" -#include "src/core/lib/iomgr/resource_quota.h" +#include "src/core/lib/resource_quota/api.h" namespace grpc { @@ -154,7 +155,7 @@ class ThreadManager { // object (that contains the actual max thread quota) and a grpc_resource_user // object through which quota is requested whenever new threads need to be // created - grpc_resource_user* resource_user_; + grpc_core::ThreadQuotaPtr thread_quota_; // Number of threads doing polling int num_pollers_; diff --git a/contrib/libs/grpc/src/cpp/util/byte_buffer_cc.cc b/contrib/libs/grpc/src/cpp/util/byte_buffer_cc.cc index fb705906455..5c6f22bd7c6 100644 --- a/contrib/libs/grpc/src/cpp/util/byte_buffer_cc.cc +++ b/contrib/libs/grpc/src/cpp/util/byte_buffer_cc.cc @@ -25,6 +25,37 @@ namespace grpc { static internal::GrpcLibraryInitializer g_gli_initializer; +Status ByteBuffer::TrySingleSlice(Slice* slice) const { + if (!buffer_) { + return Status(StatusCode::FAILED_PRECONDITION, "Buffer not initialized"); + } + if ((buffer_->type == GRPC_BB_RAW) && + (buffer_->data.raw.compression == GRPC_COMPRESS_NONE) && + (buffer_->data.raw.slice_buffer.count == 1)) { + grpc_slice internal_slice = buffer_->data.raw.slice_buffer.slices[0]; + *slice = Slice(internal_slice, Slice::ADD_REF); + return Status::OK; + } else { + return Status(StatusCode::FAILED_PRECONDITION, + "Buffer isn't made up of a single uncompressed slice."); + } +} + +Status ByteBuffer::DumpToSingleSlice(Slice* slice) const { + if (!buffer_) { + return Status(StatusCode::FAILED_PRECONDITION, "Buffer not initialized"); + } + grpc_byte_buffer_reader reader; + if (!grpc_byte_buffer_reader_init(&reader, buffer_)) { + return Status(StatusCode::INTERNAL, + "Couldn't initialize byte buffer reader"); + } + grpc_slice s = grpc_byte_buffer_reader_readall(&reader); + *slice = Slice(s, Slice::STEAL_REF); + grpc_byte_buffer_reader_destroy(&reader); + return Status::OK; +} + Status ByteBuffer::Dump(std::vector<Slice>* slices) const { slices->clear(); if (!buffer_) { |
