Merge branch 'master' into healthcheck

pull/23183/head
Karthik Ravi Shankar 5 years ago
commit 4a930208e7
  1. 3
      BUILD
  2. 2
      BUILD.gn
  3. 4
      CMakeLists.txt
  4. 4
      Makefile
  5. 2
      build_autogenerated.yaml
  6. 1
      config.m4
  7. 1
      config.w32
  8. 1
      gRPC-C++.podspec
  9. 1
      gRPC-Core.podspec
  10. 1
      grpc.gemspec
  11. 2
      grpc.gyp
  12. 4
      include/grpcpp/opencensus.h
  13. 45
      include/grpcpp/resource_quota.h
  14. 5
      include/grpcpp/server_builder_impl.h
  15. 1
      package.xml
  16. 2
      src/core/ext/filters/client_channel/resolving_lb_policy.h
  17. 142
      src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc
  18. 3
      src/core/ext/filters/http/http_filters_plugin.cc
  19. 88
      src/core/ext/filters/http/message_compress/message_decompress_filter.cc
  20. 4
      src/core/ext/filters/http/message_compress/message_decompress_filter.h
  21. 106
      src/core/ext/filters/message_size/message_size_filter.cc
  22. 6
      src/core/ext/filters/message_size/message_size_filter.h
  23. 4
      src/core/plugin_registry/grpc_plugin_registry.cc
  24. 4
      src/core/plugin_registry/grpc_unsecure_plugin_registry.cc
  25. 2
      src/cpp/common/channel_arguments.cc
  26. 4
      src/cpp/common/resource_quota_cc.cc
  27. 6
      src/cpp/ext/filters/census/grpc_plugin.cc
  28. 2
      src/cpp/server/server_builder.cc
  29. 129
      src/php/README.md
  30. 7
      src/php/ext/grpc/call.c
  31. 5
      src/php/ext/grpc/call_credentials.c
  32. 5
      src/php/ext/grpc/channel.c
  33. 11
      src/php/ext/grpc/channel_credentials.c
  34. 5
      src/php/ext/grpc/server.c
  35. 11
      src/php/ext/grpc/server_credentials.c
  36. 5
      src/php/ext/grpc/timeval.c
  37. 49
      src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi
  38. 43
      src/python/grpcio/grpc/experimental/aio/_base_server.py
  39. 1
      src/python/grpcio/grpc_core_dependencies.py
  40. 2
      src/python/grpcio_tests/tests_aio/tests.json
  41. 194
      src/python/grpcio_tests/tests_aio/unit/auth_context_test.py
  42. 65
      src/python/grpcio_tests/tests_aio/unit/context_peer_test.py
  43. 332
      test/core/end2end/tests/max_message_length.cc
  44. 3
      test/cpp/microbenchmarks/bm_call_create.cc
  45. 8
      test/cpp/microbenchmarks/bm_opencensus_plugin.cc
  46. 1
      tools/doxygen/Doxyfile.c++
  47. 2
      tools/doxygen/Doxyfile.c++.internal
  48. 1
      tools/doxygen/Doxyfile.core.internal

@ -250,7 +250,6 @@ GRPCXX_PUBLIC_HDRS = [
"include/grpcpp/impl/server_initializer_impl.h", "include/grpcpp/impl/server_initializer_impl.h",
"include/grpcpp/impl/service_type.h", "include/grpcpp/impl/service_type.h",
"include/grpcpp/resource_quota.h", "include/grpcpp/resource_quota.h",
"include/grpcpp/resource_quota_impl.h",
"include/grpcpp/security/auth_context.h", "include/grpcpp/security/auth_context.h",
"include/grpcpp/security/auth_metadata_processor.h", "include/grpcpp/security/auth_metadata_processor.h",
"include/grpcpp/security/auth_metadata_processor_impl.h", "include/grpcpp/security/auth_metadata_processor_impl.h",
@ -1045,7 +1044,6 @@ grpc_cc_library(
"src/core/ext/filters/client_channel/retry_throttle.cc", "src/core/ext/filters/client_channel/retry_throttle.cc",
"src/core/ext/filters/client_channel/server_address.cc", "src/core/ext/filters/client_channel/server_address.cc",
"src/core/ext/filters/client_channel/service_config.cc", "src/core/ext/filters/client_channel/service_config.cc",
"src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc",
"src/core/ext/filters/client_channel/service_config_parser.cc", "src/core/ext/filters/client_channel/service_config_parser.cc",
"src/core/ext/filters/client_channel/subchannel.cc", "src/core/ext/filters/client_channel/subchannel.cc",
"src/core/ext/filters/client_channel/subchannel_pool_interface.cc", "src/core/ext/filters/client_channel/subchannel_pool_interface.cc",
@ -1187,7 +1185,6 @@ grpc_cc_library(
language = "c++", language = "c++",
deps = [ deps = [
"grpc_base", "grpc_base",
"grpc_message_size_filter",
], ],
) )

@ -295,7 +295,6 @@ config("grpc_config") {
"src/core/ext/filters/client_channel/service_config.cc", "src/core/ext/filters/client_channel/service_config.cc",
"src/core/ext/filters/client_channel/service_config.h", "src/core/ext/filters/client_channel/service_config.h",
"src/core/ext/filters/client_channel/service_config_call_data.h", "src/core/ext/filters/client_channel/service_config_call_data.h",
"src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc",
"src/core/ext/filters/client_channel/service_config_parser.cc", "src/core/ext/filters/client_channel/service_config_parser.cc",
"src/core/ext/filters/client_channel/service_config_parser.h", "src/core/ext/filters/client_channel/service_config_parser.h",
"src/core/ext/filters/client_channel/subchannel.cc", "src/core/ext/filters/client_channel/subchannel.cc",
@ -1177,7 +1176,6 @@ config("grpc_config") {
"include/grpcpp/impl/server_initializer_impl.h", "include/grpcpp/impl/server_initializer_impl.h",
"include/grpcpp/impl/service_type.h", "include/grpcpp/impl/service_type.h",
"include/grpcpp/resource_quota.h", "include/grpcpp/resource_quota.h",
"include/grpcpp/resource_quota_impl.h",
"include/grpcpp/security/auth_context.h", "include/grpcpp/security/auth_context.h",
"include/grpcpp/security/auth_metadata_processor.h", "include/grpcpp/security/auth_metadata_processor.h",
"include/grpcpp/security/auth_metadata_processor_impl.h", "include/grpcpp/security/auth_metadata_processor_impl.h",

@ -1376,7 +1376,6 @@ add_library(grpc
src/core/ext/filters/client_channel/retry_throttle.cc src/core/ext/filters/client_channel/retry_throttle.cc
src/core/ext/filters/client_channel/server_address.cc src/core/ext/filters/client_channel/server_address.cc
src/core/ext/filters/client_channel/service_config.cc src/core/ext/filters/client_channel/service_config.cc
src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc
src/core/ext/filters/client_channel/service_config_parser.cc src/core/ext/filters/client_channel/service_config_parser.cc
src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel.cc
src/core/ext/filters/client_channel/subchannel_pool_interface.cc src/core/ext/filters/client_channel/subchannel_pool_interface.cc
@ -2049,7 +2048,6 @@ add_library(grpc_unsecure
src/core/ext/filters/client_channel/retry_throttle.cc src/core/ext/filters/client_channel/retry_throttle.cc
src/core/ext/filters/client_channel/server_address.cc src/core/ext/filters/client_channel/server_address.cc
src/core/ext/filters/client_channel/service_config.cc src/core/ext/filters/client_channel/service_config.cc
src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc
src/core/ext/filters/client_channel/service_config_parser.cc src/core/ext/filters/client_channel/service_config_parser.cc
src/core/ext/filters/client_channel/subchannel.cc src/core/ext/filters/client_channel/subchannel.cc
src/core/ext/filters/client_channel/subchannel_pool_interface.cc src/core/ext/filters/client_channel/subchannel_pool_interface.cc
@ -2741,7 +2739,6 @@ foreach(_hdr
include/grpcpp/impl/server_initializer_impl.h include/grpcpp/impl/server_initializer_impl.h
include/grpcpp/impl/service_type.h include/grpcpp/impl/service_type.h
include/grpcpp/resource_quota.h include/grpcpp/resource_quota.h
include/grpcpp/resource_quota_impl.h
include/grpcpp/security/auth_context.h include/grpcpp/security/auth_context.h
include/grpcpp/security/auth_metadata_processor.h include/grpcpp/security/auth_metadata_processor.h
include/grpcpp/security/auth_metadata_processor_impl.h include/grpcpp/security/auth_metadata_processor_impl.h
@ -3435,7 +3432,6 @@ foreach(_hdr
include/grpcpp/impl/server_initializer_impl.h include/grpcpp/impl/server_initializer_impl.h
include/grpcpp/impl/service_type.h include/grpcpp/impl/service_type.h
include/grpcpp/resource_quota.h include/grpcpp/resource_quota.h
include/grpcpp/resource_quota_impl.h
include/grpcpp/security/auth_context.h include/grpcpp/security/auth_context.h
include/grpcpp/security/auth_metadata_processor.h include/grpcpp/security/auth_metadata_processor.h
include/grpcpp/security/auth_metadata_processor_impl.h include/grpcpp/security/auth_metadata_processor_impl.h

@ -3675,7 +3675,6 @@ LIBGRPC_SRC = \
src/core/ext/filters/client_channel/retry_throttle.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \
src/core/ext/filters/client_channel/server_address.cc \ src/core/ext/filters/client_channel/server_address.cc \
src/core/ext/filters/client_channel/service_config.cc \ src/core/ext/filters/client_channel/service_config.cc \
src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc \
src/core/ext/filters/client_channel/service_config_parser.cc \ src/core/ext/filters/client_channel/service_config_parser.cc \
src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel.cc \
src/core/ext/filters/client_channel/subchannel_pool_interface.cc \ src/core/ext/filters/client_channel/subchannel_pool_interface.cc \
@ -4322,7 +4321,6 @@ LIBGRPC_UNSECURE_SRC = \
src/core/ext/filters/client_channel/retry_throttle.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \
src/core/ext/filters/client_channel/server_address.cc \ src/core/ext/filters/client_channel/server_address.cc \
src/core/ext/filters/client_channel/service_config.cc \ src/core/ext/filters/client_channel/service_config.cc \
src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc \
src/core/ext/filters/client_channel/service_config_parser.cc \ src/core/ext/filters/client_channel/service_config_parser.cc \
src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel.cc \
src/core/ext/filters/client_channel/subchannel_pool_interface.cc \ src/core/ext/filters/client_channel/subchannel_pool_interface.cc \
@ -4934,7 +4932,6 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/server_initializer_impl.h \ include/grpcpp/impl/server_initializer_impl.h \
include/grpcpp/impl/service_type.h \ include/grpcpp/impl/service_type.h \
include/grpcpp/resource_quota.h \ include/grpcpp/resource_quota.h \
include/grpcpp/resource_quota_impl.h \
include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_context.h \
include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/auth_metadata_processor.h \
include/grpcpp/security/auth_metadata_processor_impl.h \ include/grpcpp/security/auth_metadata_processor_impl.h \
@ -5633,7 +5630,6 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/server_initializer_impl.h \ include/grpcpp/impl/server_initializer_impl.h \
include/grpcpp/impl/service_type.h \ include/grpcpp/impl/service_type.h \
include/grpcpp/resource_quota.h \ include/grpcpp/resource_quota.h \
include/grpcpp/resource_quota_impl.h \
include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_context.h \
include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/auth_metadata_processor.h \
include/grpcpp/security/auth_metadata_processor_impl.h \ include/grpcpp/security/auth_metadata_processor_impl.h \

@ -795,7 +795,6 @@ libs:
- src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/retry_throttle.cc
- src/core/ext/filters/client_channel/server_address.cc - src/core/ext/filters/client_channel/server_address.cc
- src/core/ext/filters/client_channel/service_config.cc - src/core/ext/filters/client_channel/service_config.cc
- src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc
- src/core/ext/filters/client_channel/service_config_parser.cc - src/core/ext/filters/client_channel/service_config_parser.cc
- src/core/ext/filters/client_channel/subchannel.cc - src/core/ext/filters/client_channel/subchannel.cc
- src/core/ext/filters/client_channel/subchannel_pool_interface.cc - src/core/ext/filters/client_channel/subchannel_pool_interface.cc
@ -1657,7 +1656,6 @@ libs:
- src/core/ext/filters/client_channel/retry_throttle.cc - src/core/ext/filters/client_channel/retry_throttle.cc
- src/core/ext/filters/client_channel/server_address.cc - src/core/ext/filters/client_channel/server_address.cc
- src/core/ext/filters/client_channel/service_config.cc - src/core/ext/filters/client_channel/service_config.cc
- src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc
- src/core/ext/filters/client_channel/service_config_parser.cc - src/core/ext/filters/client_channel/service_config_parser.cc
- src/core/ext/filters/client_channel/subchannel.cc - src/core/ext/filters/client_channel/subchannel.cc
- src/core/ext/filters/client_channel/subchannel_pool_interface.cc - src/core/ext/filters/client_channel/subchannel_pool_interface.cc

@ -93,7 +93,6 @@ if test "$PHP_GRPC" != "no"; then
src/core/ext/filters/client_channel/retry_throttle.cc \ src/core/ext/filters/client_channel/retry_throttle.cc \
src/core/ext/filters/client_channel/server_address.cc \ src/core/ext/filters/client_channel/server_address.cc \
src/core/ext/filters/client_channel/service_config.cc \ src/core/ext/filters/client_channel/service_config.cc \
src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc \
src/core/ext/filters/client_channel/service_config_parser.cc \ src/core/ext/filters/client_channel/service_config_parser.cc \
src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel.cc \
src/core/ext/filters/client_channel/subchannel_pool_interface.cc \ src/core/ext/filters/client_channel/subchannel_pool_interface.cc \

@ -62,7 +62,6 @@ if (PHP_GRPC != "no") {
"src\\core\\ext\\filters\\client_channel\\retry_throttle.cc " + "src\\core\\ext\\filters\\client_channel\\retry_throttle.cc " +
"src\\core\\ext\\filters\\client_channel\\server_address.cc " + "src\\core\\ext\\filters\\client_channel\\server_address.cc " +
"src\\core\\ext\\filters\\client_channel\\service_config.cc " + "src\\core\\ext\\filters\\client_channel\\service_config.cc " +
"src\\core\\ext\\filters\\client_channel\\service_config_channel_arg_filter.cc " +
"src\\core\\ext\\filters\\client_channel\\service_config_parser.cc " + "src\\core\\ext\\filters\\client_channel\\service_config_parser.cc " +
"src\\core\\ext\\filters\\client_channel\\subchannel.cc " + "src\\core\\ext\\filters\\client_channel\\subchannel.cc " +
"src\\core\\ext\\filters\\client_channel\\subchannel_pool_interface.cc " + "src\\core\\ext\\filters\\client_channel\\subchannel_pool_interface.cc " +

@ -163,7 +163,6 @@ Pod::Spec.new do |s|
'include/grpcpp/impl/server_initializer_impl.h', 'include/grpcpp/impl/server_initializer_impl.h',
'include/grpcpp/impl/service_type.h', 'include/grpcpp/impl/service_type.h',
'include/grpcpp/resource_quota.h', 'include/grpcpp/resource_quota.h',
'include/grpcpp/resource_quota_impl.h',
'include/grpcpp/security/auth_context.h', 'include/grpcpp/security/auth_context.h',
'include/grpcpp/security/auth_metadata_processor.h', 'include/grpcpp/security/auth_metadata_processor.h',
'include/grpcpp/security/auth_metadata_processor_impl.h', 'include/grpcpp/security/auth_metadata_processor_impl.h',

@ -279,7 +279,6 @@ Pod::Spec.new do |s|
'src/core/ext/filters/client_channel/service_config.cc', 'src/core/ext/filters/client_channel/service_config.cc',
'src/core/ext/filters/client_channel/service_config.h', 'src/core/ext/filters/client_channel/service_config.h',
'src/core/ext/filters/client_channel/service_config_call_data.h', 'src/core/ext/filters/client_channel/service_config_call_data.h',
'src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc',
'src/core/ext/filters/client_channel/service_config_parser.cc', 'src/core/ext/filters/client_channel/service_config_parser.cc',
'src/core/ext/filters/client_channel/service_config_parser.h', 'src/core/ext/filters/client_channel/service_config_parser.h',
'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel.cc',

@ -201,7 +201,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/ext/filters/client_channel/service_config.cc ) s.files += %w( src/core/ext/filters/client_channel/service_config.cc )
s.files += %w( src/core/ext/filters/client_channel/service_config.h ) s.files += %w( src/core/ext/filters/client_channel/service_config.h )
s.files += %w( src/core/ext/filters/client_channel/service_config_call_data.h ) s.files += %w( src/core/ext/filters/client_channel/service_config_call_data.h )
s.files += %w( src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc )
s.files += %w( src/core/ext/filters/client_channel/service_config_parser.cc ) s.files += %w( src/core/ext/filters/client_channel/service_config_parser.cc )
s.files += %w( src/core/ext/filters/client_channel/service_config_parser.h ) s.files += %w( src/core/ext/filters/client_channel/service_config_parser.h )
s.files += %w( src/core/ext/filters/client_channel/subchannel.cc ) s.files += %w( src/core/ext/filters/client_channel/subchannel.cc )

@ -488,7 +488,6 @@
'src/core/ext/filters/client_channel/retry_throttle.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc',
'src/core/ext/filters/client_channel/server_address.cc', 'src/core/ext/filters/client_channel/server_address.cc',
'src/core/ext/filters/client_channel/service_config.cc', 'src/core/ext/filters/client_channel/service_config.cc',
'src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc',
'src/core/ext/filters/client_channel/service_config_parser.cc', 'src/core/ext/filters/client_channel/service_config_parser.cc',
'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel.cc',
'src/core/ext/filters/client_channel/subchannel_pool_interface.cc', 'src/core/ext/filters/client_channel/subchannel_pool_interface.cc',
@ -997,7 +996,6 @@
'src/core/ext/filters/client_channel/retry_throttle.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc',
'src/core/ext/filters/client_channel/server_address.cc', 'src/core/ext/filters/client_channel/server_address.cc',
'src/core/ext/filters/client_channel/service_config.cc', 'src/core/ext/filters/client_channel/service_config.cc',
'src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc',
'src/core/ext/filters/client_channel/service_config_parser.cc', 'src/core/ext/filters/client_channel/service_config_parser.cc',
'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel.cc',
'src/core/ext/filters/client_channel/subchannel_pool_interface.cc', 'src/core/ext/filters/client_channel/subchannel_pool_interface.cc',

@ -1,6 +1,6 @@
/* /*
* *
* Copyright 2018 gRPC authors. * Copyright 2019 gRPC authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,7 +23,7 @@
namespace grpc_impl { namespace grpc_impl {
class ServerContext; class ServerContext;
} } // namespace grpc_impl
namespace grpc { namespace grpc {
// These symbols in this file will not be included in the binary unless // These symbols in this file will not be included in the binary unless

@ -1,6 +1,6 @@
/* /*
* *
* Copyright 2019 gRPC authors. * Copyright 2016 gRPC authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,11 +19,50 @@
#ifndef GRPCPP_RESOURCE_QUOTA_H #ifndef GRPCPP_RESOURCE_QUOTA_H
#define GRPCPP_RESOURCE_QUOTA_H #define GRPCPP_RESOURCE_QUOTA_H
#include <grpcpp/resource_quota_impl.h> struct grpc_resource_quota;
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/grpc_library.h>
namespace grpc { namespace grpc {
typedef ::grpc_impl::ResourceQuota ResourceQuota; /// ResourceQuota represents a bound on memory and thread usage by the gRPC
/// library. A ResourceQuota can be attached to a server (via \a ServerBuilder),
/// or a client channel (via \a ChannelArguments).
/// gRPC will attempt to keep memory and threads used by all attached entities
/// below the ResourceQuota bound.
class ResourceQuota final : private ::grpc::GrpcLibraryCodegen {
public:
/// \param name - a unique name for this ResourceQuota.
explicit ResourceQuota(const grpc::string& name);
ResourceQuota();
~ResourceQuota();
/// Resize this \a ResourceQuota to a new size. If \a new_size is smaller
/// than the current size of the pool, memory usage will be monotonically
/// decreased until it falls under \a new_size.
/// No time bound is given for this to occur however.
ResourceQuota& Resize(size_t new_size);
/// Set the max number of threads that can be allocated from this
/// ResourceQuota object.
///
/// If the new_max_threads value is smaller than the current value, no new
/// threads are allocated until the number of active threads fall below
/// new_max_threads. There is no time bound on when this may happen i.e none
/// of the current threads are forcefully destroyed and all threads run their
/// normal course.
ResourceQuota& SetMaxThreads(int new_max_threads);
grpc_resource_quota* c_resource_quota() const { return impl_; }
private:
ResourceQuota(const ResourceQuota& rhs);
ResourceQuota& operator=(const ResourceQuota& rhs);
grpc_resource_quota* const impl_;
};
} // namespace grpc } // namespace grpc
#endif // GRPCPP_RESOURCE_QUOTA_H #endif // GRPCPP_RESOURCE_QUOTA_H

@ -41,7 +41,6 @@ struct grpc_resource_quota;
namespace grpc_impl { namespace grpc_impl {
class CompletionQueue; class CompletionQueue;
class ResourceQuota;
class Server; class Server;
class ServerCompletionQueue; class ServerCompletionQueue;
class ServerCredentials; class ServerCredentials;
@ -50,6 +49,7 @@ class ServerCredentials;
namespace grpc { namespace grpc {
class AsyncGenericService; class AsyncGenericService;
class ResourceQuota;
class Service; class Service;
namespace testing { namespace testing {
class ServerBuilderPluginTest; class ServerBuilderPluginTest;
@ -228,8 +228,7 @@ class ServerBuilder {
grpc_compression_algorithm algorithm); grpc_compression_algorithm algorithm);
/// Set the attached buffer pool for this server /// Set the attached buffer pool for this server
ServerBuilder& SetResourceQuota( ServerBuilder& SetResourceQuota(const grpc::ResourceQuota& resource_quota);
const grpc_impl::ResourceQuota& resource_quota);
ServerBuilder& SetOption(std::unique_ptr<grpc::ServerBuilderOption> option); ServerBuilder& SetOption(std::unique_ptr<grpc::ServerBuilderOption> option);

@ -181,7 +181,6 @@
<file baseinstalldir="/" name="src/core/ext/filters/client_channel/service_config.cc" role="src" /> <file baseinstalldir="/" name="src/core/ext/filters/client_channel/service_config.cc" role="src" />
<file baseinstalldir="/" name="src/core/ext/filters/client_channel/service_config.h" role="src" /> <file baseinstalldir="/" name="src/core/ext/filters/client_channel/service_config.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/filters/client_channel/service_config_call_data.h" role="src" /> <file baseinstalldir="/" name="src/core/ext/filters/client_channel/service_config_call_data.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc" role="src" />
<file baseinstalldir="/" name="src/core/ext/filters/client_channel/service_config_parser.cc" role="src" /> <file baseinstalldir="/" name="src/core/ext/filters/client_channel/service_config_parser.cc" role="src" />
<file baseinstalldir="/" name="src/core/ext/filters/client_channel/service_config_parser.h" role="src" /> <file baseinstalldir="/" name="src/core/ext/filters/client_channel/service_config_parser.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/filters/client_channel/subchannel.cc" role="src" /> <file baseinstalldir="/" name="src/core/ext/filters/client_channel/subchannel.cc" role="src" />

@ -68,6 +68,8 @@ class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
RefCountedPtr<LoadBalancingPolicy::Config> lb_policy_config; RefCountedPtr<LoadBalancingPolicy::Config> lb_policy_config;
}; };
virtual ~ChannelConfigHelper() = default;
// Applies the service config to the channel. // Applies the service config to the channel.
virtual ApplyServiceConfigResult ApplyServiceConfig( virtual ApplyServiceConfigResult ApplyServiceConfig(
const Resolver::Result& result) = 0; const Resolver::Result& result) = 0;

@ -1,142 +0,0 @@
//
// Copyright 2020 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.
//
// This filter reads GRPC_ARG_SERVICE_CONFIG and populates ServiceConfigCallData
// in the call context per call for direct channels.
#include <grpc/support/port_platform.h>
#include "src/core/ext/filters/client_channel/service_config_call_data.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/surface/channel_init.h"
namespace grpc_core {
namespace {
class ServiceConfigChannelArgChannelData {
public:
explicit ServiceConfigChannelArgChannelData(
const grpc_channel_element_args* args) {
const char* service_config_str = grpc_channel_args_find_string(
args->channel_args, GRPC_ARG_SERVICE_CONFIG);
if (service_config_str != nullptr) {
grpc_error* service_config_error = GRPC_ERROR_NONE;
auto service_config =
ServiceConfig::Create(service_config_str, &service_config_error);
if (service_config_error == GRPC_ERROR_NONE) {
service_config_ = std::move(service_config);
} else {
gpr_log(GPR_ERROR, "%s", grpc_error_string(service_config_error));
}
GRPC_ERROR_UNREF(service_config_error);
}
}
RefCountedPtr<ServiceConfig> service_config() const {
return service_config_;
}
private:
RefCountedPtr<ServiceConfig> service_config_;
};
class ServiceConfigChannelArgCallData {
public:
ServiceConfigChannelArgCallData(grpc_call_element* elem,
const grpc_call_element_args* args) {
ServiceConfigChannelArgChannelData* chand =
static_cast<ServiceConfigChannelArgChannelData*>(elem->channel_data);
RefCountedPtr<ServiceConfig> service_config = chand->service_config();
if (service_config != nullptr) {
GPR_DEBUG_ASSERT(args->context != nullptr);
const auto* method_params_vector =
service_config->GetMethodParsedConfigVector(args->path);
args->arena->New<ServiceConfigCallData>(
std::move(service_config), method_params_vector, args->context);
}
}
};
grpc_error* ServiceConfigChannelArgInitCallElem(
grpc_call_element* elem, const grpc_call_element_args* args) {
ServiceConfigChannelArgCallData* calld =
static_cast<ServiceConfigChannelArgCallData*>(elem->call_data);
new (calld) ServiceConfigChannelArgCallData(elem, args);
return GRPC_ERROR_NONE;
}
void ServiceConfigChannelArgDestroyCallElem(
grpc_call_element* elem, const grpc_call_final_info* /* final_info */,
grpc_closure* /* then_schedule_closure */) {
ServiceConfigChannelArgCallData* calld =
static_cast<ServiceConfigChannelArgCallData*>(elem->call_data);
calld->~ServiceConfigChannelArgCallData();
}
grpc_error* ServiceConfigChannelArgInitChannelElem(
grpc_channel_element* elem, grpc_channel_element_args* args) {
ServiceConfigChannelArgChannelData* chand =
static_cast<ServiceConfigChannelArgChannelData*>(elem->channel_data);
new (chand) ServiceConfigChannelArgChannelData(args);
return GRPC_ERROR_NONE;
}
void ServiceConfigChannelArgDestroyChannelElem(grpc_channel_element* elem) {
ServiceConfigChannelArgChannelData* chand =
static_cast<ServiceConfigChannelArgChannelData*>(elem->channel_data);
chand->~ServiceConfigChannelArgChannelData();
}
const grpc_channel_filter ServiceConfigChannelArgFilter = {
grpc_call_next_op,
grpc_channel_next_op,
sizeof(ServiceConfigChannelArgCallData),
ServiceConfigChannelArgInitCallElem,
grpc_call_stack_ignore_set_pollset_or_pollset_set,
ServiceConfigChannelArgDestroyCallElem,
sizeof(ServiceConfigChannelArgChannelData),
ServiceConfigChannelArgInitChannelElem,
ServiceConfigChannelArgDestroyChannelElem,
grpc_channel_next_get_info,
"service_config_channel_arg"};
bool maybe_add_service_config_channel_arg_filter(
grpc_channel_stack_builder* builder, void* /* arg */) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (grpc_channel_args_want_minimal_stack(channel_args) ||
grpc_channel_args_find_string(channel_args, GRPC_ARG_SERVICE_CONFIG) ==
nullptr) {
return true;
}
return grpc_channel_stack_builder_prepend_filter(
builder, &ServiceConfigChannelArgFilter, nullptr, nullptr);
}
} // namespace
} // namespace grpc_core
void grpc_service_config_channel_arg_filter_init(void) {
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_core::maybe_add_service_config_channel_arg_filter, nullptr);
}
void grpc_service_config_channel_arg_filter_shutdown(void) {}

@ -38,8 +38,7 @@ static optional_filter compress_filter = {
&grpc_message_compress_filter, GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION}; &grpc_message_compress_filter, GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION};
static optional_filter decompress_filter = { static optional_filter decompress_filter = {
&grpc_core::MessageDecompressFilter, &grpc_message_decompress_filter, GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION};
GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION};
static bool is_building_http_like_transport( static bool is_building_http_like_transport(
grpc_channel_stack_builder* builder) { grpc_channel_stack_builder* builder) {

@ -18,8 +18,6 @@
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
#include "src/core/ext/filters/http/message_compress/message_decompress_filter.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
@ -29,8 +27,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include "absl/strings/str_format.h" #include "src/core/ext/filters/http/message_compress/message_decompress_filter.h"
#include "src/core/ext/filters/message_size/message_size_filter.h"
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/compression/algorithm_metadata.h" #include "src/core/lib/compression/algorithm_metadata.h"
#include "src/core/lib/compression/compression_args.h" #include "src/core/lib/compression/compression_args.h"
@ -40,25 +37,14 @@
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/slice/slice_string_helpers.h"
namespace grpc_core {
namespace { namespace {
class ChannelData { class ChannelData {};
public:
explicit ChannelData(const grpc_channel_element_args* args)
: max_recv_size_(GetMaxRecvSizeFromChannelArgs(args->channel_args)) {}
int max_recv_size() const { return max_recv_size_; }
private:
int max_recv_size_;
};
class CallData { class CallData {
public: public:
CallData(const grpc_call_element_args& args, const ChannelData* chand) explicit CallData(const grpc_call_element_args& args)
: call_combiner_(args.call_combiner), : call_combiner_(args.call_combiner) {
max_recv_message_length_(chand->max_recv_size()) {
// Initialize state for recv_initial_metadata_ready callback // Initialize state for recv_initial_metadata_ready callback
GRPC_CLOSURE_INIT(&on_recv_initial_metadata_ready_, GRPC_CLOSURE_INIT(&on_recv_initial_metadata_ready_,
OnRecvInitialMetadataReady, this, OnRecvInitialMetadataReady, this,
@ -73,13 +59,6 @@ class CallData {
GRPC_CLOSURE_INIT(&on_recv_trailing_metadata_ready_, GRPC_CLOSURE_INIT(&on_recv_trailing_metadata_ready_,
OnRecvTrailingMetadataReady, this, OnRecvTrailingMetadataReady, this,
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);
const MessageSizeParsedConfig* limits =
MessageSizeParsedConfig::GetFromCallContext(args.context);
if (limits != nullptr && limits->limits().max_recv_size >= 0 &&
(limits->limits().max_recv_size < max_recv_message_length_ ||
max_recv_message_length_ < 0)) {
max_recv_message_length_ = limits->limits().max_recv_size;
}
} }
~CallData() { grpc_slice_buffer_destroy_internal(&recv_slices_); } ~CallData() { grpc_slice_buffer_destroy_internal(&recv_slices_); }
@ -103,7 +82,7 @@ class CallData {
void MaybeResumeOnRecvTrailingMetadataReady(); void MaybeResumeOnRecvTrailingMetadataReady();
static void OnRecvTrailingMetadataReady(void* arg, grpc_error* error); static void OnRecvTrailingMetadataReady(void* arg, grpc_error* error);
CallCombiner* call_combiner_; grpc_core::CallCombiner* call_combiner_;
// Overall error for the call // Overall error for the call
grpc_error* error_ = GRPC_ERROR_NONE; grpc_error* error_ = GRPC_ERROR_NONE;
// Fields for handling recv_initial_metadata_ready callback // Fields for handling recv_initial_metadata_ready callback
@ -112,18 +91,17 @@ class CallData {
grpc_metadata_batch* recv_initial_metadata_ = nullptr; grpc_metadata_batch* recv_initial_metadata_ = nullptr;
// Fields for handling recv_message_ready callback // Fields for handling recv_message_ready callback
bool seen_recv_message_ready_ = false; bool seen_recv_message_ready_ = false;
int max_recv_message_length_;
grpc_message_compression_algorithm algorithm_ = GRPC_MESSAGE_COMPRESS_NONE; grpc_message_compression_algorithm algorithm_ = GRPC_MESSAGE_COMPRESS_NONE;
grpc_closure on_recv_message_ready_; grpc_closure on_recv_message_ready_;
grpc_closure* original_recv_message_ready_ = nullptr; grpc_closure* original_recv_message_ready_ = nullptr;
grpc_closure on_recv_message_next_done_; grpc_closure on_recv_message_next_done_;
OrphanablePtr<ByteStream>* recv_message_ = nullptr; grpc_core::OrphanablePtr<grpc_core::ByteStream>* recv_message_ = nullptr;
// recv_slices_ holds the slices read from the original recv_message stream. // recv_slices_ holds the slices read from the original recv_message stream.
// It is initialized during construction and reset when a new stream is // It is initialized during construction and reset when a new stream is
// created using it. // created using it.
grpc_slice_buffer recv_slices_; grpc_slice_buffer recv_slices_;
std::aligned_storage<sizeof(SliceBufferByteStream), std::aligned_storage<sizeof(grpc_core::SliceBufferByteStream),
alignof(SliceBufferByteStream)>::type alignof(grpc_core::SliceBufferByteStream)>::type
recv_replacement_stream_; recv_replacement_stream_;
// Fields for handling recv_trailing_metadata_ready callback // Fields for handling recv_trailing_metadata_ready callback
bool seen_recv_trailing_metadata_ready_ = false; bool seen_recv_trailing_metadata_ready_ = false;
@ -161,7 +139,7 @@ void CallData::OnRecvInitialMetadataReady(void* arg, grpc_error* error) {
calld->MaybeResumeOnRecvTrailingMetadataReady(); calld->MaybeResumeOnRecvTrailingMetadataReady();
grpc_closure* closure = calld->original_recv_initial_metadata_ready_; grpc_closure* closure = calld->original_recv_initial_metadata_ready_;
calld->original_recv_initial_metadata_ready_ = nullptr; calld->original_recv_initial_metadata_ready_ = nullptr;
Closure::Run(DEBUG_LOCATION, closure, GRPC_ERROR_REF(error)); grpc_core::Closure::Run(DEBUG_LOCATION, closure, GRPC_ERROR_REF(error));
} }
void CallData::MaybeResumeOnRecvMessageReady() { void CallData::MaybeResumeOnRecvMessageReady() {
@ -192,19 +170,6 @@ void CallData::OnRecvMessageReady(void* arg, grpc_error* error) {
0) { 0) {
return calld->ContinueRecvMessageReadyCallback(GRPC_ERROR_NONE); return calld->ContinueRecvMessageReadyCallback(GRPC_ERROR_NONE);
} }
if (calld->max_recv_message_length_ >= 0 &&
(*calld->recv_message_)->length() >
static_cast<uint32_t>(calld->max_recv_message_length_)) {
std::string message_string = absl::StrFormat(
"Received message larger than max (%u vs. %d)",
(*calld->recv_message_)->length(), calld->max_recv_message_length_);
GPR_DEBUG_ASSERT(calld->error_ == GRPC_ERROR_NONE);
calld->error_ = grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_COPIED_STRING(message_string.c_str()),
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED);
return calld->ContinueRecvMessageReadyCallback(
GRPC_ERROR_REF(calld->error_));
}
grpc_slice_buffer_destroy_internal(&calld->recv_slices_); grpc_slice_buffer_destroy_internal(&calld->recv_slices_);
grpc_slice_buffer_init(&calld->recv_slices_); grpc_slice_buffer_init(&calld->recv_slices_);
return calld->ContinueReadingRecvMessage(); return calld->ContinueReadingRecvMessage();
@ -276,9 +241,9 @@ void CallData::FinishRecvMessage() {
// Initializing recv_replacement_stream_ with decompressed_slices removes // Initializing recv_replacement_stream_ with decompressed_slices removes
// all the slices from decompressed_slices leaving it empty. // all the slices from decompressed_slices leaving it empty.
new (&recv_replacement_stream_) new (&recv_replacement_stream_)
SliceBufferByteStream(&decompressed_slices, recv_flags); grpc_core::SliceBufferByteStream(&decompressed_slices, recv_flags);
recv_message_->reset( recv_message_->reset(reinterpret_cast<grpc_core::SliceBufferByteStream*>(
reinterpret_cast<SliceBufferByteStream*>(&recv_replacement_stream_)); &recv_replacement_stream_));
recv_message_ = nullptr; recv_message_ = nullptr;
} }
ContinueRecvMessageReadyCallback(GRPC_ERROR_REF(error_)); ContinueRecvMessageReadyCallback(GRPC_ERROR_REF(error_));
@ -289,7 +254,7 @@ void CallData::ContinueRecvMessageReadyCallback(grpc_error* error) {
// The surface will clean up the receiving stream if there is an error. // The surface will clean up the receiving stream if there is an error.
grpc_closure* closure = original_recv_message_ready_; grpc_closure* closure = original_recv_message_ready_;
original_recv_message_ready_ = nullptr; original_recv_message_ready_ = nullptr;
Closure::Run(DEBUG_LOCATION, closure, error); grpc_core::Closure::Run(DEBUG_LOCATION, closure, error);
} }
void CallData::MaybeResumeOnRecvTrailingMetadataReady() { void CallData::MaybeResumeOnRecvTrailingMetadataReady() {
@ -318,7 +283,7 @@ void CallData::OnRecvTrailingMetadataReady(void* arg, grpc_error* error) {
calld->error_ = GRPC_ERROR_NONE; calld->error_ = GRPC_ERROR_NONE;
grpc_closure* closure = calld->original_recv_trailing_metadata_ready_; grpc_closure* closure = calld->original_recv_trailing_metadata_ready_;
calld->original_recv_trailing_metadata_ready_ = nullptr; calld->original_recv_trailing_metadata_ready_ = nullptr;
Closure::Run(DEBUG_LOCATION, closure, error); grpc_core::Closure::Run(DEBUG_LOCATION, closure, error);
} }
void CallData::DecompressStartTransportStreamOpBatch( void CallData::DecompressStartTransportStreamOpBatch(
@ -357,44 +322,37 @@ void DecompressStartTransportStreamOpBatch(
calld->DecompressStartTransportStreamOpBatch(elem, batch); calld->DecompressStartTransportStreamOpBatch(elem, batch);
} }
grpc_error* DecompressInitCallElem(grpc_call_element* elem, static grpc_error* DecompressInitCallElem(grpc_call_element* elem,
const grpc_call_element_args* args) { const grpc_call_element_args* args) {
ChannelData* chand = static_cast<ChannelData*>(elem->channel_data); new (elem->call_data) CallData(*args);
new (elem->call_data) CallData(*args, chand);
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
void DecompressDestroyCallElem(grpc_call_element* elem, static void DecompressDestroyCallElem(
const grpc_call_final_info* /*final_info*/, grpc_call_element* elem, const grpc_call_final_info* /*final_info*/,
grpc_closure* /*ignored*/) { grpc_closure* /*ignored*/) {
CallData* calld = static_cast<CallData*>(elem->call_data); CallData* calld = static_cast<CallData*>(elem->call_data);
calld->~CallData(); calld->~CallData();
} }
grpc_error* DecompressInitChannelElem(grpc_channel_element* elem, static grpc_error* DecompressInitChannelElem(
grpc_channel_element_args* args) { grpc_channel_element* /*elem*/, grpc_channel_element_args* /*args*/) {
ChannelData* chand = static_cast<ChannelData*>(elem->channel_data);
new (chand) ChannelData(args);
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
void DecompressDestroyChannelElem(grpc_channel_element* elem) { void DecompressDestroyChannelElem(grpc_channel_element* /*elem*/) {}
ChannelData* chand = static_cast<ChannelData*>(elem->channel_data);
chand->~ChannelData();
}
} // namespace } // namespace
const grpc_channel_filter MessageDecompressFilter = { const grpc_channel_filter grpc_message_decompress_filter = {
DecompressStartTransportStreamOpBatch, DecompressStartTransportStreamOpBatch,
grpc_channel_next_op, grpc_channel_next_op,
sizeof(CallData), sizeof(CallData),
DecompressInitCallElem, DecompressInitCallElem,
grpc_call_stack_ignore_set_pollset_or_pollset_set, grpc_call_stack_ignore_set_pollset_or_pollset_set,
DecompressDestroyCallElem, DecompressDestroyCallElem,
sizeof(ChannelData), 0, // sizeof(ChannelData)
DecompressInitChannelElem, DecompressInitChannelElem,
DecompressDestroyChannelElem, DecompressDestroyChannelElem,
grpc_channel_next_get_info, grpc_channel_next_get_info,
"message_decompress"}; "message_decompress"};
} // namespace grpc_core

@ -23,9 +23,7 @@
#include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/channel_stack.h"
namespace grpc_core { extern const grpc_channel_filter grpc_message_decompress_filter;
extern const grpc_channel_filter MessageDecompressFilter;
} // namespace grpc_core
#endif /* GRPC_CORE_EXT_FILTERS_HTTP_MESSAGE_COMPRESS_MESSAGE_DECOMPRESS_FILTER_H \ #endif /* GRPC_CORE_EXT_FILTERS_HTTP_MESSAGE_COMPRESS_MESSAGE_DECOMPRESS_FILTER_H \
*/ */

@ -45,25 +45,6 @@ namespace {
size_t g_message_size_parser_index; size_t g_message_size_parser_index;
} // namespace } // namespace
//
// MessageSizeParsedConfig
//
const MessageSizeParsedConfig* MessageSizeParsedConfig::GetFromCallContext(
const grpc_call_context_element* context) {
if (context == nullptr) return nullptr;
auto* svc_cfg_call_data = static_cast<ServiceConfigCallData*>(
context[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value);
if (svc_cfg_call_data == nullptr) return nullptr;
return static_cast<const MessageSizeParsedConfig*>(
svc_cfg_call_data->GetMethodParsedConfig(
MessageSizeParser::ParserIndex()));
}
//
// MessageSizeParser
//
std::unique_ptr<ServiceConfigParser::ParsedConfig> std::unique_ptr<ServiceConfigParser::ParsedConfig>
MessageSizeParser::ParsePerMethodParams(const Json& json, grpc_error** error) { MessageSizeParser::ParsePerMethodParams(const Json& json, grpc_error** error) {
GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE); GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
@ -116,26 +97,12 @@ void MessageSizeParser::Register() {
} }
size_t MessageSizeParser::ParserIndex() { return g_message_size_parser_index; } size_t MessageSizeParser::ParserIndex() { return g_message_size_parser_index; }
int GetMaxRecvSizeFromChannelArgs(const grpc_channel_args* args) {
if (grpc_channel_args_want_minimal_stack(args)) return -1;
return grpc_channel_args_find_integer(
args, GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH,
{GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH, -1, INT_MAX});
}
int GetMaxSendSizeFromChannelArgs(const grpc_channel_args* args) {
if (grpc_channel_args_want_minimal_stack(args)) return -1;
return grpc_channel_args_find_integer(
args, GRPC_ARG_MAX_SEND_MESSAGE_LENGTH,
{GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH, -1, INT_MAX});
}
} // namespace grpc_core } // namespace grpc_core
namespace { namespace {
struct channel_data { struct channel_data {
grpc_core::MessageSizeParsedConfig::message_size_limits limits; grpc_core::MessageSizeParsedConfig::message_size_limits limits;
grpc_core::RefCountedPtr<grpc_core::ServiceConfig> svc_cfg;
}; };
struct call_data { struct call_data {
@ -151,8 +118,24 @@ struct call_data {
// Note: Per-method config is only available on the client, so we // Note: Per-method config is only available on the client, so we
// apply the max request size to the send limit and the max response // apply the max request size to the send limit and the max response
// size to the receive limit. // size to the receive limit.
const grpc_core::MessageSizeParsedConfig* limits = const grpc_core::MessageSizeParsedConfig* limits = nullptr;
grpc_core::MessageSizeParsedConfig::GetFromCallContext(args.context); grpc_core::ServiceConfigCallData* svc_cfg_call_data = nullptr;
if (args.context != nullptr) {
svc_cfg_call_data = static_cast<grpc_core::ServiceConfigCallData*>(
args.context[GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA].value);
}
if (svc_cfg_call_data != nullptr) {
limits = static_cast<const grpc_core::MessageSizeParsedConfig*>(
svc_cfg_call_data->GetMethodParsedConfig(
grpc_core::MessageSizeParser::ParserIndex()));
} else if (chand.svc_cfg != nullptr) {
const auto* objs_vector =
chand.svc_cfg->GetMethodParsedConfigVector(args.path);
if (objs_vector != nullptr) {
limits = static_cast<const grpc_core::MessageSizeParsedConfig*>(
(*objs_vector)[grpc_core::MessageSizeParser::ParserIndex()].get());
}
}
if (limits != nullptr) { if (limits != nullptr) {
if (limits->limits().max_send_size >= 0 && if (limits->limits().max_send_size >= 0 &&
(limits->limits().max_send_size < this->limits.max_send_size || (limits->limits().max_send_size < this->limits.max_send_size ||
@ -305,11 +288,35 @@ static void message_size_destroy_call_elem(
calld->~call_data(); calld->~call_data();
} }
static int default_size(const grpc_channel_args* args,
int without_minimal_stack) {
if (grpc_channel_args_want_minimal_stack(args)) {
return -1;
}
return without_minimal_stack;
}
grpc_core::MessageSizeParsedConfig::message_size_limits get_message_size_limits( grpc_core::MessageSizeParsedConfig::message_size_limits get_message_size_limits(
const grpc_channel_args* channel_args) { const grpc_channel_args* channel_args) {
grpc_core::MessageSizeParsedConfig::message_size_limits lim; grpc_core::MessageSizeParsedConfig::message_size_limits lim;
lim.max_send_size = grpc_core::GetMaxSendSizeFromChannelArgs(channel_args); lim.max_send_size =
lim.max_recv_size = grpc_core::GetMaxRecvSizeFromChannelArgs(channel_args); default_size(channel_args, GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH);
lim.max_recv_size =
default_size(channel_args, GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH);
for (size_t i = 0; i < channel_args->num_args; ++i) {
if (strcmp(channel_args->args[i].key, GRPC_ARG_MAX_SEND_MESSAGE_LENGTH) ==
0) {
const grpc_integer_options options = {lim.max_send_size, -1, INT_MAX};
lim.max_send_size =
grpc_channel_arg_get_integer(&channel_args->args[i], options);
}
if (strcmp(channel_args->args[i].key,
GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH) == 0) {
const grpc_integer_options options = {lim.max_recv_size, -1, INT_MAX};
lim.max_recv_size =
grpc_channel_arg_get_integer(&channel_args->args[i], options);
}
}
return lim; return lim;
} }
@ -320,6 +327,26 @@ static grpc_error* message_size_init_channel_elem(
channel_data* chand = static_cast<channel_data*>(elem->channel_data); channel_data* chand = static_cast<channel_data*>(elem->channel_data);
new (chand) channel_data(); new (chand) channel_data();
chand->limits = get_message_size_limits(args->channel_args); chand->limits = get_message_size_limits(args->channel_args);
// TODO(yashykt): We only need to read GRPC_ARG_SERVICE_CONFIG in the case of
// direct channels. (Service config is otherwise stored in the call_context by
// client_channel filter.) If we ever need a second filter that also needs to
// parse GRPC_ARG_SERVICE_CONFIG, we should refactor this code and add a
// separate filter that reads GRPC_ARG_SERVICE_CONFIG and saves the parsed
// config in the call_context.
const grpc_arg* channel_arg =
grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVICE_CONFIG);
const char* service_config_str = grpc_channel_arg_get_string(channel_arg);
if (service_config_str != nullptr) {
grpc_error* service_config_error = GRPC_ERROR_NONE;
auto svc_cfg = grpc_core::ServiceConfig::Create(service_config_str,
&service_config_error);
if (service_config_error == GRPC_ERROR_NONE) {
chand->svc_cfg = std::move(svc_cfg);
} else {
gpr_log(GPR_ERROR, "%s", grpc_error_string(service_config_error));
}
GRPC_ERROR_UNREF(service_config_error);
}
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
@ -360,9 +387,6 @@ static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder,
void* /*arg*/) { void* /*arg*/) {
const grpc_channel_args* channel_args = const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);
if (grpc_channel_args_want_minimal_stack(channel_args)) {
return true;
}
bool enable = false; bool enable = false;
grpc_core::MessageSizeParsedConfig::message_size_limits lim = grpc_core::MessageSizeParsedConfig::message_size_limits lim =
get_message_size_limits(channel_args); get_message_size_limits(channel_args);

@ -40,9 +40,6 @@ class MessageSizeParsedConfig : public ServiceConfigParser::ParsedConfig {
const message_size_limits& limits() const { return limits_; } const message_size_limits& limits() const { return limits_; }
static const MessageSizeParsedConfig* GetFromCallContext(
const grpc_call_context_element* context);
private: private:
message_size_limits limits_; message_size_limits limits_;
}; };
@ -57,9 +54,6 @@ class MessageSizeParser : public ServiceConfigParser::Parser {
static size_t ParserIndex(); static size_t ParserIndex();
}; };
int GetMaxRecvSizeFromChannelArgs(const grpc_channel_args* args);
int GetMaxSendSizeFromChannelArgs(const grpc_channel_args* args);
} // namespace grpc_core } // namespace grpc_core
#endif /* GRPC_CORE_EXT_FILTERS_MESSAGE_SIZE_MESSAGE_SIZE_FILTER_H */ #endif /* GRPC_CORE_EXT_FILTERS_MESSAGE_SIZE_MESSAGE_SIZE_FILTER_H */

@ -64,8 +64,6 @@ void grpc_max_age_filter_init(void);
void grpc_max_age_filter_shutdown(void); void grpc_max_age_filter_shutdown(void);
void grpc_message_size_filter_init(void); void grpc_message_size_filter_init(void);
void grpc_message_size_filter_shutdown(void); void grpc_message_size_filter_shutdown(void);
void grpc_service_config_channel_arg_filter_init(void);
void grpc_service_config_channel_arg_filter_shutdown(void);
void grpc_client_authority_filter_init(void); void grpc_client_authority_filter_init(void);
void grpc_client_authority_filter_shutdown(void); void grpc_client_authority_filter_shutdown(void);
void grpc_workaround_cronet_compression_filter_init(void); void grpc_workaround_cronet_compression_filter_init(void);
@ -116,8 +114,6 @@ void grpc_register_built_in_plugins(void) {
grpc_max_age_filter_shutdown); grpc_max_age_filter_shutdown);
grpc_register_plugin(grpc_message_size_filter_init, grpc_register_plugin(grpc_message_size_filter_init,
grpc_message_size_filter_shutdown); grpc_message_size_filter_shutdown);
grpc_register_plugin(grpc_service_config_channel_arg_filter_init,
grpc_service_config_channel_arg_filter_shutdown);
grpc_register_plugin(grpc_client_authority_filter_init, grpc_register_plugin(grpc_client_authority_filter_init,
grpc_client_authority_filter_shutdown); grpc_client_authority_filter_shutdown);
grpc_register_plugin(grpc_workaround_cronet_compression_filter_init, grpc_register_plugin(grpc_workaround_cronet_compression_filter_init,

@ -64,8 +64,6 @@ void grpc_max_age_filter_init(void);
void grpc_max_age_filter_shutdown(void); void grpc_max_age_filter_shutdown(void);
void grpc_message_size_filter_init(void); void grpc_message_size_filter_init(void);
void grpc_message_size_filter_shutdown(void); void grpc_message_size_filter_shutdown(void);
void grpc_service_config_channel_arg_filter_init(void);
void grpc_service_config_channel_arg_filter_shutdown(void);
void grpc_client_authority_filter_init(void); void grpc_client_authority_filter_init(void);
void grpc_client_authority_filter_shutdown(void); void grpc_client_authority_filter_shutdown(void);
void grpc_workaround_cronet_compression_filter_init(void); void grpc_workaround_cronet_compression_filter_init(void);
@ -116,8 +114,6 @@ void grpc_register_built_in_plugins(void) {
grpc_max_age_filter_shutdown); grpc_max_age_filter_shutdown);
grpc_register_plugin(grpc_message_size_filter_init, grpc_register_plugin(grpc_message_size_filter_init,
grpc_message_size_filter_shutdown); grpc_message_size_filter_shutdown);
grpc_register_plugin(grpc_service_config_channel_arg_filter_init,
grpc_service_config_channel_arg_filter_shutdown);
grpc_register_plugin(grpc_client_authority_filter_init, grpc_register_plugin(grpc_client_authority_filter_init,
grpc_client_authority_filter_shutdown); grpc_client_authority_filter_shutdown);
grpc_register_plugin(grpc_workaround_cronet_compression_filter_init, grpc_register_plugin(grpc_workaround_cronet_compression_filter_init,

@ -142,7 +142,7 @@ void ChannelArguments::SetUserAgentPrefix(
} }
void ChannelArguments::SetResourceQuota( void ChannelArguments::SetResourceQuota(
const grpc_impl::ResourceQuota& resource_quota) { const grpc::ResourceQuota& resource_quota) {
SetPointerWithVtable(GRPC_ARG_RESOURCE_QUOTA, SetPointerWithVtable(GRPC_ARG_RESOURCE_QUOTA,
resource_quota.c_resource_quota(), resource_quota.c_resource_quota(),
grpc_resource_quota_arg_vtable()); grpc_resource_quota_arg_vtable());

@ -19,7 +19,7 @@
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpcpp/resource_quota.h> #include <grpcpp/resource_quota.h>
namespace grpc_impl { namespace grpc {
ResourceQuota::ResourceQuota() : impl_(grpc_resource_quota_create(nullptr)) {} ResourceQuota::ResourceQuota() : impl_(grpc_resource_quota_create(nullptr)) {}
@ -37,4 +37,4 @@ ResourceQuota& ResourceQuota::SetMaxThreads(int new_max_threads) {
grpc_resource_quota_set_max_threads(impl_, new_max_threads); grpc_resource_quota_set_max_threads(impl_, new_max_threads);
return *this; return *this;
} }
} // namespace grpc_impl } // namespace grpc

@ -55,8 +55,9 @@ void RegisterOpenCensusPlugin() {
RpcServerReceivedMessagesPerRpc(); RpcServerReceivedMessagesPerRpc();
} }
::opencensus::trace::Span GetSpanFromServerContext(ServerContext* context) { ::opencensus::trace::Span GetSpanFromServerContext(
return reinterpret_cast<const CensusContext*>(context->census_context()) grpc::ServerContext* context) {
return reinterpret_cast<const grpc::CensusContext*>(context->census_context())
->Span(); ->Span();
} }
@ -127,5 +128,4 @@ ABSL_CONST_INIT const absl::string_view
ABSL_CONST_INIT const absl::string_view kRpcServerServerLatencyMeasureName = ABSL_CONST_INIT const absl::string_view kRpcServerServerLatencyMeasureName =
"grpc.io/server/server_latency"; "grpc.io/server/server_latency";
} // namespace grpc } // namespace grpc

@ -193,7 +193,7 @@ ServerBuilder& ServerBuilder::SetDefaultCompressionAlgorithm(
} }
ServerBuilder& ServerBuilder::SetResourceQuota( ServerBuilder& ServerBuilder::SetResourceQuota(
const grpc_impl::ResourceQuota& resource_quota) { const grpc::ResourceQuota& resource_quota) {
if (resource_quota_ != nullptr) { if (resource_quota_ != nullptr) {
grpc_resource_quota_unref(resource_quota_); grpc_resource_quota_unref(resource_quota_);
} }

@ -21,7 +21,7 @@ in 2020).
## Install the _grpc_ extension ## Install the _grpc_ extension
There are two ways to install the `grpc` extension. There are two ways to install the `grpc` extension.
* `pecl` * Via `pecl`
* Build from source * Build from source
### Install from PECL ### Install from PECL
@ -33,11 +33,11 @@ $ [sudo] pecl install grpc
or specific version or specific version
```sh ```sh
$ [sudo] pecl install grpc-1.25.0 $ [sudo] pecl install grpc-1.30.0
``` ```
Note: for users on CentOS/RHEL 6, unfortunately this step won’t work. Please make sure your `gcc` version satisfies the minimum requirement as
Please follow the instructions below to compile the PECL extension from source. specified [here](https://grpc.io/docs/languages/#official-support).
### Install on Windows ### Install on Windows
@ -47,7 +47,7 @@ You can download the pre-compiled `grpc.dll` extension from the PECL
### Build from source ### Build from source
Clone this repository at the [latest stable release tag](https://github.com/grpc/grpc/releases) Clone this repository at the [latest stable release tag](https://github.com/grpc/grpc/releases).
```sh ```sh
$ git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc $ git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc
@ -94,9 +94,9 @@ extension=grpc.so
In addition to the `grpc` extension, you will need to install the `grpc/grpc` In addition to the `grpc` extension, you will need to install the `grpc/grpc`
composer package as well. Add this to your project's `composer.json` file. composer package as well. Add this to your project's `composer.json` file.
``` ```json
"require": { "require": {
"grpc/grpc": "v1.25.0" "grpc/grpc": "~v1.30.0"
} }
``` ```
@ -127,32 +127,18 @@ the version of grpc inside package.xml file.
The compatibility between the grpc and protobuf version is listed as table The compatibility between the grpc and protobuf version is listed as table
below: below:
grpc | protobuf grpc | protobuf | grpc | protobuf | grpc | protobuf
--- | --- --- | --- | --- | --- | --- | ---
v1.0.0 | 3.0.0(GA) v1.0.0 | 3.0.0(GA) | v1.12.0 | 3.5.2 | v1.22.0 | 3.8.0
v1.0.1 | 3.0.2 v1.0.1 | 3.0.2 | v1.13.1 | 3.5.2 | v1.23.1 | 3.8.0
v1.1.0 | 3.1.0 v1.1.0 | 3.1.0 | v1.14.2 | 3.5.2 | v1.24.0 | 3.8.0
v1.2.0 | 3.2.0 v1.2.0 | 3.2.0 | v1.15.1 | 3.6.1 | v1.25.0 | 3.8.0
v1.2.0 | 3.2.0 v1.2.0 | 3.2.0 | v1.16.1 | 3.6.1 | v1.26.0 | 3.8.0
v1.3.4 | 3.3.0 v1.3.4 | 3.3.0 | v1.17.2 | 3.6.1 | v1.27.3 | 3.11.2
v1.3.5 | 3.2.0 v1.3.5 | 3.2.0 | v1.18.0 | 3.6.1 | v1.28.1 | 3.11.2
v1.4.0 | 3.3.0 v1.4.0 | 3.3.0 | v1.19.1 | 3.6.1 | v1.29.0 | 3.11.2
v1.6.0 | 3.4.0 v1.6.0 | 3.4.0 | v1.20.1 | 3.7.0 | v1.30.0 | 3.12.2
v1.8.0 | 3.5.0 v1.8.0 | 3.5.0 | v1.21.3 | 3.7.0
v1.12.0 | 3.5.2
v1.13.1 | 3.5.2
v1.14.2 | 3.5.2
v1.15.1 | 3.6.1
v1.16.1 | 3.6.1
v1.17.2 | 3.6.1
v1.18.0 | 3.6.1
v1.19.1 | 3.6.1
v1.20.1 | 3.7.0
v1.21.3 | 3.7.0
v1.22.0 | 3.8.0
v1.23.1 | 3.8.0
v1.24.0 | 3.8.0
v1.25.0 | 3.8.0
If `protoc` hasn't been installed, you can download the `protoc` binary from If `protoc` hasn't been installed, you can download the `protoc` binary from
the protocol buffers the protocol buffers
@ -190,6 +176,18 @@ $ git submodule update --init
$ make grpc_php_plugin $ make grpc_php_plugin
``` ```
Alternatively, you can also build the `grpc_php_plugin` with `bazel` now:
```sh
$ bazel build @com_google_protobuf//:protoc
$ bazel build src/compiler:grpc_php_plugin
```
The `protoc` binary will be found in
`bazel-bin/external/com_google_protobuf/protoc`.
The `grpc_php_plugin` binary will be found in
`bazel-bin/src/compiler/grpc_php_plugin`.
Plugin may use the new feature of the new protobuf version, thus please also Plugin may use the new feature of the new protobuf version, thus please also
make sure that the protobuf version installed is compatible with the grpc make sure that the protobuf version installed is compatible with the grpc
version you build this plugin. version you build this plugin.
@ -210,7 +208,7 @@ $ [sudo] pecl install protobuf
or specific version or specific version
``` sh ``` sh
$ [sudo] pecl install protobuf-3.8.0 $ [sudo] pecl install protobuf-3.12.2
``` ```
And add this to your `php.ini` file: And add this to your `php.ini` file:
@ -224,9 +222,9 @@ extension=protobuf.so
Or require the `google/protobuf` composer package. Add this to your Or require the `google/protobuf` composer package. Add this to your
`composer.json` file: `composer.json` file:
``` ```json
"require": { "require": {
"google/protobuf": "^v3.8.0" "google/protobuf": "~v3.12.2"
} }
``` ```
@ -280,8 +278,8 @@ by the `./bin/generate_proto_php.sh` script.
### Run test server ### Run test server
Run a local server serving the math services. Please see [Node][] for how to Run a local server serving the `Math`
run an example server. [service](https://github.com/grpc/grpc/blob/master/src/proto/math/math.proto#L42).
```sh ```sh
$ cd grpc/src/php/tests/generated_code $ cd grpc/src/php/tests/generated_code
@ -312,7 +310,7 @@ end-to-end example.
Here's how you can specify SSL credentials when creating your PHP client: Here's how you can specify SSL credentials when creating your PHP client:
``` ```php
$client = new Helloworld\GreeterClient('localhost:50051', [ $client = new Helloworld\GreeterClient('localhost:50051', [
'credentials' => Grpc\ChannelCredentials::createSsl( 'credentials' => Grpc\ChannelCredentials::createSsl(
file_get_contents('<path to certificate>')) file_get_contents('<path to certificate>'))
@ -337,16 +335,27 @@ all possible values of the `grpc.grpc.trace` option, please check
``` ```
grpc.grpc_verbosity=debug grpc.grpc_verbosity=debug
grpc.grpc_trace=all,-timer_check grpc.grpc_trace=all,-polling,-polling_api,-pollable_refcount,-timer,-timer_check
grpc.log_filename=/var/log/grpc.log grpc.log_filename=/var/log/grpc.log
``` ```
> Make sure the log file above is writable, by doing the following:
> ```
> $ sudo touch /var/log/grpc.log
> $ sudo chmod 666 /var/log/grpc.log
> ```
> Note: The log file does grow pretty quickly depending on how much logs are
> being printed out. Make sure you have other mechanisms (perhaps another
> cronjob) to zero out the log file from time to time,
> e.g. `cp /dev/null /var/log/grpc.log`, or turn these off when logs or tracing
> are not necessary for debugging purposes.
### User agent string ### User agent string
You can customize the user agent string for your gRPC PHP client by specifying You can customize the user agent string for your gRPC PHP client by specifying
this `grpc.primary_user_agent` option when constructing your PHP client: this `grpc.primary_user_agent` option when constructing your PHP client:
``` ```php
$client = new Helloworld\GreeterClient('localhost:50051', [ $client = new Helloworld\GreeterClient('localhost:50051', [
'credentials' => Grpc\ChannelCredentials::createInsecure(), 'credentials' => Grpc\ChannelCredentials::createInsecure(),
'grpc.primary_user_agent' => 'my-user-agent-identifier', 'grpc.primary_user_agent' => 'my-user-agent-identifier',
@ -358,7 +367,7 @@ $client = new Helloworld\GreeterClient('localhost:50051', [
To change the default maximum message size, specify this To change the default maximum message size, specify this
`grpc.max_receive_message_length` option when constructing your PHP client: `grpc.max_receive_message_length` option when constructing your PHP client:
``` ```php
$client = new Helloworld\GreeterClient('localhost:50051', [ $client = new Helloworld\GreeterClient('localhost:50051', [
'credentials' => Grpc\ChannelCredentials::createInsecure(), 'credentials' => Grpc\ChannelCredentials::createInsecure(),
'grpc.max_receive_message_length' => 8*1024*1024, 'grpc.max_receive_message_length' => 8*1024*1024,
@ -369,26 +378,28 @@ $client = new Helloworld\GreeterClient('localhost:50051', [
You can customize the compression behavior on the client side, by specifying the following options when constructing your PHP client. You can customize the compression behavior on the client side, by specifying the following options when constructing your PHP client.
``` ```php
Possible values for grpc.default_compression_algorithm:
0 - No compression
1 - Compress with DEFLATE algorithm
2 - Compress with GZIP algorithm
3 - Stream compression with GZIP algorithm
```
```
Possible values for grpc.default_compression_level:
0 - None
1 - Low level
2 - Medium level
3 - High level
```
Here's an example on how you can put them all together:
```
$client = new Helloworld\GreeterClient('localhost:50051', [ $client = new Helloworld\GreeterClient('localhost:50051', [
'credentials' => Grpc\ChannelCredentials::createInsecure(), 'credentials' => Grpc\ChannelCredentials::createInsecure(),
'grpc.default_compression_algorithm' => 2, 'grpc.default_compression_algorithm' => 2,
'grpc.default_compression_level' => 2, 'grpc.default_compression_level' => 2,
]); ]);
```
Possible values for `grpc.default_compression_algorithm`:
[Node]:https://github.com/grpc/grpc/tree/master/src/node/examples ```
0: No compression
1: Compress with DEFLATE algorithm
2: Compress with GZIP algorithm
3: Stream compression with GZIP algorithm
```
Possible values for `grpc.default_compression_level`:
```
0: None
1: Low level
2: Medium level
3: High level
```

@ -16,6 +16,11 @@
* *
*/ */
/**
* class Call
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc/call.c
*/
#include "call.h" #include "call.h"
#include <ext/spl/spl_exceptions.h> #include <ext/spl/spl_exceptions.h>
@ -193,7 +198,7 @@ zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC) {
* Must not be closed. * Must not be closed.
* @param string $method The method to call * @param string $method The method to call
* @param Timeval $deadline_obj The deadline for completing the call * @param Timeval $deadline_obj The deadline for completing the call
* @param string $host_override The host is set by user (optional) * @param string $host_override = "" The host is set by user (optional)
*/ */
PHP_METHOD(Call, __construct) { PHP_METHOD(Call, __construct) {
zval *channel_obj; zval *channel_obj;

@ -16,6 +16,11 @@
* *
*/ */
/**
* class CallCredentials
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc/call_credentials.c
*/
#include "call_credentials.h" #include "call_credentials.h"
#include <ext/spl/spl_exceptions.h> #include <ext/spl/spl_exceptions.h>

@ -16,6 +16,11 @@
* *
*/ */
/**
* class Channel
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc/channel.c
*/
#include "channel.h" #include "channel.h"
#include <ext/standard/php_var.h> #include <ext/standard/php_var.h>

@ -16,6 +16,11 @@
* *
*/ */
/**
* class ChannelCredentials
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc/channel_credentials.c
*/
#include "channel_credentials.h" #include "channel_credentials.h"
#include <ext/standard/sha1.h> #include <ext/standard/sha1.h>
@ -134,10 +139,10 @@ PHP_METHOD(ChannelCredentials, createDefault) {
/** /**
* Create SSL credentials. * Create SSL credentials.
* @param string $pem_root_certs PEM encoding of the server root certificates * @param string $pem_root_certs = "" PEM encoding of the server root certificates (optional)
* @param string $pem_key_cert_pair.private_key PEM encoding of the client's * @param string $private_key = "" PEM encoding of the client's
* private key (optional) * private key (optional)
* @param string $pem_key_cert_pair.cert_chain PEM encoding of the client's * @param string $cert_chain = "" PEM encoding of the client's
* certificate chain (optional) * certificate chain (optional)
* @return ChannelCredentials The new SSL credentials object * @return ChannelCredentials The new SSL credentials object
*/ */

@ -16,6 +16,11 @@
* *
*/ */
/**
* class Server
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc/server.c
*/
#include "server.h" #include "server.h"
#include <ext/spl/spl_exceptions.h> #include <ext/spl/spl_exceptions.h>

@ -16,6 +16,11 @@
* *
*/ */
/**
* class ServerCredentials
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc/server_credentials.c
*/
#include "server_credentials.h" #include "server_credentials.h"
#include <ext/spl/spl_exceptions.h> #include <ext/spl/spl_exceptions.h>
@ -56,9 +61,9 @@ zval *grpc_php_wrap_server_credentials(grpc_server_credentials
/** /**
* Create SSL credentials. * Create SSL credentials.
* @param string pem_root_certs PEM encoding of the server root certificates * @param string $pem_root_certs PEM encoding of the server root certificates
* @param string pem_private_key PEM encoding of the client's private key * @param string $pem_private_key PEM encoding of the client's private key
* @param string pem_cert_chain PEM encoding of the client's certificate chain * @param string $pem_cert_chain PEM encoding of the client's certificate chain
* @return Credentials The new SSL credentials object * @return Credentials The new SSL credentials object
*/ */
PHP_METHOD(ServerCredentials, createSsl) { PHP_METHOD(ServerCredentials, createSsl) {

@ -16,6 +16,11 @@
* *
*/ */
/**
* class Timeval
* @see https://github.com/grpc/grpc/tree/master/src/php/ext/grpc/timeval.c
*/
#include "timeval.h" #include "timeval.h"
#include <ext/spl/spl_exceptions.h> #include <ext/spl/spl_exceptions.h>

@ -213,6 +213,43 @@ cdef class _ServicerContext:
def disable_next_message_compression(self): def disable_next_message_compression(self):
self._rpc_state.disable_next_compression = True self._rpc_state.disable_next_compression = True
def peer(self):
cdef char *c_peer = NULL
c_peer = grpc_call_get_peer(self._rpc_state.call)
peer = (<bytes>c_peer).decode('utf8')
gpr_free(c_peer)
return peer
def peer_identities(self):
cdef Call query_call = Call()
query_call.c_call = self._rpc_state.call
identities = peer_identities(query_call)
query_call.c_call = NULL
return identities
def peer_identity_key(self):
cdef Call query_call = Call()
query_call.c_call = self._rpc_state.call
identity_key = peer_identity_key(query_call)
query_call.c_call = NULL
if identity_key:
return identity_key.decode('utf8')
else:
return None
def auth_context(self):
cdef Call query_call = Call()
query_call.c_call = self._rpc_state.call
bytes_ctx = auth_context(query_call)
query_call.c_call = NULL
if bytes_ctx:
ctx = {}
for key in bytes_ctx:
ctx[key.decode('utf8')] = bytes_ctx[key]
return ctx
else:
return {}
cdef class _SyncServicerContext: cdef class _SyncServicerContext:
"""Sync servicer context for sync handler compatibility.""" """Sync servicer context for sync handler compatibility."""
@ -260,6 +297,18 @@ cdef class _SyncServicerContext:
def add_callback(self, object callback): def add_callback(self, object callback):
self._callbacks.append(callback) self._callbacks.append(callback)
def peer(self):
return self._context.peer()
def peer_identities(self):
return self._context.peer_identities()
def peer_identity_key(self):
return self._context.peer_identity_key()
def auth_context(self):
return self._context.auth_context()
async def _run_interceptor(object interceptors, object query_handler, async def _run_interceptor(object interceptors, object query_handler,
object handler_call_details): object handler_call_details):

@ -14,7 +14,7 @@
"""Abstract base classes for server-side classes.""" """Abstract base classes for server-side classes."""
import abc import abc
from typing import Generic, Optional, Sequence from typing import Generic, Mapping, Optional, Iterable, Sequence
import grpc import grpc
@ -251,3 +251,44 @@ class ServicerContext(Generic[RequestType, ResponseType], abc.ABC):
This method will override any compression configuration set during This method will override any compression configuration set during
server creation or set on the call. server creation or set on the call.
""" """
@abc.abstractmethod
def peer(self) -> str:
"""Identifies the peer that invoked the RPC being serviced.
Returns:
A string identifying the peer that invoked the RPC being serviced.
The string format is determined by gRPC runtime.
"""
@abc.abstractmethod
def peer_identities(self) -> Optional[Iterable[bytes]]:
"""Gets one or more peer identity(s).
Equivalent to
servicer_context.auth_context().get(servicer_context.peer_identity_key())
Returns:
An iterable of the identities, or None if the call is not
authenticated. Each identity is returned as a raw bytes type.
"""
@abc.abstractmethod
def peer_identity_key(self) -> Optional[str]:
"""The auth property used to identify the peer.
For example, "x509_common_name" or "x509_subject_alternative_name" are
used to identify an SSL peer.
Returns:
The auth property (string) that indicates the
peer identity, or None if the call is not authenticated.
"""
@abc.abstractmethod
def auth_context(self) -> Mapping[str, Iterable[bytes]]:
"""Gets the auth context for the call.
Returns:
A map of strings to an iterable of bytes for each auth property.
"""

@ -71,7 +71,6 @@ CORE_SOURCE_FILES = [
'src/core/ext/filters/client_channel/retry_throttle.cc', 'src/core/ext/filters/client_channel/retry_throttle.cc',
'src/core/ext/filters/client_channel/server_address.cc', 'src/core/ext/filters/client_channel/server_address.cc',
'src/core/ext/filters/client_channel/service_config.cc', 'src/core/ext/filters/client_channel/service_config.cc',
'src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc',
'src/core/ext/filters/client_channel/service_config_parser.cc', 'src/core/ext/filters/client_channel/service_config_parser.cc',
'src/core/ext/filters/client_channel/subchannel.cc', 'src/core/ext/filters/client_channel/subchannel.cc',
'src/core/ext/filters/client_channel/subchannel_pool_interface.cc', 'src/core/ext/filters/client_channel/subchannel_pool_interface.cc',

@ -9,6 +9,7 @@
"unit._metadata_test.TestTypeMetadata", "unit._metadata_test.TestTypeMetadata",
"unit.abort_test.TestAbort", "unit.abort_test.TestAbort",
"unit.aio_rpc_error_test.TestAioRpcError", "unit.aio_rpc_error_test.TestAioRpcError",
"unit.auth_context_test.TestAuthContext",
"unit.call_test.TestStreamStreamCall", "unit.call_test.TestStreamStreamCall",
"unit.call_test.TestStreamUnaryCall", "unit.call_test.TestStreamUnaryCall",
"unit.call_test.TestUnaryStreamCall", "unit.call_test.TestUnaryStreamCall",
@ -25,6 +26,7 @@
"unit.compatibility_test.TestCompatibility", "unit.compatibility_test.TestCompatibility",
"unit.compression_test.TestCompression", "unit.compression_test.TestCompression",
"unit.connectivity_test.TestConnectivityState", "unit.connectivity_test.TestConnectivityState",
"unit.context_peer_test.TestContextPeer",
"unit.done_callback_test.TestDoneCallback", "unit.done_callback_test.TestDoneCallback",
"unit.init_test.TestChannel", "unit.init_test.TestChannel",
"unit.metadata_test.TestMetadata", "unit.metadata_test.TestMetadata",

@ -0,0 +1,194 @@
# Copyright 2020 The 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.
"""Porting auth context tests from sync stack."""
import pickle
import unittest
import logging
import grpc
from grpc.experimental import aio
from grpc.experimental import session_cache
import six
from tests.unit import resources
from tests_aio.unit._test_base import AioTestBase
_REQUEST = b'\x00\x00\x00'
_RESPONSE = b'\x00\x00\x00'
_UNARY_UNARY = '/test/UnaryUnary'
_SERVER_HOST_OVERRIDE = 'foo.test.google.fr'
_CLIENT_IDS = (
b'*.test.google.fr',
b'waterzooi.test.google.be',
b'*.test.youtube.com',
b'192.168.1.3',
)
_ID = 'id'
_ID_KEY = 'id_key'
_AUTH_CTX = 'auth_ctx'
_PRIVATE_KEY = resources.private_key()
_CERTIFICATE_CHAIN = resources.certificate_chain()
_TEST_ROOT_CERTIFICATES = resources.test_root_certificates()
_SERVER_CERTS = ((_PRIVATE_KEY, _CERTIFICATE_CHAIN),)
_PROPERTY_OPTIONS = ((
'grpc.ssl_target_name_override',
_SERVER_HOST_OVERRIDE,
),)
async def handle_unary_unary(unused_request: bytes,
servicer_context: aio.ServicerContext):
return pickle.dumps({
_ID: servicer_context.peer_identities(),
_ID_KEY: servicer_context.peer_identity_key(),
_AUTH_CTX: servicer_context.auth_context()
})
class TestAuthContext(AioTestBase):
async def test_insecure(self):
handler = grpc.method_handlers_generic_handler('test', {
'UnaryUnary':
grpc.unary_unary_rpc_method_handler(handle_unary_unary)
})
server = aio.server()
server.add_generic_rpc_handlers((handler,))
port = server.add_insecure_port('[::]:0')
await server.start()
async with aio.insecure_channel('localhost:%d' % port) as channel:
response = await channel.unary_unary(_UNARY_UNARY)(_REQUEST)
await server.stop(None)
auth_data = pickle.loads(response)
self.assertIsNone(auth_data[_ID])
self.assertIsNone(auth_data[_ID_KEY])
self.assertDictEqual({}, auth_data[_AUTH_CTX])
async def test_secure_no_cert(self):
handler = grpc.method_handlers_generic_handler('test', {
'UnaryUnary':
grpc.unary_unary_rpc_method_handler(handle_unary_unary)
})
server = aio.server()
server.add_generic_rpc_handlers((handler,))
server_cred = grpc.ssl_server_credentials(_SERVER_CERTS)
port = server.add_secure_port('[::]:0', server_cred)
await server.start()
channel_creds = grpc.ssl_channel_credentials(
root_certificates=_TEST_ROOT_CERTIFICATES)
channel = aio.secure_channel('localhost:{}'.format(port),
channel_creds,
options=_PROPERTY_OPTIONS)
response = await channel.unary_unary(_UNARY_UNARY)(_REQUEST)
await channel.close()
await server.stop(None)
auth_data = pickle.loads(response)
self.assertIsNone(auth_data[_ID])
self.assertIsNone(auth_data[_ID_KEY])
self.assertDictEqual(
{
'security_level': [b'TSI_PRIVACY_AND_INTEGRITY'],
'transport_security_type': [b'ssl'],
'ssl_session_reused': [b'false'],
}, auth_data[_AUTH_CTX])
async def test_secure_client_cert(self):
handler = grpc.method_handlers_generic_handler('test', {
'UnaryUnary':
grpc.unary_unary_rpc_method_handler(handle_unary_unary)
})
server = aio.server()
server.add_generic_rpc_handlers((handler,))
server_cred = grpc.ssl_server_credentials(
_SERVER_CERTS,
root_certificates=_TEST_ROOT_CERTIFICATES,
require_client_auth=True)
port = server.add_secure_port('[::]:0', server_cred)
await server.start()
channel_creds = grpc.ssl_channel_credentials(
root_certificates=_TEST_ROOT_CERTIFICATES,
private_key=_PRIVATE_KEY,
certificate_chain=_CERTIFICATE_CHAIN)
channel = aio.secure_channel('localhost:{}'.format(port),
channel_creds,
options=_PROPERTY_OPTIONS)
response = await channel.unary_unary(_UNARY_UNARY)(_REQUEST)
await channel.close()
await server.stop(None)
auth_data = pickle.loads(response)
auth_ctx = auth_data[_AUTH_CTX]
self.assertCountEqual(_CLIENT_IDS, auth_data[_ID])
self.assertEqual('x509_subject_alternative_name', auth_data[_ID_KEY])
self.assertSequenceEqual([b'ssl'], auth_ctx['transport_security_type'])
self.assertSequenceEqual([b'*.test.google.com'],
auth_ctx['x509_common_name'])
async def _do_one_shot_client_rpc(self, channel_creds, channel_options,
port, expect_ssl_session_reused):
channel = aio.secure_channel('localhost:{}'.format(port),
channel_creds,
options=channel_options)
response = await channel.unary_unary(_UNARY_UNARY)(_REQUEST)
auth_data = pickle.loads(response)
self.assertEqual(expect_ssl_session_reused,
auth_data[_AUTH_CTX]['ssl_session_reused'])
await channel.close()
async def test_session_resumption(self):
# Set up a secure server
handler = grpc.method_handlers_generic_handler('test', {
'UnaryUnary':
grpc.unary_unary_rpc_method_handler(handle_unary_unary)
})
server = aio.server()
server.add_generic_rpc_handlers((handler,))
server_cred = grpc.ssl_server_credentials(_SERVER_CERTS)
port = server.add_secure_port('[::]:0', server_cred)
await server.start()
# Create a cache for TLS session tickets
cache = session_cache.ssl_session_cache_lru(1)
channel_creds = grpc.ssl_channel_credentials(
root_certificates=_TEST_ROOT_CERTIFICATES)
channel_options = _PROPERTY_OPTIONS + (
('grpc.ssl_session_cache', cache),)
# Initial connection has no session to resume
await self._do_one_shot_client_rpc(channel_creds,
channel_options,
port,
expect_ssl_session_reused=[b'false'])
# Subsequent connections resume sessions
await self._do_one_shot_client_rpc(channel_creds,
channel_options,
port,
expect_ssl_session_reused=[b'true'])
await server.stop(None)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
unittest.main()

@ -0,0 +1,65 @@
# Copyright 2020 The 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.
"""Testing the server context ability to access peer info."""
import asyncio
import logging
import os
import unittest
from typing import Callable, Iterable, Sequence, Tuple
import grpc
from grpc.experimental import aio
from src.proto.grpc.testing import messages_pb2, test_pb2_grpc
from tests.unit.framework.common import test_constants
from tests_aio.unit import _common
from tests_aio.unit._test_base import AioTestBase
from tests_aio.unit._test_server import TestServiceServicer, start_test_server
_REQUEST = b'\x03\x07'
_TEST_METHOD = '/test/UnaryUnary'
class TestContextPeer(AioTestBase):
async def test_peer(self):
@grpc.unary_unary_rpc_method_handler
async def check_peer_unary_unary(request: bytes,
context: aio.ServicerContext):
self.assertEqual(_REQUEST, request)
# The peer address could be ipv4 or ipv6
self.assertIn('ip', context.peer())
return request
# Creates a server
server = aio.server()
handlers = grpc.method_handlers_generic_handler(
'test', {'UnaryUnary': check_peer_unary_unary})
server.add_generic_rpc_handlers((handlers,))
port = server.add_insecure_port('[::]:0')
await server.start()
# Creates a channel
async with aio.insecure_channel('localhost:%d' % port) as channel:
response = await channel.unary_unary(_TEST_METHOD)(_REQUEST)
self.assertEqual(_REQUEST, response)
await server.stop(None)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
unittest.main(verbosity=2)

@ -29,7 +29,6 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/metadata.h"
#include "test/core/end2end/cq_verifier.h" #include "test/core/end2end/cq_verifier.h"
@ -467,328 +466,6 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config,
grpc_byte_buffer_destroy(response_payload); grpc_byte_buffer_destroy(response_payload);
grpc_byte_buffer_destroy(recv_payload); grpc_byte_buffer_destroy(recv_payload);
grpc_call_unref(c);
if (s != nullptr) grpc_call_unref(s);
cq_verifier_destroy(cqv);
end_test(&f);
config.tear_down_data(&f);
}
static grpc_metadata gzip_compression_override() {
grpc_metadata gzip_compression_override;
gzip_compression_override.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST;
gzip_compression_override.value = grpc_slice_from_static_string("gzip");
memset(&gzip_compression_override.internal_data, 0,
sizeof(gzip_compression_override.internal_data));
return gzip_compression_override;
}
// Test receive message limit with compressed request larger than the limit
static void test_max_receive_message_length_on_compressed_request(
grpc_end2end_test_config config, bool minimal_stack) {
gpr_log(GPR_INFO,
"test max receive message length on compressed request with "
"minimal_stack=%d",
minimal_stack);
grpc_end2end_test_fixture f;
grpc_call* c = nullptr;
grpc_call* s = nullptr;
cq_verifier* cqv;
grpc_op ops[6];
grpc_op* op;
grpc_slice request_payload_slice = grpc_slice_malloc(1024);
memset(GRPC_SLICE_START_PTR(request_payload_slice), 'a', 1024);
grpc_byte_buffer* request_payload =
grpc_raw_byte_buffer_create(&request_payload_slice, 1);
grpc_byte_buffer* recv_payload = nullptr;
grpc_metadata_array initial_metadata_recv;
grpc_metadata_array trailing_metadata_recv;
grpc_metadata_array request_metadata_recv;
grpc_call_details call_details;
grpc_status_code status;
grpc_call_error error;
grpc_slice details, status_details;
int was_cancelled = 2;
// Set limit via channel args.
grpc_arg arg[2];
arg[0] = grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH), 5);
arg[1] = grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_MINIMAL_STACK), minimal_stack);
grpc_channel_args* server_args =
grpc_channel_args_copy_and_add(nullptr, arg, 2);
f = begin_test(config, "test_max_request_message_length", nullptr,
server_args);
{
grpc_core::ExecCtx exec_ctx;
grpc_channel_args_destroy(server_args);
}
cqv = cq_verifier_create(f.cq);
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/service/method"),
nullptr, gpr_inf_future(GPR_CLOCK_REALTIME),
nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
grpc_metadata_array_init(&trailing_metadata_recv);
grpc_metadata_array_init(&request_metadata_recv);
grpc_call_details_init(&call_details);
grpc_metadata compression_md = gzip_compression_override();
memset(ops, 0, sizeof(ops));
op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 1;
op->data.send_initial_metadata.metadata = &compression_md;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_SEND_MESSAGE;
op->data.send_message.send_message = request_payload;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_RECV_INITIAL_METADATA;
op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
op->data.recv_status_on_client.status = &status;
op->data.recv_status_on_client.status_details = &details;
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
cq_verify(cqv);
memset(ops, 0, sizeof(ops));
op = ops;
op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
op->data.recv_close_on_server.cancelled = &was_cancelled;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_RECV_MESSAGE;
op->data.recv_message.recv_message = &recv_payload;
op->flags = 0;
op->reserved = nullptr;
op++;
if (minimal_stack) {
/* Expect the RPC to proceed normally for a minimal stack */
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 0;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
op->data.send_status_from_server.trailing_metadata_count = 0;
op->data.send_status_from_server.status = GRPC_STATUS_OK;
status_details = grpc_slice_from_static_string("xyz");
op->data.send_status_from_server.status_details = &status_details;
op->flags = 0;
op->reserved = nullptr;
op++;
}
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
CQ_EXPECT_COMPLETION(cqv, tag(102), 1);
CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);
GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/service/method"));
if (minimal_stack) {
/* We do not perform message size checks for minimal stack. */
GPR_ASSERT(status == GRPC_STATUS_OK);
} else {
GPR_ASSERT(was_cancelled == 1);
GPR_ASSERT(status == GRPC_STATUS_RESOURCE_EXHAUSTED);
GPR_ASSERT(grpc_slice_str_cmp(
details, "Received message larger than max (29 vs. 5)") ==
0);
}
grpc_slice_unref(details);
grpc_slice_unref(request_payload_slice);
grpc_metadata_array_destroy(&initial_metadata_recv);
grpc_metadata_array_destroy(&trailing_metadata_recv);
grpc_metadata_array_destroy(&request_metadata_recv);
grpc_call_details_destroy(&call_details);
grpc_byte_buffer_destroy(request_payload);
grpc_byte_buffer_destroy(recv_payload);
grpc_call_unref(c);
if (s != nullptr) grpc_call_unref(s);
cq_verifier_destroy(cqv);
end_test(&f);
config.tear_down_data(&f);
}
// Test receive message limit with compressed response larger than the limit.
static void test_max_receive_message_length_on_compressed_response(
grpc_end2end_test_config config, bool minimal_stack) {
gpr_log(GPR_INFO,
"testing max receive message length on compressed response with "
"minimal_stack=%d",
minimal_stack);
grpc_end2end_test_fixture f;
grpc_call* c = nullptr;
grpc_call* s = nullptr;
cq_verifier* cqv;
grpc_op ops[6];
grpc_op* op;
grpc_slice response_payload_slice = grpc_slice_malloc(1024);
memset(GRPC_SLICE_START_PTR(response_payload_slice), 'a', 1024);
grpc_byte_buffer* response_payload =
grpc_raw_byte_buffer_create(&response_payload_slice, 1);
grpc_byte_buffer* recv_payload = nullptr;
grpc_metadata_array initial_metadata_recv;
grpc_metadata_array trailing_metadata_recv;
grpc_metadata_array request_metadata_recv;
grpc_call_details call_details;
grpc_status_code status;
grpc_call_error error;
grpc_slice details;
int was_cancelled = 2;
// Set limit via channel args.
grpc_arg arg[2];
arg[0] = grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH), 5);
arg[1] = grpc_channel_arg_integer_create(
const_cast<char*>(GRPC_ARG_MINIMAL_STACK), minimal_stack);
grpc_channel_args* client_args =
grpc_channel_args_copy_and_add(nullptr, arg, 2);
f = begin_test(config, "test_max_response_message_length", client_args,
nullptr);
{
grpc_core::ExecCtx exec_ctx;
grpc_channel_args_destroy(client_args);
}
cqv = cq_verifier_create(f.cq);
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq,
grpc_slice_from_static_string("/service/method"),
nullptr, gpr_inf_future(GPR_CLOCK_REALTIME),
nullptr);
GPR_ASSERT(c);
grpc_metadata_array_init(&initial_metadata_recv);
grpc_metadata_array_init(&trailing_metadata_recv);
grpc_metadata_array_init(&request_metadata_recv);
grpc_call_details_init(&call_details);
memset(ops, 0, sizeof(ops));
op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 0;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_RECV_INITIAL_METADATA;
op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_RECV_MESSAGE;
op->data.recv_message.recv_message = &recv_payload;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
op->data.recv_status_on_client.status = &status;
op->data.recv_status_on_client.status_details = &details;
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1),
nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
grpc_server_request_call(f.server, &s, &call_details,
&request_metadata_recv, f.cq, f.cq, tag(101));
GPR_ASSERT(GRPC_CALL_OK == error);
CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
cq_verify(cqv);
grpc_metadata compression_md = gzip_compression_override();
memset(ops, 0, sizeof(ops));
op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 1;
op->data.send_initial_metadata.metadata = &compression_md;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
op->data.recv_close_on_server.cancelled = &was_cancelled;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_SEND_MESSAGE;
op->data.send_message.send_message = response_payload;
op->flags = 0;
op->reserved = nullptr;
op++;
op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
op->data.send_status_from_server.trailing_metadata_count = 0;
op->data.send_status_from_server.status = GRPC_STATUS_OK;
grpc_slice status_details = grpc_slice_from_static_string("xyz");
op->data.send_status_from_server.status_details = &status_details;
op->flags = 0;
op->reserved = nullptr;
op++;
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102),
nullptr);
GPR_ASSERT(GRPC_CALL_OK == error);
CQ_EXPECT_COMPLETION(cqv, tag(102), 1);
CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);
GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/service/method"));
if (minimal_stack) {
/* We do not perform message size checks for minimal stack. */
GPR_ASSERT(status == GRPC_STATUS_OK);
} else {
GPR_ASSERT(status == GRPC_STATUS_RESOURCE_EXHAUSTED);
GPR_ASSERT(grpc_slice_str_cmp(
details, "Received message larger than max (29 vs. 5)") ==
0);
}
grpc_slice_unref(details);
grpc_slice_unref(response_payload_slice);
grpc_metadata_array_destroy(&initial_metadata_recv);
grpc_metadata_array_destroy(&trailing_metadata_recv);
grpc_metadata_array_destroy(&request_metadata_recv);
grpc_call_details_destroy(&call_details);
grpc_byte_buffer_destroy(response_payload);
grpc_byte_buffer_destroy(recv_payload);
grpc_call_unref(c); grpc_call_unref(c);
if (s != nullptr) grpc_call_unref(s); if (s != nullptr) grpc_call_unref(s);
@ -823,15 +500,6 @@ void max_message_length(grpc_end2end_test_config config) {
test_max_message_length_on_response(config, false /* send_limit */, test_max_message_length_on_response(config, false /* send_limit */,
true /* use_service_config */, true /* use_service_config */,
true /* use_string_json_value */); true /* use_string_json_value */);
/* The following tests are not useful for inproc transport and do not work
* with our simple proxy. */
if (strcmp(config.name, "inproc") != 0 &&
(config.feature_mask & FEATURE_MASK_SUPPORTS_REQUEST_PROXYING) == 0) {
test_max_receive_message_length_on_compressed_request(config, false);
test_max_receive_message_length_on_compressed_request(config, true);
test_max_receive_message_length_on_compressed_response(config, false);
test_max_receive_message_length_on_compressed_response(config, true);
}
} }
void max_message_length_pre_init(void) {} void max_message_length_pre_init(void) {}

@ -529,10 +529,9 @@ static void BM_IsolatedFilter(benchmark::State& state) {
grpc_call_final_info final_info; grpc_call_final_info final_info;
TestOp test_op_data; TestOp test_op_data;
const int kArenaSize = 4096; const int kArenaSize = 4096;
grpc_call_context_element context[GRPC_CONTEXT_COUNT] = {};
grpc_call_element_args call_args{call_stack, grpc_call_element_args call_args{call_stack,
nullptr, nullptr,
context, nullptr,
method, method,
start_time, start_time,
deadline, deadline,

@ -24,18 +24,14 @@
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "include/grpc/grpc.h" #include "include/grpc/grpc.h"
#include "include/grpcpp/grpcpp.h" #include "include/grpcpp/grpcpp.h"
#include "include/grpcpp/opencensus.h"
#include "opencensus/stats/stats.h" #include "opencensus/stats/stats.h"
#include "src/cpp/ext/filters/census/grpc_plugin.h" #include "src/cpp/ext/filters/census/grpc_plugin.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
#include "test/cpp/microbenchmarks/helpers.h" #include "test/cpp/microbenchmarks/helpers.h"
using ::grpc::RegisterOpenCensusPlugin;
using ::grpc::RegisterOpenCensusViewsForExport;
absl::once_flag once; absl::once_flag once;
void RegisterOnce() { absl::call_once(once, RegisterOpenCensusPlugin); } void RegisterOnce() { absl::call_once(once, grpc::RegisterOpenCensusPlugin); }
class EchoServer final : public grpc::testing::EchoTestService::Service { class EchoServer final : public grpc::testing::EchoTestService::Service {
grpc::Status Echo(grpc::ServerContext* context, grpc::Status Echo(grpc::ServerContext* context,
@ -110,7 +106,7 @@ static void BM_E2eLatencyCensusEnabled(benchmark::State& state) {
RegisterOnce(); RegisterOnce();
// This we can safely repeat, and doing so clears accumulated data to avoid // This we can safely repeat, and doing so clears accumulated data to avoid
// initialization costs varying between runs. // initialization costs varying between runs.
RegisterOpenCensusViewsForExport(); grpc::RegisterOpenCensusViewsForExport();
EchoServerThread server; EchoServerThread server;
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub = std::unique_ptr<grpc::testing::EchoTestService::Stub> stub =

@ -1023,7 +1023,6 @@ include/grpcpp/impl/server_initializer.h \
include/grpcpp/impl/server_initializer_impl.h \ include/grpcpp/impl/server_initializer_impl.h \
include/grpcpp/impl/service_type.h \ include/grpcpp/impl/service_type.h \
include/grpcpp/resource_quota.h \ include/grpcpp/resource_quota.h \
include/grpcpp/resource_quota_impl.h \
include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_context.h \
include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/auth_metadata_processor.h \
include/grpcpp/security/auth_metadata_processor_impl.h \ include/grpcpp/security/auth_metadata_processor_impl.h \

@ -1023,7 +1023,6 @@ include/grpcpp/impl/server_initializer.h \
include/grpcpp/impl/server_initializer_impl.h \ include/grpcpp/impl/server_initializer_impl.h \
include/grpcpp/impl/service_type.h \ include/grpcpp/impl/service_type.h \
include/grpcpp/resource_quota.h \ include/grpcpp/resource_quota.h \
include/grpcpp/resource_quota_impl.h \
include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_context.h \
include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/auth_metadata_processor.h \
include/grpcpp/security/auth_metadata_processor_impl.h \ include/grpcpp/security/auth_metadata_processor_impl.h \
@ -1164,7 +1163,6 @@ src/core/ext/filters/client_channel/server_address.h \
src/core/ext/filters/client_channel/service_config.cc \ src/core/ext/filters/client_channel/service_config.cc \
src/core/ext/filters/client_channel/service_config.h \ src/core/ext/filters/client_channel/service_config.h \
src/core/ext/filters/client_channel/service_config_call_data.h \ src/core/ext/filters/client_channel/service_config_call_data.h \
src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc \
src/core/ext/filters/client_channel/service_config_parser.cc \ src/core/ext/filters/client_channel/service_config_parser.cc \
src/core/ext/filters/client_channel/service_config_parser.h \ src/core/ext/filters/client_channel/service_config_parser.h \
src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel.cc \

@ -965,7 +965,6 @@ src/core/ext/filters/client_channel/server_address.h \
src/core/ext/filters/client_channel/service_config.cc \ src/core/ext/filters/client_channel/service_config.cc \
src/core/ext/filters/client_channel/service_config.h \ src/core/ext/filters/client_channel/service_config.h \
src/core/ext/filters/client_channel/service_config_call_data.h \ src/core/ext/filters/client_channel/service_config_call_data.h \
src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc \
src/core/ext/filters/client_channel/service_config_parser.cc \ src/core/ext/filters/client_channel/service_config_parser.cc \
src/core/ext/filters/client_channel/service_config_parser.h \ src/core/ext/filters/client_channel/service_config_parser.h \
src/core/ext/filters/client_channel/subchannel.cc \ src/core/ext/filters/client_channel/subchannel.cc \

Loading…
Cancel
Save