diff options
author | heretic <heretic@yandex-team.ru> | 2022-02-10 16:45:46 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:46 +0300 |
commit | 81eddc8c0b55990194e112b02d127b87d54164a9 (patch) | |
tree | 9142afc54d335ea52910662635b898e79e192e49 /contrib/libs/grpc/src/cpp | |
parent | 397cbe258b9e064f49c4ca575279f02f39fef76e (diff) | |
download | ydb-81eddc8c0b55990194e112b02d127b87d54164a9.tar.gz |
Restoring authorship annotation for <heretic@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/grpc/src/cpp')
54 files changed, 1258 insertions, 1258 deletions
diff --git a/contrib/libs/grpc/src/cpp/README.md b/contrib/libs/grpc/src/cpp/README.md index 8fccf8c1ecd..967a0a43b7f 100755 --- a/contrib/libs/grpc/src/cpp/README.md +++ b/contrib/libs/grpc/src/cpp/README.md @@ -1,22 +1,22 @@ -# gRPC C++ +# gRPC C++ -This directory contains the C++ implementation of gRPC. +This directory contains the C++ implementation of gRPC. # To start using gRPC C++ -This section describes how to add gRPC as a dependency to your C++ project. - +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. -## Bazel +## Bazel -Bazel is the primary build system used by the core gRPC development team. Bazel -provides fast builds and it easily handles dependencies that support bazel. +Bazel is the primary build system used by the core gRPC development team. Bazel +provides fast builds and it easily handles dependencies that support bazel. To add gRPC as a dependency in bazel: 1. determine commit SHA for the grpc release you want to use -2. Use the [http_archive](https://docs.bazel.build/versions/master/repo/http.html#http_archive) bazel rule to include gRPC source +2. Use the [http_archive](https://docs.bazel.build/versions/master/repo/http.html#http_archive) bazel rule to include gRPC source ``` http_archive( name = "com_github_grpc_grpc", @@ -31,102 +31,102 @@ To add gRPC as a dependency in bazel: grpc_deps() ``` -## CMake - -`cmake` is your best option if you cannot use bazel. It supports building on Linux, -MacOS and Windows (official support) but also has a good chance of working on -other platforms (no promises!). `cmake` has good support for crosscompiling and -can be used for targeting the Android platform. - -To build gRPC C++ from source, follow the [BUILDING guide](../../BUILDING.md). - -### find_package - -The canonical way to discover dependencies in CMake is the -[`find_package` command](https://cmake.org/cmake/help/latest/command/find_package.html). - -```cmake -find_package(gRPC CONFIG REQUIRED) -add_executable(my_exe my_exe.cc) -target_link_libraries(my_exe gRPC::grpc++) -``` -[Full example](../../examples/cpp/helloworld/CMakeLists.txt) - -`find_package` can only find software that has already been installed on your -system. In practice that means you'll need to install gRPC using cmake first. -gRPC's cmake support provides the option to install gRPC either system-wide -(not recommended) or under a directory prefix in a way that you can later -easily use it with the `find_package(gRPC CONFIG REQUIRED)` command. - -The following sections describe strategies to automatically build gRPC -as part of your project. - -### FetchContent -If you are using CMake v3.11 or newer you should use CMake's -[FetchContent module](https://cmake.org/cmake/help/latest/module/FetchContent.html). -The first time you run CMake in a given build directory, FetchContent will -clone the gRPC repository and its submodules. `FetchContent_MakeAvailable()` -also sets up an `add_subdirectory()` rule for you. This causes gRPC to be -built as part of your project. - -```cmake -cmake_minimum_required(VERSION 3.15) -project(my_project) - -include(FetchContent) -FetchContent_Declare( - gRPC - GIT_REPOSITORY https://github.com/grpc/grpc - GIT_TAG RELEASE_TAG_HERE # e.g v1.28.0 -) -set(FETCHCONTENT_QUIET OFF) -FetchContent_MakeAvailable(gRPC) - -add_executable(my_exe my_exe.cc) -target_link_libraries(my_exe grpc++) -``` - -Note that you need to -[install the prerequisites](../../BUILDING.md#pre-requisites) -before building gRPC. - -### git submodule -If you cannot use FetchContent, another approach is to add the gRPC source tree -to your project as a -[git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules). -You can then add it to your CMake project with `add_subdirectory()`. -[Example](../../examples/cpp/helloworld/CMakeLists.txt) - -### Support system-installed gRPC - -If your project builds gRPC you should still consider the case where a user -wants to build your software using a previously installed gRPC. Here's a -code snippet showing how this is typically done. - -```cmake -option(USE_SYSTEM_GRPC "Use system installed gRPC" OFF) -if(USE_SYSTEM_GRPC) - # Find system-installed gRPC - find_package(gRPC CONFIG REQUIRED) -else() - # Build gRPC using FetchContent or add_subdirectory -endif() -``` - -[Full example](../../examples/cpp/helloworld/CMakeLists.txt) - -## pkg-config - -If your project does not use CMake (e.g. you're using `make` directly), you can -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) - -## make (deprecated) - -The default choice for building on UNIX based systems used to be `make`, but we are no longer recommending it. -You should use `bazel` or `cmake` instead. - +## CMake + +`cmake` is your best option if you cannot use bazel. It supports building on Linux, +MacOS and Windows (official support) but also has a good chance of working on +other platforms (no promises!). `cmake` has good support for crosscompiling and +can be used for targeting the Android platform. + +To build gRPC C++ from source, follow the [BUILDING guide](../../BUILDING.md). + +### find_package + +The canonical way to discover dependencies in CMake is the +[`find_package` command](https://cmake.org/cmake/help/latest/command/find_package.html). + +```cmake +find_package(gRPC CONFIG REQUIRED) +add_executable(my_exe my_exe.cc) +target_link_libraries(my_exe gRPC::grpc++) +``` +[Full example](../../examples/cpp/helloworld/CMakeLists.txt) + +`find_package` can only find software that has already been installed on your +system. In practice that means you'll need to install gRPC using cmake first. +gRPC's cmake support provides the option to install gRPC either system-wide +(not recommended) or under a directory prefix in a way that you can later +easily use it with the `find_package(gRPC CONFIG REQUIRED)` command. + +The following sections describe strategies to automatically build gRPC +as part of your project. + +### FetchContent +If you are using CMake v3.11 or newer you should use CMake's +[FetchContent module](https://cmake.org/cmake/help/latest/module/FetchContent.html). +The first time you run CMake in a given build directory, FetchContent will +clone the gRPC repository and its submodules. `FetchContent_MakeAvailable()` +also sets up an `add_subdirectory()` rule for you. This causes gRPC to be +built as part of your project. + +```cmake +cmake_minimum_required(VERSION 3.15) +project(my_project) + +include(FetchContent) +FetchContent_Declare( + gRPC + GIT_REPOSITORY https://github.com/grpc/grpc + GIT_TAG RELEASE_TAG_HERE # e.g v1.28.0 +) +set(FETCHCONTENT_QUIET OFF) +FetchContent_MakeAvailable(gRPC) + +add_executable(my_exe my_exe.cc) +target_link_libraries(my_exe grpc++) +``` + +Note that you need to +[install the prerequisites](../../BUILDING.md#pre-requisites) +before building gRPC. + +### git submodule +If you cannot use FetchContent, another approach is to add the gRPC source tree +to your project as a +[git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules). +You can then add it to your CMake project with `add_subdirectory()`. +[Example](../../examples/cpp/helloworld/CMakeLists.txt) + +### Support system-installed gRPC + +If your project builds gRPC you should still consider the case where a user +wants to build your software using a previously installed gRPC. Here's a +code snippet showing how this is typically done. + +```cmake +option(USE_SYSTEM_GRPC "Use system installed gRPC" OFF) +if(USE_SYSTEM_GRPC) + # Find system-installed gRPC + find_package(gRPC CONFIG REQUIRED) +else() + # Build gRPC using FetchContent or add_subdirectory +endif() +``` + +[Full example](../../examples/cpp/helloworld/CMakeLists.txt) + +## pkg-config + +If your project does not use CMake (e.g. you're using `make` directly), you can +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) + +## make (deprecated) + +The default choice for building on UNIX based systems used to be `make`, but we are no longer recommending it. +You should use `bazel` or `cmake` instead. + To install gRPC for C++ on your system using `make`, follow the [Building gRPC C++](../../BUILDING.md) instructions to build from source and then install locally using `make install`. This also installs the protocol buffer compiler `protoc` (if you don't have it already), @@ -165,12 +165,12 @@ You can find out how to build and run our simplest gRPC C++ example in our For more detailed documentation on using gRPC in C++ , see our main documentation site at [grpc.io](https://grpc.io), specifically: -* [Overview](https://grpc.io/docs): An introduction to gRPC with a simple +* [Overview](https://grpc.io/docs): An introduction to gRPC with a simple Hello World example in all our supported languages, including C++. -* [gRPC Basics - C++](https://grpc.io/docs/languages/cpp/basics): +* [gRPC Basics - C++](https://grpc.io/docs/languages/cpp/basics): A tutorial that steps you through creating a simple gRPC C++ example application. -* [Asynchronous Basics - C++](https://grpc.io/docs/languages/cpp/async): +* [Asynchronous Basics - C++](https://grpc.io/docs/languages/cpp/async): A tutorial that shows you how to use gRPC C++'s asynchronous/non-blocking APIs. diff --git a/contrib/libs/grpc/src/cpp/client/channel_cc.cc b/contrib/libs/grpc/src/cpp/client/channel_cc.cc index 9e4a12edc71..ac95c29efcd 100644 --- a/contrib/libs/grpc/src/cpp/client/channel_cc.cc +++ b/contrib/libs/grpc/src/cpp/client/channel_cc.cc @@ -41,10 +41,10 @@ #include "src/core/lib/gpr/string.h" #include "src/core/lib/surface/completion_queue.h" -namespace grpc { +namespace grpc { static ::grpc::internal::GrpcLibraryInitializer g_gli_initializer; -Channel::Channel(const TString& host, grpc_channel* channel, +Channel::Channel(const TString& host, grpc_channel* channel, std::vector<std::unique_ptr< ::grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators) @@ -63,31 +63,31 @@ Channel::~Channel() { namespace { inline grpc_slice SliceFromArray(const char* arr, size_t len) { - return g_core_codegen_interface->grpc_slice_from_copied_buffer(arr, len); + return g_core_codegen_interface->grpc_slice_from_copied_buffer(arr, len); } -TString GetChannelInfoField(grpc_channel* channel, - grpc_channel_info* channel_info, - char*** channel_info_field) { +TString GetChannelInfoField(grpc_channel* channel, + grpc_channel_info* channel_info, + char*** channel_info_field) { char* value = nullptr; memset(channel_info, 0, sizeof(*channel_info)); *channel_info_field = &value; grpc_channel_get_info(channel, channel_info); if (value == nullptr) return ""; - TString result = value; + TString result = value; gpr_free(value); return result; } } // namespace -TString Channel::GetLoadBalancingPolicyName() const { +TString Channel::GetLoadBalancingPolicyName() const { grpc_channel_info channel_info; return GetChannelInfoField(c_channel_, &channel_info, &channel_info.lb_policy_name); } -TString Channel::GetServiceConfigJSON() const { +TString Channel::GetServiceConfigJSON() const { grpc_channel_info channel_info; return GetChannelInfoField(c_channel_, &channel_info, &channel_info.service_config_json); @@ -112,7 +112,7 @@ void ChannelResetConnectionBackoff(Channel* channel) { context->propagation_options_.c_bitmask(), cq->cq(), method.channel_tag(), context->raw_deadline(), nullptr); } else { - const ::TString* host_str = nullptr; + const ::TString* host_str = nullptr; if (!context->authority_.empty()) { host_str = &context->authority_; } else if (!host_.empty()) { @@ -249,4 +249,4 @@ class ShutdownCallback : public grpc_experimental_completion_queue_functor { return callback_cq_; } -} // namespace grpc +} // 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 286a57b589f..f4cbc97d34b 100644 --- a/contrib/libs/grpc/src/cpp/client/client_callback.cc +++ b/contrib/libs/grpc/src/cpp/client/client_callback.cc @@ -1,52 +1,52 @@ -/* - * 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 <grpcpp/impl/codegen/client_callback.h> - -#include "src/core/lib/iomgr/closure.h" -#include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/iomgr/executor.h" - -namespace grpc { -namespace internal { - -void ClientReactor::InternalScheduleOnDone(grpc::Status s) { - // Unlike other uses of closure, do not Ref or Unref here since the reactor - // object's lifetime is controlled by user code. - grpc_core::ExecCtx exec_ctx; - struct ClosureWithArg { - grpc_closure closure; - ClientReactor* const reactor; - const grpc::Status status; - ClosureWithArg(ClientReactor* reactor_arg, grpc::Status s) - : reactor(reactor_arg), status(std::move(s)) { - GRPC_CLOSURE_INIT(&closure, - [](void* void_arg, grpc_error*) { - ClosureWithArg* arg = - static_cast<ClosureWithArg*>(void_arg); - arg->reactor->OnDone(arg->status); - delete arg; - }, - this, grpc_schedule_on_exec_ctx); - } - }; - ClosureWithArg* arg = new ClosureWithArg(this, std::move(s)); - grpc_core::Executor::Run(&arg->closure, GRPC_ERROR_NONE); -} - -} // namespace internal -} // namespace grpc +/* + * 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 <grpcpp/impl/codegen/client_callback.h> + +#include "src/core/lib/iomgr/closure.h" +#include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/iomgr/executor.h" + +namespace grpc { +namespace internal { + +void ClientReactor::InternalScheduleOnDone(grpc::Status s) { + // Unlike other uses of closure, do not Ref or Unref here since the reactor + // object's lifetime is controlled by user code. + grpc_core::ExecCtx exec_ctx; + struct ClosureWithArg { + grpc_closure closure; + ClientReactor* const reactor; + const grpc::Status status; + ClosureWithArg(ClientReactor* reactor_arg, grpc::Status s) + : reactor(reactor_arg), status(std::move(s)) { + GRPC_CLOSURE_INIT(&closure, + [](void* void_arg, grpc_error*) { + ClosureWithArg* arg = + static_cast<ClosureWithArg*>(void_arg); + arg->reactor->OnDone(arg->status); + delete arg; + }, + this, grpc_schedule_on_exec_ctx); + } + }; + ClosureWithArg* arg = new ClosureWithArg(this, std::move(s)); + grpc_core::Executor::Run(&arg->closure, GRPC_ERROR_NONE); +} + +} // 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 dacfa1e1ae6..b75343d0895 100644 --- a/contrib/libs/grpc/src/cpp/client/client_context.cc +++ b/contrib/libs/grpc/src/cpp/client/client_context.cc @@ -31,7 +31,7 @@ #include <grpcpp/server_context.h> #include <grpcpp/support/time.h> -namespace grpc { +namespace grpc { class Channel; @@ -43,7 +43,7 @@ class DefaultGlobalClientCallbacks final void Destructor(ClientContext* /*context*/) override {} }; -static internal::GrpcLibraryInitializer g_gli_initializer; +static internal::GrpcLibraryInitializer g_gli_initializer; static DefaultGlobalClientCallbacks* g_default_client_callbacks = new DefaultGlobalClientCallbacks(); static ClientContext::GlobalCallbacks* g_client_callbacks = @@ -73,7 +73,7 @@ ClientContext::~ClientContext() { } void ClientContext::set_credentials( - const std::shared_ptr<CallCredentials>& creds) { + const std::shared_ptr<CallCredentials>& creds) { creds_ = creds; // If call_ is set, we have already created the call, and set the call // credentials. This should only be done before we have started the batch @@ -89,32 +89,32 @@ void ClientContext::set_credentials( } std::unique_ptr<ClientContext> ClientContext::FromInternalServerContext( - const grpc::ServerContextBase& context, PropagationOptions options) { + const grpc::ServerContextBase& context, PropagationOptions options) { std::unique_ptr<ClientContext> ctx(new ClientContext); - ctx->propagate_from_call_ = context.call_.call; + ctx->propagate_from_call_ = context.call_.call; ctx->propagation_options_ = options; return ctx; } std::unique_ptr<ClientContext> ClientContext::FromServerContext( - const grpc::ServerContext& server_context, PropagationOptions options) { + const grpc::ServerContext& server_context, PropagationOptions options) { return FromInternalServerContext(server_context, options); } std::unique_ptr<ClientContext> ClientContext::FromCallbackServerContext( - const grpc::CallbackServerContext& server_context, + const grpc::CallbackServerContext& server_context, PropagationOptions options) { return FromInternalServerContext(server_context, options); } -void ClientContext::AddMetadata(const TString& meta_key, - const TString& meta_value) { +void ClientContext::AddMetadata(const TString& meta_key, + const TString& meta_value) { send_initial_metadata_.insert(std::make_pair(meta_key, meta_value)); } -void ClientContext::set_call(grpc_call* call, - const std::shared_ptr<Channel>& channel) { - internal::MutexLock lock(&mu_); +void ClientContext::set_call(grpc_call* call, + const std::shared_ptr<Channel>& channel) { + internal::MutexLock lock(&mu_); GPR_ASSERT(call_ == nullptr); call_ = call; channel_ = channel; @@ -144,7 +144,7 @@ void ClientContext::set_compression_algorithm( } void ClientContext::TryCancel() { - internal::MutexLock lock(&mu_); + internal::MutexLock lock(&mu_); if (call_) { SendCancelToInterceptors(); grpc_call_cancel(call_, nullptr); @@ -154,14 +154,14 @@ void ClientContext::TryCancel() { } void ClientContext::SendCancelToInterceptors() { - internal::CancelInterceptorBatchMethods cancel_methods; + internal::CancelInterceptorBatchMethods cancel_methods; for (size_t i = 0; i < rpc_info_.interceptors_.size(); i++) { rpc_info_.RunInterceptor(&cancel_methods, i); } } -TString ClientContext::peer() const { - TString peer; +TString ClientContext::peer() const { + TString peer; if (call_) { char* c_peer = grpc_call_get_peer(call_); peer = c_peer; @@ -177,4 +177,4 @@ void ClientContext::SetGlobalCallbacks(GlobalCallbacks* client_callbacks) { g_client_callbacks = client_callbacks; } -} // namespace grpc +} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/client/create_channel.cc b/contrib/libs/grpc/src/cpp/client/create_channel.cc index 85ee6eeb44f..97327490ed2 100644 --- a/contrib/libs/grpc/src/cpp/client/create_channel.cc +++ b/contrib/libs/grpc/src/cpp/client/create_channel.cc @@ -26,14 +26,14 @@ #include "src/cpp/client/create_channel_internal.h" -namespace grpc { -std::shared_ptr<grpc::Channel> CreateChannel( +namespace grpc { +std::shared_ptr<grpc::Channel> CreateChannel( const grpc::string& target, const std::shared_ptr<grpc::ChannelCredentials>& creds) { - return CreateCustomChannel(target, creds, grpc::ChannelArguments()); + return CreateCustomChannel(target, creds, grpc::ChannelArguments()); } -std::shared_ptr<grpc::Channel> CreateCustomChannel( +std::shared_ptr<grpc::Channel> CreateCustomChannel( const grpc::string& target, const std::shared_ptr<grpc::ChannelCredentials>& creds, const grpc::ChannelArguments& args) { @@ -63,7 +63,7 @@ namespace experimental { /// fail) is returned. /// \param args Options for channel creation. std::shared_ptr<grpc::Channel> CreateCustomChannelWithInterceptors( - const TString& target, + const TString& target, const std::shared_ptr<grpc::ChannelCredentials>& creds, const grpc::ChannelArguments& args, std::vector< @@ -82,4 +82,4 @@ std::shared_ptr<grpc::Channel> CreateCustomChannelWithInterceptors( } } // namespace experimental -} // namespace grpc +} // namespace grpc 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 325fde94218..da2a878a227 100644 --- a/contrib/libs/grpc/src/cpp/client/create_channel_internal.cc +++ b/contrib/libs/grpc/src/cpp/client/create_channel_internal.cc @@ -25,7 +25,7 @@ struct grpc_channel; namespace grpc { std::shared_ptr<Channel> CreateChannelInternal( - const TString& host, grpc_channel* c_channel, + const TString& host, grpc_channel* c_channel, std::vector<std::unique_ptr< ::grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators) { 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 cf94e169305..09d4e56b023 100644 --- a/contrib/libs/grpc/src/cpp/client/create_channel_internal.h +++ b/contrib/libs/grpc/src/cpp/client/create_channel_internal.h @@ -30,7 +30,7 @@ struct grpc_channel; namespace grpc { std::shared_ptr<Channel> CreateChannelInternal( - const TString& host, grpc_channel* c_channel, + const TString& host, grpc_channel* c_channel, std::vector<std::unique_ptr< ::grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators); diff --git a/contrib/libs/grpc/src/cpp/client/create_channel_posix.cc b/contrib/libs/grpc/src/cpp/client/create_channel_posix.cc index 55ec2b8f70c..db09eda8a66 100644 --- a/contrib/libs/grpc/src/cpp/client/create_channel_posix.cc +++ b/contrib/libs/grpc/src/cpp/client/create_channel_posix.cc @@ -24,39 +24,39 @@ #include "src/cpp/client/create_channel_internal.h" -namespace grpc { +namespace grpc { class ChannelArguments; #ifdef GPR_SUPPORT_CHANNELS_FROM_FD -std::shared_ptr<Channel> CreateInsecureChannelFromFd(const TString& target, - int fd) { +std::shared_ptr<Channel> CreateInsecureChannelFromFd(const TString& target, + int fd) { grpc::internal::GrpcLibrary init_lib; init_lib.init(); - return CreateChannelInternal( + return CreateChannelInternal( "", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr), - std::vector< - std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>()); + std::vector< + std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>()); } -std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd( - const TString& target, int fd, const grpc::ChannelArguments& args) { - internal::GrpcLibrary init_lib; +std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd( + const TString& target, int fd, const grpc::ChannelArguments& args) { + internal::GrpcLibrary init_lib; init_lib.init(); grpc_channel_args channel_args; args.SetChannelArgs(&channel_args); - return CreateChannelInternal( + return CreateChannelInternal( "", grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args), - std::vector< - std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>()); + std::vector< + std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>()); } namespace experimental { -std::shared_ptr<Channel> CreateCustomInsecureChannelWithInterceptorsFromFd( - const TString& target, int fd, const ChannelArguments& args, +std::shared_ptr<Channel> CreateCustomInsecureChannelWithInterceptorsFromFd( + const TString& target, int fd, const ChannelArguments& args, std::vector< std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators) { @@ -64,7 +64,7 @@ std::shared_ptr<Channel> CreateCustomInsecureChannelWithInterceptorsFromFd( init_lib.init(); grpc_channel_args channel_args; args.SetChannelArgs(&channel_args); - return CreateChannelInternal( + return CreateChannelInternal( "", grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args), std::move(interceptor_creators)); @@ -74,4 +74,4 @@ std::shared_ptr<Channel> CreateCustomInsecureChannelWithInterceptorsFromFd( #endif // GPR_SUPPORT_CHANNELS_FROM_FD -} // namespace grpc +} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/client/credentials_cc.cc b/contrib/libs/grpc/src/cpp/client/credentials_cc.cc index 07f0f598d6e..9dfb2f491ca 100644 --- a/contrib/libs/grpc/src/cpp/client/credentials_cc.cc +++ b/contrib/libs/grpc/src/cpp/client/credentials_cc.cc @@ -19,7 +19,7 @@ #include <grpcpp/impl/grpc_library.h> #include <grpcpp/security/credentials.h> -namespace grpc { +namespace grpc { static grpc::internal::GrpcLibraryInitializer g_gli_initializer; ChannelCredentials::ChannelCredentials() { g_gli_initializer.summon(); } @@ -30,4 +30,4 @@ CallCredentials::CallCredentials() { g_gli_initializer.summon(); } CallCredentials::~CallCredentials() {} -} // namespace grpc +} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/client/insecure_credentials.cc b/contrib/libs/grpc/src/cpp/client/insecure_credentials.cc index f8fa5b39c2f..e5bafff70af 100644 --- a/contrib/libs/grpc/src/cpp/client/insecure_credentials.cc +++ b/contrib/libs/grpc/src/cpp/client/insecure_credentials.cc @@ -24,13 +24,13 @@ #include <grpcpp/support/config.h> #include "src/cpp/client/create_channel_internal.h" -namespace grpc { +namespace grpc { namespace { class InsecureChannelCredentialsImpl final : public ChannelCredentials { public: std::shared_ptr<Channel> CreateChannelImpl( - const TString& target, const ChannelArguments& args) override { + const TString& target, const ChannelArguments& args) override { return CreateChannelWithInterceptors( target, args, std::vector<std::unique_ptr< @@ -38,7 +38,7 @@ class InsecureChannelCredentialsImpl final : public ChannelCredentials { } std::shared_ptr<Channel> CreateChannelWithInterceptors( - const TString& target, const ChannelArguments& args, + const TString& target, const ChannelArguments& args, std::vector<std::unique_ptr< grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators) override { @@ -59,4 +59,4 @@ std::shared_ptr<ChannelCredentials> InsecureChannelCredentials() { new InsecureChannelCredentialsImpl()); } -} // namespace grpc +} // 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 dc613907b47..0f6db3caa53 100644 --- a/contrib/libs/grpc/src/cpp/client/secure_credentials.cc +++ b/contrib/libs/grpc/src/cpp/client/secure_credentials.cc @@ -20,7 +20,7 @@ #include <grpc/impl/codegen/slice.h> #include <grpc/slice.h> -#include <grpc/support/alloc.h> +#include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/string_util.h> #include <grpcpp/channel.h> @@ -38,7 +38,7 @@ #include "src/cpp/client/create_channel_internal.h" #include "src/cpp/common/secure_auth_context.h" -namespace grpc { +namespace grpc { static grpc::internal::GrpcLibraryInitializer g_gli_initializer; SecureChannelCredentials::SecureChannelCredentials( @@ -48,7 +48,7 @@ SecureChannelCredentials::SecureChannelCredentials( } std::shared_ptr<Channel> SecureChannelCredentials::CreateChannelImpl( - const TString& target, const ChannelArguments& args) { + const TString& target, const ChannelArguments& args) { return CreateChannelWithInterceptors( target, args, std::vector<std::unique_ptr< @@ -57,7 +57,7 @@ std::shared_ptr<Channel> SecureChannelCredentials::CreateChannelImpl( std::shared_ptr<Channel> SecureChannelCredentials::CreateChannelWithInterceptors( - const TString& target, const ChannelArguments& args, + const TString& target, const ChannelArguments& args, std::vector< std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators) { @@ -97,8 +97,8 @@ std::shared_ptr<CallCredentials> WrapCallCredentials( std::shared_ptr<ChannelCredentials> GoogleDefaultCredentials() { grpc::GrpcLibraryCodegen init; // To call grpc_init(). - return WrapChannelCredentials( - grpc_google_default_credentials_create(nullptr)); + return WrapChannelCredentials( + grpc_google_default_credentials_create(nullptr)); } // Builds SSL Credentials given SSL specific options @@ -135,38 +135,38 @@ void ClearStsCredentialsOptions(StsCredentialsOptions* options) { } // namespace // Builds STS credentials options from JSON. -grpc::Status StsCredentialsOptionsFromJson(const TString& json_string, +grpc::Status StsCredentialsOptionsFromJson(const TString& json_string, StsCredentialsOptions* options) { if (options == nullptr) { return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "options cannot be nullptr."); } ClearStsCredentialsOptions(options); - grpc_error* 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) { - GRPC_ERROR_UNREF(error); + grpc_error* 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) { + GRPC_ERROR_UNREF(error); return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid json."); } // Required fields. const char* value = grpc_json_get_string_property( - json, "token_exchange_service_uri", nullptr); + json, "token_exchange_service_uri", nullptr); if (value == nullptr) { ClearStsCredentialsOptions(options); return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "token_exchange_service_uri must be specified."); } options->token_exchange_service_uri.assign(value); - value = grpc_json_get_string_property(json, "subject_token_path", nullptr); + value = grpc_json_get_string_property(json, "subject_token_path", nullptr); if (value == nullptr) { ClearStsCredentialsOptions(options); return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "subject_token_path must be specified."); } options->subject_token_path.assign(value); - value = grpc_json_get_string_property(json, "subject_token_type", nullptr); + value = grpc_json_get_string_property(json, "subject_token_type", nullptr); if (value == nullptr) { ClearStsCredentialsOptions(options); return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, @@ -175,17 +175,17 @@ grpc::Status StsCredentialsOptionsFromJson(const TString& json_string, options->subject_token_type.assign(value); // Optional fields. - value = grpc_json_get_string_property(json, "resource", nullptr); + value = grpc_json_get_string_property(json, "resource", nullptr); if (value != nullptr) options->resource.assign(value); - value = grpc_json_get_string_property(json, "audience", nullptr); + value = grpc_json_get_string_property(json, "audience", nullptr); if (value != nullptr) options->audience.assign(value); - value = grpc_json_get_string_property(json, "scope", nullptr); + value = grpc_json_get_string_property(json, "scope", nullptr); if (value != nullptr) options->scope.assign(value); - value = grpc_json_get_string_property(json, "requested_token_type", nullptr); + value = grpc_json_get_string_property(json, "requested_token_type", nullptr); if (value != nullptr) options->requested_token_type.assign(value); - value = grpc_json_get_string_property(json, "actor_token_path", nullptr); + value = grpc_json_get_string_property(json, "actor_token_path", nullptr); if (value != nullptr) options->actor_token_path.assign(value); - value = grpc_json_get_string_property(json, "actor_token_type", nullptr); + value = grpc_json_get_string_property(json, "actor_token_type", nullptr); if (value != nullptr) options->actor_token_type.assign(value); return grpc::Status(); @@ -250,21 +250,21 @@ std::shared_ptr<CallCredentials> StsCredentials( return WrapCallCredentials(grpc_sts_credentials_create(&opts, nullptr)); } -std::shared_ptr<CallCredentials> MetadataCredentialsFromPlugin( - std::unique_ptr<MetadataCredentialsPlugin> plugin, - grpc_security_level min_security_level) { - grpc::GrpcLibraryCodegen init; // To call grpc_init(). - const char* type = plugin->GetType(); - grpc::MetadataCredentialsPluginWrapper* wrapper = - new grpc::MetadataCredentialsPluginWrapper(std::move(plugin)); - grpc_metadata_credentials_plugin c_plugin = { - grpc::MetadataCredentialsPluginWrapper::GetMetadata, - grpc::MetadataCredentialsPluginWrapper::DebugString, - grpc::MetadataCredentialsPluginWrapper::Destroy, wrapper, type}; - return WrapCallCredentials(grpc_metadata_credentials_create_from_plugin( - c_plugin, min_security_level, nullptr)); -} - +std::shared_ptr<CallCredentials> MetadataCredentialsFromPlugin( + std::unique_ptr<MetadataCredentialsPlugin> plugin, + grpc_security_level min_security_level) { + grpc::GrpcLibraryCodegen init; // To call grpc_init(). + const char* type = plugin->GetType(); + grpc::MetadataCredentialsPluginWrapper* wrapper = + new grpc::MetadataCredentialsPluginWrapper(std::move(plugin)); + grpc_metadata_credentials_plugin c_plugin = { + grpc::MetadataCredentialsPluginWrapper::GetMetadata, + grpc::MetadataCredentialsPluginWrapper::DebugString, + grpc::MetadataCredentialsPluginWrapper::Destroy, wrapper, type}; + return WrapCallCredentials(grpc_metadata_credentials_create_from_plugin( + c_plugin, min_security_level, nullptr)); +} + // Builds ALTS Credentials given ALTS specific options std::shared_ptr<ChannelCredentials> AltsCredentials( const AltsCredentialsOptions& options) { @@ -291,7 +291,7 @@ std::shared_ptr<ChannelCredentials> LocalCredentials( std::shared_ptr<ChannelCredentials> TlsCredentials( const TlsCredentialsOptions& options) { return WrapChannelCredentials( - grpc_tls_credentials_create(options.c_credentials_options())); + grpc_tls_credentials_create(options.c_credentials_options())); } } // namespace experimental @@ -305,7 +305,7 @@ std::shared_ptr<CallCredentials> GoogleComputeEngineCredentials() { // Builds JWT credentials. std::shared_ptr<CallCredentials> ServiceAccountJWTAccessCredentials( - const TString& json_key, long token_lifetime_seconds) { + const TString& json_key, long token_lifetime_seconds) { grpc::GrpcLibraryCodegen init; // To call grpc_init(). if (token_lifetime_seconds <= 0) { gpr_log(GPR_ERROR, @@ -320,7 +320,7 @@ std::shared_ptr<CallCredentials> ServiceAccountJWTAccessCredentials( // Builds refresh token credentials. std::shared_ptr<CallCredentials> GoogleRefreshTokenCredentials( - const TString& json_refresh_token) { + const TString& json_refresh_token) { grpc::GrpcLibraryCodegen init; // To call grpc_init(). return WrapCallCredentials(grpc_google_refresh_token_credentials_create( json_refresh_token.c_str(), nullptr)); @@ -328,7 +328,7 @@ std::shared_ptr<CallCredentials> GoogleRefreshTokenCredentials( // Builds access token credentials. std::shared_ptr<CallCredentials> AccessTokenCredentials( - const TString& access_token) { + const TString& access_token) { grpc::GrpcLibraryCodegen init; // To call grpc_init(). return WrapCallCredentials( grpc_access_token_credentials_create(access_token.c_str(), nullptr)); @@ -336,8 +336,8 @@ std::shared_ptr<CallCredentials> AccessTokenCredentials( // Builds IAM credentials. std::shared_ptr<CallCredentials> GoogleIAMCredentials( - const TString& authorization_token, - const TString& authority_selector) { + const TString& authorization_token, + const TString& authority_selector) { grpc::GrpcLibraryCodegen init; // To call grpc_init(). return WrapCallCredentials(grpc_google_iam_credentials_create( authorization_token.c_str(), authority_selector.c_str(), nullptr)); @@ -382,10 +382,10 @@ std::shared_ptr<CallCredentials> MetadataCredentialsFromPlugin( new grpc::MetadataCredentialsPluginWrapper(std::move(plugin)); grpc_metadata_credentials_plugin c_plugin = { grpc::MetadataCredentialsPluginWrapper::GetMetadata, - grpc::MetadataCredentialsPluginWrapper::DebugString, + grpc::MetadataCredentialsPluginWrapper::DebugString, grpc::MetadataCredentialsPluginWrapper::Destroy, wrapper, type}; - return WrapCallCredentials(grpc_metadata_credentials_create_from_plugin( - c_plugin, GRPC_PRIVACY_AND_INTEGRITY, nullptr)); + return WrapCallCredentials(grpc_metadata_credentials_create_from_plugin( + c_plugin, GRPC_PRIVACY_AND_INTEGRITY, nullptr)); } namespace { @@ -396,13 +396,13 @@ void DeleteWrapper(void* wrapper, grpc_error* /*ignored*/) { } } // namespace -char* MetadataCredentialsPluginWrapper::DebugString(void* wrapper) { - GPR_ASSERT(wrapper); - MetadataCredentialsPluginWrapper* w = - static_cast<MetadataCredentialsPluginWrapper*>(wrapper); - return gpr_strdup(w->plugin_->DebugString().c_str()); -} - +char* MetadataCredentialsPluginWrapper::DebugString(void* wrapper) { + GPR_ASSERT(wrapper); + MetadataCredentialsPluginWrapper* w = + static_cast<MetadataCredentialsPluginWrapper*>(wrapper); + return gpr_strdup(w->plugin_->DebugString().c_str()); +} + void MetadataCredentialsPluginWrapper::Destroy(void* wrapper) { if (wrapper == nullptr) return; grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; @@ -461,7 +461,7 @@ void MetadataCredentialsPluginWrapper::InvokePlugin( grpc_auth_metadata_context context, grpc_credentials_plugin_metadata_cb cb, void* user_data, grpc_metadata creds_md[4], size_t* num_creds_md, grpc_status_code* status_code, const char** error_details) { - std::multimap<TString, TString> metadata; + std::multimap<TString, TString> metadata; // const_cast is safe since the SecureAuthContext only inc/dec the refcount // and the object is passed as a const ref to plugin_->GetMetadata. diff --git a/contrib/libs/grpc/src/cpp/client/secure_credentials.h b/contrib/libs/grpc/src/cpp/client/secure_credentials.h index 7c02e22852b..4fc79346bf4 100644 --- a/contrib/libs/grpc/src/cpp/client/secure_credentials.h +++ b/contrib/libs/grpc/src/cpp/client/secure_credentials.h @@ -25,11 +25,11 @@ #include <grpcpp/security/tls_credentials_options.h> #include <grpcpp/support/config.h> -#include "y_absl/strings/str_cat.h" +#include "y_absl/strings/str_cat.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/cpp/server/thread_pool_interface.h" -namespace grpc { +namespace grpc { class Channel; @@ -42,13 +42,13 @@ class SecureChannelCredentials final : public ChannelCredentials { grpc_channel_credentials* GetRawCreds() { return c_creds_; } std::shared_ptr<Channel> CreateChannelImpl( - const TString& target, const ChannelArguments& args) override; + const TString& target, const ChannelArguments& args) override; SecureChannelCredentials* AsSecureCredentials() override { return this; } private: std::shared_ptr<Channel> CreateChannelWithInterceptors( - const TString& target, const ChannelArguments& args, + const TString& target, const ChannelArguments& args, std::vector<std::unique_ptr< ::grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators) override; @@ -65,10 +65,10 @@ class SecureCallCredentials final : public CallCredentials { bool ApplyToCall(grpc_call* call) override; SecureCallCredentials* AsSecureCredentials() override { return this; } - TString DebugString() override { - return y_absl::StrCat("SecureCallCredentials{", - TString(c_creds_->debug_string()), "}"); - } + TString DebugString() override { + return y_absl::StrCat("SecureCallCredentials{", + TString(c_creds_->debug_string()), "}"); + } private: grpc_call_credentials* const c_creds_; @@ -93,7 +93,7 @@ class MetadataCredentialsPluginWrapper final : private GrpcLibraryCodegen { grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX], size_t* num_creds_md, grpc_status_code* status, const char** error_details); - static char* DebugString(void* wrapper); + static char* DebugString(void* wrapper); explicit MetadataCredentialsPluginWrapper( std::unique_ptr<MetadataCredentialsPlugin> plugin); 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 3649cb84cdf..a5d42d5b53e 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 @@ -1,28 +1,28 @@ -====================Apache-2.0==================== - * 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. - - -====================COPYRIGHT==================== - * Copyright 2015 gRPC authors. - - -====================COPYRIGHT==================== - * Copyright 2016 gRPC authors. - - -====================COPYRIGHT==================== - * Copyright 2018 gRPC authors. - - -====================COPYRIGHT==================== -# Copyright 2019 gRPC authors. +====================Apache-2.0==================== + * 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. + + +====================COPYRIGHT==================== + * Copyright 2015 gRPC authors. + + +====================COPYRIGHT==================== + * Copyright 2016 gRPC authors. + + +====================COPYRIGHT==================== + * Copyright 2018 gRPC authors. + + +====================COPYRIGHT==================== +# Copyright 2019 gRPC authors. diff --git a/contrib/libs/grpc/src/cpp/common/alarm.cc b/contrib/libs/grpc/src/cpp/common/alarm.cc index 62c83f1bb23..a2612874b20 100644 --- a/contrib/libs/grpc/src/cpp/common/alarm.cc +++ b/contrib/libs/grpc/src/cpp/common/alarm.cc @@ -25,14 +25,14 @@ #include <grpcpp/impl/grpc_library.h> #include <grpcpp/support/time.h> #include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/iomgr/executor.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 grpc { namespace internal { class AlarmImpl : public ::grpc::internal::CompletionQueueTag { @@ -82,16 +82,16 @@ class AlarmImpl : public ::grpc::internal::CompletionQueueTag { Ref(); GRPC_CLOSURE_INIT(&on_alarm_, [](void* arg, grpc_error* error) { - grpc_core::Executor::Run( - GRPC_CLOSURE_CREATE( - [](void* arg, grpc_error* error) { - AlarmImpl* alarm = - static_cast<AlarmImpl*>(arg); - alarm->callback_(error == GRPC_ERROR_NONE); - alarm->Unref(); - }, - arg, nullptr), - error); + grpc_core::Executor::Run( + GRPC_CLOSURE_CREATE( + [](void* arg, grpc_error* error) { + AlarmImpl* alarm = + static_cast<AlarmImpl*>(arg); + alarm->callback_(error == GRPC_ERROR_NONE); + alarm->Unref(); + }, + arg, nullptr), + error); }, this, grpc_schedule_on_exec_ctx); grpc_timer_init(&timer_, grpc_timespec_to_millis_round_up(deadline), @@ -158,4 +158,4 @@ Alarm::~Alarm() { } void Alarm::Cancel() { static_cast<internal::AlarmImpl*>(alarm_)->Cancel(); } -} // namespace grpc +} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/common/alts_context.cc b/contrib/libs/grpc/src/cpp/common/alts_context.cc index eea14fbc803..31f0f083ef0 100644 --- a/contrib/libs/grpc/src/cpp/common/alts_context.cc +++ b/contrib/libs/grpc/src/cpp/common/alts_context.cc @@ -1,127 +1,127 @@ -/* - * - * 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 <grpc/grpc_security.h> -#include <grpcpp/security/alts_context.h> - -#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" -#include "src/proto/grpc/gcp/altscontext.upb.h" - -namespace grpc { -namespace experimental { - -// A upb-generated grpc_gcp_AltsContext is passed in to construct an -// AltsContext. Normal users should use GetAltsContextFromAuthContext to get -// AltsContext, instead of constructing their own. -AltsContext::AltsContext(const grpc_gcp_AltsContext* ctx) { - upb_strview application_protocol = - grpc_gcp_AltsContext_application_protocol(ctx); - if (application_protocol.data != nullptr && application_protocol.size > 0) { - application_protocol_ = - TString(application_protocol.data, application_protocol.size); - } - upb_strview record_protocol = grpc_gcp_AltsContext_record_protocol(ctx); - if (record_protocol.data != nullptr && record_protocol.size > 0) { - record_protocol_ = TString(record_protocol.data, record_protocol.size); - } - upb_strview peer_service_account = - grpc_gcp_AltsContext_peer_service_account(ctx); - if (peer_service_account.data != nullptr && peer_service_account.size > 0) { - peer_service_account_ = - TString(peer_service_account.data, peer_service_account.size); - } - upb_strview local_service_account = - grpc_gcp_AltsContext_local_service_account(ctx); - if (local_service_account.data != nullptr && local_service_account.size > 0) { - local_service_account_ = - TString(local_service_account.data, local_service_account.size); - } - const grpc_gcp_RpcProtocolVersions* versions = - grpc_gcp_AltsContext_peer_rpc_versions(ctx); - if (versions != nullptr) { - const grpc_gcp_RpcProtocolVersions_Version* max_version = - grpc_gcp_RpcProtocolVersions_max_rpc_version(versions); - if (max_version != nullptr) { - int max_version_major = - grpc_gcp_RpcProtocolVersions_Version_major(max_version); - int max_version_minor = - grpc_gcp_RpcProtocolVersions_Version_minor(max_version); - peer_rpc_versions_.max_rpc_version.major_version = max_version_major; - peer_rpc_versions_.max_rpc_version.minor_version = max_version_minor; - } - const grpc_gcp_RpcProtocolVersions_Version* min_version = - grpc_gcp_RpcProtocolVersions_min_rpc_version(versions); - if (min_version != nullptr) { - int min_version_major = - grpc_gcp_RpcProtocolVersions_Version_major(min_version); - int min_version_minor = - grpc_gcp_RpcProtocolVersions_Version_minor(min_version); - peer_rpc_versions_.min_rpc_version.major_version = min_version_major; - peer_rpc_versions_.min_rpc_version.minor_version = min_version_minor; - } - } - if (grpc_gcp_AltsContext_security_level(ctx) >= GRPC_SECURITY_MIN || - grpc_gcp_AltsContext_security_level(ctx) <= GRPC_SECURITY_MAX) { - security_level_ = static_cast<grpc_security_level>( - grpc_gcp_AltsContext_security_level(ctx)); - } - if (grpc_gcp_AltsContext_has_peer_attributes(ctx)) { - size_t iter = UPB_MAP_BEGIN; - const grpc_gcp_AltsContext_PeerAttributesEntry* peer_attributes_entry = - grpc_gcp_AltsContext_peer_attributes_next(ctx, &iter); - while (peer_attributes_entry != nullptr) { - upb_strview key = - grpc_gcp_AltsContext_PeerAttributesEntry_key(peer_attributes_entry); - upb_strview val = - grpc_gcp_AltsContext_PeerAttributesEntry_value(peer_attributes_entry); - peer_attributes_map_[TString(key.data, key.size)] = - TString(val.data, val.size); - peer_attributes_entry = - grpc_gcp_AltsContext_peer_attributes_next(ctx, &iter); - } - } -} - -TString AltsContext::application_protocol() const { - return application_protocol_; -} - -TString AltsContext::record_protocol() const { return record_protocol_; } - -TString AltsContext::peer_service_account() const { - return peer_service_account_; -} - -TString AltsContext::local_service_account() const { - return local_service_account_; -} - -grpc_security_level AltsContext::security_level() const { - return security_level_; -} - -AltsContext::RpcProtocolVersions AltsContext::peer_rpc_versions() const { - return peer_rpc_versions_; -} - -const std::map<TString, TString>& AltsContext::peer_attributes() const { - return peer_attributes_map_; -} - -} // namespace experimental -} // namespace grpc +/* + * + * 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 <grpc/grpc_security.h> +#include <grpcpp/security/alts_context.h> + +#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" +#include "src/proto/grpc/gcp/altscontext.upb.h" + +namespace grpc { +namespace experimental { + +// A upb-generated grpc_gcp_AltsContext is passed in to construct an +// AltsContext. Normal users should use GetAltsContextFromAuthContext to get +// AltsContext, instead of constructing their own. +AltsContext::AltsContext(const grpc_gcp_AltsContext* ctx) { + upb_strview application_protocol = + grpc_gcp_AltsContext_application_protocol(ctx); + if (application_protocol.data != nullptr && application_protocol.size > 0) { + application_protocol_ = + TString(application_protocol.data, application_protocol.size); + } + upb_strview record_protocol = grpc_gcp_AltsContext_record_protocol(ctx); + if (record_protocol.data != nullptr && record_protocol.size > 0) { + record_protocol_ = TString(record_protocol.data, record_protocol.size); + } + upb_strview peer_service_account = + grpc_gcp_AltsContext_peer_service_account(ctx); + if (peer_service_account.data != nullptr && peer_service_account.size > 0) { + peer_service_account_ = + TString(peer_service_account.data, peer_service_account.size); + } + upb_strview local_service_account = + grpc_gcp_AltsContext_local_service_account(ctx); + if (local_service_account.data != nullptr && local_service_account.size > 0) { + local_service_account_ = + TString(local_service_account.data, local_service_account.size); + } + const grpc_gcp_RpcProtocolVersions* versions = + grpc_gcp_AltsContext_peer_rpc_versions(ctx); + if (versions != nullptr) { + const grpc_gcp_RpcProtocolVersions_Version* max_version = + grpc_gcp_RpcProtocolVersions_max_rpc_version(versions); + if (max_version != nullptr) { + int max_version_major = + grpc_gcp_RpcProtocolVersions_Version_major(max_version); + int max_version_minor = + grpc_gcp_RpcProtocolVersions_Version_minor(max_version); + peer_rpc_versions_.max_rpc_version.major_version = max_version_major; + peer_rpc_versions_.max_rpc_version.minor_version = max_version_minor; + } + const grpc_gcp_RpcProtocolVersions_Version* min_version = + grpc_gcp_RpcProtocolVersions_min_rpc_version(versions); + if (min_version != nullptr) { + int min_version_major = + grpc_gcp_RpcProtocolVersions_Version_major(min_version); + int min_version_minor = + grpc_gcp_RpcProtocolVersions_Version_minor(min_version); + peer_rpc_versions_.min_rpc_version.major_version = min_version_major; + peer_rpc_versions_.min_rpc_version.minor_version = min_version_minor; + } + } + if (grpc_gcp_AltsContext_security_level(ctx) >= GRPC_SECURITY_MIN || + grpc_gcp_AltsContext_security_level(ctx) <= GRPC_SECURITY_MAX) { + security_level_ = static_cast<grpc_security_level>( + grpc_gcp_AltsContext_security_level(ctx)); + } + if (grpc_gcp_AltsContext_has_peer_attributes(ctx)) { + size_t iter = UPB_MAP_BEGIN; + const grpc_gcp_AltsContext_PeerAttributesEntry* peer_attributes_entry = + grpc_gcp_AltsContext_peer_attributes_next(ctx, &iter); + while (peer_attributes_entry != nullptr) { + upb_strview key = + grpc_gcp_AltsContext_PeerAttributesEntry_key(peer_attributes_entry); + upb_strview val = + grpc_gcp_AltsContext_PeerAttributesEntry_value(peer_attributes_entry); + peer_attributes_map_[TString(key.data, key.size)] = + TString(val.data, val.size); + peer_attributes_entry = + grpc_gcp_AltsContext_peer_attributes_next(ctx, &iter); + } + } +} + +TString AltsContext::application_protocol() const { + return application_protocol_; +} + +TString AltsContext::record_protocol() const { return record_protocol_; } + +TString AltsContext::peer_service_account() const { + return peer_service_account_; +} + +TString AltsContext::local_service_account() const { + return local_service_account_; +} + +grpc_security_level AltsContext::security_level() const { + return security_level_; +} + +AltsContext::RpcProtocolVersions AltsContext::peer_rpc_versions() const { + return peer_rpc_versions_; +} + +const std::map<TString, TString>& AltsContext::peer_attributes() const { + return peer_attributes_map_; +} + +} // namespace experimental +} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/common/alts_util.cc b/contrib/libs/grpc/src/cpp/common/alts_util.cc index 4bd7e339c02..4b955c621c9 100644 --- a/contrib/libs/grpc/src/cpp/common/alts_util.cc +++ b/contrib/libs/grpc/src/cpp/common/alts_util.cc @@ -1,82 +1,82 @@ -/* - * - * 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 "upb/upb.hpp" - -#include <grpc/grpc_security.h> -#include <grpc/support/log.h> -#include <grpcpp/security/alts_context.h> -#include <grpcpp/security/alts_util.h> - -#include "src/core/lib/gprpp/memory.h" -#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" -#include "src/cpp/common/secure_auth_context.h" -#include "src/proto/grpc/gcp/altscontext.upb.h" - -namespace grpc { -namespace experimental { - -std::unique_ptr<AltsContext> GetAltsContextFromAuthContext( - const std::shared_ptr<const AuthContext>& auth_context) { - if (auth_context == nullptr) { - gpr_log(GPR_ERROR, "auth_context is nullptr."); - return nullptr; - } - std::vector<string_ref> ctx_vector = - auth_context->FindPropertyValues(TSI_ALTS_CONTEXT); - if (ctx_vector.size() != 1) { - gpr_log(GPR_ERROR, "contains zero or more than one ALTS context."); - return nullptr; - } - upb::Arena context_arena; - grpc_gcp_AltsContext* ctx = grpc_gcp_AltsContext_parse( - ctx_vector[0].data(), ctx_vector[0].size(), context_arena.ptr()); - if (ctx == nullptr) { - gpr_log(GPR_ERROR, "fails to parse ALTS context."); - return nullptr; - } - if (grpc_gcp_AltsContext_security_level(ctx) < GRPC_SECURITY_MIN || - grpc_gcp_AltsContext_security_level(ctx) > GRPC_SECURITY_MAX) { - gpr_log(GPR_ERROR, "security_level is invalid."); - return nullptr; - } - return y_absl::make_unique<AltsContext>(AltsContext(ctx)); -} - -grpc::Status AltsClientAuthzCheck( - const std::shared_ptr<const AuthContext>& auth_context, - const std::vector<TString>& expected_service_accounts) { - std::unique_ptr<AltsContext> alts_ctx = - GetAltsContextFromAuthContext(auth_context); - if (alts_ctx == nullptr) { - return grpc::Status(grpc::StatusCode::PERMISSION_DENIED, - "fails to parse ALTS context."); - } - if (std::find(expected_service_accounts.begin(), - expected_service_accounts.end(), - alts_ctx->peer_service_account()) != - expected_service_accounts.end()) { - return grpc::Status::OK; - } - return grpc::Status( - grpc::StatusCode::PERMISSION_DENIED, - "client " + alts_ctx->peer_service_account() + " is not authorized."); -} - -} // namespace experimental -} // namespace grpc +/* + * + * 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 "upb/upb.hpp" + +#include <grpc/grpc_security.h> +#include <grpc/support/log.h> +#include <grpcpp/security/alts_context.h> +#include <grpcpp/security/alts_util.h> + +#include "src/core/lib/gprpp/memory.h" +#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h" +#include "src/cpp/common/secure_auth_context.h" +#include "src/proto/grpc/gcp/altscontext.upb.h" + +namespace grpc { +namespace experimental { + +std::unique_ptr<AltsContext> GetAltsContextFromAuthContext( + const std::shared_ptr<const AuthContext>& auth_context) { + if (auth_context == nullptr) { + gpr_log(GPR_ERROR, "auth_context is nullptr."); + return nullptr; + } + std::vector<string_ref> ctx_vector = + auth_context->FindPropertyValues(TSI_ALTS_CONTEXT); + if (ctx_vector.size() != 1) { + gpr_log(GPR_ERROR, "contains zero or more than one ALTS context."); + return nullptr; + } + upb::Arena context_arena; + grpc_gcp_AltsContext* ctx = grpc_gcp_AltsContext_parse( + ctx_vector[0].data(), ctx_vector[0].size(), context_arena.ptr()); + if (ctx == nullptr) { + gpr_log(GPR_ERROR, "fails to parse ALTS context."); + return nullptr; + } + if (grpc_gcp_AltsContext_security_level(ctx) < GRPC_SECURITY_MIN || + grpc_gcp_AltsContext_security_level(ctx) > GRPC_SECURITY_MAX) { + gpr_log(GPR_ERROR, "security_level is invalid."); + return nullptr; + } + return y_absl::make_unique<AltsContext>(AltsContext(ctx)); +} + +grpc::Status AltsClientAuthzCheck( + const std::shared_ptr<const AuthContext>& auth_context, + const std::vector<TString>& expected_service_accounts) { + std::unique_ptr<AltsContext> alts_ctx = + GetAltsContextFromAuthContext(auth_context); + if (alts_ctx == nullptr) { + return grpc::Status(grpc::StatusCode::PERMISSION_DENIED, + "fails to parse ALTS context."); + } + if (std::find(expected_service_accounts.begin(), + expected_service_accounts.end(), + alts_ctx->peer_service_account()) != + expected_service_accounts.end()) { + return grpc::Status::OK; + } + return grpc::Status( + grpc::StatusCode::PERMISSION_DENIED, + "client " + alts_ctx->peer_service_account() + " is not authorized."); +} + +} // namespace experimental +} // 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 62934a15c94..5a5dd91b5ec 100644 --- a/contrib/libs/grpc/src/cpp/common/channel_arguments.cc +++ b/contrib/libs/grpc/src/cpp/common/channel_arguments.cc @@ -27,7 +27,7 @@ #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/socket_mutator.h" -namespace grpc { +namespace grpc { ChannelArguments::ChannelArguments() { // This will be ignored if used on the server side. @@ -97,7 +97,7 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { grpc_core::ExecCtx exec_ctx; for (auto& arg : args_) { if (arg.type == mutator_arg.type && - TString(arg.key) == TString(mutator_arg.key)) { + TString(arg.key) == TString(mutator_arg.key)) { GPR_ASSERT(!replaced); arg.value.pointer.vtable->destroy(arg.value.pointer.p); arg.value.pointer = mutator_arg.value.pointer; @@ -106,7 +106,7 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { } if (!replaced) { - strings_.push_back(TString(mutator_arg.key)); + strings_.push_back(TString(mutator_arg.key)); args_.push_back(mutator_arg); args_.back().key = const_cast<char*>(strings_.back().c_str()); } @@ -117,7 +117,7 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { // prefix. The user can build up a prefix string by calling this multiple times, // each with more significant identifier. void ChannelArguments::SetUserAgentPrefix( - const TString& user_agent_prefix) { + const TString& user_agent_prefix) { if (user_agent_prefix.empty()) { return; } @@ -126,7 +126,7 @@ void ChannelArguments::SetUserAgentPrefix( for (auto& arg : args_) { ++strings_it; if (arg.type == GRPC_ARG_STRING) { - if (TString(arg.key) == GRPC_ARG_PRIMARY_USER_AGENT_STRING) { + if (TString(arg.key) == GRPC_ARG_PRIMARY_USER_AGENT_STRING) { GPR_ASSERT(arg.value.string == strings_it->c_str()); *(strings_it) = user_agent_prefix + " " + arg.value.string; arg.value.string = const_cast<char*>(strings_it->c_str()); @@ -142,7 +142,7 @@ void ChannelArguments::SetUserAgentPrefix( } void ChannelArguments::SetResourceQuota( - const grpc::ResourceQuota& resource_quota) { + const grpc::ResourceQuota& resource_quota) { SetPointerWithVtable(GRPC_ARG_RESOURCE_QUOTA, resource_quota.c_resource_quota(), grpc_resource_quota_arg_vtable()); @@ -157,16 +157,16 @@ void ChannelArguments::SetMaxSendMessageSize(int size) { } void ChannelArguments::SetLoadBalancingPolicyName( - const TString& lb_policy_name) { + const TString& lb_policy_name) { SetString(GRPC_ARG_LB_POLICY_NAME, lb_policy_name); } void ChannelArguments::SetServiceConfigJSON( - const TString& service_config_json) { + const TString& service_config_json) { SetString(GRPC_ARG_SERVICE_CONFIG, service_config_json); } -void ChannelArguments::SetInt(const TString& key, int value) { +void ChannelArguments::SetInt(const TString& key, int value) { grpc_arg arg; arg.type = GRPC_ARG_INTEGER; strings_.push_back(key); @@ -176,7 +176,7 @@ void ChannelArguments::SetInt(const TString& key, int value) { args_.push_back(arg); } -void ChannelArguments::SetPointer(const TString& key, void* value) { +void ChannelArguments::SetPointer(const TString& key, void* value) { static const grpc_arg_pointer_vtable vtable = { &PointerVtableMembers::Copy, &PointerVtableMembers::Destroy, &PointerVtableMembers::Compare}; @@ -184,7 +184,7 @@ void ChannelArguments::SetPointer(const TString& key, void* value) { } void ChannelArguments::SetPointerWithVtable( - const TString& key, void* value, + const TString& key, void* value, const grpc_arg_pointer_vtable* vtable) { grpc_arg arg; arg.type = GRPC_ARG_POINTER; @@ -195,8 +195,8 @@ void ChannelArguments::SetPointerWithVtable( args_.push_back(arg); } -void ChannelArguments::SetString(const TString& key, - const TString& value) { +void ChannelArguments::SetString(const TString& key, + const TString& value) { grpc_arg arg; arg.type = GRPC_ARG_STRING; strings_.push_back(key); @@ -214,4 +214,4 @@ void ChannelArguments::SetChannelArgs(grpc_channel_args* channel_args) const { } } -} // namespace grpc +} // 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 5e3a5d715b0..96a7105eaf4 100644 --- a/contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc +++ b/contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc @@ -24,9 +24,9 @@ #include <grpcpp/impl/grpc_library.h> #include <grpcpp/support/time.h> -namespace grpc { +namespace grpc { -static internal::GrpcLibraryInitializer g_gli_initializer; +static internal::GrpcLibraryInitializer g_gli_initializer; // 'CompletionQueue' constructor can safely call GrpcLibraryCodegen(false) here // i.e not have GrpcLibraryCodegen call grpc_init(). This is because, to create @@ -39,12 +39,12 @@ CompletionQueue::CompletionQueue(grpc_completion_queue* take) void CompletionQueue::Shutdown() { g_gli_initializer.summon(); -#ifndef NDEBUG - if (!ServerListEmpty()) { - gpr_log(GPR_ERROR, - "CompletionQueue shutdown being shutdown before its server."); - } -#endif +#ifndef NDEBUG + if (!ServerListEmpty()) { + gpr_log(GPR_ERROR, + "CompletionQueue shutdown being shutdown before its server."); + } +#endif CompleteAvalanching(); } @@ -96,4 +96,4 @@ bool CompletionQueue::CompletionQueueTLSCache::Flush(void** tag, bool* ok) { return false; } -} // namespace grpc +} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/common/resource_quota_cc.cc b/contrib/libs/grpc/src/cpp/common/resource_quota_cc.cc index e801f710ee7..64abff96338 100644 --- a/contrib/libs/grpc/src/cpp/common/resource_quota_cc.cc +++ b/contrib/libs/grpc/src/cpp/common/resource_quota_cc.cc @@ -19,11 +19,11 @@ #include <grpc/grpc.h> #include <grpcpp/resource_quota.h> -namespace grpc { +namespace grpc { ResourceQuota::ResourceQuota() : impl_(grpc_resource_quota_create(nullptr)) {} -ResourceQuota::ResourceQuota(const TString& name) +ResourceQuota::ResourceQuota(const TString& name) : impl_(grpc_resource_quota_create(name.c_str())) {} ResourceQuota::~ResourceQuota() { grpc_resource_quota_unref(impl_); } @@ -37,4 +37,4 @@ ResourceQuota& ResourceQuota::SetMaxThreads(int new_max_threads) { grpc_resource_quota_set_max_threads(impl_, new_max_threads); return *this; } -} // namespace grpc +} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/common/secure_auth_context.cc b/contrib/libs/grpc/src/cpp/common/secure_auth_context.cc index 721cb3e7fc1..e1f97889c8e 100644 --- a/contrib/libs/grpc/src/cpp/common/secure_auth_context.cc +++ b/contrib/libs/grpc/src/cpp/common/secure_auth_context.cc @@ -37,7 +37,7 @@ std::vector<grpc::string_ref> SecureAuthContext::GetPeerIdentity() const { return identity; } -TString SecureAuthContext::GetPeerIdentityPropertyName() const { +TString SecureAuthContext::GetPeerIdentityPropertyName() const { if (ctx_ == nullptr) { return ""; } @@ -46,7 +46,7 @@ TString SecureAuthContext::GetPeerIdentityPropertyName() const { } std::vector<grpc::string_ref> SecureAuthContext::FindPropertyValues( - const TString& name) const { + const TString& name) const { if (ctx_ == nullptr) { return std::vector<grpc::string_ref>(); } @@ -76,14 +76,14 @@ AuthPropertyIterator SecureAuthContext::end() const { return AuthPropertyIterator(); } -void SecureAuthContext::AddProperty(const TString& key, +void SecureAuthContext::AddProperty(const TString& key, const grpc::string_ref& value) { if (ctx_ == nullptr) return; grpc_auth_context_add_property(ctx_.get(), key.c_str(), value.data(), value.size()); } -bool SecureAuthContext::SetPeerIdentityPropertyName(const TString& name) { +bool SecureAuthContext::SetPeerIdentityPropertyName(const TString& name) { if (ctx_ == nullptr) return false; return grpc_auth_context_set_peer_identity_property_name(ctx_.get(), name.c_str()) != 0; diff --git a/contrib/libs/grpc/src/cpp/common/secure_auth_context.h b/contrib/libs/grpc/src/cpp/common/secure_auth_context.h index 60c4449876e..51013efac70 100644 --- a/contrib/libs/grpc/src/cpp/common/secure_auth_context.h +++ b/contrib/libs/grpc/src/cpp/common/secure_auth_context.h @@ -37,19 +37,19 @@ class SecureAuthContext final : public AuthContext { std::vector<grpc::string_ref> GetPeerIdentity() const override; - TString GetPeerIdentityPropertyName() const override; + TString GetPeerIdentityPropertyName() const override; std::vector<grpc::string_ref> FindPropertyValues( - const TString& name) const override; + const TString& name) const override; AuthPropertyIterator begin() const override; AuthPropertyIterator end() const override; - void AddProperty(const TString& key, + void AddProperty(const TString& key, const grpc::string_ref& value) override; - virtual bool SetPeerIdentityPropertyName(const TString& name) override; + virtual bool SetPeerIdentityPropertyName(const TString& name) override; private: grpc_core::RefCountedPtr<grpc_auth_context> ctx_; 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 736d6083a0b..844bc627ab3 100644 --- a/contrib/libs/grpc/src/cpp/common/secure_channel_arguments.cc +++ b/contrib/libs/grpc/src/cpp/common/secure_channel_arguments.cc @@ -21,19 +21,19 @@ #include <grpc/grpc_security.h> #include "src/core/lib/channel/channel_args.h" -namespace grpc { +namespace grpc { -void ChannelArguments::SetSslTargetNameOverride(const TString& name) { +void ChannelArguments::SetSslTargetNameOverride(const TString& name) { SetString(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, name); } -TString ChannelArguments::GetSslTargetNameOverride() const { +TString ChannelArguments::GetSslTargetNameOverride() const { for (unsigned int i = 0; i < args_.size(); i++) { - if (TString(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == args_[i].key) { + if (TString(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == args_[i].key) { return args_[i].value.string; } } return ""; } -} // namespace grpc +} // 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 22b03ac1887..7e435ac1de3 100644 --- a/contrib/libs/grpc/src/cpp/common/tls_credentials_options.cc +++ b/contrib/libs/grpc/src/cpp/common/tls_credentials_options.cc @@ -16,20 +16,20 @@ * */ -#include <grpc/support/alloc.h> +#include <grpc/support/alloc.h> #include <grpcpp/security/tls_credentials_options.h> - -#include "y_absl/container/inlined_vector.h" + +#include "y_absl/container/inlined_vector.h" #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" #include "src/cpp/common/tls_credentials_options_util.h" -namespace grpc { +namespace grpc { namespace experimental { /** TLS key materials config API implementation **/ -void TlsKeyMaterialsConfig::set_pem_root_certs( - const TString& pem_root_certs) { - pem_root_certs_ = pem_root_certs; +void TlsKeyMaterialsConfig::set_pem_root_certs( + const TString& pem_root_certs) { + pem_root_certs_ = pem_root_certs; } void TlsKeyMaterialsConfig::add_pem_key_cert_pair( @@ -38,10 +38,10 @@ void TlsKeyMaterialsConfig::add_pem_key_cert_pair( } void TlsKeyMaterialsConfig::set_key_materials( - const TString& pem_root_certs, - const std::vector<PemKeyCertPair>& pem_key_cert_pair_list) { - pem_key_cert_pair_list_ = pem_key_cert_pair_list; - pem_root_certs_ = pem_root_certs; + const TString& pem_root_certs, + const std::vector<PemKeyCertPair>& pem_key_cert_pair_list) { + pem_key_cert_pair_list_ = pem_key_cert_pair_list; + pem_root_certs_ = pem_root_certs; } /** TLS credential reload arg API implementation **/ @@ -69,8 +69,8 @@ grpc_ssl_certificate_config_reload_status TlsCredentialReloadArg::status() return c_arg_->status; } -TString TlsCredentialReloadArg::error_details() const { - return c_arg_->error_details->error_details(); +TString TlsCredentialReloadArg::error_details() const { + return c_arg_->error_details->error_details(); } void TlsCredentialReloadArg::set_cb_user_data(void* cb_user_data) { @@ -78,59 +78,59 @@ void TlsCredentialReloadArg::set_cb_user_data(void* cb_user_data) { } void TlsCredentialReloadArg::set_pem_root_certs( - const TString& pem_root_certs) { + const TString& pem_root_certs) { ::grpc_core::UniquePtr<char> c_pem_root_certs( gpr_strdup(pem_root_certs.c_str())); c_arg_->key_materials_config->set_pem_root_certs(std::move(c_pem_root_certs)); } -namespace { - -::grpc_core::PemKeyCertPair ConvertToCorePemKeyCertPair( - const TlsKeyMaterialsConfig::PemKeyCertPair& pem_key_cert_pair) { +namespace { + +::grpc_core::PemKeyCertPair ConvertToCorePemKeyCertPair( + const TlsKeyMaterialsConfig::PemKeyCertPair& pem_key_cert_pair) { grpc_ssl_pem_key_cert_pair* ssl_pair = (grpc_ssl_pem_key_cert_pair*)gpr_malloc( sizeof(grpc_ssl_pem_key_cert_pair)); ssl_pair->private_key = gpr_strdup(pem_key_cert_pair.private_key.c_str()); ssl_pair->cert_chain = gpr_strdup(pem_key_cert_pair.cert_chain.c_str()); - return ::grpc_core::PemKeyCertPair(ssl_pair); -} - -} // namespace - -void TlsCredentialReloadArg::add_pem_key_cert_pair( - const TlsKeyMaterialsConfig::PemKeyCertPair& pem_key_cert_pair) { + return ::grpc_core::PemKeyCertPair(ssl_pair); +} + +} // namespace + +void TlsCredentialReloadArg::add_pem_key_cert_pair( + const TlsKeyMaterialsConfig::PemKeyCertPair& pem_key_cert_pair) { c_arg_->key_materials_config->add_pem_key_cert_pair( - ConvertToCorePemKeyCertPair(pem_key_cert_pair)); -} - -void TlsCredentialReloadArg::set_key_materials( - const TString& pem_root_certs, - std::vector<TlsKeyMaterialsConfig::PemKeyCertPair> pem_key_cert_pair_list) { - /** Initialize the |key_materials_config| field of |c_arg_|, if it has not - * already been done. **/ - if (c_arg_->key_materials_config == nullptr) { - c_arg_->key_materials_config = grpc_tls_key_materials_config_create(); - } - /** Convert |pem_key_cert_pair_list| to an inlined vector of ssl pairs. **/ - ::y_absl::InlinedVector<::grpc_core::PemKeyCertPair, 1> - c_pem_key_cert_pair_list; - for (const auto& key_cert_pair : pem_key_cert_pair_list) { - c_pem_key_cert_pair_list.emplace_back( - ConvertToCorePemKeyCertPair(key_cert_pair)); - } - /** Populate the key materials config field of |c_arg_|. **/ - c_arg_->key_materials_config->set_key_materials(pem_root_certs.c_str(), - c_pem_key_cert_pair_list); -} - + ConvertToCorePemKeyCertPair(pem_key_cert_pair)); +} + +void TlsCredentialReloadArg::set_key_materials( + const TString& pem_root_certs, + std::vector<TlsKeyMaterialsConfig::PemKeyCertPair> pem_key_cert_pair_list) { + /** Initialize the |key_materials_config| field of |c_arg_|, if it has not + * already been done. **/ + if (c_arg_->key_materials_config == nullptr) { + c_arg_->key_materials_config = grpc_tls_key_materials_config_create(); + } + /** Convert |pem_key_cert_pair_list| to an inlined vector of ssl pairs. **/ + ::y_absl::InlinedVector<::grpc_core::PemKeyCertPair, 1> + c_pem_key_cert_pair_list; + for (const auto& key_cert_pair : pem_key_cert_pair_list) { + c_pem_key_cert_pair_list.emplace_back( + ConvertToCorePemKeyCertPair(key_cert_pair)); + } + /** Populate the key materials config field of |c_arg_|. **/ + c_arg_->key_materials_config->set_key_materials(pem_root_certs.c_str(), + c_pem_key_cert_pair_list); +} + void TlsCredentialReloadArg::set_key_materials_config( const std::shared_ptr<TlsKeyMaterialsConfig>& key_materials_config) { if (key_materials_config == nullptr) { c_arg_->key_materials_config = nullptr; return; } - ::y_absl::InlinedVector<::grpc_core::PemKeyCertPair, 1> + ::y_absl::InlinedVector<::grpc_core::PemKeyCertPair, 1> c_pem_key_cert_pair_list; for (const auto& key_cert_pair : key_materials_config->pem_key_cert_pair_list()) { @@ -149,7 +149,7 @@ void TlsCredentialReloadArg::set_key_materials_config( c_arg_->key_materials_config = grpc_tls_key_materials_config_create(); } c_arg_->key_materials_config->set_key_materials( - key_materials_config->pem_root_certs().c_str(), c_pem_key_cert_pair_list); + key_materials_config->pem_root_certs().c_str(), c_pem_key_cert_pair_list); c_arg_->key_materials_config->set_version(key_materials_config->version()); } @@ -159,8 +159,8 @@ void TlsCredentialReloadArg::set_status( } void TlsCredentialReloadArg::set_error_details( - const TString& error_details) { - c_arg_->error_details->set_error_details(error_details.c_str()); + const TString& error_details) { + c_arg_->error_details->set_error_details(error_details.c_str()); } void TlsCredentialReloadArg::OnCredentialReloadDoneCallback() { @@ -202,27 +202,27 @@ void* TlsServerAuthorizationCheckArg::cb_user_data() const { int TlsServerAuthorizationCheckArg::success() const { return c_arg_->success; } -TString TlsServerAuthorizationCheckArg::target_name() const { - TString cpp_target_name(c_arg_->target_name); +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); +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; -} - +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(); +TString TlsServerAuthorizationCheckArg::error_details() const { + return c_arg_->error_details->error_details(); } void TlsServerAuthorizationCheckArg::set_cb_user_data(void* cb_user_data) { @@ -234,27 +234,27 @@ void TlsServerAuthorizationCheckArg::set_success(int success) { } void TlsServerAuthorizationCheckArg::set_target_name( - const TString& 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) { + 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_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()); + const TString& error_details) { + c_arg_->error_details->set_error_details(error_details.c_str()); } void TlsServerAuthorizationCheckArg::OnServerAuthorizationCheckDoneCallback() { @@ -281,33 +281,33 @@ TlsServerAuthorizationCheckConfig::~TlsServerAuthorizationCheckConfig() {} /** gRPC TLS credential options API implementation **/ TlsCredentialsOptions::TlsCredentialsOptions( - grpc_tls_server_verification_option server_verification_option, - std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config, - std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config, - std::shared_ptr<TlsServerAuthorizationCheckConfig> - server_authorization_check_config) - : TlsCredentialsOptions( - GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, server_verification_option, - std::move(key_materials_config), std::move(credential_reload_config), - std::move(server_authorization_check_config)) {} - -TlsCredentialsOptions::TlsCredentialsOptions( + grpc_tls_server_verification_option server_verification_option, + std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config, + std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config, + std::shared_ptr<TlsServerAuthorizationCheckConfig> + server_authorization_check_config) + : TlsCredentialsOptions( + GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, server_verification_option, + std::move(key_materials_config), std::move(credential_reload_config), + std::move(server_authorization_check_config)) {} + +TlsCredentialsOptions::TlsCredentialsOptions( + grpc_ssl_client_certificate_request_type cert_request_type, + std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config, + std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config) + : TlsCredentialsOptions(cert_request_type, GRPC_TLS_SERVER_VERIFICATION, + std::move(key_materials_config), + std::move(credential_reload_config), nullptr) {} + +TlsCredentialsOptions::TlsCredentialsOptions( grpc_ssl_client_certificate_request_type cert_request_type, - std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config, - std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config) - : TlsCredentialsOptions(cert_request_type, GRPC_TLS_SERVER_VERIFICATION, - std::move(key_materials_config), - std::move(credential_reload_config), nullptr) {} - -TlsCredentialsOptions::TlsCredentialsOptions( - grpc_ssl_client_certificate_request_type cert_request_type, - grpc_tls_server_verification_option server_verification_option, + grpc_tls_server_verification_option server_verification_option, std::shared_ptr<TlsKeyMaterialsConfig> key_materials_config, std::shared_ptr<TlsCredentialReloadConfig> credential_reload_config, std::shared_ptr<TlsServerAuthorizationCheckConfig> server_authorization_check_config) : cert_request_type_(cert_request_type), - server_verification_option_(server_verification_option), + server_verification_option_(server_verification_option), key_materials_config_(std::move(key_materials_config)), credential_reload_config_(std::move(credential_reload_config)), server_authorization_check_config_( @@ -328,16 +328,16 @@ TlsCredentialsOptions::TlsCredentialsOptions( grpc_tls_credentials_options_set_server_authorization_check_config( c_credentials_options_, server_authorization_check_config_->c_config()); } - grpc_tls_credentials_options_set_server_verification_option( - c_credentials_options_, server_verification_option); + grpc_tls_credentials_options_set_server_verification_option( + c_credentials_options_, server_verification_option); } -/** Whenever a TlsCredentialsOptions instance is created, the caller takes - * ownership of the c_credentials_options_ pointer (see e.g. the implementation - * of the TlsCredentials API in secure_credentials.cc). For this reason, the - * TlsCredentialsOptions destructor is not responsible for freeing - * c_credentials_options_. **/ +/** Whenever a TlsCredentialsOptions instance is created, the caller takes + * ownership of the c_credentials_options_ pointer (see e.g. the implementation + * of the TlsCredentials API in secure_credentials.cc). For this reason, the + * TlsCredentialsOptions destructor is not responsible for freeing + * c_credentials_options_. **/ TlsCredentialsOptions::~TlsCredentialsOptions() {} } // namespace experimental -} // namespace grpc +} // namespace grpc 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 index cdcf00376ea..ed84003212b 100644 --- a/contrib/libs/grpc/src/cpp/common/tls_credentials_options_util.cc +++ b/contrib/libs/grpc/src/cpp/common/tls_credentials_options_util.cc @@ -16,12 +16,12 @@ * */ -#include "y_absl/container/inlined_vector.h" - -#include <grpcpp/security/tls_credentials_options.h> +#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 grpc { namespace experimental { /** Converts the Cpp key materials to C key materials; this allocates memory for @@ -37,7 +37,7 @@ grpc_tls_key_materials_config* ConvertToCKeyMaterialsConfig( } grpc_tls_key_materials_config* c_config = grpc_tls_key_materials_config_create(); - ::y_absl::InlinedVector<::grpc_core::PemKeyCertPair, 1> + ::y_absl::InlinedVector<::grpc_core::PemKeyCertPair, 1> c_pem_key_cert_pair_list; for (const auto& key_cert_pair : config->pem_key_cert_pair_list()) { grpc_ssl_pem_key_cert_pair* ssl_pair = @@ -49,8 +49,8 @@ grpc_tls_key_materials_config* ConvertToCKeyMaterialsConfig( ::grpc_core::PemKeyCertPair(ssl_pair); c_pem_key_cert_pair_list.push_back(::std::move(c_pem_key_cert_pair)); } - c_config->set_key_materials(config->pem_root_certs().c_str(), - c_pem_key_cert_pair_list); + c_config->set_key_materials(config->pem_root_certs().c_str(), + c_pem_key_cert_pair_list); c_config->set_version(config->version()); return c_config; } @@ -146,4 +146,4 @@ void TlsServerAuthorizationCheckArgDestroyContext(void* context) { } } // namespace experimental -} // namespace grpc +} // 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 index 6ffa0a67ddc..4ee04d15d7f 100644 --- a/contrib/libs/grpc/src/cpp/common/tls_credentials_options_util.h +++ b/contrib/libs/grpc/src/cpp/common/tls_credentials_options_util.h @@ -24,7 +24,7 @@ #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" -namespace grpc { +namespace grpc { namespace experimental { /** The following function is exposed for testing purposes. **/ @@ -53,6 +53,6 @@ void TlsCredentialReloadArgDestroyContext(void* context); void TlsServerAuthorizationCheckArgDestroyContext(void* context); } // namespace experimental -} // namespace grpc +} // 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 5a139e33070..f63cfbc68c9 100644 --- a/contrib/libs/grpc/src/cpp/common/validate_service_config.cc +++ b/contrib/libs/grpc/src/cpp/common/validate_service_config.cc @@ -23,12 +23,12 @@ namespace grpc { namespace experimental { -TString ValidateServiceConfigJSON(const TString& service_config_json) { +TString ValidateServiceConfigJSON(const TString& service_config_json) { grpc_init(); grpc_error* error = GRPC_ERROR_NONE; - grpc_core::ServiceConfig::Create(/*args=*/nullptr, - service_config_json.c_str(), &error); - TString return_value; + 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); GRPC_ERROR_UNREF(error); diff --git a/contrib/libs/grpc/src/cpp/common/version_cc.cc b/contrib/libs/grpc/src/cpp/common/version_cc.cc index dfaa505461f..7f4228346a9 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.33.2"; } +TString Version() { return "1.33.2"; } } // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/common/ya.make b/contrib/libs/grpc/src/cpp/common/ya.make index 7364db41c10..f1966dce37b 100644 --- a/contrib/libs/grpc/src/cpp/common/ya.make +++ b/contrib/libs/grpc/src/cpp/common/ya.make @@ -1,41 +1,41 @@ -# Generated by devtools/yamaker. - -LIBRARY() - -OWNER(g:cpp-contrib) - -LICENSE(Apache-2.0) - -LICENSE_TEXTS(.yandex_meta/licenses.list.txt) - -PEERDIR( - contrib/libs/grpc/grpc - contrib/libs/grpc/grpc++ - contrib/libs/grpc/src/core/lib - contrib/libs/grpc/third_party/address_sorting - contrib/libs/grpc/third_party/upb - contrib/libs/openssl -) - -ADDINCL( - GLOBAL contrib/libs/grpc/include - ${ARCADIA_BUILD_ROOT}/contrib/libs/grpc - contrib/libs/grpc - contrib/libs/grpc/src/core/ext/upb-generated - contrib/libs/grpc/third_party/upb -) - -NO_COMPILER_WARNINGS() - -IF (OS_LINUX OR OS_DARWIN) - CFLAGS( - -DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1 - ) -ENDIF() - -SRCS( - alts_context.cc - alts_util.cc -) - -END() +# Generated by devtools/yamaker. + +LIBRARY() + +OWNER(g:cpp-contrib) + +LICENSE(Apache-2.0) + +LICENSE_TEXTS(.yandex_meta/licenses.list.txt) + +PEERDIR( + contrib/libs/grpc/grpc + contrib/libs/grpc/grpc++ + contrib/libs/grpc/src/core/lib + contrib/libs/grpc/third_party/address_sorting + contrib/libs/grpc/third_party/upb + contrib/libs/openssl +) + +ADDINCL( + GLOBAL contrib/libs/grpc/include + ${ARCADIA_BUILD_ROOT}/contrib/libs/grpc + contrib/libs/grpc + contrib/libs/grpc/src/core/ext/upb-generated + contrib/libs/grpc/third_party/upb +) + +NO_COMPILER_WARNINGS() + +IF (OS_LINUX OR OS_DARWIN) + CFLAGS( + -DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1 + ) +ENDIF() + +SRCS( + alts_context.cc + alts_util.cc +) + +END() 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 132c10c6817..1b388210c05 100644 --- a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.cc +++ b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.cc @@ -40,7 +40,7 @@ ProtoServerReflection::ProtoServerReflection() : descriptor_pool_(protobuf::DescriptorPool::generated_pool()) {} void ProtoServerReflection::SetServiceList( - const std::vector<TString>* services) { + const std::vector<TString>* services) { services_ = services; } @@ -110,7 +110,7 @@ Status ProtoServerReflection::ListService(ServerContext* /*context*/, } Status ProtoServerReflection::GetFileByName( - ServerContext* /*context*/, const TString& filename, + ServerContext* /*context*/, const TString& filename, ServerReflectionResponse* response) { if (descriptor_pool_ == nullptr) { return Status::CANCELLED; @@ -121,13 +121,13 @@ Status ProtoServerReflection::GetFileByName( if (file_desc == nullptr) { return Status(StatusCode::NOT_FOUND, "File not found."); } - std::unordered_set<TString> seen_files; + std::unordered_set<TString> seen_files; FillFileDescriptorResponse(file_desc, response, &seen_files); return Status::OK; } Status ProtoServerReflection::GetFileContainingSymbol( - ServerContext* /*context*/, const TString& symbol, + ServerContext* /*context*/, const TString& symbol, ServerReflectionResponse* response) { if (descriptor_pool_ == nullptr) { return Status::CANCELLED; @@ -138,7 +138,7 @@ Status ProtoServerReflection::GetFileContainingSymbol( if (file_desc == nullptr) { return Status(StatusCode::NOT_FOUND, "Symbol not found."); } - std::unordered_set<TString> seen_files; + std::unordered_set<TString> seen_files; FillFileDescriptorResponse(file_desc, response, &seen_files); return Status::OK; } @@ -162,13 +162,13 @@ Status ProtoServerReflection::GetFileContainingExtension( if (field_desc == nullptr) { return Status(StatusCode::NOT_FOUND, "Extension not found."); } - std::unordered_set<TString> seen_files; + std::unordered_set<TString> seen_files; FillFileDescriptorResponse(field_desc->file(), response, &seen_files); return Status::OK; } Status ProtoServerReflection::GetAllExtensionNumbers( - ServerContext* /*context*/, const TString& type, + ServerContext* /*context*/, const TString& type, ExtensionNumberResponse* response) { if (descriptor_pool_ == nullptr) { return Status::CANCELLED; @@ -192,7 +192,7 @@ Status ProtoServerReflection::GetAllExtensionNumbers( void ProtoServerReflection::FillFileDescriptorResponse( const protobuf::FileDescriptor* file_desc, ServerReflectionResponse* response, - std::unordered_set<TString>* seen_files) { + std::unordered_set<TString>* seen_files) { if (seen_files->find(file_desc->name()) != seen_files->end()) { return; } 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 2dbdedef58d..2d17eed95a8 100644 --- a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.h +++ b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.h @@ -33,7 +33,7 @@ class ProtoServerReflection final ProtoServerReflection(); // Add the full names of registered services - void SetServiceList(const std::vector<TString>* services); + void SetServiceList(const std::vector<TString>* services); // implementation of ServerReflectionInfo(stream ServerReflectionRequest) rpc // in ServerReflection service @@ -47,11 +47,11 @@ class ProtoServerReflection final Status ListService(ServerContext* context, reflection::v1alpha::ListServiceResponse* response); - Status GetFileByName(ServerContext* context, const TString& file_name, + Status GetFileByName(ServerContext* context, const TString& file_name, reflection::v1alpha::ServerReflectionResponse* response); Status GetFileContainingSymbol( - ServerContext* context, const TString& symbol, + ServerContext* context, const TString& symbol, reflection::v1alpha::ServerReflectionResponse* response); Status GetFileContainingExtension( @@ -60,13 +60,13 @@ class ProtoServerReflection final reflection::v1alpha::ServerReflectionResponse* response); Status GetAllExtensionNumbers( - ServerContext* context, const TString& type, + ServerContext* context, const TString& type, reflection::v1alpha::ExtensionNumberResponse* response); void FillFileDescriptorResponse( const protobuf::FileDescriptor* file_desc, reflection::v1alpha::ServerReflectionResponse* response, - std::unordered_set<TString>* seen_files); + std::unordered_set<TString>* seen_files); void FillErrorResponse(const Status& status, reflection::v1alpha::ErrorResponse* error_response); diff --git a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection_plugin.cc b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection_plugin.cc index 63a25cdf589..007193d7f72 100644 --- a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection_plugin.cc +++ b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection_plugin.cc @@ -23,13 +23,13 @@ #include "src/cpp/ext/proto_server_reflection.h" -namespace grpc { +namespace grpc { namespace reflection { ProtoServerReflectionPlugin::ProtoServerReflectionPlugin() : reflection_service_(new grpc::ProtoServerReflection()) {} -TString ProtoServerReflectionPlugin::name() { +TString ProtoServerReflectionPlugin::name() { return "proto_server_reflection"; } @@ -41,7 +41,7 @@ void ProtoServerReflectionPlugin::Finish(grpc::ServerInitializer* si) { reflection_service_->SetServiceList(si->GetServiceList()); } -void ProtoServerReflectionPlugin::ChangeArguments(const TString& /*name*/, +void ProtoServerReflectionPlugin::ChangeArguments(const TString& /*name*/, void* /*value*/) {} bool ProtoServerReflectionPlugin::has_sync_methods() const { @@ -64,11 +64,11 @@ static std::unique_ptr< ::grpc::ServerBuilderPlugin> CreateProtoReflection() { } void InitProtoReflectionServerBuilderPlugin() { - static struct Initialize { - Initialize() { - ::grpc::ServerBuilder::InternalAddPluginFactory(&CreateProtoReflection); - } - } initializer; + static struct Initialize { + Initialize() { + ::grpc::ServerBuilder::InternalAddPluginFactory(&CreateProtoReflection); + } + } initializer; } // Force InitProtoReflectionServerBuilderPlugin() to be called at static @@ -80,4 +80,4 @@ struct StaticProtoReflectionPluginInitializer { } static_proto_reflection_plugin_initializer; } // namespace reflection -} // namespace grpc +} // 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 0e4e95465f8..07697a52d1f 100644 --- a/contrib/libs/grpc/src/cpp/server/async_generic_service.cc +++ b/contrib/libs/grpc/src/cpp/server/async_generic_service.cc @@ -24,8 +24,8 @@ namespace grpc { void AsyncGenericService::RequestCall( GenericServerContext* ctx, GenericServerAsyncReaderWriter* reader_writer, - ::grpc::CompletionQueue* call_cq, - ::grpc::ServerCompletionQueue* notification_cq, void* tag) { + ::grpc::CompletionQueue* call_cq, + ::grpc::ServerCompletionQueue* notification_cq, void* tag) { server_->RequestAsyncGenericCall(ctx, reader_writer, call_cq, notification_cq, tag); } diff --git a/contrib/libs/grpc/src/cpp/server/channel_argument_option.cc b/contrib/libs/grpc/src/cpp/server/channel_argument_option.cc index 69ee6eed686..9aad932429d 100644 --- a/contrib/libs/grpc/src/cpp/server/channel_argument_option.cc +++ b/contrib/libs/grpc/src/cpp/server/channel_argument_option.cc @@ -21,10 +21,10 @@ namespace grpc { std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption( - const TString& name, const TString& value) { + const TString& name, const TString& value) { class StringOption final : public ServerBuilderOption { public: - StringOption(const TString& name, const TString& value) + StringOption(const TString& name, const TString& value) : name_(name), value_(value) {} virtual void UpdateArguments(ChannelArguments* args) override { @@ -35,17 +35,17 @@ std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption( override {} private: - const TString name_; - const TString value_; + const TString name_; + const TString value_; }; return std::unique_ptr<ServerBuilderOption>(new StringOption(name, value)); } std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption( - const TString& name, int value) { + const TString& name, int value) { class IntOption final : public ServerBuilderOption { public: - IntOption(const TString& name, int value) + IntOption(const TString& name, int value) : name_(name), value_(value) {} virtual void UpdateArguments(ChannelArguments* args) override { @@ -56,7 +56,7 @@ std::unique_ptr<ServerBuilderOption> MakeChannelArgumentOption( override {} private: - const TString name_; + const TString name_; const int value_; }; return std::unique_ptr<ServerBuilderOption>(new IntOption(name, value)); diff --git a/contrib/libs/grpc/src/cpp/server/channelz/channelz_service.cc b/contrib/libs/grpc/src/cpp/server/channelz/channelz_service.cc index 1f402ef53d2..6dcf84bf40d 100644 --- a/contrib/libs/grpc/src/cpp/server/channelz/channelz_service.cc +++ b/contrib/libs/grpc/src/cpp/server/channelz/channelz_service.cc @@ -24,9 +24,9 @@ #include <grpc/support/alloc.h> namespace grpc { - -namespace { - + +namespace { + grpc::protobuf::util::Status ParseJson(const char* json_str, grpc::protobuf::Message* message) { grpc::protobuf::json::JsonParseOptions options; @@ -34,8 +34,8 @@ grpc::protobuf::util::Status ParseJson(const char* json_str, return grpc::protobuf::json::JsonStringToMessage(json_str, message, options); } -} // namespace - +} // namespace + Status ChannelzService::GetTopChannels( ServerContext* /*unused*/, const channelz::v1::GetTopChannelsRequest* request, diff --git a/contrib/libs/grpc/src/cpp/server/channelz/channelz_service_plugin.cc b/contrib/libs/grpc/src/cpp/server/channelz/channelz_service_plugin.cc index bae1b595440..ae26a447ab3 100644 --- a/contrib/libs/grpc/src/cpp/server/channelz/channelz_service_plugin.cc +++ b/contrib/libs/grpc/src/cpp/server/channelz/channelz_service_plugin.cc @@ -33,7 +33,7 @@ class ChannelzServicePlugin : public ::grpc::ServerBuilderPlugin { public: ChannelzServicePlugin() : channelz_service_(new grpc::ChannelzService()) {} - TString name() override { return "channelz_service"; } + TString name() override { return "channelz_service"; } void InitServer(grpc::ServerInitializer* si) override { si->RegisterService(channelz_service_); @@ -41,7 +41,7 @@ class ChannelzServicePlugin : public ::grpc::ServerBuilderPlugin { void Finish(grpc::ServerInitializer* /*si*/) override {} - void ChangeArguments(const TString& /*name*/, void* /*value*/) override {} + void ChangeArguments(const TString& /*name*/, void* /*value*/) override {} bool has_sync_methods() const override { if (channelz_service_) { @@ -75,12 +75,12 @@ namespace channelz { namespace experimental { void InitChannelzService() { - static struct Initializer { - Initializer() { - ::grpc::ServerBuilder::InternalAddPluginFactory( - &grpc::channelz::experimental::CreateChannelzServicePlugin); - } - } initialize; + static struct Initializer { + Initializer() { + ::grpc::ServerBuilder::InternalAddPluginFactory( + &grpc::channelz::experimental::CreateChannelzServicePlugin); + } + } initialize; } } // namespace experimental diff --git a/contrib/libs/grpc/src/cpp/server/external_connection_acceptor_impl.cc b/contrib/libs/grpc/src/cpp/server/external_connection_acceptor_impl.cc index 9641301ab72..09d2a9d3b56 100644 --- a/contrib/libs/grpc/src/cpp/server/external_connection_acceptor_impl.cc +++ b/contrib/libs/grpc/src/cpp/server/external_connection_acceptor_impl.cc @@ -20,7 +20,7 @@ #include <memory> -#include <grpcpp/server_builder.h> +#include <grpcpp/server_builder.h> #include <grpcpp/support/channel_arguments.h> namespace grpc { @@ -42,7 +42,7 @@ class AcceptorWrapper : public experimental::ExternalConnectionAcceptor { } // namespace ExternalConnectionAcceptorImpl::ExternalConnectionAcceptorImpl( - const TString& name, + const TString& name, ServerBuilder::experimental_type::ExternalConnectionType type, std::shared_ptr<ServerCredentials> creds) : name_(name), creds_(std::move(creds)) { diff --git a/contrib/libs/grpc/src/cpp/server/external_connection_acceptor_impl.h b/contrib/libs/grpc/src/cpp/server/external_connection_acceptor_impl.h index 8a1179bef2a..430c72862ea 100644 --- a/contrib/libs/grpc/src/cpp/server/external_connection_acceptor_impl.h +++ b/contrib/libs/grpc/src/cpp/server/external_connection_acceptor_impl.h @@ -36,7 +36,7 @@ class ExternalConnectionAcceptorImpl : public std::enable_shared_from_this<ExternalConnectionAcceptorImpl> { public: ExternalConnectionAcceptorImpl( - const TString& name, + const TString& name, ServerBuilder::experimental_type::ExternalConnectionType type, std::shared_ptr<ServerCredentials> creds); // Should only be called once. @@ -56,7 +56,7 @@ class ExternalConnectionAcceptorImpl void SetToChannelArgs(::grpc::ChannelArguments* args); private: - const TString name_; + const TString name_; std::shared_ptr<ServerCredentials> creds_; grpc_core::TcpServerFdHandler* handler_ = nullptr; // not owned grpc_core::Mutex mu_; 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 059c97a4145..3cc508d0cbf 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 @@ -18,16 +18,16 @@ #include <memory> -#include "upb/upb.hpp" - +#include "upb/upb.hpp" + #include <grpc/slice.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include <grpcpp/impl/codegen/method_handler.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" +#include "upb/upb.hpp" #define MAX_SERVICE_NAME_LENGTH 200 @@ -42,7 +42,7 @@ DefaultHealthCheckService::DefaultHealthCheckService() { } void DefaultHealthCheckService::SetServingStatus( - const TString& service_name, bool serving) { + const TString& service_name, bool serving) { grpc_core::MutexLock lock(&mu_); if (shutdown_) { // Set to NOT_SERVING in case service_name is not in the map. @@ -77,7 +77,7 @@ void DefaultHealthCheckService::Shutdown() { DefaultHealthCheckService::ServingStatus DefaultHealthCheckService::GetServingStatus( - const TString& service_name) const { + const TString& service_name) const { grpc_core::MutexLock lock(&mu_); auto it = services_map_.find(service_name); if (it == services_map_.end()) { @@ -88,7 +88,7 @@ DefaultHealthCheckService::GetServingStatus( } void DefaultHealthCheckService::RegisterCallHandler( - const TString& service_name, + const TString& service_name, std::shared_ptr<HealthCheckServiceImpl::CallHandler> handler) { grpc_core::MutexLock lock(&mu_); ServiceData& service_data = services_map_[service_name]; @@ -98,7 +98,7 @@ void DefaultHealthCheckService::RegisterCallHandler( } void DefaultHealthCheckService::UnregisterCallHandler( - const TString& service_name, + const TString& service_name, const std::shared_ptr<HealthCheckServiceImpl::CallHandler>& handler) { grpc_core::MutexLock lock(&mu_); auto it = services_map_.find(service_name); @@ -185,7 +185,7 @@ void DefaultHealthCheckService::HealthCheckServiceImpl::StartServingThread() { } void DefaultHealthCheckService::HealthCheckServiceImpl::Serve(void* arg) { - HealthCheckServiceImpl* service = static_cast<HealthCheckServiceImpl*>(arg); + HealthCheckServiceImpl* service = static_cast<HealthCheckServiceImpl*>(arg); void* tag; bool ok; while (true) { @@ -200,7 +200,7 @@ void DefaultHealthCheckService::HealthCheckServiceImpl::Serve(void* arg) { } bool DefaultHealthCheckService::HealthCheckServiceImpl::DecodeRequest( - const ByteBuffer& request, TString* service_name) { + const ByteBuffer& request, TString* service_name) { std::vector<Slice> slices; if (!request.Dump(&slices).ok()) return false; uint8_t* request_bytes = nullptr; @@ -301,7 +301,7 @@ void DefaultHealthCheckService::HealthCheckServiceImpl::CheckCallHandler:: // Process request. gpr_log(GPR_DEBUG, "[HCS %p] Health check started for handler %p", service_, this); - TString service_name; + TString service_name; grpc::Status status = Status::OK; ByteBuffer response; if (!service_->DecodeRequest(request_, &service_name)) { diff --git a/contrib/libs/grpc/src/cpp/server/health/default_health_check_service.h b/contrib/libs/grpc/src/cpp/server/health/default_health_check_service.h index 6d7479b016a..9da1dfc15fa 100644 --- a/contrib/libs/grpc/src/cpp/server/health/default_health_check_service.h +++ b/contrib/libs/grpc/src/cpp/server/health/default_health_check_service.h @@ -194,7 +194,7 @@ class DefaultHealthCheckService final : public HealthCheckServiceInterface { HealthCheckServiceImpl* service_; ByteBuffer request_; - TString service_name_; + TString service_name_; GenericServerAsyncWriter stream_; ServerContext ctx_; @@ -213,7 +213,7 @@ class DefaultHealthCheckService final : public HealthCheckServiceInterface { // Returns true on success. static bool DecodeRequest(const ByteBuffer& request, - TString* service_name); + TString* service_name); static bool EncodeResponse(ServingStatus status, ByteBuffer* response); // Needed to appease Windows compilers, which don't seem to allow @@ -234,12 +234,12 @@ class DefaultHealthCheckService final : public HealthCheckServiceInterface { DefaultHealthCheckService(); - void SetServingStatus(const TString& service_name, bool serving) override; + void SetServingStatus(const TString& service_name, bool serving) override; void SetServingStatus(bool serving) override; void Shutdown() override; - ServingStatus GetServingStatus(const TString& service_name) const; + ServingStatus GetServingStatus(const TString& service_name) const; HealthCheckServiceImpl* GetHealthCheckService( std::unique_ptr<ServerCompletionQueue> cq); @@ -266,16 +266,16 @@ class DefaultHealthCheckService final : public HealthCheckServiceInterface { }; void RegisterCallHandler( - const TString& service_name, + const TString& service_name, std::shared_ptr<HealthCheckServiceImpl::CallHandler> handler); void UnregisterCallHandler( - const TString& service_name, + const TString& service_name, const std::shared_ptr<HealthCheckServiceImpl::CallHandler>& handler); mutable grpc_core::Mutex mu_; - bool shutdown_ = false; // Guarded by mu_. - std::map<TString, ServiceData> services_map_; // Guarded by mu_. + bool shutdown_ = false; // Guarded by mu_. + std::map<TString, ServiceData> services_map_; // Guarded by mu_. std::unique_ptr<HealthCheckServiceImpl> impl_; }; diff --git a/contrib/libs/grpc/src/cpp/server/health/health_check_service.cc b/contrib/libs/grpc/src/cpp/server/health/health_check_service.cc index 35c194cb1b1..a0fa2d62f58 100644 --- a/contrib/libs/grpc/src/cpp/server/health/health_check_service.cc +++ b/contrib/libs/grpc/src/cpp/server/health/health_check_service.cc @@ -16,9 +16,9 @@ * */ -#include <grpcpp/health_check_service_interface.h> +#include <grpcpp/health_check_service_interface.h> -namespace grpc { +namespace grpc { namespace { bool g_grpc_default_health_check_service_enabled = false; } // namespace @@ -31,4 +31,4 @@ void EnableDefaultHealthCheckService(bool enable) { g_grpc_default_health_check_service_enabled = enable; } -} // namespace grpc +} // namespace grpc 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 f78a4daf078..3f33f4e045c 100644 --- a/contrib/libs/grpc/src/cpp/server/insecure_server_credentials.cc +++ b/contrib/libs/grpc/src/cpp/server/insecure_server_credentials.cc @@ -21,11 +21,11 @@ #include <grpc/grpc.h> #include <grpc/support/log.h> -namespace grpc { +namespace grpc { namespace { class InsecureServerCredentialsImpl final : public ServerCredentials { public: - int AddPortToServer(const TString& addr, grpc_server* server) override { + int AddPortToServer(const TString& addr, grpc_server* server) override { return grpc_server_add_insecure_http2_port(server, addr.c_str()); } void SetAuthMetadataProcessor( @@ -41,4 +41,4 @@ std::shared_ptr<ServerCredentials> InsecureServerCredentials() { new InsecureServerCredentialsImpl()); } -} // namespace grpc +} // namespace grpc 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 46a368da918..f07fa812a7d 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 @@ -77,8 +77,8 @@ const typename C::value_type* RandomElement(const C& container) { } // namespace -LoadRecordKey::LoadRecordKey(const TString& client_ip_and_token, - TString user_id) +LoadRecordKey::LoadRecordKey(const TString& client_ip_and_token, + TString user_id) : user_id_(std::move(user_id)) { GPR_ASSERT(client_ip_and_token.size() >= 2); int ip_hex_size; @@ -98,7 +98,7 @@ LoadRecordKey::LoadRecordKey(const TString& client_ip_and_token, } } -TString LoadRecordKey::GetClientIpBytes() const { +TString LoadRecordKey::GetClientIpBytes() const { if (client_ip_hex_.empty()) { return ""; } else if (client_ip_hex_.size() == kIpv4AddressLength) { @@ -110,8 +110,8 @@ TString LoadRecordKey::GetClientIpBytes() const { return ""; } ip_bytes = grpc_htonl(ip_bytes); - return TString(reinterpret_cast<const char*>(&ip_bytes), - sizeof(ip_bytes)); + return TString(reinterpret_cast<const char*>(&ip_bytes), + sizeof(ip_bytes)); } else if (client_ip_hex_.size() == kIpv6AddressLength) { uint32_t ip_bytes[4]; for (size_t i = 0; i < 4; ++i) { @@ -125,14 +125,14 @@ TString LoadRecordKey::GetClientIpBytes() const { } ip_bytes[i] = grpc_htonl(ip_bytes[i]); } - return TString(reinterpret_cast<const char*>(ip_bytes), - sizeof(ip_bytes)); + return TString(reinterpret_cast<const char*>(ip_bytes), + sizeof(ip_bytes)); } else { GPR_UNREACHABLE_CODE(return ""); } } -LoadRecordValue::LoadRecordValue(TString metric_name, uint64_t num_calls, +LoadRecordValue::LoadRecordValue(TString metric_name, uint64_t num_calls, double total_metric_value) { call_metrics_.emplace(std::move(metric_name), CallMetricValue(num_calls, total_metric_value)); @@ -177,8 +177,8 @@ uint64_t PerBalancerStore::GetNumCallsInProgressForReport() { return num_calls_in_progress_; } -void PerHostStore::ReportStreamCreated(const TString& lb_id, - const TString& load_key) { +void PerHostStore::ReportStreamCreated(const TString& lb_id, + const TString& load_key) { GPR_ASSERT(lb_id != kInvalidLbId); SetUpForNewLbId(lb_id, load_key); // Prior to this one, there was no load balancer receiving report, so we may @@ -188,7 +188,7 @@ void PerHostStore::ReportStreamCreated(const TString& lb_id, // this stream. Need to discuss with LB team. if (assigned_stores_.size() == 1) { for (const auto& p : per_balancer_stores_) { - const TString& other_lb_id = p.first; + const TString& other_lb_id = p.first; const std::unique_ptr<PerBalancerStore>& orphaned_store = p.second; if (other_lb_id != lb_id) { orphaned_store->Resume(); @@ -203,7 +203,7 @@ void PerHostStore::ReportStreamCreated(const TString& lb_id, } } -void PerHostStore::ReportStreamClosed(const TString& lb_id) { +void PerHostStore::ReportStreamClosed(const TString& lb_id) { auto it_store_for_gone_lb = per_balancer_stores_.find(lb_id); GPR_ASSERT(it_store_for_gone_lb != per_balancer_stores_.end()); // Remove this closed stream from our records. @@ -215,7 +215,7 @@ void PerHostStore::ReportStreamClosed(const TString& lb_id) { // The stores that were assigned to this balancer are orphaned now. They // should be re-assigned to other balancers which are still receiving reports. for (PerBalancerStore* orphaned_store : orphaned_stores) { - const TString* new_receiver = nullptr; + const TString* new_receiver = nullptr; auto it = load_key_to_receiving_lb_ids_.find(orphaned_store->load_key()); if (it != load_key_to_receiving_lb_ids_.end()) { // First, try to pick from the active balancers with the same load key. @@ -235,21 +235,21 @@ void PerHostStore::ReportStreamClosed(const TString& lb_id) { } PerBalancerStore* PerHostStore::FindPerBalancerStore( - const TString& lb_id) const { + const TString& lb_id) const { return per_balancer_stores_.find(lb_id) != per_balancer_stores_.end() ? per_balancer_stores_.find(lb_id)->second.get() : nullptr; } const std::set<PerBalancerStore*>* PerHostStore::GetAssignedStores( - const TString& lb_id) const { + const TString& lb_id) const { auto it = assigned_stores_.find(lb_id); if (it == assigned_stores_.end()) return nullptr; return &(it->second); } void PerHostStore::AssignOrphanedStore(PerBalancerStore* orphaned_store, - const TString& new_receiver) { + const TString& new_receiver) { auto it = assigned_stores_.find(new_receiver); GPR_ASSERT(it != assigned_stores_.end()); it->second.insert(orphaned_store); @@ -260,8 +260,8 @@ void PerHostStore::AssignOrphanedStore(PerBalancerStore* orphaned_store, new_receiver.c_str()); } -void PerHostStore::SetUpForNewLbId(const TString& lb_id, - const TString& load_key) { +void PerHostStore::SetUpForNewLbId(const TString& lb_id, + const TString& load_key) { // The top-level caller (i.e., LoadReportService) should guarantee the // lb_id is unique for each reporting stream. GPR_ASSERT(per_balancer_stores_.find(lb_id) == per_balancer_stores_.end()); @@ -284,7 +284,7 @@ PerBalancerStore* LoadDataStore::FindPerBalancerStore( } } -void LoadDataStore::MergeRow(const TString& hostname, +void LoadDataStore::MergeRow(const TString& hostname, const LoadRecordKey& key, const LoadRecordValue& value) { PerBalancerStore* per_balancer_store = @@ -315,20 +315,20 @@ void LoadDataStore::MergeRow(const TString& hostname, } const std::set<PerBalancerStore*>* LoadDataStore::GetAssignedStores( - const TString& hostname, const TString& lb_id) { + const TString& hostname, const TString& lb_id) { auto it = per_host_stores_.find(hostname); if (it == per_host_stores_.end()) return nullptr; return it->second.GetAssignedStores(lb_id); } -void LoadDataStore::ReportStreamCreated(const TString& hostname, - const TString& lb_id, - const TString& load_key) { +void LoadDataStore::ReportStreamCreated(const TString& hostname, + const TString& lb_id, + const TString& load_key) { per_host_stores_[hostname].ReportStreamCreated(lb_id, load_key); } -void LoadDataStore::ReportStreamClosed(const TString& hostname, - const TString& lb_id) { +void LoadDataStore::ReportStreamClosed(const TString& hostname, + const TString& lb_id) { auto it_per_host_store = per_host_stores_.find(hostname); GPR_ASSERT(it_per_host_store != per_host_stores_.end()); it_per_host_store->second.ReportStreamClosed(lb_id); diff --git a/contrib/libs/grpc/src/cpp/server/load_reporter/load_data_store.h b/contrib/libs/grpc/src/cpp/server/load_reporter/load_data_store.h index f6a31b87bce..61ba618331a 100644 --- a/contrib/libs/grpc/src/cpp/server/load_reporter/load_data_store.h +++ b/contrib/libs/grpc/src/cpp/server/load_reporter/load_data_store.h @@ -30,8 +30,8 @@ #include "src/cpp/server/load_reporter/constants.h" -#include <util/string/cast.h> - +#include <util/string/cast.h> + namespace grpc { namespace load_reporter { @@ -69,17 +69,17 @@ class CallMetricValue { // The key of a load record. class LoadRecordKey { public: - LoadRecordKey(TString lb_id, TString lb_tag, TString user_id, - TString client_ip_hex) + LoadRecordKey(TString lb_id, TString lb_tag, TString user_id, + TString client_ip_hex) : lb_id_(std::move(lb_id)), lb_tag_(std::move(lb_tag)), user_id_(std::move(user_id)), client_ip_hex_(std::move(client_ip_hex)) {} // Parses the input client_ip_and_token to set client IP, LB ID, and LB tag. - LoadRecordKey(const TString& client_ip_and_token, TString user_id); + LoadRecordKey(const TString& client_ip_and_token, TString user_id); - TString ToString() const { + TString ToString() const { return "[lb_id_=" + lb_id_ + ", lb_tag_=" + lb_tag_ + ", user_id_=" + user_id_ + ", client_ip_hex_=" + client_ip_hex_ + "]"; @@ -91,17 +91,17 @@ class LoadRecordKey { } // Gets the client IP bytes in network order (i.e., big-endian). - TString GetClientIpBytes() const; + TString GetClientIpBytes() const; // Getters. - const TString& lb_id() const { return lb_id_; } - const TString& lb_tag() const { return lb_tag_; } - const TString& user_id() const { return user_id_; } - const TString& client_ip_hex() const { return client_ip_hex_; } + const TString& lb_id() const { return lb_id_; } + const TString& lb_tag() const { return lb_tag_; } + const TString& user_id() const { return user_id_; } + const TString& client_ip_hex() const { return client_ip_hex_; } struct Hasher { - void hash_combine(size_t* seed, const TString& k) const { - *seed ^= std::hash<TString>()(k) + 0x9e3779b9 + (*seed << 6) + + void hash_combine(size_t* seed, const TString& k) const { + *seed ^= std::hash<TString>()(k) + 0x9e3779b9 + (*seed << 6) + (*seed >> 2); } @@ -116,10 +116,10 @@ class LoadRecordKey { }; private: - TString lb_id_; - TString lb_tag_; - TString user_id_; - TString client_ip_hex_; + TString lb_id_; + TString lb_tag_; + TString user_id_; + TString client_ip_hex_; }; // The value of a load record. @@ -135,7 +135,7 @@ class LoadRecordValue { bytes_recv_(bytes_recv), latency_ms_(latency_ms) {} - LoadRecordValue(TString metric_name, uint64_t num_calls, + LoadRecordValue(TString metric_name, uint64_t num_calls, double total_metric_value); void MergeFrom(const LoadRecordValue& other) { @@ -146,7 +146,7 @@ class LoadRecordValue { bytes_recv_ += other.bytes_recv_; latency_ms_ += other.latency_ms_; for (const auto& p : other.call_metrics_) { - const TString& key = p.first; + const TString& key = p.first; const CallMetricValue& value = p.second; call_metrics_[key].MergeFrom(value); } @@ -156,17 +156,17 @@ class LoadRecordValue { return static_cast<int64_t>(start_count_ - ok_count_ - error_count_); } - TString ToString() const { - return "[start_count_=" + ::ToString(start_count_) + - ", ok_count_=" + ::ToString(ok_count_) + - ", error_count_=" + ::ToString(error_count_) + - ", bytes_sent_=" + ::ToString(bytes_sent_) + - ", bytes_recv_=" + ::ToString(bytes_recv_) + - ", latency_ms_=" + ::ToString(latency_ms_) + ", " + - ::ToString(call_metrics_.size()) + " other call metric(s)]"; + TString ToString() const { + return "[start_count_=" + ::ToString(start_count_) + + ", ok_count_=" + ::ToString(ok_count_) + + ", error_count_=" + ::ToString(error_count_) + + ", bytes_sent_=" + ::ToString(bytes_sent_) + + ", bytes_recv_=" + ::ToString(bytes_recv_) + + ", latency_ms_=" + ::ToString(latency_ms_) + ", " + + ::ToString(call_metrics_.size()) + " other call metric(s)]"; } - bool InsertCallMetric(const TString& metric_name, + bool InsertCallMetric(const TString& metric_name, const CallMetricValue& metric_value) { return call_metrics_.insert({metric_name, metric_value}).second; } @@ -178,7 +178,7 @@ class LoadRecordValue { uint64_t bytes_sent() const { return bytes_sent_; } uint64_t bytes_recv() const { return bytes_recv_; } uint64_t latency_ms() const { return latency_ms_; } - const std::unordered_map<TString, CallMetricValue>& call_metrics() const { + const std::unordered_map<TString, CallMetricValue>& call_metrics() const { return call_metrics_; } @@ -189,7 +189,7 @@ class LoadRecordValue { uint64_t bytes_sent_ = 0; uint64_t bytes_recv_ = 0; uint64_t latency_ms_ = 0; - std::unordered_map<TString, CallMetricValue> call_metrics_; + std::unordered_map<TString, CallMetricValue> call_metrics_; }; // Stores the data associated with a particular LB ID. @@ -198,7 +198,7 @@ class PerBalancerStore { using LoadRecordMap = std::unordered_map<LoadRecordKey, LoadRecordValue, LoadRecordKey::Hasher>; - PerBalancerStore(TString lb_id, TString load_key) + PerBalancerStore(TString lb_id, TString load_key) : lb_id_(std::move(lb_id)), load_key_(std::move(load_key)) {} // Merge a load record with the given key and value if the store is not @@ -218,7 +218,7 @@ class PerBalancerStore { uint64_t GetNumCallsInProgressForReport(); - TString ToString() { + TString ToString() { return "[PerBalancerStore lb_id_=" + lb_id_ + " load_key_=" + load_key_ + "]"; } @@ -226,14 +226,14 @@ class PerBalancerStore { void ClearLoadRecordMap() { load_record_map_.clear(); } // Getters. - const TString& lb_id() const { return lb_id_; } - const TString& load_key() const { return load_key_; } + const TString& lb_id() const { return lb_id_; } + const TString& load_key() const { return load_key_; } const LoadRecordMap& load_record_map() const { return load_record_map_; } private: - TString lb_id_; + TString lb_id_; // TODO(juanlishen): Use bytestring protobuf type? - TString load_key_; + TString load_key_; LoadRecordMap load_record_map_; uint64_t num_calls_in_progress_ = 0; uint64_t last_reported_num_calls_in_progress_ = 0; @@ -247,39 +247,39 @@ class PerHostStore { // LB ID (guaranteed unique) associated with that stream. If it is the only // active store, adopt all the orphaned stores. If it is the first created // store, adopt the store of kInvalidLbId. - void ReportStreamCreated(const TString& lb_id, - const TString& load_key); + void ReportStreamCreated(const TString& lb_id, + const TString& load_key); // When a report stream is closed, the PerBalancerStores assigned to the // associate LB ID need to be re-assigned to other active balancers, // ideally with the same load key. If there is no active balancer, we have // to suspend those stores and drop the incoming load data until they are // resumed. - void ReportStreamClosed(const TString& lb_id); + void ReportStreamClosed(const TString& lb_id); // Returns null if not found. Caller doesn't own the returned store. - PerBalancerStore* FindPerBalancerStore(const TString& lb_id) const; + PerBalancerStore* FindPerBalancerStore(const TString& lb_id) const; // Returns null if lb_id is not found. The returned pointer points to the // underlying data structure, which is not owned by the caller. const std::set<PerBalancerStore*>* GetAssignedStores( - const TString& lb_id) const; + const TString& lb_id) const; private: // Creates a PerBalancerStore for the given LB ID, assigns the store to // itself, and records the LB ID to the load key. - void SetUpForNewLbId(const TString& lb_id, const TString& load_key); + void SetUpForNewLbId(const TString& lb_id, const TString& load_key); void AssignOrphanedStore(PerBalancerStore* orphaned_store, - const TString& new_receiver); + const TString& new_receiver); - std::unordered_map<TString, std::set<TString>> + std::unordered_map<TString, std::set<TString>> load_key_to_receiving_lb_ids_; // Key: LB ID. The key set includes all the LB IDs that have been // allocated for reporting streams so far. // Value: the unique pointer to the PerBalancerStore of the LB ID. - std::unordered_map<TString, std::unique_ptr<PerBalancerStore>> + std::unordered_map<TString, std::unique_ptr<PerBalancerStore>> per_balancer_stores_; // Key: LB ID. The key set includes the LB IDs of the balancers that are @@ -287,7 +287,7 @@ class PerHostStore { // Value: the set of raw pointers to the PerBalancerStores assigned to the LB // ID. Note that the sets in assigned_stores_ form a division of the value set // of per_balancer_stores_. - std::unordered_map<TString, std::set<PerBalancerStore*>> assigned_stores_; + std::unordered_map<TString, std::set<PerBalancerStore*>> assigned_stores_; }; // Thread-unsafe two-level bookkeeper of all the load data. @@ -302,8 +302,8 @@ class PerHostStore { class LoadDataStore { public: // Returns null if not found. Caller doesn't own the returned store. - PerBalancerStore* FindPerBalancerStore(const TString& hostname, - const TString& lb_id) const; + PerBalancerStore* FindPerBalancerStore(const TString& hostname, + const TString& lb_id) const; // Returns null if hostname or lb_id is not found. The returned pointer points // to the underlying data structure, which is not owned by the caller. @@ -313,33 +313,33 @@ class LoadDataStore { // If a PerBalancerStore can be found by the hostname and LB ID in // LoadRecordKey, the load data will be merged to that store. Otherwise, // only track the number of the in-progress calls for this unknown LB ID. - void MergeRow(const TString& hostname, const LoadRecordKey& key, + void MergeRow(const TString& hostname, const LoadRecordKey& key, const LoadRecordValue& value); // Is the given lb_id a tracked unknown LB ID (i.e., the LB ID was associated // with some received load data but unknown to this load data store)? - bool IsTrackedUnknownBalancerId(const TString& lb_id) const { + bool IsTrackedUnknownBalancerId(const TString& lb_id) const { return unknown_balancer_id_trackers_.find(lb_id) != unknown_balancer_id_trackers_.end(); } // Wrapper around PerHostStore::ReportStreamCreated. - void ReportStreamCreated(const TString& hostname, - const TString& lb_id, - const TString& load_key); + void ReportStreamCreated(const TString& hostname, + const TString& lb_id, + const TString& load_key); // Wrapper around PerHostStore::ReportStreamClosed. - void ReportStreamClosed(const TString& hostname, - const TString& lb_id); + void ReportStreamClosed(const TString& hostname, + const TString& lb_id); private: // Buffered data that was fetched from Census but hasn't been sent to // balancer. We need to keep this data ourselves because Census will // delete the data once it's returned. - std::unordered_map<TString, PerHostStore> per_host_stores_; + std::unordered_map<TString, PerHostStore> per_host_stores_; // Tracks the number of in-progress calls for each unknown LB ID. - std::unordered_map<TString, uint64_t> unknown_balancer_id_trackers_; + std::unordered_map<TString, uint64_t> unknown_balancer_id_trackers_; }; } // 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 b1acde10107..24ad9f3f248 100644 --- a/contrib/libs/grpc/src/cpp/server/load_reporter/util.cc +++ b/contrib/libs/grpc/src/cpp/server/load_reporter/util.cc @@ -24,14 +24,14 @@ #include <grpc/support/log.h> -namespace grpc { +namespace grpc { namespace load_reporter { namespace experimental { void AddLoadReportingCost(grpc::ServerContext* ctx, - const TString& cost_name, double cost_value) { + const TString& cost_name, double cost_value) { if (std::isnormal(cost_value)) { - TString buf; + TString buf; buf.resize(sizeof(cost_value) + cost_name.size()); memcpy(&(*buf.begin()), &cost_value, sizeof(cost_value)); memcpy(&(*buf.begin()) + sizeof(cost_value), cost_name.data(), @@ -44,4 +44,4 @@ void AddLoadReportingCost(grpc::ServerContext* ctx, } // namespace experimental } // namespace load_reporter -} // namespace grpc +} // namespace grpc 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 b084b01836e..732602bcb70 100644 --- a/contrib/libs/grpc/src/cpp/server/secure_server_credentials.cc +++ b/contrib/libs/grpc/src/cpp/server/secure_server_credentials.cc @@ -21,7 +21,7 @@ #include <memory> #include <grpcpp/impl/codegen/slice.h> -#include <grpcpp/impl/grpc_library.h> +#include <grpcpp/impl/grpc_library.h> #include <grpcpp/security/auth_metadata_processor.h> #include "src/cpp/common/secure_auth_context.h" @@ -92,7 +92,7 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( status.error_message().c_str()); } -int SecureServerCredentials::AddPortToServer(const TString& addr, +int SecureServerCredentials::AddPortToServer(const TString& addr, grpc_server* server) { return grpc_server_add_secure_http2_port(server, addr.c_str(), creds_); } @@ -145,11 +145,11 @@ std::shared_ptr<ServerCredentials> LocalServerCredentials( } std::shared_ptr<ServerCredentials> TlsServerCredentials( - const grpc::experimental::TlsCredentialsOptions& options) { - grpc::GrpcLibraryCodegen init; - return std::shared_ptr<ServerCredentials>(new SecureServerCredentials( - grpc_tls_server_credentials_create(options.c_credentials_options()))); + const grpc::experimental::TlsCredentialsOptions& options) { + grpc::GrpcLibraryCodegen init; + return std::shared_ptr<ServerCredentials>(new SecureServerCredentials( + grpc_tls_server_credentials_create(options.c_credentials_options()))); } } // namespace experimental -} // namespace grpc +} // namespace grpc 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 9a09c2314fa..9e3fb3f9ebf 100644 --- a/contrib/libs/grpc/src/cpp/server/secure_server_credentials.h +++ b/contrib/libs/grpc/src/cpp/server/secure_server_credentials.h @@ -28,7 +28,7 @@ #include "src/cpp/server/thread_pool_interface.h" -namespace grpc { +namespace grpc { class SecureServerCredentials; @@ -64,7 +64,7 @@ class SecureServerCredentials final : public ServerCredentials { grpc_server_credentials_release(creds_); } - int AddPortToServer(const TString& addr, grpc_server* server) override; + int AddPortToServer(const TString& addr, grpc_server* server) override; void SetAuthMetadataProcessor( const std::shared_ptr<grpc::AuthMetadataProcessor>& processor) override; @@ -74,6 +74,6 @@ class SecureServerCredentials final : public ServerCredentials { std::unique_ptr<grpc::AuthMetadataProcessorAyncWrapper> processor_; }; -} // namespace grpc +} // namespace grpc #endif // GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H diff --git a/contrib/libs/grpc/src/cpp/server/server_builder.cc b/contrib/libs/grpc/src/cpp/server/server_builder.cc index e3a9f4e4a60..0cc00b365ff 100644 --- a/contrib/libs/grpc/src/cpp/server/server_builder.cc +++ b/contrib/libs/grpc/src/cpp/server/server_builder.cc @@ -26,21 +26,21 @@ #include <utility> -#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" #include "src/cpp/server/external_connection_acceptor_impl.h" #include "src/cpp/server/thread_pool_interface.h" -namespace grpc { +namespace grpc { -static std::vector<std::unique_ptr<ServerBuilderPlugin> (*)()>* +static std::vector<std::unique_ptr<ServerBuilderPlugin> (*)()>* g_plugin_factory_list; static gpr_once once_init_plugin_list = GPR_ONCE_INIT; static void do_plugin_list_init(void) { g_plugin_factory_list = - new std::vector<std::unique_ptr<ServerBuilderPlugin> (*)()>(); + new std::vector<std::unique_ptr<ServerBuilderPlugin> (*)()>(); } ServerBuilder::ServerBuilder() @@ -68,29 +68,29 @@ ServerBuilder::~ServerBuilder() { } } -std::unique_ptr<grpc::ServerCompletionQueue> ServerBuilder::AddCompletionQueue( +std::unique_ptr<grpc::ServerCompletionQueue> ServerBuilder::AddCompletionQueue( bool is_frequently_polled) { - grpc::ServerCompletionQueue* cq = new grpc::ServerCompletionQueue( + grpc::ServerCompletionQueue* cq = new grpc::ServerCompletionQueue( GRPC_CQ_NEXT, is_frequently_polled ? GRPC_CQ_DEFAULT_POLLING : GRPC_CQ_NON_LISTENING, nullptr); cqs_.push_back(cq); - return std::unique_ptr<grpc::ServerCompletionQueue>(cq); + return std::unique_ptr<grpc::ServerCompletionQueue>(cq); } -ServerBuilder& ServerBuilder::RegisterService(Service* service) { +ServerBuilder& ServerBuilder::RegisterService(Service* service) { services_.emplace_back(new NamedService(service)); return *this; } -ServerBuilder& ServerBuilder::RegisterService(const TString& addr, - Service* service) { +ServerBuilder& ServerBuilder::RegisterService(const TString& addr, + Service* service) { services_.emplace_back(new NamedService(addr, service)); return *this; } ServerBuilder& ServerBuilder::RegisterAsyncGenericService( - AsyncGenericService* service) { + AsyncGenericService* service) { if (generic_service_ || callback_generic_service_) { gpr_log(GPR_ERROR, "Adding multiple generic services is unsupported for now. " @@ -102,22 +102,22 @@ 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); - } else { - callback_generic_service_ = service; - } - return *this; -} -#else +#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); + } else { + callback_generic_service_ = service; + } + return *this; +} +#else ServerBuilder& ServerBuilder::experimental_type::RegisterCallbackGenericService( - experimental::CallbackGenericService* service) { + experimental::CallbackGenericService* service) { if (builder_->generic_service_ || builder_->callback_generic_service_) { gpr_log(GPR_ERROR, "Adding multiple generic services is unsupported for now. " @@ -128,13 +128,13 @@ ServerBuilder& ServerBuilder::experimental_type::RegisterCallbackGenericService( } return *builder_; } -#endif +#endif std::unique_ptr<grpc::experimental::ExternalConnectionAcceptor> ServerBuilder::experimental_type::AddExternalConnectionAcceptor( experimental_type::ExternalConnectionType type, std::shared_ptr<ServerCredentials> creds) { - TString name_prefix("external:"); + TString name_prefix("external:"); char count_str[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(static_cast<long>(builder_->acceptors_.size()), count_str); builder_->acceptors_.emplace_back( @@ -144,7 +144,7 @@ ServerBuilder::experimental_type::AddExternalConnectionAcceptor( } ServerBuilder& ServerBuilder::SetOption( - std::unique_ptr<ServerBuilderOption> option) { + std::unique_ptr<ServerBuilderOption> option) { options_.push_back(std::move(option)); return *this; } @@ -193,7 +193,7 @@ ServerBuilder& ServerBuilder::SetDefaultCompressionAlgorithm( } ServerBuilder& ServerBuilder::SetResourceQuota( - const grpc::ResourceQuota& resource_quota) { + const grpc::ResourceQuota& resource_quota) { if (resource_quota_ != nullptr) { grpc_resource_quota_unref(resource_quota_); } @@ -203,10 +203,10 @@ ServerBuilder& ServerBuilder::SetResourceQuota( } ServerBuilder& ServerBuilder::AddListeningPort( - const TString& addr_uri, std::shared_ptr<ServerCredentials> creds, - int* selected_port) { - const TString uri_scheme = "dns:"; - TString addr = addr_uri; + const TString& addr_uri, std::shared_ptr<ServerCredentials> creds, + int* selected_port) { + const TString uri_scheme = "dns:"; + TString addr = addr_uri; if (addr_uri.compare(0, uri_scheme.size(), uri_scheme) == 0) { size_t pos = uri_scheme.size(); while (addr_uri[pos] == '/') ++pos; // Skip slashes. @@ -222,13 +222,13 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { if (max_receive_message_size_ >= -1) { args.SetInt(GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH, max_receive_message_size_); } - if (max_send_message_size_ >= -1) { + if (max_send_message_size_ >= -1) { args.SetInt(GRPC_ARG_MAX_SEND_MESSAGE_LENGTH, max_send_message_size_); } - for (const auto& option : options_) { - option->UpdateArguments(&args); - option->UpdatePlugins(&plugins_); - } + for (const auto& option : options_) { + option->UpdateArguments(&args); + option->UpdatePlugins(&plugins_); + } args.SetInt(GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET, enabled_compression_algorithms_bitset_); if (maybe_default_compression_level_.is_set) { @@ -245,11 +245,11 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { grpc_resource_quota_arg_vtable()); } - for (const auto& plugin : plugins_) { - plugin->UpdateServerBuilder(this); - plugin->UpdateChannelArguments(&args); - } - + for (const auto& plugin : plugins_) { + plugin->UpdateServerBuilder(this); + plugin->UpdateChannelArguments(&args); + } + // == Determine if the server has any syncrhonous methods == bool has_sync_methods = false; for (const auto& value : services_) { @@ -275,10 +275,10 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { // This is different from the completion queues added to the server via // ServerBuilder's AddCompletionQueue() method (those completion queues // are in 'cqs_' member variable of ServerBuilder object) - std::shared_ptr<std::vector<std::unique_ptr<grpc::ServerCompletionQueue>>> - sync_server_cqs( - std::make_shared< - std::vector<std::unique_ptr<grpc::ServerCompletionQueue>>>()); + std::shared_ptr<std::vector<std::unique_ptr<grpc::ServerCompletionQueue>>> + sync_server_cqs( + std::make_shared< + std::vector<std::unique_ptr<grpc::ServerCompletionQueue>>>()); bool has_frequently_polled_cqs = false; for (const auto& cq : cqs_) { @@ -307,7 +307,7 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { // Create completion queues to listen to incoming rpc requests for (int i = 0; i < sync_server_settings_.num_cqs; i++) { sync_server_cqs->emplace_back( - new grpc::ServerCompletionQueue(GRPC_CQ_NEXT, polling_type, nullptr)); + new grpc::ServerCompletionQueue(GRPC_CQ_NEXT, polling_type, nullptr)); } } @@ -329,20 +329,20 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { } std::unique_ptr<grpc::Server> server(new grpc::Server( - &args, sync_server_cqs, sync_server_settings_.min_pollers, - sync_server_settings_.max_pollers, sync_server_settings_.cq_timeout_msec, - std::move(acceptors_), resource_quota_, - std::move(interceptor_creators_))); + &args, sync_server_cqs, sync_server_settings_.min_pollers, + sync_server_settings_.max_pollers, sync_server_settings_.cq_timeout_msec, + std::move(acceptors_), resource_quota_, + std::move(interceptor_creators_))); - ServerInitializer* initializer = server->initializer(); + ServerInitializer* initializer = server->initializer(); // Register all the completion queues with the server. i.e // 1. sync_server_cqs: internal completion queues created IF this is a sync // server // 2. cqs_: Completion queues added via AddCompletionQueue() call - for (const auto& cq : *sync_server_cqs) { - grpc_server_register_completion_queue(server->server_, cq->cq(), nullptr); + for (const auto& cq : *sync_server_cqs) { + grpc_server_register_completion_queue(server->server_, cq->cq(), nullptr); has_frequently_polled_cqs = true; } @@ -355,12 +355,12 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { // AddCompletionQueue() API. Some of them may not be frequently polled (i.e by // calling Next() or AsyncNext()) and hence are not safe to be used for // listening to incoming channels. Such completion queues must be registered - // as non-listening queues. In debug mode, these should have their server list - // tracked since these are provided the user and must be Shutdown by the user - // after the server is shutdown. - for (const auto& cq : cqs_) { - grpc_server_register_completion_queue(server->server_, cq->cq(), nullptr); - cq->RegisterServer(server.get()); + // as non-listening queues. In debug mode, these should have their server list + // tracked since these are provided the user and must be Shutdown by the user + // after the server is shutdown. + for (const auto& cq : cqs_) { + grpc_server_register_completion_queue(server->server_, cq->cq(), nullptr); + cq->RegisterServer(server.get()); } if (!has_frequently_polled_cqs) { @@ -416,7 +416,7 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() { } void ServerBuilder::InternalAddPluginFactory( - std::unique_ptr<ServerBuilderPlugin> (*CreatePlugin)()) { + std::unique_ptr<ServerBuilderPlugin> (*CreatePlugin)()) { gpr_once_init(&once_init_plugin_list, do_plugin_list_init); (*g_plugin_factory_list).push_back(CreatePlugin); } @@ -431,4 +431,4 @@ ServerBuilder& ServerBuilder::EnableWorkaround(grpc_workaround_list id) { } } -} // namespace grpc +} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/server/server_callback.cc b/contrib/libs/grpc/src/cpp/server/server_callback.cc index d2963851dcb..40aef8e7359 100644 --- a/contrib/libs/grpc/src/cpp/server/server_callback.cc +++ b/contrib/libs/grpc/src/cpp/server/server_callback.cc @@ -15,70 +15,70 @@ * */ -#include <grpcpp/impl/codegen/server_callback.h> +#include <grpcpp/impl/codegen/server_callback.h> #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/executor.h" -namespace grpc { +namespace grpc { namespace internal { -void ServerCallbackCall::ScheduleOnDone(bool inline_ondone) { - if (inline_ondone) { - CallOnDone(); - } else { - // Unlike other uses of closure, do not Ref or Unref here since at this - // point, all the Ref'fing and Unref'fing is done for this call. - grpc_core::ExecCtx exec_ctx; - struct ClosureWithArg { - grpc_closure closure; - ServerCallbackCall* call; - explicit ClosureWithArg(ServerCallbackCall* call_arg) : call(call_arg) { - GRPC_CLOSURE_INIT(&closure, - [](void* void_arg, grpc_error*) { - ClosureWithArg* arg = - static_cast<ClosureWithArg*>(void_arg); - arg->call->CallOnDone(); - delete arg; - }, - this, grpc_schedule_on_exec_ctx); - } - }; - ClosureWithArg* arg = new ClosureWithArg(this); - grpc_core::Executor::Run(&arg->closure, GRPC_ERROR_NONE); - } -} - +void ServerCallbackCall::ScheduleOnDone(bool inline_ondone) { + if (inline_ondone) { + CallOnDone(); + } else { + // Unlike other uses of closure, do not Ref or Unref here since at this + // point, all the Ref'fing and Unref'fing is done for this call. + grpc_core::ExecCtx exec_ctx; + struct ClosureWithArg { + grpc_closure closure; + ServerCallbackCall* call; + explicit ClosureWithArg(ServerCallbackCall* call_arg) : call(call_arg) { + GRPC_CLOSURE_INIT(&closure, + [](void* void_arg, grpc_error*) { + ClosureWithArg* arg = + static_cast<ClosureWithArg*>(void_arg); + arg->call->CallOnDone(); + delete arg; + }, + this, grpc_schedule_on_exec_ctx); + } + }; + ClosureWithArg* arg = new ClosureWithArg(this); + grpc_core::Executor::Run(&arg->closure, GRPC_ERROR_NONE); + } +} + void ServerCallbackCall::CallOnCancel(ServerReactor* reactor) { if (reactor->InternalInlineable()) { reactor->OnCancel(); } else { - // Ref to make sure that the closure executes before the whole call gets - // destructed, and Unref within the closure. + // Ref to make sure that the closure executes before the whole call gets + // destructed, and Unref within the closure. Ref(); grpc_core::ExecCtx exec_ctx; - struct ClosureWithArg { - grpc_closure closure; + struct ClosureWithArg { + grpc_closure closure; ServerCallbackCall* call; ServerReactor* reactor; - ClosureWithArg(ServerCallbackCall* call_arg, ServerReactor* reactor_arg) - : call(call_arg), reactor(reactor_arg) { - GRPC_CLOSURE_INIT(&closure, - [](void* void_arg, grpc_error*) { - ClosureWithArg* arg = - static_cast<ClosureWithArg*>(void_arg); - arg->reactor->OnCancel(); - arg->call->MaybeDone(); - delete arg; - }, - this, grpc_schedule_on_exec_ctx); - } + ClosureWithArg(ServerCallbackCall* call_arg, ServerReactor* reactor_arg) + : call(call_arg), reactor(reactor_arg) { + GRPC_CLOSURE_INIT(&closure, + [](void* void_arg, grpc_error*) { + ClosureWithArg* arg = + static_cast<ClosureWithArg*>(void_arg); + arg->reactor->OnCancel(); + arg->call->MaybeDone(); + delete arg; + }, + this, grpc_schedule_on_exec_ctx); + } }; - ClosureWithArg* arg = new ClosureWithArg(this, reactor); - grpc_core::Executor::Run(&arg->closure, GRPC_ERROR_NONE); + ClosureWithArg* arg = new ClosureWithArg(this, reactor); + grpc_core::Executor::Run(&arg->closure, GRPC_ERROR_NONE); } } } // namespace internal -} // namespace grpc +} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/server/server_cc.cc b/contrib/libs/grpc/src/cpp/server/server_cc.cc index d8725fe0eb3..c2a911c7f7c 100644 --- a/contrib/libs/grpc/src/cpp/server/server_cc.cc +++ b/contrib/libs/grpc/src/cpp/server/server_cc.cc @@ -23,7 +23,7 @@ #include <utility> #include <grpc/grpc.h> -#include <grpc/impl/codegen/grpc_types.h> +#include <grpc/impl/codegen/grpc_types.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpcpp/completion_queue.h> @@ -47,14 +47,14 @@ #include "src/core/lib/profiling/timers.h" #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/completion_queue.h" -#include "src/core/lib/surface/server.h" +#include "src/core/lib/surface/server.h" #include "src/cpp/client/create_channel_internal.h" #include "src/cpp/server/external_connection_acceptor_impl.h" #include "src/cpp/server/health/default_health_check_service.h" #include "src/cpp/thread_manager/thread_manager.h" -#include <util/stream/str.h> - +#include <util/stream/str.h> + namespace grpc { namespace { @@ -99,15 +99,15 @@ 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 - +// 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( @@ -293,10 +293,10 @@ class Server::UnimplementedAsyncRequest final : private grpc::UnimplementedAsyncRequestContext, public GenericAsyncRequest { public: - UnimplementedAsyncRequest(ServerInterface* server, - grpc::ServerCompletionQueue* cq) + UnimplementedAsyncRequest(ServerInterface* server, + grpc::ServerCompletionQueue* cq) : GenericAsyncRequest(server, &server_context_, &generic_stream_, cq, cq, - nullptr, false) {} + nullptr, false) {} bool FinalizeResult(void** tag, bool* status) override; @@ -528,54 +528,54 @@ class Server::SyncRequest final : public grpc::internal::CompletionQueueTag { }; template <class ServerContextType> -class Server::CallbackRequest final - : public grpc::internal::CompletionQueueTag { +class Server::CallbackRequest final + : public grpc::internal::CompletionQueueTag { public: - static_assert( - std::is_base_of<grpc::CallbackServerContext, ServerContextType>::value, - "ServerContextType must be derived from CallbackServerContext"); - - // For codegen services, the value of method represents the defined - // characteristics of the method being requested. For generic services, method - // is nullptr since these services don't have pre-defined methods. - CallbackRequest(Server* server, grpc::internal::RpcServiceMethod* method, - grpc::CompletionQueue* cq, - grpc_core::Server::RegisteredCallAllocation* data) + static_assert( + std::is_base_of<grpc::CallbackServerContext, ServerContextType>::value, + "ServerContextType must be derived from CallbackServerContext"); + + // For codegen services, the value of method represents the defined + // characteristics of the method being requested. For generic services, method + // is nullptr since these services don't have pre-defined methods. + CallbackRequest(Server* server, grpc::internal::RpcServiceMethod* method, + grpc::CompletionQueue* cq, + grpc_core::Server::RegisteredCallAllocation* data) : server_(server), method_(method), - has_request_payload_(method->method_type() == - grpc::internal::RpcMethod::NORMAL_RPC || - method->method_type() == - grpc::internal::RpcMethod::SERVER_STREAMING), - cq_(cq), + has_request_payload_(method->method_type() == + grpc::internal::RpcMethod::NORMAL_RPC || + method->method_type() == + grpc::internal::RpcMethod::SERVER_STREAMING), + cq_(cq), tag_(this) { - CommonSetup(server, data); - data->deadline = &deadline_; - data->optional_payload = has_request_payload_ ? &request_payload_ : nullptr; + CommonSetup(server, data); + data->deadline = &deadline_; + data->optional_payload = has_request_payload_ ? &request_payload_ : nullptr; } - // For generic services, method is nullptr since these services don't have - // pre-defined methods. - CallbackRequest(Server* server, grpc::CompletionQueue* cq, - grpc_core::Server::BatchCallAllocation* data) - : server_(server), - method_(nullptr), - has_request_payload_(false), - call_details_(new grpc_call_details), - cq_(cq), - tag_(this) { - CommonSetup(server, data); - grpc_call_details_init(call_details_); - data->details = call_details_; + // For generic services, method is nullptr since these services don't have + // pre-defined methods. + CallbackRequest(Server* server, grpc::CompletionQueue* cq, + grpc_core::Server::BatchCallAllocation* data) + : server_(server), + method_(nullptr), + has_request_payload_(false), + call_details_(new grpc_call_details), + cq_(cq), + tag_(this) { + CommonSetup(server, data); + grpc_call_details_init(call_details_); + data->details = call_details_; } - ~CallbackRequest() { - delete call_details_; - grpc_metadata_array_destroy(&request_metadata_); - if (has_request_payload_ && request_payload_) { - grpc_byte_buffer_destroy(request_payload_); - } - server_->UnrefWithPossibleNotify(); + ~CallbackRequest() { + delete call_details_; + grpc_metadata_array_destroy(&request_metadata_); + if (has_request_payload_ && request_payload_) { + grpc_byte_buffer_destroy(request_payload_); + } + server_->UnrefWithPossibleNotify(); } // Needs specialization to account for different processing of metadata @@ -680,48 +680,48 @@ class Server::CallbackRequest final : req_->server_->generic_handler_.get(); handler->RunHandler(grpc::internal::MethodHandler::HandlerParameter( call_, &req_->ctx_, req_->request_, req_->request_status_, - req_->handler_data_, [this] { delete req_; })); + req_->handler_data_, [this] { delete req_; })); } }; - template <class CallAllocation> - void CommonSetup(Server* server, CallAllocation* data) { - server->Ref(); + template <class CallAllocation> + void CommonSetup(Server* server, CallAllocation* data) { + server->Ref(); grpc_metadata_array_init(&request_metadata_); - data->tag = &tag_; - data->call = &call_; - data->initial_metadata = &request_metadata_; + data->tag = &tag_; + data->call = &call_; + data->initial_metadata = &request_metadata_; } Server* const server_; grpc::internal::RpcServiceMethod* const method_; const bool has_request_payload_; - grpc_byte_buffer* request_payload_ = nullptr; - void* request_ = nullptr; - void* handler_data_ = nullptr; + grpc_byte_buffer* request_payload_ = nullptr; + void* request_ = nullptr; + void* handler_data_ = nullptr; grpc::Status request_status_; - grpc_call_details* const call_details_ = nullptr; + grpc_call_details* const call_details_ = nullptr; grpc_call* call_; gpr_timespec deadline_; grpc_metadata_array request_metadata_; - grpc::CompletionQueue* const cq_; + grpc::CompletionQueue* const cq_; CallbackCallTag tag_; ServerContextType ctx_; grpc::internal::InterceptorBatchMethodsImpl interceptor_methods_; }; template <> -bool Server::CallbackRequest<grpc::CallbackServerContext>::FinalizeResult( - void** /*tag*/, bool* /*status*/) { +bool Server::CallbackRequest<grpc::CallbackServerContext>::FinalizeResult( + void** /*tag*/, bool* /*status*/) { return false; } template <> -bool Server::CallbackRequest< - grpc::GenericCallbackServerContext>::FinalizeResult(void** /*tag*/, - bool* status) { +bool Server::CallbackRequest< + grpc::GenericCallbackServerContext>::FinalizeResult(void** /*tag*/, + bool* status) { if (*status) { - deadline_ = call_details_->deadline; + deadline_ = call_details_->deadline; // TODO(yangg) remove the copy here ctx_.method_ = grpc::StringFromCopiedSlice(call_details_->method); ctx_.host_ = grpc::StringFromCopiedSlice(call_details_->host); @@ -732,14 +732,14 @@ bool Server::CallbackRequest< } template <> -const char* Server::CallbackRequest<grpc::CallbackServerContext>::method_name() - const { +const char* Server::CallbackRequest<grpc::CallbackServerContext>::method_name() + const { return method_->name(); } template <> const char* Server::CallbackRequest< - grpc::GenericCallbackServerContext>::method_name() const { + grpc::GenericCallbackServerContext>::method_name() const { return ctx_.method().c_str(); } @@ -867,7 +867,7 @@ class Server::SyncRequestThreadManager : public grpc::ThreadManager { static grpc::internal::GrpcLibraryInitializer g_gli_initializer; Server::Server( - grpc::ChannelArguments* args, + grpc::ChannelArguments* args, std::shared_ptr<std::vector<std::unique_ptr<grpc::ServerCompletionQueue>>> sync_server_cqs, int min_pollers, int max_pollers, int sync_cq_timeout_msec, @@ -879,13 +879,13 @@ Server::Server( interceptor_creators) : acceptors_(std::move(acceptors)), interceptor_creators_(std::move(interceptor_creators)), - max_receive_message_size_(INT_MIN), + max_receive_message_size_(INT_MIN), sync_server_cqs_(std::move(sync_server_cqs)), started_(false), shutdown_(false), shutdown_notified_(false), server_(nullptr), - server_initializer_(new ServerInitializer(this)), + server_initializer_(new ServerInitializer(this)), health_check_service_disabled_(false) { g_gli_initializer.summon(); gpr_once_init(&grpc::g_once_init_callbacks, grpc::InitGlobalCallbacks); @@ -930,10 +930,10 @@ Server::Server( channel_args.args[i].value.pointer.p)); } } - if (0 == - strcmp(channel_args.args[i].key, GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH)) { - max_receive_message_size_ = channel_args.args[i].value.integer; - } + if (0 == + strcmp(channel_args.args[i].key, GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH)) { + max_receive_message_size_ = channel_args.args[i].value.integer; + } } server_ = grpc_server_create(&channel_args, nullptr); } @@ -955,10 +955,10 @@ Server::~Server() { } } } - // Destroy health check service before we destroy the C server so that - // it does not call grpc_server_request_registered_call() after the C - // server has been destroyed. - health_check_service_.reset(); + // Destroy health check service before we destroy the C server so that + // it does not call grpc_server_request_registered_call() after the C + // server has been destroyed. + health_check_service_.reset(); grpc_server_destroy(server_); } @@ -1005,7 +1005,7 @@ static grpc_server_register_method_payload_handling PayloadHandlingForMethod( GPR_UNREACHABLE_CODE(return GRPC_SRM_PAYLOAD_NONE;); } -bool Server::RegisterService(const TString* host, grpc::Service* service) { +bool Server::RegisterService(const TString* host, grpc::Service* service) { bool has_async_methods = service->has_async_methods(); if (has_async_methods) { GPR_ASSERT(service->server_ == nullptr && @@ -1037,16 +1037,16 @@ bool Server::RegisterService(const TString* host, grpc::Service* service) { value->AddSyncMethod(method.get(), method_registration_tag); } } else { - has_callback_methods_ = true; - grpc::internal::RpcServiceMethod* method_value = method.get(); - grpc::CompletionQueue* cq = CallbackCQ(); - server_->core_server->SetRegisteredMethodAllocator( - cq->cq(), method_registration_tag, [this, cq, method_value] { - grpc_core::Server::RegisteredCallAllocation result; - new CallbackRequest<grpc::CallbackServerContext>(this, method_value, - cq, &result); - return result; - }); + has_callback_methods_ = true; + grpc::internal::RpcServiceMethod* method_value = method.get(); + grpc::CompletionQueue* cq = CallbackCQ(); + server_->core_server->SetRegisteredMethodAllocator( + cq->cq(), method_registration_tag, [this, cq, method_value] { + grpc_core::Server::RegisteredCallAllocation result; + new CallbackRequest<grpc::CallbackServerContext>(this, method_value, + cq, &result); + return result; + }); } method_name = method->name(); @@ -1055,10 +1055,10 @@ bool Server::RegisterService(const TString* host, grpc::Service* service) { // Parse service name. if (method_name != nullptr) { std::stringstream ss(method_name); - std::string service_name; + std::string service_name; if (std::getline(ss, service_name, '/') && std::getline(ss, service_name, '/')) { - services_.push_back(service_name.c_str()); + services_.push_back(service_name.c_str()); } } return true; @@ -1072,7 +1072,7 @@ void Server::RegisterAsyncGenericService(grpc::AsyncGenericService* service) { } void Server::RegisterCallbackGenericService( - grpc::CallbackGenericService* service) { + grpc::CallbackGenericService* service) { GPR_ASSERT( service->server_ == nullptr && "Can only register a callback generic service against one server."); @@ -1080,15 +1080,15 @@ void Server::RegisterCallbackGenericService( has_callback_generic_service_ = true; generic_handler_.reset(service->Handler()); - grpc::CompletionQueue* cq = CallbackCQ(); - server_->core_server->SetBatchMethodAllocator(cq->cq(), [this, cq] { - grpc_core::Server::BatchCallAllocation result; - new CallbackRequest<grpc::GenericCallbackServerContext>(this, cq, &result); - return result; - }); + grpc::CompletionQueue* cq = CallbackCQ(); + server_->core_server->SetBatchMethodAllocator(cq->cq(), [this, cq] { + grpc_core::Server::BatchCallAllocation result; + new CallbackRequest<grpc::GenericCallbackServerContext>(this, cq, &result); + return result; + }); } -int Server::AddListeningPort(const TString& addr, +int Server::AddListeningPort(const TString& addr, grpc::ServerCredentials* creds) { GPR_ASSERT(!started_); int port = creds->AddPortToServer(addr, server_); @@ -1096,31 +1096,31 @@ int Server::AddListeningPort(const TString& addr, return port; } -void Server::Ref() { - shutdown_refs_outstanding_.fetch_add(1, std::memory_order_relaxed); -} - -void Server::UnrefWithPossibleNotify() { - if (GPR_UNLIKELY(shutdown_refs_outstanding_.fetch_sub( - 1, std::memory_order_acq_rel) == 1)) { - // No refs outstanding means that shutdown has been initiated and no more - // callback requests are outstanding. - grpc::internal::MutexLock lock(&mu_); - GPR_ASSERT(shutdown_); - shutdown_done_ = true; - shutdown_done_cv_.Signal(); - } -} - -void Server::UnrefAndWaitLocked() { - if (GPR_UNLIKELY(shutdown_refs_outstanding_.fetch_sub( - 1, std::memory_order_acq_rel) == 1)) { - shutdown_done_ = true; - return; // no need to wait on CV since done condition already set - } - shutdown_done_cv_.WaitUntil(&mu_, [this] { return shutdown_done_; }); -} - +void Server::Ref() { + shutdown_refs_outstanding_.fetch_add(1, std::memory_order_relaxed); +} + +void Server::UnrefWithPossibleNotify() { + if (GPR_UNLIKELY(shutdown_refs_outstanding_.fetch_sub( + 1, std::memory_order_acq_rel) == 1)) { + // No refs outstanding means that shutdown has been initiated and no more + // callback requests are outstanding. + grpc::internal::MutexLock lock(&mu_); + GPR_ASSERT(shutdown_); + shutdown_done_ = true; + shutdown_done_cv_.Signal(); + } +} + +void Server::UnrefAndWaitLocked() { + if (GPR_UNLIKELY(shutdown_refs_outstanding_.fetch_sub( + 1, std::memory_order_acq_rel) == 1)) { + shutdown_done_ = true; + return; // no need to wait on CV since done condition already set + } + shutdown_done_cv_.WaitUntil(&mu_, [this] { return shutdown_done_; }); +} + void Server::Start(grpc::ServerCompletionQueue** cqs, size_t num_cqs) { GPR_ASSERT(!started_); global_callbacks_->PreServerStart(this); @@ -1156,17 +1156,17 @@ void Server::Start(grpc::ServerCompletionQueue** cqs, size_t num_cqs) { // If this server uses callback methods, then create a callback generic // service to handle any unimplemented methods using the default reactor // creator - if (has_callback_methods_ && !has_callback_generic_service_) { - unimplemented_service_.reset(new grpc::CallbackGenericService); + if (has_callback_methods_ && !has_callback_generic_service_) { + unimplemented_service_.reset(new grpc::CallbackGenericService); RegisterCallbackGenericService(unimplemented_service_.get()); } -#ifndef NDEBUG - for (size_t i = 0; i < num_cqs; i++) { - cq_list_.push_back(cqs[i]); - } -#endif - +#ifndef NDEBUG + for (size_t i = 0; i < num_cqs; i++) { + cq_list_.push_back(cqs[i]); + } +#endif + grpc_server_start(server_); if (!has_async_generic_service_ && !has_callback_generic_service_) { @@ -1248,8 +1248,8 @@ void Server::ShutdownInternal(gpr_timespec deadline) { value->Wait(); } - // Drop the shutdown ref and wait for all other refs to drop as well. - UnrefAndWaitLocked(); + // Drop the shutdown ref and wait for all other refs to drop as well. + UnrefAndWaitLocked(); // Shutdown the callback CQ. The CQ is owned by its own shutdown tag, so it // will delete itself at true shutdown. @@ -1266,15 +1266,15 @@ void Server::ShutdownInternal(gpr_timespec deadline) { shutdown_notified_ = true; shutdown_cv_.Broadcast(); - -#ifndef NDEBUG - // Unregister this server with the CQs passed into it by the user so that - // those can be checked for properly-ordered shutdown. - for (auto* cq : cq_list_) { - cq->UnregisterServer(this); - } - cq_list_.clear(); -#endif + +#ifndef NDEBUG + // Unregister this server with the CQs passed into it by the user so that + // those can be checked for properly-ordered shutdown. + for (auto* cq : cq_list_) { + cq->UnregisterServer(this); + } + cq_list_.clear(); +#endif } void Server::Wait() { @@ -1294,9 +1294,9 @@ bool Server::UnimplementedAsyncRequest::FinalizeResult(void** tag, if (GenericAsyncRequest::FinalizeResult(tag, status)) { // We either had no interceptors run or we are done intercepting if (*status) { - // Create a new request/response pair using the server and CQ values - // stored in this object's base class. - new UnimplementedAsyncRequest(server_, notification_cq_); + // Create a new request/response pair using the server and CQ values + // stored in this object's base class. + new UnimplementedAsyncRequest(server_, notification_cq_); new UnimplementedAsyncResponse(this); } else { delete this; @@ -1323,18 +1323,18 @@ 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 grpc::internal::MutexLock l(&mu_); - if (callback_cq_ != nullptr) { - return callback_cq_; - } - auto* shutdown_callback = new grpc::ShutdownCallback; - 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_); - + if (callback_cq_ != nullptr) { + return callback_cq_; + } + auto* shutdown_callback = new grpc::ShutdownCallback; + 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_); + return callback_cq_; } -} // namespace grpc +} // 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 1b93e3229a6..458ac20d87c 100644 --- a/contrib/libs/grpc/src/cpp/server/server_context.cc +++ b/contrib/libs/grpc/src/cpp/server/server_context.cc @@ -16,7 +16,7 @@ * */ -#include <grpcpp/impl/codegen/server_context.h> +#include <grpcpp/impl/codegen/server_context.h> #include <algorithm> #include <utility> @@ -27,7 +27,7 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpcpp/impl/call.h> -#include <grpcpp/impl/codegen/completion_queue.h> +#include <grpcpp/impl/codegen/completion_queue.h> #include <grpcpp/support/server_callback.h> #include <grpcpp/support/time.h> @@ -35,17 +35,17 @@ #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/surface/call.h" -namespace grpc { +namespace grpc { // CompletionOp class ServerContextBase::CompletionOp final - : public internal::CallOpSetInterface { + : public internal::CallOpSetInterface { public: // initial refs: one in the server context, one in the cq // must ref the call before calling constructor and after deleting this - CompletionOp(internal::Call* call, - ::grpc::internal::ServerCallbackCall* callback_controller) + CompletionOp(internal::Call* call, + ::grpc::internal::ServerCallbackCall* callback_controller) : call_(*call), callback_controller_(callback_controller), has_tag_(false), @@ -68,7 +68,7 @@ class ServerContextBase::CompletionOp final } } - void FillOps(internal::Call* call) override; + void FillOps(internal::Call* call) override; // This should always be arena allocated in the call, so override delete. // But this class is not trivially destructible, so must actually call delete @@ -136,8 +136,8 @@ class ServerContextBase::CompletionOp final return finalized_ ? (cancelled_ != 0) : false; } - internal::Call call_; - ::grpc::internal::ServerCallbackCall* const callback_controller_; + internal::Call call_; + ::grpc::internal::ServerCallbackCall* const callback_controller_; bool has_tag_; void* tag_; void* core_cq_tag_; @@ -146,7 +146,7 @@ class ServerContextBase::CompletionOp final bool finalized_; int cancelled_; // This is an int (not bool) because it is passed to core bool done_intercepting_; - internal::InterceptorBatchMethodsImpl interceptor_methods_; + internal::InterceptorBatchMethodsImpl interceptor_methods_; }; void ServerContextBase::CompletionOp::Unref() { @@ -157,7 +157,7 @@ void ServerContextBase::CompletionOp::Unref() { } } -void ServerContextBase::CompletionOp::FillOps(internal::Call* call) { +void ServerContextBase::CompletionOp::FillOps(internal::Call* call) { grpc_op ops; ops.op = GRPC_OP_RECV_CLOSE_ON_SERVER; ops.data.recv_close_on_server.cancelled = &cancelled_; @@ -174,31 +174,31 @@ void ServerContextBase::CompletionOp::FillOps(internal::Call* call) { } bool ServerContextBase::CompletionOp::FinalizeResult(void** tag, bool* status) { - // Decide whether to call the cancel callback within the lock - bool call_cancel; - - { - grpc_core::MutexLock lock(&mu_); - if (done_intercepting_) { - // We are done intercepting. - bool has_tag = has_tag_; - if (has_tag) { - *tag = tag_; - } - Unref(); - return has_tag; + // Decide whether to call the cancel callback within the lock + bool call_cancel; + + { + grpc_core::MutexLock lock(&mu_); + if (done_intercepting_) { + // We are done intercepting. + bool has_tag = has_tag_; + if (has_tag) { + *tag = tag_; + } + Unref(); + return has_tag; + } + finalized_ = true; + + // If for some reason the incoming status is false, mark that as a + // cancellation. + // TODO(vjpai): does this ever happen? + if (!*status) { + cancelled_ = 1; } - finalized_ = true; - - // If for some reason the incoming status is false, mark that as a - // cancellation. - // TODO(vjpai): does this ever happen? - if (!*status) { - cancelled_ = 1; - } - - call_cancel = (cancelled_ != 0); - // Release the lock since we may call a callback and interceptors. + + call_cancel = (cancelled_ != 0); + // Release the lock since we may call a callback and interceptors. } if (call_cancel && callback_controller_ != nullptr) { @@ -206,28 +206,28 @@ bool ServerContextBase::CompletionOp::FinalizeResult(void** tag, bool* status) { } /* Add interception point and run through interceptors */ interceptor_methods_.AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_RECV_CLOSE); + experimental::InterceptionHookPoints::POST_RECV_CLOSE); if (interceptor_methods_.RunInterceptors()) { - // No interceptors were run - bool has_tag = has_tag_; - if (has_tag) { + // No interceptors were run + bool has_tag = has_tag_; + if (has_tag) { *tag = tag_; } Unref(); - return has_tag; + return has_tag; } - // There are interceptors to be run. Return false for now. + // There are interceptors to be run. Return false for now. return false; } // ServerContextBase body -ServerContextBase::ServerContextBase() - : deadline_(gpr_inf_future(GPR_CLOCK_REALTIME)) {} +ServerContextBase::ServerContextBase() + : deadline_(gpr_inf_future(GPR_CLOCK_REALTIME)) {} ServerContextBase::ServerContextBase(gpr_timespec deadline, - grpc_metadata_array* arr) - : deadline_(deadline) { + grpc_metadata_array* arr) + : deadline_(deadline) { std::swap(*client_metadata_.arr(), *arr); } @@ -237,7 +237,7 @@ void ServerContextBase::BindDeadlineAndMetadata(gpr_timespec deadline, std::swap(*client_metadata_.arr(), *arr); } -ServerContextBase::~ServerContextBase() { +ServerContextBase::~ServerContextBase() { if (completion_op_) { completion_op_->Unref(); } @@ -245,21 +245,21 @@ ServerContextBase::~ServerContextBase() { rpc_info_->Unref(); } if (default_reactor_used_.load(std::memory_order_relaxed)) { - reinterpret_cast<Reactor*>(&default_reactor_)->~Reactor(); + reinterpret_cast<Reactor*>(&default_reactor_)->~Reactor(); + } +} + +ServerContextBase::CallWrapper::~CallWrapper() { + if (call) { + // If the ServerContext is part of the call's arena, this could free the + // object itself. + grpc_call_unref(call); } } -ServerContextBase::CallWrapper::~CallWrapper() { - if (call) { - // If the ServerContext is part of the call's arena, this could free the - // object itself. - grpc_call_unref(call); - } -} - void ServerContextBase::BeginCompletionOp( - internal::Call* call, std::function<void(bool)> callback, - ::grpc::internal::ServerCallbackCall* callback_controller) { + internal::Call* call, std::function<void(bool)> callback, + ::grpc::internal::ServerCallbackCall* callback_controller) { GPR_ASSERT(!completion_op_); if (rpc_info_) { rpc_info_->Ref(); @@ -279,30 +279,30 @@ void ServerContextBase::BeginCompletionOp( call->PerformOps(completion_op_); } -internal::CompletionQueueTag* ServerContextBase::GetCompletionOpTag() { - return static_cast<internal::CompletionQueueTag*>(completion_op_); +internal::CompletionQueueTag* ServerContextBase::GetCompletionOpTag() { + return static_cast<internal::CompletionQueueTag*>(completion_op_); } -void ServerContextBase::AddInitialMetadata(const TString& key, - const TString& value) { +void ServerContextBase::AddInitialMetadata(const TString& key, + const TString& value) { initial_metadata_.insert(std::make_pair(key, value)); } -void ServerContextBase::AddTrailingMetadata(const TString& key, - const TString& value) { +void ServerContextBase::AddTrailingMetadata(const TString& key, + const TString& value) { trailing_metadata_.insert(std::make_pair(key, value)); } void ServerContextBase::TryCancel() const { - internal::CancelInterceptorBatchMethods cancel_methods; + internal::CancelInterceptorBatchMethods cancel_methods; if (rpc_info_) { for (size_t i = 0; i < rpc_info_->interceptors_.size(); i++) { rpc_info_->RunInterceptor(&cancel_methods, i); } } - grpc_call_error err = - grpc_call_cancel_with_status(call_.call, GRPC_STATUS_CANCELLED, - "Cancelled on the server side", nullptr); + grpc_call_error err = + grpc_call_cancel_with_status(call_.call, GRPC_STATUS_CANCELLED, + "Cancelled on the server side", nullptr); if (err != GRPC_CALL_OK) { gpr_log(GPR_ERROR, "TryCancel failed with: %d", err); } @@ -335,10 +335,10 @@ void ServerContextBase::set_compression_algorithm( AddInitialMetadata(GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY, algorithm_name); } -TString ServerContextBase::peer() const { - TString peer; - if (call_.call) { - char* c_peer = grpc_call_get_peer(call_.call); +TString ServerContextBase::peer() const { + TString peer; + if (call_.call) { + char* c_peer = grpc_call_get_peer(call_.call); peer = c_peer; gpr_free(c_peer); } @@ -346,16 +346,16 @@ TString ServerContextBase::peer() const { } const struct census_context* ServerContextBase::census_context() const { - return call_.call == nullptr ? nullptr - : grpc_census_call_get_context(call_.call); + return call_.call == nullptr ? nullptr + : grpc_census_call_get_context(call_.call); } void ServerContextBase::SetLoadReportingCosts( - const std::vector<TString>& cost_data) { - if (call_.call == nullptr) return; + const std::vector<TString>& cost_data) { + if (call_.call == nullptr) return; for (const auto& cost_datum : cost_data) { AddTrailingMetadata(GRPC_LB_COST_MD_KEY, cost_datum); } } -} // namespace grpc +} // namespace grpc diff --git a/contrib/libs/grpc/src/cpp/server/server_credentials.cc b/contrib/libs/grpc/src/cpp/server/server_credentials.cc index 449e583abd0..c3b3a8b3793 100644 --- a/contrib/libs/grpc/src/cpp/server/server_credentials.cc +++ b/contrib/libs/grpc/src/cpp/server/server_credentials.cc @@ -16,10 +16,10 @@ * */ -#include <grpcpp/security/server_credentials.h> +#include <grpcpp/security/server_credentials.h> -namespace grpc { +namespace grpc { ServerCredentials::~ServerCredentials() {} -} // namespace grpc +} // 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 3aaa6db0ea0..c3d40d4fa2d 100644 --- a/contrib/libs/grpc/src/cpp/server/server_posix.cc +++ b/contrib/libs/grpc/src/cpp/server/server_posix.cc @@ -20,7 +20,7 @@ #include <grpc/grpc_posix.h> -namespace grpc { +namespace grpc { #ifdef GPR_SUPPORT_CHANNELS_FROM_FD @@ -30,4 +30,4 @@ void AddInsecureChannelFromFd(grpc::Server* server, int fd) { #endif // GPR_SUPPORT_CHANNELS_FROM_FD -} // namespace grpc +} // 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 e6988f54749..c8560aa81dd 100644 --- a/contrib/libs/grpc/src/cpp/thread_manager/thread_manager.cc +++ b/contrib/libs/grpc/src/cpp/thread_manager/thread_manager.cc @@ -184,8 +184,8 @@ void ThreadManager::MainWorkLoop() { if (worker->created()) { worker->Start(); } else { - // Get lock again to undo changes to poller/thread counters. - grpc_core::MutexLock failure_lock(&mu_); + // Get lock again to undo changes to poller/thread counters. + grpc_core::MutexLock failure_lock(&mu_); num_pollers_--; num_threads_--; resource_exhausted = true; diff --git a/contrib/libs/grpc/src/cpp/util/error_details.cc b/contrib/libs/grpc/src/cpp/util/error_details.cc index 491a460386a..dfd3351be15 100644 --- a/contrib/libs/grpc/src/cpp/util/error_details.cc +++ b/contrib/libs/grpc/src/cpp/util/error_details.cc @@ -20,7 +20,7 @@ #include "src/proto/grpc/status/status.pb.h" -namespace grpc { +namespace grpc { grpc::Status ExtractErrorDetails(const grpc::Status& from, ::google::rpc::Status* to) { @@ -47,4 +47,4 @@ grpc::Status SetErrorDetails(const ::google::rpc::Status& from, return grpc::Status::OK; } -} // namespace grpc +} // namespace grpc |