|
|
@ -327,14 +327,16 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { |
|
|
|
if (chand->resolver_result != nullptr) { |
|
|
|
if (chand->resolver_result != nullptr) { |
|
|
|
if (chand->resolver != nullptr) { |
|
|
|
if (chand->resolver != nullptr) { |
|
|
|
// Find LB policy name.
|
|
|
|
// Find LB policy name.
|
|
|
|
const char* lb_policy_name = grpc_channel_args_get_string( |
|
|
|
const grpc_arg* channel_arg = grpc_channel_args_find( |
|
|
|
chand->resolver_result, GRPC_ARG_LB_POLICY_NAME); |
|
|
|
chand->resolver_result, GRPC_ARG_LB_POLICY_NAME); |
|
|
|
|
|
|
|
const char* lb_policy_name = grpc_channel_arg_get_string(channel_arg); |
|
|
|
// Special case: If at least one balancer address is present, we use
|
|
|
|
// Special case: If at least one balancer address is present, we use
|
|
|
|
// the grpclb policy, regardless of what the resolver actually specified.
|
|
|
|
// the grpclb policy, regardless of what the resolver actually specified.
|
|
|
|
grpc_lb_addresses* addresses = |
|
|
|
channel_arg = |
|
|
|
grpc_channel_args_get_pointer<grpc_lb_addresses>( |
|
|
|
grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_ADDRESSES); |
|
|
|
chand->resolver_result, GRPC_ARG_LB_ADDRESSES); |
|
|
|
if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_POINTER) { |
|
|
|
if (addresses != nullptr) { |
|
|
|
grpc_lb_addresses* addresses = |
|
|
|
|
|
|
|
static_cast<grpc_lb_addresses*>(channel_arg->value.pointer.p); |
|
|
|
bool found_balancer_address = false; |
|
|
|
bool found_balancer_address = false; |
|
|
|
for (size_t i = 0; i < addresses->num_addresses; ++i) { |
|
|
|
for (size_t i = 0; i < addresses->num_addresses; ++i) { |
|
|
|
if (addresses->addresses[i].is_balancer) { |
|
|
|
if (addresses->addresses[i].is_balancer) { |
|
|
@ -398,15 +400,18 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) { |
|
|
|
// The copy will be saved in chand->lb_policy_name below.
|
|
|
|
// The copy will be saved in chand->lb_policy_name below.
|
|
|
|
lb_policy_name_dup = gpr_strdup(lb_policy_name); |
|
|
|
lb_policy_name_dup = gpr_strdup(lb_policy_name); |
|
|
|
// Find service config.
|
|
|
|
// Find service config.
|
|
|
|
service_config_json = gpr_strdup(grpc_channel_args_get_string( |
|
|
|
channel_arg = grpc_channel_args_find(chand->resolver_result, |
|
|
|
chand->resolver_result, GRPC_ARG_SERVICE_CONFIG)); |
|
|
|
GRPC_ARG_SERVICE_CONFIG); |
|
|
|
|
|
|
|
service_config_json = |
|
|
|
|
|
|
|
gpr_strdup(grpc_channel_arg_get_string(channel_arg)); |
|
|
|
if (service_config_json != nullptr) { |
|
|
|
if (service_config_json != nullptr) { |
|
|
|
grpc_core::UniquePtr<grpc_core::ServiceConfig> service_config = |
|
|
|
grpc_core::UniquePtr<grpc_core::ServiceConfig> service_config = |
|
|
|
grpc_core::ServiceConfig::Create(service_config_json); |
|
|
|
grpc_core::ServiceConfig::Create(service_config_json); |
|
|
|
if (service_config != nullptr) { |
|
|
|
if (service_config != nullptr) { |
|
|
|
if (chand->enable_retries) { |
|
|
|
if (chand->enable_retries) { |
|
|
|
const char* server_uri = grpc_channel_args_get_string( |
|
|
|
channel_arg = grpc_channel_args_find(chand->resolver_result, |
|
|
|
chand->resolver_result, GRPC_ARG_SERVER_URI); |
|
|
|
GRPC_ARG_SERVER_URI); |
|
|
|
|
|
|
|
const char* server_uri = grpc_channel_arg_get_string(channel_arg); |
|
|
|
GPR_ASSERT(server_uri != nullptr); |
|
|
|
GPR_ASSERT(server_uri != nullptr); |
|
|
|
grpc_uri* uri = grpc_uri_parse(server_uri, true); |
|
|
|
grpc_uri* uri = grpc_uri_parse(server_uri, true); |
|
|
|
GPR_ASSERT(uri->path[0] != '\0'); |
|
|
|
GPR_ASSERT(uri->path[0] != '\0'); |
|
|
@ -643,37 +648,45 @@ static grpc_error* cc_init_channel_elem(grpc_channel_element* elem, |
|
|
|
"client_channel"); |
|
|
|
"client_channel"); |
|
|
|
grpc_client_channel_start_backup_polling(chand->interested_parties); |
|
|
|
grpc_client_channel_start_backup_polling(chand->interested_parties); |
|
|
|
// Record max per-RPC retry buffer size.
|
|
|
|
// Record max per-RPC retry buffer size.
|
|
|
|
chand->per_rpc_retry_buffer_size = (size_t)grpc_channel_args_get_integer( |
|
|
|
const grpc_arg* arg = grpc_channel_args_find( |
|
|
|
args->channel_args, GRPC_ARG_PER_RPC_RETRY_BUFFER_SIZE, |
|
|
|
args->channel_args, GRPC_ARG_PER_RPC_RETRY_BUFFER_SIZE); |
|
|
|
{DEFAULT_PER_RPC_RETRY_BUFFER_SIZE, 0, INT_MAX}); |
|
|
|
chand->per_rpc_retry_buffer_size = (size_t)grpc_channel_arg_get_integer( |
|
|
|
|
|
|
|
arg, {DEFAULT_PER_RPC_RETRY_BUFFER_SIZE, 0, INT_MAX}); |
|
|
|
// Record enable_retries.
|
|
|
|
// Record enable_retries.
|
|
|
|
chand->enable_retries = grpc_channel_args_get_bool( |
|
|
|
arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_ENABLE_RETRIES); |
|
|
|
args->channel_args, GRPC_ARG_ENABLE_RETRIES, true); |
|
|
|
chand->enable_retries = grpc_channel_arg_get_bool(arg, true); |
|
|
|
// Record client channel factory.
|
|
|
|
// Record client channel factory.
|
|
|
|
grpc_client_channel_factory* client_channel_factory = |
|
|
|
arg = grpc_channel_args_find(args->channel_args, |
|
|
|
grpc_channel_args_get_pointer<grpc_client_channel_factory>( |
|
|
|
GRPC_ARG_CLIENT_CHANNEL_FACTORY); |
|
|
|
args->channel_args, GRPC_ARG_CLIENT_CHANNEL_FACTORY); |
|
|
|
if (arg == nullptr) { |
|
|
|
if (client_channel_factory == nullptr) { |
|
|
|
|
|
|
|
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
"Missing or malformed client channel factory in args for client " |
|
|
|
"Missing client channel factory in args for client channel filter"); |
|
|
|
"channel filter"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
grpc_client_channel_factory_ref(client_channel_factory); |
|
|
|
if (arg->type != GRPC_ARG_POINTER) { |
|
|
|
chand->client_channel_factory = client_channel_factory; |
|
|
|
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
|
|
|
|
"client channel factory arg must be a pointer"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
grpc_client_channel_factory_ref( |
|
|
|
|
|
|
|
static_cast<grpc_client_channel_factory*>(arg->value.pointer.p)); |
|
|
|
|
|
|
|
chand->client_channel_factory = |
|
|
|
|
|
|
|
static_cast<grpc_client_channel_factory*>(arg->value.pointer.p); |
|
|
|
// Get server name to resolve, using proxy mapper if needed.
|
|
|
|
// Get server name to resolve, using proxy mapper if needed.
|
|
|
|
char* server_uri = |
|
|
|
arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVER_URI); |
|
|
|
grpc_channel_args_get_string(args->channel_args, GRPC_ARG_SERVER_URI); |
|
|
|
if (arg == nullptr) { |
|
|
|
if (server_uri == nullptr) { |
|
|
|
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
|
|
|
|
"Missing server uri in args for client channel filter"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (arg->type != GRPC_ARG_STRING) { |
|
|
|
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
"Missing or malformed server uri in args for client channel filter"); |
|
|
|
"server uri arg must be a string"); |
|
|
|
} |
|
|
|
} |
|
|
|
char* proxy_name = nullptr; |
|
|
|
char* proxy_name = nullptr; |
|
|
|
grpc_channel_args* new_args = nullptr; |
|
|
|
grpc_channel_args* new_args = nullptr; |
|
|
|
grpc_proxy_mappers_map_name(server_uri, args->channel_args, &proxy_name, |
|
|
|
grpc_proxy_mappers_map_name(arg->value.string, args->channel_args, |
|
|
|
&new_args); |
|
|
|
&proxy_name, &new_args); |
|
|
|
// Instantiate resolver.
|
|
|
|
// Instantiate resolver.
|
|
|
|
chand->resolver = grpc_core::ResolverRegistry::CreateResolver( |
|
|
|
chand->resolver = grpc_core::ResolverRegistry::CreateResolver( |
|
|
|
proxy_name != nullptr ? proxy_name : server_uri, |
|
|
|
proxy_name != nullptr ? proxy_name : arg->value.string, |
|
|
|
new_args != nullptr ? new_args : args->channel_args, |
|
|
|
new_args != nullptr ? new_args : args->channel_args, |
|
|
|
chand->interested_parties, chand->combiner); |
|
|
|
chand->interested_parties, chand->combiner); |
|
|
|
if (proxy_name != nullptr) gpr_free(proxy_name); |
|
|
|
if (proxy_name != nullptr) gpr_free(proxy_name); |
|
|
|