channel_init --> core configuration system (#27347)

* channel_init --> core configuration system

* Automated change: Fix sanity tests

* fixes

* Automated change: Fix sanity tests

* fixes

* fixes

* eliminate grpc_base_c

* fixes

* fix merge

* fix

* update visibility

* fixes

* feedback

* fix comment

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/27497/head
Craig Tiller 3 years ago committed by GitHub
parent c3759da7cc
commit 9b41852a5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 171
      BUILD
  2. 4
      CMakeLists.txt
  3. 2
      Makefile
  4. 8
      build_autogenerated.yaml
  5. 1
      config.m4
  6. 1
      config.w32
  7. 2
      gRPC-C++.podspec
  8. 3
      gRPC-Core.podspec
  9. 2
      grpc.gemspec
  10. 2
      grpc.gyp
  11. 2
      package.xml
  12. 19
      src/core/ext/filters/client_channel/client_channel_plugin.cc
  13. 56
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  14. 36
      src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc
  15. 5
      src/core/ext/filters/client_channel/subchannel.cc
  16. 35
      src/core/ext/filters/client_idle/client_idle_filter.cc
  17. 41
      src/core/ext/filters/deadline/deadline_filter.cc
  18. 24
      src/core/ext/filters/http/client_authority_filter.cc
  19. 124
      src/core/ext/filters/http/http_filters_plugin.cc
  20. 50
      src/core/ext/filters/max_age/max_age_filter.cc
  21. 30
      src/core/ext/filters/message_size/message_size_filter.cc
  22. 16
      src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc
  23. 2
      src/core/ext/transport/binder/client/BUILD
  24. 2
      src/core/ext/transport/binder/server/BUILD
  25. 2
      src/core/ext/transport/binder/transport/BUILD
  26. 1
      src/core/ext/transport/inproc/inproc_transport.cc
  27. 1
      src/core/ext/xds/xds_client.cc
  28. 4
      src/core/lib/channel/connected_channel.cc
  29. 3
      src/core/lib/channel/connected_channel.h
  30. 46
      src/core/lib/config/core_configuration.cc
  31. 38
      src/core/lib/config/core_configuration.h
  32. 49
      src/core/lib/surface/builtins.cc
  33. 26
      src/core/lib/surface/builtins.h
  34. 5
      src/core/lib/surface/channel.cc
  35. 100
      src/core/lib/surface/channel_init.cc
  36. 96
      src/core/lib/surface/channel_init.h
  37. 36
      src/core/lib/surface/init.cc
  38. 31
      src/core/lib/surface/init_secure.cc
  39. 77
      src/core/plugin_registry/grpc_plugin_registry.cc
  40. 67
      src/core/plugin_registry/grpc_unsecure_plugin_registry.cc
  41. 50
      src/cpp/common/channel_filter.cc
  42. 49
      src/cpp/common/channel_filter.h
  43. 1
      src/python/grpcio/grpc_core_dependencies.py
  44. 36
      test/core/channel/channel_stack_builder_test.cc
  45. 3
      test/core/channel/minimal_stack_is_minimal_test.cc
  46. 37
      test/core/end2end/tests/filter_causes_close.cc
  47. 70
      test/core/end2end/tests/filter_context.cc
  48. 111
      test/core/end2end/tests/filter_init_fails.cc
  49. 70
      test/core/end2end/tests/filter_latency.cc
  50. 81
      test/core/end2end/tests/filter_status_code.cc
  51. 35
      test/core/end2end/tests/retry_cancel_with_multiple_send_batches.cc
  52. 28
      test/core/end2end/tests/retry_recv_trailing_metadata_error.cc
  53. 50
      test/core/end2end/tests/retry_send_op_fails.cc
  54. 2
      test/core/security/BUILD
  55. 2
      test/core/transport/binder/end2end/BUILD
  56. 2
      test/core/transport/binder/end2end/fuzzers/BUILD
  57. 4
      test/core/tsi/alts/zero_copy_frame_protector/BUILD
  58. 2
      test/core/util/BUILD
  59. 3
      test/cpp/microbenchmarks/bm_opencensus_plugin.cc
  60. 2
      tools/doxygen/Doxyfile.c++.internal
  61. 2
      tools/doxygen/Doxyfile.core.internal

171
BUILD

@ -359,7 +359,7 @@ grpc_cc_library(
deps = [
"config",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_common",
"grpc_lb_policy_grpclb",
"grpc_trace",
@ -398,7 +398,7 @@ grpc_cc_library(
deps = [
"config",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_common",
"grpc_lb_policy_grpclb_secure",
"grpc_secure",
@ -483,7 +483,7 @@ grpc_cc_library(
"grpc++_codegen_base",
"grpc++_codegen_base_src",
"grpc++_codegen_proto",
"grpc_base_c",
"grpc_base",
"grpc_codegen",
"grpc_secure",
"ref_counted_ptr",
@ -613,7 +613,7 @@ grpc_cc_library(
visibility = ["@grpc:public"],
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_trace",
],
)
@ -819,7 +819,8 @@ grpc_cc_library(
"src/core/lib/config/core_configuration.h",
],
deps = [
"gpr_platform",
"channel_init",
"gpr_base",
"handshaker_registry",
],
)
@ -1374,7 +1375,7 @@ grpc_cc_library(
)
grpc_cc_library(
name = "grpc_base_c",
name = "grpc_base",
srcs = [
"src/core/lib/address_utils/parse_address.cc",
"src/core/lib/address_utils/sockaddr_utils.cc",
@ -1505,18 +1506,18 @@ grpc_cc_library(
"src/core/lib/slice/slice_intern.cc",
"src/core/lib/slice/slice_split.cc",
"src/core/lib/surface/api_trace.cc",
"src/core/lib/surface/builtins.cc",
"src/core/lib/surface/byte_buffer.cc",
"src/core/lib/surface/byte_buffer_reader.cc",
"src/core/lib/surface/call.cc",
"src/core/lib/surface/call_details.cc",
"src/core/lib/surface/call_log_batch.cc",
"src/core/lib/surface/channel.cc",
"src/core/lib/surface/channel_init.cc",
"src/core/lib/surface/channel_ping.cc",
"src/core/lib/surface/channel_stack_type.cc",
"src/core/lib/surface/completion_queue.cc",
"src/core/lib/surface/completion_queue_factory.cc",
"src/core/lib/surface/event_string.cc",
"src/core/lib/surface/lame_client.cc",
"src/core/lib/surface/metadata_array.cc",
"src/core/lib/surface/server.cc",
"src/core/lib/surface/validate_metadata.cc",
@ -1646,11 +1647,10 @@ grpc_cc_library(
"src/core/lib/slice/b64.h",
"src/core/lib/slice/percent_encoding.h",
"src/core/lib/surface/api_trace.h",
"src/core/lib/surface/builtins.h",
"src/core/lib/surface/call.h",
"src/core/lib/surface/call_test_only.h",
"src/core/lib/surface/channel.h",
"src/core/lib/surface/channel_init.h",
"src/core/lib/surface/channel_stack_type.h",
"src/core/lib/surface/completion_queue.h",
"src/core/lib/surface/completion_queue_factory.h",
"src/core/lib/surface/event_string.h",
@ -1706,7 +1706,9 @@ grpc_cc_library(
visibility = ["@grpc:alt_grpc_base_legacy"],
deps = [
"bitset",
"channel_stack_type",
"closure",
"config",
"dual_ref_counted",
"error",
"exec_ctx",
@ -1725,15 +1727,31 @@ grpc_cc_library(
)
grpc_cc_library(
name = "grpc_base",
name = "channel_stack_type",
srcs = [
"src/core/lib/surface/lame_client.cc",
"src/core/lib/surface/channel_stack_type.cc",
],
hdrs = [
"src/core/lib/surface/channel_stack_type.h",
],
language = "c++",
deps = [
"gpr_base",
],
)
grpc_cc_library(
name = "channel_init",
srcs = [
"src/core/lib/surface/channel_init.cc",
],
hdrs = [
"src/core/lib/surface/channel_init.h",
],
language = "c++",
visibility = ["@grpc:alt_grpc_base_legacy"],
deps = [
"channel_stack_type",
"gpr_base",
"grpc_base_c",
],
)
@ -1851,7 +1869,7 @@ grpc_cc_library(
"debug_location",
"error",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_authority_filter",
"grpc_deadline_filter",
"grpc_health_upb",
@ -1873,8 +1891,9 @@ grpc_cc_library(
],
language = "c++",
deps = [
"config",
"gpr_base",
"grpc_base_c",
"grpc_base",
],
)
@ -1888,8 +1907,9 @@ grpc_cc_library(
],
language = "c++",
deps = [
"config",
"gpr_base",
"grpc_base_c",
"grpc_base",
],
)
@ -1903,8 +1923,9 @@ grpc_cc_library(
],
language = "c++",
deps = [
"config",
"gpr_base",
"grpc_base_c",
"grpc_base",
"slice",
],
)
@ -1919,8 +1940,10 @@ grpc_cc_library(
],
language = "c++",
deps = [
"channel_stack_type",
"config",
"gpr_base",
"grpc_base_c",
"grpc_base",
"slice",
],
)
@ -1936,8 +1959,9 @@ grpc_cc_library(
external_deps = ["absl/strings:str_format"],
language = "c++",
deps = [
"config",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_codegen",
"ref_counted",
@ -1959,7 +1983,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
],
)
@ -1986,8 +2010,9 @@ grpc_cc_library(
],
language = "c++",
deps = [
"config",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_message_size_filter",
"slice",
],
@ -2003,8 +2028,9 @@ grpc_cc_library(
],
language = "c++",
deps = [
"config",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_server_backward_compatibility",
],
)
@ -2040,7 +2066,7 @@ grpc_cc_library(
visibility = ["@grpc:grpclb"],
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"useful",
],
@ -2071,10 +2097,11 @@ grpc_cc_library(
],
language = "c++",
deps = [
"config",
"error",
"google_api_upb",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_grpclb_balancer_addresses",
"grpc_lb_upb",
@ -2111,10 +2138,11 @@ grpc_cc_library(
],
language = "c++",
deps = [
"config",
"error",
"google_api_upb",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_grpclb_balancer_addresses",
"grpc_lb_upb",
@ -2180,7 +2208,7 @@ grpc_cc_library(
"google_api_upb",
"gpr_base",
"gpr_codegen",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_codegen",
"grpc_fault_injection_filter",
@ -2208,7 +2236,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_xds_client",
],
)
@ -2228,7 +2256,7 @@ grpc_cc_library(
deps = [
"error",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_xds_client",
"slice",
],
@ -2245,7 +2273,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_xds_client",
"orphanable",
@ -2269,7 +2297,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_xds_client",
],
@ -2287,7 +2315,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_lb_address_filtering",
"grpc_lb_policy_ring_hash",
@ -2311,7 +2339,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_lb_xds_channel_args",
"grpc_lb_xds_common",
@ -2333,7 +2361,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_resolver_xds_header",
"orphanable",
@ -2356,7 +2384,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
],
)
@ -2369,7 +2397,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
],
)
@ -2382,7 +2410,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_lb_subchannel_list",
],
@ -2403,7 +2431,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_lb_subchannel_list",
"grpc_trace",
@ -2419,7 +2447,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_lb_subchannel_list",
"grpc_trace",
@ -2439,7 +2467,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_lb_address_filtering",
"orphanable",
@ -2459,7 +2487,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_lb_address_filtering",
"orphanable",
@ -2487,7 +2515,7 @@ grpc_cc_library(
"error",
"gpr",
"grpc++_base",
"grpc_base_c",
"grpc_base",
"grpc_secure",
"slice",
],
@ -2508,7 +2536,7 @@ grpc_cc_library(
"gpr",
"gpr_codegen",
"grpc++",
"grpc_base_c",
"grpc_base",
],
)
@ -2615,7 +2643,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
],
)
@ -2630,7 +2658,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_resolver_dns_selection",
],
@ -2663,7 +2691,7 @@ grpc_cc_library(
deps = [
"error",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_grpclb_balancer_addresses",
"grpc_resolver_dns_selection",
@ -2681,7 +2709,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"slice",
],
@ -2698,7 +2726,7 @@ grpc_cc_library(
],
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"slice",
"useful",
@ -2726,7 +2754,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_lb_policy_ring_hash",
"grpc_xds_client",
@ -2742,7 +2770,7 @@ grpc_cc_library(
deps = [
"alts_util",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_xds_client",
],
@ -2866,7 +2894,6 @@ grpc_cc_library(
"error",
"gpr_base",
"grpc_base",
"grpc_base_c",
"grpc_client_channel",
"grpc_codegen",
"grpc_lb_xds_channel_args",
@ -2895,7 +2922,7 @@ grpc_cc_library(
language = "c++",
deps = [
"google_api_upb",
"grpc_base_c",
"grpc_base",
],
)
@ -2917,7 +2944,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
],
)
@ -2941,7 +2968,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_matchers",
"grpc_secure",
],
@ -3009,7 +3036,7 @@ grpc_cc_library(
"envoy_ads_upb",
"google_api_upb",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_mock_cel",
"grpc_rbac_engine",
],
@ -3134,7 +3161,7 @@ grpc_cc_library(
visibility = ["@grpc:grpclb"],
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_http_filters",
"grpc_trace",
"grpc_transport_chttp2_alpn",
@ -3178,7 +3205,7 @@ grpc_cc_library(
deps = [
"config",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_transport_chttp2",
"slice",
@ -3194,7 +3221,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_transport_chttp2",
"grpc_transport_chttp2_client_connector",
@ -3210,7 +3237,7 @@ grpc_cc_library(
deps = [
"error",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_secure",
"grpc_transport_chttp2",
@ -3235,7 +3262,7 @@ grpc_cc_library(
deps = [
"config",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_codegen",
"grpc_http_filters",
"grpc_transport_chttp2",
@ -3257,7 +3284,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_transport_chttp2",
"grpc_transport_chttp2_server",
],
@ -3274,7 +3301,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_secure",
"grpc_transport_chttp2",
"grpc_transport_chttp2_server",
@ -3294,7 +3321,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_trace",
"slice",
],
@ -3358,7 +3385,7 @@ grpc_cc_library(
visibility = ["@grpc:alts_frame_protector"],
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
"slice",
"tsi_interface",
"useful",
@ -3391,7 +3418,7 @@ grpc_cc_library(
deps = [
"alts_upb",
"gpr",
"grpc_base_c",
"grpc_base",
],
)
@ -3436,7 +3463,7 @@ grpc_cc_library(
"alts_frame_protector",
"alts_util",
"gpr_base",
"grpc_base_c",
"grpc_base",
"grpc_transport_chttp2_client_insecure",
"slice",
"tsi_interface",
@ -3458,12 +3485,13 @@ grpc_cc_library(
public_hdrs = GRPCXX_PUBLIC_HDRS,
visibility = ["@grpc:alt_grpc++_base_legacy"],
deps = [
"config",
"gpr_base",
"grpc",
"grpc++_codegen_base",
"grpc++_codegen_base_src",
"grpc++_internal_hdrs_only",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_codegen",
"grpc_health_upb",
@ -3489,11 +3517,12 @@ grpc_cc_library(
tags = ["avoid_dep"],
visibility = ["@grpc:alt_grpc++_base_unsecure_legacy"],
deps = [
"config",
"gpr_base",
"grpc++_codegen_base",
"grpc++_codegen_base_src",
"grpc++_internal_hdrs_only",
"grpc_base_c",
"grpc_base",
"grpc_client_channel",
"grpc_codegen",
"grpc_health_upb",
@ -3751,7 +3780,7 @@ grpc_cc_library(
deps = [
"gpr_base",
"grpc++",
"grpc_base_c",
"grpc_base",
],
)
@ -3766,7 +3795,7 @@ grpc_cc_library(
language = "c++",
deps = [
"gpr_base",
"grpc_base_c",
"grpc_base",
],
)
@ -3827,7 +3856,7 @@ grpc_cc_library(
"census",
"gpr_base",
"grpc++",
"grpc_base_c",
"grpc_base",
],
)

4
CMakeLists.txt generated

@ -2050,6 +2050,7 @@ add_library(grpc
src/core/lib/slice/slice_string_helpers.cc
src/core/lib/slice/static_slice.cc
src/core/lib/surface/api_trace.cc
src/core/lib/surface/builtins.cc
src/core/lib/surface/byte_buffer.cc
src/core/lib/surface/byte_buffer_reader.cc
src/core/lib/surface/call.cc
@ -2634,6 +2635,7 @@ add_library(grpc_unsecure
src/core/lib/slice/slice_string_helpers.cc
src/core/lib/slice/static_slice.cc
src/core/lib/surface/api_trace.cc
src/core/lib/surface/builtins.cc
src/core/lib/surface/byte_buffer.cc
src/core/lib/surface/byte_buffer_reader.cc
src/core/lib/surface/call.cc
@ -10505,6 +10507,8 @@ add_executable(core_configuration_test
src/core/lib/gprpp/time_util.cc
src/core/lib/profiling/basic_timers.cc
src/core/lib/profiling/stap_timers.cc
src/core/lib/surface/channel_init.cc
src/core/lib/surface/channel_stack_type.cc
test/core/config/core_configuration_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc

2
Makefile generated

@ -1551,6 +1551,7 @@ LIBGRPC_SRC = \
src/core/lib/slice/slice_string_helpers.cc \
src/core/lib/slice/static_slice.cc \
src/core/lib/surface/api_trace.cc \
src/core/lib/surface/builtins.cc \
src/core/lib/surface/byte_buffer.cc \
src/core/lib/surface/byte_buffer_reader.cc \
src/core/lib/surface/call.cc \
@ -1983,6 +1984,7 @@ LIBGRPC_UNSECURE_SRC = \
src/core/lib/slice/slice_string_helpers.cc \
src/core/lib/slice/static_slice.cc \
src/core/lib/surface/api_trace.cc \
src/core/lib/surface/builtins.cc \
src/core/lib/surface/byte_buffer.cc \
src/core/lib/surface/byte_buffer_reader.cc \
src/core/lib/surface/call.cc \

@ -902,6 +902,7 @@ libs:
- src/core/lib/slice/slice_utils.h
- src/core/lib/slice/static_slice.h
- src/core/lib/surface/api_trace.h
- src/core/lib/surface/builtins.h
- src/core/lib/surface/call.h
- src/core/lib/surface/call_test_only.h
- src/core/lib/surface/channel.h
@ -1465,6 +1466,7 @@ libs:
- src/core/lib/slice/slice_string_helpers.cc
- src/core/lib/slice/static_slice.cc
- src/core/lib/surface/api_trace.cc
- src/core/lib/surface/builtins.cc
- src/core/lib/surface/byte_buffer.cc
- src/core/lib/surface/byte_buffer_reader.cc
- src/core/lib/surface/call.cc
@ -1906,6 +1908,7 @@ libs:
- src/core/lib/slice/slice_utils.h
- src/core/lib/slice/static_slice.h
- src/core/lib/surface/api_trace.h
- src/core/lib/surface/builtins.h
- src/core/lib/surface/call.h
- src/core/lib/surface/call_test_only.h
- src/core/lib/surface/channel.h
@ -2187,6 +2190,7 @@ libs:
- src/core/lib/slice/slice_string_helpers.cc
- src/core/lib/slice/static_slice.cc
- src/core/lib/surface/api_trace.cc
- src/core/lib/surface/builtins.cc
- src/core/lib/surface/byte_buffer.cc
- src/core/lib/surface/byte_buffer_reader.cc
- src/core/lib/surface/call.cc
@ -5401,6 +5405,8 @@ targets:
- src/core/lib/gprpp/thd.h
- src/core/lib/gprpp/time_util.h
- src/core/lib/profiling/timers.h
- src/core/lib/surface/channel_init.h
- src/core/lib/surface/channel_stack_type.h
src:
- src/core/ext/upb-generated/google/api/annotations.upb.c
- src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c
@ -5460,6 +5466,8 @@ targets:
- src/core/lib/gprpp/time_util.cc
- src/core/lib/profiling/basic_timers.cc
- src/core/lib/profiling/stap_timers.cc
- src/core/lib/surface/channel_init.cc
- src/core/lib/surface/channel_stack_type.cc
- test/core/config/core_configuration_test.cc
deps:
- absl/base:base

1
config.m4 generated

@ -604,6 +604,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/slice/slice_string_helpers.cc \
src/core/lib/slice/static_slice.cc \
src/core/lib/surface/api_trace.cc \
src/core/lib/surface/builtins.cc \
src/core/lib/surface/byte_buffer.cc \
src/core/lib/surface/byte_buffer_reader.cc \
src/core/lib/surface/call.cc \

1
config.w32 generated

@ -570,6 +570,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\slice\\slice_string_helpers.cc " +
"src\\core\\lib\\slice\\static_slice.cc " +
"src\\core\\lib\\surface\\api_trace.cc " +
"src\\core\\lib\\surface\\builtins.cc " +
"src\\core\\lib\\surface\\byte_buffer.cc " +
"src\\core\\lib\\surface\\byte_buffer_reader.cc " +
"src\\core\\lib\\surface\\call.cc " +

2
gRPC-C++.podspec generated

@ -714,6 +714,7 @@ Pod::Spec.new do |s|
'src/core/lib/slice/slice_utils.h',
'src/core/lib/slice/static_slice.h',
'src/core/lib/surface/api_trace.h',
'src/core/lib/surface/builtins.h',
'src/core/lib/surface/call.h',
'src/core/lib/surface/call_test_only.h',
'src/core/lib/surface/channel.h',
@ -1385,6 +1386,7 @@ Pod::Spec.new do |s|
'src/core/lib/slice/slice_utils.h',
'src/core/lib/slice/static_slice.h',
'src/core/lib/surface/api_trace.h',
'src/core/lib/surface/builtins.h',
'src/core/lib/surface/call.h',
'src/core/lib/surface/call_test_only.h',
'src/core/lib/surface/channel.h',

3
gRPC-Core.podspec generated

@ -1269,6 +1269,8 @@ Pod::Spec.new do |s|
'src/core/lib/slice/static_slice.h',
'src/core/lib/surface/api_trace.cc',
'src/core/lib/surface/api_trace.h',
'src/core/lib/surface/builtins.cc',
'src/core/lib/surface/builtins.h',
'src/core/lib/surface/byte_buffer.cc',
'src/core/lib/surface/byte_buffer_reader.cc',
'src/core/lib/surface/call.cc',
@ -1972,6 +1974,7 @@ Pod::Spec.new do |s|
'src/core/lib/slice/slice_utils.h',
'src/core/lib/slice/static_slice.h',
'src/core/lib/surface/api_trace.h',
'src/core/lib/surface/builtins.h',
'src/core/lib/surface/call.h',
'src/core/lib/surface/call_test_only.h',
'src/core/lib/surface/channel.h',

2
grpc.gemspec generated

@ -1182,6 +1182,8 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/slice/static_slice.h )
s.files += %w( src/core/lib/surface/api_trace.cc )
s.files += %w( src/core/lib/surface/api_trace.h )
s.files += %w( src/core/lib/surface/builtins.cc )
s.files += %w( src/core/lib/surface/builtins.h )
s.files += %w( src/core/lib/surface/byte_buffer.cc )
s.files += %w( src/core/lib/surface/byte_buffer_reader.cc )
s.files += %w( src/core/lib/surface/call.cc )

2
grpc.gyp generated

@ -992,6 +992,7 @@
'src/core/lib/slice/slice_string_helpers.cc',
'src/core/lib/slice/static_slice.cc',
'src/core/lib/surface/api_trace.cc',
'src/core/lib/surface/builtins.cc',
'src/core/lib/surface/byte_buffer.cc',
'src/core/lib/surface/byte_buffer_reader.cc',
'src/core/lib/surface/call.cc',
@ -1399,6 +1400,7 @@
'src/core/lib/slice/slice_string_helpers.cc',
'src/core/lib/slice/static_slice.cc',
'src/core/lib/surface/api_trace.cc',
'src/core/lib/surface/builtins.cc',
'src/core/lib/surface/byte_buffer.cc',
'src/core/lib/surface/byte_buffer_reader.cc',
'src/core/lib/surface/call.cc',

2
package.xml generated

@ -1162,6 +1162,8 @@
<file baseinstalldir="/" name="src/core/lib/slice/static_slice.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/api_trace.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/api_trace.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/builtins.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/builtins.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/byte_buffer.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/byte_buffer_reader.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/call.cc" role="src" />

@ -37,12 +37,7 @@
#include "src/core/ext/filters/client_channel/retry_service_config.h"
#include "src/core/ext/filters/client_channel/retry_throttle.h"
#include "src/core/ext/filters/client_channel/service_config_parser.h"
#include "src/core/lib/surface/channel_init.h"
static bool append_filter(grpc_channel_stack_builder* builder, void* arg) {
return grpc_channel_stack_builder_append_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
}
#include "src/core/lib/config/core_configuration.h"
void grpc_client_channel_init(void) {
grpc_core::ServiceConfigParser::Init();
@ -54,16 +49,11 @@ void grpc_client_channel_init(void) {
grpc_core::ProxyMapperRegistry::Init();
grpc_core::RegisterHttpProxyMapper();
grpc_core::GlobalSubchannelPool::Init();
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter,
const_cast<grpc_channel_filter*>(
&grpc_core::ClientChannel::kFilterVtable));
grpc_client_channel_global_init_backup_polling();
}
void grpc_client_channel_shutdown(void) {
grpc_core::GlobalSubchannelPool::Shutdown();
grpc_channel_init_shutdown();
grpc_core::ProxyMapperRegistry::Shutdown();
grpc_core::internal::ServerRetryThrottleMap::Shutdown();
grpc_core::ResolverRegistry::Builder::ShutdownRegistry();
@ -75,6 +65,13 @@ namespace grpc_core {
void BuildClientChannelConfiguration(CoreConfiguration::Builder* builder) {
RegisterHttpConnectHandshaker(builder);
builder->channel_init()->RegisterStage(
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
[](grpc_channel_stack_builder* builder) {
return grpc_channel_stack_builder_append_filter(
builder, &grpc_core::ClientChannel::kFilterVtable, nullptr,
nullptr);
});
}
} // namespace grpc_core

@ -88,6 +88,8 @@
#include "src/core/lib/backoff/backoff.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/config/core_configuration.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/memory.h"
@ -100,7 +102,6 @@
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/static_metadata.h"
#define GRPC_GRPCLB_INITIAL_CONNECT_BACKOFF_SECONDS 1
@ -1744,39 +1745,34 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
// Plugin registration
//
namespace {
// Only add client_load_reporting filter if the grpclb LB policy is used.
bool maybe_add_client_load_reporting_filter(grpc_channel_stack_builder* builder,
void* arg) {
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
const grpc_arg* channel_arg =
grpc_channel_args_find(args, GRPC_ARG_LB_POLICY_NAME);
if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_STRING &&
strcmp(channel_arg->value.string, "grpclb") == 0) {
// TODO(roth): When we get around to re-attempting
// https://github.com/grpc/grpc/pull/16214, we should try to keep
// this filter at the very top of the subchannel stack, since that
// will minimize the number of metadata elements that the filter
// needs to iterate through to find the ClientStats object.
return grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr,
nullptr);
}
return true;
}
} // namespace
void grpc_lb_policy_grpclb_init() {
grpc_core::LoadBalancingPolicyRegistry::Builder::
RegisterLoadBalancingPolicyFactory(
absl::make_unique<grpc_core::GrpcLbFactory>());
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_client_load_reporting_filter,
const_cast<grpc_channel_filter*>(&grpc_client_load_reporting_filter));
}
void grpc_lb_policy_grpclb_shutdown() {}
namespace grpc_core {
void RegisterGrpcLbLoadReportingFilter(CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
[](grpc_channel_stack_builder* builder) {
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
const grpc_arg* channel_arg =
grpc_channel_args_find(args, GRPC_ARG_LB_POLICY_NAME);
if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_STRING &&
strcmp(channel_arg->value.string, "grpclb") == 0) {
// TODO(roth): When we get around to re-attempting
// https://github.com/grpc/grpc/pull/16214, we should try to keep
// this filter at the very top of the subchannel stack, since that
// will minimize the number of metadata elements that the filter
// needs to iterate through to find the ClientStats object.
return grpc_channel_stack_builder_prepend_filter(
builder, &grpc_client_load_reporting_filter, nullptr, nullptr);
}
return true;
});
}
} // namespace grpc_core

@ -23,7 +23,7 @@
#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"
#include "src/core/lib/config/core_configuration.h"
namespace grpc_core {
@ -117,27 +117,23 @@ const grpc_channel_filter ServiceConfigChannelArgFilter = {
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(
void RegisterServiceConfigChannelArgFilter(
CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_core::maybe_add_service_config_channel_arg_filter, nullptr);
[](grpc_channel_stack_builder* builder) {
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);
});
}
void grpc_service_config_channel_arg_filter_shutdown(void) {}
} // namespace grpc_core

@ -41,6 +41,7 @@
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/alloc.h"
#include "src/core/lib/gprpp/debug_location.h"
@ -50,7 +51,6 @@
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/connectivity_state.h"
#include "src/core/lib/transport/error_utils.h"
#include "src/core/lib/transport/status_metadata.h"
@ -1036,7 +1036,8 @@ bool Subchannel::PublishTransportLocked() {
builder, connecting_result_.channel_args);
grpc_channel_stack_builder_set_transport(builder,
connecting_result_.transport);
if (!grpc_channel_init_create_stack(builder, GRPC_CLIENT_SUBCHANNEL)) {
if (!CoreConfiguration::Get().channel_init().CreateStack(
builder, GRPC_CLIENT_SUBCHANNEL)) {
grpc_channel_stack_builder_destroy(builder);
return false;
}

@ -24,8 +24,8 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/http2_errors.h"
// TODO(juanlishen): The idle filter is disabled in client channel by default
@ -422,26 +422,21 @@ const grpc_channel_filter grpc_client_idle_filter = {
grpc_channel_next_get_info,
"client_idle"};
static bool MaybeAddClientIdleFilter(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) &&
GetClientIdleTimeout(channel_args) != INT_MAX) {
return grpc_channel_stack_builder_prepend_filter(
builder, &grpc_client_idle_filter, nullptr, nullptr);
} else {
return true;
}
}
} // namespace
} // namespace grpc_core
void grpc_client_idle_filter_init(void) {
grpc_channel_init_register_stage(
void RegisterClientIdleFilter(CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_core::MaybeAddClientIdleFilter, nullptr);
[](grpc_channel_stack_builder* builder) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (!grpc_channel_args_want_minimal_stack(channel_args) &&
GetClientIdleTimeout(channel_args) != INT_MAX) {
return grpc_channel_stack_builder_prepend_filter(
builder, &grpc_client_idle_filter, nullptr, nullptr);
} else {
return true;
}
});
}
void grpc_client_idle_filter_shutdown(void) {}
} // namespace grpc_core

@ -27,10 +27,10 @@
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/channel_init.h"
namespace grpc_core {
@ -370,25 +370,22 @@ bool grpc_deadline_checking_enabled(const grpc_channel_args* channel_args) {
!grpc_channel_args_want_minimal_stack(channel_args));
}
static bool maybe_add_deadline_filter(grpc_channel_stack_builder* builder,
void* arg) {
return grpc_deadline_checking_enabled(
grpc_channel_stack_builder_get_channel_arguments(builder))
? grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg),
nullptr, nullptr)
: true;
}
void grpc_deadline_filter_init(void) {
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_deadline_filter,
const_cast<grpc_channel_filter*>(&grpc_client_deadline_filter));
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_deadline_filter,
const_cast<grpc_channel_filter*>(&grpc_server_deadline_filter));
namespace grpc_core {
void RegisterDeadlineFilter(CoreConfiguration::Builder* builder) {
auto register_filter = [builder](grpc_channel_stack_type type,
const grpc_channel_filter* filter) {
builder->channel_init()->RegisterStage(
type, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
[filter](grpc_channel_stack_builder* builder) {
if (grpc_deadline_checking_enabled(
grpc_channel_stack_builder_get_channel_arguments(builder))) {
return grpc_channel_stack_builder_prepend_filter(builder, filter,
nullptr, nullptr);
}
return true;
});
};
register_filter(GRPC_CLIENT_DIRECT_CHANNEL, &grpc_client_deadline_filter);
register_filter(GRPC_SERVER_CHANNEL, &grpc_server_deadline_filter);
}
void grpc_deadline_filter_shutdown(void) {}
} // namespace grpc_core

@ -29,11 +29,12 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/transport/static_metadata.h"
@ -132,8 +133,7 @@ const grpc_channel_filter grpc_client_authority_filter = {
grpc_channel_next_get_info,
"authority"};
static bool add_client_authority_filter(grpc_channel_stack_builder* builder,
void* arg) {
static bool add_client_authority_filter(grpc_channel_stack_builder* builder) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
const grpc_arg* disable_client_authority_filter_arg = grpc_channel_args_find(
@ -146,16 +146,14 @@ static bool add_client_authority_filter(grpc_channel_stack_builder* builder,
}
}
return grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
builder, &grpc_client_authority_filter, nullptr, nullptr);
}
void grpc_client_authority_filter_init(void) {
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, INT_MAX, add_client_authority_filter,
const_cast<grpc_channel_filter*>(&grpc_client_authority_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, add_client_authority_filter,
const_cast<grpc_channel_filter*>(&grpc_client_authority_filter));
namespace grpc_core {
void RegisterClientAuthorityFilter(CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(GRPC_CLIENT_SUBCHANNEL, INT_MAX,
add_client_authority_filter);
builder->channel_init()->RegisterStage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX,
add_client_authority_filter);
}
void grpc_client_authority_filter_shutdown(void) {}
} // namespace grpc_core

@ -25,84 +25,66 @@
#include "src/core/ext/filters/http/message_compress/message_decompress_filter.h"
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/transport_impl.h"
struct optional_filter {
const grpc_channel_filter* filter;
const char* control_channel_arg;
};
static optional_filter compress_filter = {
&grpc_message_compress_filter, GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION};
static optional_filter decompress_filter = {
&grpc_core::MessageDecompressFilter,
GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION};
static bool is_building_http_like_transport(
grpc_channel_stack_builder* builder) {
grpc_transport* t = grpc_channel_stack_builder_get_transport(builder);
return t != nullptr && strstr(t->vtable->name, "http");
}
template <bool enable_in_minimal_stack>
static bool maybe_add_optional_filter(grpc_channel_stack_builder* builder,
void* arg) {
if (!is_building_http_like_transport(builder)) return true;
optional_filter* filtarg = static_cast<optional_filter*>(arg);
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
bool enable = grpc_channel_arg_get_bool(
grpc_channel_args_find(channel_args, filtarg->control_channel_arg),
enable_in_minimal_stack ||
!grpc_channel_args_want_minimal_stack(channel_args));
return enable ? grpc_channel_stack_builder_prepend_filter(
builder, filtarg->filter, nullptr, nullptr)
: true;
}
static bool maybe_add_required_filter(grpc_channel_stack_builder* builder,
void* arg) {
return is_building_http_like_transport(builder)
? grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg),
nullptr, nullptr)
: true;
}
void grpc_http_filters_init(void) {
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_optional_filter<false>, &compress_filter);
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_optional_filter<false>, &compress_filter);
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_optional_filter<false>, &compress_filter);
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_optional_filter<true>, &decompress_filter);
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_optional_filter<true>, &decompress_filter);
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_optional_filter<true>, &decompress_filter);
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_required_filter,
const_cast<grpc_channel_filter*>(&grpc_http_client_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_required_filter,
const_cast<grpc_channel_filter*>(&grpc_http_client_filter));
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_required_filter,
const_cast<grpc_channel_filter*>(&grpc_http_server_filter));
namespace grpc_core {
void RegisterHttpFilters(CoreConfiguration::Builder* builder) {
auto optional = [builder](grpc_channel_stack_type channel_type,
bool enable_in_minimal_stack,
const char* control_channel_arg,
const grpc_channel_filter* filter) {
builder->channel_init()->RegisterStage(
channel_type, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
[enable_in_minimal_stack, control_channel_arg,
filter](grpc_channel_stack_builder* builder) {
if (!is_building_http_like_transport(builder)) return true;
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
bool enable = grpc_channel_arg_get_bool(
grpc_channel_args_find(channel_args, control_channel_arg),
enable_in_minimal_stack ||
!grpc_channel_args_want_minimal_stack(channel_args));
if (!enable) return true;
return grpc_channel_stack_builder_prepend_filter(builder, filter,
nullptr, nullptr);
});
};
auto required = [builder](grpc_channel_stack_type channel_type,
const grpc_channel_filter* filter) {
builder->channel_init()->RegisterStage(
channel_type, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
[filter](grpc_channel_stack_builder* builder) {
if (!is_building_http_like_transport(builder)) return true;
return grpc_channel_stack_builder_prepend_filter(builder, filter,
nullptr, nullptr);
});
};
optional(GRPC_CLIENT_SUBCHANNEL, false,
GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION,
&grpc_message_compress_filter);
optional(GRPC_CLIENT_DIRECT_CHANNEL, false,
GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION,
&grpc_message_compress_filter);
optional(GRPC_SERVER_CHANNEL, false, GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION,
&grpc_message_compress_filter);
optional(GRPC_CLIENT_SUBCHANNEL, true,
GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION,
&grpc_core::MessageDecompressFilter);
optional(GRPC_CLIENT_DIRECT_CHANNEL, true,
GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION,
&grpc_core::MessageDecompressFilter);
optional(GRPC_SERVER_CHANNEL, true, GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION,
&grpc_core::MessageDecompressFilter);
required(GRPC_CLIENT_SUBCHANNEL, &grpc_http_client_filter);
required(GRPC_CLIENT_DIRECT_CHANNEL, &grpc_http_client_filter);
required(GRPC_SERVER_CHANNEL, &grpc_http_server_filter);
}
void grpc_http_filters_shutdown(void) {}
} // namespace grpc_core

@ -25,8 +25,8 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/http2_errors.h"
/* If these settings change, make sure that we are not sending a GOAWAY for
@ -534,29 +534,27 @@ const grpc_channel_filter grpc_max_age_filter = {
grpc_channel_next_get_info,
"max_age"};
static bool maybe_add_max_age_filter(grpc_channel_stack_builder* builder,
void* /*arg*/) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
bool enable =
grpc_channel_arg_get_integer(
grpc_channel_args_find(channel_args, GRPC_ARG_MAX_CONNECTION_AGE_MS),
MAX_CONNECTION_AGE_INTEGER_OPTIONS) != INT_MAX ||
grpc_channel_arg_get_integer(
grpc_channel_args_find(channel_args, GRPC_ARG_MAX_CONNECTION_IDLE_MS),
MAX_CONNECTION_IDLE_INTEGER_OPTIONS) != INT_MAX;
if (enable) {
return grpc_channel_stack_builder_prepend_filter(
builder, &grpc_max_age_filter, nullptr, nullptr);
} else {
return true;
}
}
void grpc_max_age_filter_init(void) {
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_max_age_filter, nullptr);
namespace grpc_core {
void RegisterMaxAgeFilter(CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
[](grpc_channel_stack_builder* builder) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
bool enable = grpc_channel_arg_get_integer(
grpc_channel_args_find(
channel_args, GRPC_ARG_MAX_CONNECTION_AGE_MS),
MAX_CONNECTION_AGE_INTEGER_OPTIONS) != INT_MAX ||
grpc_channel_arg_get_integer(
grpc_channel_args_find(
channel_args, GRPC_ARG_MAX_CONNECTION_IDLE_MS),
MAX_CONNECTION_IDLE_INTEGER_OPTIONS) != INT_MAX;
if (enable) {
return grpc_channel_stack_builder_prepend_filter(
builder, &grpc_max_age_filter, nullptr, nullptr);
} else {
return true;
}
});
}
void grpc_max_age_filter_shutdown(void) {}
} // namespace grpc_core

@ -31,11 +31,11 @@
#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_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/ref_counted.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
static void recv_message_ready(void* user_data, grpc_error_handle error);
static void recv_trailing_metadata_ready(void* user_data,
@ -344,7 +344,7 @@ const grpc_channel_filter grpc_message_size_filter = {
// Used for GRPC_CLIENT_SUBCHANNEL
static bool maybe_add_message_size_filter_subchannel(
grpc_channel_stack_builder* builder, void* /*arg*/) {
grpc_channel_stack_builder* builder) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (grpc_channel_args_want_minimal_stack(channel_args)) {
@ -356,8 +356,7 @@ static bool maybe_add_message_size_filter_subchannel(
// Used for GRPC_CLIENT_DIRECT_CHANNEL and GRPC_SERVER_CHANNEL. Adds the filter
// only if message size limits or service config is specified.
static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder,
void* /*arg*/) {
static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (grpc_channel_args_want_minimal_stack(channel_args)) {
@ -384,16 +383,21 @@ static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder,
}
void grpc_message_size_filter_init(void) {
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter_subchannel, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter, nullptr);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter, nullptr);
grpc_core::MessageSizeParser::Register();
}
void grpc_message_size_filter_shutdown(void) {}
namespace grpc_core {
void RegisterMessageSizeFilter(CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter_subchannel);
builder->channel_init()->RegisterStage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter);
builder->channel_init()->RegisterStage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_message_size_filter);
}
} // namespace grpc_core

@ -24,7 +24,7 @@
#include "src/core/ext/filters/workarounds/workaround_utils.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/transport/metadata.h"
namespace {
@ -185,7 +185,7 @@ const grpc_channel_filter grpc_workaround_cronet_compression_filter = {
"workaround_cronet_compression"};
static bool register_workaround_cronet_compression(
grpc_channel_stack_builder* builder, void* /*arg*/) {
grpc_channel_stack_builder* builder) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
const grpc_arg* a = grpc_channel_args_find(
@ -201,11 +201,17 @@ static bool register_workaround_cronet_compression(
}
void grpc_workaround_cronet_compression_filter_init(void) {
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_WORKAROUND_PRIORITY_HIGH,
register_workaround_cronet_compression, nullptr);
grpc_register_workaround(GRPC_WORKAROUND_ID_CRONET_COMPRESSION,
parse_user_agent);
}
void grpc_workaround_cronet_compression_filter_shutdown(void) {}
namespace grpc_core {
void RegisterWorkaroundCronetCompressionFilter(
CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(
GRPC_SERVER_CHANNEL, GRPC_WORKAROUND_PRIORITY_HIGH,
register_workaround_cronet_compression);
}
} // namespace grpc_core

@ -47,7 +47,6 @@ grpc_cc_library(
"//:grpc",
"//:grpc++_base",
"//:grpc_base",
"//:grpc_base_c",
"//:grpc_codegen",
"//src/core/ext/transport/binder/transport:binder_transport",
"//src/core/ext/transport/binder/utils:transport_stream_receiver",
@ -68,7 +67,6 @@ grpc_cc_library(
"//:grpc",
"//:grpc++_base",
"//:grpc_base",
"//:grpc_base_c",
"//:grpc_codegen",
"//src/core/ext/transport/binder/transport:binder_transport",
"//src/core/ext/transport/binder/wire_format:binder",

@ -42,7 +42,7 @@ grpc_cc_library(
deps = [
"//:gpr_platform",
"//:grpc++_internals",
"//:grpc_base_c",
"//:grpc_base",
"//src/core/ext/transport/binder/transport:binder_transport",
"//src/core/ext/transport/binder/wire_format:binder",
"//src/core/ext/transport/binder/wire_format:binder_android",

@ -40,7 +40,7 @@ grpc_cc_library(
deps = [
"//:gpr_base",
"//:gpr_platform",
"//:grpc_base_c",
"//:grpc_base",
"//:slice_refcount",
"//src/core/ext/transport/binder/utils:transport_stream_receiver",
"//src/core/ext/transport/binder/wire_format:binder",

@ -32,7 +32,6 @@
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/surface/server.h"
#include "src/core/lib/transport/connectivity_state.h"
#include "src/core/lib/transport/error_utils.h"

@ -55,7 +55,6 @@
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/static_metadata.h"
#define GRPC_XDS_INITIAL_CONNECT_BACKOFF_SECONDS 1

@ -232,9 +232,7 @@ static void bind_transport(grpc_channel_stack* channel_stack,
grpc_transport_stream_size(static_cast<grpc_transport*>(t));
}
bool grpc_add_connected_filter(grpc_channel_stack_builder* builder,
void* arg_must_be_null) {
GPR_ASSERT(arg_must_be_null == nullptr);
bool grpc_add_connected_filter(grpc_channel_stack_builder* builder) {
grpc_transport* t = grpc_channel_stack_builder_get_transport(builder);
GPR_ASSERT(t != nullptr);
return grpc_channel_stack_builder_append_filter(

@ -25,8 +25,7 @@
extern const grpc_channel_filter grpc_connected_filter;
bool grpc_add_connected_filter(grpc_channel_stack_builder* builder,
void* arg_must_be_null);
bool grpc_add_connected_filter(grpc_channel_stack_builder* builder);
/* Debug helper to dig the transport stream out of a call element */
grpc_stream* grpc_connected_channel_get_stream(grpc_call_element* elem);

@ -12,13 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <grpc/impl/codegen/port_platform.h>
#include <grpc/support/port_platform.h>
#include "src/core/lib/config/core_configuration.h"
#include <grpc/support/log.h>
namespace grpc_core {
std::atomic<CoreConfiguration*> CoreConfiguration::config_{nullptr};
std::atomic<CoreConfiguration::RegisteredBuilder*> CoreConfiguration::builders_{
nullptr};
CoreConfiguration::Builder::Builder() = default;
@ -27,11 +31,42 @@ CoreConfiguration* CoreConfiguration::Builder::Build() {
}
CoreConfiguration::CoreConfiguration(Builder* builder)
: handshaker_registry_(builder->handshaker_registry_.Build()) {}
: channel_init_(builder->channel_init_.Build()),
handshaker_registry_(builder->handshaker_registry_.Build()) {}
void CoreConfiguration::RegisterBuilder(std::function<void(Builder*)> builder) {
GPR_ASSERT(config_.load(std::memory_order_relaxed) == nullptr &&
"CoreConfiguration was already instantiated before builder "
"registration was completed");
RegisteredBuilder* n = new RegisteredBuilder();
n->builder = std::move(builder);
n->next = builders_.load(std::memory_order_relaxed);
while (!builders_.compare_exchange_weak(n->next, n, std::memory_order_acq_rel,
std::memory_order_relaxed)) {
}
GPR_ASSERT(config_.load(std::memory_order_relaxed) == nullptr &&
"CoreConfiguration was already instantiated before builder "
"registration was completed");
}
const CoreConfiguration& CoreConfiguration::BuildNewAndMaybeSet() {
// Construct builder, pass it up to code that knows about build configuration
Builder builder;
// The linked list of builders stores things in reverse registration order.
// To get things registered as systems relying on this expect however, we
// actually need to run things in forward registration order, so we iterate
// once over the linked list to build a vector of builders, and then iterate
// over said vector in reverse to actually run the builders.
std::vector<RegisteredBuilder*> registered_builders;
for (RegisteredBuilder* b = builders_.load(std::memory_order_acquire);
b != nullptr; b = b->next) {
registered_builders.push_back(b);
}
for (auto it = registered_builders.rbegin(); it != registered_builders.rend();
++it) {
(*it)->builder(&builder);
}
// Finally, call the built in configuration builder.
BuildCoreConfiguration(&builder);
// Use builder to construct a confguration
CoreConfiguration* p = builder.Build();
@ -49,6 +84,13 @@ const CoreConfiguration& CoreConfiguration::BuildNewAndMaybeSet() {
void CoreConfiguration::Reset() {
delete config_.exchange(nullptr, std::memory_order_acquire);
RegisteredBuilder* builder =
builders_.exchange(nullptr, std::memory_order_acquire);
while (builder != nullptr) {
RegisteredBuilder* next = builder->next;
delete builder;
builder = next;
}
}
} // namespace grpc_core

@ -20,6 +20,7 @@
#include <atomic>
#include "src/core/lib/channel/handshaker_registry.h"
#include "src/core/lib/surface/channel_init.h"
namespace grpc_core {
@ -34,6 +35,8 @@ class CoreConfiguration {
// their configuration and assemble the published CoreConfiguration.
class Builder {
public:
ChannelInit::Builder* channel_init() { return &channel_init_; }
HandshakerRegistry::Builder* handshaker_registry() {
return &handshaker_registry_;
}
@ -41,6 +44,7 @@ class CoreConfiguration {
private:
friend class CoreConfiguration;
ChannelInit::Builder channel_init_;
HandshakerRegistry::Builder handshaker_registry_;
Builder();
@ -77,13 +81,38 @@ class CoreConfiguration {
delete config_.exchange(p, std::memory_order_release);
}
// Attach a registration function globally.
// Each registration function is called *in addition to*
// BuildCoreConfiguration for the default core configuration. When using
// BuildSpecialConfiguration, one can use CallRegisteredBuilders to call them.
// Must be called before a configuration is built.
static void RegisterBuilder(std::function<void(Builder*)> builder);
// Call all registered builders.
// See RegisterBuilder for why you might want to call this.
static void CallRegisteredBuilders(Builder* builder);
// Drop the core configuration. Users must ensure no other threads are
// accessing the configuration.
// Clears any dynamically registered builders.
static void Reset();
// Helper for tests: Reset the configuration, build a special one, run some
// code, and then reset the configuration again.
// Templatized to be sure no codegen in normal builds.
template <typename BuildFunc, typename RunFunc>
static void RunWithSpecialConfiguration(BuildFunc build_configuration,
RunFunc code_to_run) {
Reset();
BuildSpecialConfiguration(build_configuration);
code_to_run();
Reset();
}
// Accessors
const ChannelInit& channel_init() const { return channel_init_; }
const HandshakerRegistry& handshaker_registry() const {
return handshaker_registry_;
}
@ -91,13 +120,22 @@ class CoreConfiguration {
private:
explicit CoreConfiguration(Builder* builder);
// Stores a builder for RegisterBuilder
struct RegisteredBuilder {
std::function<void(Builder*)> builder;
RegisteredBuilder* next;
};
// Create a new CoreConfiguration, and either set it or throw it away.
// We allow multiple CoreConfiguration's to be created in parallel.
static const CoreConfiguration& BuildNewAndMaybeSet();
// The configuration
static std::atomic<CoreConfiguration*> config_;
// Extra registered builders
static std::atomic<RegisteredBuilder*> builders_;
ChannelInit channel_init_;
HandshakerRegistry handshaker_registry_;
};

@ -0,0 +1,49 @@
// Copyright 2021 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <grpc/impl/codegen/port_platform.h>
#include "src/core/lib/surface/builtins.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/lame_client.h"
#include "src/core/lib/surface/server.h"
namespace grpc_core {
void RegisterBuiltins(CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter);
builder->channel_init()->RegisterStage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter);
builder->channel_init()->RegisterStage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter);
builder->channel_init()->RegisterStage(
GRPC_CLIENT_LAME_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
[](grpc_channel_stack_builder* builder) {
return grpc_channel_stack_builder_append_filter(
builder, &grpc_lame_filter, nullptr, nullptr);
});
builder->channel_init()->RegisterStage(
GRPC_SERVER_CHANNEL, INT_MAX, [](grpc_channel_stack_builder* builder) {
return grpc_channel_stack_builder_prepend_filter(
builder, &grpc_core::Server::kServerTopFilter, nullptr, nullptr);
});
}
} // namespace grpc_core

@ -0,0 +1,26 @@
// Copyright 2021 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_CORE_LIB_SURFACE_BUILTINS_H
#define GRPC_CORE_LIB_SURFACE_BUILTINS_H
#include <grpc/impl/codegen/port_platform.h>
#include "src/core/lib/config/core_configuration.h"
namespace grpc_core {
void RegisterBuiltins(CoreConfiguration::Builder* builder);
} // namespace grpc_core
#endif // GRPC_CORE_LIB_SURFACE_BUILTINS_H

@ -34,6 +34,7 @@
#include "src/core/lib/channel/channel_trace.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/channel/channelz_registry.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/manual_constructor.h"
@ -44,7 +45,6 @@
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/static_metadata.h"
/** Cache grpc-status: X mdelems for X = 0..NUM_CACHED_STATUS_ELEMS.
@ -269,7 +269,8 @@ grpc_channel* grpc_channel_create(const char* target,
grpc_channel_args_destroy(args);
grpc_channel_stack_builder_set_target(builder, target);
grpc_channel_stack_builder_set_transport(builder, optional_transport);
if (!grpc_channel_init_create_stack(builder, channel_stack_type)) {
if (!grpc_core::CoreConfiguration::Get().channel_init().CreateStack(
builder, channel_stack_type)) {
grpc_channel_stack_builder_destroy(builder);
if (resource_user != nullptr) {
if (preallocated_bytes > 0) {

@ -20,91 +20,37 @@
#include "src/core/lib/surface/channel_init.h"
#include <grpc/support/alloc.h>
#include <algorithm>
typedef struct stage_slot {
grpc_channel_init_stage fn;
void* arg;
int priority;
size_t insertion_order;
} stage_slot;
namespace grpc_core {
typedef struct stage_slots {
stage_slot* slots;
size_t num_slots;
size_t cap_slots;
} stage_slots;
static stage_slots g_slots[GRPC_NUM_CHANNEL_STACK_TYPES];
static bool g_finalized;
void grpc_channel_init_init(void) {
for (int i = 0; i < GRPC_NUM_CHANNEL_STACK_TYPES; i++) {
g_slots[i].slots = nullptr;
g_slots[i].num_slots = 0;
g_slots[i].cap_slots = 0;
}
g_finalized = false;
}
void grpc_channel_init_register_stage(grpc_channel_stack_type type,
int priority,
grpc_channel_init_stage stage,
void* stage_arg) {
GPR_ASSERT(!g_finalized);
if (g_slots[type].cap_slots == g_slots[type].num_slots) {
g_slots[type].cap_slots =
std::max(size_t(8), 3 * g_slots[type].cap_slots / 2);
g_slots[type].slots = static_cast<stage_slot*>(
gpr_realloc(g_slots[type].slots,
g_slots[type].cap_slots * sizeof(*g_slots[type].slots)));
}
stage_slot* s = &g_slots[type].slots[g_slots[type].num_slots++];
s->insertion_order = g_slots[type].num_slots;
s->priority = priority;
s->fn = stage;
s->arg = stage_arg;
}
static int compare_slots(const void* a, const void* b) {
const stage_slot* sa = static_cast<const stage_slot*>(a);
const stage_slot* sb = static_cast<const stage_slot*>(b);
int c = grpc_core::QsortCompare(sa->priority, sb->priority);
if (c != 0) return c;
return grpc_core::QsortCompare(sa->insertion_order, sb->insertion_order);
void ChannelInit::Builder::RegisterStage(grpc_channel_stack_type type,
int priority, Stage stage) {
slots_[type].emplace_back(std::move(stage), priority);
}
void grpc_channel_init_finalize(void) {
GPR_ASSERT(!g_finalized);
ChannelInit ChannelInit::Builder::Build() {
ChannelInit result;
for (int i = 0; i < GRPC_NUM_CHANNEL_STACK_TYPES; i++) {
qsort(g_slots[i].slots, g_slots[i].num_slots, sizeof(*g_slots[i].slots),
compare_slots);
}
g_finalized = true;
}
void grpc_channel_init_shutdown(void) {
for (int i = 0; i < GRPC_NUM_CHANNEL_STACK_TYPES; i++) {
gpr_free(g_slots[i].slots);
g_slots[i].slots =
static_cast<stage_slot*>(reinterpret_cast<void*>(0xdeadbeef));
auto& slots = slots_[i];
std::stable_sort(
slots.begin(), slots.end(),
[](const Slot& a, const Slot& b) { return a.priority < b.priority; });
auto& result_slots = result.slots_[i];
result_slots.reserve(slots.size());
for (auto& slot : slots) {
result_slots.emplace_back(std::move(slot.stage));
}
}
return result;
}
bool grpc_channel_init_create_stack(grpc_channel_stack_builder* builder,
grpc_channel_stack_type type) {
GPR_ASSERT(g_finalized);
grpc_channel_stack_builder_set_name(builder,
grpc_channel_stack_type_string(type));
for (size_t i = 0; i < g_slots[type].num_slots; i++) {
const stage_slot* slot = &g_slots[type].slots[i];
if (!slot->fn(builder, slot->arg)) {
return false;
}
bool ChannelInit::CreateStack(grpc_channel_stack_builder* builder,
grpc_channel_stack_type type) const {
for (const auto& stage : slots_[type]) {
if (!stage(builder)) return false;
}
return true;
}
} // namespace grpc_core

@ -21,9 +21,10 @@
#include <grpc/support/port_platform.h>
#include "src/core/lib/channel/channel_stack_builder.h"
#include <functional>
#include <vector>
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/transport/transport.h"
#define GRPC_CHANNEL_INIT_BUILTIN_PRIORITY 10000
@ -32,47 +33,54 @@
/// It also provides a universal entry path to run those mutators to build
/// a channel stack for various subsystems.
/// One stage of mutation: call functions against \a builder to influence the
/// finally constructed channel stack
typedef bool (*grpc_channel_init_stage)(grpc_channel_stack_builder* builder,
void* arg);
/// Global initialization of the system
void grpc_channel_init_init(void);
/// Register one stage of mutators.
/// Stages are run in priority order (lowest to highest), and then in
/// registration order (in the case of a tie).
/// Stages are registered against one of the pre-determined channel stack
/// types.
/// If the channel stack type is GRPC_CLIENT_SUBCHANNEL, the caller should
/// ensure that subchannels with different filter lists will always have
/// different channel args. This requires setting a channel arg in case the
/// registration function relies on some condition other than channel args to
/// decide whether to add a filter or not.
void grpc_channel_init_register_stage(grpc_channel_stack_type type,
int priority,
grpc_channel_init_stage stage_fn,
void* stage_arg);
/// Finalize registration. No more calls to grpc_channel_init_register_stage are
/// allowed.
void grpc_channel_init_finalize(void);
/// Shutdown the channel init system
void grpc_channel_init_shutdown(void);
/// Construct a channel stack of some sort: see channel_stack.h for details
/// \a type is the type of channel stack to create
/// \a prefix_bytes is the number of bytes before the channel stack to allocate
/// \a args are configuration arguments for the channel stack
/// \a initial_refs is the initial refcount to give the channel stack
/// \a destroy and \a destroy_arg specify how to destroy the channel stack
/// if destroy_arg is NULL, the returned value from this function will be
/// substituted
/// \a optional_transport is either NULL or a constructed transport object
/// Returns a pointer to the base of the memory allocated (the actual channel
/// stack object will be prefix_bytes past that pointer)
bool grpc_channel_init_create_stack(grpc_channel_stack_builder* builder,
grpc_channel_stack_type type);
typedef struct grpc_channel_stack_builder grpc_channel_stack_builder;
namespace grpc_core {
class ChannelInit {
public:
/// One stage of mutation: call functions against \a builder to influence the
/// finally constructed channel stack
using Stage = std::function<bool(grpc_channel_stack_builder* builder)>;
class Builder {
public:
/// Register one stage of mutators.
/// Stages are run in priority order (lowest to highest), and then in
/// registration order (in the case of a tie).
/// Stages are registered against one of the pre-determined channel stack
/// types.
/// If the channel stack type is GRPC_CLIENT_SUBCHANNEL, the caller should
/// ensure that subchannels with different filter lists will always have
/// different channel args. This requires setting a channel arg in case the
/// registration function relies on some condition other than channel args
/// to decide whether to add a filter or not.
void RegisterStage(grpc_channel_stack_type type, int priority, Stage stage);
/// Finalize registration. No more calls to grpc_channel_init_register_stage
/// are allowed.
ChannelInit Build();
private:
struct Slot {
Slot(Stage stage, int priority)
: stage(std::move(stage)), priority(priority) {}
Stage stage;
int priority;
};
std::vector<Slot> slots_[GRPC_NUM_CHANNEL_STACK_TYPES];
};
/// Construct a channel stack of some sort: see channel_stack.h for details
/// \a type is the type of channel stack to create
/// \a builder is the channel stack builder to build into.
bool CreateStack(grpc_channel_stack_builder* builder,
grpc_channel_stack_type type) const;
private:
std::vector<Stage> slots_[GRPC_NUM_CHANNEL_STACK_TYPES];
};
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H */

@ -48,7 +48,6 @@
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/completion_queue.h"
#include "src/core/lib/surface/lame_client.h"
#include "src/core/lib/surface/server.h"
@ -77,34 +76,6 @@ static void do_basic_init(void) {
gpr_time_init();
}
static bool append_filter(grpc_channel_stack_builder* builder, void* arg) {
return grpc_channel_stack_builder_append_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
}
static bool prepend_filter(grpc_channel_stack_builder* builder, void* arg) {
return grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
}
static void register_builtin_channel_init() {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter, nullptr);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter, nullptr);
grpc_channel_init_register_stage(
GRPC_CLIENT_LAME_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
append_filter, const_cast<grpc_channel_filter*>(&grpc_lame_filter));
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, INT_MAX, prepend_filter,
const_cast<grpc_channel_filter*>(&grpc_core::Server::kServerTopFilter));
}
typedef struct grpc_plugin {
void (*init)();
void (*destroy)();
@ -136,7 +107,6 @@ void grpc_init(void) {
grpc_stats_init();
grpc_slice_intern_init();
grpc_mdctx_global_init();
grpc_channel_init_init();
grpc_core::channelz::ChannelzRegistry::Init();
grpc_security_pre_init();
grpc_core::ApplicationCallbackExecCtx::GlobalInit();
@ -148,13 +118,7 @@ void grpc_init(void) {
g_all_of_the_plugins[i].init();
}
}
/* register channel finalization AFTER all plugins, to ensure that it's run
* at the appropriate time */
grpc_register_security_filters();
register_builtin_channel_init();
grpc_tracer_init();
/* no more changes to channel init pipelines */
grpc_channel_init_finalize();
grpc_iomgr_start();
}

@ -21,6 +21,8 @@
#include <limits.h>
#include <string.h>
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/security/authorization/sdk_server_authz_filter.h"
#include "src/core/lib/security/context/security_context.h"
@ -30,14 +32,13 @@
#include "src/core/lib/security/transport/auth_filters.h"
#include "src/core/lib/security/transport/secure_endpoint.h"
#include "src/core/lib/security/transport/security_handshaker.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/init.h"
#include "src/core/tsi/transport_security_interface.h"
void grpc_security_pre_init(void) {}
static bool maybe_prepend_client_auth_filter(
grpc_channel_stack_builder* builder, void* /*arg*/) {
grpc_channel_stack_builder* builder) {
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (args) {
@ -52,7 +53,7 @@ static bool maybe_prepend_client_auth_filter(
}
static bool maybe_prepend_server_auth_filter(
grpc_channel_stack_builder* builder, void* /*arg*/) {
grpc_channel_stack_builder* builder) {
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (args) {
@ -67,7 +68,7 @@ static bool maybe_prepend_server_auth_filter(
}
static bool maybe_prepend_sdk_server_authz_filter(
grpc_channel_stack_builder* builder, void* /*arg*/) {
grpc_channel_stack_builder* builder) {
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
const auto* provider =
@ -81,20 +82,22 @@ static bool maybe_prepend_sdk_server_authz_filter(
return true;
}
void grpc_register_security_filters(void) {
namespace grpc_core {
void RegisterSecurityFilters(CoreConfiguration::Builder* builder) {
// Register the auth client with a priority < INT_MAX to allow the authority
// filter -on which the auth filter depends- to be higher on the channel
// stack.
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX - 1,
maybe_prepend_client_auth_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX - 1,
maybe_prepend_client_auth_filter, nullptr);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX - 1,
maybe_prepend_server_auth_filter, nullptr);
builder->channel_init()->RegisterStage(GRPC_CLIENT_SUBCHANNEL, INT_MAX - 1,
maybe_prepend_client_auth_filter);
builder->channel_init()->RegisterStage(GRPC_CLIENT_DIRECT_CHANNEL,
INT_MAX - 1,
maybe_prepend_client_auth_filter);
builder->channel_init()->RegisterStage(GRPC_SERVER_CHANNEL, INT_MAX - 1,
maybe_prepend_server_auth_filter);
// Register the SdkServerAuthzFilter with a priority less than
// server_auth_filter to allow server_auth_filter on which the sdk filter
// depends on to be higher on the channel stack.
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX - 2,
maybe_prepend_sdk_server_authz_filter,
nullptr);
builder->channel_init()->RegisterStage(GRPC_SERVER_CHANNEL, INT_MAX - 2,
maybe_prepend_sdk_server_authz_filter);
}
} // namespace grpc_core

@ -21,13 +21,10 @@
#include <grpc/grpc.h>
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/builtins.h"
void grpc_http_filters_init(void);
void grpc_http_filters_shutdown(void);
void grpc_chttp2_plugin_init(void);
void grpc_chttp2_plugin_shutdown(void);
void grpc_deadline_filter_init(void);
void grpc_deadline_filter_shutdown(void);
void grpc_client_channel_init(void);
void grpc_client_channel_shutdown(void);
void grpc_inproc_plugin_init(void);
@ -50,16 +47,8 @@ void grpc_resolver_dns_native_init(void);
void grpc_resolver_dns_native_shutdown(void);
void grpc_resolver_sockaddr_init(void);
void grpc_resolver_sockaddr_shutdown(void);
void grpc_client_idle_filter_init(void);
void grpc_client_idle_filter_shutdown(void);
void grpc_max_age_filter_init(void);
void grpc_max_age_filter_shutdown(void);
void grpc_message_size_filter_init(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_shutdown(void);
void grpc_workaround_cronet_compression_filter_init(void);
void grpc_workaround_cronet_compression_filter_shutdown(void);
namespace grpc_core {
@ -93,22 +82,14 @@ void grpc_resolver_xds_shutdown(void);
namespace grpc_core {
void GoogleCloud2ProdResolverInit();
void GoogleCloud2ProdResolverShutdown();
}
} // namespace grpc_core
#endif
void grpc_register_built_in_plugins(void) {
grpc_register_plugin(grpc_http_filters_init,
grpc_http_filters_shutdown);
grpc_register_plugin(grpc_chttp2_plugin_init,
grpc_chttp2_plugin_shutdown);
grpc_register_plugin(grpc_deadline_filter_init,
grpc_deadline_filter_shutdown);
grpc_register_plugin(grpc_client_channel_init,
grpc_client_channel_shutdown);
grpc_register_plugin(grpc_inproc_plugin_init,
grpc_inproc_plugin_shutdown);
grpc_register_plugin(grpc_resolver_fake_init,
grpc_resolver_fake_shutdown);
grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown);
grpc_register_plugin(grpc_client_channel_init, grpc_client_channel_shutdown);
grpc_register_plugin(grpc_inproc_plugin_init, grpc_inproc_plugin_shutdown);
grpc_register_plugin(grpc_resolver_fake_init, grpc_resolver_fake_shutdown);
grpc_register_plugin(grpc_lb_policy_grpclb_init,
grpc_lb_policy_grpclb_shutdown);
grpc_register_plugin(grpc_lb_policy_priority_init,
@ -127,18 +108,10 @@ void grpc_register_built_in_plugins(void) {
grpc_resolver_dns_native_shutdown);
grpc_register_plugin(grpc_resolver_sockaddr_init,
grpc_resolver_sockaddr_shutdown);
grpc_register_plugin(grpc_client_idle_filter_init,
grpc_client_idle_filter_shutdown);
grpc_register_plugin(grpc_max_age_filter_init,
grpc_max_age_filter_shutdown);
grpc_register_plugin(grpc_message_size_filter_init,
grpc_message_size_filter_shutdown);
grpc_register_plugin(grpc_core::FaultInjectionFilterInit,
grpc_core::FaultInjectionFilterShutdown);
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_client_authority_filter_shutdown);
grpc_register_plugin(grpc_workaround_cronet_compression_filter_init,
grpc_workaround_cronet_compression_filter_shutdown);
#ifndef GRPC_NO_XDS
@ -148,16 +121,14 @@ void grpc_register_built_in_plugins(void) {
grpc_certificate_provider_registry_shutdown);
grpc_register_plugin(grpc_core::FileWatcherCertificateProviderInit,
grpc_core::FileWatcherCertificateProviderShutdown);
grpc_register_plugin(grpc_lb_policy_cds_init,
grpc_lb_policy_cds_shutdown);
grpc_register_plugin(grpc_lb_policy_cds_init, grpc_lb_policy_cds_shutdown);
grpc_register_plugin(grpc_lb_policy_xds_cluster_impl_init,
grpc_lb_policy_xds_cluster_impl_shutdown);
grpc_register_plugin(grpc_lb_policy_xds_cluster_resolver_init,
grpc_lb_policy_xds_cluster_resolver_shutdown);
grpc_register_plugin(grpc_lb_policy_xds_cluster_manager_init,
grpc_lb_policy_xds_cluster_manager_shutdown);
grpc_register_plugin(grpc_resolver_xds_init,
grpc_resolver_xds_shutdown);
grpc_register_plugin(grpc_resolver_xds_init, grpc_resolver_xds_shutdown);
grpc_register_plugin(grpc_core::GoogleCloud2ProdResolverInit,
grpc_core::GoogleCloud2ProdResolverShutdown);
#endif
@ -165,12 +136,40 @@ void grpc_register_built_in_plugins(void) {
namespace grpc_core {
extern void BuildClientChannelConfiguration(CoreConfiguration::Builder* builder);
extern void SecurityRegisterHandshakerFactories(CoreConfiguration::Builder* builder);
extern void BuildClientChannelConfiguration(
CoreConfiguration::Builder* builder);
extern void SecurityRegisterHandshakerFactories(
CoreConfiguration::Builder* builder);
extern void RegisterClientAuthorityFilter(CoreConfiguration::Builder* builder);
extern void RegisterClientIdleFilter(CoreConfiguration::Builder* builder);
extern void RegisterDeadlineFilter(CoreConfiguration::Builder* builder);
extern void RegisterGrpcLbLoadReportingFilter(
CoreConfiguration::Builder* builder);
extern void RegisterHttpFilters(CoreConfiguration::Builder* builder);
extern void RegisterMaxAgeFilter(CoreConfiguration::Builder* builder);
extern void RegisterMessageSizeFilter(CoreConfiguration::Builder* builder);
extern void RegisterSecurityFilters(CoreConfiguration::Builder* builder);
extern void RegisterServiceConfigChannelArgFilter(
CoreConfiguration::Builder* builder);
extern void RegisterWorkaroundCronetCompressionFilter(
CoreConfiguration::Builder* builder);
void BuildCoreConfiguration(CoreConfiguration::Builder* builder) {
BuildClientChannelConfiguration(builder);
SecurityRegisterHandshakerFactories(builder);
RegisterClientAuthorityFilter(builder);
RegisterClientIdleFilter(builder);
RegisterGrpcLbLoadReportingFilter(builder);
RegisterHttpFilters(builder);
RegisterMaxAgeFilter(builder);
RegisterDeadlineFilter(builder);
RegisterMessageSizeFilter(builder);
RegisterWorkaroundCronetCompressionFilter(builder);
RegisterServiceConfigChannelArgFilter(builder);
// Run last so it gets a consistent location.
// TODO(ctiller): Is this actually necessary?
RegisterSecurityFilters(builder);
RegisterBuiltins(builder);
}
} // namespace grpc_core

@ -21,13 +21,10 @@
#include <grpc/grpc.h>
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/builtins.h"
void grpc_http_filters_init(void);
void grpc_http_filters_shutdown(void);
void grpc_chttp2_plugin_init(void);
void grpc_chttp2_plugin_shutdown(void);
void grpc_deadline_filter_init(void);
void grpc_deadline_filter_shutdown(void);
void grpc_client_channel_init(void);
void grpc_client_channel_shutdown(void);
void grpc_inproc_plugin_init(void);
@ -50,10 +47,6 @@ void grpc_lb_policy_pick_first_init(void);
void grpc_lb_policy_pick_first_shutdown(void);
void grpc_lb_policy_round_robin_init(void);
void grpc_lb_policy_round_robin_shutdown(void);
void grpc_client_idle_filter_init(void);
void grpc_client_idle_filter_shutdown(void);
void grpc_max_age_filter_init(void);
void grpc_max_age_filter_shutdown(void);
void grpc_message_size_filter_init(void);
void grpc_message_size_filter_shutdown(void);
namespace grpc_core {
@ -62,32 +55,20 @@ void FaultInjectionFilterShutdown(void);
void GrpcLbPolicyRingHashInit(void);
void GrpcLbPolicyRingHashShutdown(void);
} // namespace grpc_core
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_shutdown(void);
void grpc_workaround_cronet_compression_filter_init(void);
void grpc_workaround_cronet_compression_filter_shutdown(void);
void grpc_register_built_in_plugins(void) {
grpc_register_plugin(grpc_http_filters_init,
grpc_http_filters_shutdown);
grpc_register_plugin(grpc_chttp2_plugin_init,
grpc_chttp2_plugin_shutdown);
grpc_register_plugin(grpc_deadline_filter_init,
grpc_deadline_filter_shutdown);
grpc_register_plugin(grpc_client_channel_init,
grpc_client_channel_shutdown);
grpc_register_plugin(grpc_inproc_plugin_init,
grpc_inproc_plugin_shutdown);
grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown);
grpc_register_plugin(grpc_client_channel_init, grpc_client_channel_shutdown);
grpc_register_plugin(grpc_inproc_plugin_init, grpc_inproc_plugin_shutdown);
grpc_register_plugin(grpc_resolver_dns_ares_init,
grpc_resolver_dns_ares_shutdown);
grpc_register_plugin(grpc_resolver_dns_native_init,
grpc_resolver_dns_native_shutdown);
grpc_register_plugin(grpc_resolver_sockaddr_init,
grpc_resolver_sockaddr_shutdown);
grpc_register_plugin(grpc_resolver_fake_init,
grpc_resolver_fake_shutdown);
grpc_register_plugin(grpc_resolver_fake_init, grpc_resolver_fake_shutdown);
grpc_register_plugin(grpc_lb_policy_grpclb_init,
grpc_lb_policy_grpclb_shutdown);
grpc_register_plugin(grpc_lb_policy_priority_init,
@ -100,28 +81,46 @@ void grpc_register_built_in_plugins(void) {
grpc_lb_policy_round_robin_shutdown);
grpc_register_plugin(grpc_core::GrpcLbPolicyRingHashInit,
grpc_core::GrpcLbPolicyRingHashShutdown);
grpc_register_plugin(grpc_client_idle_filter_init,
grpc_client_idle_filter_shutdown);
grpc_register_plugin(grpc_max_age_filter_init,
grpc_max_age_filter_shutdown);
grpc_register_plugin(grpc_message_size_filter_init,
grpc_message_size_filter_shutdown);
grpc_register_plugin(grpc_core::FaultInjectionFilterInit,
grpc_core::FaultInjectionFilterShutdown);
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_client_authority_filter_shutdown);
grpc_register_plugin(grpc_workaround_cronet_compression_filter_init,
grpc_workaround_cronet_compression_filter_shutdown);
}
namespace grpc_core {
extern void BuildClientChannelConfiguration(CoreConfiguration::Builder* builder);
extern void BuildClientChannelConfiguration(
CoreConfiguration::Builder* builder);
extern void RegisterClientAuthorityFilter(CoreConfiguration::Builder* builder);
extern void RegisterClientIdleFilter(CoreConfiguration::Builder* builder);
extern void RegisterDeadlineFilter(CoreConfiguration::Builder* builder);
extern void RegisterGrpcLbLoadReportingFilter(
CoreConfiguration::Builder* builder);
extern void RegisterHttpFilters(CoreConfiguration::Builder* builder);
extern void RegisterMaxAgeFilter(CoreConfiguration::Builder* builder);
extern void RegisterMessageSizeFilter(CoreConfiguration::Builder* builder);
extern void RegisterSecurityFilters(CoreConfiguration::Builder* builder);
extern void RegisterServiceConfigChannelArgFilter(
CoreConfiguration::Builder* builder);
extern void RegisterWorkaroundCronetCompressionFilter(
CoreConfiguration::Builder* builder);
void BuildCoreConfiguration(CoreConfiguration::Builder* builder) {
BuildClientChannelConfiguration(builder);
RegisterClientAuthorityFilter(builder);
RegisterClientIdleFilter(builder);
RegisterGrpcLbLoadReportingFilter(builder);
RegisterHttpFilters(builder);
RegisterMaxAgeFilter(builder);
RegisterDeadlineFilter(builder);
RegisterMessageSizeFilter(builder);
RegisterWorkaroundCronetCompressionFilter(builder);
RegisterServiceConfigChannelArgFilter(builder);
// Run last so it gets a consistent location.
// TODO(ctiller): Is this actually necessary?
RegisterBuiltins(builder);
}
}
} // namespace grpc_core

@ -23,6 +23,8 @@
#include <grpcpp/impl/codegen/slice.h>
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
namespace grpc {
@ -61,38 +63,30 @@ void CallData::SetPollsetOrPollsetSet(grpc_call_element* elem,
grpc_call_stack_ignore_set_pollset_or_pollset_set(elem, pollent);
}
// internal code used by RegisterChannelFilter()
namespace internal {
// Note: Implicitly initialized to nullptr due to static lifetime.
std::vector<FilterRecord>* channel_filters;
namespace {
bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* arg) {
const FilterRecord& filter = *static_cast<FilterRecord*>(arg);
if (filter.include_filter) {
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (!filter.include_filter(*args)) return true;
}
return grpc_channel_stack_builder_prepend_filter(builder, &filter.filter,
nullptr, nullptr);
void RegisterChannelFilter(
grpc_channel_stack_type stack_type, int priority,
std::function<bool(const grpc_channel_args&)> include_filter,
const grpc_channel_filter* filter) {
auto maybe_add_filter = [include_filter,
filter](grpc_channel_stack_builder* builder) {
if (include_filter != nullptr) {
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (!include_filter(*args)) return true;
}
return grpc_channel_stack_builder_prepend_filter(builder, filter, nullptr,
nullptr);
};
grpc_core::CoreConfiguration::RegisterBuilder(
[stack_type, priority,
maybe_add_filter](grpc_core::CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(stack_type, priority,
maybe_add_filter);
});
}
} // namespace
void ChannelFilterPluginInit() {
for (size_t i = 0; i < channel_filters->size(); ++i) {
FilterRecord& filter = (*channel_filters)[i];
grpc_channel_init_register_stage(filter.stack_type, filter.priority,
MaybeAddFilter, &filter);
}
}
void ChannelFilterPluginShutdown() {}
} // namespace internal
} // namespace grpc

@ -306,16 +306,10 @@ class ChannelFilter final {
}
};
struct FilterRecord {
grpc_channel_stack_type stack_type;
int priority;
std::function<bool(const grpc_channel_args&)> include_filter;
grpc_channel_filter filter;
};
extern std::vector<FilterRecord>* channel_filters;
void ChannelFilterPluginInit();
void ChannelFilterPluginShutdown();
void RegisterChannelFilter(
grpc_channel_stack_type stack_type, int priority,
std::function<bool(const grpc_channel_args&)> include_filter,
const grpc_channel_filter* filter);
} // namespace internal
@ -333,26 +327,21 @@ template <typename ChannelDataType, typename CallDataType>
void RegisterChannelFilter(
const char* name, grpc_channel_stack_type stack_type, int priority,
std::function<bool(const grpc_channel_args&)> include_filter) {
// If we haven't been called before, initialize channel_filters and
// call grpc_register_plugin().
if (internal::channel_filters == nullptr) {
grpc_register_plugin(internal::ChannelFilterPluginInit,
internal::ChannelFilterPluginShutdown);
internal::channel_filters = new std::vector<internal::FilterRecord>();
}
// Add an entry to channel_filters. The filter will be added when the
// C-core initialization code calls ChannelFilterPluginInit().
typedef internal::ChannelFilter<ChannelDataType, CallDataType> FilterType;
internal::FilterRecord filter_record = {
stack_type,
priority,
include_filter,
{FilterType::StartTransportStreamOpBatch, FilterType::StartTransportOp,
FilterType::call_data_size, FilterType::InitCallElement,
FilterType::SetPollsetOrPollsetSet, FilterType::DestroyCallElement,
FilterType::channel_data_size, FilterType::InitChannelElement,
FilterType::DestroyChannelElement, FilterType::GetChannelInfo, name}};
internal::channel_filters->push_back(filter_record);
using FilterType = internal::ChannelFilter<ChannelDataType, CallDataType>;
static const grpc_channel_filter filter = {
FilterType::StartTransportStreamOpBatch,
FilterType::StartTransportOp,
FilterType::call_data_size,
FilterType::InitCallElement,
FilterType::SetPollsetOrPollsetSet,
FilterType::DestroyCallElement,
FilterType::channel_data_size,
FilterType::InitChannelElement,
FilterType::DestroyChannelElement,
FilterType::GetChannelInfo,
name};
grpc::internal::RegisterChannelFilter(stack_type, priority,
std::move(include_filter), &filter);
}
} // namespace grpc

@ -579,6 +579,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/slice/slice_string_helpers.cc',
'src/core/lib/slice/static_slice.cc',
'src/core/lib/surface/api_trace.cc',
'src/core/lib/surface/builtins.cc',
'src/core/lib/surface/byte_buffer.cc',
'src/core/lib/surface/byte_buffer_reader.cc',
'src/core/lib/surface/call.cc',

@ -25,6 +25,7 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/channel_init.h"
#include "test/core/util/test_config.h"
@ -92,38 +93,29 @@ const grpc_channel_filter original_filter = {
grpc_channel_next_get_info,
"filter_name"};
static bool add_replacement_filter(grpc_channel_stack_builder* builder,
void* arg) {
const grpc_channel_filter* filter =
static_cast<const grpc_channel_filter*>(arg);
static bool add_replacement_filter(grpc_channel_stack_builder* builder) {
// Get rid of any other version of the filter, as determined by having the
// same name.
GPR_ASSERT(grpc_channel_stack_builder_remove_filter(builder, filter->name));
GPR_ASSERT(grpc_channel_stack_builder_remove_filter(builder,
replacement_filter.name));
return grpc_channel_stack_builder_prepend_filter(
builder, filter, set_arg_once_fn, &g_replacement_fn_called);
builder, &replacement_filter, set_arg_once_fn, &g_replacement_fn_called);
}
static bool add_original_filter(grpc_channel_stack_builder* builder,
void* arg) {
static bool add_original_filter(grpc_channel_stack_builder* builder) {
return grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg), set_arg_once_fn,
&g_original_fn_called);
builder, &original_filter, set_arg_once_fn, &g_original_fn_called);
}
static void init_plugin(void) {
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, INT_MAX, add_original_filter,
const_cast<grpc_channel_filter*>(&original_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, INT_MAX, add_replacement_filter,
const_cast<grpc_channel_filter*>(&replacement_filter));
}
static void destroy_plugin(void) {}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(argc, argv);
grpc_register_plugin(init_plugin, destroy_plugin);
grpc_core::CoreConfiguration::RegisterBuilder(
[](grpc_core::CoreConfiguration::Builder* builder) {
builder->channel_init()->RegisterStage(GRPC_CLIENT_CHANNEL, INT_MAX,
add_original_filter);
builder->channel_init()->RegisterStage(GRPC_CLIENT_CHANNEL, INT_MAX,
add_replacement_filter);
});
grpc_init();
test_channel_stack_builder_filter_replace();
grpc_shutdown();

@ -40,6 +40,7 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/surface/channel_stack_type.h"
@ -138,7 +139,7 @@ static int check_stack(const char* file, int line, const char* transport_name,
{
grpc_core::ExecCtx exec_ctx;
grpc_channel_stack_builder_set_channel_arguments(builder, channel_args);
GPR_ASSERT(grpc_channel_init_create_stack(
GPR_ASSERT(grpc_core::CoreConfiguration::Get().channel_init().CreateStack(
builder, (grpc_channel_stack_type)channel_stack_type));
}

@ -26,12 +26,11 @@
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/channel_init.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
static bool g_enable_filter = false;
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
@ -251,29 +250,17 @@ static const grpc_channel_filter test_filter = {
* Registration
*/
static bool maybe_add_filter(grpc_channel_stack_builder* builder,
void* /*arg*/) {
if (g_enable_filter) {
return grpc_channel_stack_builder_prepend_filter(builder, &test_filter,
nullptr, nullptr);
} else {
return true;
}
}
static void init_plugin(void) {
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, 0, maybe_add_filter,
nullptr);
}
static void destroy_plugin(void) {}
void filter_causes_close(grpc_end2end_test_config config) {
g_enable_filter = true;
test_request(config);
g_enable_filter = false;
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);
builder->channel_init()->RegisterStage(
GRPC_SERVER_CHANNEL, 0, [](grpc_channel_stack_builder* builder) {
return grpc_channel_stack_builder_prepend_filter(
builder, &test_filter, nullptr, nullptr);
});
},
[config] { test_request(config); });
}
void filter_causes_close_pre_init(void) {
grpc_register_plugin(init_plugin, destroy_plugin);
}
void filter_causes_close_pre_init(void) {}

@ -27,14 +27,13 @@
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/channel_init.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
enum { TIMEOUT = 200000 };
static bool g_enable_filter = false;
static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
@ -274,48 +273,31 @@ static const grpc_channel_filter test_filter = {
* Registration
*/
static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) {
grpc_channel_filter* filter = static_cast<grpc_channel_filter*>(arg);
if (g_enable_filter) {
// Want to add the filter as close to the end as possible, to make
// sure that all of the filters work well together. However, we
// can't add it at the very end, because the connected channel filter
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
} else {
return true;
}
}
static void init_plugin(void) {
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_filter));
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_filter));
}
static void destroy_plugin(void) {}
void filter_context(grpc_end2end_test_config config) {
g_enable_filter = true;
test_request(config);
g_enable_filter = false;
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);
for (auto type : {GRPC_CLIENT_CHANNEL, GRPC_CLIENT_SUBCHANNEL,
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_SERVER_CHANNEL}) {
builder->channel_init()->RegisterStage(
type, INT_MAX, [](grpc_channel_stack_builder* builder) {
// Want to add the filter as close to the end as possible, to
// make sure that all of the filters work well together.
// However, we can't add it at the very end, because the
// connected channel filter must be the last one. So we add it
// right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval =
grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
});
}
},
[config] { test_request(config); });
}
void filter_context_pre_init(void) {
grpc_register_plugin(init_plugin, destroy_plugin);
}
void filter_context_pre_init(void) {}

@ -27,6 +27,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/channel_init.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
@ -456,76 +457,6 @@ static const grpc_channel_filter test_filter = {
* Registration
*/
static bool maybe_add_server_channel_filter(grpc_channel_stack_builder* builder,
void* /*arg*/) {
if (g_enable_server_channel_filter) {
// Want to add the filter as close to the end as possible, to make
// sure that all of the filters work well together. However, we
// can't add it at the very end, because the connected channel filter
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
} else {
return true;
}
}
static bool maybe_add_client_channel_filter(grpc_channel_stack_builder* builder,
void* /*arg*/) {
if (g_enable_client_channel_filter) {
// Want to add the filter as close to the end as possible, to make
// sure that all of the filters work well together. However, we
// can't add it at the very end, because the connected channel filter
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
} else {
return true;
}
}
static bool maybe_add_client_subchannel_filter(
grpc_channel_stack_builder* builder, void* /*arg*/) {
if (g_enable_client_subchannel_filter) {
// Want to add the filter as close to the end as possible, to make
// sure that all of the filters work well together. However, we
// can't add it at the very end, because the client channel filter
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
} else {
return true;
}
}
static void init_plugin(void) {
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX,
maybe_add_server_channel_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX,
maybe_add_client_channel_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX,
maybe_add_client_subchannel_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX,
maybe_add_client_channel_filter, nullptr);
}
static void destroy_plugin(void) {}
static void filter_init_fails_internal(grpc_end2end_test_config config) {
gpr_log(GPR_INFO, "Testing SERVER_CHANNEL filter.");
g_enable_server_channel_filter = true;
@ -552,13 +483,37 @@ static void filter_init_fails_internal(grpc_end2end_test_config config) {
}
void filter_init_fails(grpc_end2end_test_config config) {
filter_init_fails_internal(config);
gpr_log(GPR_INFO, "Testing with channel filter init error");
g_channel_filter_init_failure = true;
filter_init_fails_internal(config);
g_channel_filter_init_failure = false;
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);
auto register_stage = [builder](grpc_channel_stack_type type,
bool* enable) {
builder->channel_init()->RegisterStage(
type, INT_MAX, [enable](grpc_channel_stack_builder* builder) {
if (!*enable) return true;
// Want to add the filter as close to the end as possible,
// to make sure that all of the filters work well together.
// However, we can't add it at the very end, because either the
// client_channel filter or connected_channel filter must be the
// last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval =
grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
});
};
register_stage(GRPC_SERVER_CHANNEL, &g_enable_server_channel_filter);
register_stage(GRPC_CLIENT_CHANNEL, &g_enable_client_channel_filter);
register_stage(GRPC_CLIENT_SUBCHANNEL,
&g_enable_client_subchannel_filter);
register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
&g_enable_client_channel_filter);
},
[config] { filter_init_fails_internal(config); });
}
void filter_init_fails_pre_init(void) {
grpc_register_plugin(init_plugin, destroy_plugin);
}
void filter_init_fails_pre_init(void) {}

@ -27,13 +27,13 @@
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/channel_init.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
enum { TIMEOUT = 200000 };
static bool g_enable_filter = false;
static gpr_mu g_mu;
static gpr_timespec g_client_latency;
static gpr_timespec g_server_latency;
@ -304,46 +304,34 @@ static const grpc_channel_filter test_server_filter = {
* Registration
*/
static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) {
grpc_channel_filter* filter = static_cast<grpc_channel_filter*>(arg);
if (g_enable_filter) {
// Want to add the filter as close to the end as possible, to make
// sure that all of the filters work well together. However, we
// can't add it at the very end, because the connected channel filter
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
} else {
return true;
}
}
static void init_plugin(void) {
gpr_mu_init(&g_mu);
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_client_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_client_filter));
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_server_filter));
}
static void destroy_plugin(void) { gpr_mu_destroy(&g_mu); }
void filter_latency(grpc_end2end_test_config config) {
g_enable_filter = true;
test_request(config);
g_enable_filter = false;
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);
auto register_stage = [builder](grpc_channel_stack_type type,
const grpc_channel_filter* filter) {
builder->channel_init()->RegisterStage(
type, INT_MAX, [filter](grpc_channel_stack_builder* builder) {
// Want to add the filter as close to the end as possible, to
// make sure that all of the filters work well together.
// However, we can't add it at the very end, because the
// connected channel filter must be the last one. So we add it
// right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval =
grpc_channel_stack_builder_add_filter_before(
it, filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
});
};
register_stage(GRPC_CLIENT_CHANNEL, &test_client_filter);
register_stage(GRPC_CLIENT_DIRECT_CHANNEL, &test_client_filter);
register_stage(GRPC_SERVER_CHANNEL, &test_server_filter);
},
[config] { test_request(config); });
}
void filter_latency_pre_init(void) {
grpc_register_plugin(init_plugin, destroy_plugin);
}
void filter_latency_pre_init(void) { gpr_mu_init(&g_mu); }

@ -35,12 +35,12 @@
#include <grpc/support/time.h>
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel_init.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/end2end/end2end_tests.h"
static bool g_enable_filter = false;
static gpr_mu g_mu;
static grpc_call_stack* g_client_call_stack;
static grpc_call_stack* g_server_call_stack;
@ -109,6 +109,9 @@ static void end_test(grpc_end2end_test_fixture* f) {
// Simple request via a server filter that saves the reported status code.
static void test_request(grpc_end2end_test_config config) {
g_client_code_recv = false;
g_server_code_recv = false;
grpc_call* c;
grpc_call* s;
grpc_end2end_test_fixture f =
@ -348,56 +351,38 @@ static const grpc_channel_filter test_server_filter = {
* Registration
*/
static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) {
grpc_channel_filter* filter = static_cast<grpc_channel_filter*>(arg);
if (g_enable_filter) {
// Want to add the filter as close to the end as possible, to make
// sure that all of the filters work well together. However, we
// can't add it at the very end, because the
// connected_channel/client_channel filter must be the last one.
// So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
} else {
return true;
}
void filter_status_code(grpc_end2end_test_config config) {
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);
auto register_stage = [builder](grpc_channel_stack_type type,
const grpc_channel_filter* filter) {
builder->channel_init()->RegisterStage(
type, INT_MAX, [filter](grpc_channel_stack_builder* builder) {
// Want to add the filter as close to the end as possible, to
// make sure that all of the filters work well together.
// However, we can't add it at the very end, because the
// connected_channel/client_channel filter must be the last one.
// So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval =
grpc_channel_stack_builder_add_filter_before(
it, filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
return retval;
});
};
register_stage(GRPC_CLIENT_CHANNEL, &test_client_filter);
register_stage(GRPC_CLIENT_DIRECT_CHANNEL, &test_client_filter);
register_stage(GRPC_SERVER_CHANNEL, &test_server_filter);
},
[config] { test_request(config); });
}
static void init_plugin(void) {
void filter_status_code_pre_init(void) {
gpr_mu_init(&g_mu);
gpr_cv_init(&g_client_code_cv);
gpr_cv_init(&g_server_code_cv);
g_client_code_recv = false;
g_server_code_recv = false;
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_client_filter));
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_client_filter));
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, INT_MAX, maybe_add_filter,
const_cast<grpc_channel_filter*>(&test_server_filter));
}
static void destroy_plugin(void) {
gpr_cv_destroy(&g_client_code_cv);
gpr_cv_destroy(&g_server_code_cv);
gpr_mu_destroy(&g_mu);
}
void filter_status_code(grpc_end2end_test_config config) {
g_enable_filter = true;
test_request(config);
g_enable_filter = false;
}
void filter_status_code_pre_init(void) {
grpc_register_plugin(init_plugin, destroy_plugin);
}

@ -31,6 +31,7 @@
#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/config/core_configuration.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/exec_ctx.h"
@ -305,11 +306,7 @@ grpc_channel_filter FailSendOpsFilter::kFilterVtable = {
"FailSendOpsFilter",
};
bool g_enable_filter = false;
bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* /*arg*/) {
// Skip if filter is not enabled.
if (!g_enable_filter) return true;
bool MaybeAddFilter(grpc_channel_stack_builder* builder) {
// Skip on proxy (which explicitly disables retries).
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
@ -321,24 +318,22 @@ bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* /*arg*/) {
builder, &FailSendOpsFilter::kFilterVtable, nullptr, nullptr);
}
void InitPlugin(void) {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, 0, MaybeAddFilter,
nullptr);
}
void DestroyPlugin(void) {}
} // namespace
void retry_cancel_with_multiple_send_batches(grpc_end2end_test_config config) {
GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL);
g_enable_filter = true;
for (size_t i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); ++i) {
test_retry_cancel_with_multiple_send_batches(config, cancellation_modes[i]);
}
g_enable_filter = false;
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);
builder->channel_init()->RegisterStage(GRPC_CLIENT_SUBCHANNEL, 0,
MaybeAddFilter);
},
[config]() {
for (size_t i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); ++i) {
test_retry_cancel_with_multiple_send_batches(config,
cancellation_modes[i]);
}
});
}
void retry_cancel_with_multiple_send_batches_pre_init(void) {
grpc_register_plugin(InitPlugin, DestroyPlugin);
}
void retry_cancel_with_multiple_send_batches_pre_init(void) {}

@ -27,6 +27,7 @@
#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/config/core_configuration.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/exec_ctx.h"
@ -337,11 +338,7 @@ grpc_channel_filter InjectStatusFilter::kFilterVtable = {
"InjectStatusFilter",
};
bool g_enable_filter = false;
bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* /*arg*/) {
// Skip if filter is not enabled.
if (!g_enable_filter) return true;
bool AddFilter(grpc_channel_stack_builder* builder) {
// Skip on proxy (which explicitly disables retries).
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
@ -353,22 +350,17 @@ bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* /*arg*/) {
builder, &InjectStatusFilter::kFilterVtable, nullptr, nullptr);
}
void InitPlugin(void) {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, 0, MaybeAddFilter,
nullptr);
}
void DestroyPlugin(void) {}
} // namespace
void retry_recv_trailing_metadata_error(grpc_end2end_test_config config) {
GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL);
g_enable_filter = true;
test_retry_recv_trailing_metadata_error(config);
g_enable_filter = false;
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);
builder->channel_init()->RegisterStage(GRPC_CLIENT_SUBCHANNEL, 0,
AddFilter);
},
[config] { test_retry_recv_trailing_metadata_error(config); });
}
void retry_recv_trailing_metadata_error_pre_init() {
grpc_register_plugin(InitPlugin, DestroyPlugin);
}
void retry_recv_trailing_metadata_error_pre_init() {}

@ -29,6 +29,7 @@
#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/config/core_configuration.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/exec_ctx.h"
@ -355,38 +356,29 @@ grpc_channel_filter FailFirstSendOpFilter::kFilterVtable = {
"FailFirstSendOpFilter",
};
bool g_enable_filter = false;
bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* /*arg*/) {
// Skip if filter is not enabled.
if (!g_enable_filter) return true;
// Skip on proxy (which explicitly disables retries).
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (!grpc_channel_args_find_bool(args, GRPC_ARG_ENABLE_RETRIES, true)) {
return true;
}
// Install filter.
return grpc_channel_stack_builder_prepend_filter(
builder, &FailFirstSendOpFilter::kFilterVtable, nullptr, nullptr);
}
void InitPlugin(void) {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, 0, MaybeAddFilter,
nullptr);
}
void DestroyPlugin(void) {}
} // namespace
void retry_send_op_fails(grpc_end2end_test_config config) {
GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_CLIENT_CHANNEL);
g_enable_filter = true;
test_retry_send_op_fails(config);
g_enable_filter = false;
grpc_core::CoreConfiguration::RunWithSpecialConfiguration(
[](grpc_core::CoreConfiguration::Builder* builder) {
grpc_core::BuildCoreConfiguration(builder);
builder->channel_init()->RegisterStage(
GRPC_CLIENT_SUBCHANNEL, 0, [](grpc_channel_stack_builder* builder) {
// Skip on proxy (which explicitly disables retries).
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
if (!grpc_channel_args_find_bool(args, GRPC_ARG_ENABLE_RETRIES,
true)) {
return true;
}
// Install filter.
return grpc_channel_stack_builder_prepend_filter(
builder, &FailFirstSendOpFilter::kFilterVtable, nullptr,
nullptr);
});
},
[config] { test_retry_send_op_fails(config); });
}
void retry_send_op_fails_pre_init(void) {
grpc_register_plugin(InitPlugin, DestroyPlugin);
}
void retry_send_op_fails_pre_init(void) {}

@ -280,7 +280,7 @@ grpc_cc_test(
deps = [
"//:gpr",
"//:grpc",
"//:grpc_base_c",
"//:grpc_base",
"//:grpc_secure",
"//:tsi",
"//:tsi_interface",

@ -66,7 +66,7 @@ grpc_cc_library(
deps = [
":fake_binder",
"//:grpc++_base",
"//:grpc_base_c",
"//:grpc_base",
"//src/core/ext/transport/binder/transport:binder_transport",
"//src/core/ext/transport/binder/wire_format:wire_reader",
],

@ -58,7 +58,6 @@ grpc_fuzzer(
"//:gpr_base",
"//:grpc++_base",
"//:grpc_base",
"//:grpc_base_c",
"//src/core/ext/transport/binder/transport:binder_transport",
"//test/core/util:grpc_test_util",
],
@ -79,7 +78,6 @@ grpc_fuzzer(
"//:gpr_base",
"//:grpc++_base",
"//:grpc_base",
"//:grpc_base_c",
"//src/core/ext/transport/binder/transport:binder_transport",
"//test/core/util:grpc_test_util",
],

@ -26,7 +26,7 @@ grpc_cc_test(
"//:alts_frame_protector",
"//:gpr",
"//:grpc",
"//:grpc_base_c",
"//:grpc_base",
"//test/core/tsi/alts/crypt:alts_crypt_test_util",
"//test/core/util:grpc_test_util",
],
@ -53,7 +53,7 @@ grpc_cc_test(
"//:alts_frame_protector",
"//:gpr",
"//:grpc",
"//:grpc_base_c",
"//:grpc_base",
"//test/core/tsi/alts/crypt:alts_crypt_test_util",
"//test/core/util:grpc_test_util",
],

@ -88,7 +88,7 @@ grpc_cc_library(
":grpc_suppressions",
":stack_tracer",
"//:gpr",
"//:grpc_base_c",
"//:grpc_base",
"//:grpc_common",
],
)

@ -28,6 +28,7 @@
#include <grpc/grpc.h>
#include <grpcpp/grpcpp.h>
#include "src/core/lib/config/core_configuration.h"
#include "src/cpp/ext/filters/census/grpc_plugin.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/test_config.h"
@ -86,6 +87,7 @@ class EchoServerThread final {
};
static void BM_E2eLatencyCensusDisabled(benchmark::State& state) {
grpc_core::CoreConfiguration::Reset();
grpc::testing::TestGrpcScope grpc_scope;
EchoServerThread server;
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub =
@ -102,6 +104,7 @@ static void BM_E2eLatencyCensusDisabled(benchmark::State& state) {
BENCHMARK(BM_E2eLatencyCensusDisabled);
static void BM_E2eLatencyCensusEnabled(benchmark::State& state) {
grpc_core::CoreConfiguration::Reset();
// Now start the test by registering the plugin (once in the execution)
RegisterOnce();
// This we can safely repeat, and doing so clears accumulated data to avoid

@ -2115,6 +2115,8 @@ src/core/lib/slice/static_slice.cc \
src/core/lib/slice/static_slice.h \
src/core/lib/surface/api_trace.cc \
src/core/lib/surface/api_trace.h \
src/core/lib/surface/builtins.cc \
src/core/lib/surface/builtins.h \
src/core/lib/surface/byte_buffer.cc \
src/core/lib/surface/byte_buffer_reader.cc \
src/core/lib/surface/call.cc \

@ -1956,6 +1956,8 @@ src/core/lib/slice/static_slice.h \
src/core/lib/surface/README.md \
src/core/lib/surface/api_trace.cc \
src/core/lib/surface/api_trace.h \
src/core/lib/surface/builtins.cc \
src/core/lib/surface/builtins.h \
src/core/lib/surface/byte_buffer.cc \
src/core/lib/surface/byte_buffer_reader.cc \
src/core/lib/surface/call.cc \

Loading…
Cancel
Save