grpc 1.32.0 → 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 (214) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +175 -376
  3. data/include/grpc/grpc.h +0 -5
  4. data/include/grpc/grpc_security.h +16 -0
  5. data/include/grpc/impl/codegen/grpc_types.h +0 -5
  6. data/src/core/ext/filters/client_channel/client_channel.cc +204 -170
  7. data/src/core/ext/filters/client_channel/config_selector.cc +0 -4
  8. data/src/core/ext/filters/client_channel/config_selector.h +34 -5
  9. data/src/core/ext/filters/client_channel/lb_policy.h +1 -1
  10. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +48 -35
  11. data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +7 -5
  12. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +3 -2
  13. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +106 -106
  14. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +2 -2
  15. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +3 -3
  16. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +3 -3
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +9 -32
  18. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +3 -3
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +198 -126
  20. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +439 -249
  21. data/src/core/ext/filters/client_channel/lb_policy/xds/eds_drop.cc +571 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +727 -0
  23. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +8 -1
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -1
  25. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +553 -358
  26. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h +28 -0
  27. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +8 -39
  28. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +4 -2
  29. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +44 -43
  30. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +5 -9
  31. data/src/core/ext/filters/client_channel/server_address.cc +80 -0
  32. data/src/core/ext/filters/client_channel/server_address.h +25 -36
  33. data/src/core/ext/filters/client_channel/service_config.cc +16 -13
  34. data/src/core/ext/filters/client_channel/service_config.h +7 -4
  35. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +2 -2
  36. data/src/core/ext/filters/client_channel/service_config_parser.cc +8 -6
  37. data/src/core/ext/filters/client_channel/service_config_parser.h +8 -5
  38. data/src/core/ext/filters/client_channel/subchannel_interface.h +44 -0
  39. data/src/core/ext/filters/message_size/message_size_filter.cc +2 -1
  40. data/src/core/ext/filters/message_size/message_size_filter.h +2 -1
  41. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +17 -10
  42. data/src/core/ext/transport/chttp2/transport/flow_control.cc +10 -2
  43. data/src/core/ext/transport/chttp2/transport/flow_control.h +10 -0
  44. data/src/core/ext/transport/chttp2/transport/internal.h +5 -0
  45. data/src/core/ext/transport/chttp2/transport/parsing.cc +16 -2
  46. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +29 -9
  47. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +66 -0
  48. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +123 -45
  49. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +310 -53
  50. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +17 -5
  51. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +45 -0
  52. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +1 -0
  53. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +16 -9
  54. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +38 -15
  55. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.c +53 -0
  56. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.h +133 -0
  57. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +54 -8
  58. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +123 -5
  59. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +40 -16
  60. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +114 -5
  61. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +36 -0
  62. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +85 -0
  63. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +36 -16
  64. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +86 -20
  65. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +23 -6
  66. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +54 -5
  67. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +10 -6
  68. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +28 -11
  69. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +184 -57
  70. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +504 -69
  71. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +6 -5
  72. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +11 -7
  73. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +78 -26
  74. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +236 -25
  75. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +8 -9
  76. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +19 -33
  77. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +7 -3
  78. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +16 -0
  79. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +65 -23
  80. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +229 -47
  81. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +20 -10
  82. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +67 -4
  83. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +3 -2
  84. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +6 -0
  85. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c +242 -0
  86. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h +753 -0
  87. data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +31 -0
  88. data/src/core/ext/upb-generated/udpa/annotations/security.upb.h +57 -0
  89. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.c +28 -0
  90. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.h +53 -0
  91. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.c +52 -0
  92. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.h +129 -0
  93. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.c +42 -0
  94. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.h +77 -0
  95. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.c +36 -0
  96. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.h +85 -0
  97. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c +54 -0
  98. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.h +160 -0
  99. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c +36 -0
  100. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.h +84 -0
  101. data/src/core/ext/xds/certificate_provider_factory.h +59 -0
  102. data/src/core/ext/xds/certificate_provider_registry.cc +103 -0
  103. data/src/core/ext/xds/certificate_provider_registry.h +57 -0
  104. data/src/core/ext/xds/certificate_provider_store.h +50 -0
  105. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.cc +377 -0
  106. data/src/core/ext/xds/google_mesh_ca_certificate_provider_factory.h +102 -0
  107. data/src/core/ext/xds/xds_api.cc +301 -93
  108. data/src/core/ext/xds/xds_api.h +129 -92
  109. data/src/core/ext/xds/xds_channel_args.h +6 -3
  110. data/src/core/ext/xds/xds_client.cc +498 -410
  111. data/src/core/ext/xds/xds_client.h +105 -51
  112. data/src/core/ext/xds/xds_client_stats.cc +18 -12
  113. data/src/core/ext/xds/xds_client_stats.h +33 -5
  114. data/src/core/lib/channel/channel_args.h +0 -1
  115. data/src/core/lib/channel/channelz.cc +10 -45
  116. data/src/core/lib/channel/channelz.h +11 -19
  117. data/src/core/lib/channel/channelz_registry.cc +12 -11
  118. data/src/core/lib/channel/channelz_registry.h +3 -0
  119. data/src/core/lib/gpr/time_precise.cc +2 -0
  120. data/src/core/lib/gpr/time_precise.h +6 -2
  121. data/src/core/lib/gprpp/dual_ref_counted.h +336 -0
  122. data/src/core/lib/gprpp/ref_counted.h +51 -22
  123. data/src/core/lib/gprpp/ref_counted_ptr.h +153 -0
  124. data/src/core/lib/iomgr/endpoint_cfstream.cc +9 -5
  125. data/src/core/lib/iomgr/exec_ctx.h +10 -8
  126. data/src/core/lib/json/json_util.cc +58 -0
  127. data/src/core/lib/json/json_util.h +37 -0
  128. data/src/core/lib/security/certificate_provider.h +60 -0
  129. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +321 -0
  130. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +214 -0
  131. data/src/core/lib/security/credentials/xds/xds_credentials.cc +45 -0
  132. data/src/core/lib/security/credentials/xds/xds_credentials.h +51 -0
  133. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +6 -10
  134. data/src/core/lib/security/security_connector/ssl_utils.h +5 -0
  135. data/src/core/lib/surface/channel.cc +9 -31
  136. data/src/core/lib/surface/channel.h +6 -1
  137. data/src/core/lib/surface/init.cc +26 -9
  138. data/src/core/lib/surface/version.cc +2 -2
  139. data/src/core/lib/transport/bdp_estimator.h +2 -1
  140. data/src/core/lib/transport/connectivity_state.h +2 -2
  141. data/src/core/lib/transport/metadata.cc +11 -1
  142. data/src/core/plugin_registry/grpc_plugin_registry.cc +35 -20
  143. data/src/core/tsi/ssl_transport_security.cc +2 -2
  144. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -2
  145. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -3
  146. data/src/ruby/lib/grpc/version.rb +1 -1
  147. data/third_party/boringssl-with-bazel/err_data.c +465 -463
  148. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +0 -6
  149. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +9 -43
  150. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa_asn1.c +55 -4
  151. data/third_party/boringssl-with-bazel/src/crypto/dsa/internal.h +34 -0
  152. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +4 -0
  153. data/third_party/boringssl-with-bazel/src/crypto/evp/p_dsa_asn1.c +6 -2
  154. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +2 -0
  155. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +4 -0
  156. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +30 -10
  157. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +10 -15
  158. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +98 -11
  159. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +51 -6
  160. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +44 -2
  161. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +221 -49
  162. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +64 -20
  163. data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +3 -3
  164. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +0 -8
  165. data/third_party/boringssl-with-bazel/src/crypto/x509/t_crl.c +3 -3
  166. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509.c +1 -1
  167. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +7 -2
  168. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_ext.c +21 -18
  169. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_obj.c +1 -1
  170. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +24 -3
  171. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +3 -3
  172. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_txt.c +67 -67
  173. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +3 -3
  174. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +29 -35
  175. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +13 -2
  176. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +9 -8
  177. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +10 -10
  178. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +2 -2
  179. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +28 -40
  180. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +3 -1
  181. data/third_party/boringssl-with-bazel/src/crypto/x509v3/ext_dat.h +1 -4
  182. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_conf.c +7 -3
  183. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_genn.c +2 -2
  184. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_info.c +1 -1
  185. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +55 -8
  186. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +1 -1
  187. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +0 -1
  188. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +1 -1
  189. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +6 -0
  190. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +1 -1
  191. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +12 -0
  192. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +9 -0
  193. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +4 -1
  194. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +9 -2
  195. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +26 -6
  196. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +188 -78
  197. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +52 -43
  198. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +18 -18
  199. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +2 -3
  200. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +1 -1
  201. data/third_party/boringssl-with-bazel/src/ssl/internal.h +9 -9
  202. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +8 -9
  203. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +1 -2
  204. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +4 -8
  205. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +2 -2
  206. metadata +72 -42
  207. data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +0 -537
  208. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +0 -1141
  209. data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +0 -17
  210. data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +0 -29
  211. data/src/core/ext/xds/xds_channel.h +0 -46
  212. data/src/core/ext/xds/xds_channel_secure.cc +0 -103
  213. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_pku.c +0 -110
  214. 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
@@ -42,6 +42,7 @@
42
42
  #include "src/core/lib/iomgr/error.h"
43
43
  #include "src/core/lib/iomgr/sockaddr_utils.h"
44
44
 
45
+ #include "envoy/config/cluster/v3/circuit_breaker.upb.h"
45
46
  #include "envoy/config/cluster/v3/cluster.upb.h"
46
47
  #include "envoy/config/core/v3/address.upb.h"
47
48
  #include "envoy/config/core/v3/base.upb.h"
@@ -55,6 +56,8 @@
55
56
  #include "envoy/config/route/v3/route.upb.h"
56
57
  #include "envoy/config/route/v3/route_components.upb.h"
57
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"
58
61
  #include "envoy/service/cluster/v3/cds.upb.h"
59
62
  #include "envoy/service/discovery/v3/discovery.upb.h"
60
63
  #include "envoy/service/endpoint/v3/eds.upb.h"
@@ -62,6 +65,7 @@
62
65
  #include "envoy/service/load_stats/v3/lrs.upb.h"
63
66
  #include "envoy/service/route/v3/rds.upb.h"
64
67
  #include "envoy/type/matcher/v3/regex.upb.h"
68
+ #include "envoy/type/matcher/v3/string.upb.h"
65
69
  #include "envoy/type/v3/percent.upb.h"
66
70
  #include "envoy/type/v3/range.upb.h"
67
71
  #include "google/protobuf/any.upb.h"
@@ -228,8 +232,8 @@ std::string XdsApi::Route::Matchers::HeaderMatcher::ToString() const {
228
232
  std::string XdsApi::Route::Matchers::ToString() const {
229
233
  std::vector<std::string> contents;
230
234
  contents.push_back(path_matcher.ToString());
231
- for (const auto& header_it : header_matchers) {
232
- contents.push_back(header_it.ToString());
235
+ for (const HeaderMatcher& header_matcher : header_matchers) {
236
+ contents.push_back(header_matcher.ToString());
233
237
  }
234
238
  if (fraction_per_million.has_value()) {
235
239
  contents.push_back(absl::StrFormat("Fraction Per Million %d",
@@ -248,8 +252,8 @@ std::string XdsApi::Route::ToString() const {
248
252
  if (!cluster_name.empty()) {
249
253
  contents.push_back(absl::StrFormat("Cluster name: %s", cluster_name));
250
254
  }
251
- for (const auto& weighted_it : weighted_clusters) {
252
- contents.push_back(weighted_it.ToString());
255
+ for (const ClusterWeight& cluster_weight : weighted_clusters) {
256
+ contents.push_back(cluster_weight.ToString());
253
257
  }
254
258
  return absl::StrJoin(contents, "\n");
255
259
  }
@@ -333,8 +337,8 @@ MatchType DomainPatternMatchType(const std::string& domain_pattern) {
333
337
 
334
338
  } // namespace
335
339
 
336
- const XdsApi::RdsUpdate::VirtualHost*
337
- XdsApi::RdsUpdate::FindVirtualHostForDomain(const std::string& domain) const {
340
+ XdsApi::RdsUpdate::VirtualHost* XdsApi::RdsUpdate::FindVirtualHostForDomain(
341
+ const std::string& domain) {
338
342
  // Find the best matched virtual host.
339
343
  // The search order for 4 groups of domain patterns:
340
344
  // 1. Exact match.
@@ -344,12 +348,12 @@ XdsApi::RdsUpdate::FindVirtualHostForDomain(const std::string& domain) const {
344
348
  // Within each group, longest match wins.
345
349
  // If the same best matched domain pattern appears in multiple virtual hosts,
346
350
  // the first matched virtual host wins.
347
- const VirtualHost* target_vhost = nullptr;
351
+ VirtualHost* target_vhost = nullptr;
348
352
  MatchType best_match_type = INVALID_MATCH;
349
353
  size_t longest_match = 0;
350
354
  // Check each domain pattern in each virtual host to determine the best
351
355
  // matched virtual host.
352
- for (const VirtualHost& vhost : virtual_hosts) {
356
+ for (VirtualHost& vhost : virtual_hosts) {
353
357
  for (const std::string& domain_pattern : vhost.domains) {
354
358
  // Check the match type first. Skip the pattern if it's not better than
355
359
  // current match.
@@ -375,49 +379,80 @@ XdsApi::RdsUpdate::FindVirtualHostForDomain(const std::string& domain) const {
375
379
  }
376
380
 
377
381
  //
378
- // XdsApi::PriorityListUpdate
382
+ // XdsApi::StringMatcher
379
383
  //
380
384
 
381
- bool XdsApi::PriorityListUpdate::operator==(
382
- const XdsApi::PriorityListUpdate& other) const {
383
- if (priorities_.size() != other.priorities_.size()) return false;
384
- for (size_t i = 0; i < priorities_.size(); ++i) {
385
- if (priorities_[i].localities != other.priorities_[i].localities) {
386
- return false;
387
- }
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;
388
393
  }
389
- return true;
390
394
  }
391
395
 
392
- void XdsApi::PriorityListUpdate::Add(
393
- XdsApi::PriorityListUpdate::LocalityMap::Locality locality) {
394
- // Pad the missing priorities in case the localities are not ordered by
395
- // priority.
396
- if (!Contains(locality.priority)) priorities_.resize(locality.priority + 1);
397
- LocalityMap& locality_map = priorities_[locality.priority];
398
- locality_map.localities.emplace(locality.name, std::move(locality));
399
- }
400
-
401
- const XdsApi::PriorityListUpdate::LocalityMap* XdsApi::PriorityListUpdate::Find(
402
- uint32_t priority) const {
403
- if (!Contains(priority)) return nullptr;
404
- return &priorities_[priority];
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;
405
407
  }
406
408
 
407
- bool XdsApi::PriorityListUpdate::Contains(
408
- const RefCountedPtr<XdsLocalityName>& name) {
409
- for (size_t i = 0; i < priorities_.size(); ++i) {
410
- const LocalityMap& locality_map = priorities_[i];
411
- if (locality_map.Contains(name)) return true;
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;
412
416
  }
413
- return false;
414
417
  }
415
418
 
416
419
  //
417
- // XdsApi::DropConfig
420
+ // XdsApi::EdsUpdate
418
421
  //
419
422
 
420
- bool XdsApi::DropConfig::ShouldDrop(const std::string** category_name) const {
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 {
421
456
  for (size_t i = 0; i < drop_category_list_.size(); ++i) {
422
457
  const auto& drop_category = drop_category_list_[i];
423
458
  // Generate a random number in [0, 1000000).
@@ -430,6 +465,27 @@ bool XdsApi::DropConfig::ShouldDrop(const std::string** category_name) const {
430
465
  return false;
431
466
  }
432
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
+
433
489
  //
434
490
  // XdsApi
435
491
  //
@@ -579,7 +635,6 @@ void PopulateBuildVersion(upb_arena* arena, envoy_config_core_v3_Node* node_msg,
579
635
  void PopulateNode(upb_arena* arena, const XdsBootstrap* bootstrap,
580
636
  const std::string& build_version,
581
637
  const std::string& user_agent_name,
582
- const std::string& server_name,
583
638
  envoy_config_core_v3_Node* node_msg) {
584
639
  const XdsBootstrap::Node* node = bootstrap->node();
585
640
  if (node != nullptr) {
@@ -596,16 +651,6 @@ void PopulateNode(upb_arena* arena, const XdsBootstrap* bootstrap,
596
651
  envoy_config_core_v3_Node_mutable_metadata(node_msg, arena);
597
652
  PopulateMetadata(arena, metadata, node->metadata.object_value());
598
653
  }
599
- if (!server_name.empty()) {
600
- google_protobuf_Struct* metadata =
601
- envoy_config_core_v3_Node_mutable_metadata(node_msg, arena);
602
- google_protobuf_Value* value = google_protobuf_Value_new(arena);
603
- google_protobuf_Value_set_string_value(value,
604
- StdStringToUpbString(server_name));
605
- google_protobuf_Struct_fields_set(
606
- metadata, upb_strview_makez("PROXYLESS_CLIENT_HOSTNAME"), value,
607
- arena);
608
- }
609
654
  if (!node->locality_region.empty() || !node->locality_zone.empty() ||
610
655
  !node->locality_subzone.empty()) {
611
656
  envoy_config_core_v3_Locality* locality =
@@ -886,7 +931,7 @@ grpc_slice XdsApi::CreateAdsRequest(
886
931
  envoy_config_core_v3_Node* node_msg =
887
932
  envoy_service_discovery_v3_DiscoveryRequest_mutable_node(request,
888
933
  arena.ptr());
889
- PopulateNode(arena.ptr(), bootstrap_, build_version_, user_agent_name_, "",
934
+ PopulateNode(arena.ptr(), bootstrap_, build_version_, user_agent_name_,
890
935
  node_msg);
891
936
  }
892
937
  // Add resource_names.
@@ -1552,7 +1597,9 @@ grpc_error* RouteConfigParse(
1552
1597
  std::string domain_pattern = UpbStringToStdString(domains[j]);
1553
1598
  const MatchType match_type = DomainPatternMatchType(domain_pattern);
1554
1599
  if (match_type == INVALID_MATCH) {
1555
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid domain pattern.");
1600
+ return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1601
+ absl::StrCat("Invalid domain pattern \"", domain_pattern, "\".")
1602
+ .c_str());
1556
1603
  }
1557
1604
  vhost.domains.emplace_back(std::move(domain_pattern));
1558
1605
  }
@@ -1608,8 +1655,8 @@ grpc_error* RouteConfigParse(
1608
1655
  grpc_error* LdsResponseParse(
1609
1656
  XdsClient* client, TraceFlag* tracer,
1610
1657
  const envoy_service_discovery_v3_DiscoveryResponse* response,
1611
- const std::string& expected_server_name,
1612
- absl::optional<XdsApi::LdsUpdate>* lds_update, upb_arena* arena) {
1658
+ const std::set<absl::string_view>& expected_listener_names,
1659
+ XdsApi::LdsUpdateMap* lds_update_map, upb_arena* arena) {
1613
1660
  // Get the resources from the response.
1614
1661
  size_t size;
1615
1662
  const google_protobuf_Any* const* resources =
@@ -1631,9 +1678,19 @@ grpc_error* LdsResponseParse(
1631
1678
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode listener.");
1632
1679
  }
1633
1680
  // Check listener name. Ignore unexpected listeners.
1634
- absl::string_view name =
1635
- UpbStringToAbsl(envoy_config_listener_v3_Listener_name(listener));
1636
- if (name != expected_server_name) continue;
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];
1637
1694
  // Get api_listener and decode it to http_connection_manager.
1638
1695
  const envoy_config_listener_v3_ApiListener* api_listener =
1639
1696
  envoy_config_listener_v3_Listener_api_listener(listener);
@@ -1661,9 +1718,8 @@ grpc_error* LdsResponseParse(
1661
1718
  grpc_error* error =
1662
1719
  RouteConfigParse(client, tracer, route_config, &rds_update);
1663
1720
  if (error != GRPC_ERROR_NONE) return error;
1664
- lds_update->emplace();
1665
- (*lds_update)->rds_update = std::move(rds_update);
1666
- return GRPC_ERROR_NONE;
1721
+ lds_update.rds_update = std::move(rds_update);
1722
+ continue;
1667
1723
  }
1668
1724
  // Validate that RDS must be used to get the route_config dynamically.
1669
1725
  if (!envoy_extensions_filters_network_http_connection_manager_v3_HttpConnectionManager_has_rds(
@@ -1687,11 +1743,9 @@ grpc_error* LdsResponseParse(
1687
1743
  "HttpConnectionManager ConfigSource for RDS does not specify ADS.");
1688
1744
  }
1689
1745
  // Get the route_config_name.
1690
- lds_update->emplace();
1691
- (*lds_update)->route_config_name = UpbStringToStdString(
1746
+ lds_update.route_config_name = UpbStringToStdString(
1692
1747
  envoy_extensions_filters_network_http_connection_manager_v3_Rds_route_config_name(
1693
1748
  rds));
1694
- return GRPC_ERROR_NONE;
1695
1749
  }
1696
1750
  return GRPC_ERROR_NONE;
1697
1751
  }
@@ -1700,7 +1754,7 @@ grpc_error* RdsResponseParse(
1700
1754
  XdsClient* client, TraceFlag* tracer,
1701
1755
  const envoy_service_discovery_v3_DiscoveryResponse* response,
1702
1756
  const std::set<absl::string_view>& expected_route_configuration_names,
1703
- absl::optional<XdsApi::RdsUpdate>* rds_update, upb_arena* arena) {
1757
+ XdsApi::RdsUpdateMap* rds_update_map, upb_arena* arena) {
1704
1758
  // Get the resources from the response.
1705
1759
  size_t size;
1706
1760
  const google_protobuf_Any* const* resources =
@@ -1722,19 +1776,111 @@ grpc_error* RdsResponseParse(
1722
1776
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Can't decode route_config.");
1723
1777
  }
1724
1778
  // Check route_config_name. Ignore unexpected route_config.
1725
- absl::string_view route_config_name = UpbStringToAbsl(
1779
+ std::string route_config_name = UpbStringToStdString(
1726
1780
  envoy_config_route_v3_RouteConfiguration_name(route_config));
1727
1781
  if (expected_route_configuration_names.find(route_config_name) ==
1728
1782
  expected_route_configuration_names.end()) {
1729
1783
  continue;
1730
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
+ }
1731
1792
  // Parse the route_config.
1732
- XdsApi::RdsUpdate local_rds_update;
1793
+ XdsApi::RdsUpdate& rds_update =
1794
+ (*rds_update_map)[std::move(route_config_name)];
1733
1795
  grpc_error* error =
1734
- RouteConfigParse(client, tracer, route_config, &local_rds_update);
1796
+ RouteConfigParse(client, tracer, route_config, &rds_update);
1735
1797
  if (error != GRPC_ERROR_NONE) return error;
1736
- rds_update->emplace(std::move(local_rds_update));
1737
- return GRPC_ERROR_NONE;
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));
1738
1884
  }
1739
1885
  return GRPC_ERROR_NONE;
1740
1886
  }
@@ -1750,7 +1896,6 @@ grpc_error* CdsResponseParse(
1750
1896
  envoy_service_discovery_v3_DiscoveryResponse_resources(response, &size);
1751
1897
  // Parse all the resources in the CDS response.
1752
1898
  for (size_t i = 0; i < size; ++i) {
1753
- XdsApi::CdsUpdate cds_update;
1754
1899
  // Check the type_url of the resource.
1755
1900
  absl::string_view type_url =
1756
1901
  UpbStringToAbsl(google_protobuf_Any_type_url(resources[i]));
@@ -1779,6 +1924,7 @@ grpc_error* CdsResponseParse(
1779
1924
  absl::StrCat("duplicate resource name \"", cluster_name, "\"")
1780
1925
  .c_str());
1781
1926
  }
1927
+ XdsApi::CdsUpdate& cds_update = (*cds_update_map)[std::move(cluster_name)];
1782
1928
  // Check the cluster_discovery_type.
1783
1929
  if (!envoy_config_cluster_v3_Cluster_has_type(cluster)) {
1784
1930
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING("DiscoveryType not found.");
@@ -1810,6 +1956,37 @@ grpc_error* CdsResponseParse(
1810
1956
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1811
1957
  "LB policy is not ROUND_ROBIN.");
1812
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
+ }
1813
1990
  // Record LRS server name (if any).
1814
1991
  const envoy_config_core_v3_ConfigSource* lrs_server =
1815
1992
  envoy_config_cluster_v3_Cluster_lrs_server(cluster);
@@ -1820,7 +1997,32 @@ grpc_error* CdsResponseParse(
1820
1997
  }
1821
1998
  cds_update.lrs_load_reporting_server_name.emplace("");
1822
1999
  }
1823
- cds_update_map->emplace(std::move(cluster_name), std::move(cds_update));
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
+ }
1824
2026
  }
1825
2027
  return GRPC_ERROR_NONE;
1826
2028
  }
@@ -1858,7 +2060,7 @@ grpc_error* ServerAddressParseAndAppend(
1858
2060
 
1859
2061
  grpc_error* LocalityParse(
1860
2062
  const envoy_config_endpoint_v3_LocalityLbEndpoints* locality_lb_endpoints,
1861
- XdsApi::PriorityListUpdate::LocalityMap::Locality* output_locality) {
2063
+ XdsApi::EdsUpdate::Priority::Locality* output_locality, size_t* priority) {
1862
2064
  // Parse LB weight.
1863
2065
  const google_protobuf_UInt32Value* lb_weight =
1864
2066
  envoy_config_endpoint_v3_LocalityLbEndpoints_load_balancing_weight(
@@ -1888,20 +2090,19 @@ grpc_error* LocalityParse(
1888
2090
  locality_lb_endpoints, &size);
1889
2091
  for (size_t i = 0; i < size; ++i) {
1890
2092
  grpc_error* error = ServerAddressParseAndAppend(
1891
- lb_endpoints[i], &output_locality->serverlist);
2093
+ lb_endpoints[i], &output_locality->endpoints);
1892
2094
  if (error != GRPC_ERROR_NONE) return error;
1893
2095
  }
1894
2096
  // Parse the priority.
1895
- output_locality->priority =
1896
- envoy_config_endpoint_v3_LocalityLbEndpoints_priority(
1897
- locality_lb_endpoints);
2097
+ *priority = envoy_config_endpoint_v3_LocalityLbEndpoints_priority(
2098
+ locality_lb_endpoints);
1898
2099
  return GRPC_ERROR_NONE;
1899
2100
  }
1900
2101
 
1901
2102
  grpc_error* DropParseAndAppend(
1902
2103
  const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload*
1903
2104
  drop_overload,
1904
- XdsApi::DropConfig* drop_config) {
2105
+ XdsApi::EdsUpdate::DropConfig* drop_config) {
1905
2106
  // Get the category.
1906
2107
  std::string category = UpbStringToStdString(
1907
2108
  envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_category(
@@ -1947,7 +2148,6 @@ grpc_error* EdsResponseParse(
1947
2148
  const google_protobuf_Any* const* resources =
1948
2149
  envoy_service_discovery_v3_DiscoveryResponse_resources(response, &size);
1949
2150
  for (size_t i = 0; i < size; ++i) {
1950
- XdsApi::EdsUpdate eds_update;
1951
2151
  // Check the type_url of the resource.
1952
2152
  absl::string_view type_url =
1953
2153
  UpbStringToAbsl(google_protobuf_Any_type_url(resources[i]));
@@ -1980,29 +2180,36 @@ grpc_error* EdsResponseParse(
1980
2180
  absl::StrCat("duplicate resource name \"", eds_service_name, "\"")
1981
2181
  .c_str());
1982
2182
  }
2183
+ XdsApi::EdsUpdate& eds_update =
2184
+ (*eds_update_map)[std::move(eds_service_name)];
1983
2185
  // Get the endpoints.
1984
2186
  size_t locality_size;
1985
2187
  const envoy_config_endpoint_v3_LocalityLbEndpoints* const* endpoints =
1986
2188
  envoy_config_endpoint_v3_ClusterLoadAssignment_endpoints(
1987
2189
  cluster_load_assignment, &locality_size);
1988
2190
  for (size_t j = 0; j < locality_size; ++j) {
1989
- XdsApi::PriorityListUpdate::LocalityMap::Locality locality;
1990
- grpc_error* error = LocalityParse(endpoints[j], &locality);
2191
+ size_t priority;
2192
+ XdsApi::EdsUpdate::Priority::Locality locality;
2193
+ grpc_error* error = LocalityParse(endpoints[j], &locality, &priority);
1991
2194
  if (error != GRPC_ERROR_NONE) return error;
1992
2195
  // Filter out locality with weight 0.
1993
2196
  if (locality.lb_weight == 0) continue;
1994
- eds_update.priority_list_update.Add(locality);
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));
1995
2204
  }
1996
- for (uint32_t priority = 0;
1997
- priority < eds_update.priority_list_update.size(); ++priority) {
1998
- auto* locality_map = eds_update.priority_list_update.Find(priority);
1999
- if (locality_map == nullptr || locality_map->size() == 0) {
2205
+ for (const auto& priority : eds_update.priorities) {
2206
+ if (priority.localities.empty()) {
2000
2207
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2001
2208
  "EDS update includes sparse priority list");
2002
2209
  }
2003
2210
  }
2004
2211
  // Get the drop config.
2005
- eds_update.drop_config = MakeRefCounted<XdsApi::DropConfig>();
2212
+ eds_update.drop_config = MakeRefCounted<XdsApi::EdsUpdate::DropConfig>();
2006
2213
  const envoy_config_endpoint_v3_ClusterLoadAssignment_Policy* policy =
2007
2214
  envoy_config_endpoint_v3_ClusterLoadAssignment_policy(
2008
2215
  cluster_load_assignment);
@@ -2018,7 +2225,6 @@ grpc_error* EdsResponseParse(
2018
2225
  if (error != GRPC_ERROR_NONE) return error;
2019
2226
  }
2020
2227
  }
2021
- eds_update_map->emplace(std::move(eds_service_name), std::move(eds_update));
2022
2228
  }
2023
2229
  return GRPC_ERROR_NONE;
2024
2230
  }
@@ -2039,7 +2245,8 @@ std::string TypeUrlInternalToExternal(absl::string_view type_url) {
2039
2245
  } // namespace
2040
2246
 
2041
2247
  XdsApi::AdsParseResult XdsApi::ParseAdsResponse(
2042
- const grpc_slice& encoded_response, const std::string& expected_server_name,
2248
+ const grpc_slice& encoded_response,
2249
+ const std::set<absl::string_view>& expected_listener_names,
2043
2250
  const std::set<absl::string_view>& expected_route_configuration_names,
2044
2251
  const std::set<absl::string_view>& expected_cluster_names,
2045
2252
  const std::set<absl::string_view>& expected_eds_service_names) {
@@ -2067,12 +2274,12 @@ XdsApi::AdsParseResult XdsApi::ParseAdsResponse(
2067
2274
  // Parse the response according to the resource type.
2068
2275
  if (IsLds(result.type_url)) {
2069
2276
  result.parse_error =
2070
- LdsResponseParse(client_, tracer_, response, expected_server_name,
2071
- &result.lds_update, arena.ptr());
2277
+ LdsResponseParse(client_, tracer_, response, expected_listener_names,
2278
+ &result.lds_update_map, arena.ptr());
2072
2279
  } else if (IsRds(result.type_url)) {
2073
2280
  result.parse_error = RdsResponseParse(client_, tracer_, response,
2074
2281
  expected_route_configuration_names,
2075
- &result.rds_update, arena.ptr());
2282
+ &result.rds_update_map, arena.ptr());
2076
2283
  } else if (IsCds(result.type_url)) {
2077
2284
  result.parse_error =
2078
2285
  CdsResponseParse(client_, tracer_, response, expected_cluster_names,
@@ -2216,7 +2423,7 @@ grpc_slice SerializeLrsRequest(
2216
2423
 
2217
2424
  } // namespace
2218
2425
 
2219
- grpc_slice XdsApi::CreateLrsInitialRequest(const std::string& server_name) {
2426
+ grpc_slice XdsApi::CreateLrsInitialRequest() {
2220
2427
  upb::Arena arena;
2221
2428
  // Create a request.
2222
2429
  envoy_service_load_stats_v3_LoadStatsRequest* request =
@@ -2226,7 +2433,7 @@ grpc_slice XdsApi::CreateLrsInitialRequest(const std::string& server_name) {
2226
2433
  envoy_service_load_stats_v3_LoadStatsRequest_mutable_node(request,
2227
2434
  arena.ptr());
2228
2435
  PopulateNode(arena.ptr(), bootstrap_, build_version_, user_agent_name_,
2229
- server_name, node_msg);
2436
+ node_msg);
2230
2437
  envoy_config_core_v3_Node_add_client_features(
2231
2438
  node_msg, upb_strview_makez("envoy.lrs.supports_send_all_clusters"),
2232
2439
  arena.ptr());
@@ -2317,7 +2524,7 @@ grpc_slice XdsApi::CreateLrsRequest(
2317
2524
  }
2318
2525
  // Add dropped requests.
2319
2526
  uint64_t total_dropped_requests = 0;
2320
- for (const auto& p : load_report.dropped_requests) {
2527
+ for (const auto& p : load_report.dropped_requests.categorized_drops) {
2321
2528
  const std::string& category = p.first;
2322
2529
  const uint64_t count = p.second;
2323
2530
  envoy_config_endpoint_v3_ClusterStats_DroppedRequests* dropped_requests =
@@ -2329,6 +2536,7 @@ grpc_slice XdsApi::CreateLrsRequest(
2329
2536
  dropped_requests, count);
2330
2537
  total_dropped_requests += count;
2331
2538
  }
2539
+ total_dropped_requests += load_report.dropped_requests.uncategorized_drops;
2332
2540
  // Set total dropped requests.
2333
2541
  envoy_config_endpoint_v3_ClusterStats_set_total_dropped_requests(
2334
2542
  cluster_stats, total_dropped_requests);