Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #include <grpc/grpc.h> |
| 35 | |
| 36 | #include <stdlib.h> |
| 37 | #include <string.h> |
| 38 | |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 39 | #include <grpc/support/alloc.h> |
| 40 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 41 | #include "src/core/channel/channel_args.h" |
| 42 | #include "src/core/channel/client_channel.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 43 | #include "src/core/channel/http_client_filter.h" |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 44 | #include "src/core/client_config/resolver_registry.h" |
ctiller | 18b49ab | 2014-12-09 14:39:16 -0800 | [diff] [blame] | 45 | #include "src/core/iomgr/tcp_client.h" |
Julien Boeuf | c6f8d0a | 2015-05-11 22:40:02 -0700 | [diff] [blame] | 46 | #include "src/core/security/auth_filters.h" |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 47 | #include "src/core/security/credentials.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 48 | #include "src/core/security/secure_transport_setup.h" |
| 49 | #include "src/core/surface/channel.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 50 | #include "src/core/transport/chttp2_transport.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 51 | #include "src/core/tsi/transport_security_interface.h" |
| 52 | |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 53 | typedef struct { |
| 54 | grpc_connector base; |
| 55 | gpr_refcount refs; |
| 56 | |
| 57 | grpc_channel_security_connector *security_connector; |
| 58 | |
| 59 | grpc_iomgr_closure *notify; |
| 60 | grpc_connect_in_args args; |
| 61 | grpc_connect_out_args *result; |
| 62 | } connector; |
| 63 | |
| 64 | static void connector_ref(grpc_connector *con) { |
| 65 | connector *c = (connector *)con; |
| 66 | gpr_ref(&c->refs); |
| 67 | } |
| 68 | |
| 69 | static void connector_unref(grpc_connector *con) { |
| 70 | connector *c = (connector *)con; |
| 71 | if (gpr_unref(&c->refs)) { |
| 72 | gpr_free(c); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | static void on_secure_transport_setup_done(void *arg, |
| 77 | grpc_security_status status, |
| 78 | grpc_endpoint *secure_endpoint) { |
| 79 | connector *c = arg; |
| 80 | grpc_iomgr_closure *notify; |
| 81 | if (status != GRPC_SECURITY_OK) { |
| 82 | gpr_log(GPR_ERROR, "Secure transport setup failed with error %d.", status); |
| 83 | memset(c->result, 0, sizeof(*c->result)); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 84 | } else { |
| 85 | c->result->transport = grpc_create_chttp2_transport( |
| 86 | c->args.channel_args, secure_endpoint, |
| 87 | NULL, 0, c->args.metadata_context, 1); |
Craig Tiller | d9a5088 | 2015-06-29 15:57:36 -0700 | [diff] [blame^] | 88 | c->result->filters = gpr_malloc(sizeof(grpc_channel_filter *) * 2); |
| 89 | c->result->filters[0] = &grpc_client_auth_filter; |
| 90 | c->result->filters[1] = &grpc_http_client_filter; |
| 91 | c->result->num_filters = 2; |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 92 | } |
Craig Tiller | d9a5088 | 2015-06-29 15:57:36 -0700 | [diff] [blame^] | 93 | notify = c->notify; |
| 94 | c->notify = NULL; |
| 95 | grpc_iomgr_add_callback(notify); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static void connected(void *arg, grpc_endpoint *tcp) { |
| 99 | connector *c = arg; |
| 100 | grpc_iomgr_closure *notify; |
| 101 | if (tcp != NULL) { |
| 102 | grpc_setup_secure_transport(&c->security_connector->base, tcp, |
| 103 | on_secure_transport_setup_done, c); |
| 104 | } else { |
| 105 | memset(c->result, 0, sizeof(*c->result)); |
| 106 | notify = c->notify; |
| 107 | c->notify = NULL; |
| 108 | grpc_iomgr_add_callback(notify); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | static void connector_connect( |
| 113 | grpc_connector *con, const grpc_connect_in_args *args, |
| 114 | grpc_connect_out_args *result, grpc_iomgr_closure *notify) { |
| 115 | connector *c = (connector *)con; |
| 116 | GPR_ASSERT(c->notify == NULL); |
| 117 | GPR_ASSERT(notify->cb); |
| 118 | c->notify = notify; |
| 119 | c->args = *args; |
| 120 | c->result = result; |
| 121 | grpc_tcp_client_connect(connected, c, args->interested_parties, args->addr, args->addr_len, args->deadline); |
| 122 | } |
| 123 | |
| 124 | static const grpc_connector_vtable connector_vtable = {connector_ref, connector_unref, connector_connect}; |
| 125 | |
| 126 | typedef struct { |
| 127 | grpc_subchannel_factory base; |
| 128 | gpr_refcount refs; |
| 129 | grpc_mdctx *mdctx; |
Craig Tiller | d9a5088 | 2015-06-29 15:57:36 -0700 | [diff] [blame^] | 130 | grpc_channel_args *merge_args; |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 131 | grpc_channel_security_connector *security_connector; |
| 132 | } subchannel_factory; |
| 133 | |
| 134 | static void subchannel_factory_ref(grpc_subchannel_factory *scf) { |
| 135 | subchannel_factory *f = (subchannel_factory *)scf; |
| 136 | gpr_ref(&f->refs); |
| 137 | } |
| 138 | |
| 139 | static void subchannel_factory_unref(grpc_subchannel_factory *scf) { |
| 140 | subchannel_factory *f = (subchannel_factory *)scf; |
| 141 | if (gpr_unref(&f->refs)) { |
| 142 | grpc_mdctx_unref(f->mdctx); |
| 143 | gpr_free(f); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | static grpc_subchannel *subchannel_factory_create_subchannel(grpc_subchannel_factory *scf, grpc_subchannel_args *args) { |
| 148 | subchannel_factory *f = (subchannel_factory *)scf; |
| 149 | connector *c = gpr_malloc(sizeof(*c)); |
Craig Tiller | d9a5088 | 2015-06-29 15:57:36 -0700 | [diff] [blame^] | 150 | grpc_channel_args *final_args = |
| 151 | grpc_channel_args_merge(args->args, f->merge_args); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 152 | grpc_subchannel *s; |
| 153 | memset(c, 0, sizeof(*c)); |
| 154 | c->base.vtable = &connector_vtable; |
| 155 | c->security_connector = f->security_connector; |
| 156 | gpr_ref_init(&c->refs, 1); |
| 157 | args->mdctx = f->mdctx; |
Craig Tiller | d9a5088 | 2015-06-29 15:57:36 -0700 | [diff] [blame^] | 158 | args->args = final_args; |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 159 | s = grpc_subchannel_create(&c->base, args); |
| 160 | grpc_connector_unref(&c->base); |
Craig Tiller | d9a5088 | 2015-06-29 15:57:36 -0700 | [diff] [blame^] | 161 | grpc_channel_args_destroy(final_args); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 162 | return s; |
| 163 | } |
| 164 | |
| 165 | static const grpc_subchannel_factory_vtable subchannel_factory_vtable = {subchannel_factory_ref, subchannel_factory_unref, subchannel_factory_create_subchannel}; |
| 166 | |
| 167 | #if 0 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 168 | typedef struct setup setup; |
| 169 | |
| 170 | /* A single setup request (started via initiate) */ |
| 171 | typedef struct { |
| 172 | grpc_client_setup_request *cs_request; |
| 173 | setup *setup; |
| 174 | /* Resolved addresses, or null if resolution not yet completed. */ |
| 175 | grpc_resolved_addresses *resolved; |
| 176 | /* which address in resolved should we pick for the next connection attempt */ |
| 177 | size_t resolved_index; |
| 178 | } request; |
| 179 | |
| 180 | struct setup { |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 181 | grpc_channel_security_connector *security_connector; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 182 | const char *target; |
| 183 | grpc_transport_setup_callback setup_callback; |
| 184 | void *setup_user_data; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | static int maybe_try_next_resolved(request *r); |
| 188 | |
| 189 | static void done(request *r, int was_successful) { |
| 190 | grpc_client_setup_request_finish(r->cs_request, was_successful); |
| 191 | if (r->resolved) { |
| 192 | grpc_resolved_addresses_destroy(r->resolved); |
| 193 | } |
| 194 | gpr_free(r); |
| 195 | } |
| 196 | |
| 197 | static void on_secure_transport_setup_done(void *rp, |
| 198 | grpc_security_status status, |
| 199 | grpc_endpoint *secure_endpoint) { |
| 200 | request *r = rp; |
| 201 | if (status != GRPC_SECURITY_OK) { |
| 202 | gpr_log(GPR_ERROR, "Secure transport setup failed with error %d.", status); |
| 203 | done(r, 0); |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 204 | } else if (grpc_client_setup_cb_begin(r->cs_request, |
| 205 | "on_secure_transport_setup_done")) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 206 | grpc_create_chttp2_transport( |
| 207 | r->setup->setup_callback, r->setup->setup_user_data, |
| 208 | grpc_client_setup_get_channel_args(r->cs_request), secure_endpoint, |
| 209 | NULL, 0, grpc_client_setup_get_mdctx(r->cs_request), 1); |
Craig Tiller | cb36e9f | 2015-05-29 11:20:21 -0700 | [diff] [blame] | 210 | grpc_client_setup_cb_end(r->cs_request, "on_secure_transport_setup_done"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 211 | done(r, 1); |
Craig Tiller | 43a2b17 | 2015-02-18 17:17:51 -0800 | [diff] [blame] | 212 | } else { |
| 213 | done(r, 0); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
| 217 | /* connection callback: tcp is either valid, or null on error */ |
| 218 | static void on_connect(void *rp, grpc_endpoint *tcp) { |
| 219 | request *r = rp; |
| 220 | |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 221 | if (!grpc_client_setup_request_should_continue(r->cs_request, |
| 222 | "on_connect.secure")) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 223 | if (tcp) { |
| 224 | grpc_endpoint_shutdown(tcp); |
| 225 | grpc_endpoint_destroy(tcp); |
| 226 | } |
| 227 | done(r, 0); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | if (!tcp) { |
| 232 | if (!maybe_try_next_resolved(r)) { |
| 233 | done(r, 0); |
| 234 | return; |
| 235 | } else { |
| 236 | return; |
| 237 | } |
| 238 | } else { |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 239 | grpc_setup_secure_transport(&r->setup->security_connector->base, tcp, |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 240 | on_secure_transport_setup_done, r); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /* attempt to connect to the next available resolved address */ |
| 245 | static int maybe_try_next_resolved(request *r) { |
| 246 | grpc_resolved_address *addr; |
| 247 | if (!r->resolved) return 0; |
| 248 | if (r->resolved_index == r->resolved->naddrs) return 0; |
| 249 | addr = &r->resolved->addrs[r->resolved_index++]; |
Craig Tiller | 8ed24e2 | 2015-05-08 09:59:51 -0700 | [diff] [blame] | 250 | grpc_tcp_client_connect( |
| 251 | on_connect, r, grpc_client_setup_get_interested_parties(r->cs_request), |
| 252 | (struct sockaddr *)&addr->addr, addr->len, |
| 253 | grpc_client_setup_request_deadline(r->cs_request)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 254 | return 1; |
| 255 | } |
| 256 | |
| 257 | /* callback for when our target address has been resolved */ |
| 258 | static void on_resolved(void *rp, grpc_resolved_addresses *resolved) { |
| 259 | request *r = rp; |
| 260 | |
| 261 | /* if we're not still the active request, abort */ |
Craig Tiller | 8674cb1 | 2015-06-05 07:09:25 -0700 | [diff] [blame] | 262 | if (!grpc_client_setup_request_should_continue(r->cs_request, |
| 263 | "on_resolved.secure")) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 264 | if (resolved) { |
| 265 | grpc_resolved_addresses_destroy(resolved); |
| 266 | } |
| 267 | done(r, 0); |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | if (!resolved) { |
| 272 | done(r, 0); |
| 273 | return; |
| 274 | } else { |
| 275 | r->resolved = resolved; |
| 276 | r->resolved_index = 0; |
| 277 | if (!maybe_try_next_resolved(r)) { |
| 278 | done(r, 0); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | static void initiate_setup(void *sp, grpc_client_setup_request *cs_request) { |
| 284 | request *r = gpr_malloc(sizeof(request)); |
| 285 | r->setup = sp; |
| 286 | r->cs_request = cs_request; |
| 287 | r->resolved = NULL; |
| 288 | r->resolved_index = 0; |
| 289 | /* TODO(klempner): Make grpc_resolve_address respect deadline */ |
| 290 | grpc_resolve_address(r->setup->target, "https", on_resolved, r); |
| 291 | } |
| 292 | |
| 293 | static void done_setup(void *sp) { |
| 294 | setup *s = sp; |
| 295 | gpr_free((void *)s->target); |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 296 | grpc_security_connector_unref(&s->security_connector->base); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 297 | gpr_free(s); |
| 298 | } |
| 299 | |
| 300 | static grpc_transport_setup_result complete_setup(void *channel_stack, |
| 301 | grpc_transport *transport, |
| 302 | grpc_mdctx *mdctx) { |
Julien Boeuf | 54b2192 | 2015-02-04 16:39:35 -0800 | [diff] [blame] | 303 | static grpc_channel_filter const *extra_filters[] = { |
Craig Tiller | 6e84aba | 2015-04-23 15:08:17 -0700 | [diff] [blame] | 304 | &grpc_client_auth_filter, &grpc_http_client_filter}; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 305 | return grpc_client_channel_transport_setup_complete( |
| 306 | channel_stack, transport, extra_filters, GPR_ARRAY_SIZE(extra_filters), |
| 307 | mdctx); |
| 308 | } |
| 309 | |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 310 | #endif |
| 311 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 312 | /* Create a secure client channel: |
| 313 | Asynchronously: - resolve target |
| 314 | - connect to it (trying alternatives as presented) |
| 315 | - perform handshakes */ |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 316 | grpc_channel *grpc_secure_channel_create(grpc_credentials *creds, |
| 317 | const char *target, |
| 318 | const grpc_channel_args *args) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 319 | grpc_channel *channel; |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 320 | grpc_arg connector_arg; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 321 | grpc_channel_args *args_copy; |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 322 | grpc_channel_args *new_args_from_connector; |
Craig Tiller | 1a727fd | 2015-04-24 13:21:22 -0700 | [diff] [blame] | 323 | grpc_channel_security_connector *connector; |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 324 | grpc_mdctx *mdctx; |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 325 | grpc_resolver *resolver; |
| 326 | subchannel_factory *f; |
Julien Boeuf | 54b2192 | 2015-02-04 16:39:35 -0800 | [diff] [blame] | 327 | #define MAX_FILTERS 3 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 328 | const grpc_channel_filter *filters[MAX_FILTERS]; |
| 329 | int n = 0; |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 330 | |
| 331 | if (grpc_find_security_connector_in_args(args) != NULL) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 332 | gpr_log(GPR_ERROR, "Cannot set security context in channel args."); |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 333 | return grpc_lame_client_channel_create(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 336 | if (grpc_credentials_create_security_connector( |
| 337 | creds, target, args, NULL, &connector, &new_args_from_connector) != |
| 338 | GRPC_SECURITY_OK) { |
| 339 | return grpc_lame_client_channel_create(); |
| 340 | } |
Julien Boeuf | 75c9b6f | 2015-05-29 13:12:12 -0700 | [diff] [blame] | 341 | mdctx = grpc_mdctx_create(); |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 342 | |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 343 | connector_arg = grpc_security_connector_to_arg(&connector->base); |
| 344 | args_copy = grpc_channel_args_copy_and_add( |
| 345 | new_args_from_connector != NULL ? new_args_from_connector : args, |
Craig Tiller | d9a5088 | 2015-06-29 15:57:36 -0700 | [diff] [blame^] | 346 | &connector_arg, 1); |
Alistair Veitch | 9686dab | 2015-05-26 14:26:47 -0700 | [diff] [blame] | 347 | /* TODO(census) |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 348 | if (grpc_channel_args_is_census_enabled(args)) { |
| 349 | filters[n++] = &grpc_client_census_filter; |
Alistair Veitch | 9686dab | 2015-05-26 14:26:47 -0700 | [diff] [blame] | 350 | } */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 351 | filters[n++] = &grpc_client_channel_filter; |
| 352 | GPR_ASSERT(n <= MAX_FILTERS); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 353 | |
| 354 | f = gpr_malloc(sizeof(*f)); |
| 355 | f->base.vtable = &subchannel_factory_vtable; |
| 356 | gpr_ref_init(&f->refs, 1); |
| 357 | f->mdctx = mdctx; |
| 358 | f->security_connector = connector; |
Craig Tiller | d9a5088 | 2015-06-29 15:57:36 -0700 | [diff] [blame^] | 359 | f->merge_args = grpc_channel_args_copy(args_copy); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 360 | resolver = grpc_resolver_create(target, &f->base); |
| 361 | if (!resolver) { |
| 362 | return NULL; |
| 363 | } |
| 364 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 365 | channel = grpc_channel_create_from_filters(filters, n, args_copy, mdctx, 1); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 366 | grpc_client_channel_set_resolver(grpc_channel_get_channel_stack(channel), resolver); |
| 367 | grpc_resolver_unref(resolver); |
| 368 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 369 | grpc_channel_args_destroy(args_copy); |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 370 | if (new_args_from_connector != NULL) { |
| 371 | grpc_channel_args_destroy(new_args_from_connector); |
| 372 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 373 | |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 374 | #if 0 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 375 | s->target = gpr_strdup(target); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 376 | s->setup_callback = complete_setup; |
| 377 | s->setup_user_data = grpc_channel_get_channel_stack(channel); |
Julien Boeuf | 7d1d9ca | 2015-04-17 14:38:48 -0700 | [diff] [blame] | 378 | s->security_connector = connector; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 379 | grpc_client_setup_create_and_attach(grpc_channel_get_channel_stack(channel), |
| 380 | args, mdctx, initiate_setup, done_setup, |
ctiller | 18b49ab | 2014-12-09 14:39:16 -0800 | [diff] [blame] | 381 | s); |
Craig Tiller | acf0f07 | 2015-06-29 08:24:16 -0700 | [diff] [blame] | 382 | #endif |
| 383 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 384 | return channel; |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 385 | } |