aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile154
-rw-r--r--build.json121
-rw-r--r--include/grpc++/channel_arguments.h6
-rw-r--r--include/grpc++/create_channel.h3
-rw-r--r--include/grpc++/credentials.h95
-rw-r--r--src/cpp/client/channel.cc40
-rw-r--r--src/cpp/client/channel.h7
-rw-r--r--src/cpp/client/create_channel.cc7
-rw-r--r--src/cpp/client/credentials.cc77
-rw-r--r--src/cpp/client/insecure_credentials.cc60
-rw-r--r--src/cpp/client/secure_credentials.cc128
-rw-r--r--test/cpp/client/credentials_test.cc3
-rw-r--r--test/cpp/end2end/async_end2end_test.cc67
-rw-r--r--test/cpp/end2end/end2end_test.cc14
-rw-r--r--test/cpp/interop/client.cc17
-rw-r--r--test/cpp/interop/server.cc7
-rw-r--r--test/cpp/util/create_test_channel.cc11
17 files changed, 524 insertions, 293 deletions
diff --git a/Makefile b/Makefile
index b018febea1..8bb6b7f1ac 100644
--- a/Makefile
+++ b/Makefile
@@ -908,13 +908,13 @@ static: static_c static_cxx
static_c: $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a
-static_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++.a
+static_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a
shared: shared_c shared_cxx
shared_c: $(LIBDIR)/$(CONFIG)/libgpr.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT)
-shared_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++.$(SHARED_EXT)
+shared_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.$(SHARED_EXT)
shared_csharp: shared_c $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT)
grpc_csharp_ext: shared_csharp
@@ -1794,6 +1794,8 @@ strip-static_cxx: static_cxx
ifeq ($(CONFIG),opt)
$(E) "[STRIP] Stripping libgrpc++.a"
$(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++.a
+ $(E) "[STRIP] Stripping libgrpc++_unsecure.a"
+ $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a
endif
strip-shared_c: shared_c
@@ -1810,6 +1812,8 @@ strip-shared_cxx: shared_cxx
ifeq ($(CONFIG),opt)
$(E) "[STRIP] Stripping libgrpc++.so"
$(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++.$(SHARED_EXT)
+ $(E) "[STRIP] Stripping libgrpc++_unsecure.so"
+ $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.$(SHARED_EXT)
endif
strip-shared_csharp: shared_csharp
@@ -1969,6 +1973,9 @@ install-static_cxx: static_cxx strip-static_cxx
$(E) "[INSTALL] Installing libgrpc++.a"
$(Q) $(INSTALL) -d $(prefix)/lib
$(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++.a $(prefix)/lib/libgrpc++.a
+ $(E) "[INSTALL] Installing libgrpc++_unsecure.a"
+ $(Q) $(INSTALL) -d $(prefix)/lib
+ $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(prefix)/lib/libgrpc++_unsecure.a
@@ -2033,6 +2040,19 @@ ifneq ($(SYSTEM),Darwin)
$(Q) ln -sf libgrpc++.$(SHARED_EXT) $(prefix)/lib/libgrpc++.so
endif
endif
+ifeq ($(SYSTEM),MINGW32)
+ $(E) "[INSTALL] Installing grpc++_unsecure.$(SHARED_EXT)"
+ $(Q) $(INSTALL) -d $(prefix)/lib
+ $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/grpc++_unsecure.$(SHARED_EXT) $(prefix)/lib/grpc++_unsecure.$(SHARED_EXT)
+ $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure-imp.a $(prefix)/lib/libgrpc++_unsecure-imp.a
+else
+ $(E) "[INSTALL] Installing libgrpc++_unsecure.$(SHARED_EXT)"
+ $(Q) $(INSTALL) -d $(prefix)/lib
+ $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.$(SHARED_EXT) $(prefix)/lib/libgrpc++_unsecure.$(SHARED_EXT)
+ifneq ($(SYSTEM),Darwin)
+ $(Q) ln -sf libgrpc++_unsecure.$(SHARED_EXT) $(prefix)/lib/libgrpc++_unsecure.so
+endif
+endif
ifneq ($(SYSTEM),MINGW32)
ifneq ($(SYSTEM),Darwin)
$(Q) ldconfig || true
@@ -3004,12 +3024,14 @@ $(OBJDIR)/$(CONFIG)/src/core/transport/transport.o:
LIBGRPC++_SRC = \
+ src/cpp/client/secure_credentials.cc \
src/cpp/client/channel.cc \
src/cpp/client/channel_arguments.cc \
src/cpp/client/client_context.cc \
src/cpp/client/client_unary_call.cc \
src/cpp/client/create_channel.cc \
src/cpp/client/credentials.cc \
+ src/cpp/client/insecure_credentials.cc \
src/cpp/client/internal_stub.cc \
src/cpp/common/call.cc \
src/cpp/common/completion_queue.cc \
@@ -3081,12 +3103,14 @@ ifneq ($(OPENSSL_DEP),)
# This is to ensure the embedded OpenSSL is built beforehand, properly
# installing headers to their final destination on the drive. We need this
# otherwise parallel compilation will fail if a source is compiled first.
+src/cpp/client/secure_credentials.cc: $(OPENSSL_DEP)
src/cpp/client/channel.cc: $(OPENSSL_DEP)
src/cpp/client/channel_arguments.cc: $(OPENSSL_DEP)
src/cpp/client/client_context.cc: $(OPENSSL_DEP)
src/cpp/client/client_unary_call.cc: $(OPENSSL_DEP)
src/cpp/client/create_channel.cc: $(OPENSSL_DEP)
src/cpp/client/credentials.cc: $(OPENSSL_DEP)
+src/cpp/client/insecure_credentials.cc: $(OPENSSL_DEP)
src/cpp/client/internal_stub.cc: $(OPENSSL_DEP)
src/cpp/common/call.cc: $(OPENSSL_DEP)
src/cpp/common/completion_queue.cc: $(OPENSSL_DEP)
@@ -3106,6 +3130,13 @@ $(LIBDIR)/$(CONFIG)/libgrpc++.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(PROTOBUF_DEP) $(LI
$(Q) mkdir -p `dirname $@`
$(Q) rm -f $(LIBDIR)/$(CONFIG)/libgrpc++.a
$(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBGRPC++_OBJS)
+ $(Q) rm -rf tmp-merge
+ $(Q) mkdir tmp-merge
+ $(Q) ( cd tmp-merge ; $(AR) x ../$(LIBDIR)/$(CONFIG)/libgrpc++.a )
+ $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge ; ar x ../$${l} ) ; done
+ $(Q) rm -f $(LIBDIR)/$(CONFIG)/libgrpc++.a tmp-merge/__.SYMDEF*
+ $(Q) ar rcs $(LIBDIR)/$(CONFIG)/libgrpc++.a tmp-merge/*
+ $(Q) rm -rf tmp-merge
ifeq ($(SYSTEM),Darwin)
$(Q) ranlib $(LIBDIR)/$(CONFIG)/libgrpc++.a
endif
@@ -3140,12 +3171,14 @@ ifneq ($(NO_DEPS),true)
endif
endif
+$(OBJDIR)/$(CONFIG)/src/cpp/client/secure_credentials.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/channel.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/channel_arguments.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/client_context.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/client_unary_call.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/create_channel.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/credentials.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/client/insecure_credentials.o:
$(OBJDIR)/$(CONFIG)/src/cpp/client/internal_stub.o:
$(OBJDIR)/$(CONFIG)/src/cpp/common/call.o:
$(OBJDIR)/$(CONFIG)/src/cpp/common/completion_queue.o:
@@ -3225,6 +3258,123 @@ endif
$(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(GENDIR)/test/cpp/util/messages.pb.cc $(GENDIR)/test/cpp/util/echo.pb.cc $(GENDIR)/test/cpp/util/echo_duplicate.pb.cc
+LIBGRPC++_UNSECURE_SRC = \
+ src/cpp/client/channel.cc \
+ src/cpp/client/channel_arguments.cc \
+ src/cpp/client/client_context.cc \
+ src/cpp/client/client_unary_call.cc \
+ src/cpp/client/create_channel.cc \
+ src/cpp/client/credentials.cc \
+ src/cpp/client/insecure_credentials.cc \
+ src/cpp/client/internal_stub.cc \
+ src/cpp/common/call.cc \
+ src/cpp/common/completion_queue.cc \
+ src/cpp/common/rpc_method.cc \
+ src/cpp/proto/proto_utils.cc \
+ src/cpp/server/server.cc \
+ src/cpp/server/server_builder.cc \
+ src/cpp/server/server_context.cc \
+ src/cpp/server/server_credentials.cc \
+ src/cpp/server/thread_pool.cc \
+ src/cpp/util/status.cc \
+ src/cpp/util/time.cc \
+
+PUBLIC_HEADERS_CXX += \
+ include/grpc++/async_unary_call.h \
+ include/grpc++/channel_arguments.h \
+ include/grpc++/channel_interface.h \
+ include/grpc++/client_context.h \
+ include/grpc++/completion_queue.h \
+ include/grpc++/config.h \
+ include/grpc++/create_channel.h \
+ include/grpc++/credentials.h \
+ include/grpc++/impl/call.h \
+ include/grpc++/impl/client_unary_call.h \
+ include/grpc++/impl/internal_stub.h \
+ include/grpc++/impl/rpc_method.h \
+ include/grpc++/impl/rpc_service_method.h \
+ include/grpc++/impl/service_type.h \
+ include/grpc++/server.h \
+ include/grpc++/server_builder.h \
+ include/grpc++/server_context.h \
+ include/grpc++/server_credentials.h \
+ include/grpc++/status.h \
+ include/grpc++/status_code_enum.h \
+ include/grpc++/stream.h \
+ include/grpc++/thread_pool_interface.h \
+
+LIBGRPC++_UNSECURE_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC++_UNSECURE_SRC))))
+
+ifeq ($(NO_PROTOBUF),true)
+
+# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay.
+
+$(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a: protobuf_dep_error
+
+ifeq ($(SYSTEM),MINGW32)
+$(LIBDIR)/$(CONFIG)/grpc++_unsecure.$(SHARED_EXT): protobuf_dep_error
+else
+$(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.$(SHARED_EXT): protobuf_dep_error
+endif
+
+else
+
+$(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBGRPC++_UNSECURE_OBJS)
+ $(E) "[AR] Creating $@"
+ $(Q) mkdir -p `dirname $@`
+ $(Q) rm -f $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a
+ $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBGRPC++_UNSECURE_OBJS)
+ifeq ($(SYSTEM),Darwin)
+ $(Q) ranlib $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a
+endif
+
+
+
+ifeq ($(SYSTEM),MINGW32)
+$(LIBDIR)/$(CONFIG)/grpc++_unsecure.$(SHARED_EXT): $(LIBGRPC++_UNSECURE_OBJS) $(ZLIB_DEP)$(LIBDIR)/$(CONFIG)/gpr.$(SHARED_EXT)$(LIBDIR)/$(CONFIG)/grpc_unsecure.$(SHARED_EXT)
+ $(E) "[LD] Linking $@"
+ $(Q) mkdir -p `dirname $@`
+ $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=$(LIBDIR)/$(CONFIG)/grpc++_unsecure.def -Wl,--out-implib=$(LIBDIR)/$(CONFIG)/libgrpc++_unsecure-imp.a -o $(LIBDIR)/$(CONFIG)/grpc++_unsecure.$(SHARED_EXT) $(LIBGRPC++_UNSECURE_OBJS) $(LDLIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgpr-imp -lgrpc_unsecure-imp
+else
+$(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.$(SHARED_EXT): $(LIBGRPC++_UNSECURE_OBJS) $(ZLIB_DEP) $(LIBDIR)/$(CONFIG)/libgpr.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT)
+ $(E) "[LD] Linking $@"
+ $(Q) mkdir -p `dirname $@`
+ifeq ($(SYSTEM),Darwin)
+ $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.$(SHARED_EXT) $(LIBGRPC++_UNSECURE_OBJS) $(LDLIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgpr -lgrpc_unsecure
+else
+ $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_unsecure.so.0 -o $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.$(SHARED_EXT) $(LIBGRPC++_UNSECURE_OBJS) $(LDLIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgpr -lgrpc_unsecure
+ $(Q) ln -sf libgrpc++_unsecure.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.so.0
+ $(Q) ln -sf libgrpc++_unsecure.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.so
+endif
+endif
+
+endif
+
+ifneq ($(NO_DEPS),true)
+-include $(LIBGRPC++_UNSECURE_OBJS:.o=.dep)
+endif
+
+$(OBJDIR)/$(CONFIG)/src/cpp/client/channel.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/client/channel_arguments.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/client/client_context.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/client/client_unary_call.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/client/create_channel.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/client/credentials.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/client/insecure_credentials.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/client/internal_stub.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/common/call.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/common/completion_queue.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/common/rpc_method.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/proto/proto_utils.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/server/server.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/server/server_builder.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/server/server_context.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/server/server_credentials.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/server/thread_pool.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/util/status.o:
+$(OBJDIR)/$(CONFIG)/src/cpp/util/time.o:
+
+
LIBPUBSUB_CLIENT_LIB_SRC = \
$(GENDIR)/examples/pubsub/label.pb.cc \
$(GENDIR)/examples/pubsub/empty.pb.cc \
diff --git a/build.json b/build.json
index f6ef33b25f..9ab59f9379 100644
--- a/build.json
+++ b/build.json
@@ -10,6 +10,60 @@
},
"filegroups": [
{
+ "name": "grpc++_base",
+ "public_headers": [
+ "include/grpc++/async_unary_call.h",
+ "include/grpc++/channel_arguments.h",
+ "include/grpc++/channel_interface.h",
+ "include/grpc++/client_context.h",
+ "include/grpc++/completion_queue.h",
+ "include/grpc++/config.h",
+ "include/grpc++/create_channel.h",
+ "include/grpc++/credentials.h",
+ "include/grpc++/impl/call.h",
+ "include/grpc++/impl/client_unary_call.h",
+ "include/grpc++/impl/internal_stub.h",
+ "include/grpc++/impl/rpc_method.h",
+ "include/grpc++/impl/rpc_service_method.h",
+ "include/grpc++/impl/service_type.h",
+ "include/grpc++/server.h",
+ "include/grpc++/server_builder.h",
+ "include/grpc++/server_context.h",
+ "include/grpc++/server_credentials.h",
+ "include/grpc++/status.h",
+ "include/grpc++/status_code_enum.h",
+ "include/grpc++/stream.h",
+ "include/grpc++/thread_pool_interface.h"
+ ],
+ "headers": [
+ "src/cpp/client/channel.h",
+ "src/cpp/proto/proto_utils.h",
+ "src/cpp/server/thread_pool.h",
+ "src/cpp/util/time.h"
+ ],
+ "src": [
+ "src/cpp/client/channel.cc",
+ "src/cpp/client/channel_arguments.cc",
+ "src/cpp/client/client_context.cc",
+ "src/cpp/client/client_unary_call.cc",
+ "src/cpp/client/create_channel.cc",
+ "src/cpp/client/credentials.cc",
+ "src/cpp/client/insecure_credentials.cc",
+ "src/cpp/client/internal_stub.cc",
+ "src/cpp/common/call.cc",
+ "src/cpp/common/completion_queue.cc",
+ "src/cpp/common/rpc_method.cc",
+ "src/cpp/proto/proto_utils.cc",
+ "src/cpp/server/server.cc",
+ "src/cpp/server/server_builder.cc",
+ "src/cpp/server/server_context.cc",
+ "src/cpp/server/server_credentials.cc",
+ "src/cpp/server/thread_pool.cc",
+ "src/cpp/util/status.cc",
+ "src/cpp/util/time.cc"
+ ]
+ },
+ {
"name": "grpc_base",
"public_headers": [
"include/grpc/byte_buffer.h",
@@ -383,60 +437,17 @@
"name": "grpc++",
"build": "all",
"language": "c++",
- "public_headers": [
- "include/grpc++/async_unary_call.h",
- "include/grpc++/channel_arguments.h",
- "include/grpc++/channel_interface.h",
- "include/grpc++/client_context.h",
- "include/grpc++/completion_queue.h",
- "include/grpc++/config.h",
- "include/grpc++/create_channel.h",
- "include/grpc++/credentials.h",
- "include/grpc++/impl/call.h",
- "include/grpc++/impl/client_unary_call.h",
- "include/grpc++/impl/internal_stub.h",
- "include/grpc++/impl/rpc_method.h",
- "include/grpc++/impl/rpc_service_method.h",
- "include/grpc++/impl/service_type.h",
- "include/grpc++/server.h",
- "include/grpc++/server_builder.h",
- "include/grpc++/server_context.h",
- "include/grpc++/server_credentials.h",
- "include/grpc++/status.h",
- "include/grpc++/status_code_enum.h",
- "include/grpc++/stream.h",
- "include/grpc++/thread_pool_interface.h"
- ],
- "headers": [
- "src/cpp/client/channel.h",
- "src/cpp/proto/proto_utils.h",
- "src/cpp/server/thread_pool.h",
- "src/cpp/util/time.h"
- ],
"src": [
- "src/cpp/client/channel.cc",
- "src/cpp/client/channel_arguments.cc",
- "src/cpp/client/client_context.cc",
- "src/cpp/client/client_unary_call.cc",
- "src/cpp/client/create_channel.cc",
- "src/cpp/client/credentials.cc",
- "src/cpp/client/internal_stub.cc",
- "src/cpp/common/call.cc",
- "src/cpp/common/completion_queue.cc",
- "src/cpp/common/rpc_method.cc",
- "src/cpp/proto/proto_utils.cc",
- "src/cpp/server/server.cc",
- "src/cpp/server/server_builder.cc",
- "src/cpp/server/server_context.cc",
- "src/cpp/server/server_credentials.cc",
- "src/cpp/server/thread_pool.cc",
- "src/cpp/util/status.cc",
- "src/cpp/util/time.cc"
+ "src/cpp/client/secure_credentials.cc"
],
"deps": [
"gpr",
"grpc"
],
+ "baselib": true,
+ "filegroups": [
+ "grpc++_base"
+ ],
"secure": true,
"vs_project_guid": "{C187A093-A0FE-489D-A40A-6E33DE0F9FEB}"
},
@@ -452,6 +463,20 @@
]
},
{
+ "name": "grpc++_unsecure",
+ "build": "all",
+ "language": "c++",
+ "deps": [
+ "gpr",
+ "grpc_unsecure"
+ ],
+ "baselib": true,
+ "filegroups": [
+ "grpc++_base"
+ ],
+ "secure": false
+ },
+ {
"name": "pubsub_client_lib",
"build": "private",
"language": "c++",
diff --git a/include/grpc++/channel_arguments.h b/include/grpc++/channel_arguments.h
index 75c3cf45b4..91f89f313e 100644
--- a/include/grpc++/channel_arguments.h
+++ b/include/grpc++/channel_arguments.h
@@ -62,6 +62,9 @@ class ChannelArguments {
void SetInt(const grpc::string& key, int value);
void SetString(const grpc::string& key, const grpc::string& value);
+ // Populates given channel_args with args_, does not take ownership.
+ void SetChannelArgs(grpc_channel_args* channel_args) const;
+
private:
friend class Channel;
friend class testing::ChannelArgumentsTest;
@@ -73,9 +76,6 @@ class ChannelArguments {
// Returns empty string when it is not set.
grpc::string GetSslTargetNameOverride() const;
- // Populates given channel_args with args_, does not take ownership.
- void SetChannelArgs(grpc_channel_args* channel_args) const;
-
std::vector<grpc_arg> args_;
std::list<grpc::string> strings_;
};
diff --git a/include/grpc++/create_channel.h b/include/grpc++/create_channel.h
index eadabda359..2c40047e9a 100644
--- a/include/grpc++/create_channel.h
+++ b/include/grpc++/create_channel.h
@@ -43,9 +43,6 @@ namespace grpc {
class ChannelArguments;
class ChannelInterface;
-std::shared_ptr<ChannelInterface> CreateChannel(const grpc::string& target,
- const ChannelArguments& args);
-
// If creds does not hold an object or is invalid, a lame channel is returned.
std::shared_ptr<ChannelInterface> CreateChannel(
const grpc::string& target, const std::unique_ptr<Credentials>& creds,
diff --git a/include/grpc++/credentials.h b/include/grpc++/credentials.h
index ac6f394847..b462b450da 100644
--- a/include/grpc++/credentials.h
+++ b/include/grpc++/credentials.h
@@ -39,29 +39,21 @@
#include <grpc++/config.h>
-struct grpc_credentials;
-
namespace grpc {
+class ChannelArguments;
+class ChannelInterface;
-// grpc_credentials wrapper class. Typical use in C++ applications is limited
-// to creating an instance using CredentialsFactory, and passing it down
-// during channel construction.
-
-class Credentials final {
+class Credentials {
public:
- ~Credentials();
-
- // TODO(abhikumar): Specify a plugin API here to be implemented by
- // credentials that do not have a corresponding implementation in C.
+ virtual ~Credentials();
private:
- explicit Credentials(grpc_credentials*);
- grpc_credentials* GetRawCreds();
-
- friend class Channel;
- friend class CredentialsFactory;
+ friend std::shared_ptr<ChannelInterface> CreateChannel(
+ const grpc::string& target, const std::unique_ptr<Credentials>& creds,
+ const ChannelArguments& args);
- grpc_credentials* creds_;
+ virtual std::shared_ptr<ChannelInterface> CreateChannel(
+ const grpc::string& target, const ChannelArguments& args) = 0;
};
// Options used to build SslCredentials
@@ -79,43 +71,44 @@ struct SslCredentialsOptions {
grpc::string pem_cert_chain;
};
-// Factory for building different types of Credentials
-// The methods may return empty unique_ptr when credentials cannot be created.
+// Factories for building different types of Credentials
+// The functions may return empty unique_ptr when credentials cannot be created.
// If a Credentials pointer is returned, it can still be invalid when used to
// create a channel. A lame channel will be created then and all rpcs will
// fail on it.
-class CredentialsFactory {
- public:
- // Builds credentials with reasonable defaults.
- static std::unique_ptr<Credentials> DefaultCredentials();
-
- // Builds SSL Credentials given SSL specific options
- static std::unique_ptr<Credentials> SslCredentials(
- const SslCredentialsOptions& options);
-
- // Builds credentials for use when running in GCE
- static std::unique_ptr<Credentials> ComputeEngineCredentials();
-
- // Builds service account credentials.
- // json_key is the JSON key string containing the client's private key.
- // scope is a space-delimited list of the requested permissions.
- // token_lifetime is the lifetime of each token acquired through this service
- // account credentials. It should be positive and should not exceed
- // grpc_max_auth_token_lifetime or will be cropped to this value.
- static std::unique_ptr<Credentials> ServiceAccountCredentials(
- const grpc::string& json_key, const grpc::string& scope,
- std::chrono::seconds token_lifetime);
-
- // Builds IAM credentials.
- static std::unique_ptr<Credentials> IAMCredentials(
- const grpc::string& authorization_token,
- const grpc::string& authority_selector);
-
- // Combines two credentials objects into a composite credentials
- static std::unique_ptr<Credentials> ComposeCredentials(
- const std::unique_ptr<Credentials>& creds1,
- const std::unique_ptr<Credentials>& creds2);
-};
+
+// Builds credentials with reasonable defaults.
+std::unique_ptr<Credentials> DefaultCredentials();
+
+// Builds SSL Credentials given SSL specific options
+std::unique_ptr<Credentials> SslCredentials(
+ const SslCredentialsOptions& options);
+
+// Builds credentials for use when running in GCE
+std::unique_ptr<Credentials> ComputeEngineCredentials();
+
+// Builds service account credentials.
+// json_key is the JSON key string containing the client's private key.
+// scope is a space-delimited list of the requested permissions.
+// token_lifetime is the lifetime of each token acquired through this service
+// account credentials. It should be positive and should not exceed
+// grpc_max_auth_token_lifetime or will be cropped to this value.
+std::unique_ptr<Credentials> ServiceAccountCredentials(
+ const grpc::string& json_key, const grpc::string& scope,
+ std::chrono::seconds token_lifetime);
+
+// Builds IAM credentials.
+std::unique_ptr<Credentials> IAMCredentials(
+ const grpc::string& authorization_token,
+ const grpc::string& authority_selector);
+
+// Combines two credentials objects into a composite credentials
+std::unique_ptr<Credentials> ComposeCredentials(
+ const std::unique_ptr<Credentials>& creds1,
+ const std::unique_ptr<Credentials>& creds2);
+
+// Credentials for an unencrypted, unauthenticated channel
+std::unique_ptr<Credentials> InsecureCredentials();
} // namespace grpc
diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc
index ca69d66cbb..65bd135d5c 100644
--- a/src/cpp/client/channel.cc
+++ b/src/cpp/client/channel.cc
@@ -54,43 +54,23 @@
namespace grpc {
-Channel::Channel(const grpc::string &target, const ChannelArguments &args)
- : target_(target) {
- grpc_channel_args channel_args;
- args.SetChannelArgs(&channel_args);
- c_channel_ = grpc_channel_create(
- target_.c_str(), channel_args.num_args > 0 ? &channel_args : nullptr);
-}
-
-Channel::Channel(const grpc::string &target,
- const std::unique_ptr<Credentials> &creds,
- const ChannelArguments &args)
- : target_(args.GetSslTargetNameOverride().empty()
- ? target
- : args.GetSslTargetNameOverride()) {
- grpc_channel_args channel_args;
- args.SetChannelArgs(&channel_args);
- grpc_credentials *c_creds = creds ? creds->GetRawCreds() : nullptr;
- c_channel_ = grpc_secure_channel_create(
- c_creds, target.c_str(),
- channel_args.num_args > 0 ? &channel_args : nullptr);
-}
+Channel::Channel(const grpc::string& target, grpc_channel* channel)
+ : target_(target), c_channel_(channel) {}
Channel::~Channel() { grpc_channel_destroy(c_channel_); }
-Call Channel::CreateCall(const RpcMethod &method, ClientContext *context,
- CompletionQueue *cq) {
- auto c_call =
- grpc_channel_create_call(
- c_channel_, cq->cq(), method.name(),
- context->authority().empty() ? target_.c_str()
- : context->authority().c_str(),
- context->RawDeadline());
+Call Channel::CreateCall(const RpcMethod& method, ClientContext* context,
+ CompletionQueue* cq) {
+ auto c_call = grpc_channel_create_call(c_channel_, cq->cq(), method.name(),
+ context->authority().empty()
+ ? target_.c_str()
+ : context->authority().c_str(),
+ context->RawDeadline());
context->set_call(c_call);
return Call(c_call, this, cq);
}
-void Channel::PerformOpsOnCall(CallOpBuffer *buf, Call *call) {
+void Channel::PerformOpsOnCall(CallOpBuffer* buf, Call* call) {
static const size_t MAX_OPS = 8;
size_t nops = MAX_OPS;
grpc_op ops[MAX_OPS];
diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h
index 06f5a8ffdf..f5c9e0f616 100644
--- a/src/cpp/client/channel.h
+++ b/src/cpp/client/channel.h
@@ -51,10 +51,7 @@ class StreamContextInterface;
class Channel final : public ChannelInterface {
public:
- Channel(const grpc::string &target, const ChannelArguments &args);
- Channel(const grpc::string &target, const std::unique_ptr<Credentials> &creds,
- const ChannelArguments &args);
-
+ Channel(const grpc::string &target, grpc_channel *c_channel);
~Channel() override;
virtual Call CreateCall(const RpcMethod &method, ClientContext *context,
@@ -63,7 +60,7 @@ class Channel final : public ChannelInterface {
private:
const grpc::string target_;
- grpc_channel *c_channel_; // owned
+ grpc_channel *const c_channel_; // owned
};
} // namespace grpc
diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc
index acf51cb90b..ef2deb3556 100644
--- a/src/cpp/client/create_channel.cc
+++ b/src/cpp/client/create_channel.cc
@@ -40,14 +40,9 @@
namespace grpc {
class ChannelArguments;
-std::shared_ptr<ChannelInterface> CreateChannel(const grpc::string &target,
- const ChannelArguments &args) {
- return std::shared_ptr<ChannelInterface>(new Channel(target, args));
-}
-
std::shared_ptr<ChannelInterface> CreateChannel(
const grpc::string &target, const std::unique_ptr<Credentials> &creds,
const ChannelArguments &args) {
- return std::shared_ptr<ChannelInterface>(new Channel(target, creds, args));
+ return creds->CreateChannel(target, args);
}
} // namespace grpc
diff --git a/src/cpp/client/credentials.cc b/src/cpp/client/credentials.cc
index 66571cad73..e806284988 100644
--- a/src/cpp/client/credentials.cc
+++ b/src/cpp/client/credentials.cc
@@ -31,85 +31,10 @@
*
*/
-#include <string>
-
-#include <grpc/grpc_security.h>
-#include <grpc/support/log.h>
-
#include <grpc++/credentials.h>
namespace grpc {
-Credentials::Credentials(grpc_credentials *c_creds) : creds_(c_creds) {}
-
-Credentials::~Credentials() { grpc_credentials_release(creds_); }
-grpc_credentials *Credentials::GetRawCreds() { return creds_; }
-
-std::unique_ptr<Credentials> CredentialsFactory::DefaultCredentials() {
- grpc_credentials *c_creds = grpc_default_credentials_create();
- std::unique_ptr<Credentials> cpp_creds(new Credentials(c_creds));
- return cpp_creds;
-}
-
-// Builds SSL Credentials given SSL specific options
-std::unique_ptr<Credentials> CredentialsFactory::SslCredentials(
- const SslCredentialsOptions &options) {
- grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {
- options.pem_private_key.c_str(), options.pem_cert_chain.c_str()};
-
- grpc_credentials *c_creds = grpc_ssl_credentials_create(
- options.pem_root_certs.empty() ? nullptr : options.pem_root_certs.c_str(),
- options.pem_private_key.empty() ? nullptr : &pem_key_cert_pair);
- std::unique_ptr<Credentials> cpp_creds(
- c_creds == nullptr ? nullptr : new Credentials(c_creds));
- return cpp_creds;
-}
-
-// Builds credentials for use when running in GCE
-std::unique_ptr<Credentials> CredentialsFactory::ComputeEngineCredentials() {
- grpc_credentials *c_creds = grpc_compute_engine_credentials_create();
- std::unique_ptr<Credentials> cpp_creds(
- c_creds == nullptr ? nullptr : new Credentials(c_creds));
- return cpp_creds;
-}
-
-// Builds service account credentials.
-std::unique_ptr<Credentials> CredentialsFactory::ServiceAccountCredentials(
- const grpc::string &json_key, const grpc::string &scope,
- std::chrono::seconds token_lifetime) {
- gpr_timespec lifetime = gpr_time_from_seconds(
- token_lifetime.count() > 0 ? token_lifetime.count() : 0);
- grpc_credentials *c_creds = grpc_service_account_credentials_create(
- json_key.c_str(), scope.c_str(), lifetime);
- std::unique_ptr<Credentials> cpp_creds(
- c_creds == nullptr ? nullptr : new Credentials(c_creds));
- return cpp_creds;
-}
-
-// Builds IAM credentials.
-std::unique_ptr<Credentials> CredentialsFactory::IAMCredentials(
- const grpc::string &authorization_token,
- const grpc::string &authority_selector) {
- grpc_credentials *c_creds = grpc_iam_credentials_create(
- authorization_token.c_str(), authority_selector.c_str());
- std::unique_ptr<Credentials> cpp_creds(
- c_creds == nullptr ? nullptr : new Credentials(c_creds));
- return cpp_creds;
-}
-
-// Combines two credentials objects into a composite credentials.
-std::unique_ptr<Credentials> CredentialsFactory::ComposeCredentials(
- const std::unique_ptr<Credentials> &creds1,
- const std::unique_ptr<Credentials> &creds2) {
- // Note that we are not saving unique_ptrs to the two credentials
- // passed in here. This is OK because the underlying C objects (i.e.,
- // creds1 and creds2) into grpc_composite_credentials_create will see their
- // refcounts incremented.
- grpc_credentials *c_creds = grpc_composite_credentials_create(
- creds1->GetRawCreds(), creds2->GetRawCreds());
- std::unique_ptr<Credentials> cpp_creds(
- c_creds == nullptr ? nullptr : new Credentials(c_creds));
- return cpp_creds;
-}
+Credentials::~Credentials() {}
} // namespace grpc
diff --git a/src/cpp/client/insecure_credentials.cc b/src/cpp/client/insecure_credentials.cc
new file mode 100644
index 0000000000..4f3bba5c8e
--- /dev/null
+++ b/src/cpp/client/insecure_credentials.cc
@@ -0,0 +1,60 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <string>
+
+#include <grpc/grpc.h>
+#include <grpc/support/log.h>
+
+#include <grpc++/channel_arguments.h>
+#include <grpc++/credentials.h>
+#include "src/cpp/client/channel.h"
+
+namespace grpc {
+
+namespace {
+class InsecureCredentialsImpl final : public Credentials {
+ public:
+ std::shared_ptr<grpc::ChannelInterface> CreateChannel(const string& target, const grpc::ChannelArguments& args) override {
+ grpc_channel_args channel_args;
+ args.SetChannelArgs(&channel_args);
+ return std::shared_ptr<ChannelInterface>(new Channel(target, grpc_channel_create(target.c_str(), &channel_args)));
+ }
+};
+} // namespace
+
+std::unique_ptr<Credentials> InsecureCredentials() {
+ return std::unique_ptr<Credentials>(new InsecureCredentialsImpl());
+}
+
+} // namespace grpc
diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc
new file mode 100644
index 0000000000..367dfe3447
--- /dev/null
+++ b/src/cpp/client/secure_credentials.cc
@@ -0,0 +1,128 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <string>
+
+#include <grpc/grpc_security.h>
+#include <grpc/support/log.h>
+
+#include <grpc++/channel_arguments.h>
+#include <grpc++/credentials.h>
+#include "src/cpp/client/channel.h"
+
+namespace grpc {
+
+namespace {
+class SecureCredentials final : public Credentials {
+ public:
+ explicit SecureCredentials(grpc_credentials* c_creds) : c_creds_(c_creds) {}
+ ~SecureCredentials() override { grpc_credentials_release(c_creds_); }
+ grpc_credentials* GetRawCreds() { return c_creds_; }
+
+ std::shared_ptr<grpc::ChannelInterface> CreateChannel(
+ const string& target, const grpc::ChannelArguments& args) override {
+ grpc_channel_args channel_args;
+ args.SetChannelArgs(&channel_args);
+ return std::shared_ptr<ChannelInterface>(new Channel(
+ target,
+ grpc_secure_channel_create(c_creds_, target.c_str(), &channel_args)));
+ }
+
+ private:
+ grpc_credentials* const c_creds_;
+};
+
+std::unique_ptr<Credentials> WrapCredentials(grpc_credentials* creds) {
+ return creds == nullptr
+ ? nullptr
+ : std::unique_ptr<Credentials>(new SecureCredentials(creds));
+}
+} // namespace
+
+std::unique_ptr<Credentials> DefaultCredentials() {
+ return WrapCredentials(grpc_default_credentials_create());
+}
+
+// Builds SSL Credentials given SSL specific options
+std::unique_ptr<Credentials> SslCredentials(
+ const SslCredentialsOptions& options) {
+ grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {
+ options.pem_private_key.c_str(), options.pem_cert_chain.c_str()};
+
+ grpc_credentials* c_creds = grpc_ssl_credentials_create(
+ options.pem_root_certs.empty() ? nullptr : options.pem_root_certs.c_str(),
+ options.pem_private_key.empty() ? nullptr : &pem_key_cert_pair);
+ return WrapCredentials(c_creds);
+}
+
+// Builds credentials for use when running in GCE
+std::unique_ptr<Credentials> ComputeEngineCredentials() {
+ return WrapCredentials(grpc_compute_engine_credentials_create());
+}
+
+// Builds service account credentials.
+std::unique_ptr<Credentials> ServiceAccountCredentials(
+ const grpc::string& json_key, const grpc::string& scope,
+ std::chrono::seconds token_lifetime) {
+ gpr_timespec lifetime = gpr_time_from_seconds(
+ token_lifetime.count() > 0 ? token_lifetime.count() : 0);
+ return WrapCredentials(grpc_service_account_credentials_create(
+ json_key.c_str(), scope.c_str(), lifetime));
+}
+
+// Builds IAM credentials.
+std::unique_ptr<Credentials> IAMCredentials(
+ const grpc::string& authorization_token,
+ const grpc::string& authority_selector) {
+ return WrapCredentials(grpc_iam_credentials_create(
+ authorization_token.c_str(), authority_selector.c_str()));
+}
+
+// Combines two credentials objects into a composite credentials.
+std::unique_ptr<Credentials> ComposeCredentials(
+ const std::unique_ptr<Credentials>& creds1,
+ const std::unique_ptr<Credentials>& creds2) {
+ // Note that we are not saving unique_ptrs to the two credentials
+ // passed in here. This is OK because the underlying C objects (i.e.,
+ // creds1 and creds2) into grpc_composite_credentials_create will see their
+ // refcounts incremented.
+ SecureCredentials* s1 = dynamic_cast<SecureCredentials*>(creds1.get());
+ SecureCredentials* s2 = dynamic_cast<SecureCredentials*>(creds2.get());
+ if (s1 && s2) {
+ return WrapCredentials(grpc_composite_credentials_create(
+ s1->GetRawCreds(), s2->GetRawCreds()));
+ }
+ return nullptr;
+}
+
+} // namespace grpc
diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc
index dc8d76d7ef..59ca33cc29 100644
--- a/test/cpp/client/credentials_test.cc
+++ b/test/cpp/client/credentials_test.cc
@@ -47,8 +47,7 @@ class CredentialsTest : public ::testing::Test {
TEST_F(CredentialsTest, InvalidServiceAccountCreds) {
std::unique_ptr<Credentials> bad1 =
- CredentialsFactory::ServiceAccountCredentials("", "",
- std::chrono::seconds(1));
+ ServiceAccountCredentials("", "", std::chrono::seconds(1));
EXPECT_EQ(nullptr, bad1.get());
}
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 248e054e49..85b4ff8120 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -65,9 +65,7 @@ namespace testing {
namespace {
-void* tag(int i) {
- return (void*)(gpr_intptr)i;
-}
+void* tag(int i) { return (void*)(gpr_intptr) i; }
void verify_ok(CompletionQueue* cq, int i, bool expect_ok) {
bool ok;
@@ -104,23 +102,15 @@ class AsyncEnd2endTest : public ::testing::Test {
}
void ResetStub() {
- std::shared_ptr<ChannelInterface> channel =
- CreateChannel(server_address_.str(), ChannelArguments());
+ std::shared_ptr<ChannelInterface> channel = CreateChannel(
+ server_address_.str(), InsecureCredentials(), ChannelArguments());
stub_.reset(grpc::cpp::test::util::TestService::NewStub(channel));
}
- void server_ok(int i) {
- verify_ok(&srv_cq_, i, true);
- }
- void client_ok(int i) {
- verify_ok(&cli_cq_, i , true);
- }
- void server_fail(int i) {
- verify_ok(&srv_cq_, i, false);
- }
- void client_fail(int i) {
- verify_ok(&cli_cq_, i, false);
- }
+ void server_ok(int i) { verify_ok(&srv_cq_, i, true); }
+ void client_ok(int i) { verify_ok(&cli_cq_, i, true); }
+ void server_fail(int i) { verify_ok(&srv_cq_, i, false); }
+ void client_fail(int i) { verify_ok(&cli_cq_, i, false); }
void SendRpc(int num_rpcs) {
for (int i = 0; i < num_rpcs; i++) {
@@ -135,12 +125,11 @@ class AsyncEnd2endTest : public ::testing::Test {
grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
send_request.set_message("Hello");
- std::unique_ptr<ClientAsyncResponseReader<EchoResponse> >
- response_reader(stub_->Echo(
- &cli_ctx, send_request, &cli_cq_, tag(1)));
+ std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader(
+ stub_->Echo(&cli_ctx, send_request, &cli_cq_, tag(1)));
- service_.RequestEcho(
- &srv_ctx, &recv_request, &response_writer, &srv_cq_, tag(2));
+ service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, &srv_cq_,
+ tag(2));
server_ok(2);
EXPECT_EQ(send_request.message(), recv_request.message());
@@ -193,8 +182,7 @@ TEST_F(AsyncEnd2endTest, SimpleClientStreaming) {
std::unique_ptr<ClientAsyncWriter<EchoRequest> > cli_stream(
stub_->RequestStream(&cli_ctx, &recv_response, &cli_cq_, tag(1)));
- service_.RequestRequestStream(
- &srv_ctx, &srv_stream, &srv_cq_, tag(2));
+ service_.RequestRequestStream(&srv_ctx, &srv_stream, &srv_cq_, tag(2));
server_ok(2);
client_ok(1);
@@ -247,8 +235,8 @@ TEST_F(AsyncEnd2endTest, SimpleServerStreaming) {
std::unique_ptr<ClientAsyncReader<EchoResponse> > cli_stream(
stub_->ResponseStream(&cli_ctx, send_request, &cli_cq_, tag(1)));
- service_.RequestResponseStream(
- &srv_ctx, &recv_request, &srv_stream, &srv_cq_, tag(2));
+ service_.RequestResponseStream(&srv_ctx, &recv_request, &srv_stream, &srv_cq_,
+ tag(2));
server_ok(2);
client_ok(1);
@@ -298,8 +286,7 @@ TEST_F(AsyncEnd2endTest, SimpleBidiStreaming) {
std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse> >
cli_stream(stub_->BidiStream(&cli_ctx, &cli_cq_, tag(1)));
- service_.RequestBidiStream(
- &srv_ctx, &srv_stream, &srv_cq_, tag(2));
+ service_.RequestBidiStream(&srv_ctx, &srv_stream, &srv_cq_, tag(2));
server_ok(2);
client_ok(1);
@@ -357,8 +344,8 @@ TEST_F(AsyncEnd2endTest, ClientInitialMetadataRpc) {
std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader(
stub_->Echo(&cli_ctx, send_request, &cli_cq_, tag(1)));
- service_.RequestEcho(
- &srv_ctx, &recv_request, &response_writer, &srv_cq_, tag(2));
+ service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, &srv_cq_,
+ tag(2));
server_ok(2);
EXPECT_EQ(send_request.message(), recv_request.message());
auto client_initial_metadata = srv_ctx.client_metadata();
@@ -399,8 +386,8 @@ TEST_F(AsyncEnd2endTest, ServerInitialMetadataRpc) {
std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader(
stub_->Echo(&cli_ctx, send_request, &cli_cq_, tag(1)));
- service_.RequestEcho(
- &srv_ctx, &recv_request, &response_writer, &srv_cq_, tag(2));
+ service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, &srv_cq_,
+ tag(2));
server_ok(2);
EXPECT_EQ(send_request.message(), recv_request.message());
srv_ctx.AddInitialMetadata(meta1.first, meta1.second);
@@ -447,8 +434,8 @@ TEST_F(AsyncEnd2endTest, ServerTrailingMetadataRpc) {
std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader(
stub_->Echo(&cli_ctx, send_request, &cli_cq_, tag(1)));
- service_.RequestEcho(
- &srv_ctx, &recv_request, &response_writer, &srv_cq_, tag(2));
+ service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, &srv_cq_,
+ tag(2));
server_ok(2);
EXPECT_EQ(send_request.message(), recv_request.message());
response_writer.SendInitialMetadata(tag(3));
@@ -462,7 +449,6 @@ TEST_F(AsyncEnd2endTest, ServerTrailingMetadataRpc) {
server_ok(4);
-
response_reader->Finish(&recv_response, &recv_status, tag(5));
client_ok(5);
EXPECT_EQ(send_response.message(), recv_response.message());
@@ -491,10 +477,12 @@ TEST_F(AsyncEnd2endTest, MetadataRpc) {
std::pair<grpc::string, grpc::string> meta2(
"key2-bin", {"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13});
std::pair<grpc::string, grpc::string> meta3("key3", "val3");
- std::pair<grpc::string, grpc::string> meta6("key4-bin",
+ std::pair<grpc::string, grpc::string> meta6(
+ "key4-bin",
{"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d", 14});
std::pair<grpc::string, grpc::string> meta5("key5", "val5");
- std::pair<grpc::string, grpc::string> meta4("key6-bin",
+ std::pair<grpc::string, grpc::string> meta4(
+ "key6-bin",
{"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15});
cli_ctx.AddMetadata(meta1.first, meta1.second);
@@ -503,8 +491,8 @@ TEST_F(AsyncEnd2endTest, MetadataRpc) {
std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader(
stub_->Echo(&cli_ctx, send_request, &cli_cq_, tag(1)));
- service_.RequestEcho(
- &srv_ctx, &recv_request, &response_writer, &srv_cq_, tag(2));
+ service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, &srv_cq_,
+ tag(2));
server_ok(2);
EXPECT_EQ(send_request.message(), recv_request.message());
auto client_initial_metadata = srv_ctx.client_metadata();
@@ -531,7 +519,6 @@ TEST_F(AsyncEnd2endTest, MetadataRpc) {
server_ok(5);
-
response_reader->Finish(&recv_response, &recv_status, tag(6));
client_ok(6);
EXPECT_EQ(send_response.message(), recv_response.message());
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index d4ca3ef49e..f5ecd1a20c 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -160,8 +160,8 @@ class End2endTest : public ::testing::Test {
void TearDown() override { server_->Shutdown(); }
void ResetStub() {
- std::shared_ptr<ChannelInterface> channel =
- CreateChannel(server_address_.str(), ChannelArguments());
+ std::shared_ptr<ChannelInterface> channel = CreateChannel(
+ server_address_.str(), InsecureCredentials(), ChannelArguments());
stub_.reset(grpc::cpp::test::util::TestService::NewStub(channel));
}
@@ -328,8 +328,7 @@ TEST_F(End2endTest, ResponseStream) {
ClientContext context;
request.set_message("hello");
- ClientReader<EchoResponse>* stream =
- stub_->ResponseStream(&context, request);
+ ClientReader<EchoResponse>* stream = stub_->ResponseStream(&context, request);
EXPECT_TRUE(stream->Read(&response));
EXPECT_EQ(response.message(), request.message() + "0");
EXPECT_TRUE(stream->Read(&response));
@@ -381,8 +380,8 @@ TEST_F(End2endTest, BidiStream) {
// Talk to the two services with the same name but different package names.
// The two stubs are created on the same channel.
TEST_F(End2endTest, DiffPackageServices) {
- std::shared_ptr<ChannelInterface> channel =
- CreateChannel(server_address_.str(), ChannelArguments());
+ std::shared_ptr<ChannelInterface> channel = CreateChannel(
+ server_address_.str(), InsecureCredentials(), ChannelArguments());
EchoRequest request;
EchoResponse response;
@@ -407,8 +406,7 @@ TEST_F(End2endTest, DiffPackageServices) {
// rpc and stream should fail on bad credentials.
TEST_F(End2endTest, BadCredentials) {
std::unique_ptr<Credentials> bad_creds =
- CredentialsFactory::ServiceAccountCredentials("", "",
- std::chrono::seconds(1));
+ ServiceAccountCredentials("", "", std::chrono::seconds(1));
EXPECT_EQ(nullptr, bad_creds.get());
std::shared_ptr<ChannelInterface> channel =
CreateChannel(server_address_.str(), bad_creds, ChannelArguments());
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc
index 78f2063c45..abe0aaccd5 100644
--- a/test/cpp/interop/client.cc
+++ b/test/cpp/interop/client.cc
@@ -80,9 +80,10 @@ DEFINE_string(oauth_scope, "", "Scope for OAuth tokens.");
using grpc::ChannelInterface;
using grpc::ClientContext;
+using grpc::ComputeEngineCredentials;
using grpc::CreateTestChannel;
using grpc::Credentials;
-using grpc::CredentialsFactory;
+using grpc::ServiceAccountCredentials;
using grpc::testing::ResponseParameters;
using grpc::testing::SimpleRequest;
using grpc::testing::SimpleResponse;
@@ -94,8 +95,8 @@ using grpc::testing::TestService;
// In some distros, gflags is in the namespace google, and in some others,
// in gflags. This hack is enabling us to find both.
-namespace google { }
-namespace gflags { }
+namespace google {}
+namespace gflags {}
using namespace google;
using namespace gflags;
@@ -133,14 +134,14 @@ std::shared_ptr<ChannelInterface> CreateChannelForTestCase(
std::unique_ptr<Credentials> creds;
GPR_ASSERT(FLAGS_enable_ssl);
grpc::string json_key = GetServiceAccountJsonKey();
- creds = CredentialsFactory::ServiceAccountCredentials(
- json_key, FLAGS_oauth_scope, std::chrono::hours(1));
+ creds = ServiceAccountCredentials(json_key, FLAGS_oauth_scope,
+ std::chrono::hours(1));
return CreateTestChannel(host_port, FLAGS_server_host_override,
FLAGS_enable_ssl, FLAGS_use_prod_roots, creds);
} else if (test_case == "compute_engine_creds") {
std::unique_ptr<Credentials> creds;
GPR_ASSERT(FLAGS_enable_ssl);
- creds = CredentialsFactory::ComputeEngineCredentials();
+ creds = ComputeEngineCredentials();
return CreateTestChannel(host_port, FLAGS_server_host_override,
FLAGS_enable_ssl, FLAGS_use_prod_roots, creds);
} else {
@@ -200,7 +201,7 @@ void DoComputeEngineCreds() {
GPR_ASSERT(!response.username().empty());
GPR_ASSERT(response.username().c_str() == FLAGS_default_service_account);
GPR_ASSERT(!response.oauth_scope().empty());
- const char *oauth_scope_str = response.oauth_scope().c_str();
+ const char* oauth_scope_str = response.oauth_scope().c_str();
GPR_ASSERT(FLAGS_oauth_scope.find(oauth_scope_str) != grpc::string::npos);
gpr_log(GPR_INFO, "Large unary with compute engine creds done.");
}
@@ -219,7 +220,7 @@ void DoServiceAccountCreds() {
GPR_ASSERT(!response.oauth_scope().empty());
grpc::string json_key = GetServiceAccountJsonKey();
GPR_ASSERT(json_key.find(response.username()) != grpc::string::npos);
- const char *oauth_scope_str = response.oauth_scope().c_str();
+ const char* oauth_scope_str = response.oauth_scope().c_str();
GPR_ASSERT(FLAGS_oauth_scope.find(oauth_scope_str) != grpc::string::npos);
gpr_log(GPR_INFO, "Large unary with service account creds done.");
}
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc
index 263bd8e304..7a7287438f 100644
--- a/test/cpp/interop/server.cc
+++ b/test/cpp/interop/server.cc
@@ -77,8 +77,8 @@ using grpc::Status;
// In some distros, gflags is in the namespace google, and in some others,
// in gflags. This hack is enabling us to find both.
-namespace google { }
-namespace gflags { }
+namespace google {}
+namespace gflags {}
using namespace google;
using namespace gflags;
@@ -215,8 +215,7 @@ void RunServer() {
if (FLAGS_enable_ssl) {
SslServerCredentialsOptions ssl_opts = {
"", {{test_server1_key, test_server1_cert}}};
- std::shared_ptr<ServerCredentials> creds =
- ServerCredentialsFactory::SslCredentials(ssl_opts);
+ std::shared_ptr<ServerCredentials> creds = ServerSslCredentials(ssl_opts);
builder.SetCredentials(creds);
}
std::unique_ptr<Server> server(builder.BuildAndStart());
diff --git a/test/cpp/util/create_test_channel.cc b/test/cpp/util/create_test_channel.cc
index b0472d32a9..278172f6ff 100644
--- a/test/cpp/util/create_test_channel.cc
+++ b/test/cpp/util/create_test_channel.cc
@@ -61,12 +61,10 @@ std::shared_ptr<ChannelInterface> CreateTestChannel(
const std::unique_ptr<Credentials>& creds) {
ChannelArguments channel_args;
if (enable_ssl) {
- const char* roots_certs =
- use_prod_roots ? "" : test_root_cert;
+ const char* roots_certs = use_prod_roots ? "" : test_root_cert;
SslCredentialsOptions ssl_opts = {roots_certs, "", ""};
- std::unique_ptr<Credentials> channel_creds =
- CredentialsFactory::SslCredentials(ssl_opts);
+ std::unique_ptr<Credentials> channel_creds = SslCredentials(ssl_opts);
if (!server.empty() && !override_hostname.empty()) {
channel_args.SetSslTargetNameOverride(override_hostname);
@@ -74,12 +72,11 @@ std::shared_ptr<ChannelInterface> CreateTestChannel(
const grpc::string& connect_to =
server.empty() ? override_hostname : server;
if (creds.get()) {
- channel_creds =
- CredentialsFactory::ComposeCredentials(creds, channel_creds);
+ channel_creds = ComposeCredentials(creds, channel_creds);
}
return CreateChannel(connect_to, channel_creds, channel_args);
} else {
- return CreateChannel(server, channel_args);
+ return CreateChannel(server, InsecureCredentials(), channel_args);
}
}