grpc 1.49.1-x86_64-linux → 1.50.0-x86_64-linux

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 (275) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +54 -153
  3. data/include/grpc/event_engine/endpoint_config.h +11 -5
  4. data/include/grpc/event_engine/event_engine.h +1 -1
  5. data/include/grpc/impl/codegen/atm_gcc_atomic.h +19 -28
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +0 -2
  7. data/include/grpc/impl/codegen/atm_windows.h +0 -2
  8. data/include/grpc/impl/codegen/grpc_types.h +6 -0
  9. data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +3 -3
  10. data/src/core/ext/filters/client_channel/backup_poller.cc +4 -6
  11. data/src/core/ext/filters/client_channel/client_channel.cc +33 -22
  12. data/src/core/ext/filters/client_channel/client_channel.h +1 -1
  13. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +0 -16
  14. data/src/core/ext/filters/client_channel/http_proxy.cc +12 -19
  15. data/src/core/ext/filters/client_channel/http_proxy.h +3 -2
  16. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +6 -4
  17. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.h +5 -4
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +0 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +112 -96
  20. data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +20 -11
  21. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +106 -108
  22. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h +16 -0
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +20 -13
  24. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +165 -257
  25. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +218 -231
  26. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +10 -6
  27. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +389 -444
  28. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +16 -16
  29. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +8 -13
  30. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +84 -96
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +38 -37
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +106 -186
  33. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +106 -93
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +170 -218
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  36. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -1
  37. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +13 -15
  38. data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +84 -37
  39. data/src/core/ext/filters/client_channel/resolver/polling_resolver.h +11 -0
  40. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -0
  41. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +5 -3
  42. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +5 -4
  43. data/src/core/ext/filters/client_channel/retry_filter.cc +25 -29
  44. data/src/core/ext/filters/client_channel/subchannel.cc +38 -33
  45. data/src/core/ext/filters/client_channel/subchannel.h +12 -3
  46. data/src/core/ext/filters/client_channel/subchannel_stream_client.cc +1 -2
  47. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +23 -16
  48. data/src/core/ext/filters/fault_injection/fault_injection_filter.h +8 -0
  49. data/src/core/ext/filters/http/client/http_client_filter.cc +1 -2
  50. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +2 -4
  51. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +0 -2
  52. data/src/core/ext/filters/http/server/http_server_filter.cc +1 -2
  53. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +12 -8
  54. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +32 -26
  55. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +1 -1
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +25 -130
  57. data/src/core/ext/transport/chttp2/transport/decode_huff.cc +287 -0
  58. data/src/core/ext/transport/chttp2/transport/decode_huff.h +1018 -0
  59. data/src/core/ext/transport/chttp2/transport/flow_control.cc +83 -51
  60. data/src/core/ext/transport/chttp2/transport/flow_control.h +11 -6
  61. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +1 -2
  62. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +2 -20
  63. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +28 -28
  64. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +1 -10
  65. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +11 -6
  66. data/src/core/ext/transport/chttp2/transport/internal.h +2 -0
  67. data/src/core/ext/transport/chttp2/transport/parsing.cc +44 -0
  68. data/src/core/ext/transport/chttp2/transport/writing.cc +3 -14
  69. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -3
  70. data/src/core/ext/xds/certificate_provider_store.cc +63 -3
  71. data/src/core/ext/xds/certificate_provider_store.h +9 -1
  72. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +5 -5
  73. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +1 -1
  74. data/src/core/ext/xds/xds_api.cc +21 -17
  75. data/src/core/ext/xds/xds_api.h +7 -0
  76. data/src/core/ext/xds/xds_bootstrap.cc +5 -537
  77. data/src/core/ext/xds/xds_bootstrap.h +39 -111
  78. data/src/core/ext/xds/xds_bootstrap_grpc.cc +370 -0
  79. data/src/core/ext/xds/xds_bootstrap_grpc.h +169 -0
  80. data/src/core/ext/xds/xds_client.cc +219 -145
  81. data/src/core/ext/xds/xds_client.h +19 -17
  82. data/src/core/ext/xds/xds_client_grpc.cc +18 -80
  83. data/src/core/ext/xds/xds_client_grpc.h +2 -25
  84. data/src/core/ext/xds/xds_client_stats.cc +4 -4
  85. data/src/core/ext/xds/xds_cluster.cc +87 -79
  86. data/src/core/ext/xds/xds_cluster.h +5 -5
  87. data/src/core/ext/xds/xds_cluster_specifier_plugin.cc +3 -1
  88. data/src/core/ext/xds/xds_common_types.cc +13 -5
  89. data/src/core/ext/xds/xds_endpoint.cc +8 -6
  90. data/src/core/ext/xds/xds_endpoint.h +3 -4
  91. data/src/core/ext/xds/xds_lb_policy_registry.cc +4 -2
  92. data/src/core/ext/xds/xds_listener.cc +25 -20
  93. data/src/core/ext/xds/xds_listener.h +3 -4
  94. data/src/core/ext/xds/xds_resource_type.h +11 -8
  95. data/src/core/ext/xds/xds_route_config.cc +15 -16
  96. data/src/core/ext/xds/xds_route_config.h +3 -3
  97. data/src/core/ext/xds/xds_server_config_fetcher.cc +7 -5
  98. data/src/core/ext/xds/xds_transport_grpc.cc +15 -7
  99. data/src/core/lib/backoff/backoff.cc +2 -4
  100. data/src/core/lib/channel/call_finalization.h +1 -3
  101. data/src/core/lib/channel/channel_args.h +114 -14
  102. data/src/core/lib/channel/channel_trace.cc +3 -4
  103. data/src/core/lib/channel/promise_based_filter.cc +18 -19
  104. data/src/core/lib/channel/status_util.cc +27 -0
  105. data/src/core/lib/channel/status_util.h +10 -0
  106. data/src/core/lib/config/core_configuration.cc +5 -1
  107. data/src/core/lib/config/core_configuration.h +33 -0
  108. data/src/core/lib/debug/stats.cc +26 -30
  109. data/src/core/lib/debug/stats.h +2 -12
  110. data/src/core/lib/debug/stats_data.cc +118 -614
  111. data/src/core/lib/debug/stats_data.h +67 -465
  112. data/src/core/lib/debug/trace.cc +0 -2
  113. data/src/core/lib/event_engine/channel_args_endpoint_config.cc +12 -20
  114. data/src/core/lib/event_engine/channel_args_endpoint_config.h +13 -7
  115. data/src/core/lib/event_engine/forkable.cc +1 -1
  116. data/src/core/lib/event_engine/poller.h +14 -12
  117. data/src/core/lib/event_engine/posix_engine/timer_manager.cc +53 -32
  118. data/src/core/lib/event_engine/posix_engine/timer_manager.h +23 -1
  119. data/src/core/lib/event_engine/thread_pool.cc +131 -94
  120. data/src/core/lib/event_engine/thread_pool.h +56 -23
  121. data/src/core/lib/event_engine/time_util.cc +30 -0
  122. data/src/core/lib/event_engine/time_util.h +32 -0
  123. data/src/core/lib/event_engine/utils.cc +0 -5
  124. data/src/core/lib/event_engine/utils.h +0 -4
  125. data/src/core/lib/event_engine/windows/iocp.cc +13 -7
  126. data/src/core/lib/event_engine/windows/iocp.h +2 -1
  127. data/src/core/lib/event_engine/windows/win_socket.cc +1 -1
  128. data/src/core/lib/experiments/config.cc +146 -0
  129. data/src/core/lib/experiments/config.h +43 -0
  130. data/src/core/lib/experiments/experiments.cc +75 -0
  131. data/src/core/lib/experiments/experiments.h +56 -0
  132. data/src/core/lib/gpr/alloc.cc +1 -9
  133. data/src/core/lib/gpr/log_windows.cc +0 -1
  134. data/src/core/lib/gpr/string_util_windows.cc +3 -30
  135. data/src/core/lib/gpr/sync_abseil.cc +0 -14
  136. data/src/core/lib/gpr/sync_posix.cc +0 -14
  137. data/src/core/lib/gpr/time_posix.cc +0 -6
  138. data/src/core/lib/gpr/time_precise.h +1 -1
  139. data/src/core/lib/gpr/tmpfile_windows.cc +5 -7
  140. data/src/core/lib/gpr/useful.h +11 -0
  141. data/src/core/lib/{gpr → gprpp}/env.h +25 -12
  142. data/src/core/lib/{gpr → gprpp}/env_linux.cc +20 -15
  143. data/src/core/lib/{gpr → gprpp}/env_posix.cc +11 -10
  144. data/src/core/lib/gprpp/env_windows.cc +56 -0
  145. data/src/core/lib/gprpp/fork.cc +14 -22
  146. data/src/core/lib/gprpp/fork.h +0 -8
  147. data/src/core/lib/gprpp/global_config_env.cc +7 -6
  148. data/src/core/lib/gprpp/notification.h +67 -0
  149. data/src/core/lib/gprpp/packed_table.h +40 -0
  150. data/src/core/lib/gprpp/ref_counted_ptr.h +20 -33
  151. data/src/core/lib/gprpp/sorted_pack.h +98 -0
  152. data/src/core/lib/gprpp/status_helper.h +6 -0
  153. data/src/core/lib/gprpp/table.h +9 -1
  154. data/src/core/lib/gprpp/tchar.cc +49 -0
  155. data/src/core/lib/gprpp/tchar.h +33 -0
  156. data/src/core/lib/gprpp/time.cc +21 -0
  157. data/src/core/lib/gprpp/time.h +55 -0
  158. data/src/core/lib/gprpp/validation_errors.cc +61 -0
  159. data/src/core/lib/gprpp/validation_errors.h +110 -0
  160. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper.h +3 -3
  161. data/src/core/{ext/filters/client_channel → lib/handshaker}/proxy_mapper_registry.cc +14 -36
  162. data/src/core/lib/handshaker/proxy_mapper_registry.h +75 -0
  163. data/src/core/lib/iomgr/call_combiner.cc +0 -8
  164. data/src/core/lib/iomgr/closure.h +0 -1
  165. data/src/core/lib/iomgr/endpoint_pair_posix.cc +14 -10
  166. data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
  167. data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -38
  168. data/src/core/lib/iomgr/ev_poll_posix.cc +2 -17
  169. data/src/core/lib/iomgr/exec_ctx.cc +0 -10
  170. data/src/core/lib/iomgr/exec_ctx.h +7 -31
  171. data/src/core/lib/iomgr/iocp_windows.cc +1 -2
  172. data/src/core/lib/iomgr/iomgr.cc +6 -8
  173. data/src/core/lib/iomgr/iomgr_fwd.h +1 -0
  174. data/src/core/lib/iomgr/pollset.h +1 -1
  175. data/src/core/lib/iomgr/pollset_set.h +0 -1
  176. data/src/core/lib/iomgr/resolve_address.h +1 -0
  177. data/src/core/lib/iomgr/resolve_address_impl.h +1 -0
  178. data/src/core/lib/iomgr/resolve_address_posix.cc +1 -0
  179. data/src/core/lib/iomgr/resolve_address_windows.cc +1 -0
  180. data/src/core/lib/iomgr/sockaddr_utils_posix.cc +2 -1
  181. data/src/core/lib/iomgr/socket_utils_common_posix.cc +12 -34
  182. data/src/core/lib/iomgr/socket_utils_posix.cc +83 -1
  183. data/src/core/lib/iomgr/socket_utils_posix.h +98 -6
  184. data/src/core/lib/iomgr/tcp_client.cc +6 -7
  185. data/src/core/lib/iomgr/tcp_client.h +11 -11
  186. data/src/core/lib/iomgr/tcp_client_cfstream.cc +6 -6
  187. data/src/core/lib/iomgr/tcp_client_posix.cc +33 -29
  188. data/src/core/lib/iomgr/tcp_client_posix.h +12 -9
  189. data/src/core/lib/iomgr/tcp_client_windows.cc +6 -6
  190. data/src/core/lib/iomgr/tcp_posix.cc +131 -114
  191. data/src/core/lib/iomgr/tcp_posix.h +3 -1
  192. data/src/core/lib/iomgr/tcp_server.cc +5 -4
  193. data/src/core/lib/iomgr/tcp_server.h +9 -6
  194. data/src/core/lib/iomgr/tcp_server_posix.cc +17 -28
  195. data/src/core/lib/iomgr/tcp_server_utils_posix.h +2 -2
  196. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +3 -3
  197. data/src/core/lib/iomgr/tcp_server_windows.cc +6 -7
  198. data/src/core/lib/iomgr/tcp_windows.cc +0 -1
  199. data/src/core/lib/iomgr/tcp_windows.h +0 -1
  200. data/src/core/lib/iomgr/timer_generic.cc +4 -4
  201. data/src/core/lib/iomgr/timer_manager.cc +1 -2
  202. data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +0 -2
  203. data/src/core/lib/json/json_object_loader.cc +21 -52
  204. data/src/core/lib/json/json_object_loader.h +56 -76
  205. data/src/core/lib/json/json_util.cc +2 -1
  206. data/src/core/lib/load_balancing/lb_policy.h +5 -5
  207. data/src/core/lib/load_balancing/lb_policy_registry.cc +29 -55
  208. data/src/core/lib/load_balancing/lb_policy_registry.h +23 -11
  209. data/src/core/lib/promise/activity.h +2 -3
  210. data/src/core/lib/promise/context.h +1 -1
  211. data/src/core/lib/promise/sleep.cc +16 -4
  212. data/src/core/lib/promise/sleep.h +8 -2
  213. data/src/core/lib/resolver/resolver.h +13 -3
  214. data/src/core/lib/resource_quota/api.cc +9 -0
  215. data/src/core/lib/resource_quota/api.h +6 -0
  216. data/src/core/lib/resource_quota/arena.cc +1 -3
  217. data/src/core/lib/resource_quota/memory_quota.cc +8 -24
  218. data/src/core/lib/resource_quota/memory_quota.h +6 -19
  219. data/src/core/lib/resource_quota/periodic_update.cc +2 -3
  220. data/src/core/{ext/xds → lib/security/certificate_provider}/certificate_provider_factory.h +3 -3
  221. data/src/core/lib/security/certificate_provider/certificate_provider_registry.cc +60 -0
  222. data/src/core/lib/security/certificate_provider/certificate_provider_registry.h +70 -0
  223. data/src/core/lib/security/credentials/channel_creds_registry_init.cc +1 -0
  224. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +15 -16
  225. data/src/core/lib/security/credentials/external/external_account_credentials.cc +2 -1
  226. data/src/core/lib/security/credentials/google_default/credentials_generic.cc +5 -8
  227. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +6 -6
  228. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
  229. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +1 -1
  230. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -2
  231. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +4 -3
  232. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +4 -2
  233. data/src/core/lib/security/credentials/tls/tls_utils.cc +3 -1
  234. data/src/core/lib/security/transport/client_auth_filter.cc +12 -1
  235. data/src/core/lib/security/transport/secure_endpoint.cc +0 -4
  236. data/src/core/lib/surface/call.cc +1 -11
  237. data/src/core/lib/surface/channel.cc +3 -2
  238. data/src/core/lib/surface/completion_queue.cc +16 -28
  239. data/src/core/lib/surface/completion_queue.h +1 -1
  240. data/src/core/lib/surface/completion_queue_factory.cc +5 -0
  241. data/src/core/lib/surface/init.cc +16 -11
  242. data/src/core/lib/surface/init_internally.cc +24 -0
  243. data/src/core/lib/surface/init_internally.h +28 -0
  244. data/src/core/lib/surface/server.cc +1 -7
  245. data/src/core/lib/surface/server.h +4 -6
  246. data/src/core/lib/surface/version.cc +2 -2
  247. data/src/core/lib/transport/bdp_estimator.cc +1 -3
  248. data/src/core/lib/transport/metadata_batch.cc +2 -3
  249. data/src/core/lib/transport/metadata_batch.h +9 -7
  250. data/src/core/lib/transport/parsed_metadata.h +4 -2
  251. data/src/core/lib/transport/status_conversion.cc +1 -3
  252. data/src/core/lib/transport/tcp_connect_handshaker.cc +9 -5
  253. data/src/core/lib/transport/transport.h +0 -1
  254. data/src/core/lib/transport/transport_impl.h +0 -1
  255. data/src/core/plugin_registry/grpc_plugin_registry.cc +23 -46
  256. data/src/core/plugin_registry/grpc_plugin_registry_extra.cc +13 -25
  257. data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
  258. data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
  259. data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
  260. data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
  261. data/src/ruby/lib/grpc/grpc_c.so +0 -0
  262. data/src/ruby/lib/grpc/version.rb +1 -1
  263. data/src/ruby/spec/channel_spec.rb +5 -0
  264. data/src/ruby/spec/generic/server_interceptors_spec.rb +1 -1
  265. data/src/ruby/spec/user_agent_spec.rb +1 -1
  266. metadata +31 -17
  267. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +0 -56
  268. data/src/core/ext/xds/certificate_provider_registry.cc +0 -103
  269. data/src/core/ext/xds/certificate_provider_registry.h +0 -59
  270. data/src/core/lib/event_engine/promise.h +0 -78
  271. data/src/core/lib/gpr/env_windows.cc +0 -74
  272. data/src/core/lib/gpr/string_windows.h +0 -32
  273. data/src/core/lib/profiling/basic_timers.cc +0 -295
  274. data/src/core/lib/profiling/stap_timers.cc +0 -50
  275. data/src/core/lib/profiling/timers.h +0 -94
@@ -19,141 +19,69 @@
19
19
 
20
20
  #include <grpc/support/port_platform.h>
21
21
 
22
- #include <algorithm>
23
- #include <map>
24
- #include <memory>
25
- #include <set>
26
22
  #include <string>
27
- #include <vector>
28
23
 
29
- #include "absl/status/status.h"
30
- #include "absl/strings/string_view.h"
31
-
32
- #include "src/core/lib/iomgr/error.h"
33
24
  #include "src/core/lib/json/json.h"
34
25
 
35
26
  namespace grpc_core {
36
27
 
37
28
  bool XdsFederationEnabled();
38
29
 
39
- class XdsClient;
40
-
41
- class XdsCertificateProviderPluginMapInterface {
42
- public:
43
- virtual ~XdsCertificateProviderPluginMapInterface() = default;
44
-
45
- virtual absl::Status AddPlugin(const std::string& instance_name,
46
- const std::string& plugin_name,
47
- const Json& config) = 0;
48
-
49
- virtual bool HasPlugin(const std::string& instance_name) const = 0;
50
-
51
- virtual std::string ToString() const = 0;
52
- };
53
-
54
30
  class XdsBootstrap {
55
31
  public:
56
- struct Node {
57
- std::string id;
58
- std::string cluster;
59
- std::string locality_region;
60
- std::string locality_zone;
61
- std::string locality_sub_zone;
62
- Json metadata;
32
+ class Node {
33
+ public:
34
+ virtual ~Node() = default;
35
+
36
+ virtual const std::string& id() const = 0;
37
+ virtual const std::string& cluster() const = 0;
38
+ virtual const std::string& locality_region() const = 0;
39
+ virtual const std::string& locality_zone() const = 0;
40
+ virtual const std::string& locality_sub_zone() const = 0;
41
+ virtual const Json::Object& metadata() const = 0;
63
42
  };
64
43
 
65
- struct XdsServer {
66
- std::string server_uri;
67
- std::string channel_creds_type;
68
- Json channel_creds_config;
69
- std::set<std::string> server_features;
44
+ class XdsServer {
45
+ public:
46
+ virtual ~XdsServer() = default;
70
47
 
71
- static XdsServer Parse(const Json& json, grpc_error_handle* error);
48
+ virtual const std::string& server_uri() const = 0;
49
+ virtual bool ShouldUseV3() const = 0;
50
+ virtual bool IgnoreResourceDeletion() const = 0;
72
51
 
73
- bool operator==(const XdsServer& other) const {
74
- return (server_uri == other.server_uri &&
75
- channel_creds_type == other.channel_creds_type &&
76
- channel_creds_config == other.channel_creds_config &&
77
- server_features == other.server_features);
78
- }
52
+ virtual bool Equals(const XdsServer& other) const = 0;
79
53
 
80
- bool operator<(const XdsServer& other) const {
81
- if (server_uri < other.server_uri) return true;
82
- if (channel_creds_type < other.channel_creds_type) return true;
83
- if (channel_creds_config.Dump() < other.channel_creds_config.Dump()) {
84
- return true;
85
- }
86
- if (server_features < other.server_features) return true;
87
- return false;
54
+ friend bool operator==(const XdsServer& a, const XdsServer& b) {
55
+ return a.Equals(b);
88
56
  }
89
-
90
- Json::Object ToJson() const;
91
-
92
- bool ShouldUseV3() const;
93
- bool IgnoreResourceDeletion() const;
94
57
  };
95
58
 
96
- struct Authority {
97
- std::string client_listener_resource_name_template;
98
- std::vector<XdsServer> xds_servers;
99
- };
59
+ class Authority {
60
+ public:
61
+ virtual ~Authority() = default;
100
62
 
101
- // Creates bootstrap object from json_string.
102
- // If *error is not GRPC_ERROR_NONE after returning, then there was an
103
- // error parsing the contents.
104
- static std::unique_ptr<XdsBootstrap> Create(
105
- absl::string_view json_string,
106
- std::unique_ptr<XdsCertificateProviderPluginMapInterface>
107
- certificate_provider_plugin_map,
108
- grpc_error_handle* error);
63
+ virtual const XdsServer* server() const = 0;
64
+ };
109
65
 
110
- // Do not instantiate directly -- use Create() above instead.
111
- XdsBootstrap(Json json,
112
- std::unique_ptr<XdsCertificateProviderPluginMapInterface>
113
- certificate_provider_plugin_map,
114
- grpc_error_handle* error);
66
+ virtual ~XdsBootstrap() = default;
115
67
 
116
- std::string ToString() const;
68
+ virtual std::string ToString() const = 0;
117
69
 
118
70
  // TODO(roth): We currently support only one server. Fix this when we
119
71
  // add support for fallback for the xds channel.
120
- const XdsServer& server() const { return servers_[0]; }
121
- const Node* node() const { return node_.get(); }
122
- const std::string& client_default_listener_resource_name_template() const {
123
- return client_default_listener_resource_name_template_;
124
- }
125
- const std::string& server_listener_resource_name_template() const {
126
- return server_listener_resource_name_template_;
127
- }
128
- const std::map<std::string, Authority>& authorities() const {
129
- return authorities_;
130
- }
131
- const Authority* LookupAuthority(const std::string& name) const;
132
- const XdsCertificateProviderPluginMapInterface*
133
- certificate_provider_plugin_map() const {
134
- return certificate_provider_plugin_map_.get();
135
- }
136
- // A util method to check that an xds server exists in this bootstrap file.
137
- bool XdsServerExists(const XdsServer& server) const;
138
-
139
- private:
140
- grpc_error_handle ParseXdsServerList(Json* json,
141
- std::vector<XdsServer>* servers);
142
- grpc_error_handle ParseAuthorities(Json* json);
143
- grpc_error_handle ParseAuthority(Json* json, const std::string& name);
144
- grpc_error_handle ParseNode(Json* json);
145
- grpc_error_handle ParseLocality(Json* json);
146
- grpc_error_handle ParseCertificateProviders(Json* json);
147
- grpc_error_handle ParseCertificateProvider(const std::string& instance_name,
148
- Json* certificate_provider_json);
149
-
150
- std::vector<XdsServer> servers_;
151
- std::unique_ptr<Node> node_;
152
- std::string client_default_listener_resource_name_template_;
153
- std::string server_listener_resource_name_template_;
154
- std::map<std::string, Authority> authorities_;
155
- std::unique_ptr<XdsCertificateProviderPluginMapInterface>
156
- certificate_provider_plugin_map_;
72
+ virtual const XdsServer& server() const = 0;
73
+
74
+ // Returns the node information, or null if not present in the bootstrap
75
+ // config.
76
+ virtual const Node* node() const = 0;
77
+
78
+ // Returns a pointer to the specified authority, or null if it does
79
+ // not exist in this bootstrap config.
80
+ virtual const Authority* LookupAuthority(const std::string& name) const = 0;
81
+
82
+ // If the server exists in the bootstrap config, returns a pointer to
83
+ // the XdsServer instance in the config. Otherwise, returns null.
84
+ virtual const XdsServer* FindXdsServer(const XdsServer& server) const = 0;
157
85
  };
158
86
 
159
87
  } // namespace grpc_core
@@ -0,0 +1,370 @@
1
+ //
2
+ // Copyright 2019 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
+ //
16
+
17
+ #include <grpc/support/port_platform.h>
18
+
19
+ #include "src/core/ext/xds/xds_bootstrap_grpc.h"
20
+
21
+ #include <stdlib.h>
22
+
23
+ #include <algorithm>
24
+ #include <set>
25
+ #include <utility>
26
+ #include <vector>
27
+
28
+ #include "absl/memory/memory.h"
29
+ #include "absl/status/status.h"
30
+ #include "absl/status/statusor.h"
31
+ #include "absl/strings/match.h"
32
+ #include "absl/strings/str_cat.h"
33
+ #include "absl/strings/str_format.h"
34
+ #include "absl/strings/str_join.h"
35
+ #include "absl/strings/string_view.h"
36
+ #include "absl/types/optional.h"
37
+
38
+ #include "src/core/lib/config/core_configuration.h"
39
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
40
+ #include "src/core/lib/json/json.h"
41
+ #include "src/core/lib/json/json_object_loader.h"
42
+ #include "src/core/lib/security/certificate_provider/certificate_provider_factory.h"
43
+ #include "src/core/lib/security/credentials/channel_creds_registry.h"
44
+
45
+ namespace grpc_core {
46
+
47
+ //
48
+ // GrpcXdsBootstrap::GrpcNode::Locality
49
+ //
50
+
51
+ const JsonLoaderInterface* GrpcXdsBootstrap::GrpcNode::Locality::JsonLoader(
52
+ const JsonArgs&) {
53
+ static const auto* loader =
54
+ JsonObjectLoader<Locality>()
55
+ .OptionalField("region", &Locality::region)
56
+ .OptionalField("zone", &Locality::zone)
57
+ .OptionalField("sub_zone", &Locality::sub_zone)
58
+ .Finish();
59
+ return loader;
60
+ }
61
+
62
+ //
63
+ // GrpcXdsBootstrap::GrpcNode
64
+ //
65
+
66
+ const JsonLoaderInterface* GrpcXdsBootstrap::GrpcNode::JsonLoader(
67
+ const JsonArgs&) {
68
+ static const auto* loader =
69
+ JsonObjectLoader<GrpcNode>()
70
+ .OptionalField("id", &GrpcNode::id_)
71
+ .OptionalField("cluster", &GrpcNode::cluster_)
72
+ .OptionalField("locality", &GrpcNode::locality_)
73
+ .OptionalField("metadata", &GrpcNode::metadata_)
74
+ .Finish();
75
+ return loader;
76
+ }
77
+
78
+ //
79
+ // GrpcXdsBootstrap::GrpcXdsServer::ChannelCreds
80
+ //
81
+
82
+ const JsonLoaderInterface*
83
+ GrpcXdsBootstrap::GrpcXdsServer::ChannelCreds::JsonLoader(const JsonArgs&) {
84
+ static const auto* loader =
85
+ JsonObjectLoader<ChannelCreds>()
86
+ .Field("type", &ChannelCreds::type)
87
+ .OptionalField("config", &ChannelCreds::config)
88
+ .Finish();
89
+ return loader;
90
+ }
91
+
92
+ //
93
+ // GrpcXdsBootstrap::GrpcXdsServer
94
+ //
95
+
96
+ namespace {
97
+
98
+ constexpr absl::string_view kServerFeatureXdsV3 = "xds_v3";
99
+ constexpr absl::string_view kServerFeatureIgnoreResourceDeletion =
100
+ "ignore_resource_deletion";
101
+
102
+ } // namespace
103
+
104
+ bool GrpcXdsBootstrap::GrpcXdsServer::ShouldUseV3() const {
105
+ return server_features_.find(std::string(kServerFeatureXdsV3)) !=
106
+ server_features_.end();
107
+ }
108
+
109
+ bool GrpcXdsBootstrap::GrpcXdsServer::IgnoreResourceDeletion() const {
110
+ return server_features_.find(std::string(
111
+ kServerFeatureIgnoreResourceDeletion)) != server_features_.end();
112
+ }
113
+
114
+ bool GrpcXdsBootstrap::GrpcXdsServer::Equals(const XdsServer& other) const {
115
+ const auto& o = static_cast<const GrpcXdsServer&>(other);
116
+ return (server_uri_ == o.server_uri_ &&
117
+ channel_creds_.type == o.channel_creds_.type &&
118
+ channel_creds_.config == o.channel_creds_.config &&
119
+ server_features_ == o.server_features_);
120
+ }
121
+
122
+ const JsonLoaderInterface* GrpcXdsBootstrap::GrpcXdsServer::JsonLoader(
123
+ const JsonArgs&) {
124
+ static const auto* loader =
125
+ JsonObjectLoader<GrpcXdsServer>()
126
+ .Field("server_uri", &GrpcXdsServer::server_uri_)
127
+ .Finish();
128
+ return loader;
129
+ }
130
+
131
+ void GrpcXdsBootstrap::GrpcXdsServer::JsonPostLoad(const Json& json,
132
+ const JsonArgs& args,
133
+ ValidationErrors* errors) {
134
+ // Parse "channel_creds".
135
+ auto channel_creds_list = LoadJsonObjectField<std::vector<ChannelCreds>>(
136
+ json.object_value(), args, "channel_creds", errors);
137
+ if (channel_creds_list.has_value()) {
138
+ ValidationErrors::ScopedField field(errors, ".channel_creds");
139
+ for (size_t i = 0; i < channel_creds_list->size(); ++i) {
140
+ ValidationErrors::ScopedField field(errors, absl::StrCat("[", i, "]"));
141
+ auto& creds = (*channel_creds_list)[i];
142
+ // Select the first channel creds type that we support.
143
+ if (channel_creds_.type.empty() &&
144
+ CoreConfiguration::Get().channel_creds_registry().IsSupported(
145
+ creds.type)) {
146
+ if (!CoreConfiguration::Get().channel_creds_registry().IsValidConfig(
147
+ creds.type, creds.config)) {
148
+ errors->AddError(absl::StrCat(
149
+ "invalid config for channel creds type \"", creds.type, "\""));
150
+ continue;
151
+ }
152
+ channel_creds_.type = std::move(creds.type);
153
+ channel_creds_.config = std::move(creds.config);
154
+ }
155
+ }
156
+ if (channel_creds_.type.empty()) {
157
+ errors->AddError("no known creds type found");
158
+ }
159
+ }
160
+ // Parse "server_features".
161
+ {
162
+ ValidationErrors::ScopedField field(errors, ".server_features");
163
+ auto it = json.object_value().find("server_features");
164
+ if (it != json.object_value().end()) {
165
+ if (it->second.type() != Json::Type::ARRAY) {
166
+ errors->AddError("is not an array");
167
+ } else {
168
+ const Json::Array& array = it->second.array_value();
169
+ for (const Json& feature_json : array) {
170
+ if (feature_json.type() == Json::Type::STRING &&
171
+ (feature_json.string_value() == kServerFeatureXdsV3 ||
172
+ feature_json.string_value() ==
173
+ kServerFeatureIgnoreResourceDeletion)) {
174
+ server_features_.insert(feature_json.string_value());
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ }
181
+
182
+ Json GrpcXdsBootstrap::GrpcXdsServer::ToJson() const {
183
+ Json::Object channel_creds_json{{"type", channel_creds_.type}};
184
+ if (!channel_creds_.config.empty()) {
185
+ channel_creds_json["config"] = channel_creds_.config;
186
+ }
187
+ Json::Object json{
188
+ {"server_uri", server_uri_},
189
+ {"channel_creds", Json::Array{std::move(channel_creds_json)}},
190
+ };
191
+ if (!server_features_.empty()) {
192
+ Json::Array server_features_json;
193
+ for (auto& feature : server_features_) {
194
+ server_features_json.emplace_back(feature);
195
+ }
196
+ json["server_features"] = std::move(server_features_json);
197
+ }
198
+ return json;
199
+ }
200
+
201
+ //
202
+ // GrpcXdsBootstrap::GrpcAuthority
203
+ //
204
+
205
+ const JsonLoaderInterface* GrpcXdsBootstrap::GrpcAuthority::JsonLoader(
206
+ const JsonArgs&) {
207
+ static const auto* loader =
208
+ JsonObjectLoader<GrpcAuthority>()
209
+ .OptionalField(
210
+ "client_listener_resource_name_template",
211
+ &GrpcAuthority::client_listener_resource_name_template_)
212
+ .OptionalField("xds_servers", &GrpcAuthority::servers_)
213
+ .Finish();
214
+ return loader;
215
+ }
216
+
217
+ //
218
+ // GrpcXdsBootstrap
219
+ //
220
+
221
+ absl::StatusOr<std::unique_ptr<GrpcXdsBootstrap>> GrpcXdsBootstrap::Create(
222
+ absl::string_view json_string) {
223
+ auto json = Json::Parse(json_string);
224
+ if (!json.ok()) {
225
+ return absl::InvalidArgumentError(absl::StrCat(
226
+ "Failed to parse bootstrap JSON string: ", json.status().ToString()));
227
+ }
228
+ // Validate JSON.
229
+ class XdsJsonArgs : public JsonArgs {
230
+ public:
231
+ bool IsEnabled(absl::string_view key) const override {
232
+ if (key == "federation") return XdsFederationEnabled();
233
+ return true;
234
+ }
235
+ };
236
+ auto bootstrap = LoadFromJson<GrpcXdsBootstrap>(*json, XdsJsonArgs());
237
+ if (!bootstrap.ok()) return bootstrap.status();
238
+ return absl::make_unique<GrpcXdsBootstrap>(std::move(*bootstrap));
239
+ }
240
+
241
+ const JsonLoaderInterface* GrpcXdsBootstrap::JsonLoader(const JsonArgs&) {
242
+ static const auto* loader =
243
+ JsonObjectLoader<GrpcXdsBootstrap>()
244
+ .Field("xds_servers", &GrpcXdsBootstrap::servers_)
245
+ .OptionalField("node", &GrpcXdsBootstrap::node_)
246
+ .OptionalField("certificate_providers",
247
+ &GrpcXdsBootstrap::certificate_providers_)
248
+ .OptionalField(
249
+ "server_listener_resource_name_template",
250
+ &GrpcXdsBootstrap::server_listener_resource_name_template_)
251
+ .OptionalField("authorities", &GrpcXdsBootstrap::authorities_,
252
+ "federation")
253
+ .OptionalField("client_default_listener_resource_name_template",
254
+ &GrpcXdsBootstrap::
255
+ client_default_listener_resource_name_template_,
256
+ "federation")
257
+ .Finish();
258
+ return loader;
259
+ }
260
+
261
+ void GrpcXdsBootstrap::JsonPostLoad(const Json& /*json*/,
262
+ const JsonArgs& /*args*/,
263
+ ValidationErrors* errors) {
264
+ // Verify that each authority has the right prefix in the
265
+ // client_listener_resource_name_template field.
266
+ {
267
+ ValidationErrors::ScopedField field(errors, ".authorities");
268
+ for (const auto& p : authorities_) {
269
+ const std::string& name = p.first;
270
+ const GrpcAuthority& authority =
271
+ static_cast<const GrpcAuthority&>(p.second);
272
+ ValidationErrors::ScopedField field(
273
+ errors, absl::StrCat("[\"", name,
274
+ "\"].client_listener_resource_name_template"));
275
+ std::string expected_prefix = absl::StrCat("xdstp://", name, "/");
276
+ if (!authority.client_listener_resource_name_template().empty() &&
277
+ !absl::StartsWith(authority.client_listener_resource_name_template(),
278
+ expected_prefix)) {
279
+ errors->AddError(
280
+ absl::StrCat("field must begin with \"", expected_prefix, "\""));
281
+ }
282
+ }
283
+ }
284
+ }
285
+
286
+ std::string GrpcXdsBootstrap::ToString() const {
287
+ std::vector<std::string> parts;
288
+ if (node_.has_value()) {
289
+ parts.push_back(
290
+ absl::StrFormat("node={\n"
291
+ " id=\"%s\",\n"
292
+ " cluster=\"%s\",\n"
293
+ " locality={\n"
294
+ " region=\"%s\",\n"
295
+ " zone=\"%s\",\n"
296
+ " sub_zone=\"%s\"\n"
297
+ " },\n"
298
+ " metadata=%s,\n"
299
+ "},\n",
300
+ node_->id(), node_->cluster(), node_->locality_region(),
301
+ node_->locality_zone(), node_->locality_sub_zone(),
302
+ Json{node_->metadata()}.Dump()));
303
+ }
304
+ parts.push_back(
305
+ absl::StrFormat("servers=[\n%s\n],\n", servers_[0].ToJson().Dump()));
306
+ if (!client_default_listener_resource_name_template_.empty()) {
307
+ parts.push_back(absl::StrFormat(
308
+ "client_default_listener_resource_name_template=\"%s\",\n",
309
+ client_default_listener_resource_name_template_));
310
+ }
311
+ if (!server_listener_resource_name_template_.empty()) {
312
+ parts.push_back(
313
+ absl::StrFormat("server_listener_resource_name_template=\"%s\",\n",
314
+ server_listener_resource_name_template_));
315
+ }
316
+ parts.push_back("authorities={\n");
317
+ for (const auto& entry : authorities_) {
318
+ parts.push_back(absl::StrFormat(" %s={\n", entry.first));
319
+ parts.push_back(
320
+ absl::StrFormat(" client_listener_resource_name_template=\"%s\",\n",
321
+ entry.second.client_listener_resource_name_template()));
322
+ if (entry.second.server() != nullptr) {
323
+ parts.push_back(absl::StrFormat(
324
+ " servers=[\n%s\n],\n",
325
+ static_cast<const GrpcXdsServer*>(entry.second.server())
326
+ ->ToJson()
327
+ .Dump()));
328
+ }
329
+ parts.push_back(" },\n");
330
+ }
331
+ parts.push_back("}\n");
332
+ parts.push_back("certificate_providers={\n");
333
+ for (const auto& entry : certificate_providers_) {
334
+ parts.push_back(
335
+ absl::StrFormat(" %s={\n"
336
+ " plugin_name=%s\n"
337
+ " config=%s\n"
338
+ " },\n",
339
+ entry.first, entry.second.plugin_name,
340
+ entry.second.config->ToString()));
341
+ }
342
+ parts.push_back("}");
343
+ return absl::StrJoin(parts, "");
344
+ }
345
+
346
+ const XdsBootstrap::Authority* GrpcXdsBootstrap::LookupAuthority(
347
+ const std::string& name) const {
348
+ auto it = authorities_.find(name);
349
+ if (it != authorities_.end()) {
350
+ return &it->second;
351
+ }
352
+ return nullptr;
353
+ }
354
+
355
+ const XdsBootstrap::XdsServer* GrpcXdsBootstrap::FindXdsServer(
356
+ const XdsBootstrap::XdsServer& server) const {
357
+ if (static_cast<const GrpcXdsServer&>(server) == servers_[0]) {
358
+ return &servers_[0];
359
+ }
360
+ for (auto& p : authorities_) {
361
+ const auto* authority_server =
362
+ static_cast<const GrpcXdsServer*>(p.second.server());
363
+ if (authority_server != nullptr && *authority_server == server) {
364
+ return authority_server;
365
+ }
366
+ }
367
+ return nullptr;
368
+ }
369
+
370
+ } // namespace grpc_core