grpc 1.31.1 → 1.35.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (1104) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +719 -17819
  3. data/etc/roots.pem +257 -573
  4. data/include/grpc/compression.h +1 -1
  5. data/include/grpc/grpc.h +15 -7
  6. data/include/grpc/grpc_security.h +254 -186
  7. data/include/grpc/impl/codegen/README.md +22 -0
  8. data/include/grpc/impl/codegen/atm_windows.h +4 -0
  9. data/include/grpc/impl/codegen/byte_buffer.h +1 -1
  10. data/include/grpc/impl/codegen/grpc_types.h +10 -8
  11. data/include/grpc/impl/codegen/log.h +0 -2
  12. data/include/grpc/impl/codegen/port_platform.h +28 -56
  13. data/include/grpc/impl/codegen/sync_windows.h +4 -0
  14. data/include/grpc/slice_buffer.h +3 -3
  15. data/include/grpc/support/sync.h +3 -3
  16. data/include/grpc/support/time.h +7 -7
  17. data/src/core/ext/filters/client_channel/backend_metric.cc +2 -4
  18. data/src/core/ext/filters/client_channel/backup_poller.cc +3 -2
  19. data/src/core/ext/filters/client_channel/client_channel.cc +2831 -1540
  20. data/src/core/ext/filters/client_channel/client_channel.h +1 -5
  21. data/src/core/ext/filters/client_channel/client_channel_channelz.h +0 -3
  22. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +1 -1
  23. data/src/core/ext/filters/client_channel/config_selector.cc +0 -4
  24. data/src/core/ext/filters/client_channel/config_selector.h +40 -8
  25. data/src/core/ext/filters/client_channel/dynamic_filters.cc +186 -0
  26. data/src/core/ext/filters/client_channel/dynamic_filters.h +99 -0
  27. data/src/core/ext/filters/client_channel/health/health_check_client.cc +16 -8
  28. data/src/core/ext/filters/client_channel/health/health_check_client.h +4 -4
  29. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +7 -9
  30. data/src/core/ext/filters/client_channel/http_proxy.cc +21 -20
  31. data/src/core/ext/filters/client_channel/lb_policy.cc +6 -2
  32. data/src/core/ext/filters/client_channel/lb_policy.h +8 -7
  33. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +48 -35
  34. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +7 -5
  35. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +10 -7
  36. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +1 -1
  37. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +210 -192
  38. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +0 -13
  39. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +0 -3
  40. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -37
  41. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +3 -1
  42. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +3 -3
  43. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  44. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +23 -17
  45. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +79 -30
  46. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +10 -9
  47. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +14 -34
  48. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +26 -15
  49. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +350 -130
  50. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +52 -24
  51. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h +24 -0
  52. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +812 -0
  53. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +722 -0
  54. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +1262 -0
  55. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +8 -1
  56. data/src/core/ext/filters/client_channel/resolver.cc +3 -1
  57. data/src/core/ext/filters/client_channel/resolver.h +4 -1
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +9 -16
  59. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +1 -32
  60. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +3 -3
  61. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +457 -19
  62. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +5 -0
  63. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +1 -1
  64. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  65. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +7 -10
  66. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +4 -4
  67. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -1
  68. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +35 -28
  69. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +664 -63
  70. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h +28 -0
  71. data/src/core/ext/filters/client_channel/resolver_factory.h +6 -6
  72. data/src/core/ext/filters/client_channel/resolver_registry.cc +40 -39
  73. data/src/core/ext/filters/client_channel/resolver_registry.h +2 -2
  74. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +29 -74
  75. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +12 -11
  76. data/src/core/ext/filters/client_channel/retry_throttle.cc +5 -3
  77. data/src/core/ext/filters/client_channel/retry_throttle.h +4 -2
  78. data/src/core/ext/filters/client_channel/server_address.cc +120 -7
  79. data/src/core/ext/filters/client_channel/server_address.h +44 -21
  80. data/src/core/ext/filters/client_channel/service_config.cc +18 -13
  81. data/src/core/ext/filters/client_channel/service_config.h +8 -5
  82. data/src/core/ext/filters/client_channel/service_config_call_data.h +19 -1
  83. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +2 -2
  84. data/src/core/ext/filters/client_channel/service_config_parser.cc +8 -6
  85. data/src/core/ext/filters/client_channel/service_config_parser.h +8 -5
  86. data/src/core/ext/filters/client_channel/subchannel.cc +115 -87
  87. data/src/core/ext/filters/client_channel/subchannel.h +30 -24
  88. data/src/core/ext/filters/client_channel/subchannel_interface.h +41 -5
  89. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +6 -2
  90. data/src/core/ext/filters/deadline/deadline_filter.cc +87 -79
  91. data/src/core/ext/filters/deadline/deadline_filter.h +7 -11
  92. data/src/core/ext/filters/http/client/http_client_filter.cc +1 -1
  93. data/src/core/ext/filters/http/client_authority_filter.cc +6 -6
  94. data/src/core/ext/filters/http/http_filters_plugin.cc +6 -3
  95. data/src/core/ext/filters/http/server/http_server_filter.cc +3 -3
  96. data/src/core/ext/filters/max_age/max_age_filter.cc +3 -2
  97. data/src/core/ext/filters/message_size/message_size_filter.cc +3 -2
  98. data/src/core/ext/filters/message_size/message_size_filter.h +2 -1
  99. data/src/core/ext/filters/workarounds/workaround_utils.cc +1 -1
  100. data/src/core/ext/transport/chttp2/client/authority.cc +3 -3
  101. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +87 -31
  102. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +19 -2
  103. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +20 -8
  104. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +21 -10
  105. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +34 -47
  106. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +200 -100
  107. data/src/core/ext/transport/chttp2/server/chttp2_server.h +2 -1
  108. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +2 -2
  109. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +16 -9
  110. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +3 -2
  111. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +7 -7
  112. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +267 -319
  113. data/src/core/ext/transport/chttp2/transport/flow_control.cc +11 -3
  114. data/src/core/ext/transport/chttp2/transport/flow_control.h +13 -3
  115. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +2 -1
  116. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +2 -2
  117. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -1
  118. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +6 -6
  119. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +12 -8
  120. data/src/core/ext/transport/chttp2/transport/internal.h +10 -2
  121. data/src/core/ext/transport/chttp2/transport/parsing.cc +19 -31
  122. data/src/core/ext/transport/chttp2/transport/writing.cc +8 -8
  123. data/src/core/ext/transport/inproc/inproc_transport.cc +52 -18
  124. data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.h +1 -0
  125. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.c +1 -1
  126. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.h +7 -0
  127. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +244 -0
  128. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +865 -0
  129. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +74 -0
  130. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +253 -0
  131. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +458 -0
  132. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +1818 -0
  133. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.c +35 -0
  134. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +77 -0
  135. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.c +55 -0
  136. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +349 -0
  137. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +124 -0
  138. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +428 -0
  139. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.c +35 -0
  140. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +88 -0
  141. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +310 -0
  142. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +991 -0
  143. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +103 -0
  144. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +388 -0
  145. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +34 -0
  146. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +78 -0
  147. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.c +53 -0
  148. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.h +149 -0
  149. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +241 -0
  150. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +839 -0
  151. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +170 -0
  152. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +752 -0
  153. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.c +36 -0
  154. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +88 -0
  155. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +176 -0
  156. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +730 -0
  157. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +28 -0
  158. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +65 -0
  159. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/socket_option.upb.c +8 -8
  160. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +95 -0
  161. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +36 -0
  162. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +92 -0
  163. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +91 -0
  164. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +243 -0
  165. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +91 -0
  166. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +305 -0
  167. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +112 -0
  168. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +367 -0
  169. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.c +33 -0
  170. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +73 -0
  171. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +128 -0
  172. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +512 -0
  173. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +155 -0
  174. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +591 -0
  175. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +41 -0
  176. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +107 -0
  177. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +178 -0
  178. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +662 -0
  179. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +63 -0
  180. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +220 -0
  181. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +900 -0
  182. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +3640 -0
  183. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +60 -0
  184. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +159 -0
  185. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +50 -0
  186. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +122 -0
  187. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +364 -0
  188. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +1475 -0
  189. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.c +20 -0
  190. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.h +35 -0
  191. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +110 -0
  192. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +426 -0
  193. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +76 -0
  194. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +236 -0
  195. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +147 -0
  196. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +621 -0
  197. data/src/core/ext/upb-generated/envoy/{api/v2 → service/cluster/v3}/cds.upb.c +6 -7
  198. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.h +56 -0
  199. data/src/core/ext/upb-generated/envoy/service/discovery/{v2 → v3}/ads.upb.c +6 -5
  200. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.h +56 -0
  201. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +139 -0
  202. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +487 -0
  203. data/src/core/ext/upb-generated/envoy/{api/v2 → service/endpoint/v3}/eds.upb.c +6 -7
  204. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.h +56 -0
  205. data/src/core/ext/upb-generated/envoy/{api/v2 → service/listener/v3}/lds.upb.c +6 -7
  206. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.h +56 -0
  207. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +55 -0
  208. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +151 -0
  209. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/rds.upb.c +6 -7
  210. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.h +56 -0
  211. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/srds.upb.c +6 -7
  212. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.h +56 -0
  213. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +47 -0
  214. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +128 -0
  215. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +35 -0
  216. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +84 -0
  217. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +34 -0
  218. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +78 -0
  219. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +64 -0
  220. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +166 -0
  221. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +54 -0
  222. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +146 -0
  223. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +63 -0
  224. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +207 -0
  225. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +88 -0
  226. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +301 -0
  227. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +90 -0
  228. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +283 -0
  229. data/src/core/ext/upb-generated/envoy/type/{http.upb.c → v3/http.upb.c} +2 -2
  230. data/src/core/ext/upb-generated/envoy/type/{http.upb.h → v3/http.upb.h} +9 -8
  231. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.c +40 -0
  232. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +99 -0
  233. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.c +51 -0
  234. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +130 -0
  235. data/src/core/ext/upb-generated/envoy/type/{semantic_version.upb.c → v3/semantic_version.upb.c} +7 -6
  236. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +68 -0
  237. data/src/core/ext/upb-generated/google/api/annotations.upb.h +1 -0
  238. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c +242 -0
  239. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h +830 -0
  240. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +234 -0
  241. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +842 -0
  242. data/src/core/ext/upb-generated/google/api/http.upb.c +3 -3
  243. data/src/core/ext/upb-generated/google/api/http.upb.h +25 -6
  244. data/src/core/ext/upb-generated/google/protobuf/any.upb.c +1 -1
  245. data/src/core/ext/upb-generated/google/protobuf/any.upb.h +7 -0
  246. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +103 -103
  247. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +455 -292
  248. data/src/core/ext/upb-generated/google/protobuf/duration.upb.c +1 -1
  249. data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +7 -0
  250. data/src/core/ext/upb-generated/google/protobuf/empty.upb.c +1 -1
  251. data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +7 -0
  252. data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +4 -4
  253. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +23 -4
  254. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.c +1 -1
  255. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +7 -0
  256. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.c +9 -9
  257. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +55 -0
  258. data/src/core/ext/upb-generated/google/rpc/status.upb.c +1 -1
  259. data/src/core/ext/upb-generated/google/rpc/status.upb.h +10 -3
  260. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +4 -4
  261. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +11 -3
  262. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +41 -41
  263. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +149 -76
  264. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c +5 -5
  265. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +21 -6
  266. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c +2 -2
  267. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +13 -0
  268. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +17 -17
  269. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +82 -25
  270. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.c +3 -3
  271. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.h +19 -0
  272. data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +31 -0
  273. data/src/core/ext/upb-generated/udpa/annotations/security.upb.h +64 -0
  274. data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.h +1 -0
  275. data/src/core/ext/upb-generated/udpa/annotations/status.upb.c +2 -2
  276. data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +9 -2
  277. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +27 -0
  278. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +60 -0
  279. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.c +28 -0
  280. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.h +60 -0
  281. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.c +52 -0
  282. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.h +143 -0
  283. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.c +42 -0
  284. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.h +84 -0
  285. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.c +36 -0
  286. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.h +94 -0
  287. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c +54 -0
  288. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.h +173 -0
  289. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c +36 -0
  290. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.h +92 -0
  291. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +3 -3
  292. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +7 -0
  293. data/src/core/ext/upb-generated/validate/validate.upb.c +68 -68
  294. data/src/core/ext/upb-generated/validate/validate.upb.h +296 -157
  295. data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.c +38 -0
  296. data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.h +30 -0
  297. data/src/core/ext/upbdefs-generated/envoy/annotations/resource.upbdefs.c +41 -0
  298. data/src/core/ext/upbdefs-generated/envoy/annotations/resource.upbdefs.h +35 -0
  299. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +254 -0
  300. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.h +105 -0
  301. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.c +100 -0
  302. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/circuit_breaker.upbdefs.h +45 -0
  303. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +558 -0
  304. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.h +145 -0
  305. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/filter.upbdefs.c +53 -0
  306. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/filter.upbdefs.h +35 -0
  307. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.c +133 -0
  308. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.h +35 -0
  309. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/address.upbdefs.c +127 -0
  310. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/address.upbdefs.h +65 -0
  311. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/backoff.upbdefs.c +56 -0
  312. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/backoff.upbdefs.h +35 -0
  313. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +266 -0
  314. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +125 -0
  315. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +143 -0
  316. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.h +55 -0
  317. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/event_service_config.upbdefs.c +56 -0
  318. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/event_service_config.upbdefs.h +35 -0
  319. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.c +66 -0
  320. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/extension.upbdefs.h +40 -0
  321. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.c +263 -0
  322. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/grpc_service.upbdefs.h +100 -0
  323. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.c +233 -0
  324. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.h +70 -0
  325. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/http_uri.upbdefs.c +56 -0
  326. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/http_uri.upbdefs.h +35 -0
  327. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +228 -0
  328. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.h +80 -0
  329. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.c +46 -0
  330. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.h +35 -0
  331. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/socket_option.upbdefs.c +59 -0
  332. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/socket_option.upbdefs.h +35 -0
  333. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c +55 -0
  334. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.h +35 -0
  335. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.c +110 -0
  336. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.h +50 -0
  337. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.c +113 -0
  338. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.h +50 -0
  339. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/load_report.upbdefs.c +146 -0
  340. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/load_report.upbdefs.h +55 -0
  341. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/api_listener.upbdefs.c +50 -0
  342. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/api_listener.upbdefs.h +35 -0
  343. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c +190 -0
  344. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.h +55 -0
  345. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +185 -0
  346. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.h +65 -0
  347. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c +62 -0
  348. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.h +40 -0
  349. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +97 -0
  350. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.h +40 -0
  351. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +915 -0
  352. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +280 -0
  353. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/scoped_route.upbdefs.c +71 -0
  354. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/scoped_route.upbdefs.h +45 -0
  355. data/src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.c +64 -0
  356. data/src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.h +40 -0
  357. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +511 -0
  358. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +115 -0
  359. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.c +48 -0
  360. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.h +30 -0
  361. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +166 -0
  362. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.h +55 -0
  363. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.c +105 -0
  364. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.h +45 -0
  365. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +249 -0
  366. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.h +60 -0
  367. data/src/core/ext/upbdefs-generated/envoy/service/cluster/v3/cds.upbdefs.c +72 -0
  368. data/src/core/ext/upbdefs-generated/envoy/service/cluster/v3/cds.upbdefs.h +35 -0
  369. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/ads.upbdefs.c +60 -0
  370. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/ads.upbdefs.h +35 -0
  371. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.c +152 -0
  372. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.h +60 -0
  373. data/src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.c +83 -0
  374. data/src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.h +35 -0
  375. data/src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.c +82 -0
  376. data/src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.h +35 -0
  377. data/src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.c +83 -0
  378. data/src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.h +40 -0
  379. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.c +86 -0
  380. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.h +35 -0
  381. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/srds.upbdefs.c +74 -0
  382. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/srds.upbdefs.h +35 -0
  383. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.c +64 -0
  384. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.h +40 -0
  385. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/number.upbdefs.c +54 -0
  386. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/number.upbdefs.h +35 -0
  387. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/path.upbdefs.c +53 -0
  388. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/path.upbdefs.h +35 -0
  389. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +73 -0
  390. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.h +45 -0
  391. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.c +72 -0
  392. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.h +40 -0
  393. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/value.upbdefs.c +81 -0
  394. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/value.upbdefs.h +45 -0
  395. data/src/core/ext/upbdefs-generated/envoy/type/metadata/v3/metadata.upbdefs.c +92 -0
  396. data/src/core/ext/upbdefs-generated/envoy/type/metadata/v3/metadata.upbdefs.h +65 -0
  397. data/src/core/ext/upbdefs-generated/envoy/type/tracing/v3/custom_tag.upbdefs.c +95 -0
  398. data/src/core/ext/upbdefs-generated/envoy/type/tracing/v3/custom_tag.upbdefs.h +55 -0
  399. data/src/core/ext/upbdefs-generated/envoy/type/v3/http.upbdefs.c +34 -0
  400. data/src/core/ext/{upb-generated/gogoproto/gogo.upb.h → upbdefs-generated/envoy/type/v3/http.upbdefs.h} +10 -9
  401. data/src/core/ext/upbdefs-generated/envoy/type/v3/percent.upbdefs.c +59 -0
  402. data/src/core/ext/upbdefs-generated/envoy/type/v3/percent.upbdefs.h +40 -0
  403. data/src/core/ext/upbdefs-generated/envoy/type/v3/range.upbdefs.c +54 -0
  404. data/src/core/ext/upbdefs-generated/envoy/type/v3/range.upbdefs.h +45 -0
  405. data/src/core/ext/upbdefs-generated/envoy/type/v3/semantic_version.upbdefs.c +47 -0
  406. data/src/core/ext/upbdefs-generated/envoy/type/v3/semantic_version.upbdefs.h +35 -0
  407. data/src/core/ext/upbdefs-generated/google/api/annotations.upbdefs.c +40 -0
  408. data/src/core/ext/upbdefs-generated/google/api/annotations.upbdefs.h +30 -0
  409. data/src/core/ext/upbdefs-generated/google/api/http.upbdefs.c +61 -0
  410. data/src/core/ext/upbdefs-generated/google/api/http.upbdefs.h +45 -0
  411. data/src/core/ext/upbdefs-generated/google/protobuf/any.upbdefs.c +38 -0
  412. data/src/core/ext/upbdefs-generated/google/protobuf/any.upbdefs.h +35 -0
  413. data/src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.c +386 -0
  414. data/src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.h +165 -0
  415. data/src/core/ext/upbdefs-generated/google/protobuf/duration.upbdefs.c +39 -0
  416. data/src/core/ext/upbdefs-generated/google/protobuf/duration.upbdefs.h +35 -0
  417. data/src/core/ext/upbdefs-generated/google/protobuf/empty.upbdefs.c +37 -0
  418. data/src/core/ext/upbdefs-generated/google/protobuf/empty.upbdefs.h +35 -0
  419. data/src/core/ext/upbdefs-generated/google/protobuf/struct.upbdefs.c +65 -0
  420. data/src/core/ext/upbdefs-generated/google/protobuf/struct.upbdefs.h +50 -0
  421. data/src/core/ext/upbdefs-generated/google/protobuf/timestamp.upbdefs.c +39 -0
  422. data/src/core/ext/upbdefs-generated/google/protobuf/timestamp.upbdefs.h +35 -0
  423. data/src/core/ext/upbdefs-generated/google/protobuf/wrappers.upbdefs.c +66 -0
  424. data/src/core/ext/upbdefs-generated/google/protobuf/wrappers.upbdefs.h +75 -0
  425. data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.c +42 -0
  426. data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.h +35 -0
  427. data/src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.c +70 -0
  428. data/src/core/ext/upbdefs-generated/udpa/annotations/migrate.upbdefs.h +45 -0
  429. data/src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.c +56 -0
  430. data/src/core/ext/upbdefs-generated/udpa/annotations/security.upbdefs.h +35 -0
  431. data/src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.c +33 -0
  432. data/src/core/ext/upbdefs-generated/udpa/annotations/sensitive.upbdefs.h +30 -0
  433. data/src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.c +49 -0
  434. data/src/core/ext/upbdefs-generated/udpa/annotations/status.upbdefs.h +35 -0
  435. data/src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.c +43 -0
  436. data/src/core/ext/upbdefs-generated/udpa/annotations/versioning.upbdefs.h +35 -0
  437. data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.c +42 -0
  438. data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.h +35 -0
  439. data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.c +62 -0
  440. data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.h +40 -0
  441. data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.c +45 -0
  442. data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.h +40 -0
  443. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.c +49 -0
  444. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.h +35 -0
  445. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.c +68 -0
  446. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.h +40 -0
  447. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.c +51 -0
  448. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.h +35 -0
  449. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.c +307 -0
  450. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.h +145 -0
  451. data/src/core/ext/xds/certificate_provider_factory.h +61 -0
  452. data/src/core/ext/xds/certificate_provider_registry.cc +103 -0
  453. data/src/core/ext/xds/certificate_provider_registry.h +57 -0
  454. data/src/core/ext/xds/certificate_provider_store.cc +87 -0
  455. data/src/core/ext/xds/certificate_provider_store.h +112 -0
  456. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +144 -0
  457. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +69 -0
  458. data/src/core/ext/xds/xds_api.cc +2308 -0
  459. data/src/core/ext/xds/xds_api.h +469 -0
  460. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.cc +208 -19
  461. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.h +31 -11
  462. data/src/core/ext/xds/xds_certificate_provider.cc +299 -0
  463. data/src/core/ext/xds/xds_certificate_provider.h +112 -0
  464. data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel_args.h +9 -6
  465. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.cc +656 -865
  466. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.h +126 -99
  467. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.cc +61 -18
  468. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.h +38 -10
  469. data/src/core/ext/xds/xds_server_config_fetcher.cc +131 -0
  470. data/src/core/lib/channel/channel_args.cc +9 -8
  471. data/src/core/lib/channel/channel_args.h +0 -1
  472. data/src/core/lib/channel/channel_trace.cc +4 -2
  473. data/src/core/lib/channel/channel_trace.h +1 -1
  474. data/src/core/lib/channel/channelz.cc +37 -74
  475. data/src/core/lib/channel/channelz.h +14 -23
  476. data/src/core/lib/channel/channelz_registry.cc +15 -12
  477. data/src/core/lib/channel/channelz_registry.h +3 -1
  478. data/src/core/lib/channel/handshaker.cc +2 -2
  479. data/src/core/lib/channel/handshaker.h +2 -2
  480. data/src/core/lib/compression/compression.cc +8 -4
  481. data/src/core/lib/compression/compression_args.cc +3 -2
  482. data/src/core/lib/compression/compression_internal.cc +10 -5
  483. data/src/core/lib/compression/compression_internal.h +2 -1
  484. data/src/core/lib/compression/stream_compression_identity.cc +1 -3
  485. data/src/core/lib/debug/stats.h +2 -2
  486. data/src/core/lib/debug/stats_data.cc +1 -0
  487. data/src/core/lib/debug/stats_data.h +13 -13
  488. data/src/core/lib/gpr/alloc.cc +3 -2
  489. data/src/core/lib/gpr/cpu_iphone.cc +10 -2
  490. data/src/core/lib/gpr/log.cc +53 -16
  491. data/src/core/lib/gpr/log_linux.cc +19 -3
  492. data/src/core/lib/gpr/log_posix.cc +15 -1
  493. data/src/core/lib/gpr/log_windows.cc +18 -4
  494. data/src/core/lib/gpr/murmur_hash.cc +1 -1
  495. data/src/core/lib/gpr/spinlock.h +10 -2
  496. data/src/core/lib/gpr/string.cc +23 -22
  497. data/src/core/lib/gpr/string.h +5 -6
  498. data/src/core/lib/gpr/sync.cc +4 -4
  499. data/src/core/lib/gpr/sync_posix.cc +2 -8
  500. data/src/core/lib/gpr/time.cc +12 -12
  501. data/src/core/lib/gpr/time_precise.cc +5 -2
  502. data/src/core/lib/gpr/time_precise.h +6 -2
  503. data/src/core/lib/gpr/tls.h +4 -0
  504. data/src/core/lib/gpr/tls_msvc.h +2 -0
  505. data/src/core/lib/gpr/tls_stdcpp.h +48 -0
  506. data/src/core/lib/gpr/useful.h +5 -4
  507. data/src/core/lib/gprpp/arena.h +3 -2
  508. data/src/core/lib/gprpp/dual_ref_counted.h +331 -0
  509. data/src/core/lib/gprpp/examine_stack.cc +43 -0
  510. data/src/core/lib/gprpp/examine_stack.h +46 -0
  511. data/src/core/lib/gprpp/fork.cc +2 -2
  512. data/src/core/lib/gprpp/manual_constructor.h +1 -1
  513. data/src/core/lib/gprpp/orphanable.h +4 -8
  514. data/src/core/lib/gprpp/ref_counted.h +91 -68
  515. data/src/core/lib/gprpp/ref_counted_ptr.h +166 -7
  516. data/src/core/lib/gprpp/stat.h +38 -0
  517. data/src/core/lib/gprpp/stat_posix.cc +49 -0
  518. data/src/core/lib/gprpp/stat_windows.cc +48 -0
  519. data/src/core/lib/gprpp/thd.h +2 -2
  520. data/src/core/lib/gprpp/thd_posix.cc +42 -37
  521. data/src/core/lib/gprpp/thd_windows.cc +3 -1
  522. data/src/core/lib/http/httpcli.cc +1 -1
  523. data/src/core/lib/http/httpcli.h +2 -3
  524. data/src/core/lib/http/httpcli_security_connector.cc +1 -1
  525. data/src/core/lib/http/parser.cc +47 -27
  526. data/src/core/lib/iomgr/call_combiner.cc +8 -5
  527. data/src/core/lib/iomgr/combiner.cc +2 -1
  528. data/src/core/lib/iomgr/endpoint.cc +5 -1
  529. data/src/core/lib/iomgr/endpoint.h +8 -4
  530. data/src/core/lib/iomgr/endpoint_cfstream.cc +36 -11
  531. data/src/core/lib/iomgr/error.cc +17 -12
  532. data/src/core/lib/iomgr/error_internal.h +1 -1
  533. data/src/core/lib/iomgr/ev_epoll1_linux.cc +20 -13
  534. data/src/core/lib/iomgr/ev_epollex_linux.cc +25 -17
  535. data/src/core/lib/iomgr/ev_poll_posix.cc +9 -7
  536. data/src/core/lib/iomgr/ev_posix.cc +0 -2
  537. data/src/core/lib/iomgr/exec_ctx.cc +1 -1
  538. data/src/core/lib/iomgr/exec_ctx.h +16 -12
  539. data/src/core/lib/iomgr/executor.cc +2 -1
  540. data/src/core/lib/iomgr/executor.h +1 -1
  541. data/src/core/lib/iomgr/executor/mpmcqueue.h +5 -5
  542. data/src/core/lib/iomgr/executor/threadpool.h +4 -4
  543. data/src/core/lib/iomgr/iomgr.cc +1 -11
  544. data/src/core/lib/iomgr/iomgr.h +0 -10
  545. data/src/core/lib/iomgr/load_file.h +1 -1
  546. data/src/core/lib/iomgr/lockfree_event.cc +19 -14
  547. data/src/core/lib/iomgr/lockfree_event.h +2 -2
  548. data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.cc +128 -44
  549. data/src/core/lib/iomgr/parse_address.h +77 -0
  550. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +2 -1
  551. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +1 -1
  552. data/src/core/lib/iomgr/pollset_set_custom.cc +1 -1
  553. data/src/core/lib/iomgr/python_util.h +4 -4
  554. data/src/core/lib/iomgr/resolve_address.cc +4 -4
  555. data/src/core/lib/iomgr/resolve_address_posix.cc +1 -5
  556. data/src/core/lib/iomgr/resource_quota.cc +4 -4
  557. data/src/core/lib/iomgr/sockaddr_utils.cc +12 -11
  558. data/src/core/lib/iomgr/sockaddr_utils.h +3 -2
  559. data/src/core/lib/iomgr/socket_factory_posix.cc +3 -2
  560. data/src/core/lib/iomgr/socket_mutator.cc +3 -2
  561. data/src/core/lib/iomgr/tcp_client.cc +3 -3
  562. data/src/core/lib/iomgr/tcp_client_custom.cc +7 -6
  563. data/src/core/lib/iomgr/tcp_custom.cc +53 -32
  564. data/src/core/lib/iomgr/tcp_posix.cc +43 -21
  565. data/src/core/lib/iomgr/tcp_server_custom.cc +28 -22
  566. data/src/core/lib/iomgr/tcp_windows.cc +26 -10
  567. data/src/core/lib/iomgr/timer_custom.cc +5 -5
  568. data/src/core/lib/iomgr/timer_generic.cc +3 -3
  569. data/src/core/lib/iomgr/timer_manager.cc +2 -2
  570. data/src/core/lib/iomgr/udp_server.cc +1 -2
  571. data/src/core/lib/iomgr/udp_server.h +1 -2
  572. data/src/core/lib/iomgr/unix_sockets_posix.cc +32 -21
  573. data/src/core/lib/iomgr/unix_sockets_posix.h +5 -0
  574. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +7 -0
  575. data/src/core/lib/iomgr/wakeup_fd_pipe.cc +2 -2
  576. data/src/core/lib/json/json.h +12 -2
  577. data/src/core/lib/json/json_reader.cc +8 -4
  578. data/src/core/lib/json/json_util.cc +58 -0
  579. data/src/core/lib/json/json_util.h +204 -0
  580. data/src/core/lib/json/json_writer.cc +2 -1
  581. data/src/core/lib/security/authorization/authorization_engine.cc +177 -0
  582. data/src/core/lib/security/authorization/authorization_engine.h +84 -0
  583. data/src/core/lib/security/authorization/evaluate_args.cc +148 -0
  584. data/src/core/lib/security/authorization/evaluate_args.h +59 -0
  585. data/src/core/lib/security/authorization/mock_cel/activation.h +57 -0
  586. data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +44 -0
  587. data/src/core/lib/security/authorization/mock_cel/cel_expression.h +69 -0
  588. data/src/core/lib/security/authorization/mock_cel/cel_value.h +97 -0
  589. data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +67 -0
  590. data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +57 -0
  591. data/src/core/lib/security/context/security_context.cc +4 -3
  592. data/src/core/lib/security/context/security_context.h +3 -1
  593. data/src/core/lib/security/credentials/alts/check_gcp_environment.cc +1 -1
  594. data/src/core/lib/security/credentials/credentials.cc +7 -7
  595. data/src/core/lib/security/credentials/credentials.h +3 -3
  596. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +413 -0
  597. data/src/core/lib/security/credentials/external/aws_external_account_credentials.h +80 -0
  598. data/src/core/lib/security/credentials/external/aws_request_signer.cc +213 -0
  599. data/src/core/lib/security/credentials/external/aws_request_signer.h +72 -0
  600. data/src/core/lib/security/credentials/external/external_account_credentials.cc +497 -0
  601. data/src/core/lib/security/credentials/external/external_account_credentials.h +120 -0
  602. data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +135 -0
  603. data/src/core/lib/security/credentials/external/file_external_account_credentials.h +48 -0
  604. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +213 -0
  605. data/src/core/lib/security/credentials/external/url_external_account_credentials.h +58 -0
  606. data/src/core/lib/security/credentials/fake/fake_credentials.cc +2 -1
  607. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +74 -50
  608. data/src/core/lib/security/credentials/insecure/insecure_credentials.cc +64 -0
  609. data/src/core/lib/security/credentials/jwt/json_token.cc +6 -3
  610. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +4 -3
  611. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +8 -4
  612. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +39 -46
  613. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +5 -4
  614. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -1
  615. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +5 -5
  616. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +1 -1
  617. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +346 -0
  618. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +213 -0
  619. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +399 -0
  620. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +138 -0
  621. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +78 -150
  622. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +57 -187
  623. data/src/core/lib/security/credentials/tls/tls_credentials.cc +16 -12
  624. data/src/core/lib/security/credentials/tls/tls_credentials.h +2 -2
  625. data/src/core/lib/security/credentials/tls/tls_utils.cc +91 -0
  626. data/src/core/lib/security/credentials/tls/tls_utils.h +38 -0
  627. data/src/core/lib/security/credentials/xds/xds_credentials.cc +175 -0
  628. data/src/core/lib/security/credentials/xds/xds_credentials.h +69 -0
  629. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +1 -1
  630. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +10 -15
  631. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +121 -0
  632. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.h +87 -0
  633. data/src/core/lib/security/security_connector/load_system_roots.h +4 -0
  634. data/src/core/lib/security/security_connector/load_system_roots_linux.h +2 -0
  635. data/src/core/lib/security/security_connector/local/local_security_connector.cc +3 -3
  636. data/src/core/lib/security/security_connector/security_connector.cc +4 -3
  637. data/src/core/lib/security/security_connector/security_connector.h +4 -2
  638. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -4
  639. data/src/core/lib/security/security_connector/ssl_utils.cc +2 -2
  640. data/src/core/lib/security/security_connector/ssl_utils.h +19 -19
  641. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +342 -279
  642. data/src/core/lib/security/security_connector/tls/tls_security_connector.h +105 -61
  643. data/src/core/lib/security/transport/secure_endpoint.cc +9 -3
  644. data/src/core/lib/security/transport/security_handshaker.cc +3 -3
  645. data/src/core/lib/security/transport/server_auth_filter.cc +2 -1
  646. data/src/core/lib/security/util/json_util.h +1 -0
  647. data/src/core/lib/slice/slice.cc +7 -4
  648. data/src/core/lib/slice/slice_buffer.cc +2 -1
  649. data/src/core/lib/slice/slice_intern.cc +6 -7
  650. data/src/core/lib/slice/slice_internal.h +2 -2
  651. data/src/core/lib/surface/call.cc +53 -44
  652. data/src/core/lib/surface/call.h +2 -1
  653. data/src/core/lib/surface/call_details.cc +8 -8
  654. data/src/core/lib/surface/channel.cc +53 -61
  655. data/src/core/lib/surface/channel.h +21 -5
  656. data/src/core/lib/surface/channel_init.cc +1 -1
  657. data/src/core/lib/surface/completion_queue.cc +38 -294
  658. data/src/core/lib/surface/completion_queue.h +16 -24
  659. data/src/core/lib/surface/init.cc +32 -16
  660. data/src/core/lib/surface/lame_client.cc +20 -46
  661. data/src/core/lib/surface/lame_client.h +4 -0
  662. data/src/core/lib/surface/server.cc +1107 -1239
  663. data/src/core/lib/surface/server.h +394 -86
  664. data/src/core/lib/surface/validate_metadata.h +3 -0
  665. data/src/core/lib/surface/version.cc +2 -2
  666. data/src/core/lib/transport/authority_override.cc +40 -0
  667. data/src/core/lib/transport/authority_override.h +37 -0
  668. data/src/core/lib/transport/bdp_estimator.cc +1 -1
  669. data/src/core/lib/transport/bdp_estimator.h +2 -1
  670. data/src/core/lib/transport/byte_stream.h +3 -3
  671. data/src/core/lib/transport/connectivity_state.cc +18 -13
  672. data/src/core/lib/transport/connectivity_state.h +26 -12
  673. data/src/core/lib/transport/error_utils.cc +13 -0
  674. data/src/core/lib/transport/error_utils.h +7 -1
  675. data/src/core/lib/transport/metadata.cc +11 -1
  676. data/src/core/lib/transport/metadata.h +2 -2
  677. data/src/core/lib/transport/metadata_batch.h +4 -4
  678. data/src/core/lib/transport/static_metadata.cc +296 -277
  679. data/src/core/lib/transport/static_metadata.h +80 -73
  680. data/src/core/lib/transport/status_metadata.cc +4 -3
  681. data/src/core/lib/transport/timeout_encoding.cc +4 -4
  682. data/src/core/lib/transport/transport.cc +5 -3
  683. data/src/core/lib/transport/transport.h +15 -8
  684. data/src/core/lib/uri/uri_parser.cc +131 -247
  685. data/src/core/lib/uri/uri_parser.h +58 -20
  686. data/src/core/plugin_registry/grpc_plugin_registry.cc +41 -20
  687. data/src/core/tsi/alts/crypt/gsec.cc +5 -4
  688. data/src/core/tsi/alts/frame_protector/frame_handler.cc +8 -6
  689. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -1
  690. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +49 -26
  691. data/src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.cc +8 -6
  692. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +4 -4
  693. data/src/core/tsi/fake_transport_security.cc +6 -3
  694. data/src/core/tsi/local_transport_security.cc +5 -1
  695. data/src/core/tsi/local_transport_security.h +6 -7
  696. data/src/core/tsi/ssl/session_cache/ssl_session.h +3 -0
  697. data/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc +1 -1
  698. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +4 -1
  699. data/src/core/tsi/ssl_transport_security.cc +81 -67
  700. data/src/core/tsi/ssl_transport_security.h +9 -6
  701. data/src/core/tsi/transport_security.cc +10 -8
  702. data/src/core/tsi/transport_security_interface.h +1 -1
  703. data/src/ruby/ext/grpc/extconf.rb +1 -1
  704. data/src/ruby/ext/grpc/rb_channel_credentials.c +9 -0
  705. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  706. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +38 -18
  707. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +74 -44
  708. data/src/ruby/lib/grpc/version.rb +1 -1
  709. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +28 -0
  710. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +18 -0
  711. data/src/ruby/spec/channel_credentials_spec.rb +10 -0
  712. data/src/ruby/spec/generic/active_call_spec.rb +19 -8
  713. data/src/ruby/spec/pb/codegen/package_option_spec.rb +2 -6
  714. data/third_party/abseil-cpp/absl/algorithm/container.h +1764 -0
  715. data/third_party/abseil-cpp/absl/base/attributes.h +99 -38
  716. data/third_party/abseil-cpp/absl/base/call_once.h +1 -1
  717. data/third_party/abseil-cpp/absl/base/casts.h +9 -6
  718. data/third_party/abseil-cpp/absl/base/config.h +60 -17
  719. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +428 -335
  720. data/third_party/abseil-cpp/absl/base/internal/bits.h +17 -16
  721. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +166 -0
  722. data/third_party/abseil-cpp/absl/base/internal/dynamic_annotations.h +398 -0
  723. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.cc +93 -0
  724. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.h +130 -0
  725. data/third_party/abseil-cpp/absl/base/internal/invoke.h +4 -4
  726. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +620 -0
  727. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.h +126 -0
  728. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +29 -1
  729. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +2 -2
  730. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +7 -5
  731. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +25 -38
  732. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +19 -25
  733. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +8 -0
  734. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +28 -5
  735. data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +8 -0
  736. data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +3 -1
  737. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +2 -2
  738. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +3 -3
  739. data/third_party/abseil-cpp/absl/base/macros.h +36 -109
  740. data/third_party/abseil-cpp/absl/base/optimization.h +61 -1
  741. data/third_party/abseil-cpp/absl/base/options.h +31 -4
  742. data/third_party/abseil-cpp/absl/base/policy_checks.h +1 -1
  743. data/third_party/abseil-cpp/absl/base/thread_annotations.h +94 -39
  744. data/third_party/abseil-cpp/absl/container/fixed_array.h +532 -0
  745. data/third_party/abseil-cpp/absl/container/flat_hash_map.h +606 -0
  746. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +504 -0
  747. data/third_party/abseil-cpp/absl/container/inlined_vector.h +33 -36
  748. data/third_party/abseil-cpp/absl/container/internal/common.h +206 -0
  749. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +33 -8
  750. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +460 -0
  751. data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +161 -0
  752. data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +208 -0
  753. data/third_party/abseil-cpp/absl/container/internal/hashtable_debug_hooks.h +85 -0
  754. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +270 -0
  755. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +321 -0
  756. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler_force_weak_definition.cc +30 -0
  757. data/third_party/abseil-cpp/absl/container/internal/have_sse.h +50 -0
  758. data/third_party/abseil-cpp/absl/container/internal/layout.h +743 -0
  759. data/third_party/abseil-cpp/absl/container/internal/raw_hash_map.h +197 -0
  760. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +48 -0
  761. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +1903 -0
  762. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +139 -0
  763. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.h +32 -0
  764. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +1945 -0
  765. data/third_party/abseil-cpp/absl/debugging/internal/demangle.h +71 -0
  766. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.cc +382 -0
  767. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +134 -0
  768. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +196 -0
  769. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +134 -0
  770. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +89 -0
  771. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +108 -0
  772. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +248 -0
  773. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_unimplemented-inl.inc +24 -0
  774. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +93 -0
  775. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +346 -0
  776. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +149 -0
  777. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +173 -0
  778. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.h +158 -0
  779. data/third_party/abseil-cpp/absl/debugging/stacktrace.cc +140 -0
  780. data/third_party/abseil-cpp/absl/debugging/stacktrace.h +231 -0
  781. data/third_party/abseil-cpp/absl/debugging/symbolize.cc +36 -0
  782. data/third_party/abseil-cpp/absl/debugging/symbolize.h +99 -0
  783. data/third_party/abseil-cpp/absl/debugging/symbolize_darwin.inc +101 -0
  784. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +1560 -0
  785. data/third_party/abseil-cpp/absl/debugging/symbolize_unimplemented.inc +40 -0
  786. data/third_party/abseil-cpp/absl/debugging/symbolize_win32.inc +81 -0
  787. data/third_party/abseil-cpp/absl/functional/bind_front.h +184 -0
  788. data/third_party/abseil-cpp/absl/functional/function_ref.h +139 -0
  789. data/third_party/abseil-cpp/absl/functional/internal/front_binder.h +95 -0
  790. data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +106 -0
  791. data/third_party/abseil-cpp/absl/hash/hash.h +325 -0
  792. data/third_party/abseil-cpp/absl/hash/internal/city.cc +346 -0
  793. data/third_party/abseil-cpp/absl/hash/internal/city.h +96 -0
  794. data/third_party/abseil-cpp/absl/hash/internal/hash.cc +55 -0
  795. data/third_party/abseil-cpp/absl/hash/internal/hash.h +996 -0
  796. data/third_party/abseil-cpp/absl/memory/memory.h +4 -0
  797. data/third_party/abseil-cpp/absl/meta/type_traits.h +2 -8
  798. data/third_party/abseil-cpp/absl/numeric/int128.cc +13 -27
  799. data/third_party/abseil-cpp/absl/numeric/int128.h +16 -15
  800. data/third_party/abseil-cpp/absl/status/internal/status_internal.h +51 -0
  801. data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +399 -0
  802. data/third_party/abseil-cpp/absl/status/status.cc +445 -0
  803. data/third_party/abseil-cpp/absl/status/status.h +817 -0
  804. data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +38 -0
  805. data/third_party/abseil-cpp/absl/status/status_payload_printer.h +51 -0
  806. data/third_party/abseil-cpp/absl/status/statusor.cc +71 -0
  807. data/third_party/abseil-cpp/absl/status/statusor.h +760 -0
  808. data/third_party/abseil-cpp/absl/strings/charconv.cc +2 -2
  809. data/third_party/abseil-cpp/absl/strings/cord.cc +1998 -0
  810. data/third_party/abseil-cpp/absl/strings/cord.h +1276 -0
  811. data/third_party/abseil-cpp/absl/strings/escaping.cc +9 -9
  812. data/third_party/abseil-cpp/absl/strings/internal/char_map.h +1 -1
  813. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +1 -1
  814. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +2 -2
  815. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +2 -2
  816. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +173 -0
  817. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +222 -136
  818. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +136 -64
  819. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.cc +1 -1
  820. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +14 -21
  821. data/third_party/abseil-cpp/absl/strings/internal/str_format/checker.h +7 -14
  822. data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.cc +31 -7
  823. data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.h +147 -135
  824. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +999 -87
  825. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.h +3 -3
  826. data/third_party/abseil-cpp/absl/strings/internal/str_format/output.h +4 -12
  827. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.cc +8 -6
  828. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.h +13 -11
  829. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +2 -2
  830. data/third_party/abseil-cpp/absl/strings/str_cat.cc +4 -4
  831. data/third_party/abseil-cpp/absl/strings/str_cat.h +1 -1
  832. data/third_party/abseil-cpp/absl/strings/str_format.h +289 -13
  833. data/third_party/abseil-cpp/absl/strings/str_split.cc +2 -2
  834. data/third_party/abseil-cpp/absl/strings/str_split.h +1 -0
  835. data/third_party/abseil-cpp/absl/strings/string_view.h +26 -19
  836. data/third_party/abseil-cpp/absl/strings/substitute.cc +5 -5
  837. data/third_party/abseil-cpp/absl/strings/substitute.h +32 -29
  838. data/third_party/abseil-cpp/absl/synchronization/barrier.cc +52 -0
  839. data/third_party/abseil-cpp/absl/synchronization/barrier.h +79 -0
  840. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.cc +57 -0
  841. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.h +99 -0
  842. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +140 -0
  843. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.h +60 -0
  844. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +697 -0
  845. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.h +141 -0
  846. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +155 -0
  847. data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +249 -0
  848. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +106 -0
  849. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +115 -0
  850. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +492 -0
  851. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +159 -0
  852. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +2739 -0
  853. data/third_party/abseil-cpp/absl/synchronization/mutex.h +1065 -0
  854. data/third_party/abseil-cpp/absl/synchronization/notification.cc +78 -0
  855. data/third_party/abseil-cpp/absl/synchronization/notification.h +123 -0
  856. data/third_party/abseil-cpp/absl/time/civil_time.cc +9 -9
  857. data/third_party/abseil-cpp/absl/time/clock.cc +3 -3
  858. data/third_party/abseil-cpp/absl/time/duration.cc +90 -59
  859. data/third_party/abseil-cpp/absl/time/format.cc +43 -36
  860. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +26 -16
  861. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/time_zone.h +4 -2
  862. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/zone_info_source.h +1 -1
  863. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +136 -29
  864. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +13 -21
  865. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +1 -1
  866. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +136 -129
  867. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +4 -5
  868. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +8 -7
  869. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +6 -6
  870. data/third_party/abseil-cpp/absl/time/internal/cctz/src/zone_info_source.cc +2 -1
  871. data/third_party/abseil-cpp/absl/time/time.h +15 -16
  872. data/third_party/abseil-cpp/absl/types/bad_variant_access.cc +64 -0
  873. data/third_party/abseil-cpp/absl/types/bad_variant_access.h +82 -0
  874. data/third_party/abseil-cpp/absl/types/internal/variant.h +1646 -0
  875. data/third_party/abseil-cpp/absl/types/optional.h +9 -9
  876. data/third_party/abseil-cpp/absl/types/span.h +49 -36
  877. data/third_party/abseil-cpp/absl/types/variant.h +861 -0
  878. data/third_party/abseil-cpp/absl/utility/utility.h +2 -2
  879. data/third_party/address_sorting/include/address_sorting/address_sorting.h +2 -0
  880. data/third_party/boringssl-with-bazel/err_data.c +479 -467
  881. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +0 -6
  882. data/third_party/boringssl-with-bazel/src/crypto/bio/bio.c +2 -0
  883. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +9 -43
  884. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa_asn1.c +55 -4
  885. data/third_party/boringssl-with-bazel/src/crypto/dsa/internal.h +34 -0
  886. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +4 -0
  887. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.c +16 -0
  888. data/third_party/boringssl-with-bazel/src/crypto/evp/p_dsa_asn1.c +6 -2
  889. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aes.c +173 -35
  890. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +2 -0
  891. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +4 -0
  892. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +30 -10
  893. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +56 -22
  894. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +8 -2
  895. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +543 -0
  896. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +237 -0
  897. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +118 -49
  898. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +267 -95
  899. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +210 -34
  900. data/third_party/boringssl-with-bazel/src/crypto/trust_token/voprf.c +766 -0
  901. data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +3 -3
  902. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +6 -4
  903. data/third_party/boringssl-with-bazel/src/crypto/x509/t_crl.c +3 -3
  904. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509.c +1 -1
  905. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +7 -2
  906. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_ext.c +21 -18
  907. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_obj.c +1 -1
  908. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +24 -3
  909. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +3 -3
  910. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_txt.c +67 -67
  911. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +3 -3
  912. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +29 -35
  913. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +13 -2
  914. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +9 -8
  915. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +10 -10
  916. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +2 -2
  917. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +28 -40
  918. data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +20 -0
  919. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +3 -1
  920. data/third_party/boringssl-with-bazel/src/crypto/x509v3/ext_dat.h +1 -4
  921. data/third_party/boringssl-with-bazel/src/crypto/x509v3/pcy_data.c +5 -3
  922. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_alt.c +14 -14
  923. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_conf.c +7 -3
  924. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_genn.c +2 -2
  925. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_info.c +1 -1
  926. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_prn.c +1 -1
  927. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +55 -8
  928. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +1 -1
  929. data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +24 -0
  930. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +54 -0
  931. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +0 -1
  932. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +6 -3
  933. data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +4 -0
  934. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +6 -0
  935. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +1 -1
  936. data/third_party/boringssl-with-bazel/src/include/openssl/des.h +6 -0
  937. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +12 -0
  938. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +9 -0
  939. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +4 -1
  940. data/third_party/boringssl-with-bazel/src/include/openssl/opensslconf.h +3 -0
  941. data/third_party/boringssl-with-bazel/src/include/openssl/pem.h +202 -134
  942. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +103 -10
  943. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +5 -2
  944. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +42 -14
  945. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +199 -78
  946. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +482 -432
  947. data/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc +18 -5
  948. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +35 -0
  949. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +18 -18
  950. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +2 -3
  951. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +1 -1
  952. data/third_party/boringssl-with-bazel/src/ssl/internal.h +49 -10
  953. data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +42 -1
  954. data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +3 -6
  955. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +8 -9
  956. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +77 -0
  957. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +11 -14
  958. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +250 -20
  959. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +1 -2
  960. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +57 -19
  961. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +140 -41
  962. data/third_party/boringssl-with-bazel/src/ssl/tls_record.cc +5 -3
  963. data/third_party/upb/third_party/wyhash/wyhash.h +145 -0
  964. data/third_party/upb/upb/decode.c +275 -145
  965. data/third_party/upb/upb/decode.h +20 -1
  966. data/third_party/upb/upb/decode.int.h +163 -0
  967. data/third_party/upb/upb/decode_fast.c +1040 -0
  968. data/third_party/upb/upb/decode_fast.h +126 -0
  969. data/third_party/upb/upb/def.c +2178 -0
  970. data/third_party/upb/upb/def.h +315 -0
  971. data/third_party/upb/upb/def.hpp +439 -0
  972. data/third_party/upb/upb/encode.c +229 -171
  973. data/third_party/upb/upb/encode.h +27 -2
  974. data/third_party/upb/upb/json_decode.c +1443 -0
  975. data/third_party/upb/upb/json_decode.h +23 -0
  976. data/third_party/upb/upb/json_encode.c +713 -0
  977. data/third_party/upb/upb/json_encode.h +36 -0
  978. data/third_party/upb/upb/msg.c +167 -88
  979. data/third_party/upb/upb/msg.h +175 -35
  980. data/third_party/upb/upb/port_def.inc +75 -62
  981. data/third_party/upb/upb/port_undef.inc +3 -7
  982. data/third_party/upb/upb/reflection.c +408 -0
  983. data/third_party/upb/upb/reflection.h +168 -0
  984. data/third_party/upb/upb/table.c +34 -208
  985. data/third_party/upb/upb/table.int.h +14 -14
  986. data/third_party/upb/upb/text_encode.c +421 -0
  987. data/third_party/upb/upb/text_encode.h +38 -0
  988. data/third_party/upb/upb/upb.c +33 -54
  989. data/third_party/upb/upb/upb.h +56 -1
  990. data/third_party/upb/upb/upb.hpp +6 -4
  991. data/third_party/upb/upb/upb.int.h +29 -0
  992. metadata +508 -172
  993. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +0 -938
  994. data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +0 -528
  995. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +0 -1143
  996. data/src/core/ext/filters/client_channel/parse_address.h +0 -53
  997. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +0 -485
  998. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +0 -68
  999. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +0 -353
  1000. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +0 -142
  1001. data/src/core/ext/filters/client_channel/xds/xds_api.cc +0 -2110
  1002. data/src/core/ext/filters/client_channel/xds/xds_api.h +0 -345
  1003. data/src/core/ext/filters/client_channel/xds/xds_channel.h +0 -46
  1004. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +0 -106
  1005. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +0 -21
  1006. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +0 -34
  1007. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.c +0 -114
  1008. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +0 -429
  1009. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.c +0 -72
  1010. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +0 -198
  1011. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.c +0 -105
  1012. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +0 -388
  1013. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +0 -52
  1014. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +0 -403
  1015. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +0 -1453
  1016. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +0 -74
  1017. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +0 -226
  1018. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.c +0 -35
  1019. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +0 -69
  1020. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c +0 -55
  1021. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +0 -323
  1022. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +0 -112
  1023. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +0 -334
  1024. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.c +0 -35
  1025. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +0 -79
  1026. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +0 -313
  1027. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +0 -891
  1028. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +0 -96
  1029. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +0 -328
  1030. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.c +0 -34
  1031. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +0 -71
  1032. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +0 -197
  1033. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +0 -649
  1034. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +0 -172
  1035. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +0 -693
  1036. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.c +0 -36
  1037. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +0 -80
  1038. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +0 -152
  1039. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +0 -536
  1040. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +0 -88
  1041. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +0 -129
  1042. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +0 -386
  1043. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +0 -52
  1044. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +0 -92
  1045. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.h +0 -224
  1046. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +0 -18
  1047. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +0 -32
  1048. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.c +0 -91
  1049. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +0 -273
  1050. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +0 -112
  1051. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +0 -332
  1052. data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.h +0 -52
  1053. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.c +0 -109
  1054. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +0 -415
  1055. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.c +0 -18
  1056. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.h +0 -32
  1057. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +0 -145
  1058. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.h +0 -538
  1059. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.c +0 -43
  1060. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.h +0 -111
  1061. data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.h +0 -52
  1062. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.c +0 -63
  1063. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.h +0 -204
  1064. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.c +0 -18
  1065. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.h +0 -32
  1066. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +0 -815
  1067. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +0 -2984
  1068. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.c +0 -59
  1069. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.h +0 -135
  1070. data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.h +0 -52
  1071. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +0 -228
  1072. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.h +0 -732
  1073. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.c +0 -316
  1074. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +0 -1167
  1075. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.c +0 -33
  1076. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.h +0 -65
  1077. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.c +0 -51
  1078. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +0 -125
  1079. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +0 -49
  1080. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +0 -54
  1081. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +0 -136
  1082. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.c +0 -63
  1083. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +0 -145
  1084. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.c +0 -53
  1085. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.h +0 -133
  1086. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.c +0 -88
  1087. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.h +0 -258
  1088. data/src/core/ext/upb-generated/envoy/type/percent.upb.c +0 -39
  1089. data/src/core/ext/upb-generated/envoy/type/percent.upb.h +0 -86
  1090. data/src/core/ext/upb-generated/envoy/type/range.upb.c +0 -50
  1091. data/src/core/ext/upb-generated/envoy/type/range.upb.h +0 -111
  1092. data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.h +0 -61
  1093. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.c +0 -89
  1094. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.h +0 -250
  1095. data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +0 -17
  1096. data/src/core/lib/gprpp/map.h +0 -53
  1097. data/src/core/lib/security/transport/target_authority_table.cc +0 -75
  1098. data/src/core/lib/security/transport/target_authority_table.h +0 -40
  1099. data/src/core/lib/slice/slice_hash_table.h +0 -199
  1100. data/src/core/lib/slice/slice_weak_hash_table.h +0 -102
  1101. data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +0 -129
  1102. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_pku.c +0 -110
  1103. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_sxnet.c +0 -274
  1104. data/third_party/upb/upb/port.c +0 -26
@@ -51,52 +51,44 @@ typedef struct grpc_cq_completion {
51
51
  } grpc_cq_completion;
52
52
 
53
53
  #ifndef NDEBUG
54
- void grpc_cq_internal_ref(grpc_completion_queue* cc, const char* reason,
54
+ void grpc_cq_internal_ref(grpc_completion_queue* cq, const char* reason,
55
55
  const char* file, int line);
56
- void grpc_cq_internal_unref(grpc_completion_queue* cc, const char* reason,
56
+ void grpc_cq_internal_unref(grpc_completion_queue* cq, const char* reason,
57
57
  const char* file, int line);
58
- #define GRPC_CQ_INTERNAL_REF(cc, reason) \
59
- grpc_cq_internal_ref(cc, reason, __FILE__, __LINE__)
60
- #define GRPC_CQ_INTERNAL_UNREF(cc, reason) \
61
- grpc_cq_internal_unref(cc, reason, __FILE__, __LINE__)
58
+ #define GRPC_CQ_INTERNAL_REF(cq, reason) \
59
+ grpc_cq_internal_ref(cq, reason, __FILE__, __LINE__)
60
+ #define GRPC_CQ_INTERNAL_UNREF(cq, reason) \
61
+ grpc_cq_internal_unref(cq, reason, __FILE__, __LINE__)
62
62
  #else
63
- void grpc_cq_internal_ref(grpc_completion_queue* cc);
64
- void grpc_cq_internal_unref(grpc_completion_queue* cc);
65
- #define GRPC_CQ_INTERNAL_REF(cc, reason) grpc_cq_internal_ref(cc)
66
- #define GRPC_CQ_INTERNAL_UNREF(cc, reason) grpc_cq_internal_unref(cc)
63
+ void grpc_cq_internal_ref(grpc_completion_queue* cq);
64
+ void grpc_cq_internal_unref(grpc_completion_queue* cq);
65
+ #define GRPC_CQ_INTERNAL_REF(cq, reason) grpc_cq_internal_ref(cq)
66
+ #define GRPC_CQ_INTERNAL_UNREF(cq, reason) grpc_cq_internal_unref(cq)
67
67
  #endif
68
68
 
69
69
  /* Initializes global variables used by completion queues */
70
70
  void grpc_cq_global_init();
71
71
 
72
- // Completion queue initializations that must be done after iomgr
73
- // TODO(vjpai): Remove when callback_alternative is no longer needed.
74
- void grpc_cq_init();
75
-
76
- // Completion queue shutdowns that must be done before iomgr shutdown.
77
- // TODO(vjpai): Remove when callback_alternative is no longer needed.
78
- void grpc_cq_shutdown();
79
-
80
72
  /* Flag that an operation is beginning: the completion channel will not finish
81
73
  shutdown until a corrensponding grpc_cq_end_* call is made.
82
74
  \a tag is currently used only in debug builds. Return true on success, and
83
75
  false if completion_queue has been shutdown. */
84
- bool grpc_cq_begin_op(grpc_completion_queue* cc, void* tag);
76
+ bool grpc_cq_begin_op(grpc_completion_queue* cq, void* tag);
85
77
 
86
78
  /* Queue a GRPC_OP_COMPLETED operation; tag must correspond to the tag passed to
87
79
  grpc_cq_begin_op */
88
- void grpc_cq_end_op(grpc_completion_queue* cc, void* tag, grpc_error* error,
80
+ void grpc_cq_end_op(grpc_completion_queue* cq, void* tag, grpc_error* error,
89
81
  void (*done)(void* done_arg, grpc_cq_completion* storage),
90
82
  void* done_arg, grpc_cq_completion* storage,
91
83
  bool internal = false);
92
84
 
93
- grpc_pollset* grpc_cq_pollset(grpc_completion_queue* cc);
85
+ grpc_pollset* grpc_cq_pollset(grpc_completion_queue* cq);
94
86
 
95
- bool grpc_cq_can_listen(grpc_completion_queue* cc);
87
+ bool grpc_cq_can_listen(grpc_completion_queue* cq);
96
88
 
97
- grpc_cq_completion_type grpc_get_cq_completion_type(grpc_completion_queue* cc);
89
+ grpc_cq_completion_type grpc_get_cq_completion_type(grpc_completion_queue* cq);
98
90
 
99
- int grpc_get_cq_poll_num(grpc_completion_queue* cc);
91
+ int grpc_get_cq_poll_num(grpc_completion_queue* cq);
100
92
 
101
93
  grpc_completion_queue* grpc_completion_queue_create_internal(
102
94
  grpc_cq_completion_type completion_type, grpc_cq_polling_type polling_type,
@@ -18,6 +18,8 @@
18
18
 
19
19
  #include <grpc/support/port_platform.h>
20
20
 
21
+ #include "src/core/lib/surface/init.h"
22
+
21
23
  #include <limits.h>
22
24
  #include <memory.h>
23
25
 
@@ -26,6 +28,7 @@
26
28
  #include <grpc/support/alloc.h>
27
29
  #include <grpc/support/log.h>
28
30
  #include <grpc/support/time.h>
31
+
29
32
  #include "src/core/lib/channel/channel_stack.h"
30
33
  #include "src/core/lib/channel/channelz_registry.h"
31
34
  #include "src/core/lib/channel/connected_channel.h"
@@ -37,6 +40,7 @@
37
40
  #include "src/core/lib/http/parser.h"
38
41
  #include "src/core/lib/iomgr/call_combiner.h"
39
42
  #include "src/core/lib/iomgr/combiner.h"
43
+ #include "src/core/lib/iomgr/exec_ctx.h"
40
44
  #include "src/core/lib/iomgr/executor.h"
41
45
  #include "src/core/lib/iomgr/iomgr.h"
42
46
  #include "src/core/lib/iomgr/resource_quota.h"
@@ -47,7 +51,6 @@
47
51
  #include "src/core/lib/surface/call.h"
48
52
  #include "src/core/lib/surface/channel_init.h"
49
53
  #include "src/core/lib/surface/completion_queue.h"
50
- #include "src/core/lib/surface/init.h"
51
54
  #include "src/core/lib/surface/lame_client.h"
52
55
  #include "src/core/lib/surface/server.h"
53
56
  #include "src/core/lib/transport/bdp_estimator.h"
@@ -98,11 +101,12 @@ static void register_builtin_channel_init() {
98
101
  grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
99
102
  GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
100
103
  grpc_add_connected_filter, nullptr);
101
- grpc_channel_init_register_stage(GRPC_CLIENT_LAME_CHANNEL,
102
- GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
103
- append_filter, (void*)&grpc_lame_filter);
104
- grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, prepend_filter,
105
- (void*)&grpc_server_top_filter);
104
+ grpc_channel_init_register_stage(
105
+ GRPC_CLIENT_LAME_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
106
+ append_filter, const_cast<grpc_channel_filter*>(&grpc_lame_filter));
107
+ grpc_channel_init_register_stage(
108
+ GRPC_SERVER_CHANNEL, INT_MAX, prepend_filter,
109
+ const_cast<grpc_channel_filter*>(&grpc_core::Server::kServerTopFilter));
106
110
  }
107
111
 
108
112
  typedef struct grpc_plugin {
@@ -144,7 +148,6 @@ void grpc_init(void) {
144
148
  grpc_core::ApplicationCallbackExecCtx::GlobalInit();
145
149
  grpc_core::ExecCtx::GlobalInit();
146
150
  grpc_iomgr_init();
147
- grpc_cq_init();
148
151
  gpr_timers_global_init();
149
152
  grpc_core::HandshakerRegistry::Init();
150
153
  grpc_security_init();
@@ -170,7 +173,6 @@ void grpc_shutdown_internal_locked(void) {
170
173
  int i;
171
174
  {
172
175
  grpc_core::ExecCtx exec_ctx(0);
173
- grpc_cq_shutdown();
174
176
  grpc_iomgr_shutdown_background_closure();
175
177
  {
176
178
  grpc_timer_manager_set_threading(false); // shutdown timer_manager thread
@@ -213,15 +215,29 @@ void grpc_shutdown_internal(void* /*ignored*/) {
213
215
  void grpc_shutdown(void) {
214
216
  GRPC_API_TRACE("grpc_shutdown(void)", 0, ());
215
217
  grpc_core::MutexLock lock(&g_init_mu);
218
+
216
219
  if (--g_initializations == 0) {
217
- g_initializations++;
218
- g_shutting_down = true;
219
- // spawn a detached thread to do the actual clean up in case we are
220
- // currently in an executor thread.
221
- grpc_core::Thread cleanup_thread(
222
- "grpc_shutdown", grpc_shutdown_internal, nullptr, nullptr,
223
- grpc_core::Thread::Options().set_joinable(false).set_tracked(false));
224
- cleanup_thread.Start();
220
+ grpc_core::ApplicationCallbackExecCtx* acec =
221
+ grpc_core::ApplicationCallbackExecCtx::Get();
222
+ if (!grpc_iomgr_is_any_background_poller_thread() &&
223
+ (acec == nullptr ||
224
+ (acec->Flags() & GRPC_APP_CALLBACK_EXEC_CTX_FLAG_IS_INTERNAL_THREAD) ==
225
+ 0)) {
226
+ // just run clean-up when this is called on non-executor thread.
227
+ gpr_log(GPR_DEBUG, "grpc_shutdown starts clean-up now");
228
+ g_shutting_down = true;
229
+ grpc_shutdown_internal_locked();
230
+ } else {
231
+ // spawn a detached thread to do the actual clean up in case we are
232
+ // currently in an executor thread.
233
+ gpr_log(GPR_DEBUG, "grpc_shutdown spawns clean-up thread");
234
+ g_initializations++;
235
+ g_shutting_down = true;
236
+ grpc_core::Thread cleanup_thread(
237
+ "grpc_shutdown", grpc_shutdown_internal, nullptr, nullptr,
238
+ grpc_core::Thread::Options().set_joinable(false).set_tracked(false));
239
+ cleanup_thread.Start();
240
+ }
225
241
  }
226
242
  }
227
243
 
@@ -39,59 +39,25 @@ namespace grpc_core {
39
39
 
40
40
  namespace {
41
41
 
42
- struct CallData {
43
- CallCombiner* call_combiner;
44
- grpc_linked_mdelem status;
45
- grpc_linked_mdelem details;
46
- Atomic<bool> filled_metadata;
47
- };
48
-
49
42
  struct ChannelData {
50
43
  ChannelData() : state_tracker("lame_channel", GRPC_CHANNEL_SHUTDOWN) {}
44
+ ~ChannelData() { GRPC_ERROR_UNREF(error); }
51
45
 
52
- grpc_status_code error_code;
53
- const char* error_message;
46
+ grpc_error* error = GRPC_ERROR_NONE;
54
47
  Mutex mu;
55
48
  ConnectivityStateTracker state_tracker;
56
49
  };
57
50
 
58
- static void fill_metadata(grpc_call_element* elem, grpc_metadata_batch* mdb) {
59
- CallData* calld = static_cast<CallData*>(elem->call_data);
60
- bool expected = false;
61
- if (!calld->filled_metadata.CompareExchangeStrong(
62
- &expected, true, MemoryOrder::RELAXED, MemoryOrder::RELAXED)) {
63
- return;
64
- }
65
- ChannelData* chand = static_cast<ChannelData*>(elem->channel_data);
66
- char tmp[GPR_LTOA_MIN_BUFSIZE];
67
- gpr_ltoa(chand->error_code, tmp);
68
- calld->status.md = grpc_mdelem_from_slices(
69
- GRPC_MDSTR_GRPC_STATUS, grpc_core::UnmanagedMemorySlice(tmp));
70
- calld->details.md = grpc_mdelem_from_slices(
71
- GRPC_MDSTR_GRPC_MESSAGE,
72
- grpc_core::UnmanagedMemorySlice(chand->error_message));
73
- calld->status.prev = calld->details.next = nullptr;
74
- calld->status.next = &calld->details;
75
- calld->details.prev = &calld->status;
76
- mdb->list.head = &calld->status;
77
- mdb->list.tail = &calld->details;
78
- mdb->list.count = 2;
79
- mdb->deadline = GRPC_MILLIS_INF_FUTURE;
80
- }
51
+ struct CallData {
52
+ CallCombiner* call_combiner;
53
+ };
81
54
 
82
55
  static void lame_start_transport_stream_op_batch(
83
56
  grpc_call_element* elem, grpc_transport_stream_op_batch* op) {
84
57
  CallData* calld = static_cast<CallData*>(elem->call_data);
85
- if (op->recv_initial_metadata) {
86
- fill_metadata(elem,
87
- op->payload->recv_initial_metadata.recv_initial_metadata);
88
- } else if (op->recv_trailing_metadata) {
89
- fill_metadata(elem,
90
- op->payload->recv_trailing_metadata.recv_trailing_metadata);
91
- }
58
+ ChannelData* chand = static_cast<ChannelData*>(elem->channel_data);
92
59
  grpc_transport_stream_op_batch_finish_with_failure(
93
- op, GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel"),
94
- calld->call_combiner);
60
+ op, GRPC_ERROR_REF(chand->error), calld->call_combiner);
95
61
  }
96
62
 
97
63
  static void lame_get_channel_info(grpc_channel_element* /*elem*/,
@@ -152,6 +118,12 @@ static void lame_destroy_channel_elem(grpc_channel_element* elem) {
152
118
 
153
119
  } // namespace
154
120
 
121
+ void SetLameFilterError(grpc_channel_element* elem, grpc_error* error) {
122
+ GPR_ASSERT(elem->filter == &grpc_lame_filter);
123
+ auto chand = static_cast<grpc_core::ChannelData*>(elem->channel_data);
124
+ chand->error = error;
125
+ }
126
+
155
127
  } // namespace grpc_core
156
128
 
157
129
  const grpc_channel_filter grpc_lame_filter = {
@@ -182,10 +154,12 @@ grpc_channel* grpc_lame_client_channel_create(const char* target,
182
154
  "grpc_lame_client_channel_create(target=%s, error_code=%d, "
183
155
  "error_message=%s)",
184
156
  3, (target, (int)error_code, error_message));
185
- GPR_ASSERT(elem->filter == &grpc_lame_filter);
186
- auto chand = static_cast<grpc_core::ChannelData*>(elem->channel_data);
187
- chand->error_code = error_code;
188
- chand->error_message = error_message;
189
-
157
+ grpc_core::SetLameFilterError(
158
+ elem, grpc_error_set_str(
159
+ grpc_error_set_int(
160
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel"),
161
+ GRPC_ERROR_INT_GRPC_STATUS, error_code),
162
+ GRPC_ERROR_STR_GRPC_MESSAGE,
163
+ grpc_slice_from_static_string(error_message)));
190
164
  return channel;
191
165
  }
@@ -25,4 +25,8 @@
25
25
 
26
26
  extern const grpc_channel_filter grpc_lame_filter;
27
27
 
28
+ namespace grpc_core {
29
+ void SetLameFilterError(grpc_channel_element* elem, grpc_error* error);
30
+ } // namespace grpc_core
31
+
28
32
  #endif /* GRPC_CORE_LIB_SURFACE_LAME_CLIENT_H */
@@ -1,20 +1,18 @@
1
- /*
2
- *
3
- * Copyright 2015-2016 gRPC authors.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
1
+ //
2
+ // Copyright 2015-2016 gRPC authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ //
18
16
 
19
17
  #include <grpc/support/port_platform.h>
20
18
 
@@ -28,15 +26,17 @@
28
26
  #include <atomic>
29
27
  #include <iterator>
30
28
  #include <list>
29
+ #include <queue>
31
30
  #include <utility>
32
31
  #include <vector>
33
32
 
33
+ #include "absl/memory/memory.h"
34
+ #include "absl/types/optional.h"
35
+
34
36
  #include <grpc/support/alloc.h>
35
37
  #include <grpc/support/log.h>
36
38
  #include <grpc/support/string_util.h>
37
39
 
38
- #include "absl/types/optional.h"
39
-
40
40
  #include "src/core/lib/channel/channel_args.h"
41
41
  #include "src/core/lib/channel/channelz.h"
42
42
  #include "src/core/lib/channel/connected_channel.h"
@@ -59,28 +59,17 @@ namespace grpc_core {
59
59
 
60
60
  TraceFlag grpc_server_channel_trace(false, "server_channel");
61
61
 
62
- namespace {
63
-
64
- void server_on_recv_initial_metadata(void* ptr, grpc_error* error);
65
- void server_recv_trailing_metadata_ready(void* user_data, grpc_error* error);
66
-
67
- struct Listener {
68
- explicit Listener(OrphanablePtr<ServerListenerInterface> l)
69
- : listener(std::move(l)) {}
70
-
71
- OrphanablePtr<ServerListenerInterface> listener;
72
- grpc_closure destroy_done;
73
- };
74
-
75
- enum class RequestedCallType { BATCH_CALL, REGISTERED_CALL };
62
+ //
63
+ // Server::RequestedCall
64
+ //
76
65
 
77
- struct registered_method;
66
+ struct Server::RequestedCall {
67
+ enum class Type { BATCH_CALL, REGISTERED_CALL };
78
68
 
79
- struct requested_call {
80
- requested_call(void* tag_arg, grpc_completion_queue* call_cq,
81
- grpc_call** call_arg, grpc_metadata_array* initial_md,
82
- grpc_call_details* details)
83
- : type(RequestedCallType::BATCH_CALL),
69
+ RequestedCall(void* tag_arg, grpc_completion_queue* call_cq,
70
+ grpc_call** call_arg, grpc_metadata_array* initial_md,
71
+ grpc_call_details* details)
72
+ : type(Type::BATCH_CALL),
84
73
  tag(tag_arg),
85
74
  cq_bound_to_call(call_cq),
86
75
  call(call_arg),
@@ -89,11 +78,11 @@ struct requested_call {
89
78
  data.batch.details = details;
90
79
  }
91
80
 
92
- requested_call(void* tag_arg, grpc_completion_queue* call_cq,
93
- grpc_call** call_arg, grpc_metadata_array* initial_md,
94
- registered_method* rm, gpr_timespec* deadline,
95
- grpc_byte_buffer** optional_payload)
96
- : type(RequestedCallType::REGISTERED_CALL),
81
+ RequestedCall(void* tag_arg, grpc_completion_queue* call_cq,
82
+ grpc_call** call_arg, grpc_metadata_array* initial_md,
83
+ RegisteredMethod* rm, gpr_timespec* deadline,
84
+ grpc_byte_buffer** optional_payload)
85
+ : type(Type::REGISTERED_CALL),
97
86
  tag(tag_arg),
98
87
  cq_bound_to_call(call_cq),
99
88
  call(call_arg),
@@ -104,7 +93,7 @@ struct requested_call {
104
93
  }
105
94
 
106
95
  MultiProducerSingleConsumerQueue::Node mpscq_node;
107
- const RequestedCallType type;
96
+ const Type type;
108
97
  void* const tag;
109
98
  grpc_completion_queue* const cq_bound_to_call;
110
99
  grpc_call** const call;
@@ -115,66 +104,40 @@ struct requested_call {
115
104
  grpc_call_details* details;
116
105
  } batch;
117
106
  struct {
118
- registered_method* method;
107
+ RegisteredMethod* method;
119
108
  gpr_timespec* deadline;
120
109
  grpc_byte_buffer** optional_payload;
121
110
  } registered;
122
111
  } data;
123
112
  };
124
113
 
125
- struct channel_registered_method {
126
- registered_method* server_registered_method = nullptr;
127
- uint32_t flags;
128
- bool has_host;
129
- ExternallyManagedSlice method;
130
- ExternallyManagedSlice host;
131
- };
132
-
133
- struct channel_data {
134
- channel_data() = default;
135
- ~channel_data();
136
-
137
- grpc_server* server = nullptr;
138
- grpc_channel* channel;
139
- size_t cq_idx;
140
- absl::optional<std::list<channel_data*>::iterator> list_position;
141
-
142
- // registered_methods is a hash-table of the methods and hosts of the
143
- // registered methods.
144
- // TODO(vjpai): Convert this to an STL map type as opposed to a direct bucket
145
- // implementation. (Consider performance impact, hash function to use, etc.)
146
- std::unique_ptr<std::vector<channel_registered_method>> registered_methods;
147
- uint32_t registered_method_max_probes;
148
-
149
- grpc_closure finish_destroy_channel_closure;
150
- intptr_t channelz_socket_uuid;
151
- };
114
+ //
115
+ // Server::RegisteredMethod
116
+ //
152
117
 
153
- struct shutdown_tag {
154
- shutdown_tag(void* tag_arg, grpc_completion_queue* cq_arg)
155
- : tag(tag_arg), cq(cq_arg) {}
118
+ struct Server::RegisteredMethod {
119
+ RegisteredMethod(
120
+ const char* method_arg, const char* host_arg,
121
+ grpc_server_register_method_payload_handling payload_handling_arg,
122
+ uint32_t flags_arg)
123
+ : method(method_arg == nullptr ? "" : method_arg),
124
+ host(host_arg == nullptr ? "" : host_arg),
125
+ payload_handling(payload_handling_arg),
126
+ flags(flags_arg) {}
156
127
 
157
- void* const tag;
158
- grpc_completion_queue* const cq;
159
- grpc_cq_completion completion;
160
- };
128
+ ~RegisteredMethod() = default;
161
129
 
162
- enum class CallState {
163
- /* waiting for metadata */
164
- NOT_STARTED,
165
- /* initial metadata read, not flow controlled in yet */
166
- PENDING,
167
- /* flow controlled in, on completion queue */
168
- ACTIVATED,
169
- /* cancelled before being queued */
170
- ZOMBIED
130
+ const std::string method;
131
+ const std::string host;
132
+ const grpc_server_register_method_payload_handling payload_handling;
133
+ const uint32_t flags;
134
+ // One request matcher per method.
135
+ std::unique_ptr<RequestMatcherInterface> matcher;
171
136
  };
172
137
 
173
- struct call_data;
174
-
175
- grpc_call_error ValidateServerRequest(
176
- grpc_completion_queue* cq_for_notification, void* tag,
177
- grpc_byte_buffer** optional_payload, registered_method* rm);
138
+ //
139
+ // Server::RequestMatcherInterface
140
+ //
178
141
 
179
142
  // RPCs that come in from the transport must be matched against RPC requests
180
143
  // from the application. An incoming request from the application can be matched
@@ -185,7 +148,7 @@ grpc_call_error ValidateServerRequest(
185
148
  // on the request's notification CQ.
186
149
  //
187
150
  // RequestMatcherInterface is the base class to provide this functionality.
188
- class RequestMatcherInterface {
151
+ class Server::RequestMatcherInterface {
189
152
  public:
190
153
  virtual ~RequestMatcherInterface() {}
191
154
 
@@ -208,7 +171,7 @@ class RequestMatcherInterface {
208
171
  // CQ. If there are pending RPCs waiting to be matched, publish one (match it
209
172
  // and notify the CQ).
210
173
  virtual void RequestCallWithPossiblePublish(size_t request_queue_index,
211
- requested_call* call) = 0;
174
+ RequestedCall* call) = 0;
212
175
 
213
176
  // This function is invoked on an incoming RPC, represented by the calld
214
177
  // object. The RequestMatcher will try to match it against an
@@ -217,339 +180,21 @@ class RequestMatcherInterface {
217
180
  // is done starting at the start_request_queue_index parameter in a cyclic
218
181
  // order rather than always starting at 0.
219
182
  virtual void MatchOrQueue(size_t start_request_queue_index,
220
- call_data* calld) = 0;
183
+ CallData* calld) = 0;
221
184
 
222
185
  // Returns the server associated with this request matcher
223
- virtual grpc_server* server() const = 0;
224
- };
225
-
226
- struct call_data {
227
- call_data(grpc_call_element* elem, const grpc_call_element_args& args)
228
- : call(grpc_call_from_top_element(elem)),
229
- call_combiner(args.call_combiner) {
230
- GRPC_CLOSURE_INIT(&on_recv_initial_metadata,
231
- server_on_recv_initial_metadata, elem,
232
- grpc_schedule_on_exec_ctx);
233
- GRPC_CLOSURE_INIT(&recv_trailing_metadata_ready,
234
- server_recv_trailing_metadata_ready, elem,
235
- grpc_schedule_on_exec_ctx);
236
- }
237
- ~call_data() {
238
- GPR_ASSERT(state.Load(grpc_core::MemoryOrder::RELAXED) !=
239
- CallState::PENDING);
240
- GRPC_ERROR_UNREF(recv_initial_metadata_error);
241
- if (host_set) {
242
- grpc_slice_unref_internal(host);
243
- }
244
- if (path_set) {
245
- grpc_slice_unref_internal(path);
246
- }
247
- grpc_metadata_array_destroy(&initial_metadata);
248
- grpc_byte_buffer_destroy(payload);
249
- }
250
-
251
- grpc_call* call;
252
-
253
- Atomic<CallState> state{CallState::NOT_STARTED};
254
-
255
- bool path_set = false;
256
- bool host_set = false;
257
- grpc_slice path;
258
- grpc_slice host;
259
- grpc_millis deadline = GRPC_MILLIS_INF_FUTURE;
260
-
261
- grpc_completion_queue* cq_new = nullptr;
262
-
263
- grpc_metadata_batch* recv_initial_metadata = nullptr;
264
- uint32_t recv_initial_metadata_flags = 0;
265
- grpc_metadata_array initial_metadata =
266
- grpc_metadata_array(); // Zero-initialize the C struct.
267
-
268
- RequestMatcherInterface* matcher = nullptr;
269
- grpc_byte_buffer* payload = nullptr;
270
-
271
- grpc_closure got_initial_metadata;
272
- grpc_closure on_recv_initial_metadata;
273
- grpc_closure kill_zombie_closure;
274
- grpc_closure* on_done_recv_initial_metadata;
275
- grpc_closure recv_trailing_metadata_ready;
276
- grpc_error* recv_initial_metadata_error = GRPC_ERROR_NONE;
277
- grpc_closure* original_recv_trailing_metadata_ready;
278
- grpc_error* recv_trailing_metadata_error = GRPC_ERROR_NONE;
279
- bool seen_recv_trailing_metadata_ready = false;
280
-
281
- grpc_closure publish;
282
-
283
- CallCombiner* call_combiner;
284
- };
285
-
286
- struct registered_method {
287
- registered_method(
288
- const char* method_arg, const char* host_arg,
289
- grpc_server_register_method_payload_handling payload_handling_arg,
290
- uint32_t flags_arg)
291
- : method(method_arg == nullptr ? "" : method_arg),
292
- host(host_arg == nullptr ? "" : host_arg),
293
- payload_handling(payload_handling_arg),
294
- flags(flags_arg) {}
295
-
296
- ~registered_method() = default;
297
-
298
- const std::string method;
299
- const std::string host;
300
- const grpc_server_register_method_payload_handling payload_handling;
301
- const uint32_t flags;
302
- /* one request matcher per method */
303
- std::unique_ptr<RequestMatcherInterface> matcher;
304
- };
305
-
306
- } // namespace
307
- } // namespace grpc_core
308
-
309
- struct grpc_server {
310
- explicit grpc_server(const grpc_channel_args* args)
311
- : channel_args(grpc_channel_args_copy(args)) {
312
- if (grpc_channel_args_find_bool(args, GRPC_ARG_ENABLE_CHANNELZ,
313
- GRPC_ENABLE_CHANNELZ_DEFAULT)) {
314
- size_t channel_tracer_max_memory = grpc_channel_args_find_integer(
315
- args, GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE,
316
- {GRPC_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE_DEFAULT, 0, INT_MAX});
317
- channelz_server =
318
- grpc_core::MakeRefCounted<grpc_core::channelz::ServerNode>(
319
- this, channel_tracer_max_memory);
320
- channelz_server->AddTraceEvent(
321
- grpc_core::channelz::ChannelTrace::Severity::Info,
322
- grpc_slice_from_static_string("Server created"));
323
- }
324
-
325
- if (args != nullptr) {
326
- grpc_resource_quota* resource_quota =
327
- grpc_resource_quota_from_channel_args(args, false /* create */);
328
- if (resource_quota != nullptr) {
329
- default_resource_user =
330
- grpc_resource_user_create(resource_quota, "default");
331
- }
332
- }
333
- }
334
-
335
- ~grpc_server() {
336
- grpc_channel_args_destroy(channel_args);
337
- for (size_t i = 0; i < cqs.size(); i++) {
338
- GRPC_CQ_INTERNAL_UNREF(cqs[i], "server");
339
- }
340
- }
341
-
342
- grpc_channel_args* const channel_args;
343
-
344
- grpc_resource_user* default_resource_user = nullptr;
345
-
346
- std::vector<grpc_completion_queue*> cqs;
347
- std::vector<grpc_pollset*> pollsets;
348
- bool started = false;
349
-
350
- /* The two following mutexes control access to server-state
351
- mu_global controls access to non-call-related state (e.g., channel state)
352
- mu_call controls access to call-related state (e.g., the call lists)
353
-
354
- If they are ever required to be nested, you must lock mu_global
355
- before mu_call. This is currently used in shutdown processing
356
- (grpc_server_shutdown_and_notify and maybe_finish_shutdown) */
357
- grpc_core::Mutex mu_global; // mutex for server and channel state
358
- grpc_core::Mutex mu_call; // mutex for call-specific state
359
-
360
- /* startup synchronization: flag is protected by mu_global, signals whether
361
- we are doing the listener start routine or not */
362
- bool starting = false;
363
- grpc_core::CondVar starting_cv;
364
-
365
- std::vector<std::unique_ptr<grpc_core::registered_method>> registered_methods;
366
-
367
- // one request matcher for unregistered methods
368
- std::unique_ptr<grpc_core::RequestMatcherInterface>
369
- unregistered_request_matcher;
370
-
371
- std::atomic_bool shutdown_flag{false};
372
- bool shutdown_published = false;
373
- std::vector<grpc_core::shutdown_tag> shutdown_tags;
374
-
375
- std::list<grpc_core::channel_data*> channels;
376
-
377
- std::list<grpc_core::Listener> listeners;
378
- size_t listeners_destroyed = 0;
379
- grpc_core::RefCount internal_refcount;
380
-
381
- /** when did we print the last shutdown progress message */
382
- gpr_timespec last_shutdown_message_time;
383
-
384
- grpc_core::RefCountedPtr<grpc_core::channelz::ServerNode> channelz_server;
385
- };
386
-
387
- // Non-API functions of the server that are only for gRPC core internal use.
388
- // TODO(markdroth): Make these class member functions
389
- void grpc_server_add_listener(
390
- grpc_server* server,
391
- grpc_core::OrphanablePtr<grpc_core::ServerListenerInterface> listener) {
392
- grpc_core::channelz::ListenSocketNode* listen_socket_node =
393
- listener->channelz_listen_socket_node();
394
- if (listen_socket_node != nullptr && server->channelz_server != nullptr) {
395
- server->channelz_server->AddChildListenSocket(listen_socket_node->Ref());
396
- }
397
- server->listeners.emplace_back(std::move(listener));
398
- }
399
-
400
- const grpc_channel_args* grpc_server_get_channel_args(grpc_server* server) {
401
- return server->channel_args;
402
- }
403
-
404
- grpc_resource_user* grpc_server_get_default_resource_user(grpc_server* server) {
405
- return server->default_resource_user;
406
- }
407
-
408
- bool grpc_server_has_open_connections(grpc_server* server) {
409
- grpc_core::MutexLock lock(&server->mu_global);
410
- return !server->channels.empty();
411
- }
412
-
413
- grpc_core::channelz::ServerNode* grpc_server_get_channelz_node(
414
- grpc_server* server) {
415
- if (server == nullptr) {
416
- return nullptr;
417
- }
418
- return server->channelz_server.get();
419
- }
420
-
421
- namespace grpc_core {
422
- namespace {
423
-
424
- void publish_call(grpc_server* server, call_data* calld, size_t cq_idx,
425
- requested_call* rc);
426
- void fail_call(grpc_server* server, size_t cq_idx, requested_call* rc,
427
- grpc_error* error);
428
- /* Before calling maybe_finish_shutdown, we must hold mu_global and not
429
- hold mu_call */
430
- void maybe_finish_shutdown(grpc_server* server);
431
-
432
- void kill_zombie(void* elem, grpc_error* /*error*/) {
433
- grpc_call_unref(
434
- grpc_call_from_top_element(static_cast<grpc_call_element*>(elem)));
435
- }
436
-
437
- // Validate a requested RPC for a server CQ and bind it to that CQ
438
- grpc_call_error ValidateServerRequest(
439
- grpc_completion_queue* cq_for_notification, void* tag,
440
- grpc_byte_buffer** optional_payload, registered_method* rm) {
441
- if ((rm == nullptr && optional_payload != nullptr) ||
442
- ((rm != nullptr) && ((optional_payload == nullptr) !=
443
- (rm->payload_handling == GRPC_SRM_PAYLOAD_NONE)))) {
444
- return GRPC_CALL_ERROR_PAYLOAD_TYPE_MISMATCH;
445
- }
446
- if (grpc_cq_begin_op(cq_for_notification, tag) == false) {
447
- return GRPC_CALL_ERROR_COMPLETION_QUEUE_SHUTDOWN;
448
- }
449
- return GRPC_CALL_OK;
450
- }
451
-
452
- // Validate that a requested RPC has a valid server CQ and is valid, and bind it
453
- grpc_call_error ValidateServerRequestAndCq(
454
- size_t* cq_idx, grpc_server* server,
455
- grpc_completion_queue* cq_for_notification, void* tag,
456
- grpc_byte_buffer** optional_payload, registered_method* rm) {
457
- size_t idx;
458
- for (idx = 0; idx < server->cqs.size(); idx++) {
459
- if (server->cqs[idx] == cq_for_notification) {
460
- break;
461
- }
462
- }
463
- if (idx == server->cqs.size()) {
464
- return GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE;
465
- }
466
- grpc_call_error error =
467
- ValidateServerRequest(cq_for_notification, tag, optional_payload, rm);
468
- if (error != GRPC_CALL_OK) {
469
- return error;
470
- }
471
-
472
- *cq_idx = idx;
473
- return GRPC_CALL_OK;
474
- }
475
- /*
476
- * channel broadcaster
477
- */
478
-
479
- struct shutdown_cleanup_args {
480
- grpc_closure closure;
481
- grpc_slice slice;
482
- };
483
-
484
- void shutdown_cleanup(void* arg, grpc_error* /*error*/) {
485
- shutdown_cleanup_args* a = static_cast<shutdown_cleanup_args*>(arg);
486
- grpc_slice_unref_internal(a->slice);
487
- delete a;
488
- }
489
-
490
- void send_shutdown(grpc_channel* channel, bool send_goaway,
491
- grpc_error* send_disconnect) {
492
- shutdown_cleanup_args* sc = new shutdown_cleanup_args;
493
- GRPC_CLOSURE_INIT(&sc->closure, shutdown_cleanup, sc,
494
- grpc_schedule_on_exec_ctx);
495
- grpc_transport_op* op = grpc_make_transport_op(&sc->closure);
496
- grpc_channel_element* elem;
497
-
498
- op->goaway_error =
499
- send_goaway ? grpc_error_set_int(
500
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown"),
501
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_OK)
502
- : GRPC_ERROR_NONE;
503
- op->set_accept_stream = true;
504
- sc->slice = grpc_slice_from_copied_string("Server shutdown");
505
- op->disconnect_with_error = send_disconnect;
506
-
507
- elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0);
508
- elem->filter->start_transport_op(elem, op);
509
- }
510
-
511
- class ChannelBroadcaster {
512
- public:
513
- // This can have an empty constructor and destructor since we want to control
514
- // when the actual setup and shutdown broadcast take place
515
-
516
- // This function copies over the channels from the locked server
517
- void FillChannelsLocked(const grpc_server* s) {
518
- GPR_DEBUG_ASSERT(channels_.empty());
519
- channels_.reserve(s->channels.size());
520
- for (const channel_data* chand : s->channels) {
521
- channels_.push_back(chand->channel);
522
- GRPC_CHANNEL_INTERNAL_REF(chand->channel, "broadcast");
523
- }
524
- }
525
-
526
- // Broadcast a shutdown on each channel
527
- void BroadcastShutdown(bool send_goaway, grpc_error* force_disconnect) {
528
- for (grpc_channel* channel : channels_) {
529
- send_shutdown(channel, send_goaway, GRPC_ERROR_REF(force_disconnect));
530
- GRPC_CHANNEL_INTERNAL_UNREF(channel, "broadcast");
531
- }
532
- channels_.clear(); // just for safety against double broadcast
533
- GRPC_ERROR_UNREF(force_disconnect);
534
- }
535
-
536
- private:
537
- std::vector<grpc_channel*> channels_;
186
+ virtual Server* server() const = 0;
538
187
  };
539
188
 
540
- /*
541
- * request_matcher
542
- */
543
-
544
189
  // The RealRequestMatcher is an implementation of RequestMatcherInterface that
545
190
  // actually uses all the features of RequestMatcherInterface: expecting the
546
191
  // application to explicitly request RPCs and then matching those to incoming
547
192
  // RPCs, along with a slow path by which incoming RPCs are put on a locked
548
193
  // pending list if they aren't able to be matched to an application request.
549
- class RealRequestMatcher : public RequestMatcherInterface {
194
+ class Server::RealRequestMatcher : public RequestMatcherInterface {
550
195
  public:
551
- explicit RealRequestMatcher(grpc_server* server)
552
- : server_(server), requests_per_cq_(server->cqs.size()) {}
196
+ explicit RealRequestMatcher(Server* server)
197
+ : server_(server), requests_per_cq_(server->cqs_.size()) {}
553
198
 
554
199
  ~RealRequestMatcher() override {
555
200
  for (LockedMultiProducerSingleConsumerQueue& queue : requests_per_cq_) {
@@ -558,24 +203,20 @@ class RealRequestMatcher : public RequestMatcherInterface {
558
203
  }
559
204
 
560
205
  void ZombifyPending() override {
561
- for (call_data* calld : pending_) {
562
- calld->state.Store(CallState::ZOMBIED, grpc_core::MemoryOrder::RELAXED);
563
- GRPC_CLOSURE_INIT(
564
- &calld->kill_zombie_closure, kill_zombie,
565
- grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0),
566
- grpc_schedule_on_exec_ctx);
567
- ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
568
- GRPC_ERROR_NONE);
206
+ while (!pending_.empty()) {
207
+ CallData* calld = pending_.front();
208
+ calld->SetState(CallData::CallState::ZOMBIED);
209
+ calld->KillZombie();
210
+ pending_.pop();
569
211
  }
570
- pending_.clear();
571
212
  }
572
213
 
573
214
  void KillRequests(grpc_error* error) override {
574
215
  for (size_t i = 0; i < requests_per_cq_.size(); i++) {
575
- requested_call* rc;
576
- while ((rc = reinterpret_cast<requested_call*>(
216
+ RequestedCall* rc;
217
+ while ((rc = reinterpret_cast<RequestedCall*>(
577
218
  requests_per_cq_[i].Pop())) != nullptr) {
578
- fail_call(server_, i, rc, GRPC_ERROR_REF(error));
219
+ server_->FailCall(i, rc, GRPC_ERROR_REF(error));
579
220
  }
580
221
  }
581
222
  GRPC_ERROR_UNREF(error);
@@ -586,106 +227,90 @@ class RealRequestMatcher : public RequestMatcherInterface {
586
227
  }
587
228
 
588
229
  void RequestCallWithPossiblePublish(size_t request_queue_index,
589
- requested_call* call) override {
230
+ RequestedCall* call) override {
590
231
  if (requests_per_cq_[request_queue_index].Push(&call->mpscq_node)) {
591
232
  /* this was the first queued request: we need to lock and start
592
233
  matching calls */
593
234
  struct PendingCall {
594
- requested_call* rc = nullptr;
595
- call_data* calld;
235
+ RequestedCall* rc = nullptr;
236
+ CallData* calld;
596
237
  };
597
238
  auto pop_next_pending = [this, request_queue_index] {
598
- PendingCall pending;
239
+ PendingCall pending_call;
599
240
  {
600
- MutexLock lock(&server_->mu_call);
241
+ MutexLock lock(&server_->mu_call_);
601
242
  if (!pending_.empty()) {
602
- pending.rc = reinterpret_cast<requested_call*>(
243
+ pending_call.rc = reinterpret_cast<RequestedCall*>(
603
244
  requests_per_cq_[request_queue_index].Pop());
604
- if (pending.rc != nullptr) {
605
- pending.calld = pending_.front();
606
- pending_.pop_front();
245
+ if (pending_call.rc != nullptr) {
246
+ pending_call.calld = pending_.front();
247
+ pending_.pop();
607
248
  }
608
249
  }
609
250
  }
610
- return pending;
251
+ return pending_call;
611
252
  };
612
253
  while (true) {
613
254
  PendingCall next_pending = pop_next_pending();
614
255
  if (next_pending.rc == nullptr) break;
615
- CallState expect_pending = CallState::PENDING;
616
- if (!next_pending.calld->state.CompareExchangeStrong(
617
- &expect_pending, CallState::ACTIVATED,
618
- grpc_core::MemoryOrder::ACQ_REL,
619
- grpc_core::MemoryOrder::RELAXED)) {
256
+ if (!next_pending.calld->MaybeActivate()) {
620
257
  // Zombied Call
621
- GRPC_CLOSURE_INIT(
622
- &next_pending.calld->kill_zombie_closure, kill_zombie,
623
- grpc_call_stack_element(
624
- grpc_call_get_call_stack(next_pending.calld->call), 0),
625
- grpc_schedule_on_exec_ctx);
626
- ExecCtx::Run(DEBUG_LOCATION, &next_pending.calld->kill_zombie_closure,
627
- GRPC_ERROR_NONE);
258
+ next_pending.calld->KillZombie();
628
259
  } else {
629
- publish_call(server_, next_pending.calld, request_queue_index,
630
- next_pending.rc);
260
+ next_pending.calld->Publish(request_queue_index, next_pending.rc);
631
261
  }
632
262
  }
633
263
  }
634
264
  }
635
265
 
636
266
  void MatchOrQueue(size_t start_request_queue_index,
637
- call_data* calld) override {
267
+ CallData* calld) override {
638
268
  for (size_t i = 0; i < requests_per_cq_.size(); i++) {
639
269
  size_t cq_idx = (start_request_queue_index + i) % requests_per_cq_.size();
640
- requested_call* rc =
641
- reinterpret_cast<requested_call*>(requests_per_cq_[cq_idx].TryPop());
642
- if (rc == nullptr) {
643
- continue;
644
- } else {
270
+ RequestedCall* rc =
271
+ reinterpret_cast<RequestedCall*>(requests_per_cq_[cq_idx].TryPop());
272
+ if (rc != nullptr) {
645
273
  GRPC_STATS_INC_SERVER_CQS_CHECKED(i);
646
- calld->state.Store(CallState::ACTIVATED,
647
- grpc_core::MemoryOrder::RELAXED);
648
- publish_call(server_, calld, cq_idx, rc);
649
- return; /* early out */
274
+ calld->SetState(CallData::CallState::ACTIVATED);
275
+ calld->Publish(cq_idx, rc);
276
+ return;
650
277
  }
651
278
  }
652
-
653
- /* no cq to take the request found: queue it on the slow list */
279
+ // No cq to take the request found; queue it on the slow list.
654
280
  GRPC_STATS_INC_SERVER_SLOWPATH_REQUESTS_QUEUED();
655
-
656
281
  // We need to ensure that all the queues are empty. We do this under
657
- // the server mu_call lock to ensure that if something is added to
282
+ // the server mu_call_ lock to ensure that if something is added to
658
283
  // an empty request queue, it will block until the call is actually
659
284
  // added to the pending list.
660
- requested_call* rc = nullptr;
285
+ RequestedCall* rc = nullptr;
661
286
  size_t cq_idx = 0;
662
287
  size_t loop_count;
663
288
  {
664
- MutexLock lock(&server_->mu_call);
289
+ MutexLock lock(&server_->mu_call_);
665
290
  for (loop_count = 0; loop_count < requests_per_cq_.size(); loop_count++) {
666
291
  cq_idx =
667
292
  (start_request_queue_index + loop_count) % requests_per_cq_.size();
668
- rc = reinterpret_cast<requested_call*>(requests_per_cq_[cq_idx].Pop());
293
+ rc = reinterpret_cast<RequestedCall*>(requests_per_cq_[cq_idx].Pop());
669
294
  if (rc != nullptr) {
670
295
  break;
671
296
  }
672
297
  }
673
298
  if (rc == nullptr) {
674
- calld->state.Store(CallState::PENDING, grpc_core::MemoryOrder::RELAXED);
675
- pending_.push_back(calld);
299
+ calld->SetState(CallData::CallState::PENDING);
300
+ pending_.push(calld);
676
301
  return;
677
302
  }
678
303
  }
679
304
  GRPC_STATS_INC_SERVER_CQS_CHECKED(loop_count + requests_per_cq_.size());
680
- calld->state.Store(CallState::ACTIVATED, grpc_core::MemoryOrder::RELAXED);
681
- publish_call(server_, calld, cq_idx, rc);
305
+ calld->SetState(CallData::CallState::ACTIVATED);
306
+ calld->Publish(cq_idx, rc);
682
307
  }
683
308
 
684
- grpc_server* server() const override { return server_; }
309
+ Server* server() const override { return server_; }
685
310
 
686
311
  private:
687
- grpc_server* const server_;
688
- std::list<call_data*> pending_;
312
+ Server* const server_;
313
+ std::queue<CallData*> pending_;
689
314
  std::vector<LockedMultiProducerSingleConsumerQueue> requests_per_cq_;
690
315
  };
691
316
 
@@ -694,17 +319,17 @@ class RealRequestMatcher : public RequestMatcherInterface {
694
319
  // will call out to an allocation function passed in at the construction of the
695
320
  // object. These request matchers are designed for the C++ callback API, so they
696
321
  // only support 1 completion queue (passed in at the constructor).
697
- class AllocatingRequestMatcherBase : public RequestMatcherInterface {
322
+ class Server::AllocatingRequestMatcherBase : public RequestMatcherInterface {
698
323
  public:
699
- AllocatingRequestMatcherBase(grpc_server* server, grpc_completion_queue* cq)
324
+ AllocatingRequestMatcherBase(Server* server, grpc_completion_queue* cq)
700
325
  : server_(server), cq_(cq) {
701
326
  size_t idx;
702
- for (idx = 0; idx < server->cqs.size(); idx++) {
703
- if (server->cqs[idx] == cq) {
327
+ for (idx = 0; idx < server->cqs_.size(); idx++) {
328
+ if (server->cqs_[idx] == cq) {
704
329
  break;
705
330
  }
706
331
  }
707
- GPR_ASSERT(idx < server->cqs.size());
332
+ GPR_ASSERT(idx < server->cqs_.size());
708
333
  cq_idx_ = idx;
709
334
  }
710
335
 
@@ -715,11 +340,11 @@ class AllocatingRequestMatcherBase : public RequestMatcherInterface {
715
340
  size_t request_queue_count() const override { return 0; }
716
341
 
717
342
  void RequestCallWithPossiblePublish(size_t /*request_queue_index*/,
718
- requested_call* /*call*/) final {
343
+ RequestedCall* /*call*/) final {
719
344
  GPR_ASSERT(false);
720
345
  }
721
346
 
722
- grpc_server* server() const override { return server_; }
347
+ Server* server() const override { return server_; }
723
348
 
724
349
  // Supply the completion queue related to this request matcher
725
350
  grpc_completion_queue* cq() const { return cq_; }
@@ -728,433 +353,770 @@ class AllocatingRequestMatcherBase : public RequestMatcherInterface {
728
353
  size_t cq_idx() const { return cq_idx_; }
729
354
 
730
355
  private:
731
- grpc_server* const server_;
356
+ Server* const server_;
732
357
  grpc_completion_queue* const cq_;
733
358
  size_t cq_idx_;
734
359
  };
735
360
 
736
361
  // An allocating request matcher for non-registered methods (used for generic
737
362
  // API and unimplemented RPCs).
738
- class AllocatingRequestMatcherBatch : public AllocatingRequestMatcherBase {
363
+ class Server::AllocatingRequestMatcherBatch
364
+ : public AllocatingRequestMatcherBase {
739
365
  public:
740
- AllocatingRequestMatcherBatch(
741
- grpc_server* server, grpc_completion_queue* cq,
742
- std::function<ServerBatchCallAllocation()> allocator)
366
+ AllocatingRequestMatcherBatch(Server* server, grpc_completion_queue* cq,
367
+ std::function<BatchCallAllocation()> allocator)
743
368
  : AllocatingRequestMatcherBase(server, cq),
744
369
  allocator_(std::move(allocator)) {}
370
+
745
371
  void MatchOrQueue(size_t /*start_request_queue_index*/,
746
- call_data* calld) override {
747
- ServerBatchCallAllocation call_info = allocator_();
748
- GPR_ASSERT(ValidateServerRequest(cq(), static_cast<void*>(call_info.tag),
749
- nullptr, nullptr) == GRPC_CALL_OK);
750
- requested_call* rc = new requested_call(
372
+ CallData* calld) override {
373
+ BatchCallAllocation call_info = allocator_();
374
+ GPR_ASSERT(server()->ValidateServerRequest(
375
+ cq(), static_cast<void*>(call_info.tag), nullptr, nullptr) ==
376
+ GRPC_CALL_OK);
377
+ RequestedCall* rc = new RequestedCall(
751
378
  static_cast<void*>(call_info.tag), cq(), call_info.call,
752
379
  call_info.initial_metadata, call_info.details);
753
- calld->state.Store(CallState::ACTIVATED, grpc_core::MemoryOrder::RELAXED);
754
- publish_call(server(), calld, cq_idx(), rc);
380
+ calld->SetState(CallData::CallState::ACTIVATED);
381
+ calld->Publish(cq_idx(), rc);
755
382
  }
756
383
 
757
384
  private:
758
- std::function<ServerBatchCallAllocation()> allocator_;
385
+ std::function<BatchCallAllocation()> allocator_;
759
386
  };
760
387
 
761
388
  // An allocating request matcher for registered methods.
762
- class AllocatingRequestMatcherRegistered : public AllocatingRequestMatcherBase {
389
+ class Server::AllocatingRequestMatcherRegistered
390
+ : public AllocatingRequestMatcherBase {
763
391
  public:
764
392
  AllocatingRequestMatcherRegistered(
765
- grpc_server* server, grpc_completion_queue* cq, registered_method* rm,
766
- std::function<ServerRegisteredCallAllocation()> allocator)
393
+ Server* server, grpc_completion_queue* cq, RegisteredMethod* rm,
394
+ std::function<RegisteredCallAllocation()> allocator)
767
395
  : AllocatingRequestMatcherBase(server, cq),
768
396
  registered_method_(rm),
769
397
  allocator_(std::move(allocator)) {}
398
+
770
399
  void MatchOrQueue(size_t /*start_request_queue_index*/,
771
- call_data* calld) override {
772
- ServerRegisteredCallAllocation call_info = allocator_();
773
- GPR_ASSERT(ValidateServerRequest(cq(), static_cast<void*>(call_info.tag),
774
- call_info.optional_payload,
775
- registered_method_) == GRPC_CALL_OK);
776
- requested_call* rc = new requested_call(
400
+ CallData* calld) override {
401
+ RegisteredCallAllocation call_info = allocator_();
402
+ GPR_ASSERT(
403
+ server()->ValidateServerRequest(cq(), static_cast<void*>(call_info.tag),
404
+ call_info.optional_payload,
405
+ registered_method_) == GRPC_CALL_OK);
406
+ RequestedCall* rc = new RequestedCall(
777
407
  static_cast<void*>(call_info.tag), cq(), call_info.call,
778
408
  call_info.initial_metadata, registered_method_, call_info.deadline,
779
409
  call_info.optional_payload);
780
- calld->state.Store(CallState::ACTIVATED, grpc_core::MemoryOrder::RELAXED);
781
- publish_call(server(), calld, cq_idx(), rc);
410
+ calld->SetState(CallData::CallState::ACTIVATED);
411
+ calld->Publish(cq_idx(), rc);
782
412
  }
783
413
 
784
414
  private:
785
- registered_method* const registered_method_;
786
- std::function<ServerRegisteredCallAllocation()> allocator_;
415
+ RegisteredMethod* const registered_method_;
416
+ std::function<RegisteredCallAllocation()> allocator_;
787
417
  };
788
418
 
789
- /*
790
- * server proper
791
- */
419
+ //
420
+ // ChannelBroadcaster
421
+ //
422
+
423
+ namespace {
792
424
 
793
- void server_ref(grpc_server* server) { server->internal_refcount.Ref(); }
425
+ class ChannelBroadcaster {
426
+ public:
427
+ // This can have an empty constructor and destructor since we want to control
428
+ // when the actual setup and shutdown broadcast take place.
794
429
 
795
- void server_unref(grpc_server* server) {
796
- if (GPR_UNLIKELY(server->internal_refcount.Unref())) {
797
- delete server;
430
+ // Copies over the channels from the locked server.
431
+ void FillChannelsLocked(std::vector<grpc_channel*> channels) {
432
+ GPR_DEBUG_ASSERT(channels_.empty());
433
+ channels_ = std::move(channels);
798
434
  }
799
- }
800
435
 
801
- void finish_destroy_channel(void* cd, grpc_error* /*error*/) {
802
- channel_data* chand = static_cast<channel_data*>(cd);
803
- grpc_server* server = chand->server;
804
- GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "server");
805
- server_unref(server);
806
- }
436
+ // Broadcasts a shutdown on each channel.
437
+ void BroadcastShutdown(bool send_goaway, grpc_error* force_disconnect) {
438
+ for (grpc_channel* channel : channels_) {
439
+ SendShutdown(channel, send_goaway, GRPC_ERROR_REF(force_disconnect));
440
+ GRPC_CHANNEL_INTERNAL_UNREF(channel, "broadcast");
441
+ }
442
+ channels_.clear(); // just for safety against double broadcast
443
+ GRPC_ERROR_UNREF(force_disconnect);
444
+ }
807
445
 
808
- void destroy_channel(channel_data* chand) {
809
- if (!chand->list_position.has_value()) return;
810
- GPR_ASSERT(chand->server != nullptr);
811
- chand->server->channels.erase(*chand->list_position);
812
- chand->list_position.reset();
813
- server_ref(chand->server);
814
- maybe_finish_shutdown(chand->server);
815
- GRPC_CLOSURE_INIT(&chand->finish_destroy_channel_closure,
816
- finish_destroy_channel, chand, grpc_schedule_on_exec_ctx);
446
+ private:
447
+ struct ShutdownCleanupArgs {
448
+ grpc_closure closure;
449
+ grpc_slice slice;
450
+ };
817
451
 
818
- if (GRPC_TRACE_FLAG_ENABLED(grpc_server_channel_trace)) {
819
- gpr_log(GPR_INFO, "Disconnected client");
452
+ static void ShutdownCleanup(void* arg, grpc_error* /*error*/) {
453
+ ShutdownCleanupArgs* a = static_cast<ShutdownCleanupArgs*>(arg);
454
+ grpc_slice_unref_internal(a->slice);
455
+ delete a;
820
456
  }
821
457
 
822
- grpc_transport_op* op =
823
- grpc_make_transport_op(&chand->finish_destroy_channel_closure);
824
- op->set_accept_stream = true;
825
- grpc_channel_next_op(grpc_channel_stack_element(
826
- grpc_channel_get_channel_stack(chand->channel), 0),
827
- op);
828
- }
458
+ static void SendShutdown(grpc_channel* channel, bool send_goaway,
459
+ grpc_error* send_disconnect) {
460
+ ShutdownCleanupArgs* sc = new ShutdownCleanupArgs;
461
+ GRPC_CLOSURE_INIT(&sc->closure, ShutdownCleanup, sc,
462
+ grpc_schedule_on_exec_ctx);
463
+ grpc_transport_op* op = grpc_make_transport_op(&sc->closure);
464
+ grpc_channel_element* elem;
465
+ op->goaway_error =
466
+ send_goaway
467
+ ? grpc_error_set_int(
468
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown"),
469
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_OK)
470
+ : GRPC_ERROR_NONE;
471
+ op->set_accept_stream = true;
472
+ sc->slice = grpc_slice_from_copied_string("Server shutdown");
473
+ op->disconnect_with_error = send_disconnect;
474
+ elem =
475
+ grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0);
476
+ elem->filter->start_transport_op(elem, op);
477
+ }
829
478
 
830
- void done_request_event(void* req, grpc_cq_completion* /*c*/) {
831
- delete static_cast<requested_call*>(req);
832
- }
479
+ std::vector<grpc_channel*> channels_;
480
+ };
833
481
 
834
- void publish_call(grpc_server* server, call_data* calld, size_t cq_idx,
835
- requested_call* rc) {
836
- grpc_call_set_completion_queue(calld->call, rc->cq_bound_to_call);
837
- grpc_call* call = calld->call;
838
- *rc->call = call;
839
- calld->cq_new = server->cqs[cq_idx];
840
- GPR_SWAP(grpc_metadata_array, *rc->initial_metadata, calld->initial_metadata);
841
- switch (rc->type) {
842
- case RequestedCallType::BATCH_CALL:
843
- GPR_ASSERT(calld->host_set);
844
- GPR_ASSERT(calld->path_set);
845
- rc->data.batch.details->host = grpc_slice_ref_internal(calld->host);
846
- rc->data.batch.details->method = grpc_slice_ref_internal(calld->path);
847
- rc->data.batch.details->deadline =
848
- grpc_millis_to_timespec(calld->deadline, GPR_CLOCK_MONOTONIC);
849
- rc->data.batch.details->flags = calld->recv_initial_metadata_flags;
850
- break;
851
- case RequestedCallType::REGISTERED_CALL:
852
- *rc->data.registered.deadline =
853
- grpc_millis_to_timespec(calld->deadline, GPR_CLOCK_MONOTONIC);
854
- if (rc->data.registered.optional_payload) {
855
- *rc->data.registered.optional_payload = calld->payload;
856
- calld->payload = nullptr;
857
- }
858
- break;
859
- default:
860
- GPR_UNREACHABLE_CODE(return );
861
- }
482
+ } // namespace
862
483
 
863
- grpc_cq_end_op(calld->cq_new, rc->tag, GRPC_ERROR_NONE, done_request_event,
864
- rc, &rc->completion, true);
865
- }
484
+ //
485
+ // Server
486
+ //
866
487
 
867
- void publish_new_rpc(void* arg, grpc_error* error) {
868
- grpc_call_element* call_elem = static_cast<grpc_call_element*>(arg);
869
- call_data* calld = static_cast<call_data*>(call_elem->call_data);
870
- channel_data* chand = static_cast<channel_data*>(call_elem->channel_data);
871
- RequestMatcherInterface* rm = calld->matcher;
872
- grpc_server* server = rm->server();
488
+ const grpc_channel_filter Server::kServerTopFilter = {
489
+ Server::CallData::StartTransportStreamOpBatch,
490
+ grpc_channel_next_op,
491
+ sizeof(Server::CallData),
492
+ Server::CallData::InitCallElement,
493
+ grpc_call_stack_ignore_set_pollset_or_pollset_set,
494
+ Server::CallData::DestroyCallElement,
495
+ sizeof(Server::ChannelData),
496
+ Server::ChannelData::InitChannelElement,
497
+ Server::ChannelData::DestroyChannelElement,
498
+ grpc_channel_next_get_info,
499
+ "server",
500
+ };
873
501
 
874
- if (error != GRPC_ERROR_NONE ||
875
- server->shutdown_flag.load(std::memory_order_acquire)) {
876
- calld->state.Store(CallState::ZOMBIED, grpc_core::MemoryOrder::RELAXED);
877
- GRPC_CLOSURE_INIT(
878
- &calld->kill_zombie_closure, kill_zombie,
879
- grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0),
880
- grpc_schedule_on_exec_ctx);
881
- ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
882
- GRPC_ERROR_REF(error));
883
- return;
502
+ namespace {
503
+
504
+ grpc_resource_user* CreateDefaultResourceUser(const grpc_channel_args* args) {
505
+ if (args != nullptr) {
506
+ grpc_resource_quota* resource_quota =
507
+ grpc_resource_quota_from_channel_args(args, false /* create */);
508
+ if (resource_quota != nullptr) {
509
+ return grpc_resource_user_create(resource_quota, "default");
510
+ }
884
511
  }
512
+ return nullptr;
513
+ }
885
514
 
886
- rm->MatchOrQueue(chand->cq_idx, calld);
515
+ RefCountedPtr<channelz::ServerNode> CreateChannelzNode(
516
+ Server* server, const grpc_channel_args* args) {
517
+ RefCountedPtr<channelz::ServerNode> channelz_node;
518
+ if (grpc_channel_args_find_bool(args, GRPC_ARG_ENABLE_CHANNELZ,
519
+ GRPC_ENABLE_CHANNELZ_DEFAULT)) {
520
+ size_t channel_tracer_max_memory = grpc_channel_args_find_integer(
521
+ args, GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE,
522
+ {GRPC_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE_DEFAULT, 0, INT_MAX});
523
+ channelz_node =
524
+ MakeRefCounted<channelz::ServerNode>(channel_tracer_max_memory);
525
+ channelz_node->AddTraceEvent(
526
+ channelz::ChannelTrace::Severity::Info,
527
+ grpc_slice_from_static_string("Server created"));
528
+ }
529
+ return channelz_node;
887
530
  }
888
531
 
889
- void finish_start_new_rpc(
890
- grpc_server* server, grpc_call_element* elem, RequestMatcherInterface* rm,
891
- grpc_server_register_method_payload_handling payload_handling) {
892
- call_data* calld = static_cast<call_data*>(elem->call_data);
532
+ } // namespace
893
533
 
894
- if (server->shutdown_flag.load(std::memory_order_acquire)) {
895
- calld->state.Store(CallState::ZOMBIED, grpc_core::MemoryOrder::RELAXED);
896
- GRPC_CLOSURE_INIT(&calld->kill_zombie_closure, kill_zombie, elem,
897
- grpc_schedule_on_exec_ctx);
898
- ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure, GRPC_ERROR_NONE);
899
- return;
534
+ Server::Server(const grpc_channel_args* args)
535
+ : channel_args_(grpc_channel_args_copy(args)),
536
+ default_resource_user_(CreateDefaultResourceUser(args)),
537
+ channelz_node_(CreateChannelzNode(this, args)) {}
538
+
539
+ Server::~Server() {
540
+ grpc_channel_args_destroy(channel_args_);
541
+ // Remove the cq pollsets from the config_fetcher.
542
+ if (started_ && config_fetcher_ != nullptr &&
543
+ config_fetcher_->interested_parties() != nullptr) {
544
+ for (grpc_pollset* pollset : pollsets_) {
545
+ grpc_pollset_set_del_pollset(config_fetcher_->interested_parties(),
546
+ pollset);
547
+ }
900
548
  }
549
+ for (size_t i = 0; i < cqs_.size(); i++) {
550
+ GRPC_CQ_INTERNAL_UNREF(cqs_[i], "server");
551
+ }
552
+ }
901
553
 
902
- calld->matcher = rm;
554
+ void Server::AddListener(OrphanablePtr<ListenerInterface> listener) {
555
+ channelz::ListenSocketNode* listen_socket_node =
556
+ listener->channelz_listen_socket_node();
557
+ if (listen_socket_node != nullptr && channelz_node_ != nullptr) {
558
+ channelz_node_->AddChildListenSocket(listen_socket_node->Ref());
559
+ }
560
+ listeners_.emplace_back(std::move(listener));
561
+ }
903
562
 
904
- switch (payload_handling) {
905
- case GRPC_SRM_PAYLOAD_NONE:
906
- publish_new_rpc(elem, GRPC_ERROR_NONE);
907
- break;
908
- case GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER: {
909
- grpc_op op;
910
- op.op = GRPC_OP_RECV_MESSAGE;
911
- op.flags = 0;
912
- op.reserved = nullptr;
913
- op.data.recv_message.recv_message = &calld->payload;
914
- GRPC_CLOSURE_INIT(&calld->publish, publish_new_rpc, elem,
915
- grpc_schedule_on_exec_ctx);
916
- grpc_call_start_batch_and_execute(calld->call, &op, 1, &calld->publish);
917
- break;
563
+ void Server::Start() {
564
+ started_ = true;
565
+ for (grpc_completion_queue* cq : cqs_) {
566
+ if (grpc_cq_can_listen(cq)) {
567
+ pollsets_.push_back(grpc_cq_pollset(cq));
918
568
  }
919
569
  }
920
- }
921
-
922
- void start_new_rpc(grpc_call_element* elem) {
923
- channel_data* chand = static_cast<channel_data*>(elem->channel_data);
924
- call_data* calld = static_cast<call_data*>(elem->call_data);
925
- grpc_server* server = chand->server;
926
- uint32_t i;
927
- uint32_t hash;
928
- channel_registered_method* rm;
929
-
930
- if (chand->registered_methods && calld->path_set && calld->host_set) {
931
- /* TODO(ctiller): unify these two searches */
932
- /* check for an exact match with host */
933
- hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash_internal(calld->host),
934
- grpc_slice_hash_internal(calld->path));
935
- for (i = 0; i <= chand->registered_method_max_probes; i++) {
936
- rm = &(*chand->registered_methods)[(hash + i) %
937
- chand->registered_methods->size()];
938
- if (rm->server_registered_method == nullptr) break;
939
- if (!rm->has_host) continue;
940
- if (rm->host != calld->host) continue;
941
- if (rm->method != calld->path) continue;
942
- if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) &&
943
- 0 == (calld->recv_initial_metadata_flags &
944
- GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST)) {
945
- continue;
946
- }
947
- finish_start_new_rpc(server, elem,
948
- rm->server_registered_method->matcher.get(),
949
- rm->server_registered_method->payload_handling);
950
- return;
570
+ if (unregistered_request_matcher_ == nullptr) {
571
+ unregistered_request_matcher_ = absl::make_unique<RealRequestMatcher>(this);
572
+ }
573
+ for (std::unique_ptr<RegisteredMethod>& rm : registered_methods_) {
574
+ if (rm->matcher == nullptr) {
575
+ rm->matcher = absl::make_unique<RealRequestMatcher>(this);
951
576
  }
952
- /* check for a wildcard method definition (no host set) */
953
- hash = GRPC_MDSTR_KV_HASH(0, grpc_slice_hash_internal(calld->path));
954
- for (i = 0; i <= chand->registered_method_max_probes; i++) {
955
- rm = &(*chand->registered_methods)[(hash + i) %
956
- chand->registered_methods->size()];
957
- if (rm->server_registered_method == nullptr) break;
958
- if (rm->has_host) continue;
959
- if (rm->method != calld->path) continue;
960
- if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) &&
961
- 0 == (calld->recv_initial_metadata_flags &
962
- GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST)) {
963
- continue;
964
- }
965
- finish_start_new_rpc(server, elem,
966
- rm->server_registered_method->matcher.get(),
967
- rm->server_registered_method->payload_handling);
968
- return;
577
+ }
578
+ {
579
+ MutexLock lock(&mu_global_);
580
+ starting_ = true;
581
+ }
582
+ // Register the interested parties from the config fetcher to the cq pollsets
583
+ // before starting listeners so that config fetcher is being polled when the
584
+ // listeners start watch the fetcher.
585
+ if (config_fetcher_ != nullptr &&
586
+ config_fetcher_->interested_parties() != nullptr) {
587
+ for (grpc_pollset* pollset : pollsets_) {
588
+ grpc_pollset_set_add_pollset(config_fetcher_->interested_parties(),
589
+ pollset);
969
590
  }
970
591
  }
971
- finish_start_new_rpc(server, elem, server->unregistered_request_matcher.get(),
972
- GRPC_SRM_PAYLOAD_NONE);
592
+ for (auto& listener : listeners_) {
593
+ listener.listener->Start(this, &pollsets_);
594
+ }
595
+ MutexLock lock(&mu_global_);
596
+ starting_ = false;
597
+ starting_cv_.Signal();
973
598
  }
974
599
 
975
- void done_shutdown_event(void* server, grpc_cq_completion* /*completion*/) {
976
- server_unref(static_cast<grpc_server*>(server));
600
+ grpc_error* Server::SetupTransport(
601
+ grpc_transport* transport, grpc_pollset* accepting_pollset,
602
+ const grpc_channel_args* args,
603
+ const RefCountedPtr<grpc_core::channelz::SocketNode>& socket_node,
604
+ grpc_resource_user* resource_user) {
605
+ // Create channel.
606
+ grpc_error* error = GRPC_ERROR_NONE;
607
+ grpc_channel* channel = grpc_channel_create(
608
+ nullptr, args, GRPC_SERVER_CHANNEL, transport, resource_user, &error);
609
+ if (channel == nullptr) {
610
+ return error;
611
+ }
612
+ ChannelData* chand = static_cast<ChannelData*>(
613
+ grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0)
614
+ ->channel_data);
615
+ // Set up CQs.
616
+ size_t cq_idx;
617
+ for (cq_idx = 0; cq_idx < cqs_.size(); cq_idx++) {
618
+ if (grpc_cq_pollset(cqs_[cq_idx]) == accepting_pollset) break;
619
+ }
620
+ if (cq_idx == cqs_.size()) {
621
+ // Completion queue not found. Pick a random one to publish new calls to.
622
+ cq_idx = static_cast<size_t>(rand()) % cqs_.size();
623
+ }
624
+ // Set up channelz node.
625
+ intptr_t channelz_socket_uuid = 0;
626
+ if (socket_node != nullptr) {
627
+ channelz_socket_uuid = socket_node->uuid();
628
+ channelz_node_->AddChildSocket(socket_node);
629
+ }
630
+ // Initialize chand.
631
+ chand->InitTransport(Ref(), channel, cq_idx, transport, channelz_socket_uuid);
632
+ return GRPC_ERROR_NONE;
977
633
  }
978
634
 
979
- int num_channels(grpc_server* server) { return server->channels.size(); }
635
+ bool Server::HasOpenConnections() {
636
+ MutexLock lock(&mu_global_);
637
+ return !channels_.empty();
638
+ }
980
639
 
981
- void kill_pending_work_locked(grpc_server* server, grpc_error* error) {
982
- if (server->started) {
983
- server->unregistered_request_matcher->KillRequests(GRPC_ERROR_REF(error));
984
- server->unregistered_request_matcher->ZombifyPending();
985
- for (std::unique_ptr<registered_method>& rm : server->registered_methods) {
986
- rm->matcher->KillRequests(GRPC_ERROR_REF(error));
987
- rm->matcher->ZombifyPending();
640
+ void Server::SetRegisteredMethodAllocator(
641
+ grpc_completion_queue* cq, void* method_tag,
642
+ std::function<RegisteredCallAllocation()> allocator) {
643
+ RegisteredMethod* rm = static_cast<RegisteredMethod*>(method_tag);
644
+ rm->matcher = absl::make_unique<AllocatingRequestMatcherRegistered>(
645
+ this, cq, rm, std::move(allocator));
646
+ }
647
+
648
+ void Server::SetBatchMethodAllocator(
649
+ grpc_completion_queue* cq, std::function<BatchCallAllocation()> allocator) {
650
+ GPR_DEBUG_ASSERT(unregistered_request_matcher_ == nullptr);
651
+ unregistered_request_matcher_ =
652
+ absl::make_unique<AllocatingRequestMatcherBatch>(this, cq,
653
+ std::move(allocator));
654
+ }
655
+
656
+ void Server::RegisterCompletionQueue(grpc_completion_queue* cq) {
657
+ for (grpc_completion_queue* queue : cqs_) {
658
+ if (queue == cq) return;
659
+ }
660
+ GRPC_CQ_INTERNAL_REF(cq, "server");
661
+ cqs_.push_back(cq);
662
+ }
663
+
664
+ namespace {
665
+
666
+ bool streq(const std::string& a, const char* b) {
667
+ return (a.empty() && b == nullptr) ||
668
+ ((b != nullptr) && !strcmp(a.c_str(), b));
669
+ }
670
+
671
+ } // namespace
672
+
673
+ Server::RegisteredMethod* Server::RegisterMethod(
674
+ const char* method, const char* host,
675
+ grpc_server_register_method_payload_handling payload_handling,
676
+ uint32_t flags) {
677
+ if (!method) {
678
+ gpr_log(GPR_ERROR,
679
+ "grpc_server_register_method method string cannot be NULL");
680
+ return nullptr;
681
+ }
682
+ for (std::unique_ptr<RegisteredMethod>& m : registered_methods_) {
683
+ if (streq(m->method, method) && streq(m->host, host)) {
684
+ gpr_log(GPR_ERROR, "duplicate registration for %s@%s", method,
685
+ host ? host : "*");
686
+ return nullptr;
988
687
  }
989
688
  }
990
- GRPC_ERROR_UNREF(error);
689
+ if ((flags & ~GRPC_INITIAL_METADATA_USED_MASK) != 0) {
690
+ gpr_log(GPR_ERROR, "grpc_server_register_method invalid flags 0x%08x",
691
+ flags);
692
+ return nullptr;
693
+ }
694
+ registered_methods_.emplace_back(absl::make_unique<RegisteredMethod>(
695
+ method, host, payload_handling, flags));
696
+ return registered_methods_.back().get();
991
697
  }
992
698
 
993
- void maybe_finish_shutdown(grpc_server* server) {
994
- size_t i;
995
- if (!server->shutdown_flag.load(std::memory_order_acquire) ||
996
- server->shutdown_published) {
699
+ void Server::DoneRequestEvent(void* req, grpc_cq_completion* /*c*/) {
700
+ delete static_cast<RequestedCall*>(req);
701
+ }
702
+
703
+ void Server::FailCall(size_t cq_idx, RequestedCall* rc, grpc_error* error) {
704
+ *rc->call = nullptr;
705
+ rc->initial_metadata->count = 0;
706
+ GPR_ASSERT(error != GRPC_ERROR_NONE);
707
+ grpc_cq_end_op(cqs_[cq_idx], rc->tag, error, DoneRequestEvent, rc,
708
+ &rc->completion);
709
+ }
710
+
711
+ // Before calling MaybeFinishShutdown(), we must hold mu_global_ and not
712
+ // hold mu_call_.
713
+ void Server::MaybeFinishShutdown() {
714
+ if (!shutdown_flag_.load(std::memory_order_acquire) || shutdown_published_) {
997
715
  return;
998
716
  }
999
-
1000
717
  {
1001
- MutexLock lock(&server->mu_call);
1002
- kill_pending_work_locked(
1003
- server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
718
+ MutexLock lock(&mu_call_);
719
+ KillPendingWorkLocked(
720
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
1004
721
  }
1005
-
1006
- if (!server->channels.empty() ||
1007
- server->listeners_destroyed < server->listeners.size()) {
722
+ if (!channels_.empty() || listeners_destroyed_ < listeners_.size()) {
1008
723
  if (gpr_time_cmp(gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME),
1009
- server->last_shutdown_message_time),
724
+ last_shutdown_message_time_),
1010
725
  gpr_time_from_seconds(1, GPR_TIMESPAN)) >= 0) {
1011
- server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME);
726
+ last_shutdown_message_time_ = gpr_now(GPR_CLOCK_REALTIME);
1012
727
  gpr_log(GPR_DEBUG,
1013
- "Waiting for %d channels and %" PRIuPTR "/%" PRIuPTR
728
+ "Waiting for %" PRIuPTR " channels and %" PRIuPTR "/%" PRIuPTR
1014
729
  " listeners to be destroyed before shutting down server",
1015
- num_channels(server),
1016
- server->listeners.size() - server->listeners_destroyed,
1017
- server->listeners.size());
730
+ channels_.size(), listeners_.size() - listeners_destroyed_,
731
+ listeners_.size());
1018
732
  }
1019
733
  return;
1020
734
  }
1021
- server->shutdown_published = 1;
1022
- for (i = 0; i < server->shutdown_tags.size(); i++) {
1023
- server_ref(server);
1024
- grpc_cq_end_op(server->shutdown_tags[i].cq, server->shutdown_tags[i].tag,
1025
- GRPC_ERROR_NONE, done_shutdown_event, server,
1026
- &server->shutdown_tags[i].completion);
735
+ shutdown_published_ = true;
736
+ for (auto& shutdown_tag : shutdown_tags_) {
737
+ Ref().release();
738
+ grpc_cq_end_op(shutdown_tag.cq, shutdown_tag.tag, GRPC_ERROR_NONE,
739
+ DoneShutdownEvent, this, &shutdown_tag.completion);
1027
740
  }
1028
741
  }
1029
742
 
1030
- void server_on_recv_initial_metadata(void* ptr, grpc_error* error) {
1031
- grpc_call_element* elem = static_cast<grpc_call_element*>(ptr);
1032
- call_data* calld = static_cast<call_data*>(elem->call_data);
1033
- grpc_millis op_deadline;
743
+ void Server::KillPendingWorkLocked(grpc_error* error) {
744
+ if (started_) {
745
+ unregistered_request_matcher_->KillRequests(GRPC_ERROR_REF(error));
746
+ unregistered_request_matcher_->ZombifyPending();
747
+ for (std::unique_ptr<RegisteredMethod>& rm : registered_methods_) {
748
+ rm->matcher->KillRequests(GRPC_ERROR_REF(error));
749
+ rm->matcher->ZombifyPending();
750
+ }
751
+ }
752
+ GRPC_ERROR_UNREF(error);
753
+ }
1034
754
 
1035
- if (error == GRPC_ERROR_NONE) {
1036
- GPR_DEBUG_ASSERT(calld->recv_initial_metadata->idx.named.path != nullptr);
1037
- GPR_DEBUG_ASSERT(calld->recv_initial_metadata->idx.named.authority !=
1038
- nullptr);
1039
- calld->path = grpc_slice_ref_internal(
1040
- GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.path->md));
1041
- calld->host = grpc_slice_ref_internal(
1042
- GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.authority->md));
1043
- calld->path_set = true;
1044
- calld->host_set = true;
1045
- grpc_metadata_batch_remove(calld->recv_initial_metadata, GRPC_BATCH_PATH);
1046
- grpc_metadata_batch_remove(calld->recv_initial_metadata,
1047
- GRPC_BATCH_AUTHORITY);
1048
- } else {
1049
- GRPC_ERROR_REF(error);
755
+ std::vector<grpc_channel*> Server::GetChannelsLocked() const {
756
+ std::vector<grpc_channel*> channels;
757
+ channels.reserve(channels_.size());
758
+ for (const ChannelData* chand : channels_) {
759
+ channels.push_back(chand->channel());
760
+ GRPC_CHANNEL_INTERNAL_REF(chand->channel(), "broadcast");
1050
761
  }
1051
- op_deadline = calld->recv_initial_metadata->deadline;
1052
- if (op_deadline != GRPC_MILLIS_INF_FUTURE) {
1053
- calld->deadline = op_deadline;
762
+ return channels;
763
+ }
764
+
765
+ void Server::ListenerDestroyDone(void* arg, grpc_error* /*error*/) {
766
+ Server* server = static_cast<Server*>(arg);
767
+ MutexLock lock(&server->mu_global_);
768
+ server->listeners_destroyed_++;
769
+ server->MaybeFinishShutdown();
770
+ }
771
+
772
+ namespace {
773
+
774
+ void DonePublishedShutdown(void* /*done_arg*/, grpc_cq_completion* storage) {
775
+ delete storage;
776
+ }
777
+
778
+ } // namespace
779
+
780
+ // - Kills all pending requests-for-incoming-RPC-calls (i.e., the requests made
781
+ // via grpc_server_request_call() and grpc_server_request_registered_call()
782
+ // will now be cancelled). See KillPendingWorkLocked().
783
+ //
784
+ // - Shuts down the listeners (i.e., the server will no longer listen on the
785
+ // port for new incoming channels).
786
+ //
787
+ // - Iterates through all channels on the server and sends shutdown msg (see
788
+ // ChannelBroadcaster::BroadcastShutdown() for details) to the clients via
789
+ // the transport layer. The transport layer then guarantees the following:
790
+ // -- Sends shutdown to the client (e.g., HTTP2 transport sends GOAWAY).
791
+ // -- If the server has outstanding calls that are in the process, the
792
+ // connection is NOT closed until the server is done with all those calls.
793
+ // -- Once there are no more calls in progress, the channel is closed.
794
+ void Server::ShutdownAndNotify(grpc_completion_queue* cq, void* tag) {
795
+ ChannelBroadcaster broadcaster;
796
+ {
797
+ // Wait for startup to be finished. Locks mu_global.
798
+ MutexLock lock(&mu_global_);
799
+ starting_cv_.WaitUntil(&mu_global_, [this] { return !starting_; });
800
+ // Stay locked, and gather up some stuff to do.
801
+ GPR_ASSERT(grpc_cq_begin_op(cq, tag));
802
+ if (shutdown_published_) {
803
+ grpc_cq_end_op(cq, tag, GRPC_ERROR_NONE, DonePublishedShutdown, nullptr,
804
+ new grpc_cq_completion);
805
+ return;
806
+ }
807
+ shutdown_tags_.emplace_back(tag, cq);
808
+ if (shutdown_flag_.load(std::memory_order_acquire)) {
809
+ return;
810
+ }
811
+ last_shutdown_message_time_ = gpr_now(GPR_CLOCK_REALTIME);
812
+ broadcaster.FillChannelsLocked(GetChannelsLocked());
813
+ shutdown_flag_.store(true, std::memory_order_release);
814
+ // Collect all unregistered then registered calls.
815
+ {
816
+ MutexLock lock(&mu_call_);
817
+ KillPendingWorkLocked(
818
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
819
+ }
820
+ MaybeFinishShutdown();
1054
821
  }
1055
- if (calld->host_set && calld->path_set) {
1056
- /* do nothing */
1057
- } else {
1058
- /* Pass the error reference to calld->recv_initial_metadata_error */
1059
- grpc_error* src_error = error;
1060
- error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
1061
- "Missing :authority or :path", &src_error, 1);
1062
- GRPC_ERROR_UNREF(src_error);
1063
- calld->recv_initial_metadata_error = GRPC_ERROR_REF(error);
822
+ // Shutdown listeners.
823
+ for (auto& listener : listeners_) {
824
+ channelz::ListenSocketNode* channelz_listen_socket_node =
825
+ listener.listener->channelz_listen_socket_node();
826
+ if (channelz_node_ != nullptr && channelz_listen_socket_node != nullptr) {
827
+ channelz_node_->RemoveChildListenSocket(
828
+ channelz_listen_socket_node->uuid());
829
+ }
830
+ GRPC_CLOSURE_INIT(&listener.destroy_done, ListenerDestroyDone, this,
831
+ grpc_schedule_on_exec_ctx);
832
+ listener.listener->SetOnDestroyDone(&listener.destroy_done);
833
+ listener.listener.reset();
1064
834
  }
1065
- grpc_closure* closure = calld->on_done_recv_initial_metadata;
1066
- calld->on_done_recv_initial_metadata = nullptr;
1067
- if (calld->seen_recv_trailing_metadata_ready) {
1068
- GRPC_CALL_COMBINER_START(calld->call_combiner,
1069
- &calld->recv_trailing_metadata_ready,
1070
- calld->recv_trailing_metadata_error,
1071
- "continue server_recv_trailing_metadata_ready");
835
+ broadcaster.BroadcastShutdown(/*send_goaway=*/true, GRPC_ERROR_NONE);
836
+ }
837
+
838
+ void Server::CancelAllCalls() {
839
+ ChannelBroadcaster broadcaster;
840
+ {
841
+ MutexLock lock(&mu_global_);
842
+ broadcaster.FillChannelsLocked(GetChannelsLocked());
1072
843
  }
1073
- Closure::Run(DEBUG_LOCATION, closure, error);
844
+ broadcaster.BroadcastShutdown(
845
+ /*send_goaway=*/false,
846
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Cancelling all calls"));
1074
847
  }
1075
848
 
1076
- void server_recv_trailing_metadata_ready(void* user_data, grpc_error* error) {
1077
- grpc_call_element* elem = static_cast<grpc_call_element*>(user_data);
1078
- call_data* calld = static_cast<call_data*>(elem->call_data);
1079
- if (calld->on_done_recv_initial_metadata != nullptr) {
1080
- calld->recv_trailing_metadata_error = GRPC_ERROR_REF(error);
1081
- calld->seen_recv_trailing_metadata_ready = true;
1082
- GRPC_CLOSURE_INIT(&calld->recv_trailing_metadata_ready,
1083
- server_recv_trailing_metadata_ready, elem,
1084
- grpc_schedule_on_exec_ctx);
1085
- GRPC_CALL_COMBINER_STOP(calld->call_combiner,
1086
- "deferring server_recv_trailing_metadata_ready "
1087
- "until after server_on_recv_initial_metadata");
1088
- return;
849
+ void Server::Orphan() {
850
+ {
851
+ MutexLock lock(&mu_global_);
852
+ GPR_ASSERT(shutdown_flag_.load(std::memory_order_acquire) ||
853
+ listeners_.empty());
854
+ GPR_ASSERT(listeners_destroyed_ == listeners_.size());
1089
855
  }
1090
- error =
1091
- grpc_error_add_child(GRPC_ERROR_REF(error),
1092
- GRPC_ERROR_REF(calld->recv_initial_metadata_error));
1093
- Closure::Run(DEBUG_LOCATION, calld->original_recv_trailing_metadata_ready,
1094
- error);
856
+ if (default_resource_user_ != nullptr) {
857
+ grpc_resource_quota_unref(grpc_resource_user_quota(default_resource_user_));
858
+ grpc_resource_user_shutdown(default_resource_user_);
859
+ grpc_resource_user_unref(default_resource_user_);
860
+ }
861
+ Unref();
1095
862
  }
1096
863
 
1097
- void server_mutate_op(grpc_call_element* elem,
1098
- grpc_transport_stream_op_batch* op) {
1099
- call_data* calld = static_cast<call_data*>(elem->call_data);
864
+ grpc_call_error Server::ValidateServerRequest(
865
+ grpc_completion_queue* cq_for_notification, void* tag,
866
+ grpc_byte_buffer** optional_payload, RegisteredMethod* rm) {
867
+ if ((rm == nullptr && optional_payload != nullptr) ||
868
+ ((rm != nullptr) && ((optional_payload == nullptr) !=
869
+ (rm->payload_handling == GRPC_SRM_PAYLOAD_NONE)))) {
870
+ return GRPC_CALL_ERROR_PAYLOAD_TYPE_MISMATCH;
871
+ }
872
+ if (grpc_cq_begin_op(cq_for_notification, tag) == false) {
873
+ return GRPC_CALL_ERROR_COMPLETION_QUEUE_SHUTDOWN;
874
+ }
875
+ return GRPC_CALL_OK;
876
+ }
1100
877
 
1101
- if (op->recv_initial_metadata) {
1102
- GPR_ASSERT(op->payload->recv_initial_metadata.recv_flags == nullptr);
1103
- calld->recv_initial_metadata =
1104
- op->payload->recv_initial_metadata.recv_initial_metadata;
1105
- calld->on_done_recv_initial_metadata =
1106
- op->payload->recv_initial_metadata.recv_initial_metadata_ready;
1107
- op->payload->recv_initial_metadata.recv_initial_metadata_ready =
1108
- &calld->on_recv_initial_metadata;
1109
- op->payload->recv_initial_metadata.recv_flags =
1110
- &calld->recv_initial_metadata_flags;
878
+ grpc_call_error Server::ValidateServerRequestAndCq(
879
+ size_t* cq_idx, grpc_completion_queue* cq_for_notification, void* tag,
880
+ grpc_byte_buffer** optional_payload, RegisteredMethod* rm) {
881
+ size_t idx;
882
+ for (idx = 0; idx < cqs_.size(); idx++) {
883
+ if (cqs_[idx] == cq_for_notification) {
884
+ break;
885
+ }
886
+ }
887
+ if (idx == cqs_.size()) {
888
+ return GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE;
1111
889
  }
1112
- if (op->recv_trailing_metadata) {
1113
- calld->original_recv_trailing_metadata_ready =
1114
- op->payload->recv_trailing_metadata.recv_trailing_metadata_ready;
1115
- op->payload->recv_trailing_metadata.recv_trailing_metadata_ready =
1116
- &calld->recv_trailing_metadata_ready;
890
+ grpc_call_error error =
891
+ ValidateServerRequest(cq_for_notification, tag, optional_payload, rm);
892
+ if (error != GRPC_CALL_OK) {
893
+ return error;
1117
894
  }
895
+ *cq_idx = idx;
896
+ return GRPC_CALL_OK;
1118
897
  }
1119
898
 
1120
- void server_start_transport_stream_op_batch(
1121
- grpc_call_element* elem, grpc_transport_stream_op_batch* op) {
1122
- server_mutate_op(elem, op);
1123
- grpc_call_next_op(elem, op);
899
+ grpc_call_error Server::QueueRequestedCall(size_t cq_idx, RequestedCall* rc) {
900
+ if (shutdown_flag_.load(std::memory_order_acquire)) {
901
+ FailCall(cq_idx, rc,
902
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
903
+ return GRPC_CALL_OK;
904
+ }
905
+ RequestMatcherInterface* rm;
906
+ switch (rc->type) {
907
+ case RequestedCall::Type::BATCH_CALL:
908
+ rm = unregistered_request_matcher_.get();
909
+ break;
910
+ case RequestedCall::Type::REGISTERED_CALL:
911
+ rm = rc->data.registered.method->matcher.get();
912
+ break;
913
+ }
914
+ rm->RequestCallWithPossiblePublish(cq_idx, rc);
915
+ return GRPC_CALL_OK;
1124
916
  }
1125
917
 
1126
- void got_initial_metadata(void* ptr, grpc_error* error) {
1127
- grpc_call_element* elem = static_cast<grpc_call_element*>(ptr);
1128
- call_data* calld = static_cast<call_data*>(elem->call_data);
1129
- if (error == GRPC_ERROR_NONE) {
1130
- start_new_rpc(elem);
1131
- } else {
1132
- CallState expect_not_started = CallState::NOT_STARTED;
1133
- CallState expect_pending = CallState::PENDING;
1134
- if (calld->state.CompareExchangeStrong(
1135
- &expect_not_started, CallState::ZOMBIED,
1136
- grpc_core::MemoryOrder::ACQ_REL, grpc_core::MemoryOrder::RELAXED)) {
1137
- GRPC_CLOSURE_INIT(&calld->kill_zombie_closure, kill_zombie, elem,
1138
- grpc_schedule_on_exec_ctx);
1139
- ExecCtx::Run(DEBUG_LOCATION, &calld->kill_zombie_closure,
1140
- GRPC_ERROR_NONE);
1141
- } else if (calld->state.CompareExchangeStrong(
1142
- &expect_pending, CallState::ZOMBIED,
1143
- grpc_core::MemoryOrder::ACQ_REL,
1144
- grpc_core::MemoryOrder::RELAXED)) {
1145
- /* zombied call will be destroyed when it's removed from the pending
1146
- queue... later */
918
+ grpc_call_error Server::RequestCall(grpc_call** call,
919
+ grpc_call_details* details,
920
+ grpc_metadata_array* request_metadata,
921
+ grpc_completion_queue* cq_bound_to_call,
922
+ grpc_completion_queue* cq_for_notification,
923
+ void* tag) {
924
+ size_t cq_idx;
925
+ grpc_call_error error = ValidateServerRequestAndCq(
926
+ &cq_idx, cq_for_notification, tag, nullptr, nullptr);
927
+ if (error != GRPC_CALL_OK) {
928
+ return error;
929
+ }
930
+ RequestedCall* rc =
931
+ new RequestedCall(tag, cq_bound_to_call, call, request_metadata, details);
932
+ return QueueRequestedCall(cq_idx, rc);
933
+ }
934
+
935
+ grpc_call_error Server::RequestRegisteredCall(
936
+ RegisteredMethod* rm, grpc_call** call, gpr_timespec* deadline,
937
+ grpc_metadata_array* request_metadata, grpc_byte_buffer** optional_payload,
938
+ grpc_completion_queue* cq_bound_to_call,
939
+ grpc_completion_queue* cq_for_notification, void* tag_new) {
940
+ size_t cq_idx;
941
+ grpc_call_error error = ValidateServerRequestAndCq(
942
+ &cq_idx, cq_for_notification, tag_new, optional_payload, rm);
943
+ if (error != GRPC_CALL_OK) {
944
+ return error;
945
+ }
946
+ RequestedCall* rc =
947
+ new RequestedCall(tag_new, cq_bound_to_call, call, request_metadata, rm,
948
+ deadline, optional_payload);
949
+ return QueueRequestedCall(cq_idx, rc);
950
+ }
951
+
952
+ //
953
+ // Server::ChannelData::ConnectivityWatcher
954
+ //
955
+
956
+ class Server::ChannelData::ConnectivityWatcher
957
+ : public AsyncConnectivityStateWatcherInterface {
958
+ public:
959
+ explicit ConnectivityWatcher(ChannelData* chand) : chand_(chand) {
960
+ GRPC_CHANNEL_INTERNAL_REF(chand_->channel_, "connectivity");
961
+ }
962
+
963
+ ~ConnectivityWatcher() override {
964
+ GRPC_CHANNEL_INTERNAL_UNREF(chand_->channel_, "connectivity");
965
+ }
966
+
967
+ private:
968
+ void OnConnectivityStateChange(grpc_connectivity_state new_state,
969
+ const absl::Status& /*status*/) override {
970
+ // Don't do anything until we are being shut down.
971
+ if (new_state != GRPC_CHANNEL_SHUTDOWN) return;
972
+ // Shut down channel.
973
+ MutexLock lock(&chand_->server_->mu_global_);
974
+ chand_->Destroy();
975
+ }
976
+
977
+ ChannelData* chand_;
978
+ };
979
+
980
+ //
981
+ // Server::ChannelData
982
+ //
983
+
984
+ Server::ChannelData::~ChannelData() {
985
+ if (registered_methods_ != nullptr) {
986
+ for (const ChannelRegisteredMethod& crm : *registered_methods_) {
987
+ grpc_slice_unref_internal(crm.method);
988
+ GPR_DEBUG_ASSERT(crm.method.refcount == &kNoopRefcount ||
989
+ crm.method.refcount == nullptr);
990
+ if (crm.has_host) {
991
+ grpc_slice_unref_internal(crm.host);
992
+ GPR_DEBUG_ASSERT(crm.host.refcount == &kNoopRefcount ||
993
+ crm.host.refcount == nullptr);
994
+ }
995
+ }
996
+ registered_methods_.reset();
997
+ }
998
+ if (server_ != nullptr) {
999
+ if (server_->channelz_node_ != nullptr && channelz_socket_uuid_ != 0) {
1000
+ server_->channelz_node_->RemoveChildSocket(channelz_socket_uuid_);
1001
+ }
1002
+ {
1003
+ MutexLock lock(&server_->mu_global_);
1004
+ if (list_position_.has_value()) {
1005
+ server_->channels_.erase(*list_position_);
1006
+ list_position_.reset();
1007
+ }
1008
+ server_->MaybeFinishShutdown();
1147
1009
  }
1148
1010
  }
1149
1011
  }
1150
1012
 
1151
- void accept_stream(void* cd, grpc_transport* /*transport*/,
1152
- const void* transport_server_data) {
1153
- channel_data* chand = static_cast<channel_data*>(cd);
1013
+ void Server::ChannelData::InitTransport(RefCountedPtr<Server> server,
1014
+ grpc_channel* channel, size_t cq_idx,
1015
+ grpc_transport* transport,
1016
+ intptr_t channelz_socket_uuid) {
1017
+ server_ = std::move(server);
1018
+ channel_ = channel;
1019
+ cq_idx_ = cq_idx;
1020
+ channelz_socket_uuid_ = channelz_socket_uuid;
1021
+ // Build a lookup table phrased in terms of mdstr's in this channels context
1022
+ // to quickly find registered methods.
1023
+ size_t num_registered_methods = server_->registered_methods_.size();
1024
+ if (num_registered_methods > 0) {
1025
+ uint32_t max_probes = 0;
1026
+ size_t slots = 2 * num_registered_methods;
1027
+ registered_methods_ =
1028
+ absl::make_unique<std::vector<ChannelRegisteredMethod>>(slots);
1029
+ for (std::unique_ptr<RegisteredMethod>& rm : server_->registered_methods_) {
1030
+ ExternallyManagedSlice host;
1031
+ ExternallyManagedSlice method(rm->method.c_str());
1032
+ const bool has_host = !rm->host.empty();
1033
+ if (has_host) {
1034
+ host = ExternallyManagedSlice(rm->host.c_str());
1035
+ }
1036
+ uint32_t hash =
1037
+ GRPC_MDSTR_KV_HASH(has_host ? host.Hash() : 0, method.Hash());
1038
+ uint32_t probes = 0;
1039
+ for (probes = 0; (*registered_methods_)[(hash + probes) % slots]
1040
+ .server_registered_method != nullptr;
1041
+ probes++) {
1042
+ }
1043
+ if (probes > max_probes) max_probes = probes;
1044
+ ChannelRegisteredMethod* crm =
1045
+ &(*registered_methods_)[(hash + probes) % slots];
1046
+ crm->server_registered_method = rm.get();
1047
+ crm->flags = rm->flags;
1048
+ crm->has_host = has_host;
1049
+ if (has_host) {
1050
+ crm->host = host;
1051
+ }
1052
+ crm->method = method;
1053
+ }
1054
+ GPR_ASSERT(slots <= UINT32_MAX);
1055
+ registered_method_max_probes_ = max_probes;
1056
+ }
1057
+ // Publish channel.
1058
+ {
1059
+ MutexLock lock(&server_->mu_global_);
1060
+ server_->channels_.push_front(this);
1061
+ list_position_ = server_->channels_.begin();
1062
+ }
1063
+ // Start accept_stream transport op.
1064
+ grpc_transport_op* op = grpc_make_transport_op(nullptr);
1065
+ op->set_accept_stream = true;
1066
+ op->set_accept_stream_fn = AcceptStream;
1067
+ op->set_accept_stream_user_data = this;
1068
+ op->start_connectivity_watch = MakeOrphanable<ConnectivityWatcher>(this);
1069
+ if (server_->shutdown_flag_.load(std::memory_order_acquire)) {
1070
+ op->disconnect_with_error =
1071
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown");
1072
+ }
1073
+ grpc_transport_perform_op(transport, op);
1074
+ }
1075
+
1076
+ Server::ChannelRegisteredMethod* Server::ChannelData::GetRegisteredMethod(
1077
+ const grpc_slice& host, const grpc_slice& path, bool is_idempotent) {
1078
+ if (registered_methods_ == nullptr) return nullptr;
1079
+ /* TODO(ctiller): unify these two searches */
1080
+ /* check for an exact match with host */
1081
+ uint32_t hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash_internal(host),
1082
+ grpc_slice_hash_internal(path));
1083
+ for (size_t i = 0; i <= registered_method_max_probes_; i++) {
1084
+ ChannelRegisteredMethod* rm =
1085
+ &(*registered_methods_)[(hash + i) % registered_methods_->size()];
1086
+ if (rm->server_registered_method == nullptr) break;
1087
+ if (!rm->has_host) continue;
1088
+ if (rm->host != host) continue;
1089
+ if (rm->method != path) continue;
1090
+ if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) &&
1091
+ !is_idempotent) {
1092
+ continue;
1093
+ }
1094
+ return rm;
1095
+ }
1096
+ /* check for a wildcard method definition (no host set) */
1097
+ hash = GRPC_MDSTR_KV_HASH(0, grpc_slice_hash_internal(path));
1098
+ for (size_t i = 0; i <= registered_method_max_probes_; i++) {
1099
+ ChannelRegisteredMethod* rm =
1100
+ &(*registered_methods_)[(hash + i) % registered_methods_->size()];
1101
+ if (rm->server_registered_method == nullptr) break;
1102
+ if (rm->has_host) continue;
1103
+ if (rm->method != path) continue;
1104
+ if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) &&
1105
+ !is_idempotent) {
1106
+ continue;
1107
+ }
1108
+ return rm;
1109
+ }
1110
+ return nullptr;
1111
+ }
1112
+
1113
+ void Server::ChannelData::AcceptStream(void* arg, grpc_transport* /*transport*/,
1114
+ const void* transport_server_data) {
1115
+ auto* chand = static_cast<Server::ChannelData*>(arg);
1154
1116
  /* create a call */
1155
1117
  grpc_call_create_args args;
1156
- args.channel = chand->channel;
1157
- args.server = chand->server;
1118
+ args.channel = chand->channel_;
1119
+ args.server = chand->server_.get();
1158
1120
  args.parent = nullptr;
1159
1121
  args.propagation_mask = 0;
1160
1122
  args.cq = nullptr;
@@ -1167,199 +1129,352 @@ void accept_stream(void* cd, grpc_transport* /*transport*/,
1167
1129
  grpc_error* error = grpc_call_create(&args, &call);
1168
1130
  grpc_call_element* elem =
1169
1131
  grpc_call_stack_element(grpc_call_get_call_stack(call), 0);
1132
+ auto* calld = static_cast<Server::CallData*>(elem->call_data);
1170
1133
  if (error != GRPC_ERROR_NONE) {
1171
- got_initial_metadata(elem, error);
1172
1134
  GRPC_ERROR_UNREF(error);
1135
+ calld->FailCallCreation();
1173
1136
  return;
1174
1137
  }
1175
- call_data* calld = static_cast<call_data*>(elem->call_data);
1176
- grpc_op op;
1177
- op.op = GRPC_OP_RECV_INITIAL_METADATA;
1178
- op.flags = 0;
1179
- op.reserved = nullptr;
1180
- op.data.recv_initial_metadata.recv_initial_metadata =
1181
- &calld->initial_metadata;
1182
- GRPC_CLOSURE_INIT(&calld->got_initial_metadata, got_initial_metadata, elem,
1183
- grpc_schedule_on_exec_ctx);
1184
- grpc_call_start_batch_and_execute(call, &op, 1, &calld->got_initial_metadata);
1138
+ calld->Start(elem);
1185
1139
  }
1186
1140
 
1187
- grpc_error* server_init_call_elem(grpc_call_element* elem,
1188
- const grpc_call_element_args* args) {
1189
- channel_data* chand = static_cast<channel_data*>(elem->channel_data);
1190
- server_ref(chand->server);
1191
- new (elem->call_data) call_data(elem, *args);
1192
- return GRPC_ERROR_NONE;
1141
+ void Server::ChannelData::FinishDestroy(void* arg, grpc_error* /*error*/) {
1142
+ auto* chand = static_cast<Server::ChannelData*>(arg);
1143
+ Server* server = chand->server_.get();
1144
+ GRPC_CHANNEL_INTERNAL_UNREF(chand->channel_, "server");
1145
+ server->Unref();
1193
1146
  }
1194
1147
 
1195
- void server_destroy_call_elem(grpc_call_element* elem,
1196
- const grpc_call_final_info* /*final_info*/,
1197
- grpc_closure* /*ignored*/) {
1198
- call_data* calld = static_cast<call_data*>(elem->call_data);
1199
- calld->~call_data();
1200
- channel_data* chand = static_cast<channel_data*>(elem->channel_data);
1201
- server_unref(chand->server);
1148
+ void Server::ChannelData::Destroy() {
1149
+ if (!list_position_.has_value()) return;
1150
+ GPR_ASSERT(server_ != nullptr);
1151
+ server_->channels_.erase(*list_position_);
1152
+ list_position_.reset();
1153
+ server_->Ref().release();
1154
+ server_->MaybeFinishShutdown();
1155
+ GRPC_CLOSURE_INIT(&finish_destroy_channel_closure_, FinishDestroy, this,
1156
+ grpc_schedule_on_exec_ctx);
1157
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_server_channel_trace)) {
1158
+ gpr_log(GPR_INFO, "Disconnected client");
1159
+ }
1160
+ grpc_transport_op* op =
1161
+ grpc_make_transport_op(&finish_destroy_channel_closure_);
1162
+ op->set_accept_stream = true;
1163
+ grpc_channel_next_op(
1164
+ grpc_channel_stack_element(grpc_channel_get_channel_stack(channel_), 0),
1165
+ op);
1202
1166
  }
1203
1167
 
1204
- grpc_error* server_init_channel_elem(grpc_channel_element* elem,
1205
- grpc_channel_element_args* args) {
1168
+ grpc_error* Server::ChannelData::InitChannelElement(
1169
+ grpc_channel_element* elem, grpc_channel_element_args* args) {
1206
1170
  GPR_ASSERT(args->is_first);
1207
1171
  GPR_ASSERT(!args->is_last);
1208
-
1209
- new (static_cast<channel_data*>(elem->channel_data)) channel_data;
1172
+ new (elem->channel_data) ChannelData();
1210
1173
  return GRPC_ERROR_NONE;
1211
1174
  }
1212
-
1213
- channel_data::~channel_data() {
1214
- if (registered_methods) {
1215
- for (const channel_registered_method& crm : *registered_methods) {
1216
- grpc_slice_unref_internal(crm.method);
1217
- GPR_DEBUG_ASSERT(crm.method.refcount == &kNoopRefcount ||
1218
- crm.method.refcount == nullptr);
1219
- if (crm.has_host) {
1220
- grpc_slice_unref_internal(crm.host);
1221
- GPR_DEBUG_ASSERT(crm.host.refcount == &kNoopRefcount ||
1222
- crm.host.refcount == nullptr);
1223
- }
1224
- }
1225
- }
1226
- if (server) {
1227
- if (server->channelz_server != nullptr && channelz_socket_uuid != 0) {
1228
- server->channelz_server->RemoveChildSocket(channelz_socket_uuid);
1229
- }
1230
- {
1231
- MutexLock lock(&server->mu_global);
1232
- if (list_position.has_value()) {
1233
- server->channels.erase(*list_position);
1234
- }
1235
- maybe_finish_shutdown(server);
1236
- }
1237
- server_unref(server);
1238
- }
1175
+
1176
+ void Server::ChannelData::DestroyChannelElement(grpc_channel_element* elem) {
1177
+ auto* chand = static_cast<ChannelData*>(elem->channel_data);
1178
+ chand->~ChannelData();
1239
1179
  }
1240
1180
 
1241
- void server_destroy_channel_elem(grpc_channel_element* elem) {
1242
- channel_data* chand = static_cast<channel_data*>(elem->channel_data);
1243
- chand->~channel_data();
1181
+ //
1182
+ // Server::CallData
1183
+ //
1184
+
1185
+ Server::CallData::CallData(grpc_call_element* elem,
1186
+ const grpc_call_element_args& args,
1187
+ RefCountedPtr<Server> server)
1188
+ : server_(std::move(server)),
1189
+ call_(grpc_call_from_top_element(elem)),
1190
+ call_combiner_(args.call_combiner) {
1191
+ GRPC_CLOSURE_INIT(&recv_initial_metadata_ready_, RecvInitialMetadataReady,
1192
+ elem, grpc_schedule_on_exec_ctx);
1193
+ GRPC_CLOSURE_INIT(&recv_trailing_metadata_ready_, RecvTrailingMetadataReady,
1194
+ elem, grpc_schedule_on_exec_ctx);
1244
1195
  }
1245
1196
 
1246
- void register_completion_queue(grpc_server* server, grpc_completion_queue* cq,
1247
- void* reserved) {
1248
- size_t i;
1249
- GPR_ASSERT(!reserved);
1250
- for (i = 0; i < server->cqs.size(); i++) {
1251
- if (server->cqs[i] == cq) return;
1197
+ Server::CallData::~CallData() {
1198
+ GPR_ASSERT(state_.Load(MemoryOrder::RELAXED) != CallState::PENDING);
1199
+ GRPC_ERROR_UNREF(recv_initial_metadata_error_);
1200
+ if (host_.has_value()) {
1201
+ grpc_slice_unref_internal(*host_);
1202
+ }
1203
+ if (path_.has_value()) {
1204
+ grpc_slice_unref_internal(*path_);
1252
1205
  }
1206
+ grpc_metadata_array_destroy(&initial_metadata_);
1207
+ grpc_byte_buffer_destroy(payload_);
1208
+ }
1253
1209
 
1254
- GRPC_CQ_INTERNAL_REF(cq, "server");
1255
- server->cqs.push_back(cq);
1210
+ void Server::CallData::SetState(CallState state) {
1211
+ state_.Store(state, MemoryOrder::RELAXED);
1256
1212
  }
1257
1213
 
1258
- bool streq(const std::string& a, const char* b) {
1259
- return (a.empty() && b == nullptr) ||
1260
- ((b != nullptr) && !strcmp(a.c_str(), b));
1214
+ bool Server::CallData::MaybeActivate() {
1215
+ CallState expected = CallState::PENDING;
1216
+ return state_.CompareExchangeStrong(&expected, CallState::ACTIVATED,
1217
+ MemoryOrder::ACQ_REL,
1218
+ MemoryOrder::RELAXED);
1261
1219
  }
1262
1220
 
1263
- class ConnectivityWatcher : public AsyncConnectivityStateWatcherInterface {
1264
- public:
1265
- explicit ConnectivityWatcher(channel_data* chand) : chand_(chand) {
1266
- GRPC_CHANNEL_INTERNAL_REF(chand_->channel, "connectivity");
1221
+ void Server::CallData::FailCallCreation() {
1222
+ CallState expected_not_started = CallState::NOT_STARTED;
1223
+ CallState expected_pending = CallState::PENDING;
1224
+ if (state_.CompareExchangeStrong(&expected_not_started, CallState::ZOMBIED,
1225
+ MemoryOrder::ACQ_REL,
1226
+ MemoryOrder::ACQUIRE)) {
1227
+ KillZombie();
1228
+ } else if (state_.CompareExchangeStrong(&expected_pending, CallState::ZOMBIED,
1229
+ MemoryOrder::ACQ_REL,
1230
+ MemoryOrder::RELAXED)) {
1231
+ // Zombied call will be destroyed when it's removed from the pending
1232
+ // queue... later.
1267
1233
  }
1234
+ }
1235
+
1236
+ void Server::CallData::Start(grpc_call_element* elem) {
1237
+ grpc_op op;
1238
+ op.op = GRPC_OP_RECV_INITIAL_METADATA;
1239
+ op.flags = 0;
1240
+ op.reserved = nullptr;
1241
+ op.data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_;
1242
+ GRPC_CLOSURE_INIT(&recv_initial_metadata_batch_complete_,
1243
+ RecvInitialMetadataBatchComplete, elem,
1244
+ grpc_schedule_on_exec_ctx);
1245
+ grpc_call_start_batch_and_execute(call_, &op, 1,
1246
+ &recv_initial_metadata_batch_complete_);
1247
+ }
1268
1248
 
1269
- ~ConnectivityWatcher() {
1270
- GRPC_CHANNEL_INTERNAL_UNREF(chand_->channel, "connectivity");
1249
+ void Server::CallData::Publish(size_t cq_idx, RequestedCall* rc) {
1250
+ grpc_call_set_completion_queue(call_, rc->cq_bound_to_call);
1251
+ *rc->call = call_;
1252
+ cq_new_ = server_->cqs_[cq_idx];
1253
+ GPR_SWAP(grpc_metadata_array, *rc->initial_metadata, initial_metadata_);
1254
+ switch (rc->type) {
1255
+ case RequestedCall::Type::BATCH_CALL:
1256
+ GPR_ASSERT(host_.has_value());
1257
+ GPR_ASSERT(path_.has_value());
1258
+ rc->data.batch.details->host = grpc_slice_ref_internal(*host_);
1259
+ rc->data.batch.details->method = grpc_slice_ref_internal(*path_);
1260
+ rc->data.batch.details->deadline =
1261
+ grpc_millis_to_timespec(deadline_, GPR_CLOCK_MONOTONIC);
1262
+ rc->data.batch.details->flags = recv_initial_metadata_flags_;
1263
+ break;
1264
+ case RequestedCall::Type::REGISTERED_CALL:
1265
+ *rc->data.registered.deadline =
1266
+ grpc_millis_to_timespec(deadline_, GPR_CLOCK_MONOTONIC);
1267
+ if (rc->data.registered.optional_payload != nullptr) {
1268
+ *rc->data.registered.optional_payload = payload_;
1269
+ payload_ = nullptr;
1270
+ }
1271
+ break;
1272
+ default:
1273
+ GPR_UNREACHABLE_CODE(return );
1271
1274
  }
1275
+ grpc_cq_end_op(cq_new_, rc->tag, GRPC_ERROR_NONE, Server::DoneRequestEvent,
1276
+ rc, &rc->completion, true);
1277
+ }
1272
1278
 
1273
- private:
1274
- void OnConnectivityStateChange(grpc_connectivity_state new_state) override {
1275
- // Don't do anything until we are being shut down.
1276
- if (new_state != GRPC_CHANNEL_SHUTDOWN) return;
1277
- // Shut down channel.
1278
- grpc_server* server = chand_->server;
1279
- MutexLock lock(&server->mu_global);
1280
- destroy_channel(chand_);
1279
+ void Server::CallData::PublishNewRpc(void* arg, grpc_error* error) {
1280
+ grpc_call_element* call_elem = static_cast<grpc_call_element*>(arg);
1281
+ auto* calld = static_cast<Server::CallData*>(call_elem->call_data);
1282
+ auto* chand = static_cast<Server::ChannelData*>(call_elem->channel_data);
1283
+ RequestMatcherInterface* rm = calld->matcher_;
1284
+ Server* server = rm->server();
1285
+ if (error != GRPC_ERROR_NONE ||
1286
+ server->shutdown_flag_.load(std::memory_order_acquire)) {
1287
+ calld->state_.Store(CallState::ZOMBIED, MemoryOrder::RELAXED);
1288
+ calld->KillZombie();
1289
+ return;
1281
1290
  }
1291
+ rm->MatchOrQueue(chand->cq_idx(), calld);
1292
+ }
1282
1293
 
1283
- channel_data* chand_;
1284
- };
1294
+ namespace {
1285
1295
 
1286
- void done_published_shutdown(void* /*done_arg*/, grpc_cq_completion* storage) {
1287
- delete storage;
1296
+ void KillZombieClosure(void* call, grpc_error* /*error*/) {
1297
+ grpc_call_unref(static_cast<grpc_call*>(call));
1288
1298
  }
1289
1299
 
1290
- void listener_destroy_done(void* s, grpc_error* /*error*/) {
1291
- grpc_server* server = static_cast<grpc_server*>(s);
1292
- MutexLock lock(&server->mu_global);
1293
- server->listeners_destroyed++;
1294
- maybe_finish_shutdown(server);
1300
+ } // namespace
1301
+
1302
+ void Server::CallData::KillZombie() {
1303
+ GRPC_CLOSURE_INIT(&kill_zombie_closure_, KillZombieClosure, call_,
1304
+ grpc_schedule_on_exec_ctx);
1305
+ ExecCtx::Run(DEBUG_LOCATION, &kill_zombie_closure_, GRPC_ERROR_NONE);
1295
1306
  }
1296
1307
 
1297
- grpc_call_error queue_call_request(grpc_server* server, size_t cq_idx,
1298
- requested_call* rc) {
1299
- if (server->shutdown_flag.load(std::memory_order_acquire)) {
1300
- fail_call(server, cq_idx, rc,
1301
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
1302
- return GRPC_CALL_OK;
1308
+ void Server::CallData::StartNewRpc(grpc_call_element* elem) {
1309
+ auto* chand = static_cast<ChannelData*>(elem->channel_data);
1310
+ if (server_->shutdown_flag_.load(std::memory_order_acquire)) {
1311
+ state_.Store(CallState::ZOMBIED, MemoryOrder::RELAXED);
1312
+ KillZombie();
1313
+ return;
1303
1314
  }
1304
- RequestMatcherInterface* rm;
1305
- switch (rc->type) {
1306
- case RequestedCallType::BATCH_CALL:
1307
- rm = server->unregistered_request_matcher.get();
1315
+ // Find request matcher.
1316
+ matcher_ = server_->unregistered_request_matcher_.get();
1317
+ grpc_server_register_method_payload_handling payload_handling =
1318
+ GRPC_SRM_PAYLOAD_NONE;
1319
+ if (path_.has_value() && host_.has_value()) {
1320
+ ChannelRegisteredMethod* rm =
1321
+ chand->GetRegisteredMethod(*host_, *path_,
1322
+ (recv_initial_metadata_flags_ &
1323
+ GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST));
1324
+ if (rm != nullptr) {
1325
+ matcher_ = rm->server_registered_method->matcher.get();
1326
+ payload_handling = rm->server_registered_method->payload_handling;
1327
+ }
1328
+ }
1329
+ // Start recv_message op if needed.
1330
+ switch (payload_handling) {
1331
+ case GRPC_SRM_PAYLOAD_NONE:
1332
+ PublishNewRpc(elem, GRPC_ERROR_NONE);
1308
1333
  break;
1309
- case RequestedCallType::REGISTERED_CALL:
1310
- rm = rc->data.registered.method->matcher.get();
1334
+ case GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER: {
1335
+ grpc_op op;
1336
+ op.op = GRPC_OP_RECV_MESSAGE;
1337
+ op.flags = 0;
1338
+ op.reserved = nullptr;
1339
+ op.data.recv_message.recv_message = &payload_;
1340
+ GRPC_CLOSURE_INIT(&publish_, PublishNewRpc, elem,
1341
+ grpc_schedule_on_exec_ctx);
1342
+ grpc_call_start_batch_and_execute(call_, &op, 1, &publish_);
1311
1343
  break;
1344
+ }
1312
1345
  }
1313
- rm->RequestCallWithPossiblePublish(cq_idx, rc);
1314
- return GRPC_CALL_OK;
1315
1346
  }
1316
1347
 
1317
- void fail_call(grpc_server* server, size_t cq_idx, requested_call* rc,
1318
- grpc_error* error) {
1319
- *rc->call = nullptr;
1320
- rc->initial_metadata->count = 0;
1321
- GPR_ASSERT(error != GRPC_ERROR_NONE);
1348
+ void Server::CallData::RecvInitialMetadataBatchComplete(void* arg,
1349
+ grpc_error* error) {
1350
+ grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
1351
+ auto* calld = static_cast<Server::CallData*>(elem->call_data);
1352
+ if (error != GRPC_ERROR_NONE) {
1353
+ calld->FailCallCreation();
1354
+ return;
1355
+ }
1356
+ calld->StartNewRpc(elem);
1357
+ }
1322
1358
 
1323
- grpc_cq_end_op(server->cqs[cq_idx], rc->tag, error, done_request_event, rc,
1324
- &rc->completion);
1359
+ void Server::CallData::StartTransportStreamOpBatchImpl(
1360
+ grpc_call_element* elem, grpc_transport_stream_op_batch* batch) {
1361
+ if (batch->recv_initial_metadata) {
1362
+ GPR_ASSERT(batch->payload->recv_initial_metadata.recv_flags == nullptr);
1363
+ recv_initial_metadata_ =
1364
+ batch->payload->recv_initial_metadata.recv_initial_metadata;
1365
+ original_recv_initial_metadata_ready_ =
1366
+ batch->payload->recv_initial_metadata.recv_initial_metadata_ready;
1367
+ batch->payload->recv_initial_metadata.recv_initial_metadata_ready =
1368
+ &recv_initial_metadata_ready_;
1369
+ batch->payload->recv_initial_metadata.recv_flags =
1370
+ &recv_initial_metadata_flags_;
1371
+ }
1372
+ if (batch->recv_trailing_metadata) {
1373
+ original_recv_trailing_metadata_ready_ =
1374
+ batch->payload->recv_trailing_metadata.recv_trailing_metadata_ready;
1375
+ batch->payload->recv_trailing_metadata.recv_trailing_metadata_ready =
1376
+ &recv_trailing_metadata_ready_;
1377
+ }
1378
+ grpc_call_next_op(elem, batch);
1325
1379
  }
1326
1380
 
1327
- } // namespace
1381
+ void Server::CallData::RecvInitialMetadataReady(void* arg, grpc_error* error) {
1382
+ grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
1383
+ CallData* calld = static_cast<CallData*>(elem->call_data);
1384
+ grpc_millis op_deadline;
1385
+ if (error == GRPC_ERROR_NONE) {
1386
+ GPR_DEBUG_ASSERT(calld->recv_initial_metadata_->idx.named.path != nullptr);
1387
+ GPR_DEBUG_ASSERT(calld->recv_initial_metadata_->idx.named.authority !=
1388
+ nullptr);
1389
+ calld->path_.emplace(grpc_slice_ref_internal(
1390
+ GRPC_MDVALUE(calld->recv_initial_metadata_->idx.named.path->md)));
1391
+ calld->host_.emplace(grpc_slice_ref_internal(
1392
+ GRPC_MDVALUE(calld->recv_initial_metadata_->idx.named.authority->md)));
1393
+ grpc_metadata_batch_remove(calld->recv_initial_metadata_, GRPC_BATCH_PATH);
1394
+ grpc_metadata_batch_remove(calld->recv_initial_metadata_,
1395
+ GRPC_BATCH_AUTHORITY);
1396
+ } else {
1397
+ GRPC_ERROR_REF(error);
1398
+ }
1399
+ op_deadline = calld->recv_initial_metadata_->deadline;
1400
+ if (op_deadline != GRPC_MILLIS_INF_FUTURE) {
1401
+ calld->deadline_ = op_deadline;
1402
+ }
1403
+ if (calld->host_.has_value() && calld->path_.has_value()) {
1404
+ /* do nothing */
1405
+ } else {
1406
+ /* Pass the error reference to calld->recv_initial_metadata_error */
1407
+ grpc_error* src_error = error;
1408
+ error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
1409
+ "Missing :authority or :path", &src_error, 1);
1410
+ GRPC_ERROR_UNREF(src_error);
1411
+ calld->recv_initial_metadata_error_ = GRPC_ERROR_REF(error);
1412
+ }
1413
+ grpc_closure* closure = calld->original_recv_initial_metadata_ready_;
1414
+ calld->original_recv_initial_metadata_ready_ = nullptr;
1415
+ if (calld->seen_recv_trailing_metadata_ready_) {
1416
+ GRPC_CALL_COMBINER_START(calld->call_combiner_,
1417
+ &calld->recv_trailing_metadata_ready_,
1418
+ calld->recv_trailing_metadata_error_,
1419
+ "continue server recv_trailing_metadata_ready");
1420
+ }
1421
+ Closure::Run(DEBUG_LOCATION, closure, error);
1422
+ }
1328
1423
 
1329
- void SetServerRegisteredMethodAllocator(
1330
- grpc_server* server, grpc_completion_queue* cq, void* method_tag,
1331
- std::function<ServerRegisteredCallAllocation()> allocator) {
1332
- registered_method* rm = static_cast<registered_method*>(method_tag);
1333
- rm->matcher = absl::make_unique<AllocatingRequestMatcherRegistered>(
1334
- server, cq, rm, std::move(allocator));
1424
+ void Server::CallData::RecvTrailingMetadataReady(void* arg, grpc_error* error) {
1425
+ grpc_call_element* elem = static_cast<grpc_call_element*>(arg);
1426
+ CallData* calld = static_cast<CallData*>(elem->call_data);
1427
+ if (calld->original_recv_initial_metadata_ready_ != nullptr) {
1428
+ calld->recv_trailing_metadata_error_ = GRPC_ERROR_REF(error);
1429
+ calld->seen_recv_trailing_metadata_ready_ = true;
1430
+ GRPC_CLOSURE_INIT(&calld->recv_trailing_metadata_ready_,
1431
+ RecvTrailingMetadataReady, elem,
1432
+ grpc_schedule_on_exec_ctx);
1433
+ GRPC_CALL_COMBINER_STOP(calld->call_combiner_,
1434
+ "deferring server recv_trailing_metadata_ready "
1435
+ "until after recv_initial_metadata_ready");
1436
+ return;
1437
+ }
1438
+ error =
1439
+ grpc_error_add_child(GRPC_ERROR_REF(error),
1440
+ GRPC_ERROR_REF(calld->recv_initial_metadata_error_));
1441
+ Closure::Run(DEBUG_LOCATION, calld->original_recv_trailing_metadata_ready_,
1442
+ error);
1335
1443
  }
1336
1444
 
1337
- void SetServerBatchMethodAllocator(
1338
- grpc_server* server, grpc_completion_queue* cq,
1339
- std::function<ServerBatchCallAllocation()> allocator) {
1340
- GPR_DEBUG_ASSERT(server->unregistered_request_matcher == nullptr);
1341
- server->unregistered_request_matcher =
1342
- absl::make_unique<AllocatingRequestMatcherBatch>(server, cq,
1343
- std::move(allocator));
1445
+ grpc_error* Server::CallData::InitCallElement(
1446
+ grpc_call_element* elem, const grpc_call_element_args* args) {
1447
+ auto* chand = static_cast<ChannelData*>(elem->channel_data);
1448
+ new (elem->call_data) Server::CallData(elem, *args, chand->server());
1449
+ return GRPC_ERROR_NONE;
1450
+ }
1451
+
1452
+ void Server::CallData::DestroyCallElement(
1453
+ grpc_call_element* elem, const grpc_call_final_info* /*final_info*/,
1454
+ grpc_closure* /*ignored*/) {
1455
+ auto* calld = static_cast<CallData*>(elem->call_data);
1456
+ calld->~CallData();
1457
+ }
1458
+
1459
+ void Server::CallData::StartTransportStreamOpBatch(
1460
+ grpc_call_element* elem, grpc_transport_stream_op_batch* batch) {
1461
+ auto* calld = static_cast<CallData*>(elem->call_data);
1462
+ calld->StartTransportStreamOpBatchImpl(elem, batch);
1344
1463
  }
1345
1464
 
1346
1465
  } // namespace grpc_core
1347
1466
 
1348
- const grpc_channel_filter grpc_server_top_filter = {
1349
- grpc_core::server_start_transport_stream_op_batch,
1350
- grpc_channel_next_op,
1351
- sizeof(grpc_core::call_data),
1352
- grpc_core::server_init_call_elem,
1353
- grpc_call_stack_ignore_set_pollset_or_pollset_set,
1354
- grpc_core::server_destroy_call_elem,
1355
- sizeof(grpc_core::channel_data),
1356
- grpc_core::server_init_channel_elem,
1357
- grpc_core::server_destroy_channel_elem,
1358
- grpc_channel_next_get_info,
1359
- "server",
1360
- };
1467
+ //
1468
+ // C-core API
1469
+ //
1361
1470
 
1362
- // The following are core surface API functions.
1471
+ grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) {
1472
+ grpc_core::ExecCtx exec_ctx;
1473
+ GRPC_API_TRACE("grpc_server_create(%p, %p)", 2, (args, reserved));
1474
+ grpc_server* c_server = new grpc_server;
1475
+ c_server->core_server = grpc_core::MakeOrphanable<grpc_core::Server>(args);
1476
+ return c_server;
1477
+ }
1363
1478
 
1364
1479
  void grpc_server_register_completion_queue(grpc_server* server,
1365
1480
  grpc_completion_queue* cq,
@@ -1367,7 +1482,7 @@ void grpc_server_register_completion_queue(grpc_server* server,
1367
1482
  GRPC_API_TRACE(
1368
1483
  "grpc_server_register_completion_queue(server=%p, cq=%p, reserved=%p)", 3,
1369
1484
  (server, cq, reserved));
1370
-
1485
+ GPR_ASSERT(!reserved);
1371
1486
  auto cq_type = grpc_get_cq_completion_type(cq);
1372
1487
  if (cq_type != GRPC_CQ_NEXT && cq_type != GRPC_CQ_CALLBACK) {
1373
1488
  gpr_log(GPR_INFO,
@@ -1377,15 +1492,7 @@ void grpc_server_register_completion_queue(grpc_server* server,
1377
1492
  /* Ideally we should log an error and abort but ruby-wrapped-language API
1378
1493
  calls grpc_completion_queue_pluck() on server completion queues */
1379
1494
  }
1380
-
1381
- grpc_core::register_completion_queue(server, cq, reserved);
1382
- }
1383
-
1384
- grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) {
1385
- grpc_core::ExecCtx exec_ctx;
1386
- GRPC_API_TRACE("grpc_server_create(%p, %p)", 2, (args, reserved));
1387
-
1388
- return new grpc_server(args);
1495
+ server->core_server->RegisterCompletionQueue(cq);
1389
1496
  }
1390
1497
 
1391
1498
  void* grpc_server_register_method(
@@ -1396,285 +1503,42 @@ void* grpc_server_register_method(
1396
1503
  "grpc_server_register_method(server=%p, method=%s, host=%s, "
1397
1504
  "flags=0x%08x)",
1398
1505
  4, (server, method, host, flags));
1399
- if (!method) {
1400
- gpr_log(GPR_ERROR,
1401
- "grpc_server_register_method method string cannot be NULL");
1402
- return nullptr;
1403
- }
1404
- for (std::unique_ptr<grpc_core::registered_method>& m :
1405
- server->registered_methods) {
1406
- if (grpc_core::streq(m->method, method) &&
1407
- grpc_core::streq(m->host, host)) {
1408
- gpr_log(GPR_ERROR, "duplicate registration for %s@%s", method,
1409
- host ? host : "*");
1410
- return nullptr;
1411
- }
1412
- }
1413
- if ((flags & ~GRPC_INITIAL_METADATA_USED_MASK) != 0) {
1414
- gpr_log(GPR_ERROR, "grpc_server_register_method invalid flags 0x%08x",
1415
- flags);
1416
- return nullptr;
1417
- }
1418
- server->registered_methods.emplace_back(
1419
- new grpc_core::registered_method(method, host, payload_handling, flags));
1420
- return static_cast<void*>(server->registered_methods.back().get());
1506
+ return server->core_server->RegisterMethod(method, host, payload_handling,
1507
+ flags);
1421
1508
  }
1422
1509
 
1423
1510
  void grpc_server_start(grpc_server* server) {
1424
- size_t i;
1425
1511
  grpc_core::ExecCtx exec_ctx;
1426
-
1427
1512
  GRPC_API_TRACE("grpc_server_start(server=%p)", 1, (server));
1428
-
1429
- server->started = true;
1430
- for (i = 0; i < server->cqs.size(); i++) {
1431
- if (grpc_cq_can_listen(server->cqs[i])) {
1432
- server->pollsets.push_back(grpc_cq_pollset(server->cqs[i]));
1433
- }
1434
- }
1435
- if (server->unregistered_request_matcher == nullptr) {
1436
- server->unregistered_request_matcher =
1437
- absl::make_unique<grpc_core::RealRequestMatcher>(server);
1438
- }
1439
- for (std::unique_ptr<grpc_core::registered_method>& rm :
1440
- server->registered_methods) {
1441
- if (rm->matcher == nullptr) {
1442
- rm->matcher = absl::make_unique<grpc_core::RealRequestMatcher>(server);
1443
- }
1444
- }
1445
-
1446
- {
1447
- grpc_core::MutexLock lock(&server->mu_global);
1448
- server->starting = true;
1449
- }
1450
-
1451
- for (auto& listener : server->listeners) {
1452
- listener.listener->Start(server, &server->pollsets);
1453
- }
1454
-
1455
- grpc_core::MutexLock lock(&server->mu_global);
1456
- server->starting = false;
1457
- server->starting_cv.Signal();
1513
+ server->core_server->Start();
1458
1514
  }
1459
1515
 
1460
- /*
1461
- - Kills all pending requests-for-incoming-RPC-calls (i.e the requests made via
1462
- grpc_server_request_call and grpc_server_request_registered call will now be
1463
- cancelled). See 'kill_pending_work_locked()'
1464
-
1465
- - Shuts down the listeners (i.e the server will no longer listen on the port
1466
- for new incoming channels).
1467
-
1468
- - Iterates through all channels on the server and sends shutdown msg (see
1469
- 'ChannelBroadcaster::BroadcastShutdown' for details) to the clients via the
1470
- transport layer. The transport layer then guarantees the following:
1471
- -- Sends shutdown to the client (for eg: HTTP2 transport sends GOAWAY)
1472
- -- If the server has outstanding calls that are in the process, the
1473
- connection is NOT closed until the server is done with all those calls
1474
- -- Once, there are no more calls in progress, the channel is closed
1475
- */
1476
1516
  void grpc_server_shutdown_and_notify(grpc_server* server,
1477
1517
  grpc_completion_queue* cq, void* tag) {
1478
- grpc_core::ChannelBroadcaster broadcaster;
1479
1518
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1480
1519
  grpc_core::ExecCtx exec_ctx;
1481
-
1482
1520
  GRPC_API_TRACE("grpc_server_shutdown_and_notify(server=%p, cq=%p, tag=%p)", 3,
1483
1521
  (server, cq, tag));
1484
-
1485
- {
1486
- /* wait for startup to be finished: locks mu_global */
1487
- grpc_core::MutexLock lock(&server->mu_global);
1488
- server->starting_cv.WaitUntil(&server->mu_global,
1489
- [server] { return !server->starting; });
1490
-
1491
- /* stay locked, and gather up some stuff to do */
1492
- GPR_ASSERT(grpc_cq_begin_op(cq, tag));
1493
- if (server->shutdown_published) {
1494
- grpc_cq_end_op(cq, tag, GRPC_ERROR_NONE,
1495
- grpc_core::done_published_shutdown, nullptr,
1496
- new grpc_cq_completion);
1497
- return;
1498
- }
1499
- server->shutdown_tags.emplace_back(tag, cq);
1500
- if (server->shutdown_flag.load(std::memory_order_acquire)) {
1501
- return;
1502
- }
1503
-
1504
- server->last_shutdown_message_time = gpr_now(GPR_CLOCK_REALTIME);
1505
-
1506
- broadcaster.FillChannelsLocked(server);
1507
-
1508
- server->shutdown_flag.store(true, std::memory_order_release);
1509
-
1510
- /* collect all unregistered then registered calls */
1511
- {
1512
- grpc_core::MutexLock lock(&server->mu_call);
1513
- grpc_core::kill_pending_work_locked(
1514
- server, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown"));
1515
- }
1516
-
1517
- grpc_core::maybe_finish_shutdown(server);
1518
- }
1519
-
1520
- /* Shutdown listeners */
1521
- for (auto& listener : server->listeners) {
1522
- grpc_core::channelz::ListenSocketNode* channelz_listen_socket_node =
1523
- listener.listener->channelz_listen_socket_node();
1524
- if (server->channelz_server != nullptr &&
1525
- channelz_listen_socket_node != nullptr) {
1526
- server->channelz_server->RemoveChildListenSocket(
1527
- channelz_listen_socket_node->uuid());
1528
- }
1529
- GRPC_CLOSURE_INIT(&listener.destroy_done, grpc_core::listener_destroy_done,
1530
- server, grpc_schedule_on_exec_ctx);
1531
- listener.listener->SetOnDestroyDone(&listener.destroy_done);
1532
- listener.listener.reset();
1533
- }
1534
-
1535
- broadcaster.BroadcastShutdown(/*send_goaway=*/true, GRPC_ERROR_NONE);
1522
+ server->core_server->ShutdownAndNotify(cq, tag);
1536
1523
  }
1537
1524
 
1538
1525
  void grpc_server_cancel_all_calls(grpc_server* server) {
1539
- grpc_core::ChannelBroadcaster broadcaster;
1540
1526
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1541
1527
  grpc_core::ExecCtx exec_ctx;
1542
-
1543
1528
  GRPC_API_TRACE("grpc_server_cancel_all_calls(server=%p)", 1, (server));
1544
-
1545
- {
1546
- grpc_core::MutexLock lock(&server->mu_global);
1547
- broadcaster.FillChannelsLocked(server);
1548
- }
1549
-
1550
- broadcaster.BroadcastShutdown(
1551
- /*send_goaway=*/false,
1552
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Cancelling all calls"));
1529
+ server->core_server->CancelAllCalls();
1553
1530
  }
1554
1531
 
1555
1532
  void grpc_server_destroy(grpc_server* server) {
1556
1533
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1557
1534
  grpc_core::ExecCtx exec_ctx;
1558
-
1559
1535
  GRPC_API_TRACE("grpc_server_destroy(server=%p)", 1, (server));
1560
-
1561
- {
1562
- grpc_core::MutexLock lock(&server->mu_global);
1563
- GPR_ASSERT(server->shutdown_flag.load(std::memory_order_acquire) ||
1564
- server->listeners.empty());
1565
- GPR_ASSERT(server->listeners_destroyed == server->listeners.size());
1566
- }
1567
-
1568
- if (server->default_resource_user != nullptr) {
1569
- grpc_resource_quota_unref(
1570
- grpc_resource_user_quota(server->default_resource_user));
1571
- grpc_resource_user_shutdown(server->default_resource_user);
1572
- grpc_resource_user_unref(server->default_resource_user);
1573
- }
1574
- grpc_core::server_unref(server);
1575
- }
1576
-
1577
- const std::vector<grpc_pollset*>& grpc_server_get_pollsets(
1578
- grpc_server* server) {
1579
- return server->pollsets;
1580
- }
1581
-
1582
- void grpc_server_setup_transport(
1583
- grpc_server* s, grpc_transport* transport, grpc_pollset* accepting_pollset,
1584
- const grpc_channel_args* args,
1585
- const grpc_core::RefCountedPtr<grpc_core::channelz::SocketNode>&
1586
- socket_node,
1587
- grpc_resource_user* resource_user) {
1588
- size_t num_registered_methods;
1589
- grpc_core::channel_registered_method* crm;
1590
- grpc_channel* channel;
1591
- grpc_core::channel_data* chand;
1592
- uint32_t hash;
1593
- size_t slots;
1594
- uint32_t probes;
1595
- uint32_t max_probes = 0;
1596
- grpc_transport_op* op = nullptr;
1597
-
1598
- channel = grpc_channel_create(nullptr, args, GRPC_SERVER_CHANNEL, transport,
1599
- resource_user);
1600
- chand = static_cast<grpc_core::channel_data*>(
1601
- grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0)
1602
- ->channel_data);
1603
- chand->server = s;
1604
- grpc_core::server_ref(s);
1605
- chand->channel = channel;
1606
- if (socket_node != nullptr) {
1607
- chand->channelz_socket_uuid = socket_node->uuid();
1608
- s->channelz_server->AddChildSocket(socket_node);
1609
- } else {
1610
- chand->channelz_socket_uuid = 0;
1611
- }
1612
-
1613
- size_t cq_idx;
1614
- for (cq_idx = 0; cq_idx < s->cqs.size(); cq_idx++) {
1615
- if (grpc_cq_pollset(s->cqs[cq_idx]) == accepting_pollset) break;
1616
- }
1617
- if (cq_idx == s->cqs.size()) {
1618
- /* completion queue not found: pick a random one to publish new calls to */
1619
- cq_idx = static_cast<size_t>(rand()) % s->cqs.size();
1620
- }
1621
- chand->cq_idx = cq_idx;
1622
-
1623
- num_registered_methods = s->registered_methods.size();
1624
- /* build a lookup table phrased in terms of mdstr's in this channels context
1625
- to quickly find registered methods */
1626
- if (num_registered_methods > 0) {
1627
- slots = 2 * num_registered_methods;
1628
- chand->registered_methods.reset(
1629
- new std::vector<grpc_core::channel_registered_method>(slots));
1630
- for (std::unique_ptr<grpc_core::registered_method>& rm :
1631
- s->registered_methods) {
1632
- grpc_core::ExternallyManagedSlice host;
1633
- grpc_core::ExternallyManagedSlice method(rm->method.c_str());
1634
- const bool has_host = !rm->host.empty();
1635
- if (has_host) {
1636
- host = grpc_core::ExternallyManagedSlice(rm->host.c_str());
1637
- }
1638
- hash = GRPC_MDSTR_KV_HASH(has_host ? host.Hash() : 0, method.Hash());
1639
- for (probes = 0; (*chand->registered_methods)[(hash + probes) % slots]
1640
- .server_registered_method != nullptr;
1641
- probes++) {
1642
- }
1643
- if (probes > max_probes) max_probes = probes;
1644
- crm = &(*chand->registered_methods)[(hash + probes) % slots];
1645
- crm->server_registered_method = rm.get();
1646
- crm->flags = rm->flags;
1647
- crm->has_host = has_host;
1648
- if (has_host) {
1649
- crm->host = host;
1650
- }
1651
- crm->method = method;
1652
- }
1653
- GPR_ASSERT(slots <= UINT32_MAX);
1654
- chand->registered_method_max_probes = max_probes;
1655
- }
1656
-
1657
- {
1658
- grpc_core::MutexLock lock(&s->mu_global);
1659
- s->channels.push_front(chand);
1660
- chand->list_position = s->channels.begin();
1661
- }
1662
-
1663
- op = grpc_make_transport_op(nullptr);
1664
- op->set_accept_stream = true;
1665
- op->set_accept_stream_fn = grpc_core::accept_stream;
1666
- op->set_accept_stream_user_data = chand;
1667
- op->start_connectivity_watch.reset(new grpc_core::ConnectivityWatcher(chand));
1668
- if (s->shutdown_flag.load(std::memory_order_acquire)) {
1669
- op->disconnect_with_error =
1670
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown");
1671
- }
1672
- grpc_transport_perform_op(transport, op);
1536
+ delete server;
1673
1537
  }
1674
1538
 
1675
1539
  grpc_call_error grpc_server_request_call(
1676
1540
  grpc_server* server, grpc_call** call, grpc_call_details* details,
1677
- grpc_metadata_array* initial_metadata,
1541
+ grpc_metadata_array* request_metadata,
1678
1542
  grpc_completion_queue* cq_bound_to_call,
1679
1543
  grpc_completion_queue* cq_for_notification, void* tag) {
1680
1544
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
@@ -1685,49 +1549,53 @@ grpc_call_error grpc_server_request_call(
1685
1549
  "server=%p, call=%p, details=%p, initial_metadata=%p, "
1686
1550
  "cq_bound_to_call=%p, cq_for_notification=%p, tag=%p)",
1687
1551
  7,
1688
- (server, call, details, initial_metadata, cq_bound_to_call,
1552
+ (server, call, details, request_metadata, cq_bound_to_call,
1689
1553
  cq_for_notification, tag));
1690
-
1691
- size_t cq_idx;
1692
- grpc_call_error error = grpc_core::ValidateServerRequestAndCq(
1693
- &cq_idx, server, cq_for_notification, tag, nullptr, nullptr);
1694
- if (error != GRPC_CALL_OK) {
1695
- return error;
1696
- }
1697
-
1698
- grpc_core::requested_call* rc = new grpc_core::requested_call(
1699
- tag, cq_bound_to_call, call, initial_metadata, details);
1700
- return queue_call_request(server, cq_idx, rc);
1554
+ return server->core_server->RequestCall(call, details, request_metadata,
1555
+ cq_bound_to_call, cq_for_notification,
1556
+ tag);
1701
1557
  }
1702
1558
 
1703
1559
  grpc_call_error grpc_server_request_registered_call(
1704
- grpc_server* server, void* rmp, grpc_call** call, gpr_timespec* deadline,
1705
- grpc_metadata_array* initial_metadata, grpc_byte_buffer** optional_payload,
1560
+ grpc_server* server, void* registered_method, grpc_call** call,
1561
+ gpr_timespec* deadline, grpc_metadata_array* request_metadata,
1562
+ grpc_byte_buffer** optional_payload,
1706
1563
  grpc_completion_queue* cq_bound_to_call,
1707
1564
  grpc_completion_queue* cq_for_notification, void* tag_new) {
1708
1565
  grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1709
1566
  grpc_core::ExecCtx exec_ctx;
1710
1567
  GRPC_STATS_INC_SERVER_REQUESTED_CALLS();
1711
- grpc_core::registered_method* rm =
1712
- static_cast<grpc_core::registered_method*>(rmp);
1568
+ auto* rm =
1569
+ static_cast<grpc_core::Server::RegisteredMethod*>(registered_method);
1713
1570
  GRPC_API_TRACE(
1714
1571
  "grpc_server_request_registered_call("
1715
- "server=%p, rmp=%p, call=%p, deadline=%p, initial_metadata=%p, "
1572
+ "server=%p, registered_method=%p, call=%p, deadline=%p, "
1573
+ "request_metadata=%p, "
1716
1574
  "optional_payload=%p, cq_bound_to_call=%p, cq_for_notification=%p, "
1717
1575
  "tag=%p)",
1718
1576
  9,
1719
- (server, rmp, call, deadline, initial_metadata, optional_payload,
1720
- cq_bound_to_call, cq_for_notification, tag_new));
1577
+ (server, registered_method, call, deadline, request_metadata,
1578
+ optional_payload, cq_bound_to_call, cq_for_notification, tag_new));
1579
+ return server->core_server->RequestRegisteredCall(
1580
+ rm, call, deadline, request_metadata, optional_payload, cq_bound_to_call,
1581
+ cq_for_notification, tag_new);
1582
+ }
1721
1583
 
1722
- size_t cq_idx;
1723
- grpc_call_error error = ValidateServerRequestAndCq(
1724
- &cq_idx, server, cq_for_notification, tag_new, optional_payload, rm);
1725
- if (error != GRPC_CALL_OK) {
1726
- return error;
1727
- }
1584
+ void grpc_server_set_config_fetcher(
1585
+ grpc_server* server, grpc_server_config_fetcher* server_config_fetcher) {
1586
+ grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1587
+ grpc_core::ExecCtx exec_ctx;
1588
+ GRPC_API_TRACE("grpc_server_set_config_fetcher(server=%p, config_fetcher=%p)",
1589
+ 2, (server, server_config_fetcher));
1590
+ server->core_server->set_config_fetcher(
1591
+ std::unique_ptr<grpc_server_config_fetcher>(server_config_fetcher));
1592
+ }
1728
1593
 
1729
- grpc_core::requested_call* rc = new grpc_core::requested_call(
1730
- tag_new, cq_bound_to_call, call, initial_metadata, rm, deadline,
1731
- optional_payload);
1732
- return queue_call_request(server, cq_idx, rc);
1594
+ void grpc_server_config_fetcher_destroy(
1595
+ grpc_server_config_fetcher* server_config_fetcher) {
1596
+ grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
1597
+ grpc_core::ExecCtx exec_ctx;
1598
+ GRPC_API_TRACE("grpc_server_config_fetcher_destroy(config_fetcher=%p)", 1,
1599
+ (server_config_fetcher));
1600
+ delete server_config_fetcher;
1733
1601
  }