aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2018-09-12 16:58:44 -0700
committerGravatar Yash Tibrewal <yashkt@google.com>2018-09-26 19:25:30 -0700
commita1598c5abfadf9e622d21a5cc0f754b412378314 (patch)
tree2f1358e3a781f503d29fe670107732cc2227f6d7 /src
parentc3db7d21ce1dfbd6f25bde500af62fd1c197928f (diff)
Create interfaces and initial plumbing for interception API
Diffstat (limited to 'src')
-rw-r--r--src/cpp/client/channel_cc.cc8
-rw-r--r--src/cpp/client/create_channel.cc42
-rw-r--r--src/cpp/client/create_channel_internal.cc10
-rw-r--r--src/cpp/client/create_channel_internal.h8
-rw-r--r--src/cpp/client/create_channel_posix.cc9
-rw-r--r--src/cpp/client/cronet_credentials.cc19
-rw-r--r--src/cpp/client/insecure_credentials.cc11
-rw-r--r--src/cpp/client/secure_credentials.cc12
-rw-r--r--src/cpp/client/secure_credentials.h6
-rw-r--r--src/cpp/server/server_cc.cc3
10 files changed, 106 insertions, 22 deletions
diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc
index c59059f045..00430d07db 100644
--- a/src/cpp/client/channel_cc.cc
+++ b/src/cpp/client/channel_cc.cc
@@ -50,8 +50,14 @@
namespace grpc {
static internal::GrpcLibraryInitializer g_gli_initializer;
-Channel::Channel(const grpc::string& host, grpc_channel* channel)
+Channel::Channel(
+ const grpc::string& host, grpc_channel* channel,
+ std::unique_ptr<std::vector<
+ std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>>
+ interceptor_creators)
: host_(host), c_channel_(channel) {
+ auto vector = interceptor_creators.release();
+ interceptor_creators_ = std::move(*vector);
g_gli_initializer.summon();
}
diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc
index 67a46ce0e1..efdff6c265 100644
--- a/src/cpp/client/create_channel.cc
+++ b/src/cpp/client/create_channel.cc
@@ -39,11 +39,43 @@ std::shared_ptr<Channel> CreateCustomChannel(
const std::shared_ptr<ChannelCredentials>& creds,
const ChannelArguments& args) {
GrpcLibraryCodegen init_lib; // We need to call init in case of a bad creds.
- return creds ? creds->CreateChannel(target, args)
- : CreateChannelInternal(
- "", grpc_lame_client_channel_create(
- nullptr, GRPC_STATUS_INVALID_ARGUMENT,
- "Invalid credentials."));
+ return creds
+ ? creds->CreateChannel(target, args)
+ : CreateChannelInternal("",
+ grpc_lame_client_channel_create(
+ nullptr, GRPC_STATUS_INVALID_ARGUMENT,
+ "Invalid credentials."),
+ nullptr);
}
+namespace experimental {
+/// Create a new \em custom \a Channel pointing to \a target with \a
+/// interceptors being invoked per call.
+///
+/// \warning For advanced use and testing ONLY. Override default channel
+/// arguments only if necessary.
+///
+/// \param target The URI of the endpoint to connect to.
+/// \param creds Credentials to use for the created channel. If it does not
+/// hold an object or is invalid, a lame channel (one on which all operations
+/// fail) is returned.
+/// \param args Options for channel creation.
+std::shared_ptr<Channel> CreateCustomChannelWithInterceptors(
+ const grpc::string& target,
+ const std::shared_ptr<ChannelCredentials>& creds,
+ const ChannelArguments& args,
+ std::unique_ptr<std::vector<
+ std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>>
+ interceptor_creators) {
+ return creds
+ ? creds->CreateChannelWithInterceptors(
+ target, args, std::move(interceptor_creators))
+ : CreateChannelInternal("",
+ grpc_lame_client_channel_create(
+ nullptr, GRPC_STATUS_INVALID_ARGUMENT,
+ "Invalid credentials."),
+ nullptr);
+}
+} // namespace experimental
+
} // namespace grpc
diff --git a/src/cpp/client/create_channel_internal.cc b/src/cpp/client/create_channel_internal.cc
index aa96edfcff..313d682aae 100644
--- a/src/cpp/client/create_channel_internal.cc
+++ b/src/cpp/client/create_channel_internal.cc
@@ -24,8 +24,12 @@ struct grpc_channel;
namespace grpc {
-std::shared_ptr<Channel> CreateChannelInternal(const grpc::string& host,
- grpc_channel* c_channel) {
- return std::shared_ptr<Channel>(new Channel(host, c_channel));
+std::shared_ptr<Channel> CreateChannelInternal(
+ const grpc::string& host, grpc_channel* c_channel,
+ std::unique_ptr<std::vector<
+ std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>>
+ interceptor_creators) {
+ return std::shared_ptr<Channel>(
+ new Channel(host, c_channel, std::move(interceptor_creators)));
}
} // namespace grpc
diff --git a/src/cpp/client/create_channel_internal.h b/src/cpp/client/create_channel_internal.h
index 86e8167277..512fc22866 100644
--- a/src/cpp/client/create_channel_internal.h
+++ b/src/cpp/client/create_channel_internal.h
@@ -21,6 +21,7 @@
#include <memory>
+#include <grpcpp/impl/codegen/client_interceptor.h>
#include <grpcpp/support/config.h>
struct grpc_channel;
@@ -28,8 +29,11 @@ struct grpc_channel;
namespace grpc {
class Channel;
-std::shared_ptr<Channel> CreateChannelInternal(const grpc::string& host,
- grpc_channel* c_channel);
+std::shared_ptr<Channel> CreateChannelInternal(
+ const grpc::string& host, grpc_channel* c_channel,
+ std::unique_ptr<std::vector<
+ std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>>
+ interceptor_creators);
} // namespace grpc
diff --git a/src/cpp/client/create_channel_posix.cc b/src/cpp/client/create_channel_posix.cc
index f9285c9b28..b9e5887bcc 100644
--- a/src/cpp/client/create_channel_posix.cc
+++ b/src/cpp/client/create_channel_posix.cc
@@ -33,7 +33,8 @@ std::shared_ptr<Channel> CreateInsecureChannelFromFd(const grpc::string& target,
internal::GrpcLibrary init_lib;
init_lib.init();
return CreateChannelInternal(
- "", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr));
+ "", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr),
+ nullptr);
}
std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd(
@@ -42,8 +43,10 @@ std::shared_ptr<Channel> CreateCustomInsecureChannelFromFd(
init_lib.init();
grpc_channel_args channel_args;
args.SetChannelArgs(&channel_args);
- return CreateChannelInternal("", grpc_insecure_channel_create_from_fd(
- target.c_str(), fd, &channel_args));
+ return CreateChannelInternal(
+ "",
+ grpc_insecure_channel_create_from_fd(target.c_str(), fd, &channel_args),
+ nullptr);
}
#endif // GPR_SUPPORT_CHANNELS_FROM_FD
diff --git a/src/cpp/client/cronet_credentials.cc b/src/cpp/client/cronet_credentials.cc
index 5c65ad05ea..09a76b428c 100644
--- a/src/cpp/client/cronet_credentials.cc
+++ b/src/cpp/client/cronet_credentials.cc
@@ -31,16 +31,25 @@ class CronetChannelCredentialsImpl final : public ChannelCredentials {
std::shared_ptr<grpc::Channel> CreateChannel(
const string& target, const grpc::ChannelArguments& args) override {
- grpc_channel_args channel_args;
- args.SetChannelArgs(&channel_args);
- return CreateChannelInternal(
- "", grpc_cronet_secure_channel_create(engine_, target.c_str(),
- &channel_args, nullptr));
+ return CreateChannelWithInterceptors(target, args, nullptr);
}
SecureChannelCredentials* AsSecureCredentials() override { return nullptr; }
private:
+ std::shared_ptr<grpc::Channel> CreateChannelWithInterceptors(
+ const string& target, const grpc::ChannelArguments& args,
+ std::unique_ptr<std::vector<
+ std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>>
+ interceptor_creators) override {
+ grpc_channel_args channel_args;
+ args.SetChannelArgs(&channel_args);
+ return CreateChannelInternal(
+ "",
+ grpc_cronet_secure_channel_create(engine_, target.c_str(),
+ &channel_args, nullptr),
+ std::move(interceptor_creators));
+ }
void* engine_;
};
diff --git a/src/cpp/client/insecure_credentials.cc b/src/cpp/client/insecure_credentials.cc
index 04dc5c0bcc..b816e0c59a 100644
--- a/src/cpp/client/insecure_credentials.cc
+++ b/src/cpp/client/insecure_credentials.cc
@@ -32,11 +32,20 @@ class InsecureChannelCredentialsImpl final : public ChannelCredentials {
public:
std::shared_ptr<grpc::Channel> CreateChannel(
const string& target, const grpc::ChannelArguments& args) override {
+ return CreateChannelWithInterceptors(target, args, nullptr);
+ }
+
+ std::shared_ptr<grpc::Channel> CreateChannelWithInterceptors(
+ const string& target, const grpc::ChannelArguments& args,
+ std::unique_ptr<std::vector<
+ std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>>
+ interceptor_creators) override {
grpc_channel_args channel_args;
args.SetChannelArgs(&channel_args);
return CreateChannelInternal(
"",
- grpc_insecure_channel_create(target.c_str(), &channel_args, nullptr));
+ grpc_insecure_channel_create(target.c_str(), &channel_args, nullptr),
+ std::move(interceptor_creators));
}
SecureChannelCredentials* AsSecureCredentials() override { return nullptr; }
diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc
index e48fbeb86d..d1cd78e755 100644
--- a/src/cpp/client/secure_credentials.cc
+++ b/src/cpp/client/secure_credentials.cc
@@ -36,12 +36,22 @@ SecureChannelCredentials::SecureChannelCredentials(
std::shared_ptr<grpc::Channel> SecureChannelCredentials::CreateChannel(
const string& target, const grpc::ChannelArguments& args) {
+ return CreateChannelWithInterceptors(target, args, nullptr);
+}
+
+std::shared_ptr<grpc::Channel>
+SecureChannelCredentials::CreateChannelWithInterceptors(
+ const string& target, const grpc::ChannelArguments& args,
+ std::unique_ptr<std::vector<
+ std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>>
+ interceptor_creators) {
grpc_channel_args channel_args;
args.SetChannelArgs(&channel_args);
return CreateChannelInternal(
args.GetSslTargetNameOverride(),
grpc_secure_channel_create(c_creds_, target.c_str(), &channel_args,
- nullptr));
+ nullptr),
+ std::move(interceptor_creators));
}
SecureCallCredentials::SecureCallCredentials(grpc_call_credentials* c_creds)
diff --git a/src/cpp/client/secure_credentials.h b/src/cpp/client/secure_credentials.h
index 85cb54227c..bfb6e17ee9 100644
--- a/src/cpp/client/secure_credentials.h
+++ b/src/cpp/client/secure_credentials.h
@@ -36,9 +36,15 @@ class SecureChannelCredentials final : public ChannelCredentials {
std::shared_ptr<grpc::Channel> CreateChannel(
const string& target, const grpc::ChannelArguments& args) override;
+
SecureChannelCredentials* AsSecureCredentials() override { return this; }
private:
+ std::shared_ptr<grpc::Channel> CreateChannelWithInterceptors(
+ const string& target, const grpc::ChannelArguments& args,
+ std::unique_ptr<std::vector<
+ std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>>
+ interceptor_creators) override;
grpc_channel_credentials* const c_creds_;
};
diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc
index 36f7eb81f9..72371e5384 100644
--- a/src/cpp/server/server_cc.cc
+++ b/src/cpp/server/server_cc.cc
@@ -473,7 +473,8 @@ std::shared_ptr<Channel> Server::InProcessChannel(
const ChannelArguments& args) {
grpc_channel_args channel_args = args.c_channel_args();
return CreateChannelInternal(
- "inproc", grpc_inproc_channel_create(server_, &channel_args, nullptr));
+ "inproc", grpc_inproc_channel_create(server_, &channel_args, nullptr),
+ nullptr);
}
static grpc_server_register_method_payload_handling PayloadHandlingForMethod(