grpc 1.1.2 → 1.2.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 (255) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1257 -404
  3. data/etc/roots.pem +189 -102
  4. data/include/grpc/census.h +7 -7
  5. data/include/grpc/compression.h +4 -4
  6. data/include/grpc/grpc.h +13 -7
  7. data/include/grpc/impl/codegen/atm_gcc_atomic.h +26 -9
  8. data/include/grpc/impl/codegen/grpc_types.h +39 -30
  9. data/include/grpc/impl/codegen/slice.h +24 -6
  10. data/include/grpc/impl/codegen/sync.h +8 -0
  11. data/include/grpc/load_reporting.h +63 -0
  12. data/include/grpc/slice.h +37 -1
  13. data/include/grpc/slice_buffer.h +7 -0
  14. data/include/grpc/support/alloc.h +3 -0
  15. data/include/grpc/support/useful.h +3 -0
  16. data/src/core/ext/census/gen/census.pb.h +1 -1
  17. data/src/core/ext/census/gen/trace_context.pb.c +9 -36
  18. data/src/core/ext/census/gen/trace_context.pb.h +20 -26
  19. data/src/core/ext/census/grpc_filter.c +3 -5
  20. data/src/core/ext/census/trace_context.c +1 -1
  21. data/src/core/ext/census/trace_context.h +3 -0
  22. data/src/core/ext/census/trace_label.h +61 -0
  23. data/src/core/ext/census/trace_propagation.h +63 -0
  24. data/src/core/ext/census/trace_status.h +45 -0
  25. data/src/core/ext/census/trace_string.h +50 -0
  26. data/src/core/ext/census/tracing.c +31 -11
  27. data/src/core/ext/census/tracing.h +124 -0
  28. data/src/core/ext/client_channel/client_channel.c +456 -368
  29. data/src/core/ext/client_channel/client_channel.h +4 -0
  30. data/src/core/ext/client_channel/client_channel_plugin.c +6 -1
  31. data/src/core/ext/client_channel/connector.c +3 -3
  32. data/src/core/ext/client_channel/connector.h +4 -3
  33. data/src/core/ext/client_channel/http_connect_handshaker.c +62 -72
  34. data/src/core/ext/client_channel/http_connect_handshaker.h +7 -10
  35. data/src/core/ext/client_channel/http_proxy.c +125 -0
  36. data/src/core/ext/client_channel/http_proxy.h +39 -0
  37. data/src/core/ext/client_channel/lb_policy.c +56 -35
  38. data/src/core/ext/client_channel/lb_policy.h +46 -39
  39. data/src/core/ext/client_channel/lb_policy_factory.h +1 -0
  40. data/src/core/ext/client_channel/parse_address.c +32 -6
  41. data/src/core/ext/client_channel/proxy_mapper.c +63 -0
  42. data/src/core/ext/client_channel/proxy_mapper.h +89 -0
  43. data/src/core/ext/client_channel/proxy_mapper_registry.c +133 -0
  44. data/src/core/ext/client_channel/proxy_mapper_registry.h +59 -0
  45. data/src/core/ext/client_channel/resolver.c +16 -9
  46. data/src/core/ext/client_channel/resolver.h +23 -12
  47. data/src/core/ext/client_channel/resolver_factory.h +1 -0
  48. data/src/core/ext/client_channel/resolver_registry.c +15 -11
  49. data/src/core/ext/client_channel/resolver_registry.h +5 -3
  50. data/src/core/ext/client_channel/subchannel.c +44 -27
  51. data/src/core/ext/client_channel/subchannel.h +6 -2
  52. data/src/core/ext/client_channel/uri_parser.c +26 -14
  53. data/src/core/ext/client_channel/uri_parser.h +3 -1
  54. data/src/core/ext/lb_policy/grpclb/grpclb.c +220 -209
  55. data/src/core/ext/lb_policy/grpclb/grpclb_channel.h +56 -0
  56. data/src/core/ext/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
  57. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +3 -6
  58. data/src/core/ext/lb_policy/pick_first/pick_first.c +71 -116
  59. data/src/core/ext/lb_policy/round_robin/round_robin.c +52 -67
  60. data/src/core/ext/load_reporting/load_reporting.c +20 -0
  61. data/src/core/ext/load_reporting/load_reporting.h +1 -16
  62. data/src/core/ext/load_reporting/load_reporting_filter.c +28 -54
  63. data/src/core/ext/resolver/dns/native/dns_resolver.c +31 -45
  64. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +20 -29
  65. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +11 -8
  66. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +11 -2
  67. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +143 -46
  68. data/src/core/ext/transport/chttp2/server/chttp2_server.c +12 -50
  69. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +1 -1
  70. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +1 -1
  71. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +7 -7
  72. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +1 -2
  73. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +1 -2
  74. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
  75. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +606 -374
  76. data/src/core/ext/transport/chttp2/transport/frame_ping.c +17 -5
  77. data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -2
  78. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +9 -13
  79. data/src/core/ext/transport/chttp2/transport/frame_settings.c +12 -11
  80. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -1
  81. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +5 -6
  82. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +100 -53
  83. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -2
  84. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +126 -70
  85. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +13 -7
  86. data/src/core/ext/transport/chttp2/transport/hpack_table.c +22 -19
  87. data/src/core/ext/transport/chttp2/transport/hpack_table.h +6 -6
  88. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +23 -11
  89. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -2
  90. data/src/core/ext/transport/chttp2/transport/internal.h +169 -42
  91. data/src/core/ext/transport/chttp2/transport/parsing.c +98 -41
  92. data/src/core/ext/transport/chttp2/transport/stream_lists.c +29 -14
  93. data/src/core/ext/transport/chttp2/transport/writing.c +137 -15
  94. data/src/core/lib/channel/channel_stack.c +14 -44
  95. data/src/core/lib/channel/channel_stack.h +10 -17
  96. data/src/core/lib/channel/channel_stack_builder.c +2 -3
  97. data/src/core/lib/channel/compress_filter.c +54 -46
  98. data/src/core/lib/channel/connected_channel.c +4 -4
  99. data/src/core/lib/channel/connected_channel.h +5 -0
  100. data/src/core/lib/channel/context.h +3 -0
  101. data/src/core/lib/channel/deadline_filter.c +61 -61
  102. data/src/core/lib/channel/deadline_filter.h +8 -5
  103. data/src/core/lib/channel/handshaker.c +47 -7
  104. data/src/core/lib/channel/handshaker.h +21 -3
  105. data/src/core/lib/channel/http_client_filter.c +149 -99
  106. data/src/core/lib/channel/http_server_filter.c +163 -147
  107. data/src/core/lib/channel/message_size_filter.c +15 -10
  108. data/src/core/lib/compression/algorithm_metadata.h +4 -4
  109. data/src/core/lib/compression/compression.c +17 -23
  110. data/src/core/lib/http/httpcli.c +3 -2
  111. data/src/core/lib/http/httpcli.h +2 -1
  112. data/src/core/lib/http/httpcli_security_connector.c +2 -3
  113. data/src/core/lib/http/parser.c +2 -2
  114. data/src/core/lib/iomgr/closure.c +6 -3
  115. data/src/core/lib/iomgr/closure.h +4 -2
  116. data/src/core/lib/iomgr/combiner.c +35 -5
  117. data/src/core/lib/iomgr/combiner.h +21 -2
  118. data/src/core/lib/iomgr/endpoint.c +3 -2
  119. data/src/core/lib/iomgr/endpoint.h +3 -2
  120. data/src/core/lib/iomgr/error.c +60 -94
  121. data/src/core/lib/iomgr/error.h +7 -10
  122. data/src/core/lib/iomgr/error_internal.h +54 -0
  123. data/src/core/lib/iomgr/ev_epoll_linux.c +253 -109
  124. data/src/core/lib/iomgr/ev_poll_posix.c +61 -29
  125. data/src/core/lib/iomgr/ev_posix.c +7 -8
  126. data/src/core/lib/iomgr/ev_posix.h +4 -4
  127. data/src/core/lib/iomgr/exec_ctx.c +11 -6
  128. data/src/core/lib/iomgr/exec_ctx.h +11 -14
  129. data/src/core/lib/iomgr/executor.c +2 -2
  130. data/src/core/lib/iomgr/load_file.c +1 -1
  131. data/src/core/lib/iomgr/network_status_tracker.c +5 -81
  132. data/src/core/lib/iomgr/pollset.h +1 -3
  133. data/src/core/lib/iomgr/pollset_set.h +2 -1
  134. data/src/core/lib/iomgr/pollset_set_uv.c +2 -1
  135. data/src/core/lib/iomgr/pollset_set_windows.c +2 -1
  136. data/src/core/lib/iomgr/pollset_uv.c +25 -11
  137. data/src/core/lib/iomgr/pollset_windows.c +0 -11
  138. data/src/core/lib/iomgr/resolve_address_uv.c +50 -2
  139. data/src/core/lib/iomgr/resource_quota.c +41 -11
  140. data/src/core/lib/iomgr/resource_quota.h +6 -0
  141. data/src/core/lib/iomgr/sockaddr_utils.c +33 -17
  142. data/src/core/lib/iomgr/sockaddr_utils.h +4 -0
  143. data/src/core/lib/iomgr/tcp_client_posix.c +2 -3
  144. data/src/core/lib/iomgr/tcp_client_uv.c +1 -3
  145. data/src/core/lib/iomgr/tcp_client_windows.c +21 -6
  146. data/src/core/lib/iomgr/tcp_posix.c +4 -5
  147. data/src/core/lib/iomgr/tcp_server_posix.c +269 -94
  148. data/src/core/lib/iomgr/tcp_server_windows.c +1 -1
  149. data/src/core/lib/iomgr/tcp_uv.c +11 -5
  150. data/src/core/lib/iomgr/tcp_windows.c +20 -7
  151. data/src/core/lib/iomgr/timer_generic.c +15 -22
  152. data/src/core/lib/iomgr/timer_generic.h +1 -1
  153. data/src/core/lib/iomgr/timer_uv.c +10 -6
  154. data/src/core/lib/iomgr/timer_uv.h +1 -1
  155. data/src/core/lib/iomgr/udp_server.c +45 -6
  156. data/src/core/lib/iomgr/udp_server.h +7 -1
  157. data/src/core/lib/iomgr/unix_sockets_posix.c +11 -1
  158. data/src/core/lib/json/json.c +1 -2
  159. data/src/core/lib/profiling/basic_timers.c +17 -3
  160. data/src/core/lib/security/context/security_context.c +3 -10
  161. data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -8
  162. data/src/core/lib/security/credentials/credentials.c +48 -2
  163. data/src/core/lib/security/credentials/credentials.h +13 -0
  164. data/src/core/lib/security/credentials/credentials_metadata.c +1 -2
  165. data/src/core/lib/security/credentials/fake/fake_credentials.c +6 -8
  166. data/src/core/lib/security/credentials/fake/fake_credentials.h +15 -0
  167. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +3 -3
  168. data/src/core/lib/security/credentials/iam/iam_credentials.c +1 -2
  169. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -2
  170. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +5 -8
  171. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  172. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +3 -5
  173. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +15 -13
  174. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +2 -4
  175. data/src/core/lib/security/transport/client_auth_filter.c +72 -47
  176. data/src/core/lib/security/transport/lb_targets_info.c +70 -0
  177. data/src/core/lib/security/transport/lb_targets_info.h +47 -0
  178. data/src/core/lib/security/transport/secure_endpoint.c +3 -3
  179. data/src/core/lib/security/transport/security_connector.c +125 -28
  180. data/src/core/lib/security/transport/security_connector.h +4 -3
  181. data/src/core/lib/security/transport/security_handshaker.c +13 -9
  182. data/src/core/lib/security/transport/server_auth_filter.c +31 -40
  183. data/src/core/lib/security/util/b64.c +1 -1
  184. data/src/core/lib/slice/slice.c +110 -20
  185. data/src/core/lib/slice/slice_buffer.c +92 -39
  186. data/src/core/lib/{transport/mdstr_hash_table.c → slice/slice_hash_table.c} +40 -33
  187. data/src/core/lib/{transport/mdstr_hash_table.h → slice/slice_hash_table.h} +21 -21
  188. data/src/core/lib/slice/slice_intern.c +346 -0
  189. data/src/core/lib/slice/slice_internal.h +15 -0
  190. data/src/core/lib/slice/slice_string_helpers.c +5 -0
  191. data/src/core/lib/slice/slice_string_helpers.h +5 -0
  192. data/src/core/lib/support/alloc.c +26 -1
  193. data/src/core/lib/support/cmdline.c +2 -4
  194. data/src/core/lib/support/cpu_posix.c +2 -7
  195. data/src/core/lib/support/histogram.c +1 -2
  196. data/src/core/lib/support/log_posix.c +8 -4
  197. data/src/core/lib/support/spinlock.h +52 -0
  198. data/src/core/lib/support/subprocess_posix.c +1 -2
  199. data/src/core/lib/support/sync.c +7 -1
  200. data/src/core/lib/support/sync_posix.c +9 -0
  201. data/src/core/lib/support/time_windows.c +7 -1
  202. data/src/core/lib/surface/call.c +647 -629
  203. data/src/core/lib/surface/call.h +4 -1
  204. data/src/core/lib/surface/call_details.c +8 -2
  205. data/src/core/lib/surface/call_log_batch.c +17 -6
  206. data/src/core/lib/surface/channel.c +49 -59
  207. data/src/core/lib/surface/channel.h +5 -6
  208. data/src/core/lib/surface/completion_queue.c +16 -45
  209. data/src/core/lib/surface/completion_queue.h +0 -3
  210. data/src/core/lib/surface/init.c +6 -2
  211. data/src/core/lib/surface/init_secure.c +1 -1
  212. data/src/core/lib/surface/lame_client.c +14 -4
  213. data/src/core/lib/surface/server.c +79 -82
  214. data/src/core/lib/surface/validate_metadata.c +46 -15
  215. data/src/core/lib/surface/validate_metadata.h +43 -0
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.c +104 -0
  218. data/src/core/lib/transport/bdp_estimator.h +76 -0
  219. data/src/core/lib/transport/connectivity_state.c +33 -13
  220. data/src/core/lib/transport/connectivity_state.h +15 -5
  221. data/src/core/lib/transport/error_utils.c +124 -0
  222. data/src/core/lib/transport/error_utils.h +56 -0
  223. data/src/core/{ext/transport/chttp2 → lib}/transport/http2_errors.h +18 -18
  224. data/src/core/lib/transport/metadata.c +259 -503
  225. data/src/core/lib/transport/metadata.h +69 -68
  226. data/src/core/lib/transport/metadata_batch.c +183 -63
  227. data/src/core/lib/transport/metadata_batch.h +50 -26
  228. data/src/core/lib/transport/pid_controller.c +28 -8
  229. data/src/core/lib/transport/pid_controller.h +15 -2
  230. data/src/core/lib/transport/service_config.c +21 -18
  231. data/src/core/lib/transport/service_config.h +5 -5
  232. data/src/core/lib/transport/static_metadata.c +753 -112
  233. data/src/core/lib/transport/static_metadata.h +403 -264
  234. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.c +18 -20
  235. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.h +9 -10
  236. data/src/core/lib/transport/timeout_encoding.c +11 -9
  237. data/src/core/lib/transport/timeout_encoding.h +3 -1
  238. data/src/core/lib/transport/transport.c +47 -87
  239. data/src/core/lib/transport/transport.h +20 -25
  240. data/src/core/lib/transport/transport_op_string.c +7 -19
  241. data/src/core/lib/tsi/fake_transport_security.c +2 -4
  242. data/src/core/lib/tsi/ssl_transport_security.c +7 -16
  243. data/src/core/lib/tsi/transport_security.c +2 -4
  244. data/src/ruby/ext/grpc/extconf.rb +4 -1
  245. data/src/ruby/ext/grpc/rb_byte_buffer.c +7 -0
  246. data/src/ruby/ext/grpc/rb_byte_buffer.h +3 -0
  247. data/src/ruby/ext/grpc/rb_call.c +47 -46
  248. data/src/ruby/ext/grpc/rb_channel.c +21 -6
  249. data/src/ruby/ext/grpc/rb_compression_options.c +9 -6
  250. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -2
  251. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +59 -8
  252. data/src/ruby/ext/grpc/rb_server.c +6 -4
  253. data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
  254. data/src/ruby/lib/grpc/version.rb +1 -1
  255. metadata +33 -9
@@ -43,10 +43,13 @@
43
43
  #include <grpc/support/string_util.h>
44
44
 
45
45
  #include "src/core/ext/transport/chttp2/alpn/alpn.h"
46
+ #include "src/core/lib/channel/channel_args.h"
46
47
  #include "src/core/lib/channel/handshaker.h"
47
48
  #include "src/core/lib/iomgr/load_file.h"
48
49
  #include "src/core/lib/security/context/security_context.h"
49
50
  #include "src/core/lib/security/credentials/credentials.h"
51
+ #include "src/core/lib/security/credentials/fake/fake_credentials.h"
52
+ #include "src/core/lib/security/transport/lb_targets_info.h"
50
53
  #include "src/core/lib/security/transport/secure_endpoint.h"
51
54
  #include "src/core/lib/security/transport/security_handshaker.h"
52
55
  #include "src/core/lib/support/env.h"
@@ -205,23 +208,23 @@ static const grpc_arg_pointer_vtable connector_pointer_vtable = {
205
208
  grpc_arg grpc_security_connector_to_arg(grpc_security_connector *sc) {
206
209
  grpc_arg result;
207
210
  result.type = GRPC_ARG_POINTER;
208
- result.key = GRPC_SECURITY_CONNECTOR_ARG;
211
+ result.key = GRPC_ARG_SECURITY_CONNECTOR;
209
212
  result.value.pointer.vtable = &connector_pointer_vtable;
210
213
  result.value.pointer.p = sc;
211
214
  return result;
212
215
  }
213
216
 
214
217
  grpc_security_connector *grpc_security_connector_from_arg(const grpc_arg *arg) {
215
- if (strcmp(arg->key, GRPC_SECURITY_CONNECTOR_ARG)) return NULL;
218
+ if (strcmp(arg->key, GRPC_ARG_SECURITY_CONNECTOR)) return NULL;
216
219
  if (arg->type != GRPC_ARG_POINTER) {
217
220
  gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type,
218
- GRPC_SECURITY_CONNECTOR_ARG);
221
+ GRPC_ARG_SECURITY_CONNECTOR);
219
222
  return NULL;
220
223
  }
221
224
  return arg->value.pointer.p;
222
225
  }
223
226
 
224
- grpc_security_connector *grpc_find_security_connector_in_args(
227
+ grpc_security_connector *grpc_security_connector_find_in_args(
225
228
  const grpc_channel_args *args) {
226
229
  size_t i;
227
230
  if (args == NULL) return NULL;
@@ -235,11 +238,21 @@ grpc_security_connector *grpc_find_security_connector_in_args(
235
238
 
236
239
  /* -- Fake implementation. -- */
237
240
 
241
+ typedef struct {
242
+ grpc_channel_security_connector base;
243
+ char *target;
244
+ char *expected_targets;
245
+ bool is_lb_channel;
246
+ } grpc_fake_channel_security_connector;
247
+
238
248
  static void fake_channel_destroy(grpc_exec_ctx *exec_ctx,
239
249
  grpc_security_connector *sc) {
240
- grpc_channel_security_connector *c = (grpc_channel_security_connector *)sc;
241
- grpc_call_credentials_unref(exec_ctx, c->request_metadata_creds);
242
- gpr_free(sc);
250
+ grpc_fake_channel_security_connector *c =
251
+ (grpc_fake_channel_security_connector *)sc;
252
+ grpc_call_credentials_unref(exec_ctx, c->base.request_metadata_creds);
253
+ gpr_free(c->target);
254
+ gpr_free(c->expected_targets);
255
+ gpr_free(c);
243
256
  }
244
257
 
245
258
  static void fake_server_destroy(grpc_exec_ctx *exec_ctx,
@@ -247,6 +260,68 @@ static void fake_server_destroy(grpc_exec_ctx *exec_ctx,
247
260
  gpr_free(sc);
248
261
  }
249
262
 
263
+ static bool fake_check_target(const char *target_type, const char *target,
264
+ const char *set_str) {
265
+ GPR_ASSERT(target_type != NULL);
266
+ GPR_ASSERT(target != NULL);
267
+ char **set = NULL;
268
+ size_t set_size = 0;
269
+ gpr_string_split(set_str, ",", &set, &set_size);
270
+ bool found = false;
271
+ for (size_t i = 0; i < set_size; ++i) {
272
+ if (set[i] != NULL && strcmp(target, set[i]) == 0) found = true;
273
+ }
274
+ for (size_t i = 0; i < set_size; ++i) {
275
+ gpr_free(set[i]);
276
+ }
277
+ gpr_free(set);
278
+ return found;
279
+ }
280
+
281
+ static void fake_secure_name_check(const char *target,
282
+ const char *expected_targets,
283
+ bool is_lb_channel) {
284
+ if (expected_targets == NULL) return;
285
+ char **lbs_and_backends = NULL;
286
+ size_t lbs_and_backends_size = 0;
287
+ bool success = false;
288
+ gpr_string_split(expected_targets, ";", &lbs_and_backends,
289
+ &lbs_and_backends_size);
290
+ if (lbs_and_backends_size > 2 || lbs_and_backends_size == 0) {
291
+ gpr_log(GPR_ERROR, "Invalid expected targets arg value: '%s'",
292
+ expected_targets);
293
+ goto done;
294
+ }
295
+ if (is_lb_channel) {
296
+ if (lbs_and_backends_size != 2) {
297
+ gpr_log(GPR_ERROR,
298
+ "Invalid expected targets arg value: '%s'. Expectations for LB "
299
+ "channels must be of the form 'be1,be2,be3,...;lb1,lb2,...",
300
+ expected_targets);
301
+ goto done;
302
+ }
303
+ if (!fake_check_target("LB", target, lbs_and_backends[1])) {
304
+ gpr_log(GPR_ERROR, "LB target '%s' not found in expected set '%s'",
305
+ target, lbs_and_backends[1]);
306
+ goto done;
307
+ }
308
+ success = true;
309
+ } else {
310
+ if (!fake_check_target("Backend", target, lbs_and_backends[0])) {
311
+ gpr_log(GPR_ERROR, "Backend target '%s' not found in expected set '%s'",
312
+ target, lbs_and_backends[0]);
313
+ goto done;
314
+ }
315
+ success = true;
316
+ }
317
+ done:
318
+ for (size_t i = 0; i < lbs_and_backends_size; ++i) {
319
+ gpr_free(lbs_and_backends[i]);
320
+ }
321
+ gpr_free(lbs_and_backends);
322
+ if (!success) abort();
323
+ }
324
+
250
325
  static void fake_check_peer(grpc_exec_ctx *exec_ctx,
251
326
  grpc_security_connector *sc, tsi_peer peer,
252
327
  grpc_auth_context **auth_context,
@@ -277,12 +352,28 @@ static void fake_check_peer(grpc_exec_ctx *exec_ctx,
277
352
  grpc_auth_context_add_cstring_property(
278
353
  *auth_context, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME,
279
354
  GRPC_FAKE_TRANSPORT_SECURITY_TYPE);
280
-
281
355
  end:
282
356
  grpc_closure_sched(exec_ctx, on_peer_checked, error);
283
357
  tsi_peer_destruct(&peer);
284
358
  }
285
359
 
360
+ static void fake_channel_check_peer(grpc_exec_ctx *exec_ctx,
361
+ grpc_security_connector *sc, tsi_peer peer,
362
+ grpc_auth_context **auth_context,
363
+ grpc_closure *on_peer_checked) {
364
+ fake_check_peer(exec_ctx, sc, peer, auth_context, on_peer_checked);
365
+ grpc_fake_channel_security_connector *c =
366
+ (grpc_fake_channel_security_connector *)sc;
367
+ fake_secure_name_check(c->target, c->expected_targets, c->is_lb_channel);
368
+ }
369
+
370
+ static void fake_server_check_peer(grpc_exec_ctx *exec_ctx,
371
+ grpc_security_connector *sc, tsi_peer peer,
372
+ grpc_auth_context **auth_context,
373
+ grpc_closure *on_peer_checked) {
374
+ fake_check_peer(exec_ctx, sc, peer, auth_context, on_peer_checked);
375
+ }
376
+
286
377
  static void fake_channel_check_call_host(grpc_exec_ctx *exec_ctx,
287
378
  grpc_channel_security_connector *sc,
288
379
  const char *host,
@@ -313,29 +404,37 @@ static void fake_server_add_handshakers(grpc_exec_ctx *exec_ctx,
313
404
  }
314
405
 
315
406
  static grpc_security_connector_vtable fake_channel_vtable = {
316
- fake_channel_destroy, fake_check_peer};
407
+ fake_channel_destroy, fake_channel_check_peer};
317
408
 
318
- static grpc_security_connector_vtable fake_server_vtable = {fake_server_destroy,
319
- fake_check_peer};
409
+ static grpc_security_connector_vtable fake_server_vtable = {
410
+ fake_server_destroy, fake_server_check_peer};
320
411
 
321
412
  grpc_channel_security_connector *grpc_fake_channel_security_connector_create(
322
- grpc_call_credentials *request_metadata_creds) {
323
- grpc_channel_security_connector *c = gpr_malloc(sizeof(*c));
324
- memset(c, 0, sizeof(*c));
325
- gpr_ref_init(&c->base.refcount, 1);
326
- c->base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME;
327
- c->base.vtable = &fake_channel_vtable;
328
- c->request_metadata_creds = grpc_call_credentials_ref(request_metadata_creds);
329
- c->check_call_host = fake_channel_check_call_host;
330
- c->add_handshakers = fake_channel_add_handshakers;
331
- return c;
413
+ grpc_call_credentials *request_metadata_creds, const char *target,
414
+ const grpc_channel_args *args) {
415
+ grpc_fake_channel_security_connector *c = gpr_zalloc(sizeof(*c));
416
+ gpr_ref_init(&c->base.base.refcount, 1);
417
+ c->base.base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME;
418
+ c->base.base.vtable = &fake_channel_vtable;
419
+ c->base.request_metadata_creds =
420
+ grpc_call_credentials_ref(request_metadata_creds);
421
+ c->base.check_call_host = fake_channel_check_call_host;
422
+ c->base.add_handshakers = fake_channel_add_handshakers;
423
+ c->target = gpr_strdup(target);
424
+ const grpc_arg *expected_target_arg =
425
+ grpc_channel_args_find(args, GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS);
426
+ if (expected_target_arg != NULL) {
427
+ GPR_ASSERT(expected_target_arg->type == GRPC_ARG_STRING);
428
+ c->expected_targets = gpr_strdup(expected_target_arg->value.string);
429
+ }
430
+ c->is_lb_channel = (grpc_lb_targets_info_find_in_args(args) != NULL);
431
+ return &c->base;
332
432
  }
333
433
 
334
434
  grpc_server_security_connector *grpc_fake_server_security_connector_create(
335
435
  void) {
336
436
  grpc_server_security_connector *c =
337
- gpr_malloc(sizeof(grpc_server_security_connector));
338
- memset(c, 0, sizeof(*c));
437
+ gpr_zalloc(sizeof(grpc_server_security_connector));
339
438
  gpr_ref_init(&c->base.refcount, 1);
340
439
  c->base.vtable = &fake_server_vtable;
341
440
  c->base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME;
@@ -601,7 +700,7 @@ static grpc_security_connector_vtable ssl_server_vtable = {
601
700
  ssl_server_destroy, ssl_server_check_peer};
602
701
 
603
702
  static grpc_slice compute_default_pem_root_certs_once(void) {
604
- grpc_slice result = gpr_empty_slice();
703
+ grpc_slice result = grpc_empty_slice();
605
704
 
606
705
  /* First try to load the roots from the environment. */
607
706
  char *default_root_certs_path =
@@ -714,8 +813,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
714
813
  pem_root_certs_size = config->pem_root_certs_size;
715
814
  }
716
815
 
717
- c = gpr_malloc(sizeof(grpc_ssl_channel_security_connector));
718
- memset(c, 0, sizeof(grpc_ssl_channel_security_connector));
816
+ c = gpr_zalloc(sizeof(grpc_ssl_channel_security_connector));
719
817
 
720
818
  gpr_ref_init(&c->base.base.refcount, 1);
721
819
  c->base.base.vtable = &ssl_channel_vtable;
@@ -776,8 +874,7 @@ grpc_security_status grpc_ssl_server_security_connector_create(
776
874
  gpr_log(GPR_ERROR, "An SSL server needs a key and a cert.");
777
875
  goto error;
778
876
  }
779
- c = gpr_malloc(sizeof(grpc_ssl_server_security_connector));
780
- memset(c, 0, sizeof(grpc_ssl_server_security_connector));
877
+ c = gpr_zalloc(sizeof(grpc_ssl_server_security_connector));
781
878
 
782
879
  gpr_ref_init(&c->base.base.refcount, 1);
783
880
  c->base.base.url_scheme = GRPC_SSL_URL_SCHEME;
@@ -57,7 +57,7 @@ typedef enum { GRPC_SECURITY_OK = 0, GRPC_SECURITY_ERROR } grpc_security_status;
57
57
 
58
58
  typedef struct grpc_security_connector grpc_security_connector;
59
59
 
60
- #define GRPC_SECURITY_CONNECTOR_ARG "grpc.security_connector"
60
+ #define GRPC_ARG_SECURITY_CONNECTOR "grpc.security_connector"
61
61
 
62
62
  typedef struct {
63
63
  void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_security_connector *sc);
@@ -115,7 +115,7 @@ grpc_arg grpc_security_connector_to_arg(grpc_security_connector *sc);
115
115
  grpc_security_connector *grpc_security_connector_from_arg(const grpc_arg *arg);
116
116
 
117
117
  /* Util to find the connector from channel args. */
118
- grpc_security_connector *grpc_find_security_connector_in_args(
118
+ grpc_security_connector *grpc_security_connector_find_in_args(
119
119
  const grpc_channel_args *args);
120
120
 
121
121
  /* --- channel_security_connector object. ---
@@ -175,7 +175,8 @@ void grpc_server_security_connector_add_handshakers(
175
175
  /* For TESTING ONLY!
176
176
  Creates a fake connector that emulates real channel security. */
177
177
  grpc_channel_security_connector *grpc_fake_channel_security_connector_create(
178
- grpc_call_credentials *request_metadata_creds);
178
+ grpc_call_credentials *request_metadata_creds, const char *target,
179
+ const grpc_channel_args *args);
179
180
 
180
181
  /* For TESTING ONLY!
181
182
  Creates a fake connector that emulates real server security. */
@@ -124,13 +124,13 @@ static void security_handshake_failed_locked(grpc_exec_ctx *exec_ctx,
124
124
  }
125
125
  const char *msg = grpc_error_string(error);
126
126
  gpr_log(GPR_DEBUG, "Security handshake failed: %s", msg);
127
- grpc_error_free_string(msg);
127
+
128
128
  if (!h->shutdown) {
129
129
  // TODO(ctiller): It is currently necessary to shutdown endpoints
130
130
  // before destroying them, even if we know that there are no
131
131
  // pending read/write callbacks. This should be fixed, at which
132
132
  // point this can be removed.
133
- grpc_endpoint_shutdown(exec_ctx, h->args->endpoint);
133
+ grpc_endpoint_shutdown(exec_ctx, h->args->endpoint, GRPC_ERROR_REF(error));
134
134
  // Not shutting down, so the write failed. Clean up before
135
135
  // invoking the callback.
136
136
  cleanup_args_for_failure_locked(exec_ctx, h);
@@ -347,15 +347,17 @@ static void security_handshaker_destroy(grpc_exec_ctx *exec_ctx,
347
347
  }
348
348
 
349
349
  static void security_handshaker_shutdown(grpc_exec_ctx *exec_ctx,
350
- grpc_handshaker *handshaker) {
350
+ grpc_handshaker *handshaker,
351
+ grpc_error *why) {
351
352
  security_handshaker *h = (security_handshaker *)handshaker;
352
353
  gpr_mu_lock(&h->mu);
353
354
  if (!h->shutdown) {
354
355
  h->shutdown = true;
355
- grpc_endpoint_shutdown(exec_ctx, h->args->endpoint);
356
+ grpc_endpoint_shutdown(exec_ctx, h->args->endpoint, GRPC_ERROR_REF(why));
356
357
  cleanup_args_for_failure_locked(exec_ctx, h);
357
358
  }
358
359
  gpr_mu_unlock(&h->mu);
360
+ GRPC_ERROR_UNREF(why);
359
361
  }
360
362
 
361
363
  static void security_handshaker_do_handshake(grpc_exec_ctx *exec_ctx,
@@ -385,8 +387,7 @@ static const grpc_handshaker_vtable security_handshaker_vtable = {
385
387
  static grpc_handshaker *security_handshaker_create(
386
388
  grpc_exec_ctx *exec_ctx, tsi_handshaker *handshaker,
387
389
  grpc_security_connector *connector) {
388
- security_handshaker *h = gpr_malloc(sizeof(security_handshaker));
389
- memset(h, 0, sizeof(security_handshaker));
390
+ security_handshaker *h = gpr_zalloc(sizeof(security_handshaker));
390
391
  grpc_handshaker_init(&security_handshaker_vtable, &h->base);
391
392
  h->handshaker = handshaker;
392
393
  h->connector = GRPC_SECURITY_CONNECTOR_REF(connector, "handshake");
@@ -417,7 +418,10 @@ static void fail_handshaker_destroy(grpc_exec_ctx *exec_ctx,
417
418
  }
418
419
 
419
420
  static void fail_handshaker_shutdown(grpc_exec_ctx *exec_ctx,
420
- grpc_handshaker *handshaker) {}
421
+ grpc_handshaker *handshaker,
422
+ grpc_error *why) {
423
+ GRPC_ERROR_UNREF(why);
424
+ }
421
425
 
422
426
  static void fail_handshaker_do_handshake(grpc_exec_ctx *exec_ctx,
423
427
  grpc_handshaker *handshaker,
@@ -446,7 +450,7 @@ static void client_handshaker_factory_add_handshakers(
446
450
  grpc_exec_ctx *exec_ctx, grpc_handshaker_factory *handshaker_factory,
447
451
  const grpc_channel_args *args, grpc_handshake_manager *handshake_mgr) {
448
452
  grpc_channel_security_connector *security_connector =
449
- (grpc_channel_security_connector *)grpc_find_security_connector_in_args(
453
+ (grpc_channel_security_connector *)grpc_security_connector_find_in_args(
450
454
  args);
451
455
  grpc_channel_security_connector_add_handshakers(exec_ctx, security_connector,
452
456
  handshake_mgr);
@@ -456,7 +460,7 @@ static void server_handshaker_factory_add_handshakers(
456
460
  grpc_exec_ctx *exec_ctx, grpc_handshaker_factory *hf,
457
461
  const grpc_channel_args *args, grpc_handshake_manager *handshake_mgr) {
458
462
  grpc_server_security_connector *security_connector =
459
- (grpc_server_security_connector *)grpc_find_security_connector_in_args(
463
+ (grpc_server_security_connector *)grpc_security_connector_find_in_args(
460
464
  args);
461
465
  grpc_server_security_connector_add_handshakers(exec_ctx, security_connector,
462
466
  handshake_mgr);
@@ -33,12 +33,13 @@
33
33
 
34
34
  #include <string.h>
35
35
 
36
+ #include <grpc/support/alloc.h>
37
+ #include <grpc/support/log.h>
38
+
36
39
  #include "src/core/lib/security/context/security_context.h"
37
40
  #include "src/core/lib/security/credentials/credentials.h"
38
41
  #include "src/core/lib/security/transport/auth_filters.h"
39
-
40
- #include <grpc/support/alloc.h>
41
- #include <grpc/support/log.h>
42
+ #include "src/core/lib/slice/slice_internal.h"
42
43
 
43
44
  typedef struct call_data {
44
45
  grpc_metadata_batch *recv_initial_metadata;
@@ -67,48 +68,34 @@ static grpc_metadata_array metadata_batch_to_md_array(
67
68
  grpc_metadata_array_init(&result);
68
69
  for (l = batch->list.head; l != NULL; l = l->next) {
69
70
  grpc_metadata *usr_md = NULL;
70
- grpc_mdelem *md = l->md;
71
- grpc_mdstr *key = md->key;
72
- grpc_mdstr *value = md->value;
71
+ grpc_mdelem md = l->md;
72
+ grpc_slice key = GRPC_MDKEY(md);
73
+ grpc_slice value = GRPC_MDVALUE(md);
73
74
  if (result.count == result.capacity) {
74
75
  result.capacity = GPR_MAX(result.capacity + 8, result.capacity * 2);
75
76
  result.metadata =
76
77
  gpr_realloc(result.metadata, result.capacity * sizeof(grpc_metadata));
77
78
  }
78
79
  usr_md = &result.metadata[result.count++];
79
- usr_md->key = grpc_mdstr_as_c_string(key);
80
- usr_md->value = grpc_mdstr_as_c_string(value);
81
- usr_md->value_length = GRPC_SLICE_LENGTH(value->slice);
80
+ usr_md->key = grpc_slice_ref_internal(key);
81
+ usr_md->value = grpc_slice_ref_internal(value);
82
82
  }
83
83
  return result;
84
84
  }
85
85
 
86
- static grpc_mdelem *remove_consumed_md(grpc_exec_ctx *exec_ctx, void *user_data,
87
- grpc_mdelem *md) {
86
+ static grpc_filtered_mdelem remove_consumed_md(grpc_exec_ctx *exec_ctx,
87
+ void *user_data,
88
+ grpc_mdelem md) {
88
89
  grpc_call_element *elem = user_data;
89
90
  call_data *calld = elem->call_data;
90
91
  size_t i;
91
92
  for (i = 0; i < calld->num_consumed_md; i++) {
92
93
  const grpc_metadata *consumed_md = &calld->consumed_md[i];
93
- /* Maybe we could do a pointer comparison but we do not have any guarantee
94
- that the metadata processor used the same pointers for consumed_md in the
95
- callback. */
96
- if (GRPC_SLICE_LENGTH(md->key->slice) != strlen(consumed_md->key) ||
97
- GRPC_SLICE_LENGTH(md->value->slice) != consumed_md->value_length) {
98
- continue;
99
- }
100
- if (memcmp(GRPC_SLICE_START_PTR(md->key->slice), consumed_md->key,
101
- GRPC_SLICE_LENGTH(md->key->slice)) == 0 &&
102
- memcmp(GRPC_SLICE_START_PTR(md->value->slice), consumed_md->value,
103
- GRPC_SLICE_LENGTH(md->value->slice)) == 0) {
104
- return NULL; /* Delete. */
105
- }
94
+ if (grpc_slice_eq(GRPC_MDKEY(md), consumed_md->key) &&
95
+ grpc_slice_eq(GRPC_MDVALUE(md), consumed_md->value))
96
+ return GRPC_FILTERED_REMOVE();
106
97
  }
107
- return md;
108
- }
109
-
110
- static void destroy_op(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
111
- gpr_free(arg);
98
+ return GRPC_FILTERED_MDELEM(md);
112
99
  }
113
100
 
114
101
  /* called from application code */
@@ -130,29 +117,33 @@ static void on_md_processing_done(
130
117
  if (status == GRPC_STATUS_OK) {
131
118
  calld->consumed_md = consumed_md;
132
119
  calld->num_consumed_md = num_consumed_md;
133
- grpc_metadata_batch_filter(&exec_ctx, calld->recv_initial_metadata,
134
- remove_consumed_md, elem);
120
+ /* TODO(ctiller): propagate error */
121
+ GRPC_LOG_IF_ERROR(
122
+ "grpc_metadata_batch_filter",
123
+ grpc_metadata_batch_filter(&exec_ctx, calld->recv_initial_metadata,
124
+ remove_consumed_md, elem,
125
+ "Response metadata filtering error"));
126
+ for (size_t i = 0; i < calld->md.count; i++) {
127
+ grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].key);
128
+ grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].value);
129
+ }
135
130
  grpc_metadata_array_destroy(&calld->md);
136
131
  grpc_closure_sched(&exec_ctx, calld->on_done_recv, GRPC_ERROR_NONE);
137
132
  } else {
138
- grpc_slice message;
139
- grpc_transport_stream_op *close_op = gpr_malloc(sizeof(*close_op));
140
- memset(close_op, 0, sizeof(*close_op));
133
+ for (size_t i = 0; i < calld->md.count; i++) {
134
+ grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].key);
135
+ grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].value);
136
+ }
141
137
  grpc_metadata_array_destroy(&calld->md);
142
138
  error_details = error_details != NULL
143
139
  ? error_details
144
140
  : "Authentication metadata processing failed.";
145
- message = grpc_slice_from_copied_string(error_details);
146
141
  calld->transport_op->send_initial_metadata = NULL;
147
142
  if (calld->transport_op->send_message != NULL) {
148
143
  grpc_byte_stream_destroy(&exec_ctx, calld->transport_op->send_message);
149
144
  calld->transport_op->send_message = NULL;
150
145
  }
151
146
  calld->transport_op->send_trailing_metadata = NULL;
152
- close_op->on_complete =
153
- grpc_closure_create(destroy_op, close_op, grpc_schedule_on_exec_ctx);
154
- grpc_transport_stream_op_add_close(&exec_ctx, close_op, status, &message);
155
- grpc_call_next_op(&exec_ctx, elem, close_op);
156
147
  grpc_closure_sched(&exec_ctx, calld->on_done_recv,
157
148
  grpc_error_set_int(GRPC_ERROR_CREATE(error_details),
158
149
  GRPC_ERROR_INT_GRPC_STATUS, status));
@@ -206,7 +197,7 @@ static void auth_start_transport_op(grpc_exec_ctx *exec_ctx,
206
197
  /* Constructor for call_data */
207
198
  static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx,
208
199
  grpc_call_element *elem,
209
- grpc_call_element_args *args) {
200
+ const grpc_call_element_args *args) {
210
201
  /* grab pointers to our data from the call element */
211
202
  call_data *calld = elem->call_data;
212
203
  channel_data *chand = elem->channel_data;