grpc 1.49.1 → 1.50.0.pre1

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

Potentially problematic release.


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

Files changed (270) 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/version.rb +1 -1
  258. data/src/ruby/spec/channel_spec.rb +5 -0
  259. data/src/ruby/spec/generic/server_interceptors_spec.rb +1 -1
  260. data/src/ruby/spec/user_agent_spec.rb +1 -1
  261. metadata +33 -19
  262. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +0 -56
  263. data/src/core/ext/xds/certificate_provider_registry.cc +0 -103
  264. data/src/core/ext/xds/certificate_provider_registry.h +0 -59
  265. data/src/core/lib/event_engine/promise.h +0 -78
  266. data/src/core/lib/gpr/env_windows.cc +0 -74
  267. data/src/core/lib/gpr/string_windows.h +0 -32
  268. data/src/core/lib/profiling/basic_timers.cc +0 -295
  269. data/src/core/lib/profiling/stap_timers.cc +0 -50
  270. data/src/core/lib/profiling/timers.h +0 -94
@@ -18,553 +18,21 @@
18
18
 
19
19
  #include "src/core/ext/xds/xds_bootstrap.h"
20
20
 
21
- #include <stdlib.h>
21
+ #include "absl/types/optional.h"
22
22
 
23
- #include <utility>
24
- #include <vector>
25
-
26
- #include "absl/memory/memory.h"
27
- #include "absl/status/status.h"
28
- #include "absl/status/statusor.h"
29
- #include "absl/strings/match.h"
30
- #include "absl/strings/str_cat.h"
31
- #include "absl/strings/str_format.h"
32
- #include "absl/strings/str_join.h"
33
- #include "absl/strings/string_view.h"
34
-
35
- #include <grpc/support/alloc.h>
36
-
37
- #include "src/core/lib/config/core_configuration.h"
38
- #include "src/core/lib/gpr/env.h"
39
23
  #include "src/core/lib/gpr/string.h"
40
- #include "src/core/lib/json/json_util.h"
41
- #include "src/core/lib/security/credentials/channel_creds_registry.h"
42
- #include "src/core/lib/transport/error_utils.h"
24
+ #include "src/core/lib/gprpp/env.h"
43
25
 
44
26
  namespace grpc_core {
45
27
 
46
28
  // TODO(donnadionne): check to see if federation is enabled, this will be
47
29
  // removed once federation is fully integrated and enabled by default.
48
30
  bool XdsFederationEnabled() {
49
- char* value = gpr_getenv("GRPC_EXPERIMENTAL_XDS_FEDERATION");
31
+ auto value = GetEnv("GRPC_EXPERIMENTAL_XDS_FEDERATION");
32
+ if (!value.has_value()) return false;
50
33
  bool parsed_value;
51
- bool parse_succeeded = gpr_parse_bool_value(value, &parsed_value);
52
- gpr_free(value);
34
+ bool parse_succeeded = gpr_parse_bool_value(value->c_str(), &parsed_value);
53
35
  return parse_succeeded && parsed_value;
54
36
  }
55
37
 
56
- namespace {
57
-
58
- const absl::string_view kServerFeatureXdsV3 = "xds_v3";
59
- const absl::string_view kServerFeatureIgnoreResourceDeletion =
60
- "ignore_resource_deletion";
61
-
62
- grpc_error_handle ParseChannelCreds(const Json::Object& json, size_t idx,
63
- XdsBootstrap::XdsServer* server) {
64
- std::vector<grpc_error_handle> error_list;
65
- std::string type;
66
- ParseJsonObjectField(json, "type", &type, &error_list);
67
- const Json::Object* config_ptr = nullptr;
68
- ParseJsonObjectField(json, "config", &config_ptr, &error_list,
69
- /*required=*/false);
70
- // Select the first channel creds type that we support.
71
- if (server->channel_creds_type.empty() &&
72
- CoreConfiguration::Get().channel_creds_registry().IsSupported(type)) {
73
- Json config;
74
- if (config_ptr != nullptr) config = *config_ptr;
75
- if (!CoreConfiguration::Get().channel_creds_registry().IsValidConfig(
76
- type, config)) {
77
- error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
78
- "invalid config for channel creds type \"", type, "\"")));
79
- }
80
- server->channel_creds_type = std::move(type);
81
- server->channel_creds_config = std::move(config);
82
- }
83
- return GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING(
84
- absl::StrCat("errors parsing index ", idx), &error_list);
85
- }
86
-
87
- grpc_error_handle ParseChannelCredsArray(const Json::Array& json,
88
- XdsBootstrap::XdsServer* server) {
89
- std::vector<grpc_error_handle> error_list;
90
- for (size_t i = 0; i < json.size(); ++i) {
91
- const Json& child = json.at(i);
92
- if (child.type() != Json::Type::OBJECT) {
93
- error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(
94
- absl::StrCat("array element ", i, " is not an object")));
95
- } else {
96
- grpc_error_handle parse_error =
97
- ParseChannelCreds(child.object_value(), i, server);
98
- if (!GRPC_ERROR_IS_NONE(parse_error)) error_list.push_back(parse_error);
99
- }
100
- }
101
- if (server->channel_creds_type.empty()) {
102
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
103
- "no known creds type found in \"channel_creds\""));
104
- }
105
- return GRPC_ERROR_CREATE_FROM_VECTOR("errors parsing \"channel_creds\" array",
106
- &error_list);
107
- }
108
-
109
- } // namespace
110
-
111
- //
112
- // XdsBootstrap::XdsServer
113
- //
114
-
115
- XdsBootstrap::XdsServer XdsBootstrap::XdsServer::Parse(
116
- const Json& json, grpc_error_handle* error) {
117
- std::vector<grpc_error_handle> error_list;
118
- XdsServer server;
119
- ParseJsonObjectField(json.object_value(), "server_uri", &server.server_uri,
120
- &error_list);
121
- const Json::Array* creds_array = nullptr;
122
- ParseJsonObjectField(json.object_value(), "channel_creds", &creds_array,
123
- &error_list);
124
- if (creds_array != nullptr) {
125
- grpc_error_handle parse_error =
126
- ParseChannelCredsArray(*creds_array, &server);
127
- if (!GRPC_ERROR_IS_NONE(parse_error)) error_list.push_back(parse_error);
128
- }
129
- const Json::Array* server_features_array = nullptr;
130
- ParseJsonObjectField(json.object_value(), "server_features",
131
- &server_features_array, &error_list, /*required=*/false);
132
- if (server_features_array != nullptr) {
133
- for (const Json& feature_json : *server_features_array) {
134
- if (feature_json.type() == Json::Type::STRING &&
135
- (feature_json.string_value() == kServerFeatureXdsV3 ||
136
- feature_json.string_value() ==
137
- kServerFeatureIgnoreResourceDeletion)) {
138
- server.server_features.insert(feature_json.string_value());
139
- }
140
- }
141
- }
142
- *error = GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING(
143
- "errors parsing xds server", &error_list);
144
- return server;
145
- }
146
-
147
- Json::Object XdsBootstrap::XdsServer::ToJson() const {
148
- Json::Object channel_creds_json{{"type", channel_creds_type}};
149
- if (channel_creds_config.type() != Json::Type::JSON_NULL) {
150
- channel_creds_json["config"] = channel_creds_config;
151
- }
152
- Json::Object json{
153
- {"server_uri", server_uri},
154
- {"channel_creds", Json::Array{std::move(channel_creds_json)}},
155
- };
156
- if (!server_features.empty()) {
157
- Json::Array server_features_json;
158
- for (auto& feature : server_features) {
159
- server_features_json.emplace_back(feature);
160
- }
161
- json["server_features"] = std::move(server_features_json);
162
- }
163
- return json;
164
- }
165
-
166
- bool XdsBootstrap::XdsServer::ShouldUseV3() const {
167
- return server_features.find(std::string(kServerFeatureXdsV3)) !=
168
- server_features.end();
169
- }
170
-
171
- bool XdsBootstrap::XdsServer::IgnoreResourceDeletion() const {
172
- return server_features.find(std::string(
173
- kServerFeatureIgnoreResourceDeletion)) != server_features.end();
174
- }
175
-
176
- //
177
- // XdsBootstrap
178
- //
179
-
180
- std::unique_ptr<XdsBootstrap> XdsBootstrap::Create(
181
- absl::string_view json_string,
182
- std::unique_ptr<XdsCertificateProviderPluginMapInterface>
183
- certificate_provider_plugin_map,
184
- grpc_error_handle* error) {
185
- auto json = Json::Parse(json_string);
186
- if (!json.ok()) {
187
- *error = GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
188
- "Failed to parse bootstrap JSON string: ", json.status().ToString()));
189
- return nullptr;
190
- }
191
- return absl::make_unique<XdsBootstrap>(
192
- std::move(*json), std::move(certificate_provider_plugin_map), error);
193
- }
194
-
195
- XdsBootstrap::XdsBootstrap(
196
- Json json,
197
- std::unique_ptr<XdsCertificateProviderPluginMapInterface>
198
- certificate_provider_plugin_map,
199
- grpc_error_handle* error)
200
- : certificate_provider_plugin_map_(
201
- std::move(certificate_provider_plugin_map)) {
202
- if (json.type() != Json::Type::OBJECT) {
203
- *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
204
- "malformed JSON in bootstrap file");
205
- return;
206
- }
207
- std::vector<grpc_error_handle> error_list;
208
- auto it = json.mutable_object()->find("xds_servers");
209
- if (it == json.mutable_object()->end()) {
210
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
211
- "\"xds_servers\" field not present"));
212
- } else if (it->second.type() != Json::Type::ARRAY) {
213
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
214
- "\"xds_servers\" field is not an array"));
215
- } else {
216
- grpc_error_handle parse_error = ParseXdsServerList(&it->second, &servers_);
217
- if (!GRPC_ERROR_IS_NONE(parse_error)) error_list.push_back(parse_error);
218
- }
219
- it = json.mutable_object()->find("node");
220
- if (it != json.mutable_object()->end()) {
221
- if (it->second.type() != Json::Type::OBJECT) {
222
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
223
- "\"node\" field is not an object"));
224
- } else {
225
- grpc_error_handle parse_error = ParseNode(&it->second);
226
- if (!GRPC_ERROR_IS_NONE(parse_error)) error_list.push_back(parse_error);
227
- }
228
- }
229
- if (XdsFederationEnabled()) {
230
- it = json.mutable_object()->find("authorities");
231
- if (it != json.mutable_object()->end()) {
232
- if (it->second.type() != Json::Type::OBJECT) {
233
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
234
- "\"authorities\" field is not an object"));
235
- } else {
236
- grpc_error_handle parse_error = ParseAuthorities(&it->second);
237
- if (!GRPC_ERROR_IS_NONE(parse_error)) error_list.push_back(parse_error);
238
- }
239
- }
240
- it = json.mutable_object()->find(
241
- "client_default_listener_resource_name_template");
242
- if (it != json.mutable_object()->end()) {
243
- if (it->second.type() != Json::Type::STRING) {
244
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
245
- "\"client_default_listener_resource_name_template\" field is not a "
246
- "string"));
247
- } else {
248
- client_default_listener_resource_name_template_ =
249
- std::move(*it->second.mutable_string_value());
250
- }
251
- }
252
- }
253
- it = json.mutable_object()->find("server_listener_resource_name_template");
254
- if (it != json.mutable_object()->end()) {
255
- if (it->second.type() != Json::Type::STRING) {
256
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
257
- "\"server_listener_resource_name_template\" field is not a string"));
258
- } else {
259
- server_listener_resource_name_template_ =
260
- std::move(*it->second.mutable_string_value());
261
- }
262
- }
263
- it = json.mutable_object()->find("certificate_providers");
264
- if (it != json.mutable_object()->end()) {
265
- if (it->second.type() != Json::Type::OBJECT) {
266
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
267
- "\"certificate_providers\" field is not an object"));
268
- } else {
269
- grpc_error_handle parse_error = ParseCertificateProviders(&it->second);
270
- if (!GRPC_ERROR_IS_NONE(parse_error)) error_list.push_back(parse_error);
271
- }
272
- }
273
- *error = GRPC_ERROR_CREATE_FROM_VECTOR("errors parsing xds bootstrap file",
274
- &error_list);
275
- }
276
-
277
- const XdsBootstrap::Authority* XdsBootstrap::LookupAuthority(
278
- const std::string& name) const {
279
- auto it = authorities_.find(name);
280
- if (it != authorities_.end()) {
281
- return &it->second;
282
- }
283
- return nullptr;
284
- }
285
-
286
- bool XdsBootstrap::XdsServerExists(
287
- const XdsBootstrap::XdsServer& server) const {
288
- if (server == servers_[0]) return true;
289
- for (auto& authority : authorities_) {
290
- for (auto& xds_server : authority.second.xds_servers) {
291
- if (server == xds_server) return true;
292
- }
293
- }
294
- return false;
295
- }
296
-
297
- grpc_error_handle XdsBootstrap::ParseXdsServerList(
298
- Json* json, std::vector<XdsServer>* servers) {
299
- std::vector<grpc_error_handle> error_list;
300
- for (size_t i = 0; i < json->mutable_array()->size(); ++i) {
301
- Json& child = json->mutable_array()->at(i);
302
- if (child.type() != Json::Type::OBJECT) {
303
- error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(
304
- absl::StrCat("array element ", i, " is not an object")));
305
- } else {
306
- grpc_error_handle parse_error;
307
- servers->emplace_back(XdsServer::Parse(child, &parse_error));
308
- if (!GRPC_ERROR_IS_NONE(parse_error)) {
309
- error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(
310
- absl::StrCat("errors parsing index ", i)));
311
- error_list.push_back(parse_error);
312
- }
313
- }
314
- }
315
- return GRPC_ERROR_CREATE_FROM_VECTOR("errors parsing \"xds_servers\" array",
316
- &error_list);
317
- }
318
-
319
- grpc_error_handle XdsBootstrap::ParseAuthorities(Json* json) {
320
- std::vector<grpc_error_handle> error_list;
321
- for (auto& p : *(json->mutable_object())) {
322
- if (p.second.type() != Json::Type::OBJECT) {
323
- error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(
324
- "field:authorities element error: element is not a object"));
325
- continue;
326
- }
327
- grpc_error_handle parse_error = ParseAuthority(&p.second, p.first);
328
- if (!GRPC_ERROR_IS_NONE(parse_error)) error_list.push_back(parse_error);
329
- }
330
- return GRPC_ERROR_CREATE_FROM_VECTOR("errors parsing \"authorities\"",
331
- &error_list);
332
- }
333
-
334
- grpc_error_handle XdsBootstrap::ParseAuthority(Json* json,
335
- const std::string& name) {
336
- std::vector<grpc_error_handle> error_list;
337
- Authority authority;
338
- auto it =
339
- json->mutable_object()->find("client_listener_resource_name_template");
340
- if (it != json->mutable_object()->end()) {
341
- if (it->second.type() != Json::Type::STRING) {
342
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
343
- "\"client_listener_resource_name_template\" field is not a string"));
344
- } else {
345
- std::string expected_prefix = absl::StrCat("xdstp://", name, "/");
346
- if (!absl::StartsWith(it->second.string_value(), expected_prefix)) {
347
- error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(
348
- absl::StrCat("\"client_listener_resource_name_template\" field "
349
- "must begin with \"",
350
- expected_prefix, "\"")));
351
- } else {
352
- authority.client_listener_resource_name_template =
353
- std::move(*it->second.mutable_string_value());
354
- }
355
- }
356
- }
357
- it = json->mutable_object()->find("xds_servers");
358
- if (it != json->mutable_object()->end()) {
359
- if (it->second.type() != Json::Type::ARRAY) {
360
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
361
- "\"xds_servers\" field is not an array"));
362
- } else {
363
- grpc_error_handle parse_error =
364
- ParseXdsServerList(&it->second, &authority.xds_servers);
365
- if (!GRPC_ERROR_IS_NONE(parse_error)) error_list.push_back(parse_error);
366
- }
367
- }
368
- if (error_list.empty()) {
369
- authorities_[name] = std::move(authority);
370
- }
371
- return GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING(
372
- absl::StrCat("errors parsing authority ", name), &error_list);
373
- }
374
-
375
- grpc_error_handle XdsBootstrap::ParseNode(Json* json) {
376
- std::vector<grpc_error_handle> error_list;
377
- node_ = absl::make_unique<Node>();
378
- auto it = json->mutable_object()->find("id");
379
- if (it != json->mutable_object()->end()) {
380
- if (it->second.type() != Json::Type::STRING) {
381
- error_list.push_back(
382
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("\"id\" field is not a string"));
383
- } else {
384
- node_->id = std::move(*it->second.mutable_string_value());
385
- }
386
- }
387
- it = json->mutable_object()->find("cluster");
388
- if (it != json->mutable_object()->end()) {
389
- if (it->second.type() != Json::Type::STRING) {
390
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
391
- "\"cluster\" field is not a string"));
392
- } else {
393
- node_->cluster = std::move(*it->second.mutable_string_value());
394
- }
395
- }
396
- it = json->mutable_object()->find("locality");
397
- if (it != json->mutable_object()->end()) {
398
- if (it->second.type() != Json::Type::OBJECT) {
399
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
400
- "\"locality\" field is not an object"));
401
- } else {
402
- grpc_error_handle parse_error = ParseLocality(&it->second);
403
- if (!GRPC_ERROR_IS_NONE(parse_error)) error_list.push_back(parse_error);
404
- }
405
- }
406
- it = json->mutable_object()->find("metadata");
407
- if (it != json->mutable_object()->end()) {
408
- if (it->second.type() != Json::Type::OBJECT) {
409
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
410
- "\"metadata\" field is not an object"));
411
- } else {
412
- node_->metadata = std::move(it->second);
413
- }
414
- }
415
- return GRPC_ERROR_CREATE_FROM_VECTOR("errors parsing \"node\" object",
416
- &error_list);
417
- }
418
-
419
- grpc_error_handle XdsBootstrap::ParseLocality(Json* json) {
420
- std::vector<grpc_error_handle> error_list;
421
- auto it = json->mutable_object()->find("region");
422
- if (it != json->mutable_object()->end()) {
423
- if (it->second.type() != Json::Type::STRING) {
424
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
425
- "\"region\" field is not a string"));
426
- } else {
427
- node_->locality_region = std::move(*it->second.mutable_string_value());
428
- }
429
- }
430
- it = json->mutable_object()->find("zone");
431
- if (it != json->mutable_object()->end()) {
432
- if (it->second.type() != Json::Type::STRING) {
433
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
434
- "\"zone\" field is not a string"));
435
- } else {
436
- node_->locality_zone = std::move(*it->second.mutable_string_value());
437
- }
438
- }
439
- it = json->mutable_object()->find("sub_zone");
440
- if (it != json->mutable_object()->end()) {
441
- if (it->second.type() != Json::Type::STRING) {
442
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
443
- "\"sub_zone\" field is not a string"));
444
- } else {
445
- node_->locality_sub_zone = std::move(*it->second.mutable_string_value());
446
- }
447
- }
448
- return GRPC_ERROR_CREATE_FROM_VECTOR("errors parsing \"locality\" object",
449
- &error_list);
450
- }
451
-
452
- grpc_error_handle XdsBootstrap::ParseCertificateProviders(Json* json) {
453
- std::vector<grpc_error_handle> error_list;
454
- for (auto& certificate_provider : *(json->mutable_object())) {
455
- if (certificate_provider.second.type() != Json::Type::OBJECT) {
456
- error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrCat(
457
- "element \"", certificate_provider.first, "\" is not an object")));
458
- } else {
459
- grpc_error_handle parse_error = ParseCertificateProvider(
460
- certificate_provider.first, &certificate_provider.second);
461
- if (!GRPC_ERROR_IS_NONE(parse_error)) error_list.push_back(parse_error);
462
- }
463
- }
464
- return GRPC_ERROR_CREATE_FROM_VECTOR(
465
- "errors parsing \"certificate_providers\" object", &error_list);
466
- }
467
-
468
- grpc_error_handle XdsBootstrap::ParseCertificateProvider(
469
- const std::string& instance_name, Json* certificate_provider_json) {
470
- std::vector<grpc_error_handle> error_list;
471
- auto it = certificate_provider_json->mutable_object()->find("plugin_name");
472
- if (it == certificate_provider_json->mutable_object()->end()) {
473
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
474
- "\"plugin_name\" field not present"));
475
- } else if (it->second.type() != Json::Type::STRING) {
476
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
477
- "\"plugin_name\" field is not a string"));
478
- } else {
479
- std::string plugin_name = std::move(*(it->second.mutable_string_value()));
480
- it = certificate_provider_json->mutable_object()->find("config");
481
- if (it != certificate_provider_json->mutable_object()->end()) {
482
- if (it->second.type() != Json::Type::OBJECT) {
483
- error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
484
- "\"config\" field is not an object"));
485
- } else {
486
- absl::Status status = certificate_provider_plugin_map_->AddPlugin(
487
- instance_name, plugin_name, it->second);
488
- if (!status.ok()) {
489
- error_list.push_back(absl_status_to_grpc_error(status));
490
- }
491
- }
492
- } else {
493
- // "config" is an optional field, so create an empty JSON object.
494
- absl::Status status = certificate_provider_plugin_map_->AddPlugin(
495
- instance_name, plugin_name, Json::Object());
496
- if (!status.ok()) {
497
- error_list.push_back(absl_status_to_grpc_error(status));
498
- }
499
- }
500
- }
501
- return GRPC_ERROR_CREATE_FROM_VECTOR_AND_CPP_STRING(
502
- absl::StrCat("errors parsing element \"", instance_name, "\""),
503
- &error_list);
504
- }
505
-
506
- std::string XdsBootstrap::ToString() const {
507
- std::vector<std::string> parts;
508
- if (node_ != nullptr) {
509
- parts.push_back(absl::StrFormat(
510
- "node={\n"
511
- " id=\"%s\",\n"
512
- " cluster=\"%s\",\n"
513
- " locality={\n"
514
- " region=\"%s\",\n"
515
- " zone=\"%s\",\n"
516
- " sub_zone=\"%s\"\n"
517
- " },\n"
518
- " metadata=%s,\n"
519
- "},\n",
520
- node_->id, node_->cluster, node_->locality_region, node_->locality_zone,
521
- node_->locality_sub_zone, node_->metadata.Dump()));
522
- }
523
- parts.push_back(
524
- absl::StrFormat("servers=[\n"
525
- " {\n"
526
- " uri=\"%s\",\n"
527
- " creds_type=%s,\n",
528
- server().server_uri, server().channel_creds_type));
529
- if (server().channel_creds_config.type() != Json::Type::JSON_NULL) {
530
- parts.push_back(absl::StrFormat(" creds_config=%s,",
531
- server().channel_creds_config.Dump()));
532
- }
533
- if (!server().server_features.empty()) {
534
- parts.push_back(absl::StrCat(" server_features=[",
535
- absl::StrJoin(server().server_features, ", "),
536
- "],\n"));
537
- }
538
- parts.push_back(" }\n],\n");
539
- if (!client_default_listener_resource_name_template_.empty()) {
540
- parts.push_back(absl::StrFormat(
541
- "client_default_listener_resource_name_template=\"%s\",\n",
542
- client_default_listener_resource_name_template_));
543
- }
544
- if (!server_listener_resource_name_template_.empty()) {
545
- parts.push_back(
546
- absl::StrFormat("server_listener_resource_name_template=\"%s\",\n",
547
- server_listener_resource_name_template_));
548
- }
549
- parts.push_back("authorities={\n");
550
- for (const auto& entry : authorities_) {
551
- parts.push_back(absl::StrFormat(" %s={\n", entry.first));
552
- parts.push_back(
553
- absl::StrFormat(" client_listener_resource_name_template=\"%s\",\n",
554
- entry.second.client_listener_resource_name_template));
555
- parts.push_back(
556
- absl::StrFormat(" servers=[\n"
557
- " {\n"
558
- " uri=\"%s\",\n"
559
- " creds_type=%s,\n",
560
- entry.second.xds_servers[0].server_uri,
561
- entry.second.xds_servers[0].channel_creds_type));
562
- parts.push_back(" },\n");
563
- }
564
- parts.push_back("}");
565
- parts.push_back("certificate_providers=");
566
- parts.push_back(certificate_provider_plugin_map_->ToString());
567
- return absl::StrJoin(parts, "");
568
- }
569
-
570
38
  } // namespace grpc_core