grpc 1.17.1 → 1.18.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 (166) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1228 -988
  3. data/etc/roots.pem +242 -30
  4. data/include/grpc/grpc.h +2 -1
  5. data/include/grpc/grpc_security_constants.h +3 -3
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  7. data/include/grpc/impl/codegen/atm_windows.h +2 -0
  8. data/include/grpc/impl/codegen/compression_types.h +2 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +1 -1
  10. data/include/grpc/impl/codegen/port_platform.h +9 -0
  11. data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
  14. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  20. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
  21. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
  22. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
  28. data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
  29. data/src/core/ext/filters/client_channel/request_routing.h +177 -0
  30. data/src/core/ext/filters/client_channel/resolver.cc +1 -1
  31. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  32. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
  33. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
  39. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
  40. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
  41. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
  42. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
  43. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
  44. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
  45. data/src/core/ext/filters/client_channel/server_address.cc +103 -0
  46. data/src/core/ext/filters/client_channel/server_address.h +108 -0
  47. data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
  48. data/src/core/ext/filters/client_channel/subchannel.h +9 -6
  49. data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
  50. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
  51. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
  52. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
  53. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  54. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
  55. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
  57. data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
  58. data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
  59. data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
  60. data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
  61. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  62. data/src/core/lib/channel/channelz.cc +19 -18
  63. data/src/core/lib/channel/channelz.h +7 -1
  64. data/src/core/lib/channel/channelz_registry.cc +3 -2
  65. data/src/core/lib/debug/trace.cc +3 -0
  66. data/src/core/lib/debug/trace.h +5 -3
  67. data/src/core/lib/gpr/sync_posix.cc +96 -4
  68. data/src/core/lib/gprpp/inlined_vector.h +25 -19
  69. data/src/core/lib/gprpp/memory.h +2 -11
  70. data/src/core/lib/gprpp/orphanable.h +18 -82
  71. data/src/core/lib/gprpp/ref_counted.h +75 -84
  72. data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
  73. data/src/core/lib/http/httpcli_security_connector.cc +101 -94
  74. data/src/core/lib/http/parser.h +5 -5
  75. data/src/core/lib/iomgr/buffer_list.cc +16 -5
  76. data/src/core/lib/iomgr/buffer_list.h +10 -3
  77. data/src/core/lib/iomgr/call_combiner.cc +50 -2
  78. data/src/core/lib/iomgr/call_combiner.h +29 -2
  79. data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
  80. data/src/core/lib/iomgr/endpoint.cc +4 -0
  81. data/src/core/lib/iomgr/endpoint.h +3 -0
  82. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  83. data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
  84. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
  85. data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
  86. data/src/core/lib/iomgr/ev_posix.cc +15 -7
  87. data/src/core/lib/iomgr/ev_posix.h +10 -0
  88. data/src/core/lib/iomgr/exec_ctx.cc +13 -0
  89. data/src/core/lib/iomgr/fork_posix.cc +1 -1
  90. data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
  91. data/src/core/lib/iomgr/internal_errqueue.h +7 -1
  92. data/src/core/lib/iomgr/iomgr.cc +7 -0
  93. data/src/core/lib/iomgr/iomgr.h +4 -0
  94. data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
  95. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  96. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  97. data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
  98. data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
  99. data/src/core/lib/iomgr/port.h +1 -2
  100. data/src/core/lib/iomgr/resource_quota.cc +1 -0
  101. data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
  102. data/src/core/lib/iomgr/tcp_custom.cc +4 -1
  103. data/src/core/lib/iomgr/tcp_posix.cc +95 -35
  104. data/src/core/lib/iomgr/tcp_windows.cc +4 -1
  105. data/src/core/lib/iomgr/timer_manager.cc +6 -0
  106. data/src/core/lib/security/context/security_context.cc +75 -108
  107. data/src/core/lib/security/context/security_context.h +59 -35
  108. data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
  109. data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
  110. data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
  111. data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
  112. data/src/core/lib/security/credentials/credentials.cc +18 -142
  113. data/src/core/lib/security/credentials/credentials.h +119 -95
  114. data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
  115. data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
  116. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
  117. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
  118. data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
  119. data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
  120. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
  121. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
  122. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
  123. data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
  124. data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
  125. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
  127. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
  128. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
  129. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
  130. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
  131. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
  132. data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
  133. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
  134. data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
  135. data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
  136. data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
  137. data/src/core/lib/security/security_connector/security_connector.cc +41 -124
  138. data/src/core/lib/security/security_connector/security_connector.h +102 -105
  139. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
  140. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
  141. data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
  142. data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
  143. data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
  144. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  145. data/src/core/lib/security/transport/security_handshaker.cc +82 -66
  146. data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
  147. data/src/core/lib/surface/init.cc +1 -0
  148. data/src/core/lib/surface/server.cc +13 -11
  149. data/src/core/lib/surface/server.h +6 -6
  150. data/src/core/lib/surface/version.cc +2 -2
  151. data/src/core/lib/transport/metadata.cc +1 -0
  152. data/src/core/lib/transport/static_metadata.cc +228 -221
  153. data/src/core/lib/transport/static_metadata.h +75 -71
  154. data/src/core/lib/transport/transport.cc +2 -1
  155. data/src/core/lib/transport/transport.h +5 -1
  156. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
  157. data/src/core/tsi/ssl_transport_security.cc +35 -24
  158. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  159. data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
  160. data/src/ruby/lib/grpc/generic/service.rb +1 -1
  161. data/src/ruby/lib/grpc/version.rb +1 -1
  162. data/src/ruby/pb/grpc/health/checker.rb +2 -3
  163. data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
  164. data/src/ruby/spec/support/services.rb +1 -0
  165. metadata +37 -32
  166. data/src/core/ext/filters/client_channel/lb_policy_factory.cc +0 -163
@@ -21,6 +21,7 @@
21
21
 
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
+ #include <grpc/support/atm.h>
24
25
  #include <grpc/support/log.h>
25
26
  #include <grpc/support/sync.h>
26
27
 
@@ -73,31 +74,82 @@ class RefCount {
73
74
  using Value = intptr_t;
74
75
 
75
76
  // `init` is the initial refcount stored in this object.
76
- constexpr explicit RefCount(Value init = 1) : value_(init) {}
77
+ //
78
+ // TraceFlagT is defined to accept both DebugOnlyTraceFlag and TraceFlag.
79
+ // Note: RefCount tracing is only enabled on debug builds, even when a
80
+ // TraceFlag is used.
81
+ template <typename TraceFlagT = TraceFlag>
82
+ constexpr explicit RefCount(Value init = 1, TraceFlagT* trace_flag = nullptr)
83
+ :
84
+ #ifndef NDEBUG
85
+ trace_flag_(trace_flag),
86
+ #endif
87
+ value_(init) {
88
+ }
77
89
 
78
90
  // Increases the ref-count by `n`.
79
- void Ref(Value n = 1) { value_.fetch_add(n, std::memory_order_relaxed); }
91
+ void Ref(Value n = 1) {
92
+ GPR_ATM_INC_ADD_THEN(value_.fetch_add(n, std::memory_order_relaxed));
93
+ }
94
+ void Ref(const DebugLocation& location, const char* reason, Value n = 1) {
95
+ #ifndef NDEBUG
96
+ if (location.Log() && trace_flag_ != nullptr && trace_flag_->enabled()) {
97
+ const RefCount::Value old_refs = get();
98
+ gpr_log(GPR_INFO, "%s:%p %s:%d ref %" PRIdPTR " -> %" PRIdPTR " %s",
99
+ trace_flag_->name(), this, location.file(), location.line(),
100
+ old_refs, old_refs + n, reason);
101
+ }
102
+ #endif
103
+ Ref(n);
104
+ }
80
105
 
81
106
  // Similar to Ref() with an assert on the ref-count being non-zero.
82
107
  void RefNonZero() {
83
108
  #ifndef NDEBUG
84
- const Value prior = value_.fetch_add(1, std::memory_order_relaxed);
109
+ const Value prior =
110
+ GPR_ATM_INC_ADD_THEN(value_.fetch_add(1, std::memory_order_relaxed));
85
111
  assert(prior > 0);
86
112
  #else
87
113
  Ref();
88
114
  #endif
89
115
  }
116
+ void RefNonZero(const DebugLocation& location, const char* reason) {
117
+ #ifndef NDEBUG
118
+ if (location.Log() && trace_flag_ != nullptr && trace_flag_->enabled()) {
119
+ const RefCount::Value old_refs = get();
120
+ gpr_log(GPR_INFO, "%s:%p %s:%d ref %" PRIdPTR " -> %" PRIdPTR " %s",
121
+ trace_flag_->name(), this, location.file(), location.line(),
122
+ old_refs, old_refs + 1, reason);
123
+ }
124
+ #endif
125
+ RefNonZero();
126
+ }
90
127
 
91
128
  // Decrements the ref-count and returns true if the ref-count reaches 0.
92
129
  bool Unref() {
93
- const Value prior = value_.fetch_sub(1, std::memory_order_acq_rel);
130
+ const Value prior =
131
+ GPR_ATM_INC_ADD_THEN(value_.fetch_sub(1, std::memory_order_acq_rel));
94
132
  GPR_DEBUG_ASSERT(prior > 0);
95
133
  return prior == 1;
96
134
  }
135
+ bool Unref(const DebugLocation& location, const char* reason) {
136
+ #ifndef NDEBUG
137
+ if (location.Log() && trace_flag_ != nullptr && trace_flag_->enabled()) {
138
+ const RefCount::Value old_refs = get();
139
+ gpr_log(GPR_INFO, "%s:%p %s:%d unref %" PRIdPTR " -> %" PRIdPTR " %s",
140
+ trace_flag_->name(), this, location.file(), location.line(),
141
+ old_refs, old_refs - 1, reason);
142
+ }
143
+ #endif
144
+ return Unref();
145
+ }
97
146
 
147
+ private:
98
148
  Value get() const { return value_.load(std::memory_order_relaxed); }
99
149
 
100
- private:
150
+ #ifndef NDEBUG
151
+ TraceFlag* trace_flag_;
152
+ #endif
101
153
  std::atomic<Value> value_;
102
154
  };
103
155
 
@@ -129,54 +181,6 @@ class RefCount {
129
181
  //
130
182
  template <typename Child, typename Impl = PolymorphicRefCount>
131
183
  class RefCounted : public Impl {
132
- public:
133
- RefCountedPtr<Child> Ref() GRPC_MUST_USE_RESULT {
134
- IncrementRefCount();
135
- return RefCountedPtr<Child>(static_cast<Child*>(this));
136
- }
137
-
138
- // TODO(roth): Once all of our code is converted to C++ and can use
139
- // RefCountedPtr<> instead of manual ref-counting, make this method
140
- // private, since it will only be used by RefCountedPtr<>, which is a
141
- // friend of this class.
142
- void Unref() {
143
- if (refs_.Unref()) {
144
- Delete(static_cast<Child*>(this));
145
- }
146
- }
147
-
148
- // Not copyable nor movable.
149
- RefCounted(const RefCounted&) = delete;
150
- RefCounted& operator=(const RefCounted&) = delete;
151
-
152
- GRPC_ABSTRACT_BASE_CLASS
153
-
154
- protected:
155
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
156
-
157
- RefCounted() = default;
158
-
159
- // Note: Depending on the Impl used, this dtor can be implicitly virtual.
160
- ~RefCounted() = default;
161
-
162
- private:
163
- // Allow RefCountedPtr<> to access IncrementRefCount().
164
- template <typename T>
165
- friend class RefCountedPtr;
166
-
167
- void IncrementRefCount() { refs_.Ref(); }
168
-
169
- RefCount refs_;
170
- };
171
-
172
- // An alternative version of the RefCounted base class that
173
- // supports tracing. This is intended to be used in cases where the
174
- // object will be handled both by idiomatic C++ code using smart
175
- // pointers and legacy code that is manually calling Ref() and Unref().
176
- // Once all of our code is converted to idiomatic C++, we may be able to
177
- // eliminate this class.
178
- template <typename Child, typename Impl = PolymorphicRefCount>
179
- class RefCountedWithTracing : public Impl {
180
184
  public:
181
185
  RefCountedPtr<Child> Ref() GRPC_MUST_USE_RESULT {
182
186
  IncrementRefCount();
@@ -185,58 +189,43 @@ class RefCountedWithTracing : public Impl {
185
189
 
186
190
  RefCountedPtr<Child> Ref(const DebugLocation& location,
187
191
  const char* reason) GRPC_MUST_USE_RESULT {
188
- if (location.Log() && trace_flag_ != nullptr && trace_flag_->enabled()) {
189
- const RefCount::Value old_refs = refs_.get();
190
- gpr_log(GPR_INFO, "%s:%p %s:%d ref %" PRIdPTR " -> %" PRIdPTR " %s",
191
- trace_flag_->name(), this, location.file(), location.line(),
192
- old_refs, old_refs + 1, reason);
193
- }
194
- return Ref();
192
+ IncrementRefCount(location, reason);
193
+ return RefCountedPtr<Child>(static_cast<Child*>(this));
195
194
  }
196
195
 
197
196
  // TODO(roth): Once all of our code is converted to C++ and can use
198
- // RefCountedPtr<> instead of manual ref-counting, make the Unref() methods
199
- // private, since they will only be used by RefCountedPtr<>, which is a
197
+ // RefCountedPtr<> instead of manual ref-counting, make this method
198
+ // private, since it will only be used by RefCountedPtr<>, which is a
200
199
  // friend of this class.
201
-
202
200
  void Unref() {
203
201
  if (refs_.Unref()) {
204
202
  Delete(static_cast<Child*>(this));
205
203
  }
206
204
  }
207
-
208
205
  void Unref(const DebugLocation& location, const char* reason) {
209
- if (location.Log() && trace_flag_ != nullptr && trace_flag_->enabled()) {
210
- const RefCount::Value old_refs = refs_.get();
211
- gpr_log(GPR_INFO, "%s:%p %s:%d unref %" PRIdPTR " -> %" PRIdPTR " %s",
212
- trace_flag_->name(), this, location.file(), location.line(),
213
- old_refs, old_refs - 1, reason);
206
+ if (refs_.Unref(location, reason)) {
207
+ Delete(static_cast<Child*>(this));
214
208
  }
215
- Unref();
216
209
  }
217
210
 
218
211
  // Not copyable nor movable.
219
- RefCountedWithTracing(const RefCountedWithTracing&) = delete;
220
- RefCountedWithTracing& operator=(const RefCountedWithTracing&) = delete;
212
+ RefCounted(const RefCounted&) = delete;
213
+ RefCounted& operator=(const RefCounted&) = delete;
221
214
 
222
215
  GRPC_ABSTRACT_BASE_CLASS
223
216
 
224
217
  protected:
225
218
  GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
226
219
 
227
- RefCountedWithTracing()
228
- : RefCountedWithTracing(static_cast<TraceFlag*>(nullptr)) {}
229
-
230
- explicit RefCountedWithTracing(TraceFlag* trace_flag)
231
- : trace_flag_(trace_flag) {}
232
-
233
- #ifdef NDEBUG
234
- explicit RefCountedWithTracing(DebugOnlyTraceFlag* trace_flag)
235
- : RefCountedWithTracing() {}
236
- #endif
220
+ // TraceFlagT is defined to accept both DebugOnlyTraceFlag and TraceFlag.
221
+ // Note: RefCount tracing is only enabled on debug builds, even when a
222
+ // TraceFlag is used.
223
+ template <typename TraceFlagT = TraceFlag>
224
+ explicit RefCounted(TraceFlagT* trace_flag = nullptr)
225
+ : refs_(1, trace_flag) {}
237
226
 
238
227
  // Note: Depending on the Impl used, this dtor can be implicitly virtual.
239
- ~RefCountedWithTracing() = default;
228
+ ~RefCounted() = default;
240
229
 
241
230
  private:
242
231
  // Allow RefCountedPtr<> to access IncrementRefCount().
@@ -244,8 +233,10 @@ class RefCountedWithTracing : public Impl {
244
233
  friend class RefCountedPtr;
245
234
 
246
235
  void IncrementRefCount() { refs_.Ref(); }
236
+ void IncrementRefCount(const DebugLocation& location, const char* reason) {
237
+ refs_.Ref(location, reason);
238
+ }
247
239
 
248
- TraceFlag* trace_flag_ = nullptr;
249
240
  RefCount refs_;
250
241
  };
251
242
 
@@ -24,6 +24,7 @@
24
24
  #include <type_traits>
25
25
  #include <utility>
26
26
 
27
+ #include "src/core/lib/gprpp/debug_location.h"
27
28
  #include "src/core/lib/gprpp/memory.h"
28
29
 
29
30
  namespace grpc_core {
@@ -49,21 +50,19 @@ class RefCountedPtr {
49
50
  }
50
51
  template <typename Y>
51
52
  RefCountedPtr(RefCountedPtr<Y>&& other) {
52
- value_ = other.value_;
53
+ value_ = static_cast<T*>(other.value_);
53
54
  other.value_ = nullptr;
54
55
  }
55
56
 
56
57
  // Move assignment.
57
58
  RefCountedPtr& operator=(RefCountedPtr&& other) {
58
- if (value_ != nullptr) value_->Unref();
59
- value_ = other.value_;
59
+ reset(other.value_);
60
60
  other.value_ = nullptr;
61
61
  return *this;
62
62
  }
63
63
  template <typename Y>
64
64
  RefCountedPtr& operator=(RefCountedPtr<Y>&& other) {
65
- if (value_ != nullptr) value_->Unref();
66
- value_ = other.value_;
65
+ reset(other.value_);
67
66
  other.value_ = nullptr;
68
67
  return *this;
69
68
  }
@@ -78,7 +77,7 @@ class RefCountedPtr {
78
77
  static_assert(std::has_virtual_destructor<T>::value,
79
78
  "T does not have a virtual dtor");
80
79
  if (other.value_ != nullptr) other.value_->IncrementRefCount();
81
- value_ = other.value_;
80
+ value_ = static_cast<T*>(other.value_);
82
81
  }
83
82
 
84
83
  // Copy assignment.
@@ -86,8 +85,7 @@ class RefCountedPtr {
86
85
  // Note: Order of reffing and unreffing is important here in case value_
87
86
  // and other.value_ are the same object.
88
87
  if (other.value_ != nullptr) other.value_->IncrementRefCount();
89
- if (value_ != nullptr) value_->Unref();
90
- value_ = other.value_;
88
+ reset(other.value_);
91
89
  return *this;
92
90
  }
93
91
  template <typename Y>
@@ -97,8 +95,7 @@ class RefCountedPtr {
97
95
  // Note: Order of reffing and unreffing is important here in case value_
98
96
  // and other.value_ are the same object.
99
97
  if (other.value_ != nullptr) other.value_->IncrementRefCount();
100
- if (value_ != nullptr) value_->Unref();
101
- value_ = other.value_;
98
+ reset(other.value_);
102
99
  return *this;
103
100
  }
104
101
 
@@ -107,21 +104,29 @@ class RefCountedPtr {
107
104
  }
108
105
 
109
106
  // If value is non-null, we take ownership of a ref to it.
110
- void reset(T* value) {
107
+ void reset(T* value = nullptr) {
111
108
  if (value_ != nullptr) value_->Unref();
112
109
  value_ = value;
113
110
  }
111
+ void reset(const DebugLocation& location, const char* reason,
112
+ T* value = nullptr) {
113
+ if (value_ != nullptr) value_->Unref(location, reason);
114
+ value_ = value;
115
+ }
114
116
  template <typename Y>
115
- void reset(Y* value) {
117
+ void reset(Y* value = nullptr) {
116
118
  static_assert(std::has_virtual_destructor<T>::value,
117
119
  "T does not have a virtual dtor");
118
120
  if (value_ != nullptr) value_->Unref();
119
- value_ = value;
121
+ value_ = static_cast<T*>(value);
120
122
  }
121
-
122
- void reset() {
123
- if (value_ != nullptr) value_->Unref();
124
- value_ = nullptr;
123
+ template <typename Y>
124
+ void reset(const DebugLocation& location, const char* reason,
125
+ Y* value = nullptr) {
126
+ static_assert(std::has_virtual_destructor<T>::value,
127
+ "T does not have a virtual dtor");
128
+ if (value_ != nullptr) value_->Unref(location, reason);
129
+ value_ = static_cast<T*>(value);
125
130
  }
126
131
 
127
132
  // TODO(roth): This method exists solely as a transition mechanism to allow
@@ -29,119 +29,125 @@
29
29
  #include "src/core/lib/channel/channel_args.h"
30
30
  #include "src/core/lib/channel/handshaker_registry.h"
31
31
  #include "src/core/lib/gpr/string.h"
32
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
32
33
  #include "src/core/lib/iomgr/pollset.h"
34
+ #include "src/core/lib/security/credentials/credentials.h"
33
35
  #include "src/core/lib/security/security_connector/ssl_utils.h"
34
36
  #include "src/core/lib/security/transport/security_handshaker.h"
35
37
  #include "src/core/lib/slice/slice_internal.h"
36
38
  #include "src/core/tsi/ssl_transport_security.h"
37
39
 
38
- typedef struct {
39
- grpc_channel_security_connector base;
40
- tsi_ssl_client_handshaker_factory* handshaker_factory;
41
- char* secure_peer_name;
42
- } grpc_httpcli_ssl_channel_security_connector;
43
-
44
- static void httpcli_ssl_destroy(grpc_security_connector* sc) {
45
- grpc_httpcli_ssl_channel_security_connector* c =
46
- reinterpret_cast<grpc_httpcli_ssl_channel_security_connector*>(sc);
47
- if (c->handshaker_factory != nullptr) {
48
- tsi_ssl_client_handshaker_factory_unref(c->handshaker_factory);
49
- c->handshaker_factory = nullptr;
40
+ class grpc_httpcli_ssl_channel_security_connector final
41
+ : public grpc_channel_security_connector {
42
+ public:
43
+ explicit grpc_httpcli_ssl_channel_security_connector(char* secure_peer_name)
44
+ : grpc_channel_security_connector(
45
+ /*url_scheme=*/nullptr,
46
+ /*channel_creds=*/nullptr,
47
+ /*request_metadata_creds=*/nullptr),
48
+ secure_peer_name_(secure_peer_name) {}
49
+
50
+ ~grpc_httpcli_ssl_channel_security_connector() override {
51
+ if (handshaker_factory_ != nullptr) {
52
+ tsi_ssl_client_handshaker_factory_unref(handshaker_factory_);
53
+ }
54
+ if (secure_peer_name_ != nullptr) {
55
+ gpr_free(secure_peer_name_);
56
+ }
57
+ }
58
+
59
+ tsi_result InitHandshakerFactory(const char* pem_root_certs,
60
+ const tsi_ssl_root_certs_store* root_store) {
61
+ tsi_ssl_client_handshaker_options options;
62
+ memset(&options, 0, sizeof(options));
63
+ options.pem_root_certs = pem_root_certs;
64
+ options.root_store = root_store;
65
+ return tsi_create_ssl_client_handshaker_factory_with_options(
66
+ &options, &handshaker_factory_);
50
67
  }
51
- if (c->secure_peer_name != nullptr) gpr_free(c->secure_peer_name);
52
- gpr_free(sc);
53
- }
54
68
 
55
- static void httpcli_ssl_add_handshakers(grpc_channel_security_connector* sc,
56
- grpc_pollset_set* interested_parties,
57
- grpc_handshake_manager* handshake_mgr) {
58
- grpc_httpcli_ssl_channel_security_connector* c =
59
- reinterpret_cast<grpc_httpcli_ssl_channel_security_connector*>(sc);
60
- tsi_handshaker* handshaker = nullptr;
61
- if (c->handshaker_factory != nullptr) {
62
- tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker(
63
- c->handshaker_factory, c->secure_peer_name, &handshaker);
64
- if (result != TSI_OK) {
65
- gpr_log(GPR_ERROR, "Handshaker creation failed with error %s.",
66
- tsi_result_to_string(result));
69
+ void add_handshakers(grpc_pollset_set* interested_parties,
70
+ grpc_handshake_manager* handshake_mgr) override {
71
+ tsi_handshaker* handshaker = nullptr;
72
+ if (handshaker_factory_ != nullptr) {
73
+ tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker(
74
+ handshaker_factory_, secure_peer_name_, &handshaker);
75
+ if (result != TSI_OK) {
76
+ gpr_log(GPR_ERROR, "Handshaker creation failed with error %s.",
77
+ tsi_result_to_string(result));
78
+ }
67
79
  }
80
+ grpc_handshake_manager_add(
81
+ handshake_mgr, grpc_security_handshaker_create(handshaker, this));
68
82
  }
69
- grpc_handshake_manager_add(
70
- handshake_mgr, grpc_security_handshaker_create(handshaker, &sc->base));
71
- }
72
83
 
73
- static void httpcli_ssl_check_peer(grpc_security_connector* sc, tsi_peer peer,
74
- grpc_auth_context** auth_context,
75
- grpc_closure* on_peer_checked) {
76
- grpc_httpcli_ssl_channel_security_connector* c =
77
- reinterpret_cast<grpc_httpcli_ssl_channel_security_connector*>(sc);
78
- grpc_error* error = GRPC_ERROR_NONE;
79
-
80
- /* Check the peer name. */
81
- if (c->secure_peer_name != nullptr &&
82
- !tsi_ssl_peer_matches_name(&peer, c->secure_peer_name)) {
83
- char* msg;
84
- gpr_asprintf(&msg, "Peer name %s is not in peer certificate",
85
- c->secure_peer_name);
86
- error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
87
- gpr_free(msg);
84
+ tsi_ssl_client_handshaker_factory* handshaker_factory() const {
85
+ return handshaker_factory_;
88
86
  }
89
- GRPC_CLOSURE_SCHED(on_peer_checked, error);
90
- tsi_peer_destruct(&peer);
91
- }
92
87
 
93
- static int httpcli_ssl_cmp(grpc_security_connector* sc1,
94
- grpc_security_connector* sc2) {
95
- grpc_httpcli_ssl_channel_security_connector* c1 =
96
- reinterpret_cast<grpc_httpcli_ssl_channel_security_connector*>(sc1);
97
- grpc_httpcli_ssl_channel_security_connector* c2 =
98
- reinterpret_cast<grpc_httpcli_ssl_channel_security_connector*>(sc2);
99
- return strcmp(c1->secure_peer_name, c2->secure_peer_name);
100
- }
88
+ void check_peer(tsi_peer peer, grpc_endpoint* ep,
89
+ grpc_core::RefCountedPtr<grpc_auth_context>* /*auth_context*/,
90
+ grpc_closure* on_peer_checked) override {
91
+ grpc_error* error = GRPC_ERROR_NONE;
92
+
93
+ /* Check the peer name. */
94
+ if (secure_peer_name_ != nullptr &&
95
+ !tsi_ssl_peer_matches_name(&peer, secure_peer_name_)) {
96
+ char* msg;
97
+ gpr_asprintf(&msg, "Peer name %s is not in peer certificate",
98
+ secure_peer_name_);
99
+ error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
100
+ gpr_free(msg);
101
+ }
102
+ GRPC_CLOSURE_SCHED(on_peer_checked, error);
103
+ tsi_peer_destruct(&peer);
104
+ }
101
105
 
102
- static grpc_security_connector_vtable httpcli_ssl_vtable = {
103
- httpcli_ssl_destroy, httpcli_ssl_check_peer, httpcli_ssl_cmp};
106
+ int cmp(const grpc_security_connector* other_sc) const override {
107
+ auto* other =
108
+ reinterpret_cast<const grpc_httpcli_ssl_channel_security_connector*>(
109
+ other_sc);
110
+ return strcmp(secure_peer_name_, other->secure_peer_name_);
111
+ }
104
112
 
105
- static grpc_security_status httpcli_ssl_channel_security_connector_create(
106
- const char* pem_root_certs, const tsi_ssl_root_certs_store* root_store,
107
- const char* secure_peer_name, grpc_channel_security_connector** sc) {
108
- tsi_result result = TSI_OK;
109
- grpc_httpcli_ssl_channel_security_connector* c;
113
+ bool check_call_host(const char* host, grpc_auth_context* auth_context,
114
+ grpc_closure* on_call_host_checked,
115
+ grpc_error** error) override {
116
+ *error = GRPC_ERROR_NONE;
117
+ return true;
118
+ }
110
119
 
111
- if (secure_peer_name != nullptr && pem_root_certs == nullptr) {
112
- gpr_log(GPR_ERROR,
113
- "Cannot assert a secure peer name without a trust root.");
114
- return GRPC_SECURITY_ERROR;
120
+ void cancel_check_call_host(grpc_closure* on_call_host_checked,
121
+ grpc_error* error) override {
122
+ GRPC_ERROR_UNREF(error);
115
123
  }
116
124
 
117
- c = static_cast<grpc_httpcli_ssl_channel_security_connector*>(
118
- gpr_zalloc(sizeof(grpc_httpcli_ssl_channel_security_connector)));
125
+ const char* secure_peer_name() const { return secure_peer_name_; }
119
126
 
120
- gpr_ref_init(&c->base.base.refcount, 1);
121
- c->base.base.vtable = &httpcli_ssl_vtable;
122
- if (secure_peer_name != nullptr) {
123
- c->secure_peer_name = gpr_strdup(secure_peer_name);
127
+ private:
128
+ tsi_ssl_client_handshaker_factory* handshaker_factory_ = nullptr;
129
+ char* secure_peer_name_;
130
+ };
131
+
132
+ static grpc_core::RefCountedPtr<grpc_channel_security_connector>
133
+ httpcli_ssl_channel_security_connector_create(
134
+ const char* pem_root_certs, const tsi_ssl_root_certs_store* root_store,
135
+ const char* secure_peer_name) {
136
+ if (secure_peer_name != nullptr && pem_root_certs == nullptr) {
137
+ gpr_log(GPR_ERROR,
138
+ "Cannot assert a secure peer name without a trust root.");
139
+ return nullptr;
124
140
  }
125
- tsi_ssl_client_handshaker_options options;
126
- memset(&options, 0, sizeof(options));
127
- options.pem_root_certs = pem_root_certs;
128
- options.root_store = root_store;
129
- result = tsi_create_ssl_client_handshaker_factory_with_options(
130
- &options, &c->handshaker_factory);
141
+ grpc_core::RefCountedPtr<grpc_httpcli_ssl_channel_security_connector> c =
142
+ grpc_core::MakeRefCounted<grpc_httpcli_ssl_channel_security_connector>(
143
+ secure_peer_name == nullptr ? nullptr : gpr_strdup(secure_peer_name));
144
+ tsi_result result = c->InitHandshakerFactory(pem_root_certs, root_store);
131
145
  if (result != TSI_OK) {
132
146
  gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
133
147
  tsi_result_to_string(result));
134
- httpcli_ssl_destroy(&c->base.base);
135
- *sc = nullptr;
136
- return GRPC_SECURITY_ERROR;
148
+ return nullptr;
137
149
  }
138
- // We don't actually need a channel credentials object in this case,
139
- // but we set it to a non-nullptr address so that we don't trigger
140
- // assertions in grpc_channel_security_connector_cmp().
141
- c->base.channel_creds = (grpc_channel_credentials*)1;
142
- c->base.add_handshakers = httpcli_ssl_add_handshakers;
143
- *sc = &c->base;
144
- return GRPC_SECURITY_OK;
150
+ return c;
145
151
  }
146
152
 
147
153
  /* handshaker */
@@ -186,10 +192,11 @@ static void ssl_handshake(void* arg, grpc_endpoint* tcp, const char* host,
186
192
  }
187
193
  c->func = on_done;
188
194
  c->arg = arg;
189
- grpc_channel_security_connector* sc = nullptr;
190
- GPR_ASSERT(httpcli_ssl_channel_security_connector_create(
191
- pem_root_certs, root_store, host, &sc) == GRPC_SECURITY_OK);
192
- grpc_arg channel_arg = grpc_security_connector_to_arg(&sc->base);
195
+ grpc_core::RefCountedPtr<grpc_channel_security_connector> sc =
196
+ httpcli_ssl_channel_security_connector_create(pem_root_certs, root_store,
197
+ host);
198
+ GPR_ASSERT(sc != nullptr);
199
+ grpc_arg channel_arg = grpc_security_connector_to_arg(sc.get());
193
200
  grpc_channel_args args = {1, &channel_arg};
194
201
  c->handshake_mgr = grpc_handshake_manager_create();
195
202
  grpc_handshakers_add(HANDSHAKER_CLIENT, &args,
@@ -197,7 +204,7 @@ static void ssl_handshake(void* arg, grpc_endpoint* tcp, const char* host,
197
204
  grpc_handshake_manager_do_handshake(
198
205
  c->handshake_mgr, tcp, nullptr /* channel_args */, deadline,
199
206
  nullptr /* acceptor */, on_handshake_done, c /* user_data */);
200
- GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "httpcli");
207
+ sc.reset(DEBUG_LOCATION, "httpcli");
201
208
  }
202
209
 
203
210
  const grpc_httpcli_handshaker grpc_httpcli_ssl = {"https", ssl_handshake};