grpc 1.18.0 → 1.22.0

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 (428) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +4731 -7404
  3. data/etc/roots.pem +146 -0
  4. data/include/grpc/grpc.h +11 -6
  5. data/include/grpc/grpc_security.h +297 -4
  6. data/include/grpc/grpc_security_constants.h +1 -1
  7. data/include/grpc/impl/codegen/byte_buffer.h +13 -0
  8. data/include/grpc/impl/codegen/gpr_types.h +1 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +30 -7
  10. data/include/grpc/impl/codegen/port_platform.h +88 -7
  11. data/include/grpc/impl/codegen/slice.h +2 -22
  12. data/include/grpc/impl/codegen/status.h +2 -1
  13. data/include/grpc/impl/codegen/sync_posix.h +18 -0
  14. data/include/grpc/slice.h +3 -3
  15. data/src/core/ext/filters/client_channel/backup_poller.cc +21 -16
  16. data/src/core/ext/filters/client_channel/backup_poller.h +8 -2
  17. data/src/core/ext/filters/client_channel/channel_connectivity.cc +3 -1
  18. data/src/core/ext/filters/client_channel/client_channel.cc +2435 -1557
  19. data/src/core/ext/filters/client_channel/client_channel.h +2 -10
  20. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +6 -89
  21. data/src/core/ext/filters/client_channel/client_channel_channelz.h +8 -33
  22. data/src/core/ext/filters/client_channel/client_channel_factory.cc +22 -34
  23. data/src/core/ext/filters/client_channel/client_channel_factory.h +19 -38
  24. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +9 -11
  25. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +179 -0
  26. data/src/core/ext/filters/client_channel/global_subchannel_pool.h +68 -0
  27. data/src/core/ext/filters/client_channel/health/health_check_client.cc +59 -55
  28. data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
  29. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +146 -157
  30. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
  31. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +29 -32
  32. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +844 -859
  33. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +3 -1
  34. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +2 -6
  35. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
  36. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +14 -12
  37. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +16 -12
  38. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +3 -3
  39. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +185 -312
  40. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +143 -375
  41. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +192 -245
  42. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +1554 -955
  43. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +0 -43
  44. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +14 -10
  45. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +2 -2
  46. data/src/core/ext/filters/client_channel/lb_policy.cc +115 -22
  47. data/src/core/ext/filters/client_channel/lb_policy.h +260 -129
  48. data/src/core/ext/filters/client_channel/lb_policy_factory.h +5 -2
  49. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +107 -4
  50. data/src/core/ext/filters/client_channel/lb_policy_registry.h +10 -3
  51. data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +96 -0
  52. data/src/core/ext/filters/client_channel/local_subchannel_pool.h +56 -0
  53. data/src/core/ext/filters/client_channel/parse_address.cc +24 -5
  54. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +121 -122
  55. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
  56. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
  57. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +24 -10
  59. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +111 -47
  60. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
  61. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
  62. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
  63. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
  64. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
  65. data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
  66. data/src/core/{lib/iomgr/network_status_tracker.cc → ext/filters/client_channel/resolver/dns/dns_resolver_selection.h} +8 -15
  67. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +36 -82
  68. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +111 -72
  69. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +13 -8
  70. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +28 -63
  71. data/src/core/ext/filters/client_channel/resolver.cc +54 -1
  72. data/src/core/ext/filters/client_channel/resolver.h +52 -23
  73. data/src/core/ext/filters/client_channel/resolver_factory.h +3 -1
  74. data/src/core/ext/filters/client_channel/resolver_registry.cc +5 -2
  75. data/src/core/ext/filters/client_channel/resolver_registry.h +5 -4
  76. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +368 -241
  77. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +58 -76
  78. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +543 -0
  79. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +139 -0
  80. data/src/core/ext/filters/client_channel/server_address.cc +4 -54
  81. data/src/core/ext/filters/client_channel/server_address.h +1 -13
  82. data/src/core/ext/filters/client_channel/service_config.cc +329 -0
  83. data/src/core/ext/filters/client_channel/service_config.h +205 -0
  84. data/src/core/ext/filters/client_channel/subchannel.cc +803 -838
  85. data/src/core/ext/filters/client_channel/subchannel.h +295 -128
  86. data/src/core/ext/filters/client_channel/subchannel_interface.h +113 -0
  87. data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +97 -0
  88. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +94 -0
  89. data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
  90. data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
  91. data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
  92. data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
  93. data/src/core/ext/filters/http/client_authority_filter.cc +6 -3
  94. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
  95. data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
  96. data/src/core/ext/filters/max_age/max_age_filter.cc +5 -2
  97. data/src/core/ext/filters/message_size/message_size_filter.cc +119 -77
  98. data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
  99. data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
  100. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +13 -12
  101. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +45 -47
  102. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +134 -143
  103. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +68 -21
  104. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +4 -4
  105. data/src/core/ext/transport/chttp2/transport/bin_decoder.h +4 -4
  106. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +7 -6
  107. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +4 -3
  108. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
  109. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +156 -94
  110. data/src/core/ext/transport/chttp2/transport/flow_control.cc +2 -2
  111. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
  112. data/src/core/ext/transport/chttp2/transport/frame_data.cc +33 -37
  113. data/src/core/ext/transport/chttp2/transport/frame_data.h +1 -1
  114. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +6 -5
  115. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +3 -2
  116. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +5 -4
  117. data/src/core/ext/transport/chttp2/transport/frame_ping.h +1 -1
  118. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +8 -6
  119. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -1
  120. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +6 -4
  121. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -1
  122. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +7 -6
  123. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +1 -1
  124. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +74 -55
  125. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +33 -11
  126. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +3 -2
  127. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +7 -14
  128. data/src/core/ext/transport/chttp2/transport/hpack_table.h +10 -1
  129. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +9 -5
  130. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +9 -3
  131. data/src/core/ext/transport/chttp2/transport/internal.h +43 -30
  132. data/src/core/ext/transport/chttp2/transport/parsing.cc +52 -70
  133. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
  134. data/src/core/ext/transport/chttp2/transport/writing.cc +70 -33
  135. data/src/core/ext/transport/inproc/inproc_transport.cc +26 -18
  136. data/src/core/lib/channel/channel_args.cc +2 -101
  137. data/src/core/lib/channel/channel_args.h +3 -37
  138. data/src/core/lib/channel/channel_stack.h +10 -6
  139. data/src/core/lib/channel/channel_trace.cc +4 -4
  140. data/src/core/lib/channel/channel_trace.h +4 -4
  141. data/src/core/lib/channel/channelz.cc +168 -38
  142. data/src/core/lib/channel/channelz.h +40 -44
  143. data/src/core/lib/channel/channelz_registry.cc +75 -107
  144. data/src/core/lib/channel/channelz_registry.h +10 -28
  145. data/src/core/lib/channel/connected_channel.cc +2 -2
  146. data/src/core/lib/channel/context.h +2 -2
  147. data/src/core/lib/channel/handshaker.cc +151 -218
  148. data/src/core/lib/channel/handshaker.h +110 -101
  149. data/src/core/lib/channel/handshaker_factory.h +11 -19
  150. data/src/core/lib/channel/handshaker_registry.cc +67 -51
  151. data/src/core/lib/channel/handshaker_registry.h +21 -16
  152. data/src/core/lib/compression/algorithm_metadata.h +3 -3
  153. data/src/core/lib/compression/compression.cc +14 -9
  154. data/src/core/lib/compression/compression_args.cc +127 -0
  155. data/src/core/lib/compression/compression_args.h +55 -0
  156. data/src/core/lib/compression/compression_internal.cc +16 -12
  157. data/src/core/lib/compression/compression_internal.h +1 -1
  158. data/src/core/lib/compression/stream_compression.cc +3 -2
  159. data/src/core/lib/compression/stream_compression.h +2 -2
  160. data/src/core/lib/compression/stream_compression_gzip.cc +9 -9
  161. data/src/core/lib/debug/trace.cc +13 -7
  162. data/src/core/lib/debug/trace.h +14 -1
  163. data/src/core/lib/gpr/arena.h +13 -9
  164. data/src/core/lib/gpr/cpu_posix.cc +5 -3
  165. data/src/core/lib/gpr/env.h +3 -6
  166. data/src/core/lib/gpr/env_linux.cc +6 -1
  167. data/src/core/lib/gpr/env_posix.cc +5 -0
  168. data/src/core/lib/gpr/env_windows.cc +7 -5
  169. data/src/core/lib/gpr/log.cc +9 -13
  170. data/src/core/lib/gpr/log_posix.cc +2 -1
  171. data/src/core/lib/gpr/string.cc +20 -7
  172. data/src/core/lib/gpr/string.h +10 -3
  173. data/src/core/lib/gpr/sync_posix.cc +65 -4
  174. data/src/core/lib/gpr/time.cc +8 -0
  175. data/src/core/lib/gpr/time_posix.cc +21 -2
  176. data/src/core/lib/gprpp/arena.cc +103 -0
  177. data/src/core/lib/gprpp/arena.h +121 -0
  178. data/src/core/lib/gprpp/atomic.h +75 -5
  179. data/src/core/lib/gprpp/fork.cc +13 -32
  180. data/src/core/lib/gprpp/fork.h +5 -1
  181. data/src/core/lib/gprpp/global_config.h +96 -0
  182. data/src/core/lib/gprpp/global_config_custom.h +29 -0
  183. data/src/core/lib/gprpp/global_config_env.cc +135 -0
  184. data/src/core/lib/gprpp/global_config_env.h +131 -0
  185. data/src/core/lib/gprpp/global_config_generic.h +44 -0
  186. data/src/core/lib/gprpp/inlined_vector.h +8 -0
  187. data/src/core/lib/gprpp/map.h +436 -0
  188. data/src/core/lib/gprpp/memory.h +2 -2
  189. data/src/core/lib/gprpp/optional.h +48 -0
  190. data/src/core/lib/gprpp/orphanable.h +6 -5
  191. data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
  192. data/src/core/lib/gprpp/ref_counted.h +36 -17
  193. data/src/core/lib/gprpp/sync.h +126 -0
  194. data/src/core/lib/gprpp/thd.h +42 -7
  195. data/src/core/lib/gprpp/thd_posix.cc +31 -13
  196. data/src/core/lib/gprpp/thd_windows.cc +47 -34
  197. data/src/core/lib/http/httpcli.cc +6 -5
  198. data/src/core/lib/http/httpcli_security_connector.cc +13 -15
  199. data/src/core/lib/http/parser.cc +3 -2
  200. data/src/core/lib/http/parser.h +2 -1
  201. data/src/core/lib/iomgr/buffer_list.cc +182 -24
  202. data/src/core/lib/iomgr/buffer_list.h +72 -10
  203. data/src/core/lib/iomgr/call_combiner.cc +84 -90
  204. data/src/core/lib/iomgr/call_combiner.h +75 -82
  205. data/src/core/lib/iomgr/cfstream_handle.cc +203 -0
  206. data/src/core/lib/iomgr/cfstream_handle.h +86 -0
  207. data/src/core/lib/iomgr/combiner.cc +11 -3
  208. data/src/core/lib/iomgr/combiner.h +1 -1
  209. data/src/core/lib/iomgr/endpoint.cc +2 -2
  210. data/src/core/lib/iomgr/endpoint.h +3 -2
  211. data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
  212. data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
  213. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  214. data/src/core/lib/iomgr/error.cc +21 -17
  215. data/src/core/lib/iomgr/error.h +36 -6
  216. data/src/core/lib/iomgr/error_cfstream.cc +52 -0
  217. data/src/core/lib/iomgr/error_cfstream.h +31 -0
  218. data/src/core/lib/iomgr/error_internal.h +1 -1
  219. data/src/core/lib/iomgr/ev_epoll1_linux.cc +44 -28
  220. data/src/core/lib/iomgr/ev_epollex_linux.cc +173 -194
  221. data/src/core/lib/iomgr/ev_poll_posix.cc +16 -487
  222. data/src/core/lib/iomgr/ev_posix.cc +29 -19
  223. data/src/core/lib/iomgr/ev_posix.h +19 -3
  224. data/src/core/lib/iomgr/ev_windows.cc +2 -2
  225. data/src/core/lib/iomgr/exec_ctx.cc +1 -0
  226. data/src/core/lib/iomgr/exec_ctx.h +137 -8
  227. data/src/core/lib/iomgr/executor.cc +147 -95
  228. data/src/core/lib/iomgr/executor.h +55 -49
  229. data/src/core/lib/iomgr/fork_posix.cc +6 -5
  230. data/src/core/lib/{gprpp/atomic_with_std.h → iomgr/grpc_if_nametoindex.h} +8 -13
  231. data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +42 -0
  232. data/src/core/lib/iomgr/{network_status_tracker.h → grpc_if_nametoindex_unsupported.cc} +15 -9
  233. data/src/core/lib/iomgr/internal_errqueue.cc +3 -5
  234. data/src/core/lib/iomgr/internal_errqueue.h +105 -3
  235. data/src/core/lib/iomgr/iomgr.cc +20 -13
  236. data/src/core/lib/iomgr/iomgr.h +15 -0
  237. data/src/core/lib/iomgr/iomgr_custom.cc +17 -3
  238. data/src/core/lib/iomgr/iomgr_custom.h +2 -0
  239. data/src/core/lib/iomgr/iomgr_internal.cc +10 -0
  240. data/src/core/lib/iomgr/iomgr_internal.h +12 -0
  241. data/src/core/lib/iomgr/iomgr_posix.cc +19 -2
  242. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
  243. data/src/core/lib/iomgr/iomgr_windows.cc +18 -2
  244. data/src/core/lib/iomgr/lockfree_event.cc +4 -4
  245. data/src/core/lib/iomgr/port.h +35 -0
  246. data/src/core/lib/iomgr/resolve_address_posix.cc +4 -3
  247. data/src/core/lib/iomgr/resolve_address_windows.cc +2 -1
  248. data/src/core/lib/iomgr/resource_quota.cc +40 -37
  249. data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
  250. data/src/core/lib/iomgr/socket_windows.cc +19 -0
  251. data/src/core/lib/iomgr/socket_windows.h +8 -0
  252. data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
  253. data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
  254. data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
  255. data/src/core/lib/iomgr/tcp_client_windows.cc +7 -5
  256. data/src/core/lib/iomgr/tcp_custom.cc +10 -14
  257. data/src/core/lib/iomgr/tcp_posix.cc +256 -140
  258. data/src/core/lib/iomgr/tcp_server.cc +5 -0
  259. data/src/core/lib/iomgr/tcp_server.h +24 -0
  260. data/src/core/lib/iomgr/tcp_server_custom.cc +14 -12
  261. data/src/core/lib/iomgr/tcp_server_posix.cc +86 -12
  262. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
  263. data/src/core/lib/iomgr/tcp_server_windows.cc +13 -11
  264. data/src/core/lib/iomgr/tcp_uv.cc +5 -7
  265. data/src/core/lib/iomgr/tcp_windows.cc +8 -14
  266. data/src/core/lib/iomgr/timer.h +2 -1
  267. data/src/core/lib/iomgr/timer_generic.cc +16 -16
  268. data/src/core/lib/iomgr/timer_manager.cc +20 -11
  269. data/src/core/lib/iomgr/udp_server.cc +8 -6
  270. data/src/core/lib/iomgr/wakeup_fd_posix.cc +1 -19
  271. data/src/core/lib/json/json.cc +1 -4
  272. data/src/core/lib/profiling/basic_timers.cc +10 -4
  273. data/src/core/lib/security/context/security_context.cc +6 -7
  274. data/src/core/lib/security/context/security_context.h +3 -4
  275. data/src/core/lib/security/credentials/alts/alts_credentials.cc +1 -1
  276. data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +2 -2
  277. data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -0
  278. data/src/core/lib/security/credentials/credentials.h +9 -1
  279. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -3
  280. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +2 -0
  281. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  282. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +2 -1
  283. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +10 -6
  284. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  285. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +3 -3
  286. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +9 -8
  287. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -2
  288. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -2
  289. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +192 -0
  290. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +210 -0
  291. data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +129 -0
  292. data/src/core/lib/security/credentials/tls/spiffe_credentials.h +62 -0
  293. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +10 -8
  294. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +13 -12
  295. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
  296. data/src/core/lib/security/security_connector/local/local_security_connector.cc +10 -8
  297. data/src/core/lib/security/security_connector/security_connector.cc +0 -1
  298. data/src/core/lib/security/security_connector/security_connector.h +3 -3
  299. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +39 -38
  300. data/src/core/lib/security/security_connector/ssl_utils.cc +164 -26
  301. data/src/core/lib/security/security_connector/ssl_utils.h +70 -1
  302. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +426 -0
  303. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +122 -0
  304. data/src/core/lib/security/transport/auth_filters.h +5 -2
  305. data/src/core/lib/security/transport/client_auth_filter.cc +55 -50
  306. data/src/core/lib/security/transport/secure_endpoint.cc +6 -6
  307. data/src/core/lib/security/transport/security_handshaker.cc +271 -303
  308. data/src/core/lib/security/transport/security_handshaker.h +11 -2
  309. data/src/core/lib/security/transport/server_auth_filter.cc +3 -3
  310. data/src/core/lib/slice/b64.h +2 -2
  311. data/src/core/lib/slice/percent_encoding.cc +3 -3
  312. data/src/core/lib/slice/percent_encoding.h +3 -3
  313. data/src/core/lib/slice/slice.cc +174 -122
  314. data/src/core/lib/slice/slice_buffer.cc +54 -21
  315. data/src/core/lib/slice/slice_hash_table.h +4 -4
  316. data/src/core/lib/slice/slice_intern.cc +49 -107
  317. data/src/core/lib/slice/slice_internal.h +264 -3
  318. data/src/core/lib/slice/slice_string_helpers.cc +10 -1
  319. data/src/core/lib/slice/slice_string_helpers.h +3 -1
  320. data/src/core/lib/slice/slice_utils.h +50 -0
  321. data/src/core/lib/slice/slice_weak_hash_table.h +6 -6
  322. data/src/core/lib/surface/api_trace.h +1 -1
  323. data/src/core/lib/surface/byte_buffer_reader.cc +17 -0
  324. data/src/core/lib/surface/call.cc +67 -46
  325. data/src/core/lib/surface/call.h +7 -2
  326. data/src/core/lib/surface/call_details.cc +0 -1
  327. data/src/core/lib/surface/channel.cc +89 -97
  328. data/src/core/lib/surface/channel.h +60 -6
  329. data/src/core/lib/surface/channel_init.h +5 -0
  330. data/src/core/lib/surface/completion_queue.cc +221 -216
  331. data/src/core/lib/surface/completion_queue.h +2 -1
  332. data/src/core/lib/surface/init.cc +82 -33
  333. data/src/core/lib/surface/init.h +1 -0
  334. data/src/core/lib/surface/init_secure.cc +1 -1
  335. data/src/core/lib/surface/lame_client.cc +5 -7
  336. data/src/core/lib/surface/server.cc +42 -47
  337. data/src/core/lib/surface/validate_metadata.cc +14 -8
  338. data/src/core/lib/surface/validate_metadata.h +13 -2
  339. data/src/core/lib/surface/version.cc +1 -1
  340. data/src/core/lib/transport/bdp_estimator.cc +3 -3
  341. data/src/core/lib/transport/bdp_estimator.h +2 -2
  342. data/src/core/lib/transport/connectivity_state.cc +10 -40
  343. data/src/core/lib/transport/connectivity_state.h +0 -8
  344. data/src/core/lib/transport/error_utils.cc +12 -0
  345. data/src/core/lib/transport/metadata.cc +258 -267
  346. data/src/core/lib/transport/metadata.h +227 -16
  347. data/src/core/lib/transport/metadata_batch.cc +1 -1
  348. data/src/core/lib/transport/metadata_batch.h +1 -1
  349. data/src/core/lib/transport/static_metadata.cc +477 -399
  350. data/src/core/lib/transport/static_metadata.h +273 -182
  351. data/src/core/lib/transport/status_metadata.cc +3 -3
  352. data/src/core/lib/transport/timeout_encoding.cc +1 -1
  353. data/src/core/lib/transport/timeout_encoding.h +1 -1
  354. data/src/core/lib/transport/transport.cc +39 -72
  355. data/src/core/lib/transport/transport.h +59 -24
  356. data/src/core/lib/transport/transport_impl.h +1 -1
  357. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +3 -3
  358. data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +1 -1
  359. data/src/core/tsi/alts/handshaker/alts_shared_resource.h +1 -1
  360. data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +4 -3
  361. data/src/core/tsi/alts/handshaker/transport_security_common_api.h +1 -1
  362. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +1 -1
  363. data/src/core/tsi/fake_transport_security.cc +4 -4
  364. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
  365. data/src/core/tsi/ssl_transport_security.cc +12 -10
  366. data/src/core/tsi/ssl_transport_security.h +24 -4
  367. data/src/ruby/bin/math_pb.rb +18 -16
  368. data/src/ruby/ext/grpc/extconf.rb +12 -4
  369. data/src/ruby/ext/grpc/rb_call_credentials.c +8 -5
  370. data/src/ruby/ext/grpc/rb_channel.c +14 -10
  371. data/src/ruby/ext/grpc/rb_channel_credentials.c +8 -4
  372. data/src/ruby/ext/grpc/rb_compression_options.c +9 -7
  373. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  374. data/src/ruby/ext/grpc/rb_grpc.c +23 -24
  375. data/src/ruby/ext/grpc/rb_grpc.h +4 -2
  376. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +24 -0
  377. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +36 -0
  378. data/src/ruby/ext/grpc/rb_server.c +8 -4
  379. data/src/ruby/lib/grpc/errors.rb +22 -3
  380. data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
  381. data/src/ruby/lib/grpc/generic/rpc_server.rb +2 -2
  382. data/src/ruby/lib/grpc/version.rb +1 -1
  383. data/src/ruby/pb/README.md +1 -1
  384. data/src/ruby/pb/grpc/health/v1/health_pb.rb +13 -10
  385. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +18 -0
  386. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +3 -1
  387. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +58 -56
  388. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +2 -0
  389. data/src/ruby/spec/errors_spec.rb +141 -0
  390. data/third_party/cares/cares/ares.h +12 -0
  391. data/third_party/cares/cares/ares_create_query.c +5 -1
  392. data/third_party/cares/cares/ares_data.c +74 -73
  393. data/third_party/cares/cares/ares_destroy.c +6 -1
  394. data/third_party/cares/cares/ares_gethostbyaddr.c +5 -5
  395. data/third_party/cares/cares/ares_gethostbyname.c +15 -4
  396. data/third_party/cares/cares/ares_getnameinfo.c +11 -0
  397. data/third_party/cares/cares/ares_init.c +274 -173
  398. data/third_party/cares/cares/ares_library_init.c +21 -3
  399. data/third_party/cares/cares/ares_options.c +6 -2
  400. data/third_party/cares/cares/ares_parse_naptr_reply.c +7 -6
  401. data/third_party/cares/cares/ares_parse_ptr_reply.c +4 -2
  402. data/third_party/cares/cares/ares_platform.c +7 -0
  403. data/third_party/cares/cares/ares_private.h +19 -11
  404. data/third_party/cares/cares/ares_process.c +27 -2
  405. data/third_party/cares/cares/ares_rules.h +1 -1
  406. data/third_party/cares/cares/ares_search.c +7 -0
  407. data/third_party/cares/cares/ares_send.c +6 -0
  408. data/third_party/cares/cares/ares_strsplit.c +174 -0
  409. data/third_party/cares/cares/ares_strsplit.h +43 -0
  410. data/third_party/cares/cares/ares_version.h +4 -4
  411. data/third_party/cares/cares/config-win32.h +1 -1
  412. data/third_party/cares/cares/inet_ntop.c +2 -3
  413. data/third_party/cares/config_darwin/ares_config.h +3 -0
  414. data/third_party/cares/config_freebsd/ares_config.h +3 -0
  415. data/third_party/cares/config_linux/ares_config.h +3 -0
  416. data/third_party/cares/config_openbsd/ares_config.h +3 -0
  417. metadata +83 -48
  418. data/src/core/ext/filters/client_channel/request_routing.cc +0 -936
  419. data/src/core/ext/filters/client_channel/request_routing.h +0 -177
  420. data/src/core/ext/filters/client_channel/subchannel_index.cc +0 -248
  421. data/src/core/ext/filters/client_channel/subchannel_index.h +0 -76
  422. data/src/core/lib/channel/handshaker_factory.cc +0 -42
  423. data/src/core/lib/gpr/arena.cc +0 -192
  424. data/src/core/lib/gprpp/atomic_with_atm.h +0 -57
  425. data/src/core/lib/iomgr/wakeup_fd_cv.cc +0 -107
  426. data/src/core/lib/iomgr/wakeup_fd_cv.h +0 -69
  427. data/src/core/lib/transport/service_config.cc +0 -106
  428. data/src/core/lib/transport/service_config.h +0 -249
@@ -21,29 +21,226 @@
21
21
 
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
- #include "src/core/ext/filters/client_channel/client_channel_channelz.h"
25
- #include "src/core/ext/filters/client_channel/client_channel_factory.h"
26
- #include "src/core/ext/filters/client_channel/subchannel.h"
24
+ #include "src/core/ext/filters/client_channel/server_address.h"
25
+ #include "src/core/ext/filters/client_channel/service_config.h"
26
+ #include "src/core/ext/filters/client_channel/subchannel_interface.h"
27
27
  #include "src/core/lib/gprpp/abstract.h"
28
28
  #include "src/core/lib/gprpp/orphanable.h"
29
29
  #include "src/core/lib/gprpp/ref_counted_ptr.h"
30
30
  #include "src/core/lib/iomgr/combiner.h"
31
31
  #include "src/core/lib/iomgr/polling_entity.h"
32
32
  #include "src/core/lib/transport/connectivity_state.h"
33
-
34
- extern grpc_core::DebugOnlyTraceFlag grpc_trace_lb_policy_refcount;
33
+ #include "src/core/lib/transport/metadata_batch.h"
35
34
 
36
35
  namespace grpc_core {
37
36
 
37
+ extern DebugOnlyTraceFlag grpc_trace_lb_policy_refcount;
38
+
38
39
  /// Interface for load balancing policies.
39
40
  ///
41
+ /// The following concepts are used here:
42
+ ///
43
+ /// Channel: An abstraction that manages connections to backend servers
44
+ /// on behalf of a client application. The application creates a channel
45
+ /// for a given server name and then sends RPCs on it, and the channel
46
+ /// figures out which backend server to send each RPC to. A channel
47
+ /// contains a resolver, a load balancing policy (or a tree of LB policies),
48
+ /// and a set of one or more subchannels.
49
+ ///
50
+ /// Subchannel: A subchannel represents a connection to one backend server.
51
+ /// The LB policy decides which subchannels to create, manages the
52
+ /// connectivity state of those subchannels, and decides which subchannel
53
+ /// to send any given RPC to.
54
+ ///
55
+ /// Resolver: A plugin that takes a gRPC server URI and resolves it to a
56
+ /// list of one or more addresses and a service config, as described
57
+ /// in https://github.com/grpc/grpc/blob/master/doc/naming.md. See
58
+ /// resolver.h for the resolver API.
59
+ ///
60
+ /// Load Balancing (LB) Policy: A plugin that takes a list of addresses
61
+ /// from the resolver, maintains and manages a subchannel for each
62
+ /// backend address, and decides which subchannel to send each RPC on.
63
+ /// An LB policy has two parts:
64
+ /// - A LoadBalancingPolicy, which deals with the control plane work of
65
+ /// managing subchannels.
66
+ /// - A SubchannelPicker, which handles the data plane work of
67
+ /// determining which subchannel a given RPC should be sent on.
68
+
69
+ /// LoadBalacingPolicy API.
70
+ ///
40
71
  /// Note: All methods with a "Locked" suffix must be called from the
41
72
  /// combiner passed to the constructor.
42
73
  ///
43
74
  /// Any I/O done by the LB policy should be done under the pollset_set
44
75
  /// returned by \a interested_parties().
76
+ // TODO(roth): Once we move to EventManager-based polling, remove the
77
+ // interested_parties() hooks from the API.
45
78
  class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
46
79
  public:
80
+ /// Interface for accessing per-call state.
81
+ class CallState {
82
+ public:
83
+ CallState() = default;
84
+ virtual ~CallState() = default;
85
+
86
+ /// Allocates memory associated with the call, which will be
87
+ /// automatically freed when the call is complete.
88
+ /// It is more efficient to use this than to allocate memory directly
89
+ /// for allocations that need to be made on a per-call basis.
90
+ virtual void* Alloc(size_t size) GRPC_ABSTRACT;
91
+
92
+ GRPC_ABSTRACT_BASE_CLASS
93
+ };
94
+
95
+ /// Arguments used when picking a subchannel for an RPC.
96
+ struct PickArgs {
97
+ /// Initial metadata associated with the picking call.
98
+ /// The LB policy may use the existing metadata to influence its routing
99
+ /// decision, and it may add new metadata elements to be sent with the
100
+ /// call to the chosen backend.
101
+ // TODO(roth): Provide a more generic metadata API here.
102
+ grpc_metadata_batch* initial_metadata = nullptr;
103
+ /// An interface for accessing call state. Can be used to allocate
104
+ /// data associated with the call in an efficient way.
105
+ CallState* call_state;
106
+ };
107
+
108
+ /// The result of picking a subchannel for an RPC.
109
+ struct PickResult {
110
+ enum ResultType {
111
+ /// Pick complete. If connected_subchannel is non-null, client channel
112
+ /// can immediately proceed with the call on connected_subchannel;
113
+ /// otherwise, call should be dropped.
114
+ PICK_COMPLETE,
115
+ /// Pick cannot be completed until something changes on the control
116
+ /// plane. Client channel will queue the pick and try again the
117
+ /// next time the picker is updated.
118
+ PICK_QUEUE,
119
+ /// LB policy is in transient failure. If the pick is wait_for_ready,
120
+ /// client channel will wait for the next picker and try again;
121
+ /// otherwise, the call will be failed immediately (although it may
122
+ /// be retried if the client channel is configured to do so).
123
+ /// The Pick() method will set its error parameter if this value is
124
+ /// returned.
125
+ PICK_TRANSIENT_FAILURE,
126
+ };
127
+ ResultType type;
128
+
129
+ /// Used only if type is PICK_COMPLETE. Will be set to the selected
130
+ /// subchannel, or nullptr if the LB policy decides to drop the call.
131
+ RefCountedPtr<ConnectedSubchannelInterface> connected_subchannel;
132
+
133
+ /// Used only if type is PICK_TRANSIENT_FAILURE.
134
+ /// Error to be set when returning a transient failure.
135
+ // TODO(roth): Replace this with something similar to grpc::Status,
136
+ // so that we don't expose grpc_error to this API.
137
+ grpc_error* error = GRPC_ERROR_NONE;
138
+
139
+ /// Used only if type is PICK_COMPLETE.
140
+ /// Callback set by lb policy to be notified of trailing metadata.
141
+ /// The user_data argument will be set to the
142
+ /// recv_trailing_metadata_ready_user_data field.
143
+ /// recv_trailing_metadata will be set to the metadata, which may be
144
+ /// modified by the callback. The callback does not take ownership,
145
+ /// however, so any data that needs to be used after returning must
146
+ /// be copied.
147
+ void (*recv_trailing_metadata_ready)(
148
+ void* user_data, grpc_metadata_batch* recv_trailing_metadata,
149
+ CallState* call_state) = nullptr;
150
+ void* recv_trailing_metadata_ready_user_data = nullptr;
151
+ };
152
+
153
+ /// A subchannel picker is the object used to pick the subchannel to
154
+ /// use for a given RPC.
155
+ ///
156
+ /// Pickers are intended to encapsulate all of the state and logic
157
+ /// needed on the data plane (i.e., to actually process picks for
158
+ /// individual RPCs sent on the channel) while excluding all of the
159
+ /// state and logic needed on the control plane (i.e., resolver
160
+ /// updates, connectivity state notifications, etc); the latter should
161
+ /// live in the LB policy object itself.
162
+ ///
163
+ /// Currently, pickers are always accessed from within the
164
+ /// client_channel data plane combiner, so they do not have to be
165
+ /// thread-safe.
166
+ class SubchannelPicker {
167
+ public:
168
+ SubchannelPicker() = default;
169
+ virtual ~SubchannelPicker() = default;
170
+
171
+ virtual PickResult Pick(PickArgs args) GRPC_ABSTRACT;
172
+
173
+ GRPC_ABSTRACT_BASE_CLASS
174
+ };
175
+
176
+ /// A proxy object used by the LB policy to communicate with the client
177
+ /// channel.
178
+ // TODO(juanlishen): Consider adding a mid-layer subclass that helps handle
179
+ // things like swapping in pending policy when it's ready. Currently, we are
180
+ // duplicating the logic in many subclasses.
181
+ class ChannelControlHelper {
182
+ public:
183
+ ChannelControlHelper() = default;
184
+ virtual ~ChannelControlHelper() = default;
185
+
186
+ /// Creates a new subchannel with the specified channel args.
187
+ virtual RefCountedPtr<SubchannelInterface> CreateSubchannel(
188
+ const grpc_channel_args& args) GRPC_ABSTRACT;
189
+
190
+ /// Creates a channel with the specified target and channel args.
191
+ /// This can be used in cases where the LB policy needs to create a
192
+ /// channel for its own use (e.g., to talk to an external load balancer).
193
+ virtual grpc_channel* CreateChannel(
194
+ const char* target, const grpc_channel_args& args) GRPC_ABSTRACT;
195
+
196
+ /// Sets the connectivity state and returns a new picker to be used
197
+ /// by the client channel.
198
+ virtual void UpdateState(grpc_connectivity_state state,
199
+ UniquePtr<SubchannelPicker>) GRPC_ABSTRACT;
200
+
201
+ /// Requests that the resolver re-resolve.
202
+ virtual void RequestReresolution() GRPC_ABSTRACT;
203
+
204
+ /// Adds a trace message associated with the channel.
205
+ /// Does NOT take ownership of \a message.
206
+ enum TraceSeverity { TRACE_INFO, TRACE_WARNING, TRACE_ERROR };
207
+ virtual void AddTraceEvent(TraceSeverity severity,
208
+ const char* message) GRPC_ABSTRACT;
209
+
210
+ GRPC_ABSTRACT_BASE_CLASS
211
+ };
212
+
213
+ /// Interface for configuration data used by an LB policy implementation.
214
+ /// Individual implementations will create a subclass that adds methods to
215
+ /// return the parameters they need.
216
+ class Config : public RefCounted<Config> {
217
+ public:
218
+ virtual ~Config() = default;
219
+
220
+ // Returns the load balancing policy name
221
+ virtual const char* name() const GRPC_ABSTRACT;
222
+
223
+ GRPC_ABSTRACT_BASE_CLASS
224
+ };
225
+
226
+ /// Data passed to the UpdateLocked() method when new addresses and
227
+ /// config are available.
228
+ struct UpdateArgs {
229
+ ServerAddressList addresses;
230
+ RefCountedPtr<Config> config;
231
+ const grpc_channel_args* args = nullptr;
232
+
233
+ // TODO(roth): Remove everything below once channel args is
234
+ // converted to a copyable and movable C++ object.
235
+ UpdateArgs() = default;
236
+ ~UpdateArgs() { grpc_channel_args_destroy(args); }
237
+ UpdateArgs(const UpdateArgs& other);
238
+ UpdateArgs(UpdateArgs&& other);
239
+ UpdateArgs& operator=(const UpdateArgs& other);
240
+ UpdateArgs& operator=(UpdateArgs&& other);
241
+ };
242
+
243
+ /// Args used to instantiate an LB policy.
47
244
  struct Args {
48
245
  /// The combiner under which all LB policy calls will be run.
49
246
  /// Policy does NOT take ownership of the reference to the combiner.
@@ -51,38 +248,17 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
51
248
  // API should change to take a smart pointer that does pass ownership
52
249
  // of a reference.
53
250
  grpc_combiner* combiner = nullptr;
54
- /// Used to create channels and subchannels.
55
- grpc_client_channel_factory* client_channel_factory = nullptr;
56
- /// Channel args from the resolver.
57
- /// Note that the LB policy gets the set of addresses from the
58
- /// GRPC_ARG_SERVER_ADDRESS_LIST channel arg.
59
- grpc_channel_args* args = nullptr;
60
- /// Load balancing config from the resolver.
61
- grpc_json* lb_config = nullptr;
251
+ /// Channel control helper.
252
+ /// Note: LB policies MUST NOT call any method on the helper from
253
+ /// their constructor.
254
+ UniquePtr<ChannelControlHelper> channel_control_helper;
255
+ /// Channel args.
256
+ // TODO(roth): Find a better channel args representation for this API.
257
+ const grpc_channel_args* args = nullptr;
62
258
  };
63
259
 
64
- /// State used for an LB pick.
65
- struct PickState {
66
- /// Initial metadata associated with the picking call.
67
- grpc_metadata_batch* initial_metadata = nullptr;
68
- /// Pointer to bitmask used for selective cancelling. See
69
- /// \a CancelMatchingPicksLocked() and \a GRPC_INITIAL_METADATA_* in
70
- /// grpc_types.h.
71
- uint32_t* initial_metadata_flags = nullptr;
72
- /// Storage for LB token in \a initial_metadata, or nullptr if not used.
73
- grpc_linked_mdelem lb_token_mdelem_storage;
74
- /// Closure to run when pick is complete, if not completed synchronously.
75
- /// If null, pick will fail if a result is not available synchronously.
76
- grpc_closure* on_complete = nullptr;
77
- /// Will be set to the selected subchannel, or nullptr on failure or when
78
- /// the LB policy decides to drop the call.
79
- RefCountedPtr<ConnectedSubchannel> connected_subchannel;
80
- /// Will be populated with context to pass to the subchannel call, if
81
- /// needed.
82
- grpc_call_context_element subchannel_call_context[GRPC_CONTEXT_COUNT] = {};
83
- /// Next pointer. For internal use by LB policy.
84
- PickState* next = nullptr;
85
- };
260
+ explicit LoadBalancingPolicy(Args args, intptr_t initial_refcount = 1);
261
+ virtual ~LoadBalancingPolicy();
86
262
 
87
263
  // Not copyable nor movable.
88
264
  LoadBalancingPolicy(const LoadBalancingPolicy&) = delete;
@@ -91,123 +267,78 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
91
267
  /// Returns the name of the LB policy.
92
268
  virtual const char* name() const GRPC_ABSTRACT;
93
269
 
94
- /// Updates the policy with a new set of \a args and a new \a lb_config from
95
- /// the resolver. Note that the LB policy gets the set of addresses from the
96
- /// GRPC_ARG_SERVER_ADDRESS_LIST channel arg.
97
- virtual void UpdateLocked(const grpc_channel_args& args,
98
- grpc_json* lb_config) GRPC_ABSTRACT;
99
-
100
- /// Finds an appropriate subchannel for a call, based on data in \a pick.
101
- /// \a pick must remain alive until the pick is complete.
102
- ///
103
- /// If a result is known immediately, returns true, setting \a *error
104
- /// upon failure. Otherwise, \a pick->on_complete will be invoked once
105
- /// the pick is complete with its error argument set to indicate success
106
- /// or failure.
107
- ///
108
- /// If \a pick->on_complete is null and no result is known immediately,
109
- /// a synchronous failure will be returned (i.e., \a *error will be
110
- /// set and true will be returned).
111
- virtual bool PickLocked(PickState* pick, grpc_error** error) GRPC_ABSTRACT;
112
-
113
- /// Cancels \a pick.
114
- /// The \a on_complete callback of the pending pick will be invoked with
115
- /// \a pick->connected_subchannel set to null.
116
- virtual void CancelPickLocked(PickState* pick,
117
- grpc_error* error) GRPC_ABSTRACT;
118
-
119
- /// Cancels all pending picks for which their \a initial_metadata_flags (as
120
- /// given in the call to \a PickLocked()) matches
121
- /// \a initial_metadata_flags_eq when ANDed with
122
- /// \a initial_metadata_flags_mask.
123
- virtual void CancelMatchingPicksLocked(uint32_t initial_metadata_flags_mask,
124
- uint32_t initial_metadata_flags_eq,
125
- grpc_error* error) GRPC_ABSTRACT;
126
-
127
- /// Requests a notification when the connectivity state of the policy
128
- /// changes from \a *state. When that happens, sets \a *state to the
129
- /// new state and schedules \a closure.
130
- virtual void NotifyOnStateChangeLocked(grpc_connectivity_state* state,
131
- grpc_closure* closure) GRPC_ABSTRACT;
132
-
133
- /// Returns the policy's current connectivity state. Sets \a error to
134
- /// the associated error, if any.
135
- virtual grpc_connectivity_state CheckConnectivityLocked(
136
- grpc_error** connectivity_error) GRPC_ABSTRACT;
137
-
138
- /// Hands off pending picks to \a new_policy.
139
- virtual void HandOffPendingPicksLocked(LoadBalancingPolicy* new_policy)
140
- GRPC_ABSTRACT;
270
+ /// Updates the policy with new data from the resolver. Will be invoked
271
+ /// immediately after LB policy is constructed, and then again whenever
272
+ /// the resolver returns a new result.
273
+ virtual void UpdateLocked(UpdateArgs) GRPC_ABSTRACT; // NOLINT
141
274
 
142
275
  /// Tries to enter a READY connectivity state.
143
- /// TODO(roth): As part of restructuring how we handle IDLE state,
144
- /// consider whether this method is still needed.
145
- virtual void ExitIdleLocked() GRPC_ABSTRACT;
276
+ /// This is a no-op by default, since most LB policies never go into
277
+ /// IDLE state.
278
+ virtual void ExitIdleLocked() {}
146
279
 
147
280
  /// Resets connection backoff.
148
281
  virtual void ResetBackoffLocked() GRPC_ABSTRACT;
149
282
 
150
- /// Populates child_subchannels and child_channels with the uuids of this
151
- /// LB policy's referenced children. This is not invoked from the
152
- /// client_channel's combiner. The implementation is responsible for
153
- /// providing its own synchronization.
154
- virtual void FillChildRefsForChannelz(
155
- channelz::ChildRefsList* child_subchannels,
156
- channelz::ChildRefsList* child_channels) GRPC_ABSTRACT;
157
-
158
- void Orphan() override {
159
- // Invoke ShutdownAndUnrefLocked() inside of the combiner.
160
- GRPC_CLOSURE_SCHED(
161
- GRPC_CLOSURE_CREATE(&LoadBalancingPolicy::ShutdownAndUnrefLocked, this,
162
- grpc_combiner_scheduler(combiner_)),
163
- GRPC_ERROR_NONE);
164
- }
283
+ grpc_pollset_set* interested_parties() const { return interested_parties_; }
165
284
 
166
- /// Sets the re-resolution closure to \a request_reresolution.
167
- void SetReresolutionClosureLocked(grpc_closure* request_reresolution) {
168
- GPR_ASSERT(request_reresolution_ == nullptr);
169
- request_reresolution_ = request_reresolution;
170
- }
285
+ void Orphan() override;
171
286
 
172
- grpc_pollset_set* interested_parties() const { return interested_parties_; }
287
+ // A picker that returns PICK_QUEUE for all picks.
288
+ // Also calls the parent LB policy's ExitIdleLocked() method when the
289
+ // first pick is seen.
290
+ class QueuePicker : public SubchannelPicker {
291
+ public:
292
+ explicit QueuePicker(RefCountedPtr<LoadBalancingPolicy> parent)
293
+ : parent_(std::move(parent)) {}
173
294
 
174
- GRPC_ABSTRACT_BASE_CLASS
295
+ ~QueuePicker() { parent_.reset(DEBUG_LOCATION, "QueuePicker"); }
175
296
 
176
- protected:
177
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
297
+ PickResult Pick(PickArgs args) override;
178
298
 
179
- explicit LoadBalancingPolicy(const Args& args);
180
- virtual ~LoadBalancingPolicy();
299
+ private:
300
+ static void CallExitIdle(void* arg, grpc_error* error);
301
+
302
+ RefCountedPtr<LoadBalancingPolicy> parent_;
303
+ bool exit_idle_called_ = false;
304
+ };
305
+
306
+ // A picker that returns PICK_TRANSIENT_FAILURE for all picks.
307
+ class TransientFailurePicker : public SubchannelPicker {
308
+ public:
309
+ explicit TransientFailurePicker(grpc_error* error) : error_(error) {}
310
+ ~TransientFailurePicker() override { GRPC_ERROR_UNREF(error_); }
311
+
312
+ PickResult Pick(PickArgs args) override;
313
+
314
+ private:
315
+ grpc_error* error_;
316
+ };
181
317
 
318
+ GRPC_ABSTRACT_BASE_CLASS
319
+
320
+ protected:
182
321
  grpc_combiner* combiner() const { return combiner_; }
183
- grpc_client_channel_factory* client_channel_factory() const {
184
- return client_channel_factory_;
322
+
323
+ // Note: LB policies MUST NOT call any method on the helper from their
324
+ // constructor.
325
+ // Note: This will return null after ShutdownLocked() has been called.
326
+ ChannelControlHelper* channel_control_helper() const {
327
+ return channel_control_helper_.get();
185
328
  }
186
329
 
187
- /// Shuts down the policy. Any pending picks that have not been
188
- /// handed off to a new policy via HandOffPendingPicksLocked() will be
189
- /// failed.
330
+ /// Shuts down the policy.
190
331
  virtual void ShutdownLocked() GRPC_ABSTRACT;
191
332
 
192
- /// Tries to request a re-resolution.
193
- void TryReresolutionLocked(grpc_core::TraceFlag* grpc_lb_trace,
194
- grpc_error* error);
195
-
196
333
  private:
197
- static void ShutdownAndUnrefLocked(void* arg, grpc_error* ignored) {
198
- LoadBalancingPolicy* policy = static_cast<LoadBalancingPolicy*>(arg);
199
- policy->ShutdownLocked();
200
- policy->Unref();
201
- }
334
+ static void ShutdownAndUnrefLocked(void* arg, grpc_error* ignored);
202
335
 
203
336
  /// Combiner under which LB policy actions take place.
204
337
  grpc_combiner* combiner_;
205
- /// Client channel factory, used to create channels and subchannels.
206
- grpc_client_channel_factory* client_channel_factory_;
207
338
  /// Owned pointer to interested parties in load balancing decisions.
208
339
  grpc_pollset_set* interested_parties_;
209
- /// Callback to force a re-resolution.
210
- grpc_closure* request_reresolution_;
340
+ /// Channel control helper.
341
+ UniquePtr<ChannelControlHelper> channel_control_helper_;
211
342
  };
212
343
 
213
344
  } // namespace grpc_core
@@ -31,15 +31,18 @@ class LoadBalancingPolicyFactory {
31
31
  public:
32
32
  /// Returns a new LB policy instance.
33
33
  virtual OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
34
- const LoadBalancingPolicy::Args& args) const GRPC_ABSTRACT;
34
+ LoadBalancingPolicy::Args) const GRPC_ABSTRACT;
35
35
 
36
36
  /// Returns the LB policy name that this factory provides.
37
37
  /// Caller does NOT take ownership of result.
38
38
  virtual const char* name() const GRPC_ABSTRACT;
39
39
 
40
+ virtual RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
41
+ const grpc_json* json, grpc_error** error) const GRPC_ABSTRACT;
42
+
40
43
  virtual ~LoadBalancingPolicyFactory() {}
41
44
 
42
- GRPC_ABSTRACT_BASE_CLASS
45
+ GRPC_ABSTRACT_BASE_CLASS;
43
46
  };
44
47
 
45
48
  } // namespace grpc_core
@@ -84,19 +84,122 @@ void LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
84
84
 
85
85
  OrphanablePtr<LoadBalancingPolicy>
86
86
  LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
87
- const char* name, const LoadBalancingPolicy::Args& args) {
87
+ const char* name, LoadBalancingPolicy::Args args) {
88
88
  GPR_ASSERT(g_state != nullptr);
89
89
  // Find factory.
90
90
  LoadBalancingPolicyFactory* factory =
91
91
  g_state->GetLoadBalancingPolicyFactory(name);
92
92
  if (factory == nullptr) return nullptr; // Specified name not found.
93
93
  // Create policy via factory.
94
- return factory->CreateLoadBalancingPolicy(args);
94
+ return factory->CreateLoadBalancingPolicy(std::move(args));
95
95
  }
96
96
 
97
- bool LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(const char* name) {
97
+ bool LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(
98
+ const char* name, bool* requires_config) {
98
99
  GPR_ASSERT(g_state != nullptr);
99
- return g_state->GetLoadBalancingPolicyFactory(name) != nullptr;
100
+ auto* factory = g_state->GetLoadBalancingPolicyFactory(name);
101
+ if (factory == nullptr) {
102
+ return false;
103
+ }
104
+ if (requires_config != nullptr) {
105
+ grpc_error* error = GRPC_ERROR_NONE;
106
+ // Check if the load balancing policy allows an empty config
107
+ *requires_config =
108
+ factory->ParseLoadBalancingConfig(nullptr, &error) == nullptr;
109
+ GRPC_ERROR_UNREF(error);
110
+ }
111
+ return true;
112
+ }
113
+
114
+ namespace {
115
+ // Returns the JSON node of policy (with both policy name and config content)
116
+ // given the JSON node of a LoadBalancingConfig array.
117
+ grpc_json* ParseLoadBalancingConfigHelper(const grpc_json* lb_config_array,
118
+ grpc_error** error) {
119
+ GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
120
+ char* error_msg;
121
+ if (lb_config_array == nullptr || lb_config_array->type != GRPC_JSON_ARRAY) {
122
+ gpr_asprintf(&error_msg, "field:%s error:type should be array",
123
+ lb_config_array->key);
124
+ *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg);
125
+ gpr_free(error_msg);
126
+ return nullptr;
127
+ }
128
+ const char* field_name = lb_config_array->key;
129
+ // Find the first LB policy that this client supports.
130
+ for (const grpc_json* lb_config = lb_config_array->child;
131
+ lb_config != nullptr; lb_config = lb_config->next) {
132
+ if (lb_config->type != GRPC_JSON_OBJECT) {
133
+ gpr_asprintf(&error_msg,
134
+ "field:%s error:child entry should be of type object",
135
+ field_name);
136
+ *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg);
137
+ gpr_free(error_msg);
138
+ return nullptr;
139
+ }
140
+ grpc_json* policy = nullptr;
141
+ for (grpc_json* field = lb_config->child; field != nullptr;
142
+ field = field->next) {
143
+ if (field->key == nullptr || field->type != GRPC_JSON_OBJECT) {
144
+ gpr_asprintf(&error_msg,
145
+ "field:%s error:child entry should be of type object",
146
+ field_name);
147
+ *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg);
148
+ gpr_free(error_msg);
149
+ return nullptr;
150
+ }
151
+ if (policy != nullptr) {
152
+ gpr_asprintf(&error_msg, "field:%s error:oneOf violation", field_name);
153
+ *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg);
154
+ gpr_free(error_msg);
155
+ return nullptr;
156
+ } // Violate "oneof" type.
157
+ policy = field;
158
+ }
159
+ if (policy == nullptr) {
160
+ gpr_asprintf(&error_msg, "field:%s error:no policy found in child entry",
161
+ field_name);
162
+ *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg);
163
+ gpr_free(error_msg);
164
+ return nullptr;
165
+ }
166
+ // If we support this policy, then select it.
167
+ if (LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(policy->key,
168
+ nullptr)) {
169
+ return policy;
170
+ }
171
+ }
172
+ gpr_asprintf(&error_msg, "field:%s error:No known policy", field_name);
173
+ *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg);
174
+ gpr_free(error_msg);
175
+ return nullptr;
176
+ }
177
+ } // namespace
178
+
179
+ RefCountedPtr<LoadBalancingPolicy::Config>
180
+ LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(const grpc_json* json,
181
+ grpc_error** error) {
182
+ GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
183
+ GPR_ASSERT(g_state != nullptr);
184
+ const grpc_json* policy = ParseLoadBalancingConfigHelper(json, error);
185
+ if (policy == nullptr) {
186
+ return nullptr;
187
+ } else {
188
+ GPR_DEBUG_ASSERT(*error == GRPC_ERROR_NONE && json != nullptr);
189
+ // Find factory.
190
+ LoadBalancingPolicyFactory* factory =
191
+ g_state->GetLoadBalancingPolicyFactory(policy->key);
192
+ if (factory == nullptr) {
193
+ char* msg;
194
+ gpr_asprintf(&msg, "field:%s error:Factory not found to create policy",
195
+ json->key);
196
+ *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
197
+ gpr_free(msg);
198
+ return nullptr;
199
+ }
200
+ // Parse load balancing config via factory.
201
+ return factory->ParseLoadBalancingConfig(policy, error);
202
+ }
100
203
  }
101
204
 
102
205
  } // namespace grpc_core
@@ -46,11 +46,18 @@ class LoadBalancingPolicyRegistry {
46
46
 
47
47
  /// Creates an LB policy of the type specified by \a name.
48
48
  static OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
49
- const char* name, const LoadBalancingPolicy::Args& args);
49
+ const char* name, LoadBalancingPolicy::Args args);
50
50
 
51
51
  /// Returns true if the LB policy factory specified by \a name exists in this
52
- /// registry.
53
- static bool LoadBalancingPolicyExists(const char* name);
52
+ /// registry. If the load balancing policy requires a config to be specified
53
+ /// then sets \a requires_config to true.
54
+ static bool LoadBalancingPolicyExists(const char* name,
55
+ bool* requires_config);
56
+
57
+ /// Returns a parsed object of the load balancing policy to be used from a
58
+ /// LoadBalancingConfig array \a json.
59
+ static RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
60
+ const grpc_json* json, grpc_error** error);
54
61
  };
55
62
 
56
63
  } // namespace grpc_core