grpc 1.31.0.pre1 → 1.33.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 (614) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +693 -16022
  3. data/include/grpc/grpc.h +0 -5
  4. data/include/grpc/grpc_security.h +47 -14
  5. data/include/grpc/impl/codegen/README.md +22 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +0 -5
  7. data/include/grpc/impl/codegen/port_platform.h +6 -1
  8. data/src/core/ext/filters/client_channel/backup_poller.cc +3 -2
  9. data/src/core/ext/filters/client_channel/client_channel.cc +264 -186
  10. data/src/core/ext/filters/client_channel/client_channel.h +1 -1
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +0 -3
  12. data/src/core/ext/filters/client_channel/config_selector.cc +0 -4
  13. data/src/core/ext/filters/client_channel/config_selector.h +34 -5
  14. data/src/core/ext/filters/client_channel/health/health_check_client.cc +6 -1
  15. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +2 -3
  16. data/src/core/ext/filters/client_channel/lb_policy.h +3 -1
  17. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +48 -35
  18. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +7 -5
  19. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +9 -6
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +126 -119
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +0 -13
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +0 -3
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -37
  24. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +21 -15
  25. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +32 -13
  26. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +8 -7
  27. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +9 -32
  28. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +26 -16
  29. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +207 -129
  30. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +453 -255
  31. data/src/core/ext/filters/client_channel/lb_policy/xds/eds_drop.cc +571 -0
  32. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +727 -0
  33. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +8 -1
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -1
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +3 -3
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +1 -1
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  38. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +1 -1
  39. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -1
  40. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +602 -58
  41. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h +28 -0
  42. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +8 -39
  43. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +4 -3
  44. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +49 -47
  45. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +5 -9
  46. data/src/core/ext/filters/client_channel/server_address.cc +120 -7
  47. data/src/core/ext/filters/client_channel/server_address.h +48 -21
  48. data/src/core/ext/filters/client_channel/service_config.cc +16 -13
  49. data/src/core/ext/filters/client_channel/service_config.h +7 -4
  50. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +2 -2
  51. data/src/core/ext/filters/client_channel/service_config_parser.cc +8 -6
  52. data/src/core/ext/filters/client_channel/service_config_parser.h +8 -5
  53. data/src/core/ext/filters/client_channel/subchannel.cc +64 -23
  54. data/src/core/ext/filters/client_channel/subchannel.h +16 -4
  55. data/src/core/ext/filters/client_channel/subchannel_interface.h +44 -0
  56. data/src/core/ext/filters/max_age/max_age_filter.cc +2 -1
  57. data/src/core/ext/filters/message_size/message_size_filter.cc +2 -1
  58. data/src/core/ext/filters/message_size/message_size_filter.h +2 -1
  59. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +87 -31
  60. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +18 -1
  61. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +10 -35
  62. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +19 -25
  63. data/src/core/ext/transport/chttp2/server/chttp2_server.h +2 -1
  64. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +2 -2
  65. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +6 -6
  66. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +3 -2
  67. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +256 -287
  68. data/src/core/ext/transport/chttp2/transport/flow_control.cc +11 -3
  69. data/src/core/ext/transport/chttp2/transport/flow_control.h +10 -0
  70. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +2 -2
  71. data/src/core/ext/transport/chttp2/transport/internal.h +10 -1
  72. data/src/core/ext/transport/chttp2/transport/parsing.cc +17 -30
  73. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -5
  74. data/src/core/ext/transport/inproc/inproc_transport.cc +12 -12
  75. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +244 -0
  76. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +766 -0
  77. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +74 -0
  78. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +226 -0
  79. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +458 -0
  80. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +1635 -0
  81. data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/filter.upb.c +8 -8
  82. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +69 -0
  83. data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/outlier_detection.upb.c +8 -8
  84. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +323 -0
  85. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +124 -0
  86. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +379 -0
  87. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/backoff.upb.c +8 -8
  88. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +79 -0
  89. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +310 -0
  90. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +869 -0
  91. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +103 -0
  92. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +351 -0
  93. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +34 -0
  94. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +71 -0
  95. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.c +53 -0
  96. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.h +133 -0
  97. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +241 -0
  98. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +752 -0
  99. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +170 -0
  100. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +684 -0
  101. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/http_uri.upb.c +8 -8
  102. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +80 -0
  103. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +176 -0
  104. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +645 -0
  105. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +28 -0
  106. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +58 -0
  107. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/socket_option.upb.c +6 -6
  108. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +88 -0
  109. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +36 -0
  110. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +85 -0
  111. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +91 -0
  112. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +220 -0
  113. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +91 -0
  114. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +273 -0
  115. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +112 -0
  116. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +332 -0
  117. data/src/core/ext/upb-generated/envoy/config/listener/{v2 → v3}/api_listener.upb.c +8 -8
  118. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +65 -0
  119. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +128 -0
  120. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +467 -0
  121. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +155 -0
  122. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +539 -0
  123. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +41 -0
  124. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +94 -0
  125. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +178 -0
  126. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +616 -0
  127. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +63 -0
  128. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +204 -0
  129. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +900 -0
  130. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +3290 -0
  131. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +60 -0
  132. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +139 -0
  133. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +50 -0
  134. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +108 -0
  135. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +364 -0
  136. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +1336 -0
  137. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.c +20 -0
  138. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.h +34 -0
  139. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +110 -0
  140. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +387 -0
  141. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +76 -0
  142. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +214 -0
  143. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +147 -0
  144. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +570 -0
  145. data/src/core/ext/upb-generated/envoy/{api/v2 → service/cluster/v3}/cds.upb.c +5 -6
  146. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.h +49 -0
  147. data/src/core/ext/upb-generated/envoy/service/discovery/{v2 → v3}/ads.upb.c +5 -4
  148. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.h +49 -0
  149. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +139 -0
  150. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +449 -0
  151. data/src/core/ext/upb-generated/envoy/{api/v2 → service/endpoint/v3}/eds.upb.c +5 -6
  152. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.h +49 -0
  153. data/src/core/ext/upb-generated/envoy/{api/v2 → service/listener/v3}/lds.upb.c +5 -6
  154. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.h +49 -0
  155. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +55 -0
  156. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +136 -0
  157. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/rds.upb.c +5 -6
  158. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.h +49 -0
  159. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/srds.upb.c +5 -6
  160. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.h +49 -0
  161. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +47 -0
  162. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +114 -0
  163. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +35 -0
  164. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +77 -0
  165. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +34 -0
  166. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +71 -0
  167. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +64 -0
  168. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +145 -0
  169. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +54 -0
  170. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +133 -0
  171. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +63 -0
  172. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +188 -0
  173. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +88 -0
  174. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +258 -0
  175. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +90 -0
  176. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +250 -0
  177. data/src/core/ext/upb-generated/envoy/type/{http.upb.c → v3/http.upb.c} +2 -2
  178. data/src/core/ext/upb-generated/envoy/type/{http.upb.h → v3/http.upb.h} +8 -8
  179. data/src/core/ext/upb-generated/envoy/type/{percent.upb.c → v3/percent.upb.c} +9 -8
  180. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +86 -0
  181. data/src/core/ext/upb-generated/envoy/type/{range.upb.c → v3/range.upb.c} +12 -11
  182. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +111 -0
  183. data/src/core/ext/upb-generated/envoy/type/{semantic_version.upb.c → v3/semantic_version.upb.c} +6 -5
  184. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +61 -0
  185. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c +242 -0
  186. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h +753 -0
  187. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +234 -0
  188. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +759 -0
  189. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +36 -36
  190. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +1 -1
  191. data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +31 -0
  192. data/src/core/ext/upb-generated/udpa/annotations/security.upb.h +57 -0
  193. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +27 -0
  194. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +53 -0
  195. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.c +28 -0
  196. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.h +53 -0
  197. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.c +52 -0
  198. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.h +129 -0
  199. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.c +42 -0
  200. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.h +77 -0
  201. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.c +36 -0
  202. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.h +85 -0
  203. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c +54 -0
  204. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.h +160 -0
  205. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c +36 -0
  206. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.h +84 -0
  207. data/src/core/ext/upb-generated/validate/validate.upb.c +11 -11
  208. data/src/core/ext/upb-generated/validate/validate.upb.h +1 -1
  209. data/src/core/ext/xds/certificate_provider_factory.h +59 -0
  210. data/src/core/ext/xds/certificate_provider_registry.cc +103 -0
  211. data/src/core/ext/xds/certificate_provider_registry.h +57 -0
  212. data/src/core/ext/xds/certificate_provider_store.h +50 -0
  213. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc +377 -0
  214. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.h +102 -0
  215. data/src/core/ext/xds/xds_api.cc +2596 -0
  216. data/src/core/ext/xds/xds_api.h +397 -0
  217. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.cc +44 -2
  218. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.h +8 -3
  219. data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel_args.h +9 -6
  220. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.cc +541 -785
  221. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.h +114 -93
  222. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.cc +20 -14
  223. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.h +36 -8
  224. data/src/core/lib/channel/channel_args.h +0 -1
  225. data/src/core/lib/channel/channelz.cc +24 -60
  226. data/src/core/lib/channel/channelz.h +12 -20
  227. data/src/core/lib/channel/channelz_registry.cc +15 -12
  228. data/src/core/lib/channel/channelz_registry.h +3 -0
  229. data/src/core/lib/gpr/sync_posix.cc +2 -8
  230. data/src/core/lib/gpr/time_precise.cc +2 -0
  231. data/src/core/lib/gpr/time_precise.h +6 -2
  232. data/src/core/lib/gprpp/dual_ref_counted.h +336 -0
  233. data/src/core/lib/gprpp/ref_counted.h +51 -22
  234. data/src/core/lib/gprpp/ref_counted_ptr.h +153 -0
  235. data/src/core/lib/iomgr/endpoint.cc +5 -1
  236. data/src/core/lib/iomgr/endpoint.h +7 -3
  237. data/src/core/lib/iomgr/endpoint_cfstream.cc +36 -11
  238. data/src/core/lib/iomgr/ev_posix.cc +0 -2
  239. data/src/core/lib/iomgr/exec_ctx.h +10 -8
  240. data/src/core/lib/iomgr/iomgr.cc +0 -10
  241. data/src/core/lib/iomgr/iomgr.h +0 -10
  242. data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.cc +1 -1
  243. data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.h +3 -3
  244. data/src/core/lib/iomgr/sockaddr_utils.cc +2 -1
  245. data/src/core/lib/iomgr/sockaddr_utils.h +2 -1
  246. data/src/core/lib/iomgr/tcp_custom.cc +32 -16
  247. data/src/core/lib/iomgr/tcp_posix.cc +31 -13
  248. data/src/core/lib/iomgr/tcp_windows.cc +26 -10
  249. data/src/core/lib/json/json_util.cc +58 -0
  250. data/src/core/lib/json/json_util.h +37 -0
  251. data/src/core/lib/security/authorization/authorization_engine.cc +177 -0
  252. data/src/core/lib/security/authorization/authorization_engine.h +84 -0
  253. data/src/core/lib/security/authorization/evaluate_args.cc +153 -0
  254. data/src/core/lib/security/authorization/evaluate_args.h +59 -0
  255. data/src/core/lib/security/authorization/mock_cel/activation.h +57 -0
  256. data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +42 -0
  257. data/src/core/lib/security/authorization/mock_cel/cel_expression.h +68 -0
  258. data/src/core/lib/security/authorization/mock_cel/cel_value.h +93 -0
  259. data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +67 -0
  260. data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +56 -0
  261. data/src/core/lib/security/authorization/mock_cel/statusor.h +50 -0
  262. data/src/core/lib/security/certificate_provider.h +60 -0
  263. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +56 -38
  264. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +321 -0
  265. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +214 -0
  266. data/src/core/lib/security/credentials/xds/xds_credentials.cc +45 -0
  267. data/src/core/lib/security/credentials/xds/xds_credentials.h +51 -0
  268. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +7 -12
  269. data/src/core/lib/security/security_connector/ssl_utils.h +5 -0
  270. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  271. data/src/core/lib/surface/call.cc +12 -12
  272. data/src/core/lib/surface/call.h +2 -1
  273. data/src/core/lib/surface/channel.cc +37 -51
  274. data/src/core/lib/surface/channel.h +18 -3
  275. data/src/core/lib/surface/completion_queue.cc +10 -272
  276. data/src/core/lib/surface/completion_queue.h +0 -8
  277. data/src/core/lib/surface/init.cc +27 -12
  278. data/src/core/lib/surface/server.cc +1066 -1244
  279. data/src/core/lib/surface/server.h +363 -87
  280. data/src/core/lib/surface/version.cc +2 -2
  281. data/src/core/lib/transport/authority_override.cc +38 -0
  282. data/src/core/lib/transport/authority_override.h +32 -0
  283. data/src/core/lib/transport/bdp_estimator.h +2 -1
  284. data/src/core/lib/transport/connectivity_state.cc +18 -13
  285. data/src/core/lib/transport/connectivity_state.h +20 -8
  286. data/src/core/lib/transport/error_utils.cc +13 -0
  287. data/src/core/lib/transport/error_utils.h +6 -0
  288. data/src/core/lib/transport/metadata.cc +11 -1
  289. data/src/core/lib/transport/static_metadata.cc +295 -276
  290. data/src/core/lib/transport/static_metadata.h +80 -73
  291. data/src/core/lib/transport/transport.h +7 -0
  292. data/src/core/lib/uri/uri_parser.cc +23 -21
  293. data/src/core/lib/uri/uri_parser.h +3 -1
  294. data/src/core/plugin_registry/grpc_plugin_registry.cc +35 -20
  295. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +22 -0
  296. data/src/core/tsi/ssl_transport_security.cc +2 -2
  297. data/src/ruby/bin/math_services_pb.rb +4 -4
  298. data/src/ruby/ext/grpc/rb_channel_credentials.c +9 -0
  299. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -4
  300. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +7 -7
  301. data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
  302. data/src/ruby/lib/grpc/version.rb +1 -1
  303. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +2 -2
  304. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +5 -0
  305. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +28 -12
  306. data/src/ruby/spec/channel_credentials_spec.rb +10 -0
  307. data/src/ruby/spec/generic/active_call_spec.rb +19 -8
  308. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  309. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  310. data/src/ruby/spec/pb/codegen/package_option_spec.rb +20 -0
  311. data/src/ruby/spec/user_agent_spec.rb +74 -0
  312. data/third_party/abseil-cpp/absl/algorithm/container.h +1727 -0
  313. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +161 -0
  314. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.cc +93 -0
  315. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.h +130 -0
  316. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +620 -0
  317. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.h +126 -0
  318. data/third_party/abseil-cpp/absl/container/fixed_array.h +515 -0
  319. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +503 -0
  320. data/third_party/abseil-cpp/absl/container/internal/common.h +202 -0
  321. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +440 -0
  322. data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +146 -0
  323. data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +191 -0
  324. data/third_party/abseil-cpp/absl/container/internal/hashtable_debug_hooks.h +85 -0
  325. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +269 -0
  326. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +297 -0
  327. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler_force_weak_definition.cc +30 -0
  328. data/third_party/abseil-cpp/absl/container/internal/have_sse.h +49 -0
  329. data/third_party/abseil-cpp/absl/container/internal/layout.h +741 -0
  330. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +48 -0
  331. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +1882 -0
  332. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +138 -0
  333. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.h +32 -0
  334. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +1895 -0
  335. data/third_party/abseil-cpp/absl/debugging/internal/demangle.h +71 -0
  336. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.cc +382 -0
  337. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +134 -0
  338. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +192 -0
  339. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +125 -0
  340. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +70 -0
  341. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +99 -0
  342. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +248 -0
  343. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_unimplemented-inl.inc +24 -0
  344. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +85 -0
  345. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +346 -0
  346. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +128 -0
  347. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +194 -0
  348. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.h +158 -0
  349. data/third_party/abseil-cpp/absl/debugging/stacktrace.cc +140 -0
  350. data/third_party/abseil-cpp/absl/debugging/stacktrace.h +231 -0
  351. data/third_party/abseil-cpp/absl/debugging/symbolize.cc +25 -0
  352. data/third_party/abseil-cpp/absl/debugging/symbolize.h +99 -0
  353. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +1480 -0
  354. data/third_party/abseil-cpp/absl/debugging/symbolize_unimplemented.inc +40 -0
  355. data/third_party/abseil-cpp/absl/debugging/symbolize_win32.inc +81 -0
  356. data/third_party/abseil-cpp/absl/functional/function_ref.h +139 -0
  357. data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +106 -0
  358. data/third_party/abseil-cpp/absl/hash/hash.h +324 -0
  359. data/third_party/abseil-cpp/absl/hash/internal/city.cc +346 -0
  360. data/third_party/abseil-cpp/absl/hash/internal/city.h +96 -0
  361. data/third_party/abseil-cpp/absl/hash/internal/hash.cc +55 -0
  362. data/third_party/abseil-cpp/absl/hash/internal/hash.h +988 -0
  363. data/third_party/abseil-cpp/absl/status/status.cc +447 -0
  364. data/third_party/abseil-cpp/absl/status/status.h +428 -0
  365. data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +43 -0
  366. data/third_party/abseil-cpp/absl/status/status_payload_printer.h +51 -0
  367. data/third_party/abseil-cpp/absl/strings/cord.cc +2019 -0
  368. data/third_party/abseil-cpp/absl/strings/cord.h +1121 -0
  369. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +151 -0
  370. data/third_party/abseil-cpp/absl/synchronization/barrier.cc +52 -0
  371. data/third_party/abseil-cpp/absl/synchronization/barrier.h +79 -0
  372. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.cc +57 -0
  373. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.h +99 -0
  374. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +140 -0
  375. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.h +60 -0
  376. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +697 -0
  377. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.h +141 -0
  378. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +155 -0
  379. data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +261 -0
  380. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +106 -0
  381. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +115 -0
  382. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +484 -0
  383. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +159 -0
  384. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +2728 -0
  385. data/third_party/abseil-cpp/absl/synchronization/mutex.h +1056 -0
  386. data/third_party/abseil-cpp/absl/synchronization/notification.cc +78 -0
  387. data/third_party/abseil-cpp/absl/synchronization/notification.h +123 -0
  388. data/third_party/abseil-cpp/absl/types/bad_variant_access.cc +64 -0
  389. data/third_party/abseil-cpp/absl/types/bad_variant_access.h +82 -0
  390. data/third_party/abseil-cpp/absl/types/internal/variant.h +1646 -0
  391. data/third_party/abseil-cpp/absl/types/variant.h +861 -0
  392. data/third_party/boringssl-with-bazel/err_data.c +475 -467
  393. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +0 -6
  394. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +9 -43
  395. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa_asn1.c +55 -4
  396. data/third_party/boringssl-with-bazel/src/crypto/dsa/internal.h +34 -0
  397. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +4 -0
  398. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.c +16 -0
  399. data/third_party/boringssl-with-bazel/src/crypto/evp/p_dsa_asn1.c +6 -2
  400. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +2 -0
  401. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +4 -0
  402. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +30 -10
  403. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +10 -15
  404. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +543 -0
  405. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +237 -0
  406. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +44 -2
  407. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +221 -49
  408. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +64 -20
  409. data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +3 -3
  410. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +0 -8
  411. data/third_party/boringssl-with-bazel/src/crypto/x509/t_crl.c +3 -3
  412. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509.c +1 -1
  413. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +7 -2
  414. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_ext.c +21 -18
  415. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_obj.c +1 -1
  416. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +24 -3
  417. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +3 -3
  418. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_txt.c +67 -67
  419. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +3 -3
  420. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +29 -35
  421. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +13 -2
  422. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +9 -8
  423. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +10 -10
  424. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +2 -2
  425. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +28 -40
  426. data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +20 -0
  427. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +3 -1
  428. data/third_party/boringssl-with-bazel/src/crypto/x509v3/ext_dat.h +1 -4
  429. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_conf.c +7 -3
  430. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_genn.c +2 -2
  431. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_info.c +1 -1
  432. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +55 -8
  433. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +1 -1
  434. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +52 -0
  435. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +0 -1
  436. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +2 -2
  437. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +6 -0
  438. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +1 -1
  439. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +12 -0
  440. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +9 -0
  441. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +4 -1
  442. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +48 -9
  443. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +2 -3
  444. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +26 -6
  445. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +199 -78
  446. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +52 -43
  447. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +18 -18
  448. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +2 -3
  449. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +1 -1
  450. data/third_party/boringssl-with-bazel/src/ssl/internal.h +13 -9
  451. data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +3 -6
  452. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +8 -9
  453. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +10 -0
  454. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +34 -9
  455. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +1 -2
  456. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +4 -8
  457. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +7 -2
  458. data/third_party/boringssl-with-bazel/src/ssl/tls_record.cc +5 -3
  459. data/third_party/re2/re2/bitmap256.h +117 -0
  460. data/third_party/re2/re2/bitstate.cc +385 -0
  461. data/third_party/re2/re2/compile.cc +1279 -0
  462. data/third_party/re2/re2/dfa.cc +2130 -0
  463. data/third_party/re2/re2/filtered_re2.cc +121 -0
  464. data/third_party/re2/re2/filtered_re2.h +109 -0
  465. data/third_party/re2/re2/mimics_pcre.cc +197 -0
  466. data/third_party/re2/re2/nfa.cc +713 -0
  467. data/third_party/re2/re2/onepass.cc +623 -0
  468. data/third_party/re2/re2/parse.cc +2464 -0
  469. data/third_party/re2/re2/perl_groups.cc +119 -0
  470. data/third_party/re2/re2/pod_array.h +55 -0
  471. data/third_party/re2/re2/prefilter.cc +710 -0
  472. data/third_party/re2/re2/prefilter.h +108 -0
  473. data/third_party/re2/re2/prefilter_tree.cc +407 -0
  474. data/third_party/re2/re2/prefilter_tree.h +139 -0
  475. data/third_party/re2/re2/prog.cc +988 -0
  476. data/third_party/re2/re2/prog.h +436 -0
  477. data/third_party/re2/re2/re2.cc +1362 -0
  478. data/third_party/re2/re2/re2.h +1002 -0
  479. data/third_party/re2/re2/regexp.cc +980 -0
  480. data/third_party/re2/re2/regexp.h +659 -0
  481. data/third_party/re2/re2/set.cc +154 -0
  482. data/third_party/re2/re2/set.h +80 -0
  483. data/third_party/re2/re2/simplify.cc +657 -0
  484. data/third_party/re2/re2/sparse_array.h +392 -0
  485. data/third_party/re2/re2/sparse_set.h +264 -0
  486. data/third_party/re2/re2/stringpiece.cc +65 -0
  487. data/third_party/re2/re2/stringpiece.h +210 -0
  488. data/third_party/re2/re2/tostring.cc +351 -0
  489. data/third_party/re2/re2/unicode_casefold.cc +582 -0
  490. data/third_party/re2/re2/unicode_casefold.h +78 -0
  491. data/third_party/re2/re2/unicode_groups.cc +6269 -0
  492. data/third_party/re2/re2/unicode_groups.h +67 -0
  493. data/third_party/re2/re2/walker-inl.h +246 -0
  494. data/third_party/re2/util/benchmark.h +156 -0
  495. data/third_party/re2/util/flags.h +26 -0
  496. data/third_party/re2/util/logging.h +109 -0
  497. data/third_party/re2/util/malloc_counter.h +19 -0
  498. data/third_party/re2/util/mix.h +41 -0
  499. data/third_party/re2/util/mutex.h +148 -0
  500. data/third_party/re2/util/pcre.cc +1025 -0
  501. data/third_party/re2/util/pcre.h +681 -0
  502. data/third_party/re2/util/rune.cc +260 -0
  503. data/third_party/re2/util/strutil.cc +149 -0
  504. data/third_party/re2/util/strutil.h +21 -0
  505. data/third_party/re2/util/test.h +50 -0
  506. data/third_party/re2/util/utf.h +44 -0
  507. data/third_party/re2/util/util.h +42 -0
  508. data/third_party/upb/upb/decode.c +64 -15
  509. data/third_party/upb/upb/encode.c +2 -2
  510. data/third_party/upb/upb/msg.h +2 -2
  511. data/third_party/upb/upb/port_def.inc +1 -1
  512. data/third_party/upb/upb/table.c +0 -11
  513. data/third_party/upb/upb/table.int.h +0 -9
  514. data/third_party/upb/upb/upb.c +16 -14
  515. data/third_party/upb/upb/upb.h +26 -0
  516. data/third_party/upb/upb/upb.hpp +2 -0
  517. metadata +340 -153
  518. data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +0 -528
  519. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +0 -1142
  520. data/src/core/ext/filters/client_channel/xds/xds_api.cc +0 -2110
  521. data/src/core/ext/filters/client_channel/xds/xds_api.h +0 -345
  522. data/src/core/ext/filters/client_channel/xds/xds_channel.h +0 -46
  523. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +0 -106
  524. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +0 -21
  525. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +0 -34
  526. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.c +0 -114
  527. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +0 -429
  528. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.c +0 -72
  529. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +0 -198
  530. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.c +0 -105
  531. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +0 -388
  532. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +0 -52
  533. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +0 -403
  534. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +0 -1453
  535. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +0 -74
  536. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +0 -226
  537. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +0 -69
  538. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +0 -323
  539. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +0 -112
  540. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +0 -334
  541. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +0 -79
  542. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +0 -313
  543. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +0 -891
  544. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +0 -96
  545. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +0 -328
  546. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.c +0 -34
  547. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +0 -71
  548. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +0 -197
  549. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +0 -649
  550. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +0 -172
  551. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +0 -693
  552. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +0 -80
  553. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +0 -152
  554. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +0 -536
  555. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +0 -88
  556. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +0 -129
  557. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +0 -386
  558. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +0 -52
  559. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +0 -92
  560. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.h +0 -224
  561. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +0 -18
  562. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +0 -32
  563. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.c +0 -91
  564. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +0 -273
  565. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +0 -112
  566. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +0 -332
  567. data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.h +0 -52
  568. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.c +0 -109
  569. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +0 -415
  570. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.c +0 -18
  571. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.h +0 -32
  572. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +0 -145
  573. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.h +0 -538
  574. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.c +0 -43
  575. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.h +0 -111
  576. data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.h +0 -52
  577. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.c +0 -63
  578. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.h +0 -204
  579. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.c +0 -18
  580. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.h +0 -32
  581. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +0 -815
  582. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +0 -2984
  583. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.c +0 -59
  584. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.h +0 -135
  585. data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.h +0 -52
  586. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +0 -228
  587. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.h +0 -732
  588. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.c +0 -316
  589. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +0 -1167
  590. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.h +0 -65
  591. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.c +0 -51
  592. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +0 -125
  593. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +0 -49
  594. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +0 -54
  595. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +0 -136
  596. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.c +0 -63
  597. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +0 -145
  598. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.c +0 -53
  599. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.h +0 -133
  600. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.c +0 -88
  601. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.h +0 -258
  602. data/src/core/ext/upb-generated/envoy/type/percent.upb.h +0 -86
  603. data/src/core/ext/upb-generated/envoy/type/range.upb.h +0 -111
  604. data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.h +0 -61
  605. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.c +0 -89
  606. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.h +0 -250
  607. data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +0 -17
  608. data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +0 -29
  609. data/src/core/lib/security/transport/target_authority_table.cc +0 -75
  610. data/src/core/lib/security/transport/target_authority_table.h +0 -40
  611. data/src/core/lib/slice/slice_hash_table.h +0 -199
  612. data/src/core/lib/slice/slice_weak_hash_table.h +0 -102
  613. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_pku.c +0 -110
  614. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_sxnet.c +0 -274
@@ -0,0 +1,102 @@
1
+ //
2
+ //
3
+ // Copyright 2020 gRPC authors.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 (the "License");
6
+ // you may not use this file except in compliance with the License.
7
+ // You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS IS" BASIS,
13
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ // See the License for the specific language governing permissions and
15
+ // limitations under the License.
16
+ //
17
+ //
18
+
19
+ #ifndef GRPC_CORE_EXT_XDS_GOOGLE_MESH_CA_CERTIFICATE_PROVIDER_FACTORY_H
20
+ #define GRPC_CORE_EXT_XDS_GOOGLE_MESH_CA_CERTIFICATE_PROVIDER_FACTORY_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include "src/core/ext/xds/certificate_provider_factory.h"
25
+ #include "src/core/lib/backoff/backoff.h"
26
+ #include "src/core/lib/gprpp/ref_counted.h"
27
+
28
+ namespace grpc_core {
29
+
30
+ class GoogleMeshCaCertificateProviderFactory
31
+ : public CertificateProviderFactory {
32
+ public:
33
+ class Config : public CertificateProviderFactory::Config {
34
+ public:
35
+ struct StsConfig {
36
+ std::string token_exchange_service_uri;
37
+ std::string resource;
38
+ std::string audience;
39
+ std::string scope;
40
+ std::string requested_token_type;
41
+ std::string subject_token_path;
42
+ std::string subject_token_type;
43
+ std::string actor_token_path;
44
+ std::string actor_token_type;
45
+ };
46
+
47
+ const char* name() const override;
48
+
49
+ const std::string& endpoint() const { return endpoint_; }
50
+
51
+ const StsConfig& sts_config() const { return sts_config_; }
52
+
53
+ grpc_millis timeout() const { return timeout_; }
54
+
55
+ grpc_millis certificate_lifetime() const { return certificate_lifetime_; }
56
+
57
+ grpc_millis renewal_grace_period() const { return renewal_grace_period_; }
58
+
59
+ uint32_t key_size() const { return key_size_; }
60
+
61
+ const std::string& location() const { return location_; }
62
+
63
+ static std::unique_ptr<Config> Parse(const Json& config_json,
64
+ grpc_error** error);
65
+
66
+ private:
67
+ // Helpers for parsing the config
68
+ std::vector<grpc_error*> ParseJsonObjectStsService(
69
+ const Json::Object& sts_service);
70
+ std::vector<grpc_error*> ParseJsonObjectCallCredentials(
71
+ const Json::Object& call_credentials);
72
+ std::vector<grpc_error*> ParseJsonObjectGoogleGrpc(
73
+ const Json::Object& google_grpc);
74
+ std::vector<grpc_error*> ParseJsonObjectGrpcServices(
75
+ const Json::Object& grpc_service);
76
+ std::vector<grpc_error*> ParseJsonObjectServer(const Json::Object& server);
77
+
78
+ std::string endpoint_;
79
+ StsConfig sts_config_;
80
+ grpc_millis timeout_;
81
+ grpc_millis certificate_lifetime_;
82
+ grpc_millis renewal_grace_period_;
83
+ uint32_t key_size_;
84
+ std::string location_;
85
+ };
86
+
87
+ const char* name() const override;
88
+
89
+ std::unique_ptr<CertificateProviderFactory::Config>
90
+ CreateCertificateProviderConfig(const Json& config_json,
91
+ grpc_error** error) override;
92
+
93
+ RefCountedPtr<grpc_tls_certificate_provider> CreateCertificateProvider(
94
+ std::unique_ptr<CertificateProviderFactory::Config> config) override {
95
+ // TODO(yashykt) : To be implemented
96
+ return nullptr;
97
+ }
98
+ };
99
+
100
+ } // namespace grpc_core
101
+
102
+ #endif // GRPC_CORE_EXT_XDS_GOOGLE_MESH_CA_CERTIFICATE_PROVIDER_FACTORY_H
@@ -0,0 +1,2596 @@
1
+ /*
2
+ *
3
+ * Copyright 2018 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #include <grpc/support/port_platform.h>
20
+
21
+ #include <algorithm>
22
+ #include <cctype>
23
+ #include <cstdint>
24
+ #include <cstdlib>
25
+ #include <string>
26
+
27
+ #include "absl/strings/str_cat.h"
28
+ #include "absl/strings/str_format.h"
29
+ #include "absl/strings/str_join.h"
30
+ #include "absl/strings/str_split.h"
31
+
32
+ #include "upb/upb.hpp"
33
+
34
+ #include <grpc/impl/codegen/log.h>
35
+ #include <grpc/support/alloc.h>
36
+ #include <grpc/support/string_util.h>
37
+
38
+ #include "src/core/ext/xds/xds_api.h"
39
+ #include "src/core/lib/gpr/env.h"
40
+ #include "src/core/lib/gpr/string.h"
41
+ #include "src/core/lib/gpr/useful.h"
42
+ #include "src/core/lib/iomgr/error.h"
43
+ #include "src/core/lib/iomgr/sockaddr_utils.h"
44
+
45
+ #include "envoy/config/cluster/v3/circuit_breaker.upb.h"
46
+ #include "envoy/config/cluster/v3/cluster.upb.h"
47
+ #include "envoy/config/core/v3/address.upb.h"
48
+ #include "envoy/config/core/v3/base.upb.h"
49
+ #include "envoy/config/core/v3/config_source.upb.h"
50
+ #include "envoy/config/core/v3/health_check.upb.h"
51
+ #include "envoy/config/endpoint/v3/endpoint.upb.h"
52
+ #include "envoy/config/endpoint/v3/endpoint_components.upb.h"
53
+ #include "envoy/config/endpoint/v3/load_report.upb.h"
54
+ #include "envoy/config/listener/v3/api_listener.upb.h"
55
+ #include "envoy/config/listener/v3/listener.upb.h"
56
+ #include "envoy/config/route/v3/route.upb.h"
57
+ #include "envoy/config/route/v3/route_components.upb.h"
58
+ #include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h"
59
+ #include "envoy/extensions/transport_sockets/tls/v3/common.upb.h"
60
+ #include "envoy/extensions/transport_sockets/tls/v3/tls.upb.h"
61
+ #include "envoy/service/cluster/v3/cds.upb.h"
62
+ #include "envoy/service/discovery/v3/discovery.upb.h"
63
+ #include "envoy/service/endpoint/v3/eds.upb.h"
64
+ #include "envoy/service/listener/v3/lds.upb.h"
65
+ #include "envoy/service/load_stats/v3/lrs.upb.h"
66
+ #include "envoy/service/route/v3/rds.upb.h"
67
+ #include "envoy/type/matcher/v3/regex.upb.h"
68
+ #include "envoy/type/matcher/v3/string.upb.h"
69
+ #include "envoy/type/v3/percent.upb.h"
70
+ #include "envoy/type/v3/range.upb.h"
71
+ #include "google/protobuf/any.upb.h"
72
+ #include "google/protobuf/duration.upb.h"
73
+ #include "google/protobuf/struct.upb.h"
74
+ #include "google/protobuf/wrappers.upb.h"
75
+ #include "google/rpc/status.upb.h"
76
+ #include "upb/upb.h"
77
+
78
+ namespace grpc_core {
79
+
80
+ //
81
+ // XdsApi::Route::Matchers::PathMatcher
82
+ //
83
+
84
+ XdsApi::Route::Matchers::PathMatcher::PathMatcher(const PathMatcher& other)
85
+ : type(other.type) {
86
+ if (type == PathMatcherType::REGEX) {
87
+ regex_matcher = absl::make_unique<RE2>(other.regex_matcher->pattern());
88
+ } else {
89
+ string_matcher = other.string_matcher;
90
+ }
91
+ }
92
+
93
+ XdsApi::Route::Matchers::PathMatcher& XdsApi::Route::Matchers::PathMatcher::
94
+ operator=(const PathMatcher& other) {
95
+ type = other.type;
96
+ if (type == PathMatcherType::REGEX) {
97
+ regex_matcher = absl::make_unique<RE2>(other.regex_matcher->pattern());
98
+ } else {
99
+ string_matcher = other.string_matcher;
100
+ }
101
+ return *this;
102
+ }
103
+
104
+ bool XdsApi::Route::Matchers::PathMatcher::operator==(
105
+ const PathMatcher& other) const {
106
+ if (type != other.type) return false;
107
+ if (type == PathMatcherType::REGEX) {
108
+ // Should never be null.
109
+ if (regex_matcher == nullptr || other.regex_matcher == nullptr) {
110
+ return false;
111
+ }
112
+ return regex_matcher->pattern() == other.regex_matcher->pattern();
113
+ }
114
+ return string_matcher == other.string_matcher;
115
+ }
116
+
117
+ std::string XdsApi::Route::Matchers::PathMatcher::ToString() const {
118
+ std::string path_type_string;
119
+ switch (type) {
120
+ case PathMatcherType::PATH:
121
+ path_type_string = "path match";
122
+ break;
123
+ case PathMatcherType::PREFIX:
124
+ path_type_string = "prefix match";
125
+ break;
126
+ case PathMatcherType::REGEX:
127
+ path_type_string = "regex match";
128
+ break;
129
+ default:
130
+ break;
131
+ }
132
+ return absl::StrFormat("Path %s:%s", path_type_string,
133
+ type == PathMatcherType::REGEX
134
+ ? regex_matcher->pattern()
135
+ : string_matcher);
136
+ }
137
+
138
+ //
139
+ // XdsApi::Route::Matchers::HeaderMatcher
140
+ //
141
+
142
+ XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcher(
143
+ const HeaderMatcher& other)
144
+ : name(other.name), type(other.type), invert_match(other.invert_match) {
145
+ switch (type) {
146
+ case HeaderMatcherType::REGEX:
147
+ regex_match = absl::make_unique<RE2>(other.regex_match->pattern());
148
+ break;
149
+ case HeaderMatcherType::RANGE:
150
+ range_start = other.range_start;
151
+ range_end = other.range_end;
152
+ break;
153
+ case HeaderMatcherType::PRESENT:
154
+ present_match = other.present_match;
155
+ break;
156
+ default:
157
+ string_matcher = other.string_matcher;
158
+ }
159
+ }
160
+
161
+ XdsApi::Route::Matchers::HeaderMatcher& XdsApi::Route::Matchers::HeaderMatcher::
162
+ operator=(const HeaderMatcher& other) {
163
+ name = other.name;
164
+ type = other.type;
165
+ invert_match = other.invert_match;
166
+ switch (type) {
167
+ case HeaderMatcherType::REGEX:
168
+ regex_match = absl::make_unique<RE2>(other.regex_match->pattern());
169
+ break;
170
+ case HeaderMatcherType::RANGE:
171
+ range_start = other.range_start;
172
+ range_end = other.range_end;
173
+ break;
174
+ case HeaderMatcherType::PRESENT:
175
+ present_match = other.present_match;
176
+ break;
177
+ default:
178
+ string_matcher = other.string_matcher;
179
+ }
180
+ return *this;
181
+ }
182
+
183
+ bool XdsApi::Route::Matchers::HeaderMatcher::operator==(
184
+ const HeaderMatcher& other) const {
185
+ if (name != other.name) return false;
186
+ if (type != other.type) return false;
187
+ if (invert_match != other.invert_match) return false;
188
+ switch (type) {
189
+ case HeaderMatcherType::REGEX:
190
+ return regex_match->pattern() != other.regex_match->pattern();
191
+ case HeaderMatcherType::RANGE:
192
+ return range_start != other.range_start && range_end != other.range_end;
193
+ case HeaderMatcherType::PRESENT:
194
+ return present_match != other.present_match;
195
+ default:
196
+ return string_matcher != other.string_matcher;
197
+ }
198
+ }
199
+
200
+ std::string XdsApi::Route::Matchers::HeaderMatcher::ToString() const {
201
+ switch (type) {
202
+ case HeaderMatcherType::EXACT:
203
+ return absl::StrFormat("Header exact match:%s %s:%s",
204
+ invert_match ? " not" : "", name, string_matcher);
205
+ case HeaderMatcherType::REGEX:
206
+ return absl::StrFormat("Header regex match:%s %s:%s",
207
+ invert_match ? " not" : "", name,
208
+ regex_match->pattern());
209
+ case HeaderMatcherType::RANGE:
210
+ return absl::StrFormat("Header range match:%s %s:[%d, %d)",
211
+ invert_match ? " not" : "", name, range_start,
212
+ range_end);
213
+ case HeaderMatcherType::PRESENT:
214
+ return absl::StrFormat("Header present match:%s %s:%s",
215
+ invert_match ? " not" : "", name,
216
+ present_match ? "true" : "false");
217
+ case HeaderMatcherType::PREFIX:
218
+ return absl::StrFormat("Header prefix match:%s %s:%s",
219
+ invert_match ? " not" : "", name, string_matcher);
220
+ case HeaderMatcherType::SUFFIX:
221
+ return absl::StrFormat("Header suffix match:%s %s:%s",
222
+ invert_match ? " not" : "", name, string_matcher);
223
+ default:
224
+ return "";
225
+ }
226
+ }
227
+
228
+ //
229
+ // XdsApi::Route
230
+ //
231
+
232
+ std::string XdsApi::Route::Matchers::ToString() const {
233
+ std::vector<std::string> contents;
234
+ contents.push_back(path_matcher.ToString());
235
+ for (const HeaderMatcher& header_matcher : header_matchers) {
236
+ contents.push_back(header_matcher.ToString());
237
+ }
238
+ if (fraction_per_million.has_value()) {
239
+ contents.push_back(absl::StrFormat("Fraction Per Million %d",
240
+ fraction_per_million.value()));
241
+ }
242
+ return absl::StrJoin(contents, "\n");
243
+ }
244
+
245
+ std::string XdsApi::Route::ClusterWeight::ToString() const {
246
+ return absl::StrFormat("{cluster=%s, weight=%d}", name, weight);
247
+ }
248
+
249
+ std::string XdsApi::Route::ToString() const {
250
+ std::vector<std::string> contents;
251
+ contents.push_back(matchers.ToString());
252
+ if (!cluster_name.empty()) {
253
+ contents.push_back(absl::StrFormat("Cluster name: %s", cluster_name));
254
+ }
255
+ for (const ClusterWeight& cluster_weight : weighted_clusters) {
256
+ contents.push_back(cluster_weight.ToString());
257
+ }
258
+ return absl::StrJoin(contents, "\n");
259
+ }
260
+
261
+ //
262
+ // XdsApi::RdsUpdate
263
+ //
264
+
265
+ std::string XdsApi::RdsUpdate::ToString() const {
266
+ std::vector<std::string> vhosts;
267
+ for (const VirtualHost& vhost : virtual_hosts) {
268
+ vhosts.push_back(
269
+ absl::StrCat("vhost={\n"
270
+ " domains=[",
271
+ absl::StrJoin(vhost.domains, ", "),
272
+ "]\n"
273
+ " routes=[\n"));
274
+ for (const XdsApi::Route& route : vhost.routes) {
275
+ vhosts.push_back(" {\n");
276
+ vhosts.push_back(route.ToString());
277
+ vhosts.push_back("\n }\n");
278
+ }
279
+ vhosts.push_back(" ]\n");
280
+ vhosts.push_back("]\n");
281
+ }
282
+ return absl::StrJoin(vhosts, "");
283
+ }
284
+
285
+ namespace {
286
+
287
+ // Better match type has smaller value.
288
+ enum MatchType {
289
+ EXACT_MATCH,
290
+ SUFFIX_MATCH,
291
+ PREFIX_MATCH,
292
+ UNIVERSE_MATCH,
293
+ INVALID_MATCH,
294
+ };
295
+
296
+ // Returns true if match succeeds.
297
+ bool DomainMatch(MatchType match_type, std::string domain_pattern,
298
+ std::string expected_host_name) {
299
+ // Normalize the args to lower-case. Domain matching is case-insensitive.
300
+ std::transform(domain_pattern.begin(), domain_pattern.end(),
301
+ domain_pattern.begin(),
302
+ [](unsigned char c) { return std::tolower(c); });
303
+ std::transform(expected_host_name.begin(), expected_host_name.end(),
304
+ expected_host_name.begin(),
305
+ [](unsigned char c) { return std::tolower(c); });
306
+ if (match_type == EXACT_MATCH) {
307
+ return domain_pattern == expected_host_name;
308
+ } else if (match_type == SUFFIX_MATCH) {
309
+ // Asterisk must match at least one char.
310
+ if (expected_host_name.size() < domain_pattern.size()) return false;
311
+ absl::string_view pattern_suffix(domain_pattern.c_str() + 1);
312
+ absl::string_view host_suffix(expected_host_name.c_str() +
313
+ expected_host_name.size() -
314
+ pattern_suffix.size());
315
+ return pattern_suffix == host_suffix;
316
+ } else if (match_type == PREFIX_MATCH) {
317
+ // Asterisk must match at least one char.
318
+ if (expected_host_name.size() < domain_pattern.size()) return false;
319
+ absl::string_view pattern_prefix(domain_pattern.c_str(),
320
+ domain_pattern.size() - 1);
321
+ absl::string_view host_prefix(expected_host_name.c_str(),
322
+ pattern_prefix.size());
323
+ return pattern_prefix == host_prefix;
324
+ } else {
325
+ return match_type == UNIVERSE_MATCH;
326
+ }
327
+ }
328
+
329
+ MatchType DomainPatternMatchType(const std::string& domain_pattern) {
330
+ if (domain_pattern.empty()) return INVALID_MATCH;
331
+ if (domain_pattern.find('*') == std::string::npos) return EXACT_MATCH;
332
+ if (domain_pattern == "*") return UNIVERSE_MATCH;
333
+ if (domain_pattern[0] == '*') return SUFFIX_MATCH;
334
+ if (domain_pattern[domain_pattern.size() - 1] == '*') return PREFIX_MATCH;
335
+ return INVALID_MATCH;
336
+ }
337
+
338
+ } // namespace
339
+
340
+ XdsApi::RdsUpdate::VirtualHost* XdsApi::RdsUpdate::FindVirtualHostForDomain(
341
+ const std::string& domain) {
342
+ // Find the best matched virtual host.
343
+ // The search order for 4 groups of domain patterns:
344
+ // 1. Exact match.
345
+ // 2. Suffix match (e.g., "*ABC").
346
+ // 3. Prefix match (e.g., "ABC*").
347
+ // 4. Universe match (i.e., "*").
348
+ // Within each group, longest match wins.
349
+ // If the same best matched domain pattern appears in multiple virtual hosts,
350
+ // the first matched virtual host wins.
351
+ VirtualHost* target_vhost = nullptr;
352
+ MatchType best_match_type = INVALID_MATCH;
353
+ size_t longest_match = 0;
354
+ // Check each domain pattern in each virtual host to determine the best
355
+ // matched virtual host.
356
+ for (VirtualHost& vhost : virtual_hosts) {
357
+ for (const std::string& domain_pattern : vhost.domains) {
358
+ // Check the match type first. Skip the pattern if it's not better than
359
+ // current match.
360
+ const MatchType match_type = DomainPatternMatchType(domain_pattern);
361
+ // This should be caught by RouteConfigParse().
362
+ GPR_ASSERT(match_type != INVALID_MATCH);
363
+ if (match_type > best_match_type) continue;
364
+ if (match_type == best_match_type &&
365
+ domain_pattern.size() <= longest_match) {
366
+ continue;
367
+ }
368
+ // Skip if match fails.
369
+ if (!DomainMatch(match_type, domain_pattern, domain)) continue;
370
+ // Choose this match.
371
+ target_vhost = &vhost;
372
+ best_match_type = match_type;
373
+ longest_match = domain_pattern.size();
374
+ if (best_match_type == EXACT_MATCH) break;
375
+ }
376
+ if (best_match_type == EXACT_MATCH) break;
377
+ }
378
+ return target_vhost;
379
+ }
380
+
381
+ //
382
+ // XdsApi::StringMatcher
383
+ //
384
+
385
+ XdsApi::StringMatcher::StringMatcher(const StringMatcher& other)
386
+ : type(other.type) {
387
+ switch (type) {
388
+ case StringMatcherType::SAFE_REGEX:
389
+ regex_match = absl::make_unique<RE2>(other.regex_match->pattern());
390
+ break;
391
+ default:
392
+ string_matcher = other.string_matcher;
393
+ }
394
+ }
395
+
396
+ XdsApi::StringMatcher& XdsApi::StringMatcher::operator=(
397
+ const StringMatcher& other) {
398
+ type = other.type;
399
+ switch (type) {
400
+ case StringMatcherType::SAFE_REGEX:
401
+ regex_match = absl::make_unique<RE2>(other.regex_match->pattern());
402
+ break;
403
+ default:
404
+ string_matcher = other.string_matcher;
405
+ }
406
+ return *this;
407
+ }
408
+
409
+ bool XdsApi::StringMatcher::operator==(const StringMatcher& other) const {
410
+ if (type != other.type) return false;
411
+ switch (type) {
412
+ case StringMatcherType::SAFE_REGEX:
413
+ return regex_match->pattern() != other.regex_match->pattern();
414
+ default:
415
+ return string_matcher != other.string_matcher;
416
+ }
417
+ }
418
+
419
+ //
420
+ // XdsApi::EdsUpdate
421
+ //
422
+
423
+ std::string XdsApi::EdsUpdate::Priority::Locality::ToString() const {
424
+ std::vector<std::string> endpoint_strings;
425
+ for (const ServerAddress& endpoint : endpoints) {
426
+ endpoint_strings.emplace_back(endpoint.ToString());
427
+ }
428
+ return absl::StrCat("{name=", name->AsHumanReadableString(),
429
+ ", lb_weight=", lb_weight, ", endpoints=[",
430
+ absl::StrJoin(endpoint_strings, ", "), "]}");
431
+ }
432
+
433
+ bool XdsApi::EdsUpdate::Priority::operator==(const Priority& other) const {
434
+ if (localities.size() != other.localities.size()) return false;
435
+ auto it1 = localities.begin();
436
+ auto it2 = other.localities.begin();
437
+ while (it1 != localities.end()) {
438
+ if (*it1->first != *it2->first) return false;
439
+ if (it1->second != it2->second) return false;
440
+ ++it1;
441
+ ++it2;
442
+ }
443
+ return true;
444
+ }
445
+
446
+ std::string XdsApi::EdsUpdate::Priority::ToString() const {
447
+ std::vector<std::string> locality_strings;
448
+ for (const auto& p : localities) {
449
+ locality_strings.emplace_back(p.second.ToString());
450
+ }
451
+ return absl::StrCat("[", absl::StrJoin(locality_strings, ", "), "]");
452
+ }
453
+
454
+ bool XdsApi::EdsUpdate::DropConfig::ShouldDrop(
455
+ const std::string** category_name) const {
456
+ for (size_t i = 0; i < drop_category_list_.size(); ++i) {
457
+ const auto& drop_category = drop_category_list_[i];
458
+ // Generate a random number in [0, 1000000).
459
+ const uint32_t random = static_cast<uint32_t>(rand()) % 1000000;
460
+ if (random < drop_category.parts_per_million) {
461
+ *category_name = &drop_category.name;
462
+ return true;
463
+ }
464
+ }
465
+ return false;
466
+ }
467
+
468
+ std::string XdsApi::EdsUpdate::DropConfig::ToString() const {
469
+ std::vector<std::string> category_strings;
470
+ for (const DropCategory& category : drop_category_list_) {
471
+ category_strings.emplace_back(
472
+ absl::StrCat(category.name, "=", category.parts_per_million));
473
+ }
474
+ return absl::StrCat("{[", absl::StrJoin(category_strings, ", "),
475
+ "], drop_all=", drop_all_, "}");
476
+ }
477
+
478
+ std::string XdsApi::EdsUpdate::ToString() const {
479
+ std::vector<std::string> priority_strings;
480
+ for (size_t i = 0; i < priorities.size(); ++i) {
481
+ const Priority& priority = priorities[i];
482
+ priority_strings.emplace_back(
483
+ absl::StrCat("priority ", i, ": ", priority.ToString()));
484
+ }
485
+ return absl::StrCat("priorities=[", absl::StrJoin(priority_strings, ", "),
486
+ "], drop_config=", drop_config->ToString());
487
+ }
488
+
489
+ //
490
+ // XdsApi
491
+ //
492
+
493
+ const char* XdsApi::kLdsTypeUrl =
494
+ "type.googleapis.com/envoy.config.listener.v3.Listener";
495
+ const char* XdsApi::kRdsTypeUrl =
496
+ "type.googleapis.com/envoy.config.route.v3.RouteConfiguration";
497
+ const char* XdsApi::kCdsTypeUrl =
498
+ "type.googleapis.com/envoy.config.cluster.v3.Cluster";
499
+ const char* XdsApi::kEdsTypeUrl =
500
+ "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment";
501
+
502
+ namespace {
503
+
504
+ const char* kLdsV2TypeUrl = "type.googleapis.com/envoy.api.v2.Listener";
505
+ const char* kRdsV2TypeUrl =
506
+ "type.googleapis.com/envoy.api.v2.RouteConfiguration";
507
+ const char* kCdsV2TypeUrl = "type.googleapis.com/envoy.api.v2.Cluster";
508
+ const char* kEdsV2TypeUrl =
509
+ "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment";
510
+
511
+ bool IsLds(absl::string_view type_url) {
512
+ return type_url == XdsApi::kLdsTypeUrl || type_url == kLdsV2TypeUrl;
513
+ }
514
+
515
+ bool IsRds(absl::string_view type_url) {
516
+ return type_url == XdsApi::kRdsTypeUrl || type_url == kRdsV2TypeUrl;
517
+ }
518
+
519
+ bool IsCds(absl::string_view type_url) {
520
+ return type_url == XdsApi::kCdsTypeUrl || type_url == kCdsV2TypeUrl;
521
+ }
522
+
523
+ bool IsEds(absl::string_view type_url) {
524
+ return type_url == XdsApi::kEdsTypeUrl || type_url == kEdsV2TypeUrl;
525
+ }
526
+
527
+ } // namespace
528
+
529
+ XdsApi::XdsApi(XdsClient* client, TraceFlag* tracer,
530
+ const XdsBootstrap* bootstrap)
531
+ : client_(client),
532
+ tracer_(tracer),
533
+ use_v3_(bootstrap != nullptr && bootstrap->server().ShouldUseV3()),
534
+ bootstrap_(bootstrap),
535
+ build_version_(absl::StrCat("gRPC C-core ", GPR_PLATFORM_STRING, " ",
536
+ grpc_version_string())),
537
+ user_agent_name_(absl::StrCat("gRPC C-core ", GPR_PLATFORM_STRING)) {}
538
+
539
+ namespace {
540
+
541
+ // Works for both std::string and absl::string_view.
542
+ template <typename T>
543
+ inline upb_strview StdStringToUpbString(const T& str) {
544
+ return upb_strview_make(str.data(), str.size());
545
+ }
546
+
547
+ void PopulateMetadataValue(upb_arena* arena, google_protobuf_Value* value_pb,
548
+ const Json& value);
549
+
550
+ void PopulateListValue(upb_arena* arena, google_protobuf_ListValue* list_value,
551
+ const Json::Array& values) {
552
+ for (const auto& value : values) {
553
+ auto* value_pb = google_protobuf_ListValue_add_values(list_value, arena);
554
+ PopulateMetadataValue(arena, value_pb, value);
555
+ }
556
+ }
557
+
558
+ void PopulateMetadata(upb_arena* arena, google_protobuf_Struct* metadata_pb,
559
+ const Json::Object& metadata) {
560
+ for (const auto& p : metadata) {
561
+ google_protobuf_Value* value = google_protobuf_Value_new(arena);
562
+ PopulateMetadataValue(arena, value, p.second);
563
+ google_protobuf_Struct_fields_set(
564
+ metadata_pb, StdStringToUpbString(p.first), value, arena);
565
+ }
566
+ }
567
+
568
+ void PopulateMetadataValue(upb_arena* arena, google_protobuf_Value* value_pb,
569
+ const Json& value) {
570
+ switch (value.type()) {
571
+ case Json::Type::JSON_NULL:
572
+ google_protobuf_Value_set_null_value(value_pb, 0);
573
+ break;
574
+ case Json::Type::NUMBER:
575
+ google_protobuf_Value_set_number_value(
576
+ value_pb, strtod(value.string_value().c_str(), nullptr));
577
+ break;
578
+ case Json::Type::STRING:
579
+ google_protobuf_Value_set_string_value(
580
+ value_pb, StdStringToUpbString(value.string_value()));
581
+ break;
582
+ case Json::Type::JSON_TRUE:
583
+ google_protobuf_Value_set_bool_value(value_pb, true);
584
+ break;
585
+ case Json::Type::JSON_FALSE:
586
+ google_protobuf_Value_set_bool_value(value_pb, false);
587
+ break;
588
+ case Json::Type::OBJECT: {
589
+ google_protobuf_Struct* struct_value =
590
+ google_protobuf_Value_mutable_struct_value(value_pb, arena);
591
+ PopulateMetadata(arena, struct_value, value.object_value());
592
+ break;
593
+ }
594
+ case Json::Type::ARRAY: {
595
+ google_protobuf_ListValue* list_value =
596
+ google_protobuf_Value_mutable_list_value(value_pb, arena);
597
+ PopulateListValue(arena, list_value, value.array_value());
598
+ break;
599
+ }
600
+ }
601
+ }
602
+
603
+ // Helper functions to manually do protobuf string encoding, so that we
604
+ // can populate the node build_version field that was removed in v3.
605
+ std::string EncodeVarint(uint64_t val) {
606
+ std::string data;
607
+ do {
608
+ uint8_t byte = val & 0x7fU;
609
+ val >>= 7;
610
+ if (val) byte |= 0x80U;
611
+ data += byte;
612
+ } while (val);
613
+ return data;
614
+ }
615
+ std::string EncodeTag(uint32_t field_number, uint8_t wire_type) {
616
+ return EncodeVarint((field_number << 3) | wire_type);
617
+ }
618
+ std::string EncodeStringField(uint32_t field_number, const std::string& str) {
619
+ static const uint8_t kDelimitedWireType = 2;
620
+ return EncodeTag(field_number, kDelimitedWireType) +
621
+ EncodeVarint(str.size()) + str;
622
+ }
623
+
624
+ void PopulateBuildVersion(upb_arena* arena, envoy_config_core_v3_Node* node_msg,
625
+ const std::string& build_version) {
626
+ std::string encoded_build_version = EncodeStringField(5, build_version);
627
+ // TODO(roth): This should use upb_msg_addunknown(), but that API is
628
+ // broken in the current version of upb, so we're using the internal
629
+ // API for now. Change this once we upgrade to a version of upb that
630
+ // fixes this bug.
631
+ _upb_msg_addunknown(node_msg, encoded_build_version.data(),
632
+ encoded_build_version.size(), arena);
633
+ }
634
+
635
+ void PopulateNode(upb_arena* arena, const XdsBootstrap* bootstrap,
636
+ const std::string& build_version,
637
+ const std::string& user_agent_name,
638
+ envoy_config_core_v3_Node* node_msg) {
639
+ const XdsBootstrap::Node* node = bootstrap->node();
640
+ if (node != nullptr) {
641
+ if (!node->id.empty()) {
642
+ envoy_config_core_v3_Node_set_id(node_msg,
643
+ StdStringToUpbString(node->id));
644
+ }
645
+ if (!node->cluster.empty()) {
646
+ envoy_config_core_v3_Node_set_cluster(
647
+ node_msg, StdStringToUpbString(node->cluster));
648
+ }
649
+ if (!node->metadata.object_value().empty()) {
650
+ google_protobuf_Struct* metadata =
651
+ envoy_config_core_v3_Node_mutable_metadata(node_msg, arena);
652
+ PopulateMetadata(arena, metadata, node->metadata.object_value());
653
+ }
654
+ if (!node->locality_region.empty() || !node->locality_zone.empty() ||
655
+ !node->locality_subzone.empty()) {
656
+ envoy_config_core_v3_Locality* locality =
657
+ envoy_config_core_v3_Node_mutable_locality(node_msg, arena);
658
+ if (!node->locality_region.empty()) {
659
+ envoy_config_core_v3_Locality_set_region(
660
+ locality, StdStringToUpbString(node->locality_region));
661
+ }
662
+ if (!node->locality_zone.empty()) {
663
+ envoy_config_core_v3_Locality_set_zone(
664
+ locality, StdStringToUpbString(node->locality_zone));
665
+ }
666
+ if (!node->locality_subzone.empty()) {
667
+ envoy_config_core_v3_Locality_set_sub_zone(
668
+ locality, StdStringToUpbString(node->locality_subzone));
669
+ }
670
+ }
671
+ }
672
+ if (!bootstrap->server().ShouldUseV3()) {
673
+ PopulateBuildVersion(arena, node_msg, build_version);
674
+ }
675
+ envoy_config_core_v3_Node_set_user_agent_name(
676
+ node_msg, StdStringToUpbString(user_agent_name));
677
+ envoy_config_core_v3_Node_set_user_agent_version(
678
+ node_msg, upb_strview_makez(grpc_version_string()));
679
+ envoy_config_core_v3_Node_add_client_features(
680
+ node_msg, upb_strview_makez("envoy.lb.does_not_support_overprovisioning"),
681
+ arena);
682
+ }
683
+
684
+ inline absl::string_view UpbStringToAbsl(const upb_strview& str) {
685
+ return absl::string_view(str.data, str.size);
686
+ }
687
+
688
+ inline std::string UpbStringToStdString(const upb_strview& str) {
689
+ return std::string(str.data, str.size);
690
+ }
691
+
692
+ inline void AddStringField(const char* name, const upb_strview& value,
693
+ std::vector<std::string>* fields,
694
+ bool add_if_empty = false) {
695
+ if (value.size > 0 || add_if_empty) {
696
+ fields->emplace_back(
697
+ absl::StrCat(name, ": \"", UpbStringToAbsl(value), "\""));
698
+ }
699
+ }
700
+
701
+ inline void AddUInt32ValueField(const char* name,
702
+ const google_protobuf_UInt32Value* value,
703
+ std::vector<std::string>* fields) {
704
+ if (value != nullptr) {
705
+ fields->emplace_back(absl::StrCat(
706
+ name, " { value: ", google_protobuf_UInt32Value_value(value), " }"));
707
+ }
708
+ }
709
+
710
+ inline void AddLocalityField(int indent_level,
711
+ const envoy_config_core_v3_Locality* locality,
712
+ std::vector<std::string>* fields) {
713
+ std::string indent =
714
+ absl::StrJoin(std::vector<std::string>(indent_level, " "), "");
715
+ // region
716
+ std::string field = absl::StrCat(indent, "region");
717
+ AddStringField(field.c_str(), envoy_config_core_v3_Locality_region(locality),
718
+ fields);
719
+ // zone
720
+ field = absl::StrCat(indent, "zone");
721
+ AddStringField(field.c_str(), envoy_config_core_v3_Locality_zone(locality),
722
+ fields);
723
+ // sub_zone
724
+ field = absl::StrCat(indent, "sub_zone");
725
+ AddStringField(field.c_str(),
726
+ envoy_config_core_v3_Locality_sub_zone(locality), fields);
727
+ }
728
+
729
+ void AddNodeLogFields(const envoy_config_core_v3_Node* node,
730
+ const std::string& build_version,
731
+ std::vector<std::string>* fields) {
732
+ fields->emplace_back("node {");
733
+ // id
734
+ AddStringField(" id", envoy_config_core_v3_Node_id(node), fields);
735
+ // metadata
736
+ const google_protobuf_Struct* metadata =
737
+ envoy_config_core_v3_Node_metadata(node);
738
+ if (metadata != nullptr) {
739
+ fields->emplace_back(" metadata {");
740
+ size_t entry_idx = UPB_MAP_BEGIN;
741
+ while (true) {
742
+ const google_protobuf_Struct_FieldsEntry* entry =
743
+ google_protobuf_Struct_fields_next(metadata, &entry_idx);
744
+ if (entry == nullptr) break;
745
+ fields->emplace_back(" field {");
746
+ // key
747
+ AddStringField(" key", google_protobuf_Struct_FieldsEntry_key(entry),
748
+ fields);
749
+ // value
750
+ const google_protobuf_Value* value =
751
+ google_protobuf_Struct_FieldsEntry_value(entry);
752
+ if (value != nullptr) {
753
+ std::string value_str;
754
+ if (google_protobuf_Value_has_string_value(value)) {
755
+ value_str = absl::StrCat(
756
+ "string_value: \"",
757
+ UpbStringToAbsl(google_protobuf_Value_string_value(value)), "\"");
758
+ } else if (google_protobuf_Value_has_null_value(value)) {
759
+ value_str = "null_value: NULL_VALUE";
760
+ } else if (google_protobuf_Value_has_number_value(value)) {
761
+ value_str = absl::StrCat("double_value: ",
762
+ google_protobuf_Value_number_value(value));
763
+ } else if (google_protobuf_Value_has_bool_value(value)) {
764
+ value_str = absl::StrCat("bool_value: ",
765
+ google_protobuf_Value_bool_value(value));
766
+ } else if (google_protobuf_Value_has_struct_value(value)) {
767
+ value_str = "struct_value: <not printed>";
768
+ } else if (google_protobuf_Value_has_list_value(value)) {
769
+ value_str = "list_value: <not printed>";
770
+ } else {
771
+ value_str = "<unknown>";
772
+ }
773
+ fields->emplace_back(absl::StrCat(" value { ", value_str, " }"));
774
+ }
775
+ fields->emplace_back(" }");
776
+ }
777
+ fields->emplace_back(" }");
778
+ }
779
+ // locality
780
+ const envoy_config_core_v3_Locality* locality =
781
+ envoy_config_core_v3_Node_locality(node);
782
+ if (locality != nullptr) {
783
+ fields->emplace_back(" locality {");
784
+ AddLocalityField(2, locality, fields);
785
+ fields->emplace_back(" }");
786
+ }
787
+ // build_version (doesn't exist in v3 proto; this is a horrible hack)
788
+ if (!build_version.empty()) {
789
+ fields->emplace_back(
790
+ absl::StrCat(" build_version: \"", build_version, "\""));
791
+ }
792
+ // user_agent_name
793
+ AddStringField(" user_agent_name",
794
+ envoy_config_core_v3_Node_user_agent_name(node), fields);
795
+ // user_agent_version
796
+ AddStringField(" user_agent_version",
797
+ envoy_config_core_v3_Node_user_agent_version(node), fields);
798
+ // client_features
799
+ size_t num_client_features;
800
+ const upb_strview* client_features =
801
+ envoy_config_core_v3_Node_client_features(node, &num_client_features);
802
+ for (size_t i = 0; i < num_client_features; ++i) {
803
+ AddStringField(" client_features", client_features[i], fields);
804
+ }
805
+ fields->emplace_back("}");
806
+ }
807
+
808
+ void MaybeLogDiscoveryRequest(
809
+ XdsClient* client, TraceFlag* tracer,
810
+ const envoy_service_discovery_v3_DiscoveryRequest* request,
811
+ const std::string& build_version) {
812
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
813
+ gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
814
+ // TODO(roth): When we can upgrade upb, use upb textformat code to dump
815
+ // the raw proto instead of doing this manually.
816
+ std::vector<std::string> fields;
817
+ // version_info
818
+ AddStringField(
819
+ "version_info",
820
+ envoy_service_discovery_v3_DiscoveryRequest_version_info(request),
821
+ &fields);
822
+ // node
823
+ const envoy_config_core_v3_Node* node =
824
+ envoy_service_discovery_v3_DiscoveryRequest_node(request);
825
+ if (node != nullptr) AddNodeLogFields(node, build_version, &fields);
826
+ // resource_names
827
+ size_t num_resource_names;
828
+ const upb_strview* resource_names =
829
+ envoy_service_discovery_v3_DiscoveryRequest_resource_names(
830
+ request, &num_resource_names);
831
+ for (size_t i = 0; i < num_resource_names; ++i) {
832
+ AddStringField("resource_names", resource_names[i], &fields);
833
+ }
834
+ // type_url
835
+ AddStringField(
836
+ "type_url",
837
+ envoy_service_discovery_v3_DiscoveryRequest_type_url(request), &fields);
838
+ // response_nonce
839
+ AddStringField(
840
+ "response_nonce",
841
+ envoy_service_discovery_v3_DiscoveryRequest_response_nonce(request),
842
+ &fields);
843
+ // error_detail
844
+ const struct google_rpc_Status* error_detail =
845
+ envoy_service_discovery_v3_DiscoveryRequest_error_detail(request);
846
+ if (error_detail != nullptr) {
847
+ fields.emplace_back("error_detail {");
848
+ // code
849
+ int32_t code = google_rpc_Status_code(error_detail);
850
+ if (code != 0) fields.emplace_back(absl::StrCat(" code: ", code));
851
+ // message
852
+ AddStringField(" message", google_rpc_Status_message(error_detail),
853
+ &fields);
854
+ fields.emplace_back("}");
855
+ }
856
+ gpr_log(GPR_DEBUG, "[xds_client %p] constructed ADS request: %s", client,
857
+ absl::StrJoin(fields, "\n").c_str());
858
+ }
859
+ }
860
+
861
+ grpc_slice SerializeDiscoveryRequest(
862
+ upb_arena* arena, envoy_service_discovery_v3_DiscoveryRequest* request) {
863
+ size_t output_length;
864
+ char* output = envoy_service_discovery_v3_DiscoveryRequest_serialize(
865
+ request, arena, &output_length);
866
+ return grpc_slice_from_copied_buffer(output, output_length);
867
+ }
868
+
869
+ absl::string_view TypeUrlExternalToInternal(bool use_v3,
870
+ const std::string& type_url) {
871
+ if (!use_v3) {
872
+ if (type_url == XdsApi::kLdsTypeUrl) {
873
+ return kLdsV2TypeUrl;
874
+ }
875
+ if (type_url == XdsApi::kRdsTypeUrl) {
876
+ return kRdsV2TypeUrl;
877
+ }
878
+ if (type_url == XdsApi::kCdsTypeUrl) {
879
+ return kCdsV2TypeUrl;
880
+ }
881
+ if (type_url == XdsApi::kEdsTypeUrl) {
882
+ return kEdsV2TypeUrl;
883
+ }
884
+ }
885
+ return type_url;
886
+ }
887
+
888
+ } // namespace
889
+
890
+ grpc_slice XdsApi::CreateAdsRequest(
891
+ const std::string& type_url,
892
+ const std::set<absl::string_view>& resource_names,
893
+ const std::string& version, const std::string& nonce, grpc_error* error,
894
+ bool populate_node) {
895
+ upb::Arena arena;
896
+ // Create a request.
897
+ envoy_service_discovery_v3_DiscoveryRequest* request =
898
+ envoy_service_discovery_v3_DiscoveryRequest_new(arena.ptr());
899
+ // Set type_url.
900
+ absl::string_view real_type_url =
901
+ TypeUrlExternalToInternal(use_v3_, type_url);
902
+ envoy_service_discovery_v3_DiscoveryRequest_set_type_url(
903
+ request, StdStringToUpbString(real_type_url));
904
+ // Set version_info.
905
+ if (!version.empty()) {
906
+ envoy_service_discovery_v3_DiscoveryRequest_set_version_info(
907
+ request, StdStringToUpbString(version));
908
+ }
909
+ // Set nonce.
910
+ if (!nonce.empty()) {
911
+ envoy_service_discovery_v3_DiscoveryRequest_set_response_nonce(
912
+ request, StdStringToUpbString(nonce));
913
+ }
914
+ // Set error_detail if it's a NACK.
915
+ if (error != GRPC_ERROR_NONE) {
916
+ grpc_slice error_description_slice;
917
+ GPR_ASSERT(grpc_error_get_str(error, GRPC_ERROR_STR_DESCRIPTION,
918
+ &error_description_slice));
919
+ upb_strview error_description_strview =
920
+ upb_strview_make(reinterpret_cast<const char*>(
921
+ GPR_SLICE_START_PTR(error_description_slice)),
922
+ GPR_SLICE_LENGTH(error_description_slice));
923
+ google_rpc_Status* error_detail =
924
+ envoy_service_discovery_v3_DiscoveryRequest_mutable_error_detail(
925
+ request, arena.ptr());
926
+ google_rpc_Status_set_message(error_detail, error_description_strview);
927
+ GRPC_ERROR_UNREF(error);
928
+ }
929
+ // Populate node.
930
+ if (populate_node) {
931
+ envoy_config_core_v3_Node* node_msg =
932
+ envoy_service_discovery_v3_DiscoveryRequest_mutable_node(request,
933
+ arena.ptr());
934
+ PopulateNode(arena.ptr(), bootstrap_, build_version_, user_agent_name_,
935
+ node_msg);
936
+ }
937
+ // Add resource_names.
938
+ for (const auto& resource_name : resource_names) {
939
+ envoy_service_discovery_v3_DiscoveryRequest_add_resource_names(
940
+ request, StdStringToUpbString(resource_name), arena.ptr());
941
+ }
942
+ MaybeLogDiscoveryRequest(client_, tracer_, request, build_version_);
943
+ return SerializeDiscoveryRequest(arena.ptr(), request);
944
+ }
945
+
946
+ namespace {
947
+
948
+ void MaybeLogDiscoveryResponse(
949
+ XdsClient* client, TraceFlag* tracer,
950
+ const envoy_service_discovery_v3_DiscoveryResponse* response) {
951
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
952
+ gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
953
+ // TODO(roth): When we can upgrade upb, use upb textformat code to dump
954
+ // the raw proto instead of doing this manually.
955
+ std::vector<std::string> fields;
956
+ // version_info
957
+ AddStringField(
958
+ "version_info",
959
+ envoy_service_discovery_v3_DiscoveryResponse_version_info(response),
960
+ &fields);
961
+ // resources
962
+ size_t num_resources;
963
+ envoy_service_discovery_v3_DiscoveryResponse_resources(response,
964
+ &num_resources);
965
+ fields.emplace_back(
966
+ absl::StrCat("resources: <", num_resources, " element(s)>"));
967
+ // type_url
968
+ AddStringField(
969
+ "type_url",
970
+ envoy_service_discovery_v3_DiscoveryResponse_type_url(response),
971
+ &fields);
972
+ // nonce
973
+ AddStringField("nonce",
974
+ envoy_service_discovery_v3_DiscoveryResponse_nonce(response),
975
+ &fields);
976
+ gpr_log(GPR_DEBUG, "[xds_client %p] received response: %s", client,
977
+ absl::StrJoin(fields, "\n").c_str());
978
+ }
979
+ }
980
+
981
+ void MaybeLogRouteConfiguration(
982
+ XdsClient* client, TraceFlag* tracer,
983
+ const envoy_config_route_v3_RouteConfiguration* route_config) {
984
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
985
+ gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
986
+ // TODO(roth): When we can upgrade upb, use upb textformat code to dump
987
+ // the raw proto instead of doing this manually.
988
+ std::vector<std::string> fields;
989
+ // name
990
+ AddStringField("name",
991
+ envoy_config_route_v3_RouteConfiguration_name(route_config),
992
+ &fields);
993
+ // virtual_hosts
994
+ size_t num_virtual_hosts;
995
+ const envoy_config_route_v3_VirtualHost* const* virtual_hosts =
996
+ envoy_config_route_v3_RouteConfiguration_virtual_hosts(
997
+ route_config, &num_virtual_hosts);
998
+ for (size_t i = 0; i < num_virtual_hosts; ++i) {
999
+ const auto* virtual_host = virtual_hosts[i];
1000
+ fields.push_back("virtual_hosts {");
1001
+ // name
1002
+ AddStringField(" name",
1003
+ envoy_config_route_v3_VirtualHost_name(virtual_host),
1004
+ &fields);
1005
+ // domains
1006
+ size_t num_domains;
1007
+ const upb_strview* const domains =
1008
+ envoy_config_route_v3_VirtualHost_domains(virtual_host, &num_domains);
1009
+ for (size_t j = 0; j < num_domains; ++j) {
1010
+ AddStringField(" domains", domains[j], &fields);
1011
+ }
1012
+ // routes
1013
+ size_t num_routes;
1014
+ const envoy_config_route_v3_Route* const* routes =
1015
+ envoy_config_route_v3_VirtualHost_routes(virtual_host, &num_routes);
1016
+ for (size_t j = 0; j < num_routes; ++j) {
1017
+ const auto* route = routes[j];
1018
+ fields.push_back(" route {");
1019
+ // name
1020
+ AddStringField(" name", envoy_config_route_v3_Route_name(route),
1021
+ &fields);
1022
+ // match
1023
+ const envoy_config_route_v3_RouteMatch* match =
1024
+ envoy_config_route_v3_Route_match(route);
1025
+ if (match != nullptr) {
1026
+ fields.emplace_back(" match {");
1027
+ // path matching
1028
+ if (envoy_config_route_v3_RouteMatch_has_prefix(match)) {
1029
+ AddStringField(" prefix",
1030
+ envoy_config_route_v3_RouteMatch_prefix(match),
1031
+ &fields,
1032
+ /*add_if_empty=*/true);
1033
+ } else if (envoy_config_route_v3_RouteMatch_has_path(match)) {
1034
+ AddStringField(" path",
1035
+ envoy_config_route_v3_RouteMatch_path(match),
1036
+ &fields,
1037
+ /*add_if_empty=*/true);
1038
+ } else if (envoy_config_route_v3_RouteMatch_has_safe_regex(match)) {
1039
+ fields.emplace_back(" safe_regex: <not printed>");
1040
+ } else {
1041
+ fields.emplace_back(" <unknown path matching type>");
1042
+ }
1043
+ // header matching
1044
+ size_t num_headers;
1045
+ envoy_config_route_v3_RouteMatch_headers(match, &num_headers);
1046
+ if (num_headers > 0) {
1047
+ fields.emplace_back(
1048
+ absl::StrCat(" headers: <", num_headers, " element(s)>"));
1049
+ }
1050
+ fields.emplace_back(" }");
1051
+ }
1052
+ // action
1053
+ if (envoy_config_route_v3_Route_has_route(route)) {
1054
+ const envoy_config_route_v3_RouteAction* action =
1055
+ envoy_config_route_v3_Route_route(route);
1056
+ fields.emplace_back(" route {");
1057
+ if (envoy_config_route_v3_RouteAction_has_cluster(action)) {
1058
+ AddStringField(" cluster",
1059
+ envoy_config_route_v3_RouteAction_cluster(action),
1060
+ &fields);
1061
+ } else if (envoy_config_route_v3_RouteAction_has_cluster_header(
1062
+ action)) {
1063
+ AddStringField(
1064
+ " cluster_header",
1065
+ envoy_config_route_v3_RouteAction_cluster_header(action),
1066
+ &fields);
1067
+ } else if (envoy_config_route_v3_RouteAction_has_weighted_clusters(
1068
+ action)) {
1069
+ const envoy_config_route_v3_WeightedCluster* weighted_clusters =
1070
+ envoy_config_route_v3_RouteAction_weighted_clusters(action);
1071
+ fields.emplace_back(" weighted_clusters {");
1072
+ size_t num_cluster_weights;
1073
+ const envoy_config_route_v3_WeightedCluster_ClusterWeight* const*
1074
+ cluster_weights =
1075
+ envoy_config_route_v3_WeightedCluster_clusters(
1076
+ weighted_clusters, &num_cluster_weights);
1077
+ for (size_t i = 0; i < num_cluster_weights; ++i) {
1078
+ const envoy_config_route_v3_WeightedCluster_ClusterWeight*
1079
+ cluster_weight = cluster_weights[i];
1080
+ fields.emplace_back(" clusters {");
1081
+ AddStringField(
1082
+ " name",
1083
+ envoy_config_route_v3_WeightedCluster_ClusterWeight_name(
1084
+ cluster_weight),
1085
+ &fields);
1086
+ AddUInt32ValueField(
1087
+ " weight",
1088
+ envoy_config_route_v3_WeightedCluster_ClusterWeight_weight(
1089
+ cluster_weight),
1090
+ &fields);
1091
+ fields.emplace_back(" }");
1092
+ }
1093
+ AddUInt32ValueField(
1094
+ " total_weight",
1095
+ envoy_config_route_v3_WeightedCluster_total_weight(
1096
+ weighted_clusters),
1097
+ &fields);
1098
+ fields.emplace_back(" }");
1099
+ }
1100
+ fields.emplace_back(" }");
1101
+ } else if (envoy_config_route_v3_Route_has_redirect(route)) {
1102
+ fields.emplace_back(" redirect: <not printed>");
1103
+ } else if (envoy_config_route_v3_Route_has_direct_response(route)) {
1104
+ fields.emplace_back(" direct_response: <not printed>");
1105
+ } else if (envoy_config_route_v3_Route_has_filter_action(route)) {
1106
+ fields.emplace_back(" filter_action: <not printed>");
1107
+ }
1108
+ fields.push_back(" }");
1109
+ }
1110
+ fields.push_back("}");
1111
+ }
1112
+ gpr_log(GPR_DEBUG, "[xds_client %p] RouteConfiguration: %s", client,
1113
+ absl::StrJoin(fields, "\n").c_str());
1114
+ }
1115
+ }
1116
+
1117
+ void MaybeLogCluster(XdsClient* client, TraceFlag* tracer,
1118
+ const envoy_config_cluster_v3_Cluster* cluster) {
1119
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
1120
+ gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
1121
+ // TODO(roth): When we can upgrade upb, use upb textformat code to dump
1122
+ // the raw proto instead of doing this manually.
1123
+ std::vector<std::string> fields;
1124
+ // name
1125
+ AddStringField("name", envoy_config_cluster_v3_Cluster_name(cluster),
1126
+ &fields);
1127
+ // type
1128
+ if (envoy_config_cluster_v3_Cluster_has_type(cluster)) {
1129
+ fields.emplace_back(absl::StrCat(
1130
+ "type: ", envoy_config_cluster_v3_Cluster_type(cluster)));
1131
+ } else if (envoy_config_cluster_v3_Cluster_has_cluster_type(cluster)) {
1132
+ fields.emplace_back("cluster_type: <not printed>");
1133
+ } else {
1134
+ fields.emplace_back("<unknown type>");
1135
+ }
1136
+ // eds_cluster_config
1137
+ const envoy_config_cluster_v3_Cluster_EdsClusterConfig* eds_cluster_config =
1138
+ envoy_config_cluster_v3_Cluster_eds_cluster_config(cluster);
1139
+ if (eds_cluster_config != nullptr) {
1140
+ fields.emplace_back("eds_cluster_config {");
1141
+ // eds_config
1142
+ const struct envoy_config_core_v3_ConfigSource* eds_config =
1143
+ envoy_config_cluster_v3_Cluster_EdsClusterConfig_eds_config(
1144
+ eds_cluster_config);
1145
+ if (eds_config != nullptr) {
1146
+ if (envoy_config_core_v3_ConfigSource_has_ads(eds_config)) {
1147
+ fields.emplace_back(" eds_config { ads {} }");
1148
+ } else {
1149
+ fields.emplace_back(" eds_config: <non-ADS type>");
1150
+ }
1151
+ }
1152
+ // service_name
1153
+ AddStringField(
1154
+ " service_name",
1155
+ envoy_config_cluster_v3_Cluster_EdsClusterConfig_service_name(
1156
+ eds_cluster_config),
1157
+ &fields);
1158
+ fields.emplace_back("}");
1159
+ }
1160
+ // lb_policy
1161
+ fields.emplace_back(absl::StrCat(
1162
+ "lb_policy: ", envoy_config_cluster_v3_Cluster_lb_policy(cluster)));
1163
+ // lrs_server
1164
+ const envoy_config_core_v3_ConfigSource* lrs_server =
1165
+ envoy_config_cluster_v3_Cluster_lrs_server(cluster);
1166
+ if (lrs_server != nullptr) {
1167
+ if (envoy_config_core_v3_ConfigSource_has_self(lrs_server)) {
1168
+ fields.emplace_back("lrs_server { self {} }");
1169
+ } else {
1170
+ fields.emplace_back("lrs_server: <non-self type>");
1171
+ }
1172
+ }
1173
+ gpr_log(GPR_DEBUG, "[xds_client %p] Cluster: %s", client,
1174
+ absl::StrJoin(fields, "\n").c_str());
1175
+ }
1176
+ }
1177
+
1178
+ void MaybeLogClusterLoadAssignment(
1179
+ XdsClient* client, TraceFlag* tracer,
1180
+ const envoy_config_endpoint_v3_ClusterLoadAssignment* cla) {
1181
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
1182
+ gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
1183
+ // TODO(roth): When we can upgrade upb, use upb textformat code to dump
1184
+ // the raw proto instead of doing this manually.
1185
+ std::vector<std::string> fields;
1186
+ // cluster_name
1187
+ AddStringField(
1188
+ "cluster_name",
1189
+ envoy_config_endpoint_v3_ClusterLoadAssignment_cluster_name(cla),
1190
+ &fields);
1191
+ // endpoints
1192
+ size_t num_localities;
1193
+ const struct envoy_config_endpoint_v3_LocalityLbEndpoints* const*
1194
+ locality_endpoints =
1195
+ envoy_config_endpoint_v3_ClusterLoadAssignment_endpoints(
1196
+ cla, &num_localities);
1197
+ for (size_t i = 0; i < num_localities; ++i) {
1198
+ const auto* locality_endpoint = locality_endpoints[i];
1199
+ fields.emplace_back("endpoints {");
1200
+ // locality
1201
+ const auto* locality =
1202
+ envoy_config_endpoint_v3_LocalityLbEndpoints_locality(
1203
+ locality_endpoint);
1204
+ if (locality != nullptr) {
1205
+ fields.emplace_back(" locality {");
1206
+ AddLocalityField(2, locality, &fields);
1207
+ fields.emplace_back(" }");
1208
+ }
1209
+ // lb_endpoints
1210
+ size_t num_lb_endpoints;
1211
+ const envoy_config_endpoint_v3_LbEndpoint* const* lb_endpoints =
1212
+ envoy_config_endpoint_v3_LocalityLbEndpoints_lb_endpoints(
1213
+ locality_endpoint, &num_lb_endpoints);
1214
+ for (size_t j = 0; j < num_lb_endpoints; ++j) {
1215
+ const auto* lb_endpoint = lb_endpoints[j];
1216
+ fields.emplace_back(" lb_endpoints {");
1217
+ // health_status
1218
+ uint32_t health_status =
1219
+ envoy_config_endpoint_v3_LbEndpoint_health_status(lb_endpoint);
1220
+ if (health_status > 0) {
1221
+ fields.emplace_back(
1222
+ absl::StrCat(" health_status: ", health_status));
1223
+ }
1224
+ // endpoint
1225
+ const envoy_config_endpoint_v3_Endpoint* endpoint =
1226
+ envoy_config_endpoint_v3_LbEndpoint_endpoint(lb_endpoint);
1227
+ if (endpoint != nullptr) {
1228
+ fields.emplace_back(" endpoint {");
1229
+ // address
1230
+ const auto* address =
1231
+ envoy_config_endpoint_v3_Endpoint_address(endpoint);
1232
+ if (address != nullptr) {
1233
+ fields.emplace_back(" address {");
1234
+ // socket_address
1235
+ const auto* socket_address =
1236
+ envoy_config_core_v3_Address_socket_address(address);
1237
+ if (socket_address != nullptr) {
1238
+ fields.emplace_back(" socket_address {");
1239
+ // address
1240
+ AddStringField(
1241
+ " address",
1242
+ envoy_config_core_v3_SocketAddress_address(socket_address),
1243
+ &fields);
1244
+ // port_value
1245
+ if (envoy_config_core_v3_SocketAddress_has_port_value(
1246
+ socket_address)) {
1247
+ fields.emplace_back(
1248
+ absl::StrCat(" port_value: ",
1249
+ envoy_config_core_v3_SocketAddress_port_value(
1250
+ socket_address)));
1251
+ } else {
1252
+ fields.emplace_back(" <non-numeric port>");
1253
+ }
1254
+ fields.emplace_back(" }");
1255
+ } else {
1256
+ fields.emplace_back(" <non-socket address>");
1257
+ }
1258
+ fields.emplace_back(" }");
1259
+ }
1260
+ fields.emplace_back(" }");
1261
+ }
1262
+ fields.emplace_back(" }");
1263
+ }
1264
+ // load_balancing_weight
1265
+ AddUInt32ValueField(
1266
+ " load_balancing_weight",
1267
+ envoy_config_endpoint_v3_LocalityLbEndpoints_load_balancing_weight(
1268
+ locality_endpoint),
1269
+ &fields);
1270
+ // priority
1271
+ uint32_t priority = envoy_config_endpoint_v3_LocalityLbEndpoints_priority(
1272
+ locality_endpoint);
1273
+ if (priority > 0) {
1274
+ fields.emplace_back(absl::StrCat(" priority: ", priority));
1275
+ }
1276
+ fields.emplace_back("}");
1277
+ }
1278
+ // policy
1279
+ const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy* policy =
1280
+ envoy_config_endpoint_v3_ClusterLoadAssignment_policy(cla);
1281
+ if (policy != nullptr) {
1282
+ fields.emplace_back("policy {");
1283
+ // drop_overloads
1284
+ size_t num_drop_overloads;
1285
+ const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload* const*
1286
+ drop_overloads =
1287
+ envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_drop_overloads(
1288
+ policy, &num_drop_overloads);
1289
+ for (size_t i = 0; i < num_drop_overloads; ++i) {
1290
+ auto* drop_overload = drop_overloads[i];
1291
+ fields.emplace_back(" drop_overloads {");
1292
+ // category
1293
+ AddStringField(
1294
+ " category",
1295
+ envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_category(
1296
+ drop_overload),
1297
+ &fields);
1298
+ // drop_percentage
1299
+ const auto* drop_percentage =
1300
+ envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_drop_percentage(
1301
+ drop_overload);
1302
+ if (drop_percentage != nullptr) {
1303
+ fields.emplace_back(" drop_percentage {");
1304
+ fields.emplace_back(absl::StrCat(
1305
+ " numerator: ",
1306
+ envoy_type_v3_FractionalPercent_numerator(drop_percentage)));
1307
+ fields.emplace_back(absl::StrCat(
1308
+ " denominator: ",
1309
+ envoy_type_v3_FractionalPercent_denominator(drop_percentage)));
1310
+ fields.emplace_back(" }");
1311
+ }
1312
+ fields.emplace_back(" }");
1313
+ }
1314
+ // overprovisioning_factor
1315
+ fields.emplace_back("}");
1316
+ }
1317
+ gpr_log(GPR_DEBUG, "[xds_client %p] ClusterLoadAssignment: %s", client,
1318
+ absl::StrJoin(fields, "\n").c_str());
1319
+ }
1320
+ }
1321
+
1322
+ grpc_error* RoutePathMatchParse(const envoy_config_route_v3_RouteMatch* match,
1323
+ XdsApi::Route* route, bool* ignore_route) {
1324
+ if (envoy_config_route_v3_RouteMatch_has_prefix(match)) {
1325
+ absl::string_view prefix =
1326
+ UpbStringToAbsl(envoy_config_route_v3_RouteMatch_prefix(match));
1327
+ // Empty prefix "" is accepted.
1328
+ if (prefix.size() > 0) {
1329
+ // Prefix "/" is accepted.
1330
+ if (prefix[0] != '/') {
1331
+ // Prefix which does not start with a / will never match anything, so
1332
+ // ignore this route.
1333
+ *ignore_route = true;
1334
+ return GRPC_ERROR_NONE;
1335
+ }
1336
+ std::vector<absl::string_view> prefix_elements =
1337
+ absl::StrSplit(prefix.substr(1), absl::MaxSplits('/', 2));
1338
+ if (prefix_elements.size() > 2) {
1339
+ // Prefix cannot have more than 2 slashes.
1340
+ *ignore_route = true;
1341
+ return GRPC_ERROR_NONE;
1342
+ } else if (prefix_elements.size() == 2 && prefix_elements[0].empty()) {
1343
+ // Prefix contains empty string between the 2 slashes
1344
+ *ignore_route = true;
1345
+ return GRPC_ERROR_NONE;
1346
+ }
1347
+ }
1348
+ route->matchers.path_matcher.type =
1349
+ XdsApi::Route::Matchers::PathMatcher::PathMatcherType::PREFIX;
1350
+ route->matchers.path_matcher.string_matcher = std::string(prefix);
1351
+ } else if (envoy_config_route_v3_RouteMatch_has_path(match)) {
1352
+ absl::string_view path =
1353
+ UpbStringToAbsl(envoy_config_route_v3_RouteMatch_path(match));
1354
+ if (path.size() == 0) {
1355
+ // Path that is empty will never match anything, so ignore this route.
1356
+ *ignore_route = true;
1357
+ return GRPC_ERROR_NONE;
1358
+ }
1359
+ if (path[0] != '/') {
1360
+ // Path which does not start with a / will never match anything, so
1361
+ // ignore this route.
1362
+ *ignore_route = true;
1363
+ return GRPC_ERROR_NONE;
1364
+ }
1365
+ std::vector<absl::string_view> path_elements =
1366
+ absl::StrSplit(path.substr(1), absl::MaxSplits('/', 2));
1367
+ if (path_elements.size() != 2) {
1368
+ // Path not in the required format of /service/method will never match
1369
+ // anything, so ignore this route.
1370
+ *ignore_route = true;
1371
+ return GRPC_ERROR_NONE;
1372
+ } else if (path_elements[0].empty()) {
1373
+ // Path contains empty service name will never match anything, so ignore
1374
+ // this route.
1375
+ *ignore_route = true;
1376
+ return GRPC_ERROR_NONE;
1377
+ } else if (path_elements[1].empty()) {
1378
+ // Path contains empty method name will never match anything, so ignore
1379
+ // this route.
1380
+ *ignore_route = true;
1381
+ return GRPC_ERROR_NONE;
1382
+ }
1383
+ route->matchers.path_matcher.type =
1384
+ XdsApi::Route::Matchers::PathMatcher::PathMatcherType::PATH;
1385
+ route->matchers.path_matcher.string_matcher = std::string(path);
1386
+ } else if (envoy_config_route_v3_RouteMatch_has_safe_regex(match)) {
1387
+ const envoy_type_matcher_v3_RegexMatcher* regex_matcher =
1388
+ envoy_config_route_v3_RouteMatch_safe_regex(match);
1389
+ GPR_ASSERT(regex_matcher != nullptr);
1390
+ std::string matcher = UpbStringToStdString(
1391
+ envoy_type_matcher_v3_RegexMatcher_regex(regex_matcher));
1392
+ std::unique_ptr<RE2> regex = absl::make_unique<RE2>(std::move(matcher));
1393
+ if (!regex->ok()) {
1394
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1395
+ "Invalid regex string specified in path matcher.");
1396
+ }
1397
+ route->matchers.path_matcher.type =
1398
+ XdsApi::Route::Matchers::PathMatcher::PathMatcherType::REGEX;
1399
+ route->matchers.path_matcher.regex_matcher = std::move(regex);
1400
+ } else {
1401
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1402
+ "Invalid route path specifier specified.");
1403
+ }
1404
+ return GRPC_ERROR_NONE;
1405
+ }
1406
+
1407
+ grpc_error* RouteHeaderMatchersParse(
1408
+ const envoy_config_route_v3_RouteMatch* match, XdsApi::Route* route) {
1409
+ size_t size;
1410
+ const envoy_config_route_v3_HeaderMatcher* const* headers =
1411
+ envoy_config_route_v3_RouteMatch_headers(match, &size);
1412
+ for (size_t i = 0; i < size; ++i) {
1413
+ const envoy_config_route_v3_HeaderMatcher* header = headers[i];
1414
+ XdsApi::Route::Matchers::HeaderMatcher header_matcher;
1415
+ header_matcher.name =
1416
+ UpbStringToStdString(envoy_config_route_v3_HeaderMatcher_name(header));
1417
+ if (envoy_config_route_v3_HeaderMatcher_has_exact_match(header)) {
1418
+ header_matcher.type =
1419
+ XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::EXACT;
1420
+ header_matcher.string_matcher = UpbStringToStdString(
1421
+ envoy_config_route_v3_HeaderMatcher_exact_match(header));
1422
+ } else if (envoy_config_route_v3_HeaderMatcher_has_safe_regex_match(
1423
+ header)) {
1424
+ const envoy_type_matcher_v3_RegexMatcher* regex_matcher =
1425
+ envoy_config_route_v3_HeaderMatcher_safe_regex_match(header);
1426
+ GPR_ASSERT(regex_matcher != nullptr);
1427
+ const std::string matcher = UpbStringToStdString(
1428
+ envoy_type_matcher_v3_RegexMatcher_regex(regex_matcher));
1429
+ std::unique_ptr<RE2> regex = absl::make_unique<RE2>(matcher);
1430
+ if (!regex->ok()) {
1431
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1432
+ "Invalid regex string specified in header matcher.");
1433
+ }
1434
+ header_matcher.type =
1435
+ XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::REGEX;
1436
+ header_matcher.regex_match = std::move(regex);
1437
+ } else if (envoy_config_route_v3_HeaderMatcher_has_range_match(header)) {
1438
+ header_matcher.type =
1439
+ XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::RANGE;
1440
+ const envoy_type_v3_Int64Range* range_matcher =
1441
+ envoy_config_route_v3_HeaderMatcher_range_match(header);
1442
+ header_matcher.range_start =
1443
+ envoy_type_v3_Int64Range_start(range_matcher);
1444
+ header_matcher.range_end = envoy_type_v3_Int64Range_end(range_matcher);
1445
+ if (header_matcher.range_end < header_matcher.range_start) {
1446
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1447
+ "Invalid range header matcher specifier specified: end "
1448
+ "cannot be smaller than start.");
1449
+ }
1450
+ } else if (envoy_config_route_v3_HeaderMatcher_has_present_match(header)) {
1451
+ header_matcher.type =
1452
+ XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::PRESENT;
1453
+ header_matcher.present_match =
1454
+ envoy_config_route_v3_HeaderMatcher_present_match(header);
1455
+ } else if (envoy_config_route_v3_HeaderMatcher_has_prefix_match(header)) {
1456
+ header_matcher.type =
1457
+ XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::PREFIX;
1458
+ header_matcher.string_matcher = UpbStringToStdString(
1459
+ envoy_config_route_v3_HeaderMatcher_prefix_match(header));
1460
+ } else if (envoy_config_route_v3_HeaderMatcher_has_suffix_match(header)) {
1461
+ header_matcher.type =
1462
+ XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::SUFFIX;
1463
+ header_matcher.string_matcher = UpbStringToStdString(
1464
+ envoy_config_route_v3_HeaderMatcher_suffix_match(header));
1465
+ } else {
1466
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1467
+ "Invalid route header matcher specified.");
1468
+ }
1469
+ header_matcher.invert_match =
1470
+ envoy_config_route_v3_HeaderMatcher_invert_match(header);
1471
+ route->matchers.header_matchers.emplace_back(std::move(header_matcher));
1472
+ }
1473
+ return GRPC_ERROR_NONE;
1474
+ }
1475
+
1476
+ grpc_error* RouteRuntimeFractionParse(
1477
+ const envoy_config_route_v3_RouteMatch* match, XdsApi::Route* route) {
1478
+ const envoy_config_core_v3_RuntimeFractionalPercent* runtime_fraction =
1479
+ envoy_config_route_v3_RouteMatch_runtime_fraction(match);
1480
+ if (runtime_fraction != nullptr) {
1481
+ const envoy_type_v3_FractionalPercent* fraction =
1482
+ envoy_config_core_v3_RuntimeFractionalPercent_default_value(
1483
+ runtime_fraction);
1484
+ if (fraction != nullptr) {
1485
+ uint32_t numerator = envoy_type_v3_FractionalPercent_numerator(fraction);
1486
+ const auto denominator =
1487
+ static_cast<envoy_type_v3_FractionalPercent_DenominatorType>(
1488
+ envoy_type_v3_FractionalPercent_denominator(fraction));
1489
+ // Normalize to million.
1490
+ switch (denominator) {
1491
+ case envoy_type_v3_FractionalPercent_HUNDRED:
1492
+ numerator *= 10000;
1493
+ break;
1494
+ case envoy_type_v3_FractionalPercent_TEN_THOUSAND:
1495
+ numerator *= 100;
1496
+ break;
1497
+ case envoy_type_v3_FractionalPercent_MILLION:
1498
+ break;
1499
+ default:
1500
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1501
+ "Unknown denominator type");
1502
+ }
1503
+ route->matchers.fraction_per_million = numerator;
1504
+ }
1505
+ }
1506
+ return GRPC_ERROR_NONE;
1507
+ }
1508
+
1509
+ grpc_error* RouteActionParse(const envoy_config_route_v3_Route* route_msg,
1510
+ XdsApi::Route* route, bool* ignore_route) {
1511
+ if (!envoy_config_route_v3_Route_has_route(route_msg)) {
1512
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1513
+ "No RouteAction found in route.");
1514
+ }
1515
+ const envoy_config_route_v3_RouteAction* route_action =
1516
+ envoy_config_route_v3_Route_route(route_msg);
1517
+ // Get the cluster or weighted_clusters in the RouteAction.
1518
+ if (envoy_config_route_v3_RouteAction_has_cluster(route_action)) {
1519
+ route->cluster_name = UpbStringToStdString(
1520
+ envoy_config_route_v3_RouteAction_cluster(route_action));
1521
+ if (route->cluster_name.size() == 0) {
1522
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1523
+ "RouteAction cluster contains empty cluster name.");
1524
+ }
1525
+ } else if (envoy_config_route_v3_RouteAction_has_weighted_clusters(
1526
+ route_action)) {
1527
+ const envoy_config_route_v3_WeightedCluster* weighted_cluster =
1528
+ envoy_config_route_v3_RouteAction_weighted_clusters(route_action);
1529
+ uint32_t total_weight = 100;
1530
+ const google_protobuf_UInt32Value* weight =
1531
+ envoy_config_route_v3_WeightedCluster_total_weight(weighted_cluster);
1532
+ if (weight != nullptr) {
1533
+ total_weight = google_protobuf_UInt32Value_value(weight);
1534
+ }
1535
+ size_t clusters_size;
1536
+ const envoy_config_route_v3_WeightedCluster_ClusterWeight* const* clusters =
1537
+ envoy_config_route_v3_WeightedCluster_clusters(weighted_cluster,
1538
+ &clusters_size);
1539
+ uint32_t sum_of_weights = 0;
1540
+ for (size_t j = 0; j < clusters_size; ++j) {
1541
+ const envoy_config_route_v3_WeightedCluster_ClusterWeight*
1542
+ cluster_weight = clusters[j];
1543
+ XdsApi::Route::ClusterWeight cluster;
1544
+ cluster.name = UpbStringToStdString(
1545
+ envoy_config_route_v3_WeightedCluster_ClusterWeight_name(
1546
+ cluster_weight));
1547
+ if (cluster.name.empty()) {
1548
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1549
+ "RouteAction weighted_cluster cluster contains empty cluster "
1550
+ "name.");
1551
+ }
1552
+ const google_protobuf_UInt32Value* weight =
1553
+ envoy_config_route_v3_WeightedCluster_ClusterWeight_weight(
1554
+ cluster_weight);
1555
+ if (weight == nullptr) {
1556
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1557
+ "RouteAction weighted_cluster cluster missing weight");
1558
+ }
1559
+ cluster.weight = google_protobuf_UInt32Value_value(weight);
1560
+ sum_of_weights += cluster.weight;
1561
+ route->weighted_clusters.emplace_back(std::move(cluster));
1562
+ }
1563
+ if (total_weight != sum_of_weights) {
1564
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1565
+ "RouteAction weighted_cluster has incorrect total weight");
1566
+ }
1567
+ if (route->weighted_clusters.empty()) {
1568
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1569
+ "RouteAction weighted_cluster has no valid clusters specified.");
1570
+ }
1571
+ } else {
1572
+ // No cluster or weighted_clusters found in RouteAction, ignore this route.
1573
+ *ignore_route = true;
1574
+ return GRPC_ERROR_NONE;
1575
+ }
1576
+ return GRPC_ERROR_NONE;
1577
+ }
1578
+
1579
+ grpc_error* RouteConfigParse(
1580
+ XdsClient* client, TraceFlag* tracer,
1581
+ const envoy_config_route_v3_RouteConfiguration* route_config,
1582
+ XdsApi::RdsUpdate* rds_update) {
1583
+ MaybeLogRouteConfiguration(client, tracer, route_config);
1584
+ // Get the virtual hosts.
1585
+ size_t size;
1586
+ const envoy_config_route_v3_VirtualHost* const* virtual_hosts =
1587
+ envoy_config_route_v3_RouteConfiguration_virtual_hosts(route_config,
1588
+ &size);
1589
+ for (size_t i = 0; i < size; ++i) {
1590
+ rds_update->virtual_hosts.emplace_back();
1591
+ XdsApi::RdsUpdate::VirtualHost& vhost = rds_update->virtual_hosts.back();
1592
+ // Parse domains.
1593
+ size_t domain_size;
1594
+ upb_strview const* domains = envoy_config_route_v3_VirtualHost_domains(
1595
+ virtual_hosts[i], &domain_size);
1596
+ for (size_t j = 0; j < domain_size; ++j) {
1597
+ std::string domain_pattern = UpbStringToStdString(domains[j]);
1598
+ const MatchType match_type = DomainPatternMatchType(domain_pattern);
1599
+ if (match_type == INVALID_MATCH) {
1600
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1601
+ absl::StrCat("Invalid domain pattern \"", domain_pattern, "\".")
1602
+ .c_str());
1603
+ }
1604
+ vhost.domains.emplace_back(std::move(domain_pattern));
1605
+ }
1606
+ if (vhost.domains.empty()) {
1607
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("VirtualHost has no domains");
1608
+ }
1609
+ // Parse routes.
1610
+ size_t num_routes;
1611
+ const envoy_config_route_v3_Route* const* routes =
1612
+ envoy_config_route_v3_VirtualHost_routes(virtual_hosts[i], &num_routes);
1613
+ if (num_routes < 1) {
1614
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1615
+ "No route found in the virtual host.");
1616
+ }
1617
+ // Loop over the whole list of routes
1618
+ for (size_t j = 0; j < num_routes; ++j) {
1619
+ const envoy_config_route_v3_RouteMatch* match =
1620
+ envoy_config_route_v3_Route_match(routes[j]);
1621
+ size_t query_parameters_size;
1622
+ static_cast<void>(envoy_config_route_v3_RouteMatch_query_parameters(
1623
+ match, &query_parameters_size));
1624
+ if (query_parameters_size > 0) {
1625
+ continue;
1626
+ }
1627
+ XdsApi::Route route;
1628
+ bool ignore_route = false;
1629
+ grpc_error* error = RoutePathMatchParse(match, &route, &ignore_route);
1630
+ if (error != GRPC_ERROR_NONE) return error;
1631
+ if (ignore_route) continue;
1632
+ error = RouteHeaderMatchersParse(match, &route);
1633
+ if (error != GRPC_ERROR_NONE) return error;
1634
+ error = RouteRuntimeFractionParse(match, &route);
1635
+ if (error != GRPC_ERROR_NONE) return error;
1636
+ error = RouteActionParse(routes[j], &route, &ignore_route);
1637
+ if (error != GRPC_ERROR_NONE) return error;
1638
+ if (ignore_route) continue;
1639
+ const google_protobuf_BoolValue* case_sensitive =
1640
+ envoy_config_route_v3_RouteMatch_case_sensitive(match);
1641
+ if (case_sensitive != nullptr &&
1642
+ !google_protobuf_BoolValue_value(case_sensitive)) {
1643
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1644
+ "case_sensitive if set must be set to true.");
1645
+ }
1646
+ vhost.routes.emplace_back(std::move(route));
1647
+ }
1648
+ if (vhost.routes.empty()) {
1649
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No valid routes specified.");
1650
+ }
1651
+ }
1652
+ return GRPC_ERROR_NONE;
1653
+ }
1654
+
1655
+ grpc_error* LdsResponseParse(
1656
+ XdsClient* client, TraceFlag* tracer,
1657
+ const envoy_service_discovery_v3_DiscoveryResponse* response,
1658
+ const std::set<absl::string_view>& expected_listener_names,
1659
+ XdsApi::LdsUpdateMap* lds_update_map, upb_arena* arena) {
1660
+ // Get the resources from the response.
1661
+ size_t size;
1662
+ const google_protobuf_Any* const* resources =
1663
+ envoy_service_discovery_v3_DiscoveryResponse_resources(response, &size);
1664
+ for (size_t i = 0; i < size; ++i) {
1665
+ // Check the type_url of the resource.
1666
+ absl::string_view type_url =
1667
+ UpbStringToAbsl(google_protobuf_Any_type_url(resources[i]));
1668
+ if (!IsLds(type_url)) {
1669
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not LDS.");
1670
+ }
1671
+ // Decode the listener.
1672
+ const upb_strview encoded_listener =
1673
+ google_protobuf_Any_value(resources[i]);
1674
+ const envoy_config_listener_v3_Listener* listener =
1675
+ envoy_config_listener_v3_Listener_parse(encoded_listener.data,
1676
+ encoded_listener.size, arena);
1677
+ if (listener == nullptr) {
1678
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode listener.");
1679
+ }
1680
+ // Check listener name. Ignore unexpected listeners.
1681
+ std::string listener_name =
1682
+ UpbStringToStdString(envoy_config_listener_v3_Listener_name(listener));
1683
+ if (expected_listener_names.find(listener_name) ==
1684
+ expected_listener_names.end()) {
1685
+ continue;
1686
+ }
1687
+ // Fail if listener name is duplicated.
1688
+ if (lds_update_map->find(listener_name) != lds_update_map->end()) {
1689
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1690
+ absl::StrCat("duplicate listener name \"", listener_name, "\"")
1691
+ .c_str());
1692
+ }
1693
+ XdsApi::LdsUpdate& lds_update = (*lds_update_map)[listener_name];
1694
+ // Get api_listener and decode it to http_connection_manager.
1695
+ const envoy_config_listener_v3_ApiListener* api_listener =
1696
+ envoy_config_listener_v3_Listener_api_listener(listener);
1697
+ if (api_listener == nullptr) {
1698
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1699
+ "Listener has no ApiListener.");
1700
+ }
1701
+ const upb_strview encoded_api_listener = google_protobuf_Any_value(
1702
+ envoy_config_listener_v3_ApiListener_api_listener(api_listener));
1703
+ const envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager*
1704
+ http_connection_manager =
1705
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_parse(
1706
+ encoded_api_listener.data, encoded_api_listener.size, arena);
1707
+ if (http_connection_manager == nullptr) {
1708
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1709
+ "Could not parse HttpConnectionManager config from ApiListener");
1710
+ }
1711
+ // Found inlined route_config. Parse it to find the cluster_name.
1712
+ if (envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_route_config(
1713
+ http_connection_manager)) {
1714
+ const envoy_config_route_v3_RouteConfiguration* route_config =
1715
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_route_config(
1716
+ http_connection_manager);
1717
+ XdsApi::RdsUpdate rds_update;
1718
+ grpc_error* error =
1719
+ RouteConfigParse(client, tracer, route_config, &rds_update);
1720
+ if (error != GRPC_ERROR_NONE) return error;
1721
+ lds_update.rds_update = std::move(rds_update);
1722
+ continue;
1723
+ }
1724
+ // Validate that RDS must be used to get the route_config dynamically.
1725
+ if (!envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_rds(
1726
+ http_connection_manager)) {
1727
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1728
+ "HttpConnectionManager neither has inlined route_config nor RDS.");
1729
+ }
1730
+ const envoy_extensions_filters_network_http_connection_manager_v3_Rds* rds =
1731
+ envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_rds(
1732
+ http_connection_manager);
1733
+ // Check that the ConfigSource specifies ADS.
1734
+ const envoy_config_core_v3_ConfigSource* config_source =
1735
+ envoy_extensions_filters_network_http_connection_manager_v3_Rds_config_source(
1736
+ rds);
1737
+ if (config_source == nullptr) {
1738
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1739
+ "HttpConnectionManager missing config_source for RDS.");
1740
+ }
1741
+ if (!envoy_config_core_v3_ConfigSource_has_ads(config_source)) {
1742
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1743
+ "HttpConnectionManager ConfigSource for RDS does not specify ADS.");
1744
+ }
1745
+ // Get the route_config_name.
1746
+ lds_update.route_config_name = UpbStringToStdString(
1747
+ envoy_extensions_filters_network_http_connection_manager_v3_Rds_route_config_name(
1748
+ rds));
1749
+ }
1750
+ return GRPC_ERROR_NONE;
1751
+ }
1752
+
1753
+ grpc_error* RdsResponseParse(
1754
+ XdsClient* client, TraceFlag* tracer,
1755
+ const envoy_service_discovery_v3_DiscoveryResponse* response,
1756
+ const std::set<absl::string_view>& expected_route_configuration_names,
1757
+ XdsApi::RdsUpdateMap* rds_update_map, upb_arena* arena) {
1758
+ // Get the resources from the response.
1759
+ size_t size;
1760
+ const google_protobuf_Any* const* resources =
1761
+ envoy_service_discovery_v3_DiscoveryResponse_resources(response, &size);
1762
+ for (size_t i = 0; i < size; ++i) {
1763
+ // Check the type_url of the resource.
1764
+ absl::string_view type_url =
1765
+ UpbStringToAbsl(google_protobuf_Any_type_url(resources[i]));
1766
+ if (!IsRds(type_url)) {
1767
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not RDS.");
1768
+ }
1769
+ // Decode the route_config.
1770
+ const upb_strview encoded_route_config =
1771
+ google_protobuf_Any_value(resources[i]);
1772
+ const envoy_config_route_v3_RouteConfiguration* route_config =
1773
+ envoy_config_route_v3_RouteConfiguration_parse(
1774
+ encoded_route_config.data, encoded_route_config.size, arena);
1775
+ if (route_config == nullptr) {
1776
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode route_config.");
1777
+ }
1778
+ // Check route_config_name. Ignore unexpected route_config.
1779
+ std::string route_config_name = UpbStringToStdString(
1780
+ envoy_config_route_v3_RouteConfiguration_name(route_config));
1781
+ if (expected_route_configuration_names.find(route_config_name) ==
1782
+ expected_route_configuration_names.end()) {
1783
+ continue;
1784
+ }
1785
+ // Fail if route config name is duplicated.
1786
+ if (rds_update_map->find(route_config_name) != rds_update_map->end()) {
1787
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1788
+ absl::StrCat("duplicate route config name \"", route_config_name,
1789
+ "\"")
1790
+ .c_str());
1791
+ }
1792
+ // Parse the route_config.
1793
+ XdsApi::RdsUpdate& rds_update =
1794
+ (*rds_update_map)[std::move(route_config_name)];
1795
+ grpc_error* error =
1796
+ RouteConfigParse(client, tracer, route_config, &rds_update);
1797
+ if (error != GRPC_ERROR_NONE) return error;
1798
+ }
1799
+ return GRPC_ERROR_NONE;
1800
+ }
1801
+
1802
+ grpc_error* CommonTlsContextParse(
1803
+ const envoy_extensions_transport_sockets_tls_v3_CommonTlsContext*
1804
+ common_tls_context_proto,
1805
+ XdsApi::CommonTlsContext* common_tls_context) GRPC_MUST_USE_RESULT;
1806
+ grpc_error* CommonTlsContextParse(
1807
+ const envoy_extensions_transport_sockets_tls_v3_CommonTlsContext*
1808
+ common_tls_context_proto,
1809
+ XdsApi::CommonTlsContext* common_tls_context) {
1810
+ auto* combined_validation_context =
1811
+ envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_combined_validation_context(
1812
+ common_tls_context_proto);
1813
+ if (combined_validation_context != nullptr) {
1814
+ auto* default_validation_context =
1815
+ envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_CombinedCertificateValidationContext_default_validation_context(
1816
+ combined_validation_context);
1817
+ if (default_validation_context != nullptr) {
1818
+ size_t len = 0;
1819
+ auto* subject_alt_names_matchers =
1820
+ envoy_extensions_transport_sockets_tls_v3_CertificateValidationContext_match_subject_alt_names(
1821
+ default_validation_context, &len);
1822
+ for (size_t i = 0; i < len; ++i) {
1823
+ XdsApi::StringMatcher matcher;
1824
+ if (envoy_type_matcher_v3_StringMatcher_has_exact(
1825
+ subject_alt_names_matchers[i])) {
1826
+ matcher.type = XdsApi::StringMatcher::StringMatcherType::EXACT;
1827
+ matcher.string_matcher =
1828
+ UpbStringToStdString(envoy_type_matcher_v3_StringMatcher_exact(
1829
+ subject_alt_names_matchers[i]));
1830
+ } else if (envoy_type_matcher_v3_StringMatcher_has_prefix(
1831
+ subject_alt_names_matchers[i])) {
1832
+ matcher.type = XdsApi::StringMatcher::StringMatcherType::PREFIX;
1833
+ matcher.string_matcher =
1834
+ UpbStringToStdString(envoy_type_matcher_v3_StringMatcher_prefix(
1835
+ subject_alt_names_matchers[i]));
1836
+ } else if (envoy_type_matcher_v3_StringMatcher_has_suffix(
1837
+ subject_alt_names_matchers[i])) {
1838
+ matcher.type = XdsApi::StringMatcher::StringMatcherType::SUFFIX;
1839
+ matcher.string_matcher =
1840
+ UpbStringToStdString(envoy_type_matcher_v3_StringMatcher_suffix(
1841
+ subject_alt_names_matchers[i]));
1842
+ } else if (envoy_type_matcher_v3_StringMatcher_has_safe_regex(
1843
+ subject_alt_names_matchers[i])) {
1844
+ matcher.type = XdsApi::StringMatcher::StringMatcherType::SAFE_REGEX;
1845
+ auto* regex_matcher = envoy_type_matcher_v3_StringMatcher_safe_regex(
1846
+ subject_alt_names_matchers[i]);
1847
+ std::unique_ptr<RE2> regex =
1848
+ absl::make_unique<RE2>(UpbStringToStdString(
1849
+ envoy_type_matcher_v3_RegexMatcher_regex(regex_matcher)));
1850
+ if (!regex->ok()) {
1851
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1852
+ "Invalid regex string specified in string matcher.");
1853
+ }
1854
+ matcher.regex_match = std::move(regex);
1855
+ } else {
1856
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1857
+ "Invalid StringMatcher specified");
1858
+ }
1859
+ matcher.ignore_case = envoy_type_matcher_v3_StringMatcher_ignore_case(
1860
+ subject_alt_names_matchers[i]);
1861
+ common_tls_context->combined_validation_context
1862
+ .default_validation_context.match_subject_alt_names.emplace_back(
1863
+ matcher);
1864
+ }
1865
+ }
1866
+ auto* validation_context_certificate_provider_instance =
1867
+ envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_CombinedCertificateValidationContext_validation_context_certificate_provider_instance(
1868
+ combined_validation_context);
1869
+ if (validation_context_certificate_provider_instance != nullptr) {
1870
+ common_tls_context->combined_validation_context
1871
+ .validation_context_certificate_provider_instance = UpbStringToStdString(
1872
+ envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_CertificateProviderInstance_instance_name(
1873
+ validation_context_certificate_provider_instance));
1874
+ }
1875
+ }
1876
+ auto* tls_certificate_certificate_provider_instance =
1877
+ envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_tls_certificate_certificate_provider_instance(
1878
+ common_tls_context_proto);
1879
+ if (tls_certificate_certificate_provider_instance != nullptr) {
1880
+ common_tls_context
1881
+ ->tls_certificate_certificate_provider_instance = UpbStringToStdString(
1882
+ envoy_extensions_transport_sockets_tls_v3_CommonTlsContext_CertificateProviderInstance_instance_name(
1883
+ tls_certificate_certificate_provider_instance));
1884
+ }
1885
+ return GRPC_ERROR_NONE;
1886
+ }
1887
+
1888
+ grpc_error* CdsResponseParse(
1889
+ XdsClient* client, TraceFlag* tracer,
1890
+ const envoy_service_discovery_v3_DiscoveryResponse* response,
1891
+ const std::set<absl::string_view>& expected_cluster_names,
1892
+ XdsApi::CdsUpdateMap* cds_update_map, upb_arena* arena) {
1893
+ // Get the resources from the response.
1894
+ size_t size;
1895
+ const google_protobuf_Any* const* resources =
1896
+ envoy_service_discovery_v3_DiscoveryResponse_resources(response, &size);
1897
+ // Parse all the resources in the CDS response.
1898
+ for (size_t i = 0; i < size; ++i) {
1899
+ // Check the type_url of the resource.
1900
+ absl::string_view type_url =
1901
+ UpbStringToAbsl(google_protobuf_Any_type_url(resources[i]));
1902
+ if (!IsCds(type_url)) {
1903
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not CDS.");
1904
+ }
1905
+ // Decode the cluster.
1906
+ const upb_strview encoded_cluster = google_protobuf_Any_value(resources[i]);
1907
+ const envoy_config_cluster_v3_Cluster* cluster =
1908
+ envoy_config_cluster_v3_Cluster_parse(encoded_cluster.data,
1909
+ encoded_cluster.size, arena);
1910
+ if (cluster == nullptr) {
1911
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode cluster.");
1912
+ }
1913
+ MaybeLogCluster(client, tracer, cluster);
1914
+ // Ignore unexpected cluster names.
1915
+ std::string cluster_name =
1916
+ UpbStringToStdString(envoy_config_cluster_v3_Cluster_name(cluster));
1917
+ if (expected_cluster_names.find(cluster_name) ==
1918
+ expected_cluster_names.end()) {
1919
+ continue;
1920
+ }
1921
+ // Fail on duplicate resources.
1922
+ if (cds_update_map->find(cluster_name) != cds_update_map->end()) {
1923
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1924
+ absl::StrCat("duplicate resource name \"", cluster_name, "\"")
1925
+ .c_str());
1926
+ }
1927
+ XdsApi::CdsUpdate& cds_update = (*cds_update_map)[std::move(cluster_name)];
1928
+ // Check the cluster_discovery_type.
1929
+ if (!envoy_config_cluster_v3_Cluster_has_type(cluster)) {
1930
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("DiscoveryType not found.");
1931
+ }
1932
+ if (envoy_config_cluster_v3_Cluster_type(cluster) !=
1933
+ envoy_config_cluster_v3_Cluster_EDS) {
1934
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("DiscoveryType is not EDS.");
1935
+ }
1936
+ // Check the EDS config source.
1937
+ const envoy_config_cluster_v3_Cluster_EdsClusterConfig* eds_cluster_config =
1938
+ envoy_config_cluster_v3_Cluster_eds_cluster_config(cluster);
1939
+ const envoy_config_core_v3_ConfigSource* eds_config =
1940
+ envoy_config_cluster_v3_Cluster_EdsClusterConfig_eds_config(
1941
+ eds_cluster_config);
1942
+ if (!envoy_config_core_v3_ConfigSource_has_ads(eds_config)) {
1943
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1944
+ "EDS ConfigSource is not ADS.");
1945
+ }
1946
+ // Record EDS service_name (if any).
1947
+ upb_strview service_name =
1948
+ envoy_config_cluster_v3_Cluster_EdsClusterConfig_service_name(
1949
+ eds_cluster_config);
1950
+ if (service_name.size != 0) {
1951
+ cds_update.eds_service_name = UpbStringToStdString(service_name);
1952
+ }
1953
+ // Check the LB policy.
1954
+ if (envoy_config_cluster_v3_Cluster_lb_policy(cluster) !=
1955
+ envoy_config_cluster_v3_Cluster_ROUND_ROBIN) {
1956
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1957
+ "LB policy is not ROUND_ROBIN.");
1958
+ }
1959
+ // Record Upstream tls context
1960
+ auto* transport_socket =
1961
+ envoy_config_cluster_v3_Cluster_transport_socket(cluster);
1962
+ if (transport_socket != nullptr) {
1963
+ absl::string_view name = UpbStringToAbsl(
1964
+ envoy_config_core_v3_TransportSocket_name(transport_socket));
1965
+ if (name == "tls") {
1966
+ auto* typed_config =
1967
+ envoy_config_core_v3_TransportSocket_typed_config(transport_socket);
1968
+ if (typed_config != nullptr) {
1969
+ const upb_strview encoded_upstream_tls_context =
1970
+ google_protobuf_Any_value(typed_config);
1971
+ auto* upstream_tls_context =
1972
+ envoy_extensions_transport_sockets_tls_v3_UpstreamTlsContext_parse(
1973
+ encoded_upstream_tls_context.data,
1974
+ encoded_upstream_tls_context.size, arena);
1975
+ if (upstream_tls_context == nullptr) {
1976
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1977
+ "Can't decode upstream tls context.");
1978
+ }
1979
+ auto* common_tls_context =
1980
+ envoy_extensions_transport_sockets_tls_v3_UpstreamTlsContext_common_tls_context(
1981
+ upstream_tls_context);
1982
+ if (common_tls_context != nullptr) {
1983
+ grpc_error* error = CommonTlsContextParse(
1984
+ common_tls_context, &cds_update.common_tls_context);
1985
+ if (error != GRPC_ERROR_NONE) return error;
1986
+ }
1987
+ }
1988
+ }
1989
+ }
1990
+ // Record LRS server name (if any).
1991
+ const envoy_config_core_v3_ConfigSource* lrs_server =
1992
+ envoy_config_cluster_v3_Cluster_lrs_server(cluster);
1993
+ if (lrs_server != nullptr) {
1994
+ if (!envoy_config_core_v3_ConfigSource_has_self(lrs_server)) {
1995
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1996
+ "LRS ConfigSource is not self.");
1997
+ }
1998
+ cds_update.lrs_load_reporting_server_name.emplace("");
1999
+ }
2000
+ // The Cluster resource encodes the circuit breaking parameters in a list of
2001
+ // Thresholds messages, where each message specifies the parameters for a
2002
+ // particular RoutingPriority. we will look only at the first entry in the
2003
+ // list for priority DEFAULT and default to 1024 if not found.
2004
+ if (envoy_config_cluster_v3_Cluster_has_circuit_breakers(cluster)) {
2005
+ const envoy_config_cluster_v3_CircuitBreakers* circuit_breakers =
2006
+ envoy_config_cluster_v3_Cluster_circuit_breakers(cluster);
2007
+ size_t num_thresholds;
2008
+ const envoy_config_cluster_v3_CircuitBreakers_Thresholds* const*
2009
+ thresholds = envoy_config_cluster_v3_CircuitBreakers_thresholds(
2010
+ circuit_breakers, &num_thresholds);
2011
+ for (size_t i = 0; i < num_thresholds; ++i) {
2012
+ const auto* threshold = thresholds[i];
2013
+ if (envoy_config_cluster_v3_CircuitBreakers_Thresholds_priority(
2014
+ threshold) == envoy_config_core_v3_DEFAULT) {
2015
+ const google_protobuf_UInt32Value* max_requests =
2016
+ envoy_config_cluster_v3_CircuitBreakers_Thresholds_max_requests(
2017
+ threshold);
2018
+ if (max_requests != nullptr) {
2019
+ cds_update.max_concurrent_requests =
2020
+ google_protobuf_UInt32Value_value(max_requests);
2021
+ }
2022
+ break;
2023
+ }
2024
+ }
2025
+ }
2026
+ }
2027
+ return GRPC_ERROR_NONE;
2028
+ }
2029
+
2030
+ grpc_error* ServerAddressParseAndAppend(
2031
+ const envoy_config_endpoint_v3_LbEndpoint* lb_endpoint,
2032
+ ServerAddressList* list) {
2033
+ // If health_status is not HEALTHY or UNKNOWN, skip this endpoint.
2034
+ const int32_t health_status =
2035
+ envoy_config_endpoint_v3_LbEndpoint_health_status(lb_endpoint);
2036
+ if (health_status != envoy_config_core_v3_UNKNOWN &&
2037
+ health_status != envoy_config_core_v3_HEALTHY) {
2038
+ return GRPC_ERROR_NONE;
2039
+ }
2040
+ // Find the ip:port.
2041
+ const envoy_config_endpoint_v3_Endpoint* endpoint =
2042
+ envoy_config_endpoint_v3_LbEndpoint_endpoint(lb_endpoint);
2043
+ const envoy_config_core_v3_Address* address =
2044
+ envoy_config_endpoint_v3_Endpoint_address(endpoint);
2045
+ const envoy_config_core_v3_SocketAddress* socket_address =
2046
+ envoy_config_core_v3_Address_socket_address(address);
2047
+ std::string address_str = UpbStringToStdString(
2048
+ envoy_config_core_v3_SocketAddress_address(socket_address));
2049
+ uint32_t port = envoy_config_core_v3_SocketAddress_port_value(socket_address);
2050
+ if (GPR_UNLIKELY(port >> 16) != 0) {
2051
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid port.");
2052
+ }
2053
+ // Populate grpc_resolved_address.
2054
+ grpc_resolved_address addr;
2055
+ grpc_string_to_sockaddr(&addr, address_str.c_str(), port);
2056
+ // Append the address to the list.
2057
+ list->emplace_back(addr, nullptr);
2058
+ return GRPC_ERROR_NONE;
2059
+ }
2060
+
2061
+ grpc_error* LocalityParse(
2062
+ const envoy_config_endpoint_v3_LocalityLbEndpoints* locality_lb_endpoints,
2063
+ XdsApi::EdsUpdate::Priority::Locality* output_locality, size_t* priority) {
2064
+ // Parse LB weight.
2065
+ const google_protobuf_UInt32Value* lb_weight =
2066
+ envoy_config_endpoint_v3_LocalityLbEndpoints_load_balancing_weight(
2067
+ locality_lb_endpoints);
2068
+ // If LB weight is not specified, it means this locality is assigned no load.
2069
+ // TODO(juanlishen): When we support CDS to configure the inter-locality
2070
+ // policy, we should change the LB weight handling.
2071
+ output_locality->lb_weight =
2072
+ lb_weight != nullptr ? google_protobuf_UInt32Value_value(lb_weight) : 0;
2073
+ if (output_locality->lb_weight == 0) return GRPC_ERROR_NONE;
2074
+ // Parse locality name.
2075
+ const envoy_config_core_v3_Locality* locality =
2076
+ envoy_config_endpoint_v3_LocalityLbEndpoints_locality(
2077
+ locality_lb_endpoints);
2078
+ std::string region =
2079
+ UpbStringToStdString(envoy_config_core_v3_Locality_region(locality));
2080
+ std::string zone =
2081
+ UpbStringToStdString(envoy_config_core_v3_Locality_region(locality));
2082
+ std::string sub_zone =
2083
+ UpbStringToStdString(envoy_config_core_v3_Locality_sub_zone(locality));
2084
+ output_locality->name = MakeRefCounted<XdsLocalityName>(
2085
+ std::move(region), std::move(zone), std::move(sub_zone));
2086
+ // Parse the addresses.
2087
+ size_t size;
2088
+ const envoy_config_endpoint_v3_LbEndpoint* const* lb_endpoints =
2089
+ envoy_config_endpoint_v3_LocalityLbEndpoints_lb_endpoints(
2090
+ locality_lb_endpoints, &size);
2091
+ for (size_t i = 0; i < size; ++i) {
2092
+ grpc_error* error = ServerAddressParseAndAppend(
2093
+ lb_endpoints[i], &output_locality->endpoints);
2094
+ if (error != GRPC_ERROR_NONE) return error;
2095
+ }
2096
+ // Parse the priority.
2097
+ *priority = envoy_config_endpoint_v3_LocalityLbEndpoints_priority(
2098
+ locality_lb_endpoints);
2099
+ return GRPC_ERROR_NONE;
2100
+ }
2101
+
2102
+ grpc_error* DropParseAndAppend(
2103
+ const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload*
2104
+ drop_overload,
2105
+ XdsApi::EdsUpdate::DropConfig* drop_config) {
2106
+ // Get the category.
2107
+ std::string category = UpbStringToStdString(
2108
+ envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_category(
2109
+ drop_overload));
2110
+ if (category.size() == 0) {
2111
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty drop category name");
2112
+ }
2113
+ // Get the drop rate (per million).
2114
+ const envoy_type_v3_FractionalPercent* drop_percentage =
2115
+ envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_drop_percentage(
2116
+ drop_overload);
2117
+ uint32_t numerator =
2118
+ envoy_type_v3_FractionalPercent_numerator(drop_percentage);
2119
+ const auto denominator =
2120
+ static_cast<envoy_type_v3_FractionalPercent_DenominatorType>(
2121
+ envoy_type_v3_FractionalPercent_denominator(drop_percentage));
2122
+ // Normalize to million.
2123
+ switch (denominator) {
2124
+ case envoy_type_v3_FractionalPercent_HUNDRED:
2125
+ numerator *= 10000;
2126
+ break;
2127
+ case envoy_type_v3_FractionalPercent_TEN_THOUSAND:
2128
+ numerator *= 100;
2129
+ break;
2130
+ case envoy_type_v3_FractionalPercent_MILLION:
2131
+ break;
2132
+ default:
2133
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Unknown denominator type");
2134
+ }
2135
+ // Cap numerator to 1000000.
2136
+ numerator = GPR_MIN(numerator, 1000000);
2137
+ drop_config->AddCategory(std::move(category), numerator);
2138
+ return GRPC_ERROR_NONE;
2139
+ }
2140
+
2141
+ grpc_error* EdsResponseParse(
2142
+ XdsClient* client, TraceFlag* tracer,
2143
+ const envoy_service_discovery_v3_DiscoveryResponse* response,
2144
+ const std::set<absl::string_view>& expected_eds_service_names,
2145
+ XdsApi::EdsUpdateMap* eds_update_map, upb_arena* arena) {
2146
+ // Get the resources from the response.
2147
+ size_t size;
2148
+ const google_protobuf_Any* const* resources =
2149
+ envoy_service_discovery_v3_DiscoveryResponse_resources(response, &size);
2150
+ for (size_t i = 0; i < size; ++i) {
2151
+ // Check the type_url of the resource.
2152
+ absl::string_view type_url =
2153
+ UpbStringToAbsl(google_protobuf_Any_type_url(resources[i]));
2154
+ if (!IsEds(type_url)) {
2155
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resource is not EDS.");
2156
+ }
2157
+ // Get the cluster_load_assignment.
2158
+ upb_strview encoded_cluster_load_assignment =
2159
+ google_protobuf_Any_value(resources[i]);
2160
+ envoy_config_endpoint_v3_ClusterLoadAssignment* cluster_load_assignment =
2161
+ envoy_config_endpoint_v3_ClusterLoadAssignment_parse(
2162
+ encoded_cluster_load_assignment.data,
2163
+ encoded_cluster_load_assignment.size, arena);
2164
+ if (cluster_load_assignment == nullptr) {
2165
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2166
+ "Can't parse cluster_load_assignment.");
2167
+ }
2168
+ MaybeLogClusterLoadAssignment(client, tracer, cluster_load_assignment);
2169
+ // Check the EDS service name. Ignore unexpected names.
2170
+ std::string eds_service_name = UpbStringToStdString(
2171
+ envoy_config_endpoint_v3_ClusterLoadAssignment_cluster_name(
2172
+ cluster_load_assignment));
2173
+ if (expected_eds_service_names.find(eds_service_name) ==
2174
+ expected_eds_service_names.end()) {
2175
+ continue;
2176
+ }
2177
+ // Fail on duplicate resources.
2178
+ if (eds_update_map->find(eds_service_name) != eds_update_map->end()) {
2179
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
2180
+ absl::StrCat("duplicate resource name \"", eds_service_name, "\"")
2181
+ .c_str());
2182
+ }
2183
+ XdsApi::EdsUpdate& eds_update =
2184
+ (*eds_update_map)[std::move(eds_service_name)];
2185
+ // Get the endpoints.
2186
+ size_t locality_size;
2187
+ const envoy_config_endpoint_v3_LocalityLbEndpoints* const* endpoints =
2188
+ envoy_config_endpoint_v3_ClusterLoadAssignment_endpoints(
2189
+ cluster_load_assignment, &locality_size);
2190
+ for (size_t j = 0; j < locality_size; ++j) {
2191
+ size_t priority;
2192
+ XdsApi::EdsUpdate::Priority::Locality locality;
2193
+ grpc_error* error = LocalityParse(endpoints[j], &locality, &priority);
2194
+ if (error != GRPC_ERROR_NONE) return error;
2195
+ // Filter out locality with weight 0.
2196
+ if (locality.lb_weight == 0) continue;
2197
+ // Make sure prorities is big enough. Note that they might not
2198
+ // arrive in priority order.
2199
+ while (eds_update.priorities.size() < priority + 1) {
2200
+ eds_update.priorities.emplace_back();
2201
+ }
2202
+ eds_update.priorities[priority].localities.emplace(locality.name.get(),
2203
+ std::move(locality));
2204
+ }
2205
+ for (const auto& priority : eds_update.priorities) {
2206
+ if (priority.localities.empty()) {
2207
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2208
+ "EDS update includes sparse priority list");
2209
+ }
2210
+ }
2211
+ // Get the drop config.
2212
+ eds_update.drop_config = MakeRefCounted<XdsApi::EdsUpdate::DropConfig>();
2213
+ const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy* policy =
2214
+ envoy_config_endpoint_v3_ClusterLoadAssignment_policy(
2215
+ cluster_load_assignment);
2216
+ if (policy != nullptr) {
2217
+ size_t drop_size;
2218
+ const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload* const*
2219
+ drop_overload =
2220
+ envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_drop_overloads(
2221
+ policy, &drop_size);
2222
+ for (size_t j = 0; j < drop_size; ++j) {
2223
+ grpc_error* error =
2224
+ DropParseAndAppend(drop_overload[j], eds_update.drop_config.get());
2225
+ if (error != GRPC_ERROR_NONE) return error;
2226
+ }
2227
+ }
2228
+ }
2229
+ return GRPC_ERROR_NONE;
2230
+ }
2231
+
2232
+ std::string TypeUrlInternalToExternal(absl::string_view type_url) {
2233
+ if (type_url == kLdsV2TypeUrl) {
2234
+ return XdsApi::kLdsTypeUrl;
2235
+ } else if (type_url == kRdsV2TypeUrl) {
2236
+ return XdsApi::kRdsTypeUrl;
2237
+ } else if (type_url == kCdsV2TypeUrl) {
2238
+ return XdsApi::kCdsTypeUrl;
2239
+ } else if (type_url == kEdsV2TypeUrl) {
2240
+ return XdsApi::kEdsTypeUrl;
2241
+ }
2242
+ return std::string(type_url);
2243
+ }
2244
+
2245
+ } // namespace
2246
+
2247
+ XdsApi::AdsParseResult XdsApi::ParseAdsResponse(
2248
+ const grpc_slice& encoded_response,
2249
+ const std::set<absl::string_view>& expected_listener_names,
2250
+ const std::set<absl::string_view>& expected_route_configuration_names,
2251
+ const std::set<absl::string_view>& expected_cluster_names,
2252
+ const std::set<absl::string_view>& expected_eds_service_names) {
2253
+ AdsParseResult result;
2254
+ upb::Arena arena;
2255
+ // Decode the response.
2256
+ const envoy_service_discovery_v3_DiscoveryResponse* response =
2257
+ envoy_service_discovery_v3_DiscoveryResponse_parse(
2258
+ reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(encoded_response)),
2259
+ GRPC_SLICE_LENGTH(encoded_response), arena.ptr());
2260
+ // If decoding fails, output an empty type_url and return.
2261
+ if (response == nullptr) {
2262
+ result.parse_error =
2263
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode DiscoveryResponse.");
2264
+ return result;
2265
+ }
2266
+ MaybeLogDiscoveryResponse(client_, tracer_, response);
2267
+ // Record the type_url, the version_info, and the nonce of the response.
2268
+ result.type_url = TypeUrlInternalToExternal(UpbStringToAbsl(
2269
+ envoy_service_discovery_v3_DiscoveryResponse_type_url(response)));
2270
+ result.version = UpbStringToStdString(
2271
+ envoy_service_discovery_v3_DiscoveryResponse_version_info(response));
2272
+ result.nonce = UpbStringToStdString(
2273
+ envoy_service_discovery_v3_DiscoveryResponse_nonce(response));
2274
+ // Parse the response according to the resource type.
2275
+ if (IsLds(result.type_url)) {
2276
+ result.parse_error =
2277
+ LdsResponseParse(client_, tracer_, response, expected_listener_names,
2278
+ &result.lds_update_map, arena.ptr());
2279
+ } else if (IsRds(result.type_url)) {
2280
+ result.parse_error = RdsResponseParse(client_, tracer_, response,
2281
+ expected_route_configuration_names,
2282
+ &result.rds_update_map, arena.ptr());
2283
+ } else if (IsCds(result.type_url)) {
2284
+ result.parse_error =
2285
+ CdsResponseParse(client_, tracer_, response, expected_cluster_names,
2286
+ &result.cds_update_map, arena.ptr());
2287
+ } else if (IsEds(result.type_url)) {
2288
+ result.parse_error =
2289
+ EdsResponseParse(client_, tracer_, response, expected_eds_service_names,
2290
+ &result.eds_update_map, arena.ptr());
2291
+ }
2292
+ return result;
2293
+ }
2294
+
2295
+ namespace {
2296
+
2297
+ void MaybeLogLrsRequest(
2298
+ XdsClient* client, TraceFlag* tracer,
2299
+ const envoy_service_load_stats_v3_LoadStatsRequest* request,
2300
+ const std::string& build_version) {
2301
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer) &&
2302
+ gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
2303
+ // TODO(roth): When we can upgrade upb, use upb textformat code to dump
2304
+ // the raw proto instead of doing this manually.
2305
+ std::vector<std::string> fields;
2306
+ // node
2307
+ const auto* node =
2308
+ envoy_service_load_stats_v3_LoadStatsRequest_node(request);
2309
+ if (node != nullptr) {
2310
+ AddNodeLogFields(node, build_version, &fields);
2311
+ }
2312
+ // cluster_stats
2313
+ size_t num_cluster_stats;
2314
+ const struct envoy_config_endpoint_v3_ClusterStats* const* cluster_stats =
2315
+ envoy_service_load_stats_v3_LoadStatsRequest_cluster_stats(
2316
+ request, &num_cluster_stats);
2317
+ for (size_t i = 0; i < num_cluster_stats; ++i) {
2318
+ const auto* cluster_stat = cluster_stats[i];
2319
+ fields.emplace_back("cluster_stats {");
2320
+ // cluster_name
2321
+ AddStringField(
2322
+ " cluster_name",
2323
+ envoy_config_endpoint_v3_ClusterStats_cluster_name(cluster_stat),
2324
+ &fields);
2325
+ // cluster_service_name
2326
+ AddStringField(" cluster_service_name",
2327
+ envoy_config_endpoint_v3_ClusterStats_cluster_service_name(
2328
+ cluster_stat),
2329
+ &fields);
2330
+ // upstream_locality_stats
2331
+ size_t num_stats;
2332
+ const envoy_config_endpoint_v3_UpstreamLocalityStats* const* stats =
2333
+ envoy_config_endpoint_v3_ClusterStats_upstream_locality_stats(
2334
+ cluster_stat, &num_stats);
2335
+ for (size_t j = 0; j < num_stats; ++j) {
2336
+ const auto* stat = stats[j];
2337
+ fields.emplace_back(" upstream_locality_stats {");
2338
+ // locality
2339
+ const auto* locality =
2340
+ envoy_config_endpoint_v3_UpstreamLocalityStats_locality(stat);
2341
+ if (locality != nullptr) {
2342
+ fields.emplace_back(" locality {");
2343
+ AddLocalityField(3, locality, &fields);
2344
+ fields.emplace_back(" }");
2345
+ }
2346
+ // total_successful_requests
2347
+ fields.emplace_back(absl::StrCat(
2348
+ " total_successful_requests: ",
2349
+ envoy_config_endpoint_v3_UpstreamLocalityStats_total_successful_requests(
2350
+ stat)));
2351
+ // total_requests_in_progress
2352
+ fields.emplace_back(absl::StrCat(
2353
+ " total_requests_in_progress: ",
2354
+ envoy_config_endpoint_v3_UpstreamLocalityStats_total_requests_in_progress(
2355
+ stat)));
2356
+ // total_error_requests
2357
+ fields.emplace_back(absl::StrCat(
2358
+ " total_error_requests: ",
2359
+ envoy_config_endpoint_v3_UpstreamLocalityStats_total_error_requests(
2360
+ stat)));
2361
+ // total_issued_requests
2362
+ fields.emplace_back(absl::StrCat(
2363
+ " total_issued_requests: ",
2364
+ envoy_config_endpoint_v3_UpstreamLocalityStats_total_issued_requests(
2365
+ stat)));
2366
+ fields.emplace_back(" }");
2367
+ }
2368
+ // total_dropped_requests
2369
+ fields.emplace_back(absl::StrCat(
2370
+ " total_dropped_requests: ",
2371
+ envoy_config_endpoint_v3_ClusterStats_total_dropped_requests(
2372
+ cluster_stat)));
2373
+ // dropped_requests
2374
+ size_t num_drops;
2375
+ const envoy_config_endpoint_v3_ClusterStats_DroppedRequests* const*
2376
+ drops = envoy_config_endpoint_v3_ClusterStats_dropped_requests(
2377
+ cluster_stat, &num_drops);
2378
+ for (size_t j = 0; j < num_drops; ++j) {
2379
+ const auto* drop = drops[j];
2380
+ fields.emplace_back(" dropped_requests {");
2381
+ // category
2382
+ AddStringField(
2383
+ " category",
2384
+ envoy_config_endpoint_v3_ClusterStats_DroppedRequests_category(
2385
+ drop),
2386
+ &fields);
2387
+ // dropped_count
2388
+ fields.emplace_back(absl::StrCat(
2389
+ " dropped_count: ",
2390
+ envoy_config_endpoint_v3_ClusterStats_DroppedRequests_dropped_count(
2391
+ drop)));
2392
+ fields.emplace_back(" }");
2393
+ }
2394
+ // load_report_interval
2395
+ const auto* load_report_interval =
2396
+ envoy_config_endpoint_v3_ClusterStats_load_report_interval(
2397
+ cluster_stat);
2398
+ if (load_report_interval != nullptr) {
2399
+ fields.emplace_back(" load_report_interval {");
2400
+ fields.emplace_back(absl::StrCat(
2401
+ " seconds: ",
2402
+ google_protobuf_Duration_seconds(load_report_interval)));
2403
+ fields.emplace_back(
2404
+ absl::StrCat(" nanos: ",
2405
+ google_protobuf_Duration_nanos(load_report_interval)));
2406
+ fields.emplace_back(" }");
2407
+ }
2408
+ fields.emplace_back("}");
2409
+ }
2410
+ gpr_log(GPR_DEBUG, "[xds_client %p] constructed LRS request: %s", client,
2411
+ absl::StrJoin(fields, "\n").c_str());
2412
+ }
2413
+ }
2414
+
2415
+ grpc_slice SerializeLrsRequest(
2416
+ const envoy_service_load_stats_v3_LoadStatsRequest* request,
2417
+ upb_arena* arena) {
2418
+ size_t output_length;
2419
+ char* output = envoy_service_load_stats_v3_LoadStatsRequest_serialize(
2420
+ request, arena, &output_length);
2421
+ return grpc_slice_from_copied_buffer(output, output_length);
2422
+ }
2423
+
2424
+ } // namespace
2425
+
2426
+ grpc_slice XdsApi::CreateLrsInitialRequest() {
2427
+ upb::Arena arena;
2428
+ // Create a request.
2429
+ envoy_service_load_stats_v3_LoadStatsRequest* request =
2430
+ envoy_service_load_stats_v3_LoadStatsRequest_new(arena.ptr());
2431
+ // Populate node.
2432
+ envoy_config_core_v3_Node* node_msg =
2433
+ envoy_service_load_stats_v3_LoadStatsRequest_mutable_node(request,
2434
+ arena.ptr());
2435
+ PopulateNode(arena.ptr(), bootstrap_, build_version_, user_agent_name_,
2436
+ node_msg);
2437
+ envoy_config_core_v3_Node_add_client_features(
2438
+ node_msg, upb_strview_makez("envoy.lrs.supports_send_all_clusters"),
2439
+ arena.ptr());
2440
+ MaybeLogLrsRequest(client_, tracer_, request, build_version_);
2441
+ return SerializeLrsRequest(request, arena.ptr());
2442
+ }
2443
+
2444
+ namespace {
2445
+
2446
+ void LocalityStatsPopulate(
2447
+ envoy_config_endpoint_v3_UpstreamLocalityStats* output,
2448
+ const XdsLocalityName& locality_name,
2449
+ const XdsClusterLocalityStats::Snapshot& snapshot, upb_arena* arena) {
2450
+ // Set locality.
2451
+ envoy_config_core_v3_Locality* locality =
2452
+ envoy_config_endpoint_v3_UpstreamLocalityStats_mutable_locality(output,
2453
+ arena);
2454
+ if (!locality_name.region().empty()) {
2455
+ envoy_config_core_v3_Locality_set_region(
2456
+ locality, StdStringToUpbString(locality_name.region()));
2457
+ }
2458
+ if (!locality_name.zone().empty()) {
2459
+ envoy_config_core_v3_Locality_set_zone(
2460
+ locality, StdStringToUpbString(locality_name.zone()));
2461
+ }
2462
+ if (!locality_name.sub_zone().empty()) {
2463
+ envoy_config_core_v3_Locality_set_sub_zone(
2464
+ locality, StdStringToUpbString(locality_name.sub_zone()));
2465
+ }
2466
+ // Set total counts.
2467
+ envoy_config_endpoint_v3_UpstreamLocalityStats_set_total_successful_requests(
2468
+ output, snapshot.total_successful_requests);
2469
+ envoy_config_endpoint_v3_UpstreamLocalityStats_set_total_requests_in_progress(
2470
+ output, snapshot.total_requests_in_progress);
2471
+ envoy_config_endpoint_v3_UpstreamLocalityStats_set_total_error_requests(
2472
+ output, snapshot.total_error_requests);
2473
+ envoy_config_endpoint_v3_UpstreamLocalityStats_set_total_issued_requests(
2474
+ output, snapshot.total_issued_requests);
2475
+ // Add backend metrics.
2476
+ for (const auto& p : snapshot.backend_metrics) {
2477
+ const std::string& metric_name = p.first;
2478
+ const XdsClusterLocalityStats::BackendMetric& metric_value = p.second;
2479
+ envoy_config_endpoint_v3_EndpointLoadMetricStats* load_metric =
2480
+ envoy_config_endpoint_v3_UpstreamLocalityStats_add_load_metric_stats(
2481
+ output, arena);
2482
+ envoy_config_endpoint_v3_EndpointLoadMetricStats_set_metric_name(
2483
+ load_metric, StdStringToUpbString(metric_name));
2484
+ envoy_config_endpoint_v3_EndpointLoadMetricStats_set_num_requests_finished_with_metric(
2485
+ load_metric, metric_value.num_requests_finished_with_metric);
2486
+ envoy_config_endpoint_v3_EndpointLoadMetricStats_set_total_metric_value(
2487
+ load_metric, metric_value.total_metric_value);
2488
+ }
2489
+ }
2490
+
2491
+ } // namespace
2492
+
2493
+ grpc_slice XdsApi::CreateLrsRequest(
2494
+ ClusterLoadReportMap cluster_load_report_map) {
2495
+ upb::Arena arena;
2496
+ // Create a request.
2497
+ envoy_service_load_stats_v3_LoadStatsRequest* request =
2498
+ envoy_service_load_stats_v3_LoadStatsRequest_new(arena.ptr());
2499
+ for (auto& p : cluster_load_report_map) {
2500
+ const std::string& cluster_name = p.first.first;
2501
+ const std::string& eds_service_name = p.first.second;
2502
+ const ClusterLoadReport& load_report = p.second;
2503
+ // Add cluster stats.
2504
+ envoy_config_endpoint_v3_ClusterStats* cluster_stats =
2505
+ envoy_service_load_stats_v3_LoadStatsRequest_add_cluster_stats(
2506
+ request, arena.ptr());
2507
+ // Set the cluster name.
2508
+ envoy_config_endpoint_v3_ClusterStats_set_cluster_name(
2509
+ cluster_stats, StdStringToUpbString(cluster_name));
2510
+ // Set EDS service name, if non-empty.
2511
+ if (!eds_service_name.empty()) {
2512
+ envoy_config_endpoint_v3_ClusterStats_set_cluster_service_name(
2513
+ cluster_stats, StdStringToUpbString(eds_service_name));
2514
+ }
2515
+ // Add locality stats.
2516
+ for (const auto& p : load_report.locality_stats) {
2517
+ const XdsLocalityName& locality_name = *p.first;
2518
+ const auto& snapshot = p.second;
2519
+ envoy_config_endpoint_v3_UpstreamLocalityStats* locality_stats =
2520
+ envoy_config_endpoint_v3_ClusterStats_add_upstream_locality_stats(
2521
+ cluster_stats, arena.ptr());
2522
+ LocalityStatsPopulate(locality_stats, locality_name, snapshot,
2523
+ arena.ptr());
2524
+ }
2525
+ // Add dropped requests.
2526
+ uint64_t total_dropped_requests = 0;
2527
+ for (const auto& p : load_report.dropped_requests.categorized_drops) {
2528
+ const std::string& category = p.first;
2529
+ const uint64_t count = p.second;
2530
+ envoy_config_endpoint_v3_ClusterStats_DroppedRequests* dropped_requests =
2531
+ envoy_config_endpoint_v3_ClusterStats_add_dropped_requests(
2532
+ cluster_stats, arena.ptr());
2533
+ envoy_config_endpoint_v3_ClusterStats_DroppedRequests_set_category(
2534
+ dropped_requests, StdStringToUpbString(category));
2535
+ envoy_config_endpoint_v3_ClusterStats_DroppedRequests_set_dropped_count(
2536
+ dropped_requests, count);
2537
+ total_dropped_requests += count;
2538
+ }
2539
+ total_dropped_requests += load_report.dropped_requests.uncategorized_drops;
2540
+ // Set total dropped requests.
2541
+ envoy_config_endpoint_v3_ClusterStats_set_total_dropped_requests(
2542
+ cluster_stats, total_dropped_requests);
2543
+ // Set real load report interval.
2544
+ gpr_timespec timespec =
2545
+ grpc_millis_to_timespec(load_report.load_report_interval, GPR_TIMESPAN);
2546
+ google_protobuf_Duration* load_report_interval =
2547
+ envoy_config_endpoint_v3_ClusterStats_mutable_load_report_interval(
2548
+ cluster_stats, arena.ptr());
2549
+ google_protobuf_Duration_set_seconds(load_report_interval, timespec.tv_sec);
2550
+ google_protobuf_Duration_set_nanos(load_report_interval, timespec.tv_nsec);
2551
+ }
2552
+ MaybeLogLrsRequest(client_, tracer_, request, build_version_);
2553
+ return SerializeLrsRequest(request, arena.ptr());
2554
+ }
2555
+
2556
+ grpc_error* XdsApi::ParseLrsResponse(const grpc_slice& encoded_response,
2557
+ bool* send_all_clusters,
2558
+ std::set<std::string>* cluster_names,
2559
+ grpc_millis* load_reporting_interval) {
2560
+ upb::Arena arena;
2561
+ // Decode the response.
2562
+ const envoy_service_load_stats_v3_LoadStatsResponse* decoded_response =
2563
+ envoy_service_load_stats_v3_LoadStatsResponse_parse(
2564
+ reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(encoded_response)),
2565
+ GRPC_SLICE_LENGTH(encoded_response), arena.ptr());
2566
+ // Parse the response.
2567
+ if (decoded_response == nullptr) {
2568
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode response.");
2569
+ }
2570
+ // Check send_all_clusters.
2571
+ if (envoy_service_load_stats_v3_LoadStatsResponse_send_all_clusters(
2572
+ decoded_response)) {
2573
+ *send_all_clusters = true;
2574
+ } else {
2575
+ // Store the cluster names.
2576
+ size_t size;
2577
+ const upb_strview* clusters =
2578
+ envoy_service_load_stats_v3_LoadStatsResponse_clusters(decoded_response,
2579
+ &size);
2580
+ for (size_t i = 0; i < size; ++i) {
2581
+ cluster_names->emplace(UpbStringToStdString(clusters[i]));
2582
+ }
2583
+ }
2584
+ // Get the load report interval.
2585
+ const google_protobuf_Duration* load_reporting_interval_duration =
2586
+ envoy_service_load_stats_v3_LoadStatsResponse_load_reporting_interval(
2587
+ decoded_response);
2588
+ gpr_timespec timespec{
2589
+ google_protobuf_Duration_seconds(load_reporting_interval_duration),
2590
+ google_protobuf_Duration_nanos(load_reporting_interval_duration),
2591
+ GPR_TIMESPAN};
2592
+ *load_reporting_interval = gpr_time_to_millis(timespec);
2593
+ return GRPC_ERROR_NONE;
2594
+ }
2595
+
2596
+ } // namespace grpc_core