Fix grpclb code.

pull/8795/head
Mark D. Roth 8 years ago
parent c217e490b1
commit f75d26925f
  1. 8
      src/core/ext/lb_policy/grpclb/grpclb.c
  2. 26
      src/core/ext/transport/chttp2/client/insecure/channel_create.c
  3. 24
      src/core/ext/transport/chttp2/client/secure/secure_channel_create.c

@ -818,9 +818,15 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx,
* We need the LB channel to return addresses with is_balancer=false
* so that it does not wind up recursively using the grpclb LB policy,
* as per the special case logic in client_channel.c.
*
* Finally, we also strip out the channel arg for the server URI,
* since that will be different for the LB channel than for the parent
* channel. (The client channel factory will re-add this arg with
* the right value.)
*/
static const char *keys_to_remove[] = {GRPC_ARG_LB_POLICY_NAME,
GRPC_ARG_LB_ADDRESSES};
GRPC_ARG_LB_ADDRESSES,
GRPC_ARG_SERVER_URI};
grpc_channel_args *new_args = grpc_channel_args_copy_and_remove(
args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove));
glb_policy->lb_channel = grpc_client_channel_factory_create_channel(

@ -65,7 +65,16 @@ static grpc_channel *client_channel_factory_create_channel(
grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
const char *target, grpc_client_channel_type type,
const grpc_channel_args *args) {
return grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL);
// Add channel arg containing the server URI.
grpc_arg arg;
arg.type = GRPC_ARG_STRING;
arg.key = GRPC_ARG_SERVER_URI;
arg.value.string = (char *)target;
grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args,
GRPC_CLIENT_CHANNEL, NULL);
grpc_channel_args_destroy(new_args);
return channel;
}
static const grpc_client_channel_factory_vtable client_channel_factory_vtable =
@ -90,19 +99,14 @@ grpc_channel *grpc_insecure_channel_create(const char *target,
GPR_ASSERT(reserved == NULL);
grpc_client_channel_factory *factory =
(grpc_client_channel_factory *)&client_channel_factory;
// Add channel args containing the server name and client channel factory.
grpc_arg new_args[2];
new_args[0].type = GRPC_ARG_STRING;
new_args[0].key = GRPC_ARG_SERVER_URI;
new_args[0].value.string = (char *)target;
new_args[1] = grpc_client_channel_factory_create_channel_arg(factory);
grpc_channel_args *args_copy =
grpc_channel_args_copy_and_add(args, new_args, GPR_ARRAY_SIZE(new_args));
// Add channel arg containing the client channel factory.
grpc_arg arg = grpc_client_channel_factory_create_channel_arg(factory);
grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
// Create channel.
grpc_channel *channel = client_channel_factory_create_channel(
&exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, args_copy);
&exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args);
// Clean up.
grpc_channel_args_destroy(args_copy);
grpc_channel_args_destroy(new_args);
grpc_client_channel_factory_unref(&exec_ctx, factory);
grpc_exec_ctx_finish(&exec_ctx);
return channel != NULL ? channel : grpc_lame_client_channel_create(

@ -89,7 +89,16 @@ static grpc_channel *client_channel_factory_create_channel(
grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
const char *target, grpc_client_channel_type type,
const grpc_channel_args *args) {
return grpc_channel_create(exec_ctx, target, args, GRPC_CLIENT_CHANNEL, NULL);
// Add channel arg containing the server URI.
grpc_arg arg;
arg.type = GRPC_ARG_STRING;
arg.key = GRPC_ARG_SERVER_URI;
arg.value.string = (char *)target;
grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args,
GRPC_CLIENT_CHANNEL, NULL);
grpc_channel_args_destroy(new_args);
return channel;
}
static const grpc_client_channel_factory_vtable client_channel_factory_vtable =
@ -137,14 +146,11 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds,
GRPC_SECURITY_CONNECTOR_REF(&security_connector->base,
"grpc_secure_channel_create");
f->security_connector = security_connector;
// Add channel args containing the server name, client channel
// factory, and security connector.
grpc_arg new_args[3];
new_args[0].type = GRPC_ARG_STRING;
new_args[0].key = GRPC_ARG_SERVER_URI;
new_args[0].value.string = (char *)target;
new_args[1] = grpc_client_channel_factory_create_channel_arg(&f->base);
new_args[2] = grpc_security_connector_to_arg(&security_connector->base);
// Add channel args containing the client channel factory and security
// connector.
grpc_arg new_args[2];
new_args[0] = grpc_client_channel_factory_create_channel_arg(&f->base);
new_args[1] = grpc_security_connector_to_arg(&security_connector->base);
grpc_channel_args *args_copy = grpc_channel_args_copy_and_add(
new_args_from_connector != NULL ? new_args_from_connector : args,
new_args, GPR_ARRAY_SIZE(new_args));

Loading…
Cancel
Save