Use overriden host name when creating a call.

Change on 2014/12/22 by yangg <yangg@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=82672321
pull/1/merge
yangg 10 years ago committed by Jan Tattermusch
parent 5b7f32a2bb
commit 7cebec7ccd
  1. 3
      include/grpc++/channel_arguments.h
  2. 6
      src/cpp/client/channel.cc
  3. 9
      src/cpp/client/channel_arguments.cc

@ -70,6 +70,9 @@ class ChannelArguments {
ChannelArguments(const ChannelArguments&); ChannelArguments(const ChannelArguments&);
ChannelArguments& operator=(const ChannelArguments&); ChannelArguments& operator=(const ChannelArguments&);
// Returns empty string when it is not set.
grpc::string GetSslTargetNameOverride() const;
// Populates given channel_args with args_, does not take ownership. // Populates given channel_args with args_, does not take ownership.
void SetChannelArgs(grpc_channel_args* channel_args) const; void SetChannelArgs(grpc_channel_args* channel_args) const;

@ -64,11 +64,13 @@ Channel::Channel(const grpc::string& target, const ChannelArguments& args)
Channel::Channel(const grpc::string& target, Channel::Channel(const grpc::string& target,
const std::unique_ptr<Credentials>& creds, const std::unique_ptr<Credentials>& creds,
const ChannelArguments& args) const ChannelArguments& args)
: target_(target) { : target_(args.GetSslTargetNameOverride().empty()
? target
: args.GetSslTargetNameOverride()) {
grpc_channel_args channel_args; grpc_channel_args channel_args;
args.SetChannelArgs(&channel_args); args.SetChannelArgs(&channel_args);
c_channel_ = grpc_secure_channel_create( c_channel_ = grpc_secure_channel_create(
creds->GetRawCreds(), target_.c_str(), creds->GetRawCreds(), target.c_str(),
channel_args.num_args > 0 ? &channel_args : nullptr); channel_args.num_args > 0 ? &channel_args : nullptr);
} }

@ -41,6 +41,15 @@ void ChannelArguments::SetSslTargetNameOverride(const grpc::string& name) {
SetString(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, name); SetString(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, name);
} }
grpc::string ChannelArguments::GetSslTargetNameOverride() const {
for (int i = 0; i < args_.size(); i++) {
if (grpc::string(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == args_[i].key) {
return args_[i].value.string;
}
}
return "";
}
void ChannelArguments::SetInt(const grpc::string& key, int value) { void ChannelArguments::SetInt(const grpc::string& key, int value) {
grpc_arg arg; grpc_arg arg;
arg.type = GRPC_ARG_INTEGER; arg.type = GRPC_ARG_INTEGER;

Loading…
Cancel
Save