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,28 @@
1
+ //
2
+ // Copyright 2019 gRPC authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ //
16
+
17
+ #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_XDS_XDS_RESOLVER_H
18
+ #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_XDS_XDS_RESOLVER_H
19
+
20
+ #include <grpc/support/port_platform.h>
21
+
22
+ namespace grpc_core {
23
+
24
+ extern const char* kXdsClusterAttribute;
25
+
26
+ } // namespace grpc_core
27
+
28
+ #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_XDS_XDS_RESOLVER_H */
@@ -38,6 +38,7 @@
38
38
  #include "src/core/lib/channel/status_util.h"
39
39
  #include "src/core/lib/gpr/string.h"
40
40
  #include "src/core/lib/gprpp/memory.h"
41
+ #include "src/core/lib/json/json_util.h"
41
42
  #include "src/core/lib/uri/uri_parser.h"
42
43
 
43
44
  // As per the retry design, we do not allow more than 5 retry attempts.
@@ -62,38 +63,6 @@ void ClientChannelServiceConfigParser::Register() {
62
63
 
63
64
  namespace {
64
65
 
65
- // Parses a JSON field of the form generated for a google.proto.Duration
66
- // proto message, as per:
67
- // https://developers.google.com/protocol-buffers/docs/proto3#json
68
- bool ParseDuration(const Json& field, grpc_millis* duration) {
69
- if (field.type() != Json::Type::STRING) return false;
70
- size_t len = field.string_value().size();
71
- if (field.string_value()[len - 1] != 's') return false;
72
- grpc_core::UniquePtr<char> buf(gpr_strdup(field.string_value().c_str()));
73
- *(buf.get() + len - 1) = '\0'; // Remove trailing 's'.
74
- char* decimal_point = strchr(buf.get(), '.');
75
- int nanos = 0;
76
- if (decimal_point != nullptr) {
77
- *decimal_point = '\0';
78
- nanos = gpr_parse_nonnegative_int(decimal_point + 1);
79
- if (nanos == -1) {
80
- return false;
81
- }
82
- int num_digits = static_cast<int>(strlen(decimal_point + 1));
83
- if (num_digits > 9) { // We don't accept greater precision than nanos.
84
- return false;
85
- }
86
- for (int i = 0; i < (9 - num_digits); ++i) {
87
- nanos *= 10;
88
- }
89
- }
90
- int seconds =
91
- decimal_point == buf.get() ? 0 : gpr_parse_nonnegative_int(buf.get());
92
- if (seconds == -1) return false;
93
- *duration = seconds * GPR_MS_PER_SEC + nanos / GPR_NS_PER_MS;
94
- return true;
95
- }
96
-
97
66
  std::unique_ptr<ClientChannelMethodParsedConfig::RetryPolicy> ParseRetryPolicy(
98
67
  const Json& json, grpc_error** error) {
99
68
  GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
@@ -128,7 +97,7 @@ std::unique_ptr<ClientChannelMethodParsedConfig::RetryPolicy> ParseRetryPolicy(
128
97
  // Parse initialBackoff.
129
98
  it = json.object_value().find("initialBackoff");
130
99
  if (it != json.object_value().end()) {
131
- if (!ParseDuration(it->second, &retry_policy->initial_backoff)) {
100
+ if (!ParseDurationFromJson(it->second, &retry_policy->initial_backoff)) {
132
101
  error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
133
102
  "field:initialBackoff error:Failed to parse"));
134
103
  } else if (retry_policy->initial_backoff == 0) {
@@ -139,7 +108,7 @@ std::unique_ptr<ClientChannelMethodParsedConfig::RetryPolicy> ParseRetryPolicy(
139
108
  // Parse maxBackoff.
140
109
  it = json.object_value().find("maxBackoff");
141
110
  if (it != json.object_value().end()) {
142
- if (!ParseDuration(it->second, &retry_policy->max_backoff)) {
111
+ if (!ParseDurationFromJson(it->second, &retry_policy->max_backoff)) {
143
112
  error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
144
113
  "field:maxBackoff error:failed to parse"));
145
114
  } else if (retry_policy->max_backoff == 0) {
@@ -315,8 +284,8 @@ const char* ParseHealthCheckConfig(const Json& field, grpc_error** error) {
315
284
  } // namespace
316
285
 
317
286
  std::unique_ptr<ServiceConfigParser::ParsedConfig>
318
- ClientChannelServiceConfigParser::ParseGlobalParams(const Json& json,
319
- grpc_error** error) {
287
+ ClientChannelServiceConfigParser::ParseGlobalParams(
288
+ const grpc_channel_args* /*args*/, const Json& json, grpc_error** error) {
320
289
  GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
321
290
  std::vector<grpc_error*> error_list;
322
291
  RefCountedPtr<LoadBalancingPolicy::Config> parsed_lb_config;
@@ -394,8 +363,8 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const Json& json,
394
363
  }
395
364
 
396
365
  std::unique_ptr<ServiceConfigParser::ParsedConfig>
397
- ClientChannelServiceConfigParser::ParsePerMethodParams(const Json& json,
398
- grpc_error** error) {
366
+ ClientChannelServiceConfigParser::ParsePerMethodParams(
367
+ const grpc_channel_args* /*args*/, const Json& json, grpc_error** error) {
399
368
  GPR_DEBUG_ASSERT(error != nullptr && *error == GRPC_ERROR_NONE);
400
369
  std::vector<grpc_error*> error_list;
401
370
  absl::optional<bool> wait_for_ready;
@@ -416,7 +385,7 @@ ClientChannelServiceConfigParser::ParsePerMethodParams(const Json& json,
416
385
  // Parse timeout.
417
386
  it = json.object_value().find("timeout");
418
387
  if (it != json.object_value().end()) {
419
- if (!ParseDuration(it->second, &timeout)) {
388
+ if (!ParseDurationFromJson(it->second, &timeout)) {
420
389
  error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
421
390
  "field:timeout error:Failed parsing"));
422
391
  };
@@ -111,10 +111,12 @@ class ClientChannelMethodParsedConfig
111
111
  class ClientChannelServiceConfigParser : public ServiceConfigParser::Parser {
112
112
  public:
113
113
  std::unique_ptr<ServiceConfigParser::ParsedConfig> ParseGlobalParams(
114
- const Json& json, grpc_error** error) override;
114
+ const grpc_channel_args* /*args*/, const Json& json,
115
+ grpc_error** error) override;
115
116
 
116
117
  std::unique_ptr<ServiceConfigParser::ParsedConfig> ParsePerMethodParams(
117
- const Json& json, grpc_error** error) override;
118
+ const grpc_channel_args* /*args*/, const Json& json,
119
+ grpc_error** error) override;
118
120
 
119
121
  static size_t ParserIndex();
120
122
  static void Register();
@@ -109,9 +109,10 @@ class ResolvingLoadBalancingPolicy::ResolvingControlHelper
109
109
  : parent_(std::move(parent)) {}
110
110
 
111
111
  RefCountedPtr<SubchannelInterface> CreateSubchannel(
112
- const grpc_channel_args& args) override {
112
+ ServerAddress address, const grpc_channel_args& args) override {
113
113
  if (parent_->resolver_ == nullptr) return nullptr; // Shutting down.
114
- return parent_->channel_control_helper()->CreateSubchannel(args);
114
+ return parent_->channel_control_helper()->CreateSubchannel(
115
+ std::move(address), args);
115
116
  }
116
117
 
117
118
  void UpdateState(grpc_connectivity_state state, const absl::Status& status,
@@ -173,6 +174,10 @@ ResolvingLoadBalancingPolicy::~ResolvingLoadBalancingPolicy() {
173
174
 
174
175
  void ResolvingLoadBalancingPolicy::ShutdownLocked() {
175
176
  if (resolver_ != nullptr) {
177
+ if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
178
+ gpr_log(GPR_INFO, "resolving_lb=%p: shutting down resolver=%p", this,
179
+ resolver_.get());
180
+ }
176
181
  resolver_.reset();
177
182
  if (lb_policy_ != nullptr) {
178
183
  if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) {
@@ -228,9 +233,12 @@ void ResolvingLoadBalancingPolicy::CreateOrUpdateLbPolicyLocked(
228
233
  UpdateArgs update_args;
229
234
  update_args.addresses = std::move(result.addresses);
230
235
  update_args.config = std::move(lb_policy_config);
231
- // TODO(roth): Once channel args is converted to C++, use std::move() here.
232
- update_args.args = result.args;
233
- result.args = nullptr;
236
+ // Remove the config selector from channel args so that we're not holding
237
+ // unnecessary refs that cause it to be destroyed somewhere other than in the
238
+ // WorkSerializer.
239
+ const char* arg_name = GRPC_ARG_CONFIG_SELECTOR;
240
+ update_args.args =
241
+ grpc_channel_args_copy_and_remove(result.args, &arg_name, 1);
234
242
  // Create policy if needed.
235
243
  if (lb_policy_ == nullptr) {
236
244
  lb_policy_ = CreateLbPolicyLocked(*update_args.args);
@@ -302,53 +310,46 @@ void ResolvingLoadBalancingPolicy::OnResolverResultChangedLocked(
302
310
  //
303
311
  // We track a list of strings to eventually be concatenated and traced.
304
312
  TraceStringVector trace_strings;
305
- const bool resolution_contains_addresses = result.addresses.size() > 0;
306
- // Process the resolver result.
307
- ChannelConfigHelper::ApplyServiceConfigResult service_config_result;
313
+ MaybeAddTraceMessagesForAddressChangesLocked(!result.addresses.empty(),
314
+ &trace_strings);
315
+ // The result of grpc_error_string() is owned by the error itself.
316
+ // We're storing that string in trace_strings, so we need to make sure
317
+ // that the error lives until we're done with the string.
318
+ grpc_error* service_config_error =
319
+ GRPC_ERROR_REF(result.service_config_error);
320
+ if (service_config_error != GRPC_ERROR_NONE) {
321
+ trace_strings.push_back(grpc_error_string(service_config_error));
322
+ }
323
+ // Choose the service config.
324
+ ChannelConfigHelper::ChooseServiceConfigResult service_config_result;
308
325
  if (helper_ != nullptr) {
309
- service_config_result = helper_->ApplyServiceConfig(result);
310
- if (service_config_result.service_config_error != GRPC_ERROR_NONE) {
311
- if (service_config_result.no_valid_service_config) {
312
- // We received an invalid service config and we don't have a
313
- // fallback service config.
314
- OnResolverError(service_config_result.service_config_error);
315
- service_config_result.service_config_error = GRPC_ERROR_NONE;
316
- }
317
- }
326
+ service_config_result = helper_->ChooseServiceConfig(result);
318
327
  } else {
319
328
  service_config_result.lb_policy_config = child_lb_config_;
320
329
  }
321
- // Before we send the args to the LB policy, grab the ConfigSelector for
322
- // later use.
323
- RefCountedPtr<ConfigSelector> config_selector =
324
- ConfigSelector::GetFromChannelArgs(*result.args);
325
- // Create or update LB policy, as needed.
326
- if (service_config_result.lb_policy_config != nullptr) {
330
+ if (service_config_result.no_valid_service_config) {
331
+ // We received an invalid service config and we don't have a
332
+ // previous service config to fall back to.
333
+ OnResolverError(GRPC_ERROR_REF(service_config_error));
334
+ trace_strings.push_back("no valid service config");
335
+ } else {
336
+ // Create or update LB policy, as needed.
327
337
  CreateOrUpdateLbPolicyLocked(
328
338
  std::move(service_config_result.lb_policy_config), std::move(result));
329
- }
330
- // Apply ConfigSelector to channel.
331
- // This needs to happen after the LB policy has been updated, since
332
- // the ConfigSelector may need the LB policy to know about new
333
- // destinations before it can send RPCs to those destinations.
334
- if (helper_ != nullptr) {
335
- helper_->ApplyConfigSelector(service_config_result.service_config_changed,
336
- std::move(config_selector));
339
+ if (service_config_result.service_config_changed) {
340
+ // Tell channel to start using new service config for calls.
341
+ // This needs to happen after the LB policy has been updated, since
342
+ // the ConfigSelector may need the LB policy to know about new
343
+ // destinations before it can send RPCs to those destinations.
344
+ if (helper_ != nullptr) helper_->StartUsingServiceConfigForCalls();
345
+ // TODO(ncteisen): might be worth somehow including a snippet of the
346
+ // config in the trace, at the risk of bloating the trace logs.
347
+ trace_strings.push_back("Service config changed");
348
+ }
337
349
  }
338
350
  // Add channel trace event.
339
- if (service_config_result.service_config_changed) {
340
- // TODO(ncteisen): might be worth somehow including a snippet of the
341
- // config in the trace, at the risk of bloating the trace logs.
342
- trace_strings.push_back("Service config changed");
343
- }
344
- if (service_config_result.service_config_error != GRPC_ERROR_NONE) {
345
- trace_strings.push_back(
346
- grpc_error_string(service_config_result.service_config_error));
347
- }
348
- MaybeAddTraceMessagesForAddressChangesLocked(resolution_contains_addresses,
349
- &trace_strings);
350
351
  ConcatenateAndAddChannelTraceLocked(trace_strings);
351
- GRPC_ERROR_UNREF(service_config_result.service_config_error);
352
+ GRPC_ERROR_UNREF(service_config_error);
352
353
  }
353
354
 
354
355
  } // namespace grpc_core
@@ -55,29 +55,25 @@ class ResolvingLoadBalancingPolicy : public LoadBalancingPolicy {
55
55
  public:
56
56
  class ChannelConfigHelper {
57
57
  public:
58
- struct ApplyServiceConfigResult {
58
+ struct ChooseServiceConfigResult {
59
59
  // Set to true if the service config has changed since the last result.
60
60
  bool service_config_changed = false;
61
61
  // Set to true if we don't have a valid service config to use.
62
62
  // This tells the ResolvingLoadBalancingPolicy to put the channel
63
63
  // into TRANSIENT_FAILURE.
64
64
  bool no_valid_service_config = false;
65
- // A service config parsing error occurred.
66
- grpc_error* service_config_error = GRPC_ERROR_NONE;
67
65
  // The LB policy config to use.
68
66
  RefCountedPtr<LoadBalancingPolicy::Config> lb_policy_config;
69
67
  };
70
68
 
71
69
  virtual ~ChannelConfigHelper() = default;
72
70
 
73
- // Applies the service config to the channel.
74
- virtual ApplyServiceConfigResult ApplyServiceConfig(
71
+ // Chooses the service config for the channel.
72
+ virtual ChooseServiceConfigResult ChooseServiceConfig(
75
73
  const Resolver::Result& result) = 0;
76
74
 
77
- // Applies the ConfigSelector to the channel.
78
- virtual void ApplyConfigSelector(
79
- bool service_config_changed,
80
- RefCountedPtr<ConfigSelector> config_selector) = 0;
75
+ // Starts using the service config for calls.
76
+ virtual void StartUsingServiceConfigForCalls() = 0;
81
77
 
82
78
  // Indicates a resolver transient failure.
83
79
  virtual void ResolverTransientFailure(grpc_error* error) = 0;
@@ -20,6 +20,15 @@
20
20
 
21
21
  #include "src/core/ext/filters/client_channel/server_address.h"
22
22
 
23
+ #include <memory>
24
+ #include <string>
25
+ #include <vector>
26
+
27
+ #include "absl/strings/str_cat.h"
28
+ #include "absl/strings/str_join.h"
29
+
30
+ #include "src/core/lib/iomgr/sockaddr_utils.h"
31
+
23
32
  namespace grpc_core {
24
33
 
25
34
  //
@@ -39,6 +48,38 @@ ServerAddress::ServerAddress(
39
48
  address_.len = static_cast<socklen_t>(address_len);
40
49
  }
41
50
 
51
+ ServerAddress::ServerAddress(const ServerAddress& other)
52
+ : address_(other.address_), args_(grpc_channel_args_copy(other.args_)) {
53
+ for (const auto& p : other.attributes_) {
54
+ attributes_[p.first] = p.second->Copy();
55
+ }
56
+ }
57
+ ServerAddress& ServerAddress::operator=(const ServerAddress& other) {
58
+ address_ = other.address_;
59
+ grpc_channel_args_destroy(args_);
60
+ args_ = grpc_channel_args_copy(other.args_);
61
+ attributes_.clear();
62
+ for (const auto& p : other.attributes_) {
63
+ attributes_[p.first] = p.second->Copy();
64
+ }
65
+ return *this;
66
+ }
67
+
68
+ ServerAddress::ServerAddress(ServerAddress&& other) noexcept
69
+ : address_(other.address_),
70
+ args_(other.args_),
71
+ attributes_(std::move(other.attributes_)) {
72
+ other.args_ = nullptr;
73
+ }
74
+ ServerAddress& ServerAddress::operator=(ServerAddress&& other) noexcept {
75
+ address_ = other.address_;
76
+ grpc_channel_args_destroy(args_);
77
+ args_ = other.args_;
78
+ other.args_ = nullptr;
79
+ attributes_ = std::move(other.attributes_);
80
+ return *this;
81
+ }
82
+
42
83
  namespace {
43
84
 
44
85
  int CompareAttributes(
@@ -78,4 +119,43 @@ int ServerAddress::Cmp(const ServerAddress& other) const {
78
119
  return CompareAttributes(attributes_, other.attributes_);
79
120
  }
80
121
 
122
+ const ServerAddress::AttributeInterface* ServerAddress::GetAttribute(
123
+ const char* key) const {
124
+ auto it = attributes_.find(key);
125
+ if (it == attributes_.end()) return nullptr;
126
+ return it->second.get();
127
+ }
128
+
129
+ // Returns a copy of the address with a modified attribute.
130
+ // If the new value is null, the attribute is removed.
131
+ ServerAddress ServerAddress::WithAttribute(
132
+ const char* key, std::unique_ptr<AttributeInterface> value) const {
133
+ ServerAddress address = *this;
134
+ if (value == nullptr) {
135
+ address.attributes_.erase(key);
136
+ } else {
137
+ address.attributes_[key] = std::move(value);
138
+ }
139
+ return address;
140
+ }
141
+
142
+ std::string ServerAddress::ToString() const {
143
+ std::vector<std::string> parts = {
144
+ grpc_sockaddr_to_string(&address_, false),
145
+ };
146
+ if (args_ != nullptr) {
147
+ parts.emplace_back(
148
+ absl::StrCat("args={", grpc_channel_args_string(args_), "}"));
149
+ }
150
+ if (!attributes_.empty()) {
151
+ std::vector<std::string> attrs;
152
+ for (const auto& p : attributes_) {
153
+ attrs.emplace_back(absl::StrCat(p.first, "=", p.second->ToString()));
154
+ }
155
+ parts.emplace_back(
156
+ absl::StrCat("attributes={", absl::StrJoin(attrs, ", "), "}"));
157
+ }
158
+ return absl::StrJoin(parts, " ");
159
+ }
160
+
81
161
  } // namespace grpc_core
@@ -22,6 +22,7 @@
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
24
  #include <map>
25
+ #include <memory>
25
26
 
26
27
  #include "absl/container/inlined_vector.h"
27
28
 
@@ -42,15 +43,22 @@ class ServerAddress {
42
43
  // Base class for resolver-supplied attributes.
43
44
  // Unlike channel args, these attributes don't affect subchannel
44
45
  // uniqueness or behavior. They are for use by LB policies only.
46
+ //
47
+ // Attributes are keyed by a C string that is unique by address, not
48
+ // by value. All attributes added with the same key must be of the
49
+ // same type.
45
50
  class AttributeInterface {
46
51
  public:
47
- virtual ~AttributeInterface();
52
+ virtual ~AttributeInterface() = default;
48
53
 
49
54
  // Creates a copy of the attribute.
50
55
  virtual std::unique_ptr<AttributeInterface> Copy() const = 0;
51
56
 
52
57
  // Compares this attribute with another.
53
58
  virtual int Cmp(const AttributeInterface* other) const = 0;
59
+
60
+ // Returns a human-readable representation of the attribute.
61
+ virtual std::string ToString() const = 0;
54
62
  };
55
63
 
56
64
  // Takes ownership of args.
@@ -65,38 +73,12 @@ class ServerAddress {
65
73
  ~ServerAddress() { grpc_channel_args_destroy(args_); }
66
74
 
67
75
  // Copyable.
68
- ServerAddress(const ServerAddress& other)
69
- : address_(other.address_), args_(grpc_channel_args_copy(other.args_)) {
70
- for (const auto& p : other.attributes_) {
71
- attributes_[p.first] = p.second->Copy();
72
- }
73
- }
74
- ServerAddress& operator=(const ServerAddress& other) {
75
- address_ = other.address_;
76
- grpc_channel_args_destroy(args_);
77
- args_ = grpc_channel_args_copy(other.args_);
78
- attributes_.clear();
79
- for (const auto& p : other.attributes_) {
80
- attributes_[p.first] = p.second->Copy();
81
- }
82
- return *this;
83
- }
76
+ ServerAddress(const ServerAddress& other);
77
+ ServerAddress& operator=(const ServerAddress& other);
84
78
 
85
79
  // Movable.
86
- ServerAddress(ServerAddress&& other)
87
- : address_(other.address_),
88
- args_(other.args_),
89
- attributes_(std::move(other.attributes_)) {
90
- other.args_ = nullptr;
91
- }
92
- ServerAddress& operator=(ServerAddress&& other) {
93
- address_ = other.address_;
94
- grpc_channel_args_destroy(args_);
95
- args_ = other.args_;
96
- other.args_ = nullptr;
97
- attributes_ = std::move(other.attributes_);
98
- return *this;
99
- }
80
+ ServerAddress(ServerAddress&& other) noexcept;
81
+ ServerAddress& operator=(ServerAddress&& other) noexcept;
100
82
 
101
83
  bool operator==(const ServerAddress& other) const { return Cmp(other) == 0; }
102
84
 
@@ -105,13 +87,20 @@ class ServerAddress {
105
87
  const grpc_resolved_address& address() const { return address_; }
106
88
  const grpc_channel_args* args() const { return args_; }
107
89
 
108
- const AttributeInterface* GetAttribute(const char* key) const {
109
- auto it = attributes_.find(key);
110
- if (it == attributes_.end()) return nullptr;
111
- return it->second.get();
112
- }
90
+ const AttributeInterface* GetAttribute(const char* key) const;
91
+
92
+ // Returns a copy of the address with a modified attribute.
93
+ // If the new value is null, the attribute is removed.
94
+ ServerAddress WithAttribute(const char* key,
95
+ std::unique_ptr<AttributeInterface> value) const;
96
+
97
+ std::string ToString() const;
113
98
 
114
99
  private:
100
+ // Allows the channel to access the attributes without knowing the keys.
101
+ // (We intentionally do not allow LB policies to do this.)
102
+ friend class ChannelServerAddressPeer;
103
+
115
104
  grpc_resolved_address address_;
116
105
  grpc_channel_args* args_;
117
106
  std::map<const char*, std::unique_ptr<AttributeInterface>> attributes_;