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
@@ -37,20 +37,6 @@
37
37
 
38
38
  namespace grpc_core {
39
39
 
40
- // PolymorphicRefCount enforces polymorphic destruction of RefCounted.
41
- class PolymorphicRefCount {
42
- public:
43
- virtual ~PolymorphicRefCount() = default;
44
- };
45
-
46
- // NonPolymorphicRefCount does not enforce polymorphic destruction of
47
- // RefCounted. Please refer to grpc_core::RefCounted for more details, and
48
- // when in doubt use PolymorphicRefCount.
49
- class NonPolymorphicRefCount {
50
- public:
51
- ~NonPolymorphicRefCount() = default;
52
- };
53
-
54
40
  // RefCount is a simple atomic ref-count.
55
41
  //
56
42
  // This is a C++ implementation of gpr_refcount, with inline functions. Due to
@@ -218,9 +204,45 @@ class RefCount {
218
204
  Atomic<Value> value_;
219
205
  };
220
206
 
207
+ // PolymorphicRefCount enforces polymorphic destruction of RefCounted.
208
+ class PolymorphicRefCount {
209
+ public:
210
+ virtual ~PolymorphicRefCount() = default;
211
+ };
212
+
213
+ // NonPolymorphicRefCount does not enforce polymorphic destruction of
214
+ // RefCounted. Please refer to grpc_core::RefCounted for more details, and
215
+ // when in doubt use PolymorphicRefCount.
216
+ class NonPolymorphicRefCount {
217
+ public:
218
+ ~NonPolymorphicRefCount() = default;
219
+ };
220
+
221
+ namespace internal {
222
+ template <typename T, bool DoDelete>
223
+ class Delete;
224
+ template <typename T>
225
+ class Delete<T, true> {
226
+ public:
227
+ Delete(T* t) { delete t; }
228
+ };
229
+ template <typename T>
230
+ class Delete<T, false> {
231
+ public:
232
+ Delete(T* t) {}
233
+ };
234
+ } // namespace internal
235
+
221
236
  // A base class for reference-counted objects.
222
- // New objects should be created via New() and start with a refcount of 1.
223
- // When the refcount reaches 0, the object will be deleted via delete .
237
+ // New objects should be created via new and start with a refcount of 1.
238
+ // When the refcount reaches 0, the object will be deleted via delete.
239
+ //
240
+ // If DeleteUponUnref is false, deletion will not occur when the ref
241
+ // count reaches 0. This is useful in cases where all existing objects
242
+ // must be tracked in a registry but the object's entry in the registry
243
+ // cannot be removed from the object's dtor due to synchronization issues.
244
+ // In this case, the registry can be cleaned up later by identifying
245
+ // entries for which RefIfNonZero() returns null.
224
246
  //
225
247
  // This will commonly be used by CRTP (curiously-recurring template pattern)
226
248
  // e.g., class MyClass : public RefCounted<MyClass>
@@ -244,7 +266,8 @@ class RefCount {
244
266
  // Child* ch;
245
267
  // ch->Unref();
246
268
  //
247
- template <typename Child, typename Impl = PolymorphicRefCount>
269
+ template <typename Child, typename Impl = PolymorphicRefCount,
270
+ bool DeleteUponUnref = true>
248
271
  class RefCounted : public Impl {
249
272
  public:
250
273
  // Note: Depending on the Impl used, this dtor can be implicitly virtual.
@@ -267,18 +290,24 @@ class RefCounted : public Impl {
267
290
  // friend of this class.
268
291
  void Unref() {
269
292
  if (GPR_UNLIKELY(refs_.Unref())) {
270
- delete static_cast<Child*>(this);
293
+ internal::Delete<Child, DeleteUponUnref>(static_cast<Child*>(this));
271
294
  }
272
295
  }
273
296
  void Unref(const DebugLocation& location, const char* reason) {
274
297
  if (GPR_UNLIKELY(refs_.Unref(location, reason))) {
275
- delete static_cast<Child*>(this);
298
+ internal::Delete<Child, DeleteUponUnref>(static_cast<Child*>(this));
276
299
  }
277
300
  }
278
301
 
279
- bool RefIfNonZero() { return refs_.RefIfNonZero(); }
280
- bool RefIfNonZero(const DebugLocation& location, const char* reason) {
281
- return refs_.RefIfNonZero(location, reason);
302
+ RefCountedPtr<Child> RefIfNonZero() GRPC_MUST_USE_RESULT {
303
+ return RefCountedPtr<Child>(refs_.RefIfNonZero() ? static_cast<Child*>(this)
304
+ : nullptr);
305
+ }
306
+ RefCountedPtr<Child> RefIfNonZero(const DebugLocation& location,
307
+ const char* reason) GRPC_MUST_USE_RESULT {
308
+ return RefCountedPtr<Child>(refs_.RefIfNonZero(location, reason)
309
+ ? static_cast<Child*>(this)
310
+ : nullptr);
282
311
  }
283
312
 
284
313
  // Not copyable nor movable.
@@ -177,6 +177,154 @@ class RefCountedPtr {
177
177
  T* value_ = nullptr;
178
178
  };
179
179
 
180
+ // A smart pointer class for objects that provide IncrementWeakRefCount() and
181
+ // WeakUnref() methods, such as those provided by the DualRefCounted base class.
182
+ template <typename T>
183
+ class WeakRefCountedPtr {
184
+ public:
185
+ WeakRefCountedPtr() {}
186
+ WeakRefCountedPtr(std::nullptr_t) {}
187
+
188
+ // If value is non-null, we take ownership of a ref to it.
189
+ template <typename Y>
190
+ explicit WeakRefCountedPtr(Y* value) {
191
+ value_ = value;
192
+ }
193
+
194
+ // Move ctors.
195
+ WeakRefCountedPtr(WeakRefCountedPtr&& other) {
196
+ value_ = other.value_;
197
+ other.value_ = nullptr;
198
+ }
199
+ template <typename Y>
200
+ WeakRefCountedPtr(WeakRefCountedPtr<Y>&& other) {
201
+ value_ = static_cast<T*>(other.value_);
202
+ other.value_ = nullptr;
203
+ }
204
+
205
+ // Move assignment.
206
+ WeakRefCountedPtr& operator=(WeakRefCountedPtr&& other) {
207
+ reset(other.value_);
208
+ other.value_ = nullptr;
209
+ return *this;
210
+ }
211
+ template <typename Y>
212
+ WeakRefCountedPtr& operator=(WeakRefCountedPtr<Y>&& other) {
213
+ reset(other.value_);
214
+ other.value_ = nullptr;
215
+ return *this;
216
+ }
217
+
218
+ // Copy ctors.
219
+ WeakRefCountedPtr(const WeakRefCountedPtr& other) {
220
+ if (other.value_ != nullptr) other.value_->IncrementWeakRefCount();
221
+ value_ = other.value_;
222
+ }
223
+ template <typename Y>
224
+ WeakRefCountedPtr(const WeakRefCountedPtr<Y>& other) {
225
+ static_assert(std::has_virtual_destructor<T>::value,
226
+ "T does not have a virtual dtor");
227
+ if (other.value_ != nullptr) other.value_->IncrementWeakRefCount();
228
+ value_ = static_cast<T*>(other.value_);
229
+ }
230
+
231
+ // Copy assignment.
232
+ WeakRefCountedPtr& operator=(const WeakRefCountedPtr& other) {
233
+ // Note: Order of reffing and unreffing is important here in case value_
234
+ // and other.value_ are the same object.
235
+ if (other.value_ != nullptr) other.value_->IncrementWeakRefCount();
236
+ reset(other.value_);
237
+ return *this;
238
+ }
239
+ template <typename Y>
240
+ WeakRefCountedPtr& operator=(const WeakRefCountedPtr<Y>& other) {
241
+ static_assert(std::has_virtual_destructor<T>::value,
242
+ "T does not have a virtual dtor");
243
+ // Note: Order of reffing and unreffing is important here in case value_
244
+ // and other.value_ are the same object.
245
+ if (other.value_ != nullptr) other.value_->IncrementWeakRefCount();
246
+ reset(other.value_);
247
+ return *this;
248
+ }
249
+
250
+ ~WeakRefCountedPtr() {
251
+ if (value_ != nullptr) value_->WeakUnref();
252
+ }
253
+
254
+ void swap(WeakRefCountedPtr& other) { std::swap(value_, other.value_); }
255
+
256
+ // If value is non-null, we take ownership of a ref to it.
257
+ void reset(T* value = nullptr) {
258
+ if (value_ != nullptr) value_->WeakUnref();
259
+ value_ = value;
260
+ }
261
+ void reset(const DebugLocation& location, const char* reason,
262
+ T* value = nullptr) {
263
+ if (value_ != nullptr) value_->WeakUnref(location, reason);
264
+ value_ = value;
265
+ }
266
+ template <typename Y>
267
+ void reset(Y* value = nullptr) {
268
+ static_assert(std::has_virtual_destructor<T>::value,
269
+ "T does not have a virtual dtor");
270
+ if (value_ != nullptr) value_->WeakUnref();
271
+ value_ = static_cast<T*>(value);
272
+ }
273
+ template <typename Y>
274
+ void reset(const DebugLocation& location, const char* reason,
275
+ Y* value = nullptr) {
276
+ static_assert(std::has_virtual_destructor<T>::value,
277
+ "T does not have a virtual dtor");
278
+ if (value_ != nullptr) value_->WeakUnref(location, reason);
279
+ value_ = static_cast<T*>(value);
280
+ }
281
+
282
+ // TODO(roth): This method exists solely as a transition mechanism to allow
283
+ // us to pass a ref to idiomatic C code that does not use WeakRefCountedPtr<>.
284
+ // Once all of our code has been converted to idiomatic C++, this
285
+ // method should go away.
286
+ T* release() {
287
+ T* value = value_;
288
+ value_ = nullptr;
289
+ return value;
290
+ }
291
+
292
+ T* get() const { return value_; }
293
+
294
+ T& operator*() const { return *value_; }
295
+ T* operator->() const { return value_; }
296
+
297
+ template <typename Y>
298
+ bool operator==(const WeakRefCountedPtr<Y>& other) const {
299
+ return value_ == other.value_;
300
+ }
301
+
302
+ template <typename Y>
303
+ bool operator==(const Y* other) const {
304
+ return value_ == other;
305
+ }
306
+
307
+ bool operator==(std::nullptr_t) const { return value_ == nullptr; }
308
+
309
+ template <typename Y>
310
+ bool operator!=(const WeakRefCountedPtr<Y>& other) const {
311
+ return value_ != other.value_;
312
+ }
313
+
314
+ template <typename Y>
315
+ bool operator!=(const Y* other) const {
316
+ return value_ != other;
317
+ }
318
+
319
+ bool operator!=(std::nullptr_t) const { return value_ != nullptr; }
320
+
321
+ private:
322
+ template <typename Y>
323
+ friend class WeakRefCountedPtr;
324
+
325
+ T* value_ = nullptr;
326
+ };
327
+
180
328
  template <typename T, typename... Args>
181
329
  inline RefCountedPtr<T> MakeRefCounted(Args&&... args) {
182
330
  return RefCountedPtr<T>(new T(std::forward<Args>(args)...));
@@ -187,6 +335,11 @@ bool operator<(const RefCountedPtr<T>& p1, const RefCountedPtr<T>& p2) {
187
335
  return p1.get() < p2.get();
188
336
  }
189
337
 
338
+ template <typename T>
339
+ bool operator<(const WeakRefCountedPtr<T>& p1, const WeakRefCountedPtr<T>& p2) {
340
+ return p1.get() < p2.get();
341
+ }
342
+
190
343
  } // namespace grpc_core
191
344
 
192
345
  #endif /* GRPC_CORE_LIB_GPRPP_REF_COUNTED_PTR_H */
@@ -365,13 +365,17 @@ grpc_endpoint* grpc_cfstream_endpoint_create(
365
365
  CFSTREAM_HANDLE_REF(ep_impl->stream_sync, "endpoint create");
366
366
 
367
367
  ep_impl->peer_string = peer_string;
368
- const int* native_handle =
369
- reinterpret_cast<const int*>(CFReadStreamCopyProperty(
370
- ep_impl->read_stream, kCFStreamPropertySocketNativeHandle));
371
368
  grpc_resolved_address resolved_local_addr;
372
369
  resolved_local_addr.len = sizeof(resolved_local_addr.addr);
373
- if (getsockname(*native_handle,
374
- reinterpret_cast<sockaddr*>(resolved_local_addr.addr),
370
+ CFDataRef native_handle = static_cast<CFDataRef>(CFReadStreamCopyProperty(
371
+ ep_impl->read_stream, kCFStreamPropertySocketNativeHandle));
372
+ CFSocketNativeHandle sockfd;
373
+ CFDataGetBytes(native_handle, CFRangeMake(0, sizeof(CFSocketNativeHandle)),
374
+ (UInt8*)&sockfd);
375
+ if (native_handle) {
376
+ CFRelease(native_handle);
377
+ }
378
+ if (getsockname(sockfd, reinterpret_cast<sockaddr*>(resolved_local_addr.addr),
375
379
  &resolved_local_addr.len) < 0) {
376
380
  ep_impl->local_address = "";
377
381
  } else {
@@ -331,9 +331,15 @@ class ApplicationCallbackExecCtx {
331
331
  }
332
332
  }
333
333
 
334
+ uintptr_t Flags() { return flags_; }
335
+
336
+ static ApplicationCallbackExecCtx* Get() {
337
+ return reinterpret_cast<ApplicationCallbackExecCtx*>(
338
+ gpr_tls_get(&callback_exec_ctx_));
339
+ }
340
+
334
341
  static void Set(ApplicationCallbackExecCtx* exec_ctx, uintptr_t flags) {
335
- if (reinterpret_cast<ApplicationCallbackExecCtx*>(
336
- gpr_tls_get(&callback_exec_ctx_)) == nullptr) {
342
+ if (Get() == nullptr) {
337
343
  if (!(GRPC_APP_CALLBACK_EXEC_CTX_FLAG_IS_INTERNAL_THREAD & flags)) {
338
344
  grpc_core::Fork::IncExecCtxCount();
339
345
  }
@@ -346,8 +352,7 @@ class ApplicationCallbackExecCtx {
346
352
  functor->internal_success = is_success;
347
353
  functor->internal_next = nullptr;
348
354
 
349
- auto* ctx = reinterpret_cast<ApplicationCallbackExecCtx*>(
350
- gpr_tls_get(&callback_exec_ctx_));
355
+ ApplicationCallbackExecCtx* ctx = Get();
351
356
 
352
357
  if (ctx->head_ == nullptr) {
353
358
  ctx->head_ = functor;
@@ -364,10 +369,7 @@ class ApplicationCallbackExecCtx {
364
369
  /** Global shutdown for ApplicationCallbackExecCtx. Called by init. */
365
370
  static void GlobalShutdown(void) { gpr_tls_destroy(&callback_exec_ctx_); }
366
371
 
367
- static bool Available() {
368
- return reinterpret_cast<ApplicationCallbackExecCtx*>(
369
- gpr_tls_get(&callback_exec_ctx_)) != nullptr;
370
- }
372
+ static bool Available() { return Get() != nullptr; }
371
373
 
372
374
  private:
373
375
  uintptr_t flags_{0u};
@@ -0,0 +1,58 @@
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
+ #include <grpc/support/port_platform.h>
20
+
21
+ #include "src/core/lib/json/json_util.h"
22
+
23
+ #include <grpc/support/string_util.h>
24
+
25
+ #include "src/core/lib/gpr/string.h"
26
+
27
+ namespace grpc_core {
28
+
29
+ bool ParseDurationFromJson(const Json& field, grpc_millis* duration) {
30
+ if (field.type() != Json::Type::STRING) return false;
31
+ size_t len = field.string_value().size();
32
+ if (field.string_value()[len - 1] != 's') return false;
33
+ grpc_core::UniquePtr<char> buf(gpr_strdup(field.string_value().c_str()));
34
+ *(buf.get() + len - 1) = '\0'; // Remove trailing 's'.
35
+ char* decimal_point = strchr(buf.get(), '.');
36
+ int nanos = 0;
37
+ if (decimal_point != nullptr) {
38
+ *decimal_point = '\0';
39
+ nanos = gpr_parse_nonnegative_int(decimal_point + 1);
40
+ if (nanos == -1) {
41
+ return false;
42
+ }
43
+ int num_digits = static_cast<int>(strlen(decimal_point + 1));
44
+ if (num_digits > 9) { // We don't accept greater precision than nanos.
45
+ return false;
46
+ }
47
+ for (int i = 0; i < (9 - num_digits); ++i) {
48
+ nanos *= 10;
49
+ }
50
+ }
51
+ int seconds =
52
+ decimal_point == buf.get() ? 0 : gpr_parse_nonnegative_int(buf.get());
53
+ if (seconds == -1) return false;
54
+ *duration = seconds * GPR_MS_PER_SEC + nanos / GPR_NS_PER_MS;
55
+ return true;
56
+ }
57
+
58
+ } // namespace grpc_core
@@ -0,0 +1,37 @@
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_LIB_JSON_JSON_UTIL_H
20
+ #define GRPC_CORE_LIB_JSON_JSON_UTIL_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include "src/core/lib/iomgr/exec_ctx.h"
25
+ #include "src/core/lib/json/json.h"
26
+
27
+ namespace grpc_core {
28
+
29
+ // Parses a JSON field of the form generated for a google.proto.Duration
30
+ // proto message, as per:
31
+ // https://developers.google.com/protocol-buffers/docs/proto3#json
32
+ // Returns true on success, false otherwise.
33
+ bool ParseDurationFromJson(const Json& field, grpc_millis* duration);
34
+
35
+ } // namespace grpc_core
36
+
37
+ #endif // GRPC_CORE_LIB_JSON_JSON_UTIL_H
@@ -0,0 +1,60 @@
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_LIB_SECURITY_CERTIFICATE_PROVIDER_H
20
+ #define GRPC_CORE_LIB_SECURITY_CERTIFICATE_PROVIDER_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include "src/core/lib/gprpp/ref_counted.h"
25
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
26
+ #include "src/core/lib/iomgr/pollset_set.h"
27
+
28
+ // TODO(yashkt): After https://github.com/grpc/grpc/pull/23572, remove this
29
+ // forward declaration and include the header for the distributor instead.
30
+ struct grpc_tls_certificate_distributor;
31
+
32
+ // Interface for a grpc_tls_certificate_provider that handles the process to
33
+ // fetch credentials and validation contexts. Implementations are free to rely
34
+ // on local or remote sources to fetch the latest secrets, and free to share any
35
+ // state among different instances as they deem fit.
36
+ //
37
+ // On creation, grpc_tls_certificate_provider creates a
38
+ // grpc_tls_certificate_distributor object. When the credentials and validation
39
+ // contexts become valid or changed, a grpc_tls_certificate_provider should
40
+ // notify its distributor so as to propagate the update to the watchers.
41
+ struct grpc_tls_certificate_provider
42
+ : public grpc_core::RefCounted<grpc_tls_certificate_provider> {
43
+ public:
44
+ grpc_tls_certificate_provider()
45
+ : interested_parties_(grpc_pollset_set_create()) {}
46
+
47
+ virtual ~grpc_tls_certificate_provider() {
48
+ grpc_pollset_set_destroy(interested_parties_);
49
+ }
50
+
51
+ grpc_pollset_set* interested_parties() const { return interested_parties_; }
52
+
53
+ virtual grpc_core::RefCountedPtr<grpc_tls_certificate_distributor>
54
+ distributor() const = 0;
55
+
56
+ private:
57
+ grpc_pollset_set* interested_parties_;
58
+ };
59
+
60
+ #endif // GRPC_CORE_LIB_SECURITY_CERTIFICATE_PROVIDER_H