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
@@ -37,10 +37,10 @@
37
37
  #include <grpc/support/host_port.h>
38
38
  #include <grpc/support/string_util.h>
39
39
 
40
- #include "src/core/ext/client_channel/http_connect_handshaker.h"
41
40
  #include "src/core/ext/client_channel/lb_policy_registry.h"
42
41
  #include "src/core/ext/client_channel/resolver_registry.h"
43
42
  #include "src/core/lib/channel/channel_args.h"
43
+ #include "src/core/lib/iomgr/combiner.h"
44
44
  #include "src/core/lib/iomgr/resolve_address.h"
45
45
  #include "src/core/lib/iomgr/timer.h"
46
46
  #include "src/core/lib/support/backoff.h"
@@ -64,8 +64,6 @@ typedef struct {
64
64
  /** pollset_set to drive the name resolution process */
65
65
  grpc_pollset_set *interested_parties;
66
66
 
67
- /** mutex guarding the rest of the state */
68
- gpr_mu mu;
69
67
  /** are we currently resolving? */
70
68
  bool resolving;
71
69
  /** which version of the result have we published? */
@@ -96,18 +94,20 @@ static void dns_start_resolving_locked(grpc_exec_ctx *exec_ctx,
96
94
  static void dns_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
97
95
  dns_resolver *r);
98
96
 
99
- static void dns_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *r);
100
- static void dns_channel_saw_error(grpc_exec_ctx *exec_ctx, grpc_resolver *r);
101
- static void dns_next(grpc_exec_ctx *exec_ctx, grpc_resolver *r,
102
- grpc_channel_args **target_result,
103
- grpc_closure *on_complete);
97
+ static void dns_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *r);
98
+ static void dns_channel_saw_error_locked(grpc_exec_ctx *exec_ctx,
99
+ grpc_resolver *r);
100
+ static void dns_next_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *r,
101
+ grpc_channel_args **target_result,
102
+ grpc_closure *on_complete);
104
103
 
105
104
  static const grpc_resolver_vtable dns_resolver_vtable = {
106
- dns_destroy, dns_shutdown, dns_channel_saw_error, dns_next};
105
+ dns_destroy, dns_shutdown_locked, dns_channel_saw_error_locked,
106
+ dns_next_locked};
107
107
 
108
- static void dns_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver) {
108
+ static void dns_shutdown_locked(grpc_exec_ctx *exec_ctx,
109
+ grpc_resolver *resolver) {
109
110
  dns_resolver *r = (dns_resolver *)resolver;
110
- gpr_mu_lock(&r->mu);
111
111
  if (r->have_retry_timer) {
112
112
  grpc_timer_cancel(exec_ctx, &r->retry_timer);
113
113
  }
@@ -117,25 +117,21 @@ static void dns_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver) {
117
117
  GRPC_ERROR_CREATE("Resolver Shutdown"));
118
118
  r->next_completion = NULL;
119
119
  }
120
- gpr_mu_unlock(&r->mu);
121
120
  }
122
121
 
123
- static void dns_channel_saw_error(grpc_exec_ctx *exec_ctx,
124
- grpc_resolver *resolver) {
122
+ static void dns_channel_saw_error_locked(grpc_exec_ctx *exec_ctx,
123
+ grpc_resolver *resolver) {
125
124
  dns_resolver *r = (dns_resolver *)resolver;
126
- gpr_mu_lock(&r->mu);
127
125
  if (!r->resolving) {
128
126
  gpr_backoff_reset(&r->backoff_state);
129
127
  dns_start_resolving_locked(exec_ctx, r);
130
128
  }
131
- gpr_mu_unlock(&r->mu);
132
129
  }
133
130
 
134
- static void dns_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
135
- grpc_channel_args **target_result,
136
- grpc_closure *on_complete) {
131
+ static void dns_next_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
132
+ grpc_channel_args **target_result,
133
+ grpc_closure *on_complete) {
137
134
  dns_resolver *r = (dns_resolver *)resolver;
138
- gpr_mu_lock(&r->mu);
139
135
  GPR_ASSERT(!r->next_completion);
140
136
  r->next_completion = on_complete;
141
137
  r->target_result = target_result;
@@ -145,30 +141,26 @@ static void dns_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
145
141
  } else {
146
142
  dns_maybe_finish_next_locked(exec_ctx, r);
147
143
  }
148
- gpr_mu_unlock(&r->mu);
149
144
  }
150
145
 
151
- static void dns_on_retry_timer(grpc_exec_ctx *exec_ctx, void *arg,
152
- grpc_error *error) {
146
+ static void dns_on_retry_timer_locked(grpc_exec_ctx *exec_ctx, void *arg,
147
+ grpc_error *error) {
153
148
  dns_resolver *r = arg;
154
149
 
155
- gpr_mu_lock(&r->mu);
156
150
  r->have_retry_timer = false;
157
151
  if (error == GRPC_ERROR_NONE) {
158
152
  if (!r->resolving) {
159
153
  dns_start_resolving_locked(exec_ctx, r);
160
154
  }
161
155
  }
162
- gpr_mu_unlock(&r->mu);
163
156
 
164
157
  GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "retry-timer");
165
158
  }
166
159
 
167
- static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg,
168
- grpc_error *error) {
160
+ static void dns_on_resolved_locked(grpc_exec_ctx *exec_ctx, void *arg,
161
+ grpc_error *error) {
169
162
  dns_resolver *r = arg;
170
163
  grpc_channel_args *result = NULL;
171
- gpr_mu_lock(&r->mu);
172
164
  GPR_ASSERT(r->resolving);
173
165
  r->resolving = false;
174
166
  if (r->addresses != NULL) {
@@ -188,9 +180,8 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg,
188
180
  gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
189
181
  gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now);
190
182
  gpr_timespec timeout = gpr_time_sub(next_try, now);
191
- const char *msg = grpc_error_string(error);
192
- gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", msg);
193
- grpc_error_free_string(msg);
183
+ gpr_log(GPR_INFO, "dns resolution failed (will retry): %s",
184
+ grpc_error_string(error));
194
185
  GPR_ASSERT(!r->have_retry_timer);
195
186
  r->have_retry_timer = true;
196
187
  GRPC_RESOLVER_REF(&r->base, "retry-timer");
@@ -200,8 +191,8 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg,
200
191
  } else {
201
192
  gpr_log(GPR_DEBUG, "retrying immediately");
202
193
  }
203
- grpc_closure_init(&r->on_retry, dns_on_retry_timer, r,
204
- grpc_schedule_on_exec_ctx);
194
+ grpc_closure_init(&r->on_retry, dns_on_retry_timer_locked, r,
195
+ grpc_combiner_scheduler(r->base.combiner, false));
205
196
  grpc_timer_init(exec_ctx, &r->retry_timer, next_try, &r->on_retry, now);
206
197
  }
207
198
  if (r->resolved_result != NULL) {
@@ -210,7 +201,6 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg,
210
201
  r->resolved_result = result;
211
202
  r->resolved_version++;
212
203
  dns_maybe_finish_next_locked(exec_ctx, r);
213
- gpr_mu_unlock(&r->mu);
214
204
 
215
205
  GRPC_RESOLVER_UNREF(exec_ctx, &r->base, "dns-resolving");
216
206
  }
@@ -223,7 +213,8 @@ static void dns_start_resolving_locked(grpc_exec_ctx *exec_ctx,
223
213
  r->addresses = NULL;
224
214
  grpc_resolve_address(
225
215
  exec_ctx, r->name_to_resolve, r->default_port, r->interested_parties,
226
- grpc_closure_create(dns_on_resolved, r, grpc_schedule_on_exec_ctx),
216
+ grpc_closure_create(dns_on_resolved_locked, r,
217
+ grpc_combiner_scheduler(r->base.combiner, false)),
227
218
  &r->addresses);
228
219
  }
229
220
 
@@ -242,11 +233,10 @@ static void dns_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
242
233
 
243
234
  static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
244
235
  dns_resolver *r = (dns_resolver *)gr;
245
- gpr_mu_destroy(&r->mu);
246
236
  if (r->resolved_result != NULL) {
247
237
  grpc_channel_args_destroy(exec_ctx, r->resolved_result);
248
238
  }
249
- grpc_pollset_set_destroy(r->interested_parties);
239
+ grpc_pollset_set_destroy(exec_ctx, r->interested_parties);
250
240
  gpr_free(r->name_to_resolve);
251
241
  gpr_free(r->default_port);
252
242
  grpc_channel_args_destroy(exec_ctx, r->channel_args);
@@ -261,16 +251,12 @@ static grpc_resolver *dns_create(grpc_exec_ctx *exec_ctx,
261
251
  return NULL;
262
252
  }
263
253
  // Get name from args.
264
- const char *path = args->uri->path;
254
+ char *path = args->uri->path;
265
255
  if (path[0] == '/') ++path;
266
- // Get proxy name, if any.
267
- char *proxy_name = grpc_get_http_proxy_server();
268
256
  // Create resolver.
269
- dns_resolver *r = gpr_malloc(sizeof(dns_resolver));
270
- memset(r, 0, sizeof(*r));
271
- gpr_mu_init(&r->mu);
272
- grpc_resolver_init(&r->base, &dns_resolver_vtable);
273
- r->name_to_resolve = proxy_name == NULL ? gpr_strdup(path) : proxy_name;
257
+ dns_resolver *r = gpr_zalloc(sizeof(dns_resolver));
258
+ grpc_resolver_init(&r->base, &dns_resolver_vtable, args->combiner);
259
+ r->name_to_resolve = gpr_strdup(path);
274
260
  r->default_port = gpr_strdup(default_port);
275
261
  r->channel_args = grpc_channel_args_copy(args->args);
276
262
  r->interested_parties = grpc_pollset_set_create();
@@ -45,6 +45,7 @@
45
45
  #include "src/core/ext/client_channel/parse_address.h"
46
46
  #include "src/core/ext/client_channel/resolver_registry.h"
47
47
  #include "src/core/lib/channel/channel_args.h"
48
+ #include "src/core/lib/iomgr/combiner.h"
48
49
  #include "src/core/lib/iomgr/resolve_address.h"
49
50
  #include "src/core/lib/iomgr/unix_sockets_posix.h"
50
51
  #include "src/core/lib/slice/slice_internal.h"
@@ -58,8 +59,6 @@ typedef struct {
58
59
  grpc_lb_addresses *addresses;
59
60
  /** channel args */
60
61
  grpc_channel_args *channel_args;
61
- /** mutex guarding the rest of the state */
62
- gpr_mu mu;
63
62
  /** have we published? */
64
63
  bool published;
65
64
  /** pending next completion, or NULL */
@@ -73,48 +72,43 @@ static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *r);
73
72
  static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
74
73
  sockaddr_resolver *r);
75
74
 
76
- static void sockaddr_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *r);
77
- static void sockaddr_channel_saw_error(grpc_exec_ctx *exec_ctx,
78
- grpc_resolver *r);
79
- static void sockaddr_next(grpc_exec_ctx *exec_ctx, grpc_resolver *r,
80
- grpc_channel_args **target_result,
81
- grpc_closure *on_complete);
75
+ static void sockaddr_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *r);
76
+ static void sockaddr_channel_saw_error_locked(grpc_exec_ctx *exec_ctx,
77
+ grpc_resolver *r);
78
+ static void sockaddr_next_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *r,
79
+ grpc_channel_args **target_result,
80
+ grpc_closure *on_complete);
82
81
 
83
82
  static const grpc_resolver_vtable sockaddr_resolver_vtable = {
84
- sockaddr_destroy, sockaddr_shutdown, sockaddr_channel_saw_error,
85
- sockaddr_next};
83
+ sockaddr_destroy, sockaddr_shutdown_locked,
84
+ sockaddr_channel_saw_error_locked, sockaddr_next_locked};
86
85
 
87
- static void sockaddr_shutdown(grpc_exec_ctx *exec_ctx,
88
- grpc_resolver *resolver) {
86
+ static void sockaddr_shutdown_locked(grpc_exec_ctx *exec_ctx,
87
+ grpc_resolver *resolver) {
89
88
  sockaddr_resolver *r = (sockaddr_resolver *)resolver;
90
- gpr_mu_lock(&r->mu);
91
89
  if (r->next_completion != NULL) {
92
90
  *r->target_result = NULL;
93
91
  grpc_closure_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE);
94
92
  r->next_completion = NULL;
95
93
  }
96
- gpr_mu_unlock(&r->mu);
97
94
  }
98
95
 
99
- static void sockaddr_channel_saw_error(grpc_exec_ctx *exec_ctx,
100
- grpc_resolver *resolver) {
96
+ static void sockaddr_channel_saw_error_locked(grpc_exec_ctx *exec_ctx,
97
+ grpc_resolver *resolver) {
101
98
  sockaddr_resolver *r = (sockaddr_resolver *)resolver;
102
- gpr_mu_lock(&r->mu);
103
99
  r->published = false;
104
100
  sockaddr_maybe_finish_next_locked(exec_ctx, r);
105
- gpr_mu_unlock(&r->mu);
106
101
  }
107
102
 
108
- static void sockaddr_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
109
- grpc_channel_args **target_result,
110
- grpc_closure *on_complete) {
103
+ static void sockaddr_next_locked(grpc_exec_ctx *exec_ctx,
104
+ grpc_resolver *resolver,
105
+ grpc_channel_args **target_result,
106
+ grpc_closure *on_complete) {
111
107
  sockaddr_resolver *r = (sockaddr_resolver *)resolver;
112
- gpr_mu_lock(&r->mu);
113
108
  GPR_ASSERT(!r->next_completion);
114
109
  r->next_completion = on_complete;
115
110
  r->target_result = target_result;
116
111
  sockaddr_maybe_finish_next_locked(exec_ctx, r);
117
- gpr_mu_unlock(&r->mu);
118
112
  }
119
113
 
120
114
  static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
@@ -131,7 +125,6 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
131
125
 
132
126
  static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
133
127
  sockaddr_resolver *r = (sockaddr_resolver *)gr;
134
- gpr_mu_destroy(&r->mu);
135
128
  grpc_lb_addresses_destroy(exec_ctx, r->addresses);
136
129
  grpc_channel_args_destroy(exec_ctx, r->channel_args);
137
130
  gpr_free(r);
@@ -182,7 +175,7 @@ static grpc_resolver *sockaddr_create(grpc_exec_ctx *exec_ctx,
182
175
  bool errors_found = false;
183
176
  for (size_t i = 0; i < addresses->num_addresses; i++) {
184
177
  grpc_uri ith_uri = *args->uri;
185
- char *part_str = grpc_dump_slice(path_parts.slices[i], GPR_DUMP_ASCII);
178
+ char *part_str = grpc_slice_to_c_string(path_parts.slices[i]);
186
179
  ith_uri.path = part_str;
187
180
  if (!parse(&ith_uri, &addresses->addresses[i].address)) {
188
181
  errors_found = true; /* GPR_TRUE */
@@ -197,12 +190,10 @@ static grpc_resolver *sockaddr_create(grpc_exec_ctx *exec_ctx,
197
190
  return NULL;
198
191
  }
199
192
  /* Instantiate resolver. */
200
- sockaddr_resolver *r = gpr_malloc(sizeof(sockaddr_resolver));
201
- memset(r, 0, sizeof(*r));
193
+ sockaddr_resolver *r = gpr_zalloc(sizeof(sockaddr_resolver));
202
194
  r->addresses = addresses;
203
195
  r->channel_args = grpc_channel_args_copy(args->args);
204
- gpr_mu_init(&r->mu);
205
- grpc_resolver_init(&r->base, &sockaddr_resolver_vtable);
196
+ grpc_resolver_init(&r->base, &sockaddr_resolver_vtable, args->combiner);
206
197
  return &r->base;
207
198
  }
208
199
 
@@ -92,19 +92,21 @@ static void chttp2_connector_unref(grpc_exec_ctx *exec_ctx,
92
92
  }
93
93
 
94
94
  static void chttp2_connector_shutdown(grpc_exec_ctx *exec_ctx,
95
- grpc_connector *con) {
95
+ grpc_connector *con, grpc_error *why) {
96
96
  chttp2_connector *c = (chttp2_connector *)con;
97
97
  gpr_mu_lock(&c->mu);
98
98
  c->shutdown = true;
99
99
  if (c->handshake_mgr != NULL) {
100
- grpc_handshake_manager_shutdown(exec_ctx, c->handshake_mgr);
100
+ grpc_handshake_manager_shutdown(exec_ctx, c->handshake_mgr,
101
+ GRPC_ERROR_REF(why));
101
102
  }
102
103
  // If handshaking is not yet in progress, shutdown the endpoint.
103
104
  // Otherwise, the handshaker will do this for us.
104
105
  if (!c->connecting && c->endpoint != NULL) {
105
- grpc_endpoint_shutdown(exec_ctx, c->endpoint);
106
+ grpc_endpoint_shutdown(exec_ctx, c->endpoint, GRPC_ERROR_REF(why));
106
107
  }
107
108
  gpr_mu_unlock(&c->mu);
109
+ GRPC_ERROR_UNREF(why);
108
110
  }
109
111
 
110
112
  static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
@@ -121,7 +123,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
121
123
  // before destroying them, even if we know that there are no
122
124
  // pending read/write callbacks. This should be fixed, at which
123
125
  // point this can be removed.
124
- grpc_endpoint_shutdown(exec_ctx, args->endpoint);
126
+ grpc_endpoint_shutdown(exec_ctx, args->endpoint, GRPC_ERROR_REF(error));
125
127
  grpc_endpoint_destroy(exec_ctx, args->endpoint);
126
128
  grpc_channel_args_destroy(exec_ctx, args->args);
127
129
  grpc_slice_buffer_destroy_internal(exec_ctx, args->read_buffer);
@@ -195,7 +197,9 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
195
197
  grpc_closure *notify = c->notify;
196
198
  c->notify = NULL;
197
199
  grpc_closure_sched(exec_ctx, notify, error);
198
- if (c->endpoint != NULL) grpc_endpoint_shutdown(exec_ctx, c->endpoint);
200
+ if (c->endpoint != NULL) {
201
+ grpc_endpoint_shutdown(exec_ctx, c->endpoint, GRPC_ERROR_REF(error));
202
+ }
199
203
  gpr_mu_unlock(&c->mu);
200
204
  chttp2_connector_unref(exec_ctx, arg);
201
205
  } else {
@@ -222,7 +226,7 @@ static void chttp2_connector_connect(grpc_exec_ctx *exec_ctx,
222
226
  grpc_closure *notify) {
223
227
  chttp2_connector *c = (chttp2_connector *)con;
224
228
  grpc_resolved_address addr;
225
- grpc_get_subchannel_address_arg(args->channel_args, &addr);
229
+ grpc_get_subchannel_address_arg(exec_ctx, args->channel_args, &addr);
226
230
  gpr_mu_lock(&c->mu);
227
231
  GPR_ASSERT(c->notify == NULL);
228
232
  c->notify = notify;
@@ -244,8 +248,7 @@ static const grpc_connector_vtable chttp2_connector_vtable = {
244
248
  chttp2_connector_connect};
245
249
 
246
250
  grpc_connector *grpc_chttp2_connector_create() {
247
- chttp2_connector *c = gpr_malloc(sizeof(*c));
248
- memset(c, 0, sizeof(*c));
251
+ chttp2_connector *c = gpr_zalloc(sizeof(*c));
249
252
  c->base.vtable = &chttp2_connector_vtable;
250
253
  gpr_mu_init(&c->mu);
251
254
  gpr_ref_init(&c->refs, 1);
@@ -39,6 +39,7 @@
39
39
  #include <grpc/support/string_util.h>
40
40
 
41
41
  #include "src/core/ext/client_channel/client_channel.h"
42
+ #include "src/core/ext/client_channel/resolver_registry.h"
42
43
  #include "src/core/ext/transport/chttp2/client/chttp2_connector.h"
43
44
  #include "src/core/lib/channel/channel_args.h"
44
45
  #include "src/core/lib/surface/api_trace.h"
@@ -63,12 +64,20 @@ static grpc_channel *client_channel_factory_create_channel(
63
64
  grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
64
65
  const char *target, grpc_client_channel_type type,
65
66
  const grpc_channel_args *args) {
67
+ if (target == NULL) {
68
+ gpr_log(GPR_ERROR, "cannot create channel with NULL target name");
69
+ return NULL;
70
+ }
66
71
  // Add channel arg containing the server URI.
67
72
  grpc_arg arg;
68
73
  arg.type = GRPC_ARG_STRING;
69
74
  arg.key = GRPC_ARG_SERVER_URI;
70
- arg.value.string = (char *)target;
71
- grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
75
+ arg.value.string =
76
+ grpc_resolver_factory_add_default_prefix_if_needed(exec_ctx, target);
77
+ const char *to_remove[] = {GRPC_ARG_SERVER_URI};
78
+ grpc_channel_args *new_args =
79
+ grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1);
80
+ gpr_free(arg.value.string);
72
81
  grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args,
73
82
  GRPC_CLIENT_CHANNEL, NULL);
74
83
  grpc_channel_args_destroy(exec_ctx, new_args);
@@ -39,10 +39,16 @@
39
39
  #include <grpc/support/string_util.h>
40
40
 
41
41
  #include "src/core/ext/client_channel/client_channel.h"
42
+ #include "src/core/ext/client_channel/resolver_registry.h"
43
+ #include "src/core/ext/client_channel/uri_parser.h"
42
44
  #include "src/core/ext/transport/chttp2/client/chttp2_connector.h"
43
45
  #include "src/core/lib/channel/channel_args.h"
46
+ #include "src/core/lib/iomgr/sockaddr_utils.h"
44
47
  #include "src/core/lib/security/credentials/credentials.h"
48
+ #include "src/core/lib/security/transport/lb_targets_info.h"
45
49
  #include "src/core/lib/security/transport/security_connector.h"
50
+ #include "src/core/lib/slice/slice_hash_table.h"
51
+ #include "src/core/lib/slice/slice_internal.h"
46
52
  #include "src/core/lib/surface/api_trace.h"
47
53
  #include "src/core/lib/surface/channel.h"
48
54
 
@@ -52,12 +58,114 @@ static void client_channel_factory_ref(
52
58
  static void client_channel_factory_unref(
53
59
  grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory) {}
54
60
 
61
+ static grpc_subchannel_args *get_secure_naming_subchannel_args(
62
+ grpc_exec_ctx *exec_ctx, const grpc_subchannel_args *args) {
63
+ grpc_channel_credentials *channel_credentials =
64
+ grpc_channel_credentials_find_in_args(args->args);
65
+ if (channel_credentials == NULL) {
66
+ gpr_log(GPR_ERROR,
67
+ "Can't create subchannel: channel credentials missing for secure "
68
+ "channel.");
69
+ return NULL;
70
+ }
71
+ // Make sure security connector does not already exist in args.
72
+ if (grpc_security_connector_find_in_args(args->args) != NULL) {
73
+ gpr_log(GPR_ERROR,
74
+ "Can't create subchannel: security connector already present in "
75
+ "channel args.");
76
+ return NULL;
77
+ }
78
+ // To which address are we connecting? By default, use the server URI.
79
+ const grpc_arg *server_uri_arg =
80
+ grpc_channel_args_find(args->args, GRPC_ARG_SERVER_URI);
81
+ GPR_ASSERT(server_uri_arg != NULL);
82
+ GPR_ASSERT(server_uri_arg->type == GRPC_ARG_STRING);
83
+ const char *server_uri_str = server_uri_arg->value.string;
84
+ GPR_ASSERT(server_uri_str != NULL);
85
+ grpc_uri *server_uri =
86
+ grpc_uri_parse(exec_ctx, server_uri_str, true /* supress errors */);
87
+ GPR_ASSERT(server_uri != NULL);
88
+ const char *server_uri_path;
89
+ server_uri_path =
90
+ server_uri->path[0] == '/' ? server_uri->path + 1 : server_uri->path;
91
+ const grpc_slice_hash_table *targets_info =
92
+ grpc_lb_targets_info_find_in_args(args->args);
93
+ char *target_name_to_check = NULL;
94
+ if (targets_info != NULL) { // LB channel
95
+ // Find the balancer name for the target.
96
+ const char *target_uri_str =
97
+ grpc_get_subchannel_address_uri_arg(args->args);
98
+ grpc_uri *target_uri =
99
+ grpc_uri_parse(exec_ctx, target_uri_str, false /* suppress errors */);
100
+ GPR_ASSERT(target_uri != NULL);
101
+ if (target_uri->path[0] != '\0') { // "path" may be empty
102
+ const grpc_slice key = grpc_slice_from_static_string(
103
+ target_uri->path[0] == '/' ? target_uri->path + 1 : target_uri->path);
104
+ const char *value = grpc_slice_hash_table_get(targets_info, key);
105
+ if (value != NULL) target_name_to_check = gpr_strdup(value);
106
+ grpc_slice_unref_internal(exec_ctx, key);
107
+ }
108
+ if (target_name_to_check == NULL) {
109
+ // If the target name to check hasn't already been set, fall back to using
110
+ // SERVER_URI
111
+ target_name_to_check = gpr_strdup(server_uri_path);
112
+ }
113
+ grpc_uri_destroy(target_uri);
114
+ } else { // regular channel: the secure name is the original server URI.
115
+ target_name_to_check = gpr_strdup(server_uri_path);
116
+ }
117
+ grpc_uri_destroy(server_uri);
118
+ GPR_ASSERT(target_name_to_check != NULL);
119
+ grpc_channel_security_connector *subchannel_security_connector = NULL;
120
+ // Create the security connector using the credentials and target name.
121
+ grpc_channel_args *new_args_from_connector = NULL;
122
+ const grpc_security_status security_status =
123
+ grpc_channel_credentials_create_security_connector(
124
+ exec_ctx, channel_credentials, target_name_to_check, args->args,
125
+ &subchannel_security_connector, &new_args_from_connector);
126
+ if (security_status != GRPC_SECURITY_OK) {
127
+ gpr_log(GPR_ERROR,
128
+ "Failed to create secure subchannel for secure name '%s'",
129
+ target_name_to_check);
130
+ gpr_free(target_name_to_check);
131
+ return NULL;
132
+ }
133
+ gpr_free(target_name_to_check);
134
+ grpc_arg new_security_connector_arg =
135
+ grpc_security_connector_to_arg(&subchannel_security_connector->base);
136
+
137
+ grpc_channel_args *new_args = grpc_channel_args_copy_and_add(
138
+ new_args_from_connector != NULL ? new_args_from_connector : args->args,
139
+ &new_security_connector_arg, 1);
140
+ GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &subchannel_security_connector->base,
141
+ "lb_channel_create");
142
+ if (new_args_from_connector != NULL) {
143
+ grpc_channel_args_destroy(exec_ctx, new_args_from_connector);
144
+ }
145
+ grpc_subchannel_args *final_sc_args = gpr_malloc(sizeof(*final_sc_args));
146
+ memcpy(final_sc_args, args, sizeof(*args));
147
+ final_sc_args->args = new_args;
148
+ return final_sc_args;
149
+ }
150
+
55
151
  static grpc_subchannel *client_channel_factory_create_subchannel(
56
152
  grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
57
153
  const grpc_subchannel_args *args) {
154
+ grpc_subchannel_args *subchannel_args =
155
+ get_secure_naming_subchannel_args(exec_ctx, args);
156
+ if (subchannel_args == NULL) {
157
+ gpr_log(
158
+ GPR_ERROR,
159
+ "Failed to create subchannel arguments during subchannel creation.");
160
+ return NULL;
161
+ }
58
162
  grpc_connector *connector = grpc_chttp2_connector_create();
59
- grpc_subchannel *s = grpc_subchannel_create(exec_ctx, connector, args);
163
+ grpc_subchannel *s =
164
+ grpc_subchannel_create(exec_ctx, connector, subchannel_args);
60
165
  grpc_connector_unref(exec_ctx, connector);
166
+ grpc_channel_args_destroy(exec_ctx,
167
+ (grpc_channel_args *)subchannel_args->args);
168
+ gpr_free(subchannel_args);
61
169
  return s;
62
170
  }
63
171
 
@@ -65,12 +173,20 @@ static grpc_channel *client_channel_factory_create_channel(
65
173
  grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
66
174
  const char *target, grpc_client_channel_type type,
67
175
  const grpc_channel_args *args) {
176
+ if (target == NULL) {
177
+ gpr_log(GPR_ERROR, "cannot create channel with NULL target name");
178
+ return NULL;
179
+ }
68
180
  // Add channel arg containing the server URI.
69
181
  grpc_arg arg;
70
182
  arg.type = GRPC_ARG_STRING;
71
183
  arg.key = GRPC_ARG_SERVER_URI;
72
- arg.value.string = (char *)target;
73
- grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
184
+ arg.value.string =
185
+ grpc_resolver_factory_add_default_prefix_if_needed(exec_ctx, target);
186
+ const char *to_remove[] = {GRPC_ARG_SERVER_URI};
187
+ grpc_channel_args *new_args =
188
+ grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1);
189
+ gpr_free(arg.value.string);
74
190
  grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args,
75
191
  GRPC_CLIENT_CHANNEL, NULL);
76
192
  grpc_channel_args_destroy(exec_ctx, new_args);
@@ -85,10 +201,10 @@ static const grpc_client_channel_factory_vtable client_channel_factory_vtable =
85
201
  static grpc_client_channel_factory client_channel_factory = {
86
202
  &client_channel_factory_vtable};
87
203
 
88
- /* Create a secure client channel:
89
- Asynchronously: - resolve target
90
- - connect to it (trying alternatives as presented)
91
- - perform handshakes */
204
+ // Create a secure client channel:
205
+ // Asynchronously: - resolve target
206
+ // - connect to it (trying alternatives as presented)
207
+ // - perform handshakes
92
208
  grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds,
93
209
  const char *target,
94
210
  const grpc_channel_args *args,
@@ -97,46 +213,27 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds,
97
213
  GRPC_API_TRACE(
98
214
  "grpc_secure_channel_create(creds=%p, target=%s, args=%p, "
99
215
  "reserved=%p)",
100
- 4, (creds, target, args, reserved));
216
+ 4, ((void *)creds, target, (void *)args, (void *)reserved));
101
217
  GPR_ASSERT(reserved == NULL);
102
- // Make sure security connector does not already exist in args.
103
- if (grpc_find_security_connector_in_args(args) != NULL) {
104
- gpr_log(GPR_ERROR, "Cannot set security context in channel args.");
218
+ grpc_channel *channel = NULL;
219
+ if (creds != NULL) {
220
+ // Add channel args containing the client channel factory and channel
221
+ // credentials.
222
+ grpc_arg args_to_add[] = {
223
+ grpc_client_channel_factory_create_channel_arg(&client_channel_factory),
224
+ grpc_channel_credentials_to_arg(creds)};
225
+ grpc_channel_args *new_args = grpc_channel_args_copy_and_add(
226
+ args, args_to_add, GPR_ARRAY_SIZE(args_to_add));
227
+ // Create channel.
228
+ channel = client_channel_factory_create_channel(
229
+ &exec_ctx, &client_channel_factory, target,
230
+ GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args);
231
+ // Clean up.
232
+ grpc_channel_args_destroy(&exec_ctx, new_args);
105
233
  grpc_exec_ctx_finish(&exec_ctx);
106
- return grpc_lame_client_channel_create(
107
- target, GRPC_STATUS_INTERNAL,
108
- "Security connector exists in channel args.");
109
- }
110
- // Create security connector and construct new channel args.
111
- grpc_channel_security_connector *security_connector;
112
- grpc_channel_args *new_args_from_connector;
113
- if (grpc_channel_credentials_create_security_connector(
114
- &exec_ctx, creds, target, args, &security_connector,
115
- &new_args_from_connector) != GRPC_SECURITY_OK) {
116
- grpc_exec_ctx_finish(&exec_ctx);
117
- return grpc_lame_client_channel_create(
118
- target, GRPC_STATUS_INTERNAL, "Failed to create security connector.");
119
- }
120
- // Add channel args containing the client channel factory and security
121
- // connector.
122
- grpc_arg args_to_add[2];
123
- args_to_add[0] =
124
- grpc_client_channel_factory_create_channel_arg(&client_channel_factory);
125
- args_to_add[1] = grpc_security_connector_to_arg(&security_connector->base);
126
- grpc_channel_args *new_args = grpc_channel_args_copy_and_add(
127
- new_args_from_connector != NULL ? new_args_from_connector : args,
128
- args_to_add, GPR_ARRAY_SIZE(args_to_add));
129
- if (new_args_from_connector != NULL) {
130
- grpc_channel_args_destroy(&exec_ctx, new_args_from_connector);
131
234
  }
132
- // Create channel.
133
- grpc_channel *channel = client_channel_factory_create_channel(
134
- &exec_ctx, &client_channel_factory, target,
135
- GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args);
136
- // Clean up.
137
- GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &security_connector->base,
138
- "secure_client_channel_factory_create_channel");
139
- grpc_channel_args_destroy(&exec_ctx, new_args);
140
- grpc_exec_ctx_finish(&exec_ctx);
141
- return channel; /* may be NULL */
235
+ return channel != NULL ? channel
236
+ : grpc_lame_client_channel_create(
237
+ target, GRPC_STATUS_INTERNAL,
238
+ "Failed to create secure client channel");
142
239
  }