diff options
author | 2018-02-26 13:17:06 -0800 | |
---|---|---|
committer | 2018-02-26 14:39:26 -0800 | |
commit | 3e7f2df04749720dc55a265c5ff03f9fbda2b44c (patch) | |
tree | ce7db5e3a31faac6fe23b12bfa9eec92e1440e16 /src/core/ext/transport | |
parent | 200dffc822bb8383ef325b75861eff21f911e98e (diff) |
Convert slice hash table and service config code to C++.
Diffstat (limited to 'src/core/ext/transport')
-rw-r--r-- | src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index dcfcd243a9..a82009ff69 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -30,10 +30,11 @@ #include "src/core/ext/filters/client_channel/uri_parser.h" #include "src/core/ext/transport/chttp2/client/chttp2_connector.h" #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/security_connector/security_connector.h" -#include "src/core/lib/security/transport/lb_targets_info.h" +#include "src/core/lib/security/transport/target_authority_table.h" #include "src/core/lib/slice/slice_hash_table.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/api_trace.h" @@ -73,11 +74,11 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( const char* server_uri_path; server_uri_path = server_uri->path[0] == '/' ? server_uri->path + 1 : server_uri->path; - const grpc_slice_hash_table* targets_info = - grpc_lb_targets_info_find_in_args(args->args); - char* target_name_to_check = nullptr; - if (targets_info != nullptr) { // LB channel - // Find the balancer name for the target. + const grpc_core::TargetAuthorityTable* target_authority_table = + grpc_core::FindTargetAuthorityTableInArgs(args->args); + grpc_core::UniquePtr<char> authority; + if (target_authority_table != nullptr) { + // Find the authority for the target. const char* target_uri_str = grpc_get_subchannel_address_uri_arg(args->args); grpc_uri* target_uri = @@ -86,37 +87,33 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( if (target_uri->path[0] != '\0') { // "path" may be empty const grpc_slice key = grpc_slice_from_static_string( target_uri->path[0] == '/' ? target_uri->path + 1 : target_uri->path); - const char* value = static_cast<const char*>( - grpc_slice_hash_table_get(targets_info, key)); - if (value != nullptr) target_name_to_check = gpr_strdup(value); + const grpc_core::UniquePtr<char>* value = + target_authority_table->Get(key); + if (value != nullptr) authority.reset(gpr_strdup(value->get())); grpc_slice_unref_internal(key); } - if (target_name_to_check == nullptr) { - // If the target name to check hasn't already been set, fall back to using - // SERVER_URI - target_name_to_check = gpr_strdup(server_uri_path); - } grpc_uri_destroy(target_uri); - } else { // regular channel: the secure name is the original server URI. - target_name_to_check = gpr_strdup(server_uri_path); + } + // If the authority hasn't already been set (either because no target + // authority table was present or because the target was not present + // in the table), fall back to using the original server URI. + if (authority == nullptr) { + authority.reset(gpr_strdup(server_uri_path)); } grpc_uri_destroy(server_uri); - GPR_ASSERT(target_name_to_check != nullptr); grpc_channel_security_connector* subchannel_security_connector = nullptr; // Create the security connector using the credentials and target name. grpc_channel_args* new_args_from_connector = nullptr; const grpc_security_status security_status = grpc_channel_credentials_create_security_connector( - channel_credentials, target_name_to_check, args->args, + channel_credentials, authority.get(), args->args, &subchannel_security_connector, &new_args_from_connector); if (security_status != GRPC_SECURITY_OK) { gpr_log(GPR_ERROR, "Failed to create secure subchannel for secure name '%s'", - target_name_to_check); - gpr_free(target_name_to_check); + authority.get()); return nullptr; } - gpr_free(target_name_to_check); grpc_arg new_security_connector_arg = grpc_security_connector_to_arg(&subchannel_security_connector->base); |