Merge pull request #5302 from nicolasnoble/python-windows
Enabling python artifact building for Windows.
diff --git a/BUILD b/BUILD
index 09f53f9..0a5139d 100644
--- a/BUILD
+++ b/BUILD
@@ -180,6 +180,7 @@
"src/core/client_config/resolvers/sockaddr_resolver.h",
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.h",
+ "src/core/client_config/subchannel_index.h",
"src/core/client_config/uri_parser.h",
"src/core/compression/algorithm_metadata.h",
"src/core/compression/message_compress.h",
@@ -311,6 +312,7 @@
"src/core/client_config/resolvers/sockaddr_resolver.c",
"src/core/client_config/subchannel.c",
"src/core/client_config/subchannel_factory.c",
+ "src/core/client_config/subchannel_index.c",
"src/core/client_config/uri_parser.c",
"src/core/compression/algorithm.c",
"src/core/compression/message_compress.c",
@@ -498,6 +500,7 @@
"src/core/client_config/resolvers/sockaddr_resolver.h",
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.h",
+ "src/core/client_config/subchannel_index.h",
"src/core/client_config/uri_parser.h",
"src/core/compression/algorithm_metadata.h",
"src/core/compression/message_compress.h",
@@ -616,6 +619,7 @@
"src/core/client_config/resolvers/sockaddr_resolver.c",
"src/core/client_config/subchannel.c",
"src/core/client_config/subchannel_factory.c",
+ "src/core/client_config/subchannel_index.c",
"src/core/client_config/uri_parser.c",
"src/core/compression/algorithm.c",
"src/core/compression/message_compress.c",
@@ -1272,6 +1276,7 @@
"src/core/client_config/resolvers/sockaddr_resolver.c",
"src/core/client_config/subchannel.c",
"src/core/client_config/subchannel_factory.c",
+ "src/core/client_config/subchannel_index.c",
"src/core/client_config/uri_parser.c",
"src/core/compression/algorithm.c",
"src/core/compression/message_compress.c",
@@ -1440,6 +1445,7 @@
"src/core/client_config/resolvers/sockaddr_resolver.h",
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.h",
+ "src/core/client_config/subchannel_index.h",
"src/core/client_config/uri_parser.h",
"src/core/compression/algorithm_metadata.h",
"src/core/compression/message_compress.h",
diff --git a/Makefile b/Makefile
index c53b743..51b8921 100644
--- a/Makefile
+++ b/Makefile
@@ -2345,6 +2345,7 @@
src/core/client_config/resolvers/sockaddr_resolver.c \
src/core/client_config/subchannel.c \
src/core/client_config/subchannel_factory.c \
+ src/core/client_config/subchannel_index.c \
src/core/client_config/uri_parser.c \
src/core/compression/algorithm.c \
src/core/compression/message_compress.c \
@@ -2688,6 +2689,7 @@
src/core/client_config/resolvers/sockaddr_resolver.c \
src/core/client_config/subchannel.c \
src/core/client_config/subchannel_factory.c \
+ src/core/client_config/subchannel_index.c \
src/core/client_config/uri_parser.c \
src/core/compression/algorithm.c \
src/core/compression/message_compress.c \
@@ -3197,6 +3199,7 @@
test/cpp/util/create_test_channel.cc \
test/cpp/util/string_ref_helper.cc \
test/cpp/util/subprocess.cc \
+ test/cpp/util/test_credentials_provider.cc \
LIBGRPC++_TEST_UTIL_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC++_TEST_UTIL_SRC))))
@@ -3247,6 +3250,7 @@
$(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/string_ref_helper.o: $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/subprocess.o: $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
+$(OBJDIR)/$(CONFIG)/test/cpp/util/test_credentials_provider.o: $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
LIBGRPC++_UNSECURE_SRC = \
@@ -13050,6 +13054,7 @@
test/cpp/util/string_ref_helper.cc: $(OPENSSL_DEP)
test/cpp/util/subprocess.cc: $(OPENSSL_DEP)
test/cpp/util/test_config.cc: $(OPENSSL_DEP)
+test/cpp/util/test_credentials_provider.cc: $(OPENSSL_DEP)
endif
.PHONY: all strip tools dep_error openssl_dep_error openssl_dep_message git_update stop buildtests buildtests_c buildtests_cxx test test_c test_cxx install install_c install_cxx install-headers install-headers_c install-headers_cxx install-shared install-shared_c install-shared_cxx install-static install-static_c install-static_cxx strip strip-shared strip-static strip_c strip-shared_c strip-static_c strip_cxx strip-shared_cxx strip-static_cxx dep_c dep_cxx bins_dep_c bins_dep_cxx clean
diff --git a/binding.gyp b/binding.gyp
index 59356d3..a2a64ff 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -584,6 +584,7 @@
'src/core/client_config/resolvers/sockaddr_resolver.c',
'src/core/client_config/subchannel.c',
'src/core/client_config/subchannel_factory.c',
+ 'src/core/client_config/subchannel_index.c',
'src/core/client_config/uri_parser.c',
'src/core/compression/algorithm.c',
'src/core/compression/message_compress.c',
diff --git a/build.yaml b/build.yaml
index de741d6..cb6cb56 100644
--- a/build.yaml
+++ b/build.yaml
@@ -270,6 +270,7 @@
- src/core/client_config/resolvers/sockaddr_resolver.h
- src/core/client_config/subchannel.h
- src/core/client_config/subchannel_factory.h
+ - src/core/client_config/subchannel_index.h
- src/core/client_config/uri_parser.h
- src/core/compression/algorithm_metadata.h
- src/core/compression/message_compress.h
@@ -385,6 +386,7 @@
- src/core/client_config/resolvers/sockaddr_resolver.c
- src/core/client_config/subchannel.c
- src/core/client_config/subchannel_factory.c
+ - src/core/client_config/subchannel_index.c
- src/core/client_config/uri_parser.c
- src/core/compression/algorithm.c
- src/core/compression/message_compress.c
@@ -735,6 +737,7 @@
- test/cpp/util/create_test_channel.h
- test/cpp/util/string_ref_helper.h
- test/cpp/util/subprocess.h
+ - test/cpp/util/test_credentials_provider.h
src:
- src/proto/grpc/testing/echo_messages.proto
- src/proto/grpc/testing/echo.proto
@@ -745,6 +748,7 @@
- test/cpp/util/create_test_channel.cc
- test/cpp/util/string_ref_helper.cc
- test/cpp/util/subprocess.cc
+ - test/cpp/util/test_credentials_provider.cc
deps:
- grpc++
- grpc_test_util
@@ -2648,8 +2652,8 @@
LDXX: clang++
compile_the_world: true
test_environ:
- ASAN_OPTIONS: suppressions=tools/asan_suppressions.txt:detect_leaks=1:color=always
- LSAN_OPTIONS: suppressions=tools/asan_suppressions.txt:report_objects=1
+ ASAN_OPTIONS: detect_leaks=1:color=always
+ LSAN_OPTIONS: suppressions=tools/lsan_suppressions.txt:report_objects=1
timeout_multiplier: 1.5
asan-noleaks:
CC: clang
diff --git a/doc/load-balancing.md b/doc/load-balancing.md
new file mode 100644
index 0000000..681be02
--- /dev/null
+++ b/doc/load-balancing.md
@@ -0,0 +1,97 @@
+Load Balancing in gRPC
+=======================
+
+# Objective
+
+To design a load balancing API between a gRPC client and a Load Balancer to
+instruct the client how to send load to multiple backend servers.
+
+# Background
+
+Prior to any gRPC specifics, we explore some usual ways to approach load
+balancing.
+
+### Proxy Model
+
+Using a proxy provides a solid trustable client that can report load to the load
+balancing system. Proxies typically require more resources to operate since they
+have temporary copies of the RPC request and response. This model also increases
+latency to the RPCs.
+
+The proxy model was deemed inefficient when considering request heavy services
+like storage.
+
+### Balancing-aware Client
+
+This thicker client places more of the load balancing logic in the client. For
+example, the client could contain many load balancing policies (Round Robin,
+Random, etc) used to select servers from a list. In this model, a list of
+servers would be either statically configured in the client, provided by the
+name resolution system, an external load balancer, etc. In any case, the client
+is responsible for choosing the preferred server from the list.
+
+One of the drawbacks of this approach is writing and maintaining the load
+balancing policies in multiple languages and/or versions of the clients. These
+policies can be fairly complicated. Some of the algorithms also require client
+to server communication so the client would need to get thicker to support
+additional RPCs to get health or load information in addition to sending RPCs
+for user requests.
+
+It would also significantly complicate the client's code: the new design hides
+the load balancing complexity of multiple layers and presents it as a simple
+list of servers to the client.
+
+### External Load Balancing Service
+
+The client load balancing code is kept simple and portable, implementing
+well-known algorithms (ie, Round Robin) for server selection.
+Complex load balancing algorithms are instead provided by the load balancer. The
+client relies on the load balancer to provide _load balancing configuration_ and
+_the list of servers_ to which the client should send requests. The balancer
+updates the server list as needed to balance the load as well as handle server
+unavailability or health issues. The load balancer will make any necessary
+complex decisions and inform the client. The load balancer may communicate with
+the backend servers to collect load and health information.
+
+# Proposed Architecture
+
+The gRPC load balancing approach follows the third approach, by having an
+external load balancer which provides simple clients with a list of servers.
+
+## Client
+
+When establishing a gRPC stream to the balancer, the client will send an initial
+request to the load balancer (via a regular gRPC message). The load balancer
+will respond with client config (including, for example, settings for flow
+control, RPC deadlines, etc.) or a redirect to another load balancer. If the
+balancer did not redirect the client, it will then send a list of servers to the
+client. The client will contain simple load balancing logic for choosing the
+next server when it needs to send a request.
+
+## Load Balancer
+
+The Load Balancer is responsible for providing the client with a list of servers
+and client RPC parameters. The balancer chooses when to update the list of
+servers and can decide whether to provide a complete list, a subset, or a
+specific list of “picked” servers in a particular order. The balancer can
+optionally provide an expiration interval after which the server list should no
+longer be trusted and should be updated by the balancer.
+
+The load balancer may open reporting streams to each server contained in the
+server list. These streams are primarily used for load reporting. For example,
+Weighted Round Robin requires that the servers report utilization to the load
+balancer in order to compute the next list of servers.
+
+## Server
+
+The gRPC Server is responsible for answering RPC requests and providing
+responses to the client. The server will also report load to the load balancer
+if a reporting stream was opened for this purpose.
+
+### Security
+
+The load balancer may be separate from the actual server backends and a
+compromise of the load balancer should only lead to a compromise of the
+loadbalancing functionality. In other words, a compromised load balancer should
+not be able to cause a client to trust a (potentially malicious) backend server
+any more than in a comparable situation without loadbalancing.
diff --git a/gRPC.podspec b/gRPC.podspec
index 036deea..d2d151b 100644
--- a/gRPC.podspec
+++ b/gRPC.podspec
@@ -184,6 +184,7 @@
'src/core/client_config/resolvers/sockaddr_resolver.h',
'src/core/client_config/subchannel.h',
'src/core/client_config/subchannel_factory.h',
+ 'src/core/client_config/subchannel_index.h',
'src/core/client_config/uri_parser.h',
'src/core/compression/algorithm_metadata.h',
'src/core/compression/message_compress.h',
@@ -328,6 +329,7 @@
'src/core/client_config/resolvers/sockaddr_resolver.c',
'src/core/client_config/subchannel.c',
'src/core/client_config/subchannel_factory.c',
+ 'src/core/client_config/subchannel_index.c',
'src/core/client_config/uri_parser.c',
'src/core/compression/algorithm.c',
'src/core/compression/message_compress.c',
@@ -492,6 +494,7 @@
'src/core/client_config/resolvers/sockaddr_resolver.h',
'src/core/client_config/subchannel.h',
'src/core/client_config/subchannel_factory.h',
+ 'src/core/client_config/subchannel_index.h',
'src/core/client_config/uri_parser.h',
'src/core/compression/algorithm_metadata.h',
'src/core/compression/message_compress.h',
diff --git a/grpc.gemspec b/grpc.gemspec
index 792222a..061b0f2 100755
--- a/grpc.gemspec
+++ b/grpc.gemspec
@@ -180,6 +180,7 @@
s.files += %w( src/core/client_config/resolvers/sockaddr_resolver.h )
s.files += %w( src/core/client_config/subchannel.h )
s.files += %w( src/core/client_config/subchannel_factory.h )
+ s.files += %w( src/core/client_config/subchannel_index.h )
s.files += %w( src/core/client_config/uri_parser.h )
s.files += %w( src/core/compression/algorithm_metadata.h )
s.files += %w( src/core/compression/message_compress.h )
@@ -311,6 +312,7 @@
s.files += %w( src/core/client_config/resolvers/sockaddr_resolver.c )
s.files += %w( src/core/client_config/subchannel.c )
s.files += %w( src/core/client_config/subchannel_factory.c )
+ s.files += %w( src/core/client_config/subchannel_index.c )
s.files += %w( src/core/client_config/uri_parser.c )
s.files += %w( src/core/compression/algorithm.c )
s.files += %w( src/core/compression/message_compress.c )
diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h
index e65349d..5e450b0 100644
--- a/include/grpc++/impl/codegen/call.h
+++ b/include/grpc++/impl/codegen/call.h
@@ -272,6 +272,7 @@
class DeserializeFunc {
public:
virtual Status Deserialize(grpc_byte_buffer* buf, int max_message_size) = 0;
+ virtual ~DeserializeFunc() {}
};
template <class R>
@@ -283,6 +284,8 @@
return SerializationTraits<R>::Deserialize(buf, message_, max_message_size);
}
+ ~DeserializeFuncType() override {}
+
private:
R* message_; // Not a managed pointer because management is external to this
};
diff --git a/include/grpc++/support/channel_arguments.h b/include/grpc++/support/channel_arguments.h
index a2960a7..a9ede35 100644
--- a/include/grpc++/support/channel_arguments.h
+++ b/include/grpc++/support/channel_arguments.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -51,7 +51,7 @@
/// concrete setters are provided.
class ChannelArguments {
public:
- ChannelArguments() {}
+ ChannelArguments();
~ChannelArguments() {}
ChannelArguments(const ChannelArguments& other);
@@ -62,8 +62,8 @@
void Swap(ChannelArguments& other);
- /// Populates this instance with the arguments from \a channel_args. Does not
- /// take ownership of \a channel_args.
+ /// Dump arguments in this instance to \a channel_args. Does not take
+ /// ownership of \a channel_args.
///
/// Note that the underlying arguments are shared. Changes made to either \a
/// channel_args or this instance would be reflected on both.
@@ -77,6 +77,9 @@
/// Set the compression algorithm for the channel.
void SetCompressionAlgorithm(grpc_compression_algorithm algorithm);
+ /// The given string will be sent at the front of the user agent string.
+ void SetUserAgentPrefix(const grpc::string& user_agent_prefix);
+
// Generic channel argument setters. Only for advanced use cases.
/// Set an integer argument \a value under \a key.
void SetInt(const grpc::string& key, int value);
@@ -92,6 +95,17 @@
friend class SecureChannelCredentials;
friend class testing::ChannelArgumentsTest;
+ /// Default pointer argument operations.
+ struct PointerVtableMembers {
+ static void* Copy(void* in) { return in; }
+ static void Destroy(void* in) {}
+ static int Compare(void* a, void* b) {
+ if (a < b) return -1;
+ if (a > b) return 1;
+ return 0;
+ }
+ };
+
// Returns empty string when it is not set.
grpc::string GetSslTargetNameOverride() const;
diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h
index ea1e96c..b11f6ff 100644
--- a/include/grpc/impl/codegen/grpc_types.h
+++ b/include/grpc/impl/codegen/grpc_types.h
@@ -68,6 +68,12 @@
GRPC_ARG_POINTER
} grpc_arg_type;
+typedef struct grpc_arg_pointer_vtable {
+ void *(*copy)(void *p);
+ void (*destroy)(void *p);
+ int (*cmp)(void *p, void *q);
+} grpc_arg_pointer_vtable;
+
/** A single argument... each argument has a key and a value
A note on naming keys:
@@ -88,8 +94,7 @@
int integer;
struct {
void *p;
- void *(*copy)(void *p);
- void (*destroy)(void *p);
+ const grpc_arg_pointer_vtable *vtable;
} pointer;
} value;
} grpc_arg;
diff --git a/include/grpc/support/avl.h b/include/grpc/support/avl.h
index 28eb5b1..2fe2d0b 100644
--- a/include/grpc/support/avl.h
+++ b/include/grpc/support/avl.h
@@ -81,11 +81,12 @@
if key exists in avl, the new tree's key entry updated
(i.e. a duplicate is not created) */
GPRAPI gpr_avl gpr_avl_add(gpr_avl avl, void *key, void *value);
-/** return a new tree with key deleted */
+/** return a new tree with key deleted
+ implicitly unrefs avl to allow easy chaining. */
GPRAPI gpr_avl gpr_avl_remove(gpr_avl avl, void *key);
/** lookup key, and return the associated value.
does not mutate avl.
returns NULL if key is not found. */
GPRAPI void *gpr_avl_get(gpr_avl avl, void *key);
-#endif
+#endif /* GRPC_SUPPORT_AVL_H */
diff --git a/include/grpc/support/useful.h b/include/grpc/support/useful.h
index 9f08d78..a0e76da 100644
--- a/include/grpc/support/useful.h
+++ b/include/grpc/support/useful.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -72,4 +72,6 @@
0x0f0f0f0f) % \
255)
+#define GPR_ICMP(a, b) ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0))
+
#endif /* GRPC_SUPPORT_USEFUL_H */
diff --git a/package.json b/package.json
index 0feb027..0f7f454 100644
--- a/package.json
+++ b/package.json
@@ -125,6 +125,7 @@
"src/core/client_config/resolvers/sockaddr_resolver.h",
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.h",
+ "src/core/client_config/subchannel_index.h",
"src/core/client_config/uri_parser.h",
"src/core/compression/algorithm_metadata.h",
"src/core/compression/message_compress.h",
@@ -256,6 +257,7 @@
"src/core/client_config/resolvers/sockaddr_resolver.c",
"src/core/client_config/subchannel.c",
"src/core/client_config/subchannel_factory.c",
+ "src/core/client_config/subchannel_index.c",
"src/core/client_config/uri_parser.c",
"src/core/compression/algorithm.c",
"src/core/compression/message_compress.c",
diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c
index 0427ce0..bae7a90 100644
--- a/src/core/channel/channel_args.c
+++ b/src/core/channel/channel_args.c
@@ -37,6 +37,7 @@
#include <grpc/census.h>
#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>
@@ -55,9 +56,8 @@
break;
case GRPC_ARG_POINTER:
dst.value.pointer = src->value.pointer;
- dst.value.pointer.p = src->value.pointer.copy
- ? src->value.pointer.copy(src->value.pointer.p)
- : src->value.pointer.p;
+ dst.value.pointer.p =
+ src->value.pointer.vtable->copy(src->value.pointer.p);
break;
}
return dst;
@@ -94,6 +94,58 @@
return grpc_channel_args_copy_and_add(a, b->args, b->num_args);
}
+static int cmp_arg(const grpc_arg *a, const grpc_arg *b) {
+ int c = GPR_ICMP(a->type, b->type);
+ if (c != 0) return c;
+ c = strcmp(a->key, b->key);
+ if (c != 0) return c;
+ switch (a->type) {
+ case GRPC_ARG_STRING:
+ return strcmp(a->value.string, b->value.string);
+ case GRPC_ARG_INTEGER:
+ return GPR_ICMP(a->value.integer, b->value.integer);
+ case GRPC_ARG_POINTER:
+ c = GPR_ICMP(a->value.pointer.p, b->value.pointer.p);
+ if (c != 0) {
+ c = GPR_ICMP(a->value.pointer.vtable, b->value.pointer.vtable);
+ if (c == 0) {
+ c = a->value.pointer.vtable->cmp(a->value.pointer.p,
+ b->value.pointer.p);
+ }
+ }
+ return c;
+ }
+ GPR_UNREACHABLE_CODE(return 0);
+}
+
+/* stabilizing comparison function: since channel_args ordering matters for
+ * keys with the same name, we need to preserve that ordering */
+static int cmp_key_stable(const void *ap, const void *bp) {
+ const grpc_arg *const *a = ap;
+ const grpc_arg *const *b = bp;
+ int c = strcmp((*a)->key, (*b)->key);
+ if (c == 0) c = GPR_ICMP(*a, *b);
+ return c;
+}
+
+grpc_channel_args *grpc_channel_args_normalize(const grpc_channel_args *a) {
+ grpc_arg **args = gpr_malloc(sizeof(grpc_arg *) * a->num_args);
+ for (size_t i = 0; i < a->num_args; i++) {
+ args[i] = &a->args[i];
+ }
+ qsort(args, a->num_args, sizeof(grpc_arg *), cmp_key_stable);
+
+ grpc_channel_args *b = gpr_malloc(sizeof(grpc_channel_args));
+ b->num_args = a->num_args;
+ b->args = gpr_malloc(sizeof(grpc_arg) * b->num_args);
+ for (size_t i = 0; i < a->num_args; i++) {
+ b->args[i] = copy_arg(args[i]);
+ }
+
+ gpr_free(args);
+ return b;
+}
+
void grpc_channel_args_destroy(grpc_channel_args *a) {
size_t i;
for (i = 0; i < a->num_args; i++) {
@@ -104,9 +156,7 @@
case GRPC_ARG_INTEGER:
break;
case GRPC_ARG_POINTER:
- if (a->args[i].value.pointer.destroy) {
- a->args[i].value.pointer.destroy(a->args[i].value.pointer.p);
- }
+ a->args[i].value.pointer.vtable->destroy(a->args[i].value.pointer.p);
break;
}
gpr_free(a->args[i].key);
@@ -208,3 +258,14 @@
return (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; /* All algs. enabled */
}
}
+
+int grpc_channel_args_compare(const grpc_channel_args *a,
+ const grpc_channel_args *b) {
+ int c = GPR_ICMP(a->num_args, b->num_args);
+ if (c != 0) return c;
+ for (size_t i = 0; i < a->num_args; i++) {
+ c = cmp_arg(&a->args[i], &b->args[i]);
+ if (c != 0) return c;
+ }
+ return 0;
+}
diff --git a/src/core/channel/channel_args.h b/src/core/channel/channel_args.h
index 480cc9a..b3a7c9f 100644
--- a/src/core/channel/channel_args.h
+++ b/src/core/channel/channel_args.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,6 +40,9 @@
/* Copy some arguments */
grpc_channel_args *grpc_channel_args_copy(const grpc_channel_args *src);
+/* Copy some arguments, stably sorting keys */
+grpc_channel_args *grpc_channel_args_normalize(const grpc_channel_args *a);
+
/** Copy some arguments and add the to_add parameter in the end.
If to_add is NULL, it is equivalent to call grpc_channel_args_copy. */
grpc_channel_args *grpc_channel_args_copy_and_add(const grpc_channel_args *src,
@@ -85,4 +88,7 @@
int grpc_channel_args_compression_algorithm_get_states(
const grpc_channel_args *a);
+int grpc_channel_args_compare(const grpc_channel_args *a,
+ const grpc_channel_args *b);
+
#endif /* GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_ARGS_H */
diff --git a/src/core/client_config/connector.c b/src/core/client_config/connector.c
index 1603ffb..aa34aa7 100644
--- a/src/core/client_config/connector.c
+++ b/src/core/client_config/connector.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,8 +33,9 @@
#include "src/core/client_config/connector.h"
-void grpc_connector_ref(grpc_connector* connector) {
+grpc_connector* grpc_connector_ref(grpc_connector* connector) {
connector->vtable->ref(connector);
+ return connector;
}
void grpc_connector_unref(grpc_exec_ctx* exec_ctx, grpc_connector* connector) {
diff --git a/src/core/client_config/connector.h b/src/core/client_config/connector.h
index b4482fa..b91eb51 100644
--- a/src/core/client_config/connector.h
+++ b/src/core/client_config/connector.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -81,7 +81,7 @@
grpc_connect_out_args *out_args, grpc_closure *notify);
};
-void grpc_connector_ref(grpc_connector *connector);
+grpc_connector *grpc_connector_ref(grpc_connector *connector);
void grpc_connector_unref(grpc_exec_ctx *exec_ctx, grpc_connector *connector);
/** Connect using the connector: max one outstanding call at a time */
void grpc_connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *connector,
diff --git a/src/core/client_config/subchannel.c b/src/core/client_config/subchannel.c
index 0a996a1..6599c75 100644
--- a/src/core/client_config/subchannel.c
+++ b/src/core/client_config/subchannel.c
@@ -36,16 +36,17 @@
#include <string.h>
#include <grpc/support/alloc.h>
+#include <grpc/support/avl.h>
#include "src/core/channel/channel_args.h"
#include "src/core/channel/client_channel.h"
#include "src/core/channel/connected_channel.h"
#include "src/core/client_config/initial_connect_string.h"
+#include "src/core/client_config/subchannel_index.h"
#include "src/core/iomgr/timer.h"
#include "src/core/profiling/timers.h"
#include "src/core/surface/channel.h"
#include "src/core/transport/connectivity_state.h"
-#include "src/core/transport/connectivity_state.h"
#define INTERNAL_REF_BITS 16
#define STRONG_REF_MASK (~(gpr_atm)((1 << INTERNAL_REF_BITS) - 1))
@@ -94,6 +95,8 @@
struct sockaddr *addr;
size_t addr_len;
+ grpc_subchannel_key *key;
+
/** initial string to send to peer */
gpr_slice initial_connect_string;
@@ -207,6 +210,7 @@
grpc_connectivity_state_destroy(exec_ctx, &c->state_tracker);
grpc_connector_unref(exec_ctx, c->connector);
grpc_pollset_set_destroy(&c->pollset_set);
+ grpc_subchannel_key_destroy(exec_ctx, c->key);
gpr_free(c);
}
@@ -222,22 +226,42 @@
return old_val;
}
-void grpc_subchannel_ref(grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
+grpc_subchannel *grpc_subchannel_ref(grpc_subchannel *c
+ GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
gpr_atm old_refs;
old_refs = ref_mutate(c, (1 << INTERNAL_REF_BITS),
0 REF_MUTATE_PURPOSE("STRONG_REF"));
GPR_ASSERT((old_refs & STRONG_REF_MASK) != 0);
+ return c;
}
-void grpc_subchannel_weak_ref(grpc_subchannel *c
- GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
+grpc_subchannel *grpc_subchannel_weak_ref(grpc_subchannel *c
+ GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
gpr_atm old_refs;
old_refs = ref_mutate(c, 1, 0 REF_MUTATE_PURPOSE("WEAK_REF"));
GPR_ASSERT(old_refs != 0);
+ return c;
+}
+
+grpc_subchannel *grpc_subchannel_ref_from_weak_ref(
+ grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) {
+ if (!c) return NULL;
+ for (;;) {
+ gpr_atm old_refs = gpr_atm_acq_load(&c->ref_pair);
+ if (old_refs >= (1 << INTERNAL_REF_BITS)) {
+ gpr_atm new_refs = old_refs + (1 << INTERNAL_REF_BITS);
+ if (gpr_atm_rel_cas(&c->ref_pair, old_refs, new_refs)) {
+ return c;
+ }
+ } else {
+ return NULL;
+ }
+ }
}
static void disconnect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) {
grpc_connected_subchannel *con;
+ grpc_subchannel_index_unregister(exec_ctx, c->key, c);
gpr_mu_lock(&c->mu);
GPR_ASSERT(!c->disconnected);
c->disconnected = 1;
@@ -276,10 +300,19 @@
return (uint32_t)(gpr_time_to_millis(gpr_now(GPR_CLOCK_MONOTONIC)));
}
-grpc_subchannel *grpc_subchannel_create(grpc_connector *connector,
+grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx,
+ grpc_connector *connector,
grpc_subchannel_args *args) {
- grpc_subchannel *c = gpr_malloc(sizeof(*c));
+ grpc_subchannel_key *key = grpc_subchannel_key_create(connector, args);
+ grpc_subchannel *c = grpc_subchannel_index_find(exec_ctx, key);
+ if (c) {
+ grpc_subchannel_key_destroy(exec_ctx, key);
+ return c;
+ }
+
+ c = gpr_malloc(sizeof(*c));
memset(c, 0, sizeof(*c));
+ c->key = key;
gpr_atm_no_barrier_store(&c->ref_pair, 1 << INTERNAL_REF_BITS);
c->connector = connector;
grpc_connector_ref(c->connector);
@@ -305,7 +338,8 @@
grpc_connectivity_state_init(&c->state_tracker, GRPC_CHANNEL_IDLE,
"subchannel");
gpr_mu_init(&c->mu);
- return c;
+
+ return grpc_subchannel_index_register(exec_ctx, key, c);
}
static void continue_connect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) {
diff --git a/src/core/client_config/subchannel.h b/src/core/client_config/subchannel.h
index 57c7c9d..313e63c 100644
--- a/src/core/client_config/subchannel.h
+++ b/src/core/client_config/subchannel.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -48,6 +48,8 @@
#ifdef GRPC_STREAM_REFCOUNT_DEBUG
#define GRPC_SUBCHANNEL_REF(p, r) \
grpc_subchannel_ref((p), __FILE__, __LINE__, (r))
+#define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \
+ grpc_subchannel_ref_from_weak_ref((p), __FILE__, __LINE__, (r))
#define GRPC_SUBCHANNEL_UNREF(cl, p, r) \
grpc_subchannel_unref((cl), (p), __FILE__, __LINE__, (r))
#define GRPC_SUBCHANNEL_WEAK_REF(p, r) \
@@ -66,6 +68,8 @@
, const char *file, int line, const char *reason
#else
#define GRPC_SUBCHANNEL_REF(p, r) grpc_subchannel_ref((p))
+#define GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(p, r) \
+ grpc_subchannel_ref_from_weak_ref((p))
#define GRPC_SUBCHANNEL_UNREF(cl, p, r) grpc_subchannel_unref((cl), (p))
#define GRPC_SUBCHANNEL_WEAK_REF(p, r) grpc_subchannel_weak_ref((p))
#define GRPC_SUBCHANNEL_WEAK_UNREF(cl, p, r) \
@@ -79,13 +83,15 @@
#define GRPC_SUBCHANNEL_REF_EXTRA_ARGS
#endif
-void grpc_subchannel_ref(grpc_subchannel *channel
- GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
+grpc_subchannel *grpc_subchannel_ref(grpc_subchannel *channel
+ GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
+grpc_subchannel *grpc_subchannel_ref_from_weak_ref(
+ grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
void grpc_subchannel_unref(grpc_exec_ctx *exec_ctx,
grpc_subchannel *channel
GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
-void grpc_subchannel_weak_ref(grpc_subchannel *channel
- GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
+grpc_subchannel *grpc_subchannel_weak_ref(grpc_subchannel *channel
+ GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
void grpc_subchannel_weak_unref(grpc_exec_ctx *exec_ctx,
grpc_subchannel *channel
GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
@@ -146,6 +152,8 @@
grpc_subchannel_call *subchannel_call);
struct grpc_subchannel_args {
+ /* When updating this struct, also update subchannel_index.c */
+
/** Channel filters for this channel - wrapped factories will likely
want to mutate this */
const grpc_channel_filter **filters;
@@ -159,7 +167,8 @@
};
/** create a subchannel given a connector */
-grpc_subchannel *grpc_subchannel_create(grpc_connector *connector,
+grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx,
+ grpc_connector *connector,
grpc_subchannel_args *args);
#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_H */
diff --git a/src/core/client_config/subchannel_index.c b/src/core/client_config/subchannel_index.c
new file mode 100644
index 0000000..f78a7fd
--- /dev/null
+++ b/src/core/client_config/subchannel_index.c
@@ -0,0 +1,259 @@
+//
+//
+// Copyright 2016, 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 "src/core/client_config/subchannel_index.h"
+
+#include <stdbool.h>
+#include <string.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/avl.h>
+#include <grpc/support/tls.h>
+
+#include "src/core/channel/channel_args.h"
+
+// a map of subchannel_key --> subchannel, used for detecting connections
+// to the same destination in order to share them
+static gpr_avl g_subchannel_index;
+
+static gpr_mu g_mu;
+
+struct grpc_subchannel_key {
+ grpc_connector *connector;
+ grpc_subchannel_args args;
+};
+
+GPR_TLS_DECL(subchannel_index_exec_ctx);
+
+static void enter_ctx(grpc_exec_ctx *exec_ctx) {
+ GPR_ASSERT(gpr_tls_get(&subchannel_index_exec_ctx) == 0);
+ gpr_tls_set(&subchannel_index_exec_ctx, (intptr_t)exec_ctx);
+}
+
+static void leave_ctx(grpc_exec_ctx *exec_ctx) {
+ GPR_ASSERT(gpr_tls_get(&subchannel_index_exec_ctx) == (intptr_t)exec_ctx);
+ gpr_tls_set(&subchannel_index_exec_ctx, 0);
+}
+
+static grpc_exec_ctx *current_ctx() {
+ grpc_exec_ctx *c = (grpc_exec_ctx *)gpr_tls_get(&subchannel_index_exec_ctx);
+ GPR_ASSERT(c != NULL);
+ return c;
+}
+
+static grpc_subchannel_key *create_key(
+ grpc_connector *connector, grpc_subchannel_args *args,
+ grpc_channel_args *(*copy_channel_args)(const grpc_channel_args *args)) {
+ grpc_subchannel_key *k = gpr_malloc(sizeof(*k));
+ k->connector = grpc_connector_ref(connector);
+ k->args.filter_count = args->filter_count;
+ k->args.filters = gpr_malloc(sizeof(*k->args.filters) * k->args.filter_count);
+ memcpy((grpc_channel_filter *)k->args.filters, args->filters,
+ sizeof(*k->args.filters) * k->args.filter_count);
+ k->args.addr_len = args->addr_len;
+ k->args.addr = gpr_malloc(args->addr_len);
+ memcpy(k->args.addr, args->addr, k->args.addr_len);
+ k->args.args = copy_channel_args(args->args);
+ return k;
+}
+
+grpc_subchannel_key *grpc_subchannel_key_create(grpc_connector *connector,
+ grpc_subchannel_args *args) {
+ return create_key(connector, args, grpc_channel_args_normalize);
+}
+
+static grpc_subchannel_key *subchannel_key_copy(grpc_subchannel_key *k) {
+ return create_key(k->connector, &k->args, grpc_channel_args_copy);
+}
+
+static int subchannel_key_compare(grpc_subchannel_key *a,
+ grpc_subchannel_key *b) {
+ int c = GPR_ICMP(a->connector, b->connector);
+ if (c != 0) return c;
+ c = GPR_ICMP(a->args.addr_len, b->args.addr_len);
+ if (c != 0) return c;
+ c = GPR_ICMP(a->args.filter_count, b->args.filter_count);
+ if (c != 0) return c;
+ c = memcmp(a->args.addr, b->args.addr, a->args.addr_len);
+ if (c != 0) return c;
+ c = memcmp(a->args.filters, b->args.filters,
+ a->args.filter_count * sizeof(*a->args.filters));
+ return grpc_channel_args_compare(a->args.args, b->args.args);
+}
+
+void grpc_subchannel_key_destroy(grpc_exec_ctx *exec_ctx,
+ grpc_subchannel_key *k) {
+ grpc_connector_unref(exec_ctx, k->connector);
+ gpr_free(k->args.addr);
+ gpr_free((grpc_channel_args *)k->args.filters);
+ grpc_channel_args_destroy((grpc_channel_args *)k->args.args);
+ gpr_free(k);
+}
+
+static void sck_avl_destroy(void *p) {
+ grpc_subchannel_key_destroy(current_ctx(), p);
+}
+
+static void *sck_avl_copy(void *p) { return subchannel_key_copy(p); }
+
+static long sck_avl_compare(void *a, void *b) {
+ return subchannel_key_compare(a, b);
+}
+
+static void scv_avl_destroy(void *p) {
+ GRPC_SUBCHANNEL_WEAK_UNREF(current_ctx(), p, "subchannel_index");
+}
+
+static void *scv_avl_copy(void *p) {
+ GRPC_SUBCHANNEL_WEAK_REF(p, "subchannel_index");
+ return p;
+}
+
+static const gpr_avl_vtable subchannel_avl_vtable = {
+ .destroy_key = sck_avl_destroy,
+ .copy_key = sck_avl_copy,
+ .compare_keys = sck_avl_compare,
+ .destroy_value = scv_avl_destroy,
+ .copy_value = scv_avl_copy};
+
+void grpc_subchannel_index_init(void) {
+ g_subchannel_index = gpr_avl_create(&subchannel_avl_vtable);
+ gpr_mu_init(&g_mu);
+}
+
+void grpc_subchannel_index_shutdown(void) {
+ gpr_mu_destroy(&g_mu);
+ gpr_avl_unref(g_subchannel_index);
+}
+
+grpc_subchannel *grpc_subchannel_index_find(grpc_exec_ctx *exec_ctx,
+ grpc_subchannel_key *key) {
+ enter_ctx(exec_ctx);
+
+ // Lock, and take a reference to the subchannel index.
+ // We don't need to do the search under a lock as avl's are immutable.
+ gpr_mu_lock(&g_mu);
+ gpr_avl index = gpr_avl_ref(g_subchannel_index);
+ gpr_mu_unlock(&g_mu);
+
+ grpc_subchannel *c =
+ GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(gpr_avl_get(index, key), "index_find");
+ gpr_avl_unref(index);
+
+ leave_ctx(exec_ctx);
+ return c;
+}
+
+grpc_subchannel *grpc_subchannel_index_register(grpc_exec_ctx *exec_ctx,
+ grpc_subchannel_key *key,
+ grpc_subchannel *constructed) {
+ enter_ctx(exec_ctx);
+
+ grpc_subchannel *c = NULL;
+
+ while (c == NULL) {
+ // Compare and swap loop:
+ // - take a reference to the current index
+ gpr_mu_lock(&g_mu);
+ gpr_avl index = gpr_avl_ref(g_subchannel_index);
+ gpr_mu_unlock(&g_mu);
+
+ // - Check to see if a subchannel already exists
+ c = gpr_avl_get(index, key);
+ if (c != NULL) {
+ // yes -> we're done
+ GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, constructed, "index_register");
+ } else {
+ // no -> update the avl and compare/swap
+ gpr_avl updated =
+ gpr_avl_add(gpr_avl_ref(index), subchannel_key_copy(key),
+ GRPC_SUBCHANNEL_WEAK_REF(constructed, "index_register"));
+
+ // it may happen (but it's expected to be unlikely)
+ // that some other thread has changed the index:
+ // compare/swap here to check that, and retry as necessary
+ gpr_mu_lock(&g_mu);
+ if (index.root == g_subchannel_index.root) {
+ GPR_SWAP(gpr_avl, updated, g_subchannel_index);
+ c = constructed;
+ }
+ gpr_mu_unlock(&g_mu);
+
+ gpr_avl_unref(updated);
+ }
+ gpr_avl_unref(index);
+ }
+
+ leave_ctx(exec_ctx);
+
+ return c;
+}
+
+void grpc_subchannel_index_unregister(grpc_exec_ctx *exec_ctx,
+ grpc_subchannel_key *key,
+ grpc_subchannel *constructed) {
+ enter_ctx(exec_ctx);
+
+ bool done = false;
+ while (!done) {
+ // Compare and swap loop:
+ // - take a reference to the current index
+ gpr_mu_lock(&g_mu);
+ gpr_avl index = gpr_avl_ref(g_subchannel_index);
+ gpr_mu_unlock(&g_mu);
+
+ // Check to see if this key still refers to the previously
+ // registered subchannel
+ grpc_subchannel *c = gpr_avl_get(index, key);
+ if (c != constructed) {
+ gpr_avl_unref(index);
+ break;
+ }
+
+ // compare and swap the update (some other thread may have
+ // mutated the index behind us)
+ gpr_avl updated = gpr_avl_remove(gpr_avl_ref(index), key);
+
+ gpr_mu_lock(&g_mu);
+ if (index.root == g_subchannel_index.root) {
+ GPR_SWAP(gpr_avl, updated, g_subchannel_index);
+ done = true;
+ }
+ gpr_mu_unlock(&g_mu);
+
+ gpr_avl_unref(updated);
+ gpr_avl_unref(index);
+ }
+
+ leave_ctx(exec_ctx);
+}
diff --git a/src/core/client_config/subchannel_index.h b/src/core/client_config/subchannel_index.h
new file mode 100644
index 0000000..095ef17
--- /dev/null
+++ b/src/core/client_config/subchannel_index.h
@@ -0,0 +1,77 @@
+/*
+ *
+ * Copyright 2016, 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.
+ *
+ */
+
+#ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_INDEX_H
+#define GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_INDEX_H
+
+#include "src/core/client_config/connector.h"
+#include "src/core/client_config/subchannel.h"
+
+/** \file Provides an index of active subchannels so that they can be
+ shared amongst channels */
+
+typedef struct grpc_subchannel_key grpc_subchannel_key;
+
+/** Create a key that can be used to uniquely identify a subchannel */
+grpc_subchannel_key *grpc_subchannel_key_create(grpc_connector *con,
+ grpc_subchannel_args *args);
+
+/** Destroy a subchannel key */
+void grpc_subchannel_key_destroy(grpc_exec_ctx *exec_ctx,
+ grpc_subchannel_key *key);
+
+/** Given a subchannel key, find the subchannel registered for it.
+ Returns NULL if no such channel exists.
+ Thread-safe. */
+grpc_subchannel *grpc_subchannel_index_find(grpc_exec_ctx *exec_ctx,
+ grpc_subchannel_key *key);
+
+/** Register a subchannel against a key.
+ Takes ownership of \a constructed.
+ Returns the registered subchannel. This may be different from
+ \a constructed in the case of a registration race. */
+grpc_subchannel *grpc_subchannel_index_register(grpc_exec_ctx *exec_ctx,
+ grpc_subchannel_key *key,
+ grpc_subchannel *constructed);
+
+/** Remove \a constructed as the registered subchannel for \a key. */
+void grpc_subchannel_index_unregister(grpc_exec_ctx *exec_ctx,
+ grpc_subchannel_key *key,
+ grpc_subchannel *constructed);
+
+/** Initialize the subchannel index (global) */
+void grpc_subchannel_index_init(void);
+/** Shutdown the subchannel index (global) */
+void grpc_subchannel_index_shutdown(void);
+
+#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_INDEX_H */
diff --git a/src/core/iomgr/pollset_posix.h b/src/core/iomgr/pollset_posix.h
index b34bb09..5868b3f 100644
--- a/src/core/iomgr/pollset_posix.h
+++ b/src/core/iomgr/pollset_posix.h
@@ -142,6 +142,10 @@
void grpc_remove_fd_from_all_epoll_sets(int fd);
/* override to allow tests to hook poll() usage */
+/* NOTE: Any changes to grpc_poll_function must take place when the gRPC
+ is certainly not doing any polling anywhere.
+ Otherwise, there might be a race between changing the variable and actually
+ doing a polling operation */
typedef int (*grpc_poll_function_type)(struct pollfd *, nfds_t, int);
extern grpc_poll_function_type grpc_poll_function;
extern grpc_wakeup_fd grpc_global_wakeup_fd;
diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c
index afba007..c58574b 100644
--- a/src/core/security/credentials.c
+++ b/src/core/security/credentials.c
@@ -196,14 +196,21 @@
return grpc_server_credentials_ref(p);
}
+static int server_credentials_pointer_cmp(void *a, void *b) {
+ return GPR_ICMP(a, b);
+}
+
+static const grpc_arg_pointer_vtable cred_ptr_vtable = {
+ server_credentials_pointer_arg_copy, server_credentials_pointer_arg_destroy,
+ server_credentials_pointer_cmp};
+
grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials *p) {
grpc_arg arg;
memset(&arg, 0, sizeof(grpc_arg));
arg.type = GRPC_ARG_POINTER;
arg.key = GRPC_SERVER_CREDENTIALS_ARG;
arg.value.pointer.p = p;
- arg.value.pointer.copy = server_credentials_pointer_arg_copy;
- arg.value.pointer.destroy = server_credentials_pointer_arg_destroy;
+ arg.value.pointer.vtable = &cred_ptr_vtable;
return arg;
}
diff --git a/src/core/security/security_connector.c b/src/core/security/security_connector.c
index bdccbab..b462053 100644
--- a/src/core/security/security_connector.c
+++ b/src/core/security/security_connector.c
@@ -202,12 +202,17 @@
return GRPC_SECURITY_CONNECTOR_REF(p, "connector_pointer_arg");
}
+static int connector_pointer_cmp(void *a, void *b) { return GPR_ICMP(a, b); }
+
+static const grpc_arg_pointer_vtable connector_pointer_vtable = {
+ connector_pointer_arg_copy, connector_pointer_arg_destroy,
+ connector_pointer_cmp};
+
grpc_arg grpc_security_connector_to_arg(grpc_security_connector *sc) {
grpc_arg result;
result.type = GRPC_ARG_POINTER;
result.key = GRPC_SECURITY_CONNECTOR_ARG;
- result.value.pointer.destroy = connector_pointer_arg_destroy;
- result.value.pointer.copy = connector_pointer_arg_copy;
+ result.value.pointer.vtable = &connector_pointer_vtable;
result.value.pointer.p = sc;
return result;
}
diff --git a/src/core/security/security_context.c b/src/core/security/security_context.c
index 2068c97..a71b3bc 100644
--- a/src/core/security/security_context.c
+++ b/src/core/security/security_context.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -309,14 +309,19 @@
return GRPC_AUTH_CONTEXT_REF(p, "auth_context_pointer_arg");
}
+static int auth_context_pointer_cmp(void *a, void *b) { return GPR_ICMP(a, b); }
+
+static const grpc_arg_pointer_vtable auth_context_pointer_vtable = {
+ auth_context_pointer_arg_copy, auth_context_pointer_arg_destroy,
+ auth_context_pointer_cmp};
+
grpc_arg grpc_auth_context_to_arg(grpc_auth_context *p) {
grpc_arg arg;
memset(&arg, 0, sizeof(grpc_arg));
arg.type = GRPC_ARG_POINTER;
arg.key = GRPC_AUTH_CONTEXT_ARG;
arg.value.pointer.p = p;
- arg.value.pointer.copy = auth_context_pointer_arg_copy;
- arg.value.pointer.destroy = auth_context_pointer_arg_destroy;
+ arg.value.pointer.vtable = &auth_context_pointer_vtable;
return arg;
}
diff --git a/src/core/support/avl.c b/src/core/support/avl.c
index 9734c99..f378b3e 100644
--- a/src/core/support/avl.c
+++ b/src/core/support/avl.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -167,7 +167,7 @@
vtable->copy_key(right->left->key),
vtable->copy_value(right->left->value),
new_node(key, value, left, ref_node(right->left->left)),
- new_node(vtable->copy_key(right->key), vtable->copy_key(right->value),
+ new_node(vtable->copy_key(right->key), vtable->copy_value(right->value),
ref_node(right->left->right), ref_node(right->right)));
unref_node(vtable, right);
return n;
diff --git a/src/core/surface/channel_create.c b/src/core/surface/channel_create.c
index 4d4337d..fd7e20e 100644
--- a/src/core/surface/channel_create.c
+++ b/src/core/surface/channel_create.c
@@ -172,7 +172,7 @@
c->base.vtable = &connector_vtable;
gpr_ref_init(&c->refs, 1);
args->args = final_args;
- s = grpc_subchannel_create(&c->base, args);
+ s = grpc_subchannel_create(exec_ctx, &c->base, args);
grpc_connector_unref(exec_ctx, &c->base);
grpc_channel_args_destroy(final_args);
return s;
diff --git a/src/core/surface/init.c b/src/core/surface/init.c
index e3ab70d..a4a53d3 100644
--- a/src/core/surface/init.c
+++ b/src/core/surface/init.c
@@ -46,6 +46,8 @@
#include "src/core/client_config/resolver_registry.h"
#include "src/core/client_config/resolvers/dns_resolver.h"
#include "src/core/client_config/resolvers/sockaddr_resolver.h"
+#include "src/core/client_config/subchannel.h"
+#include "src/core/client_config/subchannel_index.h"
#include "src/core/debug/trace.h"
#include "src/core/iomgr/executor.h"
#include "src/core/iomgr/iomgr.h"
@@ -127,6 +129,7 @@
}
gpr_timers_global_init();
grpc_cq_global_init();
+ grpc_subchannel_index_init();
for (i = 0; i < g_number_of_plugins; i++) {
if (g_all_of_the_plugins[i].init != NULL) {
g_all_of_the_plugins[i].init();
@@ -145,6 +148,7 @@
grpc_executor_shutdown();
grpc_cq_global_shutdown();
grpc_iomgr_shutdown();
+ grpc_subchannel_index_shutdown();
census_shutdown();
gpr_timers_global_destroy();
grpc_tracer_shutdown();
diff --git a/src/core/surface/secure_channel_create.c b/src/core/surface/secure_channel_create.c
index dd1441a..9c04426 100644
--- a/src/core/surface/secure_channel_create.c
+++ b/src/core/surface/secure_channel_create.c
@@ -238,7 +238,7 @@
gpr_mu_init(&c->mu);
gpr_ref_init(&c->refs, 1);
args->args = final_args;
- s = grpc_subchannel_create(&c->base, args);
+ s = grpc_subchannel_create(exec_ctx, &c->base, args);
grpc_connector_unref(exec_ctx, &c->base);
grpc_channel_args_destroy(final_args);
return s;
diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc
index fdaa28f..76a1b31 100644
--- a/src/cpp/client/create_channel.cc
+++ b/src/cpp/client/create_channel.cc
@@ -32,7 +32,6 @@
*/
#include <memory>
-#include <sstream>
#include <grpc++/channel.h>
#include <grpc++/create_channel.h>
@@ -56,13 +55,8 @@
const ChannelArguments& args) {
internal::GrpcLibrary
init_lib; // We need to call init in case of a bad creds.
- ChannelArguments cp_args = args;
- std::ostringstream user_agent_prefix;
- user_agent_prefix << "grpc-c++/" << grpc_version_string();
- cp_args.SetString(GRPC_ARG_PRIMARY_USER_AGENT_STRING,
- user_agent_prefix.str());
return creds
- ? creds->CreateChannel(target, cp_args)
+ ? creds->CreateChannel(target, args)
: CreateChannelInternal("", grpc_lame_client_channel_create(
NULL, GRPC_STATUS_INVALID_ARGUMENT,
"Invalid credentials."));
diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc
index 90cd513..d7faa5e 100644
--- a/src/cpp/common/channel_arguments.cc
+++ b/src/cpp/common/channel_arguments.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,14 +30,23 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
-
#include <grpc++/support/channel_arguments.h>
+#include <sstream>
+
+#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/support/log.h>
#include "src/core/channel/channel_args.h"
namespace grpc {
+ChannelArguments::ChannelArguments() {
+ std::ostringstream user_agent_prefix;
+ user_agent_prefix << "grpc-c++/" << grpc_version_string();
+ // This will be ignored if used on the server side.
+ SetString(GRPC_ARG_PRIMARY_USER_AGENT_STRING, user_agent_prefix.str());
+}
+
ChannelArguments::ChannelArguments(const ChannelArguments& other)
: strings_(other.strings_) {
args_.reserve(other.args_.size());
@@ -62,9 +71,7 @@
break;
case GRPC_ARG_POINTER:
ap.value.pointer = a->value.pointer;
- ap.value.pointer.p = a->value.pointer.copy
- ? a->value.pointer.copy(ap.value.pointer.p)
- : ap.value.pointer.p;
+ ap.value.pointer.p = a->value.pointer.vtable->copy(ap.value.pointer.p);
break;
}
args_.push_back(ap);
@@ -81,6 +88,31 @@
SetInt(GRPC_COMPRESSION_ALGORITHM_ARG, algorithm);
}
+// Note: a second call to this will add in front the result of the first call.
+// An example is calling this on a copy of ChannelArguments which already has a
+// prefix. The user can build up a prefix string by calling this multiple times,
+// each with more significant identifier.
+void ChannelArguments::SetUserAgentPrefix(
+ const grpc::string& user_agent_prefix) {
+ if (user_agent_prefix.empty()) {
+ return;
+ }
+ bool replaced = false;
+ for (auto it = args_.begin(); it != args_.end(); ++it) {
+ const grpc_arg& arg = *it;
+ if (arg.type == GRPC_ARG_STRING &&
+ grpc::string(arg.key) == GRPC_ARG_PRIMARY_USER_AGENT_STRING) {
+ strings_.push_back(user_agent_prefix + " " + arg.value.string);
+ it->value.string = const_cast<char*>(strings_.back().c_str());
+ replaced = true;
+ break;
+ }
+ }
+ if (!replaced) {
+ SetString(GRPC_ARG_PRIMARY_USER_AGENT_STRING, user_agent_prefix);
+ }
+}
+
void ChannelArguments::SetInt(const grpc::string& key, int value) {
grpc_arg arg;
arg.type = GRPC_ARG_INTEGER;
@@ -92,13 +124,15 @@
}
void ChannelArguments::SetPointer(const grpc::string& key, void* value) {
+ static const grpc_arg_pointer_vtable vtable = {
+ &PointerVtableMembers::Copy, &PointerVtableMembers::Destroy,
+ &PointerVtableMembers::Compare};
grpc_arg arg;
arg.type = GRPC_ARG_POINTER;
strings_.push_back(key);
arg.key = const_cast<char*>(strings_.back().c_str());
arg.value.pointer.p = value;
- arg.value.pointer.copy = nullptr;
- arg.value.pointer.destroy = nullptr;
+ arg.value.pointer.vtable = &vtable;
args_.push_back(arg);
}
diff --git a/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs b/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs
index f77e9c6..1837f5c 100644
--- a/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs
+++ b/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -71,7 +71,7 @@
/// <returns>The interceptor.</returns>
public static AsyncAuthInterceptor FromAccessToken(string accessToken)
{
- Preconditions.CheckNotNull(accessToken);
+ GrpcPreconditions.CheckNotNull(accessToken);
return new AsyncAuthInterceptor(async (context, metadata) =>
{
metadata.Add(CreateBearerTokenHeader(accessToken));
diff --git a/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs b/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs
index 5c9ab04..5ba06d6 100644
--- a/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs
+++ b/src/csharp/Grpc.Core/AsyncAuthInterceptor.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -61,8 +61,8 @@
/// </summary>
public AuthInterceptorContext(string serviceUrl, string methodName)
{
- this.serviceUrl = Preconditions.CheckNotNull(serviceUrl);
- this.methodName = Preconditions.CheckNotNull(methodName);
+ this.serviceUrl = GrpcPreconditions.CheckNotNull(serviceUrl);
+ this.methodName = GrpcPreconditions.CheckNotNull(methodName);
}
/// <summary>
diff --git a/src/csharp/Grpc.Core/CallCredentials.cs b/src/csharp/Grpc.Core/CallCredentials.cs
index a71c890..7cd41d0 100644
--- a/src/csharp/Grpc.Core/CallCredentials.cs
+++ b/src/csharp/Grpc.Core/CallCredentials.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -87,7 +87,7 @@
/// <param name="interceptor">authentication interceptor</param>
public MetadataCredentials(AsyncAuthInterceptor interceptor)
{
- this.interceptor = Preconditions.CheckNotNull(interceptor);
+ this.interceptor = GrpcPreconditions.CheckNotNull(interceptor);
}
internal override CallCredentialsSafeHandle ToNativeCredentials()
@@ -111,7 +111,7 @@
/// <param name="credentials">credentials to compose</param>
public CompositeCallCredentials(params CallCredentials[] credentials)
{
- Preconditions.CheckArgument(credentials.Length >= 2, "Composite credentials object can only be created from 2 or more credentials.");
+ GrpcPreconditions.CheckArgument(credentials.Length >= 2, "Composite credentials object can only be created from 2 or more credentials.");
this.credentials = new List<CallCredentials>(credentials);
}
diff --git a/src/csharp/Grpc.Core/CallInvocationDetails.cs b/src/csharp/Grpc.Core/CallInvocationDetails.cs
index 8228b8f..52bfbe6 100644
--- a/src/csharp/Grpc.Core/CallInvocationDetails.cs
+++ b/src/csharp/Grpc.Core/CallInvocationDetails.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -85,11 +85,11 @@
/// <param name="options">Call options.</param>
public CallInvocationDetails(Channel channel, string method, string host, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller, CallOptions options)
{
- this.channel = Preconditions.CheckNotNull(channel, "channel");
- this.method = Preconditions.CheckNotNull(method, "method");
+ this.channel = GrpcPreconditions.CheckNotNull(channel, "channel");
+ this.method = GrpcPreconditions.CheckNotNull(method, "method");
this.host = host;
- this.requestMarshaller = Preconditions.CheckNotNull(requestMarshaller, "requestMarshaller");
- this.responseMarshaller = Preconditions.CheckNotNull(responseMarshaller, "responseMarshaller");
+ this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarshaller, "requestMarshaller");
+ this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMarshaller, "responseMarshaller");
this.options = options;
}
diff --git a/src/csharp/Grpc.Core/CallOptions.cs b/src/csharp/Grpc.Core/CallOptions.cs
index 1fda80c..7bd95d4 100644
--- a/src/csharp/Grpc.Core/CallOptions.cs
+++ b/src/csharp/Grpc.Core/CallOptions.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -176,13 +176,13 @@
{
if (propagationToken.Options.IsPropagateDeadline)
{
- Preconditions.CheckArgument(!newOptions.deadline.HasValue,
+ GrpcPreconditions.CheckArgument(!newOptions.deadline.HasValue,
"Cannot propagate deadline from parent call. The deadline has already been set explicitly.");
newOptions.deadline = propagationToken.ParentDeadline;
}
if (propagationToken.Options.IsPropagateCancellation)
{
- Preconditions.CheckArgument(!newOptions.cancellationToken.CanBeCanceled,
+ GrpcPreconditions.CheckArgument(!newOptions.cancellationToken.CanBeCanceled,
"Cannot propagate cancellation token from parent call. The cancellation token has already been set to a non-default value.");
newOptions.cancellationToken = propagationToken.ParentCancellationToken;
}
diff --git a/src/csharp/Grpc.Core/Channel.cs b/src/csharp/Grpc.Core/Channel.cs
index d8d43c7..d7a482d 100644
--- a/src/csharp/Grpc.Core/Channel.cs
+++ b/src/csharp/Grpc.Core/Channel.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -68,7 +68,7 @@
/// <param name="options">Channel options.</param>
public Channel(string target, ChannelCredentials credentials, IEnumerable<ChannelOption> options = null)
{
- this.target = Preconditions.CheckNotNull(target, "target");
+ this.target = GrpcPreconditions.CheckNotNull(target, "target");
this.options = CreateOptionsDictionary(options);
EnsureUserAgentChannelOption(this.options);
this.environment = GrpcEnvironment.AddRef();
@@ -117,7 +117,7 @@
/// </summary>
public Task WaitForStateChangedAsync(ChannelState lastObservedState, DateTime? deadline = null)
{
- Preconditions.CheckArgument(lastObservedState != ChannelState.FatalFailure,
+ GrpcPreconditions.CheckArgument(lastObservedState != ChannelState.FatalFailure,
"FatalFailure is a terminal state. No further state changes can occur.");
var tcs = new TaskCompletionSource<object>();
var deadlineTimespec = deadline.HasValue ? Timespec.FromDateTime(deadline.Value) : Timespec.InfFuture;
@@ -184,7 +184,7 @@
{
lock (myLock)
{
- Preconditions.CheckState(!shutdownRequested);
+ GrpcPreconditions.CheckState(!shutdownRequested);
shutdownRequested = true;
}
@@ -221,7 +221,7 @@
bool success = false;
handle.DangerousAddRef(ref success);
- Preconditions.CheckState(success);
+ GrpcPreconditions.CheckState(success);
}
internal void RemoveCallReference(object call)
diff --git a/src/csharp/Grpc.Core/ChannelCredentials.cs b/src/csharp/Grpc.Core/ChannelCredentials.cs
index 5d96958..03cda28 100644
--- a/src/csharp/Grpc.Core/ChannelCredentials.cs
+++ b/src/csharp/Grpc.Core/ChannelCredentials.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -183,9 +183,9 @@
/// <param name="callCredentials">channelCredentials to compose</param>
public CompositeChannelCredentials(ChannelCredentials channelCredentials, CallCredentials callCredentials)
{
- this.channelCredentials = Preconditions.CheckNotNull(channelCredentials);
- this.callCredentials = Preconditions.CheckNotNull(callCredentials);
- Preconditions.CheckArgument(channelCredentials.IsComposable, "Supplied channel credentials do not allow composition.");
+ this.channelCredentials = GrpcPreconditions.CheckNotNull(channelCredentials);
+ this.callCredentials = GrpcPreconditions.CheckNotNull(callCredentials);
+ GrpcPreconditions.CheckArgument(channelCredentials.IsComposable, "Supplied channel credentials do not allow composition.");
}
internal override ChannelCredentialsSafeHandle ToNativeCredentials()
diff --git a/src/csharp/Grpc.Core/ChannelOptions.cs b/src/csharp/Grpc.Core/ChannelOptions.cs
index d70673c..65e15e2 100644
--- a/src/csharp/Grpc.Core/ChannelOptions.cs
+++ b/src/csharp/Grpc.Core/ChannelOptions.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -73,8 +73,8 @@
public ChannelOption(string name, string stringValue)
{
this.type = OptionType.String;
- this.name = Preconditions.CheckNotNull(name, "name");
- this.stringValue = Preconditions.CheckNotNull(stringValue, "stringValue");
+ this.name = GrpcPreconditions.CheckNotNull(name, "name");
+ this.stringValue = GrpcPreconditions.CheckNotNull(stringValue, "stringValue");
}
/// <summary>
@@ -85,7 +85,7 @@
public ChannelOption(string name, int intValue)
{
this.type = OptionType.Integer;
- this.name = Preconditions.CheckNotNull(name, "name");
+ this.name = GrpcPreconditions.CheckNotNull(name, "name");
this.intValue = intValue;
}
@@ -118,7 +118,7 @@
{
get
{
- Preconditions.CheckState(type == OptionType.Integer);
+ GrpcPreconditions.CheckState(type == OptionType.Integer);
return intValue;
}
}
@@ -130,7 +130,7 @@
{
get
{
- Preconditions.CheckState(type == OptionType.String);
+ GrpcPreconditions.CheckState(type == OptionType.String);
return stringValue;
}
}
diff --git a/src/csharp/Grpc.Core/ContextPropagationToken.cs b/src/csharp/Grpc.Core/ContextPropagationToken.cs
index 1d899b9..c0f638f 100644
--- a/src/csharp/Grpc.Core/ContextPropagationToken.cs
+++ b/src/csharp/Grpc.Core/ContextPropagationToken.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -68,7 +68,7 @@
internal ContextPropagationToken(CallSafeHandle parentCall, DateTime deadline, CancellationToken cancellationToken, ContextPropagationOptions options)
{
- this.parentCall = Preconditions.CheckNotNull(parentCall);
+ this.parentCall = GrpcPreconditions.CheckNotNull(parentCall);
this.deadline = deadline;
this.cancellationToken = cancellationToken;
this.options = options ?? ContextPropagationOptions.Default;
diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj
index 8d7d2ca..3189835 100644
--- a/src/csharp/Grpc.Core/Grpc.Core.csproj
+++ b/src/csharp/Grpc.Core/Grpc.Core.csproj
@@ -39,8 +39,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
- <Reference Include="System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="System.Interactive.Async">
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
</ItemGroup>
@@ -91,7 +90,6 @@
<Compile Include="Internal\AsyncCallBase.cs" />
<Compile Include="Internal\AsyncCallServer.cs" />
<Compile Include="Internal\AsyncCall.cs" />
- <Compile Include="Utils\Preconditions.cs" />
<Compile Include="Internal\ServerCredentialsSafeHandle.cs" />
<Compile Include="ServerCredentials.cs" />
<Compile Include="Metadata.cs" />
@@ -130,6 +128,7 @@
<Compile Include="Profiling\IProfiler.cs" />
<Compile Include="Profiling\Profilers.cs" />
<Compile Include="Internal\DefaultSslRootsOverride.cs" />
+ <Compile Include="Utils\GrpcPreconditions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Grpc.Core.nuspec" />
diff --git a/src/csharp/Grpc.Core/GrpcEnvironment.cs b/src/csharp/Grpc.Core/GrpcEnvironment.cs
index f3aa3d7..86b37b8 100644
--- a/src/csharp/Grpc.Core/GrpcEnvironment.cs
+++ b/src/csharp/Grpc.Core/GrpcEnvironment.cs
@@ -83,7 +83,7 @@
{
lock (staticLock)
{
- Preconditions.CheckState(refCount > 0);
+ GrpcPreconditions.CheckState(refCount > 0);
refCount--;
if (refCount == 0)
{
@@ -118,7 +118,7 @@
/// </summary>
public static void SetLogger(ILogger customLogger)
{
- Preconditions.CheckNotNull(customLogger, "customLogger");
+ GrpcPreconditions.CheckNotNull(customLogger, "customLogger");
logger = customLogger;
}
diff --git a/src/csharp/Grpc.Core/Internal/AsyncCall.cs b/src/csharp/Grpc.Core/Internal/AsyncCall.cs
index 7dc4490..2caba26 100644
--- a/src/csharp/Grpc.Core/Internal/AsyncCall.cs
+++ b/src/csharp/Grpc.Core/Internal/AsyncCall.cs
@@ -99,7 +99,7 @@
lock (myLock)
{
- Preconditions.CheckState(!started);
+ GrpcPreconditions.CheckState(!started);
started = true;
Initialize(cq);
@@ -141,7 +141,7 @@
{
lock (myLock)
{
- Preconditions.CheckState(!started);
+ GrpcPreconditions.CheckState(!started);
started = true;
Initialize(environment.CompletionQueue);
@@ -168,7 +168,7 @@
{
lock (myLock)
{
- Preconditions.CheckState(!started);
+ GrpcPreconditions.CheckState(!started);
started = true;
Initialize(environment.CompletionQueue);
@@ -192,7 +192,7 @@
{
lock (myLock)
{
- Preconditions.CheckState(!started);
+ GrpcPreconditions.CheckState(!started);
started = true;
Initialize(environment.CompletionQueue);
@@ -217,7 +217,7 @@
{
lock (myLock)
{
- Preconditions.CheckState(!started);
+ GrpcPreconditions.CheckState(!started);
started = true;
Initialize(environment.CompletionQueue);
@@ -257,7 +257,7 @@
{
lock (myLock)
{
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
CheckSendingAllowed();
call.StartSendCloseFromClient(HandleHalfclosed);
@@ -297,7 +297,7 @@
{
lock (myLock)
{
- Preconditions.CheckState(finishedStatus.HasValue, "Status can only be accessed once the call has finished.");
+ GrpcPreconditions.CheckState(finishedStatus.HasValue, "Status can only be accessed once the call has finished.");
return finishedStatus.Value.Status;
}
}
@@ -310,7 +310,7 @@
{
lock (myLock)
{
- Preconditions.CheckState(finishedStatus.HasValue, "Trailers can only be accessed once the call has finished.");
+ GrpcPreconditions.CheckState(finishedStatus.HasValue, "Trailers can only be accessed once the call has finished.");
return finishedStatus.Value.Trailers;
}
}
diff --git a/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs b/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
index 81a9a40..45d4c3e 100644
--- a/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
+++ b/src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
@@ -79,9 +79,9 @@
public AsyncCallBase(Func<TWrite, byte[]> serializer, Func<byte[], TRead> deserializer, GrpcEnvironment environment)
{
- this.serializer = Preconditions.CheckNotNull(serializer);
- this.deserializer = Preconditions.CheckNotNull(deserializer);
- this.environment = Preconditions.CheckNotNull(environment);
+ this.serializer = GrpcPreconditions.CheckNotNull(serializer);
+ this.deserializer = GrpcPreconditions.CheckNotNull(deserializer);
+ this.environment = GrpcPreconditions.CheckNotNull(environment);
}
/// <summary>
@@ -91,7 +91,7 @@
{
lock (myLock)
{
- Preconditions.CheckState(started);
+ GrpcPreconditions.CheckState(started);
cancelRequested = true;
if (!disposed)
@@ -135,7 +135,7 @@
lock (myLock)
{
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
CheckSendingAllowed();
call.StartSendMessage(HandleSendFinished, payload, writeFlags, !initialMetadataSent);
@@ -154,7 +154,7 @@
{
lock (myLock)
{
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
CheckReadingAllowed();
call.StartReceiveMessage(HandleReadFinished);
@@ -204,22 +204,22 @@
protected void CheckSendingAllowed()
{
- Preconditions.CheckState(started);
+ GrpcPreconditions.CheckState(started);
CheckNotCancelled();
- Preconditions.CheckState(!disposed);
+ GrpcPreconditions.CheckState(!disposed);
- Preconditions.CheckState(!halfcloseRequested, "Already halfclosed.");
- Preconditions.CheckState(!finished, "Already finished.");
- Preconditions.CheckState(sendCompletionDelegate == null, "Only one write can be pending at a time");
+ GrpcPreconditions.CheckState(!halfcloseRequested, "Already halfclosed.");
+ GrpcPreconditions.CheckState(!finished, "Already finished.");
+ GrpcPreconditions.CheckState(sendCompletionDelegate == null, "Only one write can be pending at a time");
}
protected virtual void CheckReadingAllowed()
{
- Preconditions.CheckState(started);
- Preconditions.CheckState(!disposed);
+ GrpcPreconditions.CheckState(started);
+ GrpcPreconditions.CheckState(!disposed);
- Preconditions.CheckState(!readingDone, "Stream has already been closed.");
- Preconditions.CheckState(readCompletionDelegate == null, "Only one read can be pending at a time");
+ GrpcPreconditions.CheckState(!readingDone, "Stream has already been closed.");
+ GrpcPreconditions.CheckState(readCompletionDelegate == null, "Only one read can be pending at a time");
}
protected void CheckNotCancelled()
diff --git a/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs b/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs
index 6752d3f..b72cbd7 100644
--- a/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs
+++ b/src/csharp/Grpc.Core/Internal/AsyncCallServer.cs
@@ -53,7 +53,7 @@
public AsyncCallServer(Func<TResponse, byte[]> serializer, Func<byte[], TRequest> deserializer, GrpcEnvironment environment, Server server) : base(serializer, deserializer, environment)
{
- this.server = Preconditions.CheckNotNull(server);
+ this.server = GrpcPreconditions.CheckNotNull(server);
}
public void Initialize(CallSafeHandle call)
@@ -71,7 +71,7 @@
{
lock (myLock)
{
- Preconditions.CheckNotNull(call);
+ GrpcPreconditions.CheckNotNull(call);
started = true;
@@ -108,14 +108,14 @@
{
lock (myLock)
{
- Preconditions.CheckNotNull(headers, "metadata");
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ GrpcPreconditions.CheckNotNull(headers, "metadata");
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
- Preconditions.CheckState(!initialMetadataSent, "Response headers can only be sent once per call.");
- Preconditions.CheckState(streamingWritesCounter == 0, "Response headers can only be sent before the first write starts.");
+ GrpcPreconditions.CheckState(!initialMetadataSent, "Response headers can only be sent once per call.");
+ GrpcPreconditions.CheckState(streamingWritesCounter == 0, "Response headers can only be sent before the first write starts.");
CheckSendingAllowed();
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
using (var metadataArray = MetadataArraySafeHandle.Create(headers))
{
@@ -136,7 +136,7 @@
{
lock (myLock)
{
- Preconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
+ GrpcPreconditions.CheckNotNull(completionDelegate, "Completion delegate cannot be null");
CheckSendingAllowed();
using (var metadataArray = MetadataArraySafeHandle.Create(trailers))
@@ -177,7 +177,7 @@
protected override void CheckReadingAllowed()
{
base.CheckReadingAllowed();
- Preconditions.CheckArgument(!cancelRequested);
+ GrpcPreconditions.CheckArgument(!cancelRequested);
}
protected override void OnAfterReleaseResources()
diff --git a/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs b/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs
index 9d7a990..5c75b52 100644
--- a/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs
@@ -101,7 +101,7 @@
{
bool success = false;
shutdownRefcount.IncrementIfNonzero(ref success);
- Preconditions.CheckState(success, "Shutdown has already been called");
+ GrpcPreconditions.CheckState(success, "Shutdown has already been called");
}
private void EndOp()
diff --git a/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs b/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs
index 2796c95..3a293e1 100644
--- a/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs
+++ b/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -59,7 +59,7 @@
public void Register(IntPtr key, OpCompletionDelegate callback)
{
environment.DebugStats.PendingBatchCompletions.Increment();
- Preconditions.CheckState(dict.TryAdd(key, callback));
+ GrpcPreconditions.CheckState(dict.TryAdd(key, callback));
}
public void RegisterBatchCompletion(BatchContextSafeHandle ctx, BatchCompletionDelegate callback)
@@ -71,7 +71,7 @@
public OpCompletionDelegate Extract(IntPtr key)
{
OpCompletionDelegate value;
- Preconditions.CheckState(dict.TryRemove(key, out value));
+ GrpcPreconditions.CheckState(dict.TryRemove(key, out value));
environment.DebugStats.PendingBatchCompletions.Decrement();
return value;
}
diff --git a/src/csharp/Grpc.Core/Internal/Enums.cs b/src/csharp/Grpc.Core/Internal/Enums.cs
index b0eab20..098e7c0 100644
--- a/src/csharp/Grpc.Core/Internal/Enums.cs
+++ b/src/csharp/Grpc.Core/Internal/Enums.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -72,7 +72,7 @@
/// </summary>
public static void CheckOk(this GRPCCallError callError)
{
- Preconditions.CheckState(callError == GRPCCallError.OK, "Call error: " + callError);
+ GrpcPreconditions.CheckState(callError == GRPCCallError.OK, "Call error: " + callError);
}
}
diff --git a/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs b/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs
index 36b865c..e810ffc 100644
--- a/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs
+++ b/src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs
@@ -53,7 +53,7 @@
public NativeMetadataCredentialsPlugin(AsyncAuthInterceptor interceptor)
{
- this.interceptor = Preconditions.CheckNotNull(interceptor, "interceptor");
+ this.interceptor = GrpcPreconditions.CheckNotNull(interceptor, "interceptor");
this.nativeInterceptor = NativeMetadataInterceptorHandler;
// Make sure the callback doesn't get garbage collected until it is destroyed.
diff --git a/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs b/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs
index de66759..ccf144d 100644
--- a/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs
+++ b/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -78,10 +78,10 @@
var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken);
try
{
- Preconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false));
+ GrpcPreconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false));
var request = requestStream.Current;
// TODO(jtattermusch): we need to read the full stream so that native callhandle gets deallocated.
- Preconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false));
+ GrpcPreconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false));
var result = await handler(request, context).ConfigureAwait(false);
status = context.Status;
await responseStream.WriteAsync(result).ConfigureAwait(false);
@@ -134,10 +134,10 @@
var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken);
try
{
- Preconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false));
+ GrpcPreconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false));
var request = requestStream.Current;
// TODO(jtattermusch): we need to read the full stream so that native callhandle gets deallocated.
- Preconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false));
+ GrpcPreconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false));
await handler(request, responseStream, context).ConfigureAwait(false);
status = context.Status;
}
diff --git a/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs
index a1d080c..a50f357 100644
--- a/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/ServerCredentialsSafeHandle.cs
@@ -49,7 +49,7 @@
public static ServerCredentialsSafeHandle CreateSslCredentials(string pemRootCerts, string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray, bool forceClientAuth)
{
- Preconditions.CheckArgument(keyCertPairCertChainArray.Length == keyCertPairPrivateKeyArray.Length);
+ GrpcPreconditions.CheckArgument(keyCertPairCertChainArray.Length == keyCertPairPrivateKeyArray.Length);
return Native.grpcsharp_ssl_server_credentials_create(pemRootCerts,
keyCertPairCertChainArray, keyCertPairPrivateKeyArray,
new UIntPtr((ulong)keyCertPairCertChainArray.Length),
diff --git a/src/csharp/Grpc.Core/Internal/Timespec.cs b/src/csharp/Grpc.Core/Internal/Timespec.cs
index 148d877..754be4e 100644
--- a/src/csharp/Grpc.Core/Internal/Timespec.cs
+++ b/src/csharp/Grpc.Core/Internal/Timespec.cs
@@ -141,8 +141,8 @@
/// </summary>
public DateTime ToDateTime()
{
- Preconditions.CheckState(tv_nsec >= 0 && tv_nsec < NanosPerSecond);
- Preconditions.CheckState(clock_type == GPRClockType.Realtime);
+ GrpcPreconditions.CheckState(tv_nsec >= 0 && tv_nsec < NanosPerSecond);
+ GrpcPreconditions.CheckState(clock_type == GPRClockType.Realtime);
// fast path for InfFuture
if (this.Equals(InfFuture))
@@ -195,7 +195,7 @@
return Timespec.InfPast;
}
- Preconditions.CheckArgument(dateTime.Kind == DateTimeKind.Utc, "dateTime needs of kind DateTimeKind.Utc or be equal to DateTime.MaxValue or DateTime.MinValue.");
+ GrpcPreconditions.CheckArgument(dateTime.Kind == DateTimeKind.Utc, "dateTime needs of kind DateTimeKind.Utc or be equal to DateTime.MaxValue or DateTime.MinValue.");
try
{
diff --git a/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs b/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
index 95a8797..e763c15 100644
--- a/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
+++ b/src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
@@ -65,7 +65,7 @@
public UnmanagedLibrary(string libraryPath)
{
- this.libraryPath = Preconditions.CheckNotNull(libraryPath);
+ this.libraryPath = GrpcPreconditions.CheckNotNull(libraryPath);
if (!File.Exists(this.libraryPath))
{
diff --git a/src/csharp/Grpc.Core/KeyCertificatePair.cs b/src/csharp/Grpc.Core/KeyCertificatePair.cs
index 6f69197..0fb6817 100644
--- a/src/csharp/Grpc.Core/KeyCertificatePair.cs
+++ b/src/csharp/Grpc.Core/KeyCertificatePair.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -54,8 +54,8 @@
/// <param name="privateKey">PEM encoded private key.</param>
public KeyCertificatePair(string certificateChain, string privateKey)
{
- this.certificateChain = Preconditions.CheckNotNull(certificateChain, "certificateChain");
- this.privateKey = Preconditions.CheckNotNull(privateKey, "privateKey");
+ this.certificateChain = GrpcPreconditions.CheckNotNull(certificateChain, "certificateChain");
+ this.privateKey = GrpcPreconditions.CheckNotNull(privateKey, "privateKey");
}
/// <summary>
diff --git a/src/csharp/Grpc.Core/Marshaller.cs b/src/csharp/Grpc.Core/Marshaller.cs
index 3493d2d..5847248 100644
--- a/src/csharp/Grpc.Core/Marshaller.cs
+++ b/src/csharp/Grpc.Core/Marshaller.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -51,8 +51,8 @@
/// <param name="deserializer">Function that will be used to deserialize messages.</param>
public Marshaller(Func<T, byte[]> serializer, Func<byte[], T> deserializer)
{
- this.serializer = Preconditions.CheckNotNull(serializer, "serializer");
- this.deserializer = Preconditions.CheckNotNull(deserializer, "deserializer");
+ this.serializer = GrpcPreconditions.CheckNotNull(serializer, "serializer");
+ this.deserializer = GrpcPreconditions.CheckNotNull(deserializer, "deserializer");
}
/// <summary>
diff --git a/src/csharp/Grpc.Core/Metadata.cs b/src/csharp/Grpc.Core/Metadata.cs
index 21bdf4f..aa22f84 100644
--- a/src/csharp/Grpc.Core/Metadata.cs
+++ b/src/csharp/Grpc.Core/Metadata.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -179,7 +179,7 @@
private void CheckWriteable()
{
- Preconditions.CheckState(!readOnly, "Object is read only");
+ GrpcPreconditions.CheckState(!readOnly, "Object is read only");
}
#endregion
@@ -211,10 +211,10 @@
public Entry(string key, byte[] valueBytes)
{
this.key = NormalizeKey(key);
- Preconditions.CheckArgument(this.key.EndsWith(BinaryHeaderSuffix),
+ GrpcPreconditions.CheckArgument(this.key.EndsWith(BinaryHeaderSuffix),
"Key for binary valued metadata entry needs to have suffix indicating binary value.");
this.value = null;
- Preconditions.CheckNotNull(valueBytes, "valueBytes");
+ GrpcPreconditions.CheckNotNull(valueBytes, "valueBytes");
this.valueBytes = new byte[valueBytes.Length];
Buffer.BlockCopy(valueBytes, 0, this.valueBytes, 0, valueBytes.Length); // defensive copy to guarantee immutability
}
@@ -227,9 +227,9 @@
public Entry(string key, string value)
{
this.key = NormalizeKey(key);
- Preconditions.CheckArgument(!this.key.EndsWith(BinaryHeaderSuffix),
+ GrpcPreconditions.CheckArgument(!this.key.EndsWith(BinaryHeaderSuffix),
"Key for ASCII valued metadata entry cannot have suffix indicating binary value.");
- this.value = Preconditions.CheckNotNull(value, "value");
+ this.value = GrpcPreconditions.CheckNotNull(value, "value");
this.valueBytes = null;
}
@@ -270,7 +270,7 @@
{
get
{
- Preconditions.CheckState(!IsBinary, "Cannot access string value of a binary metadata entry");
+ GrpcPreconditions.CheckState(!IsBinary, "Cannot access string value of a binary metadata entry");
return value ?? Encoding.GetString(valueBytes);
}
}
@@ -323,8 +323,8 @@
private static string NormalizeKey(string key)
{
- var normalized = Preconditions.CheckNotNull(key, "key").ToLower(CultureInfo.InvariantCulture);
- Preconditions.CheckArgument(ValidKeyRegex.IsMatch(normalized),
+ var normalized = GrpcPreconditions.CheckNotNull(key, "key").ToLower(CultureInfo.InvariantCulture);
+ GrpcPreconditions.CheckArgument(ValidKeyRegex.IsMatch(normalized),
"Metadata entry key not valid. Keys can only contain lowercase alphanumeric characters, underscores and hyphens.");
return normalized;
}
diff --git a/src/csharp/Grpc.Core/Method.cs b/src/csharp/Grpc.Core/Method.cs
index 99162a7..3870076 100644
--- a/src/csharp/Grpc.Core/Method.cs
+++ b/src/csharp/Grpc.Core/Method.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -106,10 +106,10 @@
public Method(MethodType type, string serviceName, string name, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller)
{
this.type = type;
- this.serviceName = Preconditions.CheckNotNull(serviceName, "serviceName");
- this.name = Preconditions.CheckNotNull(name, "name");
- this.requestMarshaller = Preconditions.CheckNotNull(requestMarshaller, "requestMarshaller");
- this.responseMarshaller = Preconditions.CheckNotNull(responseMarshaller, "responseMarshaller");
+ this.serviceName = GrpcPreconditions.CheckNotNull(serviceName, "serviceName");
+ this.name = GrpcPreconditions.CheckNotNull(name, "name");
+ this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarshaller, "requestMarshaller");
+ this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMarshaller, "responseMarshaller");
this.fullName = GetFullName(serviceName, name);
}
diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs
index d120f95..5d0fc6b 100644
--- a/src/csharp/Grpc.Core/Server.cs
+++ b/src/csharp/Grpc.Core/Server.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -125,7 +125,7 @@
{
lock (myLock)
{
- Preconditions.CheckState(!startRequested);
+ GrpcPreconditions.CheckState(!startRequested);
startRequested = true;
handle.Start();
@@ -142,8 +142,8 @@
{
lock (myLock)
{
- Preconditions.CheckState(startRequested);
- Preconditions.CheckState(!shutdownRequested);
+ GrpcPreconditions.CheckState(startRequested);
+ GrpcPreconditions.CheckState(!shutdownRequested);
shutdownRequested = true;
}
@@ -162,8 +162,8 @@
{
lock (myLock)
{
- Preconditions.CheckState(startRequested);
- Preconditions.CheckState(!shutdownRequested);
+ GrpcPreconditions.CheckState(startRequested);
+ GrpcPreconditions.CheckState(!shutdownRequested);
shutdownRequested = true;
}
@@ -181,7 +181,7 @@
bool success = false;
handle.DangerousAddRef(ref success);
- Preconditions.CheckState(success);
+ GrpcPreconditions.CheckState(success);
}
internal void RemoveCallReference(object call)
@@ -197,7 +197,7 @@
{
lock (myLock)
{
- Preconditions.CheckState(!startRequested);
+ GrpcPreconditions.CheckState(!startRequested);
foreach (var entry in serviceDefinition.CallHandlers)
{
callHandlers.Add(entry.Key, entry.Value);
@@ -213,8 +213,8 @@
{
lock (myLock)
{
- Preconditions.CheckNotNull(serverPort.Credentials, "serverPort");
- Preconditions.CheckState(!startRequested);
+ GrpcPreconditions.CheckNotNull(serverPort.Credentials, "serverPort");
+ GrpcPreconditions.CheckState(!startRequested);
var address = string.Format("{0}:{1}", serverPort.Host, serverPort.Port);
int boundPort;
using (var nativeCredentials = serverPort.Credentials.ToNativeCredentials())
diff --git a/src/csharp/Grpc.Core/ServerCredentials.cs b/src/csharp/Grpc.Core/ServerCredentials.cs
index 3c6703d..456d331 100644
--- a/src/csharp/Grpc.Core/ServerCredentials.cs
+++ b/src/csharp/Grpc.Core/ServerCredentials.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -90,11 +90,11 @@
public SslServerCredentials(IEnumerable<KeyCertificatePair> keyCertificatePairs, string rootCertificates, bool forceClientAuth)
{
this.keyCertificatePairs = new List<KeyCertificatePair>(keyCertificatePairs).AsReadOnly();
- Preconditions.CheckArgument(this.keyCertificatePairs.Count > 0,
+ GrpcPreconditions.CheckArgument(this.keyCertificatePairs.Count > 0,
"At least one KeyCertificatePair needs to be provided.");
if (forceClientAuth)
{
- Preconditions.CheckNotNull(rootCertificates,
+ GrpcPreconditions.CheckNotNull(rootCertificates,
"Cannot force client authentication unless you provide rootCertificates.");
}
this.rootCertificates = rootCertificates;
diff --git a/src/csharp/Grpc.Core/ServerPort.cs b/src/csharp/Grpc.Core/ServerPort.cs
index 598404d..10ddcb7 100644
--- a/src/csharp/Grpc.Core/ServerPort.cs
+++ b/src/csharp/Grpc.Core/ServerPort.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -62,9 +62,9 @@
/// <param name="credentials">credentials to use to secure this port.</param>
public ServerPort(string host, int port, ServerCredentials credentials)
{
- this.host = Preconditions.CheckNotNull(host, "host");
+ this.host = GrpcPreconditions.CheckNotNull(host, "host");
this.port = port;
- this.credentials = Preconditions.CheckNotNull(credentials, "credentials");
+ this.credentials = GrpcPreconditions.CheckNotNull(credentials, "credentials");
}
/// <summary>
diff --git a/src/csharp/Grpc.Core/Utils/Preconditions.cs b/src/csharp/Grpc.Core/Utils/GrpcPreconditions.cs
similarity index 98%
rename from src/csharp/Grpc.Core/Utils/Preconditions.cs
rename to src/csharp/Grpc.Core/Utils/GrpcPreconditions.cs
index a8ab603..76bf04c 100644
--- a/src/csharp/Grpc.Core/Utils/Preconditions.cs
+++ b/src/csharp/Grpc.Core/Utils/GrpcPreconditions.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,7 @@
/// <summary>
/// Utility methods to simplify checking preconditions in the code.
/// </summary>
- public static class Preconditions
+ public static class GrpcPreconditions
{
/// <summary>
/// Throws <see cref="ArgumentException"/> if condition is false.
diff --git a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
index 26c6445..e2ad1a8 100644
--- a/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
+++ b/src/csharp/Grpc.HealthCheck/HealthServiceImpl.cs
@@ -1,5 +1,5 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -127,8 +127,8 @@
{
public Key(string host, string service)
{
- this.Host = Preconditions.CheckNotNull(host);
- this.Service = Preconditions.CheckNotNull(service);
+ this.Host = GrpcPreconditions.CheckNotNull(host);
+ this.Service = GrpcPreconditions.CheckNotNull(service);
}
readonly string Host;
diff --git a/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs b/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
index e9e659c..c401601 100644
--- a/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
+++ b/src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -58,7 +58,7 @@
public static IClientRunner CreateStarted(ClientConfig config)
{
string target = config.ServerTargets.Single();
- Grpc.Core.Utils.Preconditions.CheckArgument(config.LoadParams.LoadCase == LoadParams.LoadOneofCase.ClosedLoop);
+ GrpcPreconditions.CheckArgument(config.LoadParams.LoadCase == LoadParams.LoadOneofCase.ClosedLoop);
var credentials = config.SecurityParams != null ? TestCredentials.CreateSslCredentials() : ChannelCredentials.Insecure;
var channel = new Channel(target, credentials);
@@ -95,7 +95,7 @@
public SyncUnaryClientRunner(Channel channel, int payloadSize, HistogramParams histogramParams)
{
- this.channel = Grpc.Core.Utils.Preconditions.CheckNotNull(channel);
+ this.channel = GrpcPreconditions.CheckNotNull(channel);
this.payloadSize = payloadSize;
this.histogram = new Histogram(histogramParams.Resolution, histogramParams.MaxPossible);
diff --git a/src/csharp/Grpc.IntegrationTesting/Histogram.cs b/src/csharp/Grpc.IntegrationTesting/Histogram.cs
index 7e7cb2c..08a674d 100644
--- a/src/csharp/Grpc.IntegrationTesting/Histogram.cs
+++ b/src/csharp/Grpc.IntegrationTesting/Histogram.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -66,8 +66,8 @@
public Histogram(double resolution, double maxPossible)
{
- Grpc.Core.Utils.Preconditions.CheckArgument(resolution > 0);
- Grpc.Core.Utils.Preconditions.CheckArgument(maxPossible > 0);
+ GrpcPreconditions.CheckArgument(resolution > 0);
+ GrpcPreconditions.CheckArgument(maxPossible > 0);
this.maxPossible = maxPossible;
this.multiplier = 1.0 + resolution;
this.oneOnLogMultiplier = 1.0 / Math.Log(1.0 + resolution);
diff --git a/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs b/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs
index e8be775..9b09b9b 100644
--- a/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs
+++ b/src/csharp/Grpc.IntegrationTesting/ServerRunners.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -57,7 +57,7 @@
/// </summary>
public static IServerRunner CreateStarted(ServerConfig config)
{
- Grpc.Core.Utils.Preconditions.CheckArgument(config.ServerType == ServerType.ASYNC_SERVER);
+ GrpcPreconditions.CheckArgument(config.ServerType == ServerType.ASYNC_SERVER);
var credentials = config.SecurityParams != null ? TestCredentials.CreateSslServerCredentials() : ServerCredentials.Insecure;
// TODO: qps_driver needs to setup payload properly...
@@ -83,7 +83,7 @@
public ServerRunnerImpl(Server server)
{
- this.server = Grpc.Core.Utils.Preconditions.CheckNotNull(server);
+ this.server = GrpcPreconditions.CheckNotNull(server);
}
public int BoundPort
diff --git a/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs b/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs
index bb2918b..59ecebf 100644
--- a/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs
+++ b/src/csharp/Grpc.IntegrationTesting/WorkerServiceImpl.cs
@@ -1,6 +1,6 @@
#region Copyright notice and license
-// Copyright 2015, Google Inc.
+// Copyright 2015-2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -49,7 +49,7 @@
{
public async Task RunServer(IAsyncStreamReader<ServerArgs> requestStream, IServerStreamWriter<ServerStatus> responseStream, ServerCallContext context)
{
- Grpc.Core.Utils.Preconditions.CheckState(await requestStream.MoveNext());
+ GrpcPreconditions.CheckState(await requestStream.MoveNext());
var serverConfig = requestStream.Current.Setup;
var runner = ServerRunners.CreateStarted(serverConfig);
@@ -73,7 +73,7 @@
public async Task RunClient(IAsyncStreamReader<ClientArgs> requestStream, IServerStreamWriter<ClientStatus> responseStream, ServerCallContext context)
{
- Grpc.Core.Utils.Preconditions.CheckState(await requestStream.MoveNext());
+ GrpcPreconditions.CheckState(await requestStream.MoveNext());
var clientConfig = requestStream.Current.Setup;
var runner = ClientRunners.CreateStarted(clientConfig);
diff --git a/src/node/ext/call_credentials.cc b/src/node/ext/call_credentials.cc
index 91acb86..98696db 100644
--- a/src/node/ext/call_credentials.cc
+++ b/src/node/ext/call_credentials.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -187,7 +187,8 @@
shared_ptr<Resources> resources(new Resources);
grpc_status_code code = static_cast<grpc_status_code>(
Nan::To<uint32_t>(info[0]).FromJust());
- char *details = *Utf8String(info[1]);
+ Utf8String details_utf8_str(info[1]);
+ char *details = *details_utf8_str;
grpc_metadata_array array;
if (!CreateMetadataArray(Nan::To<Object>(info[2]).ToLocalChecked(),
&array, resources)){
diff --git a/src/node/ext/node_grpc.cc b/src/node/ext/node_grpc.cc
index 654c5ae..0c71b2d 100644
--- a/src/node/ext/node_grpc.cc
+++ b/src/node/ext/node_grpc.cc
@@ -237,7 +237,8 @@
"headerKeyIsLegal's argument must be a string");
}
Local<String> key = Nan::To<String>(info[0]).ToLocalChecked();
- char *key_str = *Nan::Utf8String(key);
+ Nan::Utf8String key_utf8_str(key);
+ char *key_str = *key_utf8_str;
info.GetReturnValue().Set(static_cast<bool>(
grpc_header_key_is_legal(key_str, static_cast<size_t>(key->Length()))));
}
@@ -248,7 +249,8 @@
"metadataNonbinValueIsLegal's argument must be a string");
}
Local<String> value = Nan::To<String>(info[0]).ToLocalChecked();
- char *value_str = *Nan::Utf8String(value);
+ Nan::Utf8String value_utf8_str(value);
+ char *value_str = *value_utf8_str;
info.GetReturnValue().Set(static_cast<bool>(
grpc_header_nonbin_value_is_legal(
value_str, static_cast<size_t>(value->Length()))));
@@ -260,7 +262,8 @@
"metadataKeyIsLegal's argument must be a string");
}
Local<String> key = Nan::To<String>(info[0]).ToLocalChecked();
- char *key_str = *Nan::Utf8String(key);
+ Nan::Utf8String key_utf8_str(key);
+ char *key_str = *key_utf8_str;
info.GetReturnValue().Set(static_cast<bool>(
grpc_is_binary_header(key_str, static_cast<size_t>(key->Length()))));
}
diff --git a/src/node/index.js b/src/node/index.js
index 7eacdc6..1c19772 100644
--- a/src/node/index.js
+++ b/src/node/index.js
@@ -56,17 +56,18 @@
/**
* Load a gRPC object from an existing ProtoBuf.Reflect object.
* @param {ProtoBuf.Reflect.Namespace} value The ProtoBuf object to load.
+ * @param {Object=} options Options to apply to the loaded object
* @return {Object<string, *>} The resulting gRPC object
*/
-exports.loadObject = function loadObject(value) {
+exports.loadObject = function loadObject(value, options) {
var result = {};
if (value.className === 'Namespace') {
_.each(value.children, function(child) {
- result[child.name] = loadObject(child);
+ result[child.name] = loadObject(child, options);
});
return result;
} else if (value.className === 'Service') {
- return client.makeProtobufClientConstructor(value);
+ return client.makeProtobufClientConstructor(value, options);
} else if (value.className === 'Message' || value.className === 'Enum') {
return value.build();
} else {
@@ -77,28 +78,45 @@
var loadObject = exports.loadObject;
/**
- * Load a gRPC object from a .proto file.
- * @param {string} filename The file to load
+ * Load a gRPC object from a .proto file. The options object can provide the
+ * following options:
+ * - convertFieldsToCamelCase: Loads this file with that option on protobuf.js
+ * set as specified. See
+ * https://github.com/dcodeIO/protobuf.js/wiki/Advanced-options for details
+ * - binaryAsBase64: deserialize bytes values as base64 strings instead of
+ * Buffers. Defaults to false
+ * - longsAsStrings: deserialize long values as strings instead of objects.
+ * Defaults to true
+ * @param {string|{root: string, file: string}} filename The file to load
* @param {string=} format The file format to expect. Must be either 'proto' or
* 'json'. Defaults to 'proto'
+ * @param {Object=} options Options to apply to the loaded file
* @return {Object<string, *>} The resulting gRPC object
*/
-exports.load = function load(filename, format) {
+exports.load = function load(filename, format, options) {
if (!format) {
format = 'proto';
}
- var builder;
- switch(format) {
- case 'proto':
- builder = ProtoBuf.loadProtoFile(filename);
- break;
- case 'json':
- builder = ProtoBuf.loadJsonFile(filename);
- break;
- default:
- throw new Error('Unrecognized format "' + format + '"');
+ var convertFieldsToCamelCaseOriginal = ProtoBuf.convertFieldsToCamelCase;
+ if(options && options.hasOwnProperty('convertFieldsToCamelCase')) {
+ ProtoBuf.convertFieldsToCamelCase = options.convertFieldsToCamelCase;
}
- return loadObject(builder.ns);
+ var builder;
+ try {
+ switch(format) {
+ case 'proto':
+ builder = ProtoBuf.loadProtoFile(filename);
+ break;
+ case 'json':
+ builder = ProtoBuf.loadJsonFile(filename);
+ break;
+ default:
+ throw new Error('Unrecognized format "' + format + '"');
+ }
+ } finally {
+ ProtoBuf.convertFieldsToCamelCase = convertFieldsToCamelCaseOriginal;
+ }
+ return loadObject(builder.ns, options);
};
/**
diff --git a/src/node/src/client.js b/src/node/src/client.js
index b5247a6..c02c447 100644
--- a/src/node/src/client.js
+++ b/src/node/src/client.js
@@ -698,13 +698,16 @@
* Creates a constructor for clients for the given service
* @param {ProtoBuf.Reflect.Service} service The service to generate a client
* for
+ * @param {Object=} options Options to apply to the client
* @return {function(string, Object)} New client constructor
*/
-exports.makeProtobufClientConstructor = function(service) {
- var method_attrs = common.getProtobufServiceAttrs(service, service.name);
+exports.makeProtobufClientConstructor = function(service, options) {
+ var method_attrs = common.getProtobufServiceAttrs(service, service.name,
+ options);
var Client = exports.makeClientConstructor(
method_attrs, common.fullyQualifiedName(service));
Client.service = service;
+ Client.service.grpc_options = options;
return Client;
};
diff --git a/src/node/src/common.js b/src/node/src/common.js
index 2e6c01c..e521760 100644
--- a/src/node/src/common.js
+++ b/src/node/src/common.js
@@ -44,9 +44,20 @@
/**
* Get a function that deserializes a specific type of protobuf.
* @param {function()} cls The constructor of the message type to deserialize
+ * @param {bool=} binaryAsBase64 Deserialize bytes fields as base64 strings
+ * instead of Buffers. Defaults to false
+ * @param {bool=} longsAsStrings Deserialize long values as strings instead of
+ * objects. Defaults to true
* @return {function(Buffer):cls} The deserialization function
*/
-exports.deserializeCls = function deserializeCls(cls) {
+exports.deserializeCls = function deserializeCls(cls, binaryAsBase64,
+ longsAsStrings) {
+ if (binaryAsBase64 === undefined || binaryAsBase64 === null) {
+ binaryAsBase64 = false;
+ }
+ if (longsAsStrings === undefined || longsAsStrings === null) {
+ longsAsStrings = true;
+ }
/**
* Deserialize a buffer to a message object
* @param {Buffer} arg_buf The buffer to deserialize
@@ -55,7 +66,7 @@
return function deserialize(arg_buf) {
// Convert to a native object with binary fields as Buffers (first argument)
// and longs as strings (second argument)
- return cls.decode(arg_buf).toRaw(false, true);
+ return cls.decode(arg_buf).toRaw(binaryAsBase64, longsAsStrings);
};
};
@@ -119,19 +130,28 @@
/**
* Return a map from method names to method attributes for the service.
* @param {ProtoBuf.Reflect.Service} service The service to get attributes for
+ * @param {Object=} options Options to apply to these attributes
* @return {Object} The attributes map
*/
-exports.getProtobufServiceAttrs = function getProtobufServiceAttrs(service) {
+exports.getProtobufServiceAttrs = function getProtobufServiceAttrs(service,
+ options) {
var prefix = '/' + fullyQualifiedName(service) + '/';
+ var binaryAsBase64, longsAsStrings;
+ if (options) {
+ binaryAsBase64 = options.binaryAsBase64;
+ longsAsStrings = options.longsAsStrings;
+ }
return _.object(_.map(service.children, function(method) {
return [_.camelCase(method.name), {
path: prefix + method.name,
requestStream: method.requestStream,
responseStream: method.responseStream,
requestSerialize: serializeCls(method.resolvedRequestType.build()),
- requestDeserialize: deserializeCls(method.resolvedRequestType.build()),
+ requestDeserialize: deserializeCls(method.resolvedRequestType.build(),
+ binaryAsBase64, longsAsStrings),
responseSerialize: serializeCls(method.resolvedResponseType.build()),
- responseDeserialize: deserializeCls(method.resolvedResponseType.build())
+ responseDeserialize: deserializeCls(method.resolvedResponseType.build(),
+ binaryAsBase64, longsAsStrings)
}];
}));
};
diff --git a/src/node/src/credentials.js b/src/node/src/credentials.js
index 710ab6d..1d73723 100644
--- a/src/node/src/credentials.js
+++ b/src/node/src/credentials.js
@@ -98,6 +98,8 @@
message = error.message;
if (error.hasOwnProperty('code')) {
code = error.code;
+ } else {
+ code = grpc.status.UNAUTHENTICATED;
}
if (!metadata) {
metadata = new Metadata();
@@ -116,13 +118,16 @@
exports.createFromGoogleCredential = function(google_credential) {
return exports.createFromMetadataGenerator(function(auth_context, callback) {
var service_url = auth_context.service_url;
+ console.log('Service URL:', service_url);
google_credential.getRequestMetadata(service_url, function(err, header) {
if (err) {
+ console.log('Auth error:', err);
callback(err);
return;
}
var metadata = new Metadata();
metadata.add('authorization', header.Authorization);
+ console.log(header.Authorization);
callback(null, metadata);
});
});
diff --git a/src/node/src/metadata.js b/src/node/src/metadata.js
index 51a9f8a..33d7ea1 100644
--- a/src/node/src/metadata.js
+++ b/src/node/src/metadata.js
@@ -64,7 +64,7 @@
if (grpc.metadataKeyIsLegal(key)) {
return key;
} else {
- throw new Error('Metadata key contains illegal characters');
+ throw new Error('Metadata key"' + key + '" contains illegal characters');
}
}
@@ -79,7 +79,8 @@
'keys that don\'t end with \'-bin\' must have String values');
}
if (!grpc.metadataNonbinValueIsLegal(value)) {
- throw new Error('Metadata string value contains illegal characters');
+ throw new Error('Metadata string value "' + value +
+ '" contains illegal characters');
}
}
}
diff --git a/src/node/src/server.js b/src/node/src/server.js
index e5aadcd..0cf7ba3 100644
--- a/src/node/src/server.js
+++ b/src/node/src/server.js
@@ -737,7 +737,12 @@
* method implementation for the provided service.
*/
Server.prototype.addProtoService = function(service, implementation) {
- this.addService(common.getProtobufServiceAttrs(service), implementation);
+ var options;
+ if (service.grpc_options) {
+ options = service.grpc_options;
+ }
+ this.addService(common.getProtobufServiceAttrs(service, options),
+ implementation);
};
/**
diff --git a/src/node/test/common_test.js b/src/node/test/common_test.js
index 08ba429..66a4205 100644
--- a/src/node/test/common_test.js
+++ b/src/node/test/common_test.js
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -42,7 +42,7 @@
var messages_proto = ProtoBuf.loadProtoFile(
__dirname + '/test_messages.proto').build();
-describe('Proto message serialize and deserialize', function() {
+describe('Proto message long int serialize and deserialize', function() {
var longSerialize = common.serializeCls(messages_proto.LongValues);
var longDeserialize = common.deserializeCls(messages_proto.LongValues);
var pos_value = '314159265358979';
@@ -87,4 +87,52 @@
assert.strictEqual(longDeserialize(serialized).sfixed_64.toString(),
neg_value);
});
+ it('should deserialize as a number with the right option set', function() {
+ var longNumDeserialize = common.deserializeCls(messages_proto.LongValues,
+ false, false);
+ var serialized = longSerialize({int_64: pos_value});
+ assert.strictEqual(typeof longDeserialize(serialized).int_64, 'string');
+ /* With the longsAsStrings option disabled, long values are represented as
+ * objects with 3 keys: low, high, and unsigned */
+ assert.strictEqual(typeof longNumDeserialize(serialized).int_64, 'object');
+ });
+});
+describe('Proto message bytes serialize and deserialize', function() {
+ var sequenceSerialize = common.serializeCls(messages_proto.SequenceValues);
+ var sequenceDeserialize = common.deserializeCls(
+ messages_proto.SequenceValues);
+ var sequenceBase64Deserialize = common.deserializeCls(
+ messages_proto.SequenceValues, true);
+ var buffer_val = new Buffer([0x69, 0xb7]);
+ var base64_val = 'abc=';
+ it('should preserve a buffer', function() {
+ var serialized = sequenceSerialize({bytes_field: buffer_val});
+ var deserialized = sequenceDeserialize(serialized);
+ assert.strictEqual(deserialized.bytes_field.compare(buffer_val), 0);
+ });
+ it('should accept base64 encoded strings', function() {
+ var serialized = sequenceSerialize({bytes_field: base64_val});
+ var deserialized = sequenceDeserialize(serialized);
+ assert.strictEqual(deserialized.bytes_field.compare(buffer_val), 0);
+ });
+ it('should output base64 encoded strings with an option set', function() {
+ var serialized = sequenceSerialize({bytes_field: base64_val});
+ var deserialized = sequenceBase64Deserialize(serialized);
+ assert.strictEqual(deserialized.bytes_field, base64_val);
+ });
+ /* The next two tests are specific tests to verify that issue
+ * https://github.com/grpc/grpc/issues/5174 has been fixed. They are skipped
+ * because they will not pass until a protobuf.js release has been published
+ * with a fix for https://github.com/dcodeIO/protobuf.js/issues/390 */
+ it.skip('should serialize a repeated field as packed by default', function() {
+ var expected_serialize = new Buffer([0x12, 0x01, 0x01, 0x0a]);
+ var serialized = sequenceSerialize({repeated_field: [10]});
+ assert.strictEqual(expected_serialize.compare(serialized), 0);
+ });
+ it.skip('should deserialize packed or unpacked repeated', function() {
+ var serialized = new Buffer([0x12, 0x01, 0x01, 0x0a]);
+ assert.doesNotThrow(function() {
+ sequenceDeserialize(serialized);
+ });
+ });
});
diff --git a/src/node/test/test_messages.proto b/src/node/test/test_messages.proto
index c77a937..9b8cb87 100644
--- a/src/node/test/test_messages.proto
+++ b/src/node/test/test_messages.proto
@@ -36,3 +36,8 @@
fixed64 fixed_64 = 4;
sfixed64 sfixed_64 = 5;
}
+
+message SequenceValues {
+ bytes bytes_field = 1;
+ repeated int32 repeated_field = 2;
+}
diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py
index 976bfff..f43ac5c 100644
--- a/src/python/grpcio/grpc_core_dependencies.py
+++ b/src/python/grpcio/grpc_core_dependencies.py
@@ -100,6 +100,7 @@
'src/core/client_config/resolvers/sockaddr_resolver.c',
'src/core/client_config/subchannel.c',
'src/core/client_config/subchannel_factory.c',
+ 'src/core/client_config/subchannel_index.c',
'src/core/client_config/uri_parser.c',
'src/core/compression/algorithm.c',
'src/core/compression/message_compress.c',
diff --git a/summerofcode/ideas.md b/summerofcode/ideas.md
new file mode 100644
index 0000000..0732623
--- /dev/null
+++ b/summerofcode/ideas.md
@@ -0,0 +1,4 @@
+Google Summer of Code 2016 gRPC Ideas
+=====================================
+
+(Skeleton for now.)
diff --git a/test/core/end2end/fixtures/h2_uchannel.c b/test/core/end2end/fixtures/h2_uchannel.c
index 5ab64f9..dbdd352 100644
--- a/test/core/end2end/fixtures/h2_uchannel.c
+++ b/test/core/end2end/fixtures/h2_uchannel.c
@@ -159,7 +159,7 @@
c->base.vtable = &connector_vtable;
gpr_ref_init(&c->refs, 1);
args->args = final_args;
- s = grpc_subchannel_create(&c->base, args);
+ s = grpc_subchannel_create(exec_ctx, &c->base, args);
grpc_connector_unref(exec_ctx, &c->base);
grpc_channel_args_destroy(final_args);
if (*f->sniffed_subchannel) {
diff --git a/test/cpp/common/channel_arguments_test.cc b/test/cpp/common/channel_arguments_test.cc
index e010d37..a4821b4 100644
--- a/test/cpp/common/channel_arguments_test.cc
+++ b/test/cpp/common/channel_arguments_test.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,94 +41,141 @@
class ChannelArgumentsTest : public ::testing::Test {
protected:
+ ChannelArgumentsTest()
+ : pointer_vtable_({&ChannelArguments::PointerVtableMembers::Copy,
+ &ChannelArguments::PointerVtableMembers::Destroy,
+ &ChannelArguments::PointerVtableMembers::Compare}) {}
+
void SetChannelArgs(const ChannelArguments& channel_args,
grpc_channel_args* args) {
channel_args.SetChannelArgs(args);
}
+
+ grpc::string GetDefaultUserAgentPrefix() {
+ std::ostringstream user_agent_prefix;
+ user_agent_prefix << "grpc-c++/" << grpc_version_string();
+ return user_agent_prefix.str();
+ }
+
+ void VerifyDefaultChannelArgs() {
+ grpc_channel_args args;
+ SetChannelArgs(channel_args_, &args);
+ EXPECT_EQ(static_cast<size_t>(1), args.num_args);
+ EXPECT_STREQ(GRPC_ARG_PRIMARY_USER_AGENT_STRING, args.args[0].key);
+ EXPECT_EQ(GetDefaultUserAgentPrefix(),
+ grpc::string(args.args[0].value.string));
+ }
+
+ bool HasArg(grpc_arg expected_arg) {
+ grpc_channel_args args;
+ SetChannelArgs(channel_args_, &args);
+ for (size_t i = 0; i < args.num_args; i++) {
+ const grpc_arg& arg = args.args[i];
+ if (arg.type == expected_arg.type &&
+ grpc::string(arg.key) == expected_arg.key) {
+ if (arg.type == GRPC_ARG_INTEGER) {
+ return arg.value.integer == expected_arg.value.integer;
+ } else if (arg.type == GRPC_ARG_STRING) {
+ return grpc::string(arg.value.string) == expected_arg.value.string;
+ } else if (arg.type == GRPC_ARG_POINTER) {
+ return arg.value.pointer.p == expected_arg.value.pointer.p &&
+ arg.value.pointer.vtable->copy ==
+ expected_arg.value.pointer.vtable->copy &&
+ arg.value.pointer.vtable->destroy ==
+ expected_arg.value.pointer.vtable->destroy;
+ }
+ }
+ }
+ return false;
+ }
+ grpc_arg_pointer_vtable pointer_vtable_;
+ ChannelArguments channel_args_;
};
TEST_F(ChannelArgumentsTest, SetInt) {
- grpc_channel_args args;
- ChannelArguments channel_args;
- // Empty arguments.
- SetChannelArgs(channel_args, &args);
- EXPECT_EQ(static_cast<size_t>(0), args.num_args);
+ VerifyDefaultChannelArgs();
+ grpc::string key0("key0");
+ grpc_arg arg0;
+ arg0.type = GRPC_ARG_INTEGER;
+ arg0.key = const_cast<char*>(key0.c_str());
+ arg0.value.integer = 0;
+ grpc::string key1("key1");
+ grpc_arg arg1;
+ arg1.type = GRPC_ARG_INTEGER;
+ arg1.key = const_cast<char*>(key1.c_str());
+ arg1.value.integer = 1;
- grpc::string key("key0");
- channel_args.SetInt(key, 0);
+ grpc::string arg_key0(key0);
+ channel_args_.SetInt(arg_key0, arg0.value.integer);
// Clear key early to make sure channel_args takes a copy
- key = "";
- SetChannelArgs(channel_args, &args);
- EXPECT_EQ(static_cast<size_t>(1), args.num_args);
- EXPECT_EQ(GRPC_ARG_INTEGER, args.args[0].type);
- EXPECT_STREQ("key0", args.args[0].key);
- EXPECT_EQ(0, args.args[0].value.integer);
+ arg_key0.clear();
+ EXPECT_TRUE(HasArg(arg0));
- key = "key1";
- channel_args.SetInt(key, 1);
- key = "";
- SetChannelArgs(channel_args, &args);
- EXPECT_EQ(static_cast<size_t>(2), args.num_args);
- // We do not enforce order on the arguments.
- for (size_t i = 0; i < args.num_args; i++) {
- EXPECT_EQ(GRPC_ARG_INTEGER, args.args[i].type);
- if (grpc::string(args.args[i].key) == "key0") {
- EXPECT_EQ(0, args.args[i].value.integer);
- } else if (grpc::string(args.args[i].key) == "key1") {
- EXPECT_EQ(1, args.args[i].value.integer);
- }
- }
+ grpc::string arg_key1(key1);
+ channel_args_.SetInt(arg_key1, arg1.value.integer);
+ arg_key1.clear();
+ EXPECT_TRUE(HasArg(arg0));
+ EXPECT_TRUE(HasArg(arg1));
}
TEST_F(ChannelArgumentsTest, SetString) {
- grpc_channel_args args;
- ChannelArguments channel_args;
- // Empty arguments.
- SetChannelArgs(channel_args, &args);
- EXPECT_EQ(static_cast<size_t>(0), args.num_args);
+ VerifyDefaultChannelArgs();
+ grpc::string key0("key0");
+ grpc::string val0("val0");
+ grpc_arg arg0;
+ arg0.type = GRPC_ARG_STRING;
+ arg0.key = const_cast<char*>(key0.c_str());
+ arg0.value.string = const_cast<char*>(val0.c_str());
+ grpc::string key1("key1");
+ grpc::string val1("val1");
+ grpc_arg arg1;
+ arg1.type = GRPC_ARG_STRING;
+ arg1.key = const_cast<char*>(key1.c_str());
+ arg1.value.string = const_cast<char*>(val1.c_str());
- grpc::string key("key0");
- grpc::string val("val0");
- channel_args.SetString(key, val);
+ grpc::string key(key0);
+ grpc::string val(val0);
+ channel_args_.SetString(key, val);
// Clear key/val early to make sure channel_args takes a copy
key = "";
val = "";
- SetChannelArgs(channel_args, &args);
- EXPECT_EQ(static_cast<size_t>(1), args.num_args);
- EXPECT_EQ(GRPC_ARG_STRING, args.args[0].type);
- EXPECT_STREQ("key0", args.args[0].key);
- EXPECT_STREQ("val0", args.args[0].value.string);
+ EXPECT_TRUE(HasArg(arg0));
- key = "key1";
- val = "val1";
- channel_args.SetString(key, val);
- SetChannelArgs(channel_args, &args);
- EXPECT_EQ(static_cast<size_t>(2), args.num_args);
- // We do not enforce order on the arguments.
- for (size_t i = 0; i < args.num_args; i++) {
- EXPECT_EQ(GRPC_ARG_STRING, args.args[i].type);
- if (grpc::string(args.args[i].key) == "key0") {
- EXPECT_STREQ("val0", args.args[i].value.string);
- } else if (grpc::string(args.args[i].key) == "key1") {
- EXPECT_STREQ("val1", args.args[i].value.string);
- }
- }
+ key = key1;
+ val = val1;
+ channel_args_.SetString(key, val);
+ // Clear key/val early to make sure channel_args takes a copy
+ key = "";
+ val = "";
+ EXPECT_TRUE(HasArg(arg0));
+ EXPECT_TRUE(HasArg(arg1));
}
TEST_F(ChannelArgumentsTest, SetPointer) {
- grpc_channel_args args;
- ChannelArguments channel_args;
- // Empty arguments.
- SetChannelArgs(channel_args, &args);
- EXPECT_EQ(static_cast<size_t>(0), args.num_args);
+ VerifyDefaultChannelArgs();
+ grpc::string key0("key0");
+ grpc_arg arg0;
+ arg0.type = GRPC_ARG_POINTER;
+ arg0.key = const_cast<char*>(key0.c_str());
+ arg0.value.pointer.p = &key0;
+ arg0.value.pointer.vtable = &pointer_vtable_;
- grpc::string key("key0");
- channel_args.SetPointer(key, &key);
- SetChannelArgs(channel_args, &args);
- EXPECT_EQ(static_cast<size_t>(1), args.num_args);
- EXPECT_EQ(GRPC_ARG_POINTER, args.args[0].type);
- EXPECT_STREQ("key0", args.args[0].key);
- EXPECT_EQ(&key, args.args[0].value.pointer.p);
+ grpc::string key(key0);
+ channel_args_.SetPointer(key, arg0.value.pointer.p);
+ EXPECT_TRUE(HasArg(arg0));
+}
+
+TEST_F(ChannelArgumentsTest, SetUserAgentPrefix) {
+ VerifyDefaultChannelArgs();
+ grpc::string prefix("prefix");
+ grpc::string whole_prefix = prefix + " " + GetDefaultUserAgentPrefix();
+ grpc_arg arg0;
+ arg0.type = GRPC_ARG_STRING;
+ arg0.key = const_cast<char*>(GRPC_ARG_PRIMARY_USER_AGENT_STRING);
+ arg0.value.string = const_cast<char*>(whole_prefix.c_str());
+
+ channel_args_.SetUserAgentPrefix(prefix);
+ EXPECT_TRUE(HasArg(arg0));
}
} // namespace testing
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index a194c61..a15cbd7 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -43,6 +43,7 @@
#include <grpc/grpc.h>
#include <grpc/support/thd.h>
#include <grpc/support/time.h>
+#include <grpc/support/tls.h>
#include <gtest/gtest.h>
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
@@ -59,6 +60,8 @@
using grpc::testing::EchoResponse;
using std::chrono::system_clock;
+GPR_TLS_DECL(g_is_async_end2end_test);
+
namespace grpc {
namespace testing {
@@ -67,9 +70,11 @@
void* tag(int i) { return (void*)(intptr_t)i; }
#ifdef GPR_POSIX_SOCKET
-static int assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds,
- int timeout) {
- GPR_ASSERT(timeout == 0);
+static int maybe_assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds,
+ int timeout) {
+ if (gpr_tls_get(&g_is_async_end2end_test)) {
+ GPR_ASSERT(timeout == 0);
+ }
return poll(pfds, nfds, timeout);
}
@@ -86,21 +91,21 @@
grpc_poll_function_type prev_;
};
-class PollingCheckRegion : public PollOverride {
+class PollingOverrider : public PollOverride {
public:
- explicit PollingCheckRegion(bool allow_blocking)
- : PollOverride(allow_blocking ? poll : assert_non_blocking_poll) {}
+ explicit PollingOverrider(bool allow_blocking)
+ : PollOverride(allow_blocking ? poll : maybe_assert_non_blocking_poll) {}
};
#else
-class PollingCheckRegion {
+class PollingOverrider {
public:
- explicit PollingCheckRegion(bool allow_blocking) {}
+ explicit PollingOverrider(bool allow_blocking) {}
};
#endif
-class Verifier : public PollingCheckRegion {
+class Verifier {
public:
- explicit Verifier(bool spin) : PollingCheckRegion(!spin), spin_(spin) {}
+ explicit Verifier(bool spin) : spin_(spin) {}
Verifier& Expect(int i, bool expect_ok) {
expectations_[tag(i)] = expect_ok;
return *this;
@@ -183,6 +188,8 @@
AsyncEnd2endTest() {}
void SetUp() GRPC_OVERRIDE {
+ poll_overrider_.reset(new PollingOverrider(!GetParam()));
+
int port = grpc_pick_unused_port_or_die();
server_address_ << "localhost:" << port;
@@ -193,6 +200,8 @@
builder.RegisterService(&service_);
cq_ = builder.AddCompletionQueue();
server_ = builder.BuildAndStart();
+
+ gpr_tls_set(&g_is_async_end2end_test, 1);
}
void TearDown() GRPC_OVERRIDE {
@@ -202,6 +211,8 @@
cq_->Shutdown();
while (cq_->Next(&ignored_tag, &ignored_ok))
;
+ poll_overrider_.reset();
+ gpr_tls_set(&g_is_async_end2end_test, 0);
}
void ResetStub() {
@@ -249,6 +260,8 @@
std::unique_ptr<Server> server_;
grpc::testing::EchoTestService::AsyncService service_;
std::ostringstream server_address_;
+
+ std::unique_ptr<PollingOverrider> poll_overrider_;
};
TEST_P(AsyncEnd2endTest, SimpleRpc) {
@@ -1087,7 +1100,7 @@
Verifier(GetParam()).Expect(7, true).Verify(cq_.get());
// This is expected to fail in all cases i.e for all values of
- // server_try_cancel. This is becasue at this point, either there are no
+ // server_try_cancel. This is because at this point, either there are no
// more msgs from the client (because client called WritesDone) or the RPC
// is cancelled on the server
srv_stream.Read(&recv_request, tag(8));
@@ -1164,6 +1177,9 @@
int main(int argc, char** argv) {
grpc_test_init(argc, argv);
+ gpr_tls_init(&g_is_async_end2end_test);
::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+ int ret = RUN_ALL_TESTS();
+ gpr_tls_destroy(&g_is_async_end2end_test);
+ return ret;
}
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 65da71b..ce8e4d2 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -51,11 +51,11 @@
#include "src/core/security/credentials.h"
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
-#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
#include "test/cpp/end2end/test_service_impl.h"
#include "test/cpp/util/string_ref_helper.h"
+#include "test/cpp/util/test_credentials_provider.h"
using grpc::testing::EchoRequest;
using grpc::testing::EchoResponse;
@@ -191,12 +191,14 @@
class TestScenario {
public:
- TestScenario(bool proxy, bool tls) : use_proxy(proxy), use_tls(tls) {}
+ TestScenario(bool proxy, const grpc::string& creds_type)
+ : use_proxy(proxy), credentials_type(creds_type) {}
void Log() const {
- gpr_log(GPR_INFO, "Scenario: proxy %d, tls %d", use_proxy, use_tls);
+ gpr_log(GPR_INFO, "Scenario: proxy %d, credentials %s", use_proxy,
+ credentials_type.c_str());
}
bool use_proxy;
- bool use_tls;
+ const grpc::string credentials_type;
};
class End2endTest : public ::testing::TestWithParam<TestScenario> {
@@ -220,14 +222,8 @@
server_address_ << "127.0.0.1:" << port;
// Setup server
ServerBuilder builder;
- auto server_creds = InsecureServerCredentials();
- if (GetParam().use_tls) {
- SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key,
- test_server1_cert};
- SslServerCredentialsOptions ssl_opts;
- ssl_opts.pem_root_certs = "";
- ssl_opts.pem_key_cert_pairs.push_back(pkcp);
- server_creds = SslServerCredentials(ssl_opts);
+ auto server_creds = GetServerCredentials(GetParam().credentials_type);
+ if (GetParam().credentials_type != kInsecureCredentialsType) {
server_creds->SetAuthMetadataProcessor(processor);
}
builder.AddListeningPort(server_address_.str(), server_creds);
@@ -246,11 +242,10 @@
}
EXPECT_TRUE(is_server_started_);
ChannelArguments args;
- auto channel_creds = InsecureChannelCredentials();
- if (GetParam().use_tls) {
- SslCredentialsOptions ssl_opts = {test_root_cert, "", ""};
- args.SetSslTargetNameOverride("foo.test.google.fr");
- channel_creds = SslCredentials(ssl_opts);
+ auto channel_creds =
+ GetChannelCredentials(GetParam().credentials_type, &args);
+ if (!user_agent_prefix_.empty()) {
+ args.SetUserAgentPrefix(user_agent_prefix_);
}
args.SetString(GRPC_ARG_SECONDARY_USER_AGENT_STRING, "end2end_test");
channel_ = CreateCustomChannel(server_address_.str(), channel_creds, args);
@@ -285,6 +280,7 @@
TestServiceImpl service_;
TestServiceImpl special_service_;
TestServiceImplDupPkg dup_pkg_service_;
+ grpc::string user_agent_prefix_;
};
static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs,
@@ -601,6 +597,25 @@
TestBidiStreamServerCancel(CANCEL_AFTER_PROCESSING, 5);
}
+TEST_P(End2endTest, SimpleRpcWithCustomeUserAgentPrefix) {
+ user_agent_prefix_ = "custom_prefix";
+ ResetStub();
+ EchoRequest request;
+ EchoResponse response;
+ request.set_message("Hello hello hello hello");
+ request.mutable_param()->set_echo_metadata(true);
+
+ ClientContext context;
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_EQ(response.message(), request.message());
+ EXPECT_TRUE(s.ok());
+ const auto& trailing_metadata = context.GetServerTrailingMetadata();
+ auto iter = trailing_metadata.find("user-agent");
+ EXPECT_TRUE(iter != trailing_metadata.end());
+ grpc::string expected_prefix = user_agent_prefix_ + " grpc-c++/";
+ EXPECT_TRUE(iter->second.starts_with(expected_prefix));
+}
+
TEST_P(End2endTest, MultipleRpcsWithVariedBinaryMetadataValue) {
ResetStub();
std::vector<std::thread*> threads;
@@ -918,7 +933,7 @@
// Takes 10s.
TEST_P(End2endTest, ChannelStateTimeout) {
- if (GetParam().use_tls) {
+ if (GetParam().credentials_type != kInsecureCredentialsType) {
return;
}
int port = grpc_pick_unused_port_or_die();
@@ -1127,7 +1142,7 @@
protected:
SecureEnd2endTest() {
GPR_ASSERT(!GetParam().use_proxy);
- GPR_ASSERT(GetParam().use_tls);
+ GPR_ASSERT(GetParam().credentials_type != kInsecureCredentialsType);
}
};
@@ -1350,21 +1365,42 @@
EXPECT_EQ("*.test.youtube.com", ToString(auth_ctx->GetPeerIdentity()[2]));
}
+std::vector<TestScenario> CreateTestScenarios(bool use_proxy,
+ bool test_insecure,
+ bool test_secure) {
+ std::vector<TestScenario> scenarios;
+ std::vector<grpc::string> credentials_types;
+ if (test_secure) {
+ credentials_types = GetSecureCredentialsTypeList();
+ }
+ if (test_insecure) {
+ credentials_types.push_back(kInsecureCredentialsType);
+ }
+ for (auto it = credentials_types.begin(); it != credentials_types.end();
+ ++it) {
+ scenarios.push_back(TestScenario(false, *it));
+ if (use_proxy) {
+ scenarios.push_back(TestScenario(true, *it));
+ }
+ }
+ return scenarios;
+}
+
INSTANTIATE_TEST_CASE_P(End2end, End2endTest,
- ::testing::Values(TestScenario(false, false),
- TestScenario(false, true)));
+ ::testing::ValuesIn(CreateTestScenarios(false, true,
+ true)));
INSTANTIATE_TEST_CASE_P(End2endServerTryCancel, End2endServerTryCancelTest,
- ::testing::Values(TestScenario(false, false)));
+ ::testing::ValuesIn(CreateTestScenarios(false, true,
+ false)));
INSTANTIATE_TEST_CASE_P(ProxyEnd2end, ProxyEnd2endTest,
- ::testing::Values(TestScenario(false, false),
- TestScenario(false, true),
- TestScenario(true, false),
- TestScenario(true, true)));
+ ::testing::ValuesIn(CreateTestScenarios(true, true,
+ true)));
INSTANTIATE_TEST_CASE_P(SecureEnd2end, SecureEnd2endTest,
- ::testing::Values(TestScenario(false, true)));
+ ::testing::ValuesIn(CreateTestScenarios(false, false,
+ true)));
} // namespace
} // namespace testing
diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc
new file mode 100644
index 0000000..1086e14
--- /dev/null
+++ b/test/cpp/util/test_credentials_provider.cc
@@ -0,0 +1,82 @@
+
+/*
+ *
+ * Copyright 2016, 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 "test/cpp/util/test_credentials_provider.h"
+
+#include "test/core/end2end/data/ssl_test_data.h"
+
+namespace grpc {
+namespace testing {
+
+const char kTlsCredentialsType[] = "TLS_CREDENTIALS";
+
+std::shared_ptr<ChannelCredentials> GetChannelCredentials(
+ const grpc::string& type, ChannelArguments* args) {
+ if (type == kInsecureCredentialsType) {
+ return InsecureChannelCredentials();
+ } else if (type == kTlsCredentialsType) {
+ SslCredentialsOptions ssl_opts = {test_root_cert, "", ""};
+ args->SetSslTargetNameOverride("foo.test.google.fr");
+ return SslCredentials(ssl_opts);
+ } else {
+ gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
+ }
+ return nullptr;
+}
+
+std::shared_ptr<ServerCredentials> GetServerCredentials(
+ const grpc::string& type) {
+ if (type == kInsecureCredentialsType) {
+ return InsecureServerCredentials();
+ } else if (type == kTlsCredentialsType) {
+ SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key,
+ test_server1_cert};
+ SslServerCredentialsOptions ssl_opts;
+ ssl_opts.pem_root_certs = "";
+ ssl_opts.pem_key_cert_pairs.push_back(pkcp);
+ return SslServerCredentials(ssl_opts);
+ } else {
+ gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
+ }
+ return nullptr;
+}
+
+std::vector<grpc::string> GetSecureCredentialsTypeList() {
+ std::vector<grpc::string> types;
+ types.push_back(kTlsCredentialsType);
+ return types;
+}
+
+} // namespace testing
+} // namespace grpc
diff --git a/test/cpp/util/test_credentials_provider.h b/test/cpp/util/test_credentials_provider.h
new file mode 100644
index 0000000..f725305
--- /dev/null
+++ b/test/cpp/util/test_credentials_provider.h
@@ -0,0 +1,63 @@
+/*
+ *
+ * Copyright 2016, 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.
+ *
+ */
+
+#ifndef GRPC_TEST_CPP_UTIL_TEST_CREDENTIALS_PROVIDER_H
+#define GRPC_TEST_CPP_UTIL_TEST_CREDENTIALS_PROVIDER_H
+
+#include <memory>
+
+#include <grpc++/security/credentials.h>
+#include <grpc++/security/server_credentials.h>
+#include <grpc++/support/channel_arguments.h>
+
+namespace grpc {
+namespace testing {
+
+const char kInsecureCredentialsType[] = "INSECURE_CREDENTIALS";
+
+// Provide channel credentials according to the given type. Alter the channel
+// arguments if needed.
+std::shared_ptr<ChannelCredentials> GetChannelCredentials(
+ const grpc::string& type, ChannelArguments* args);
+
+// Provide server credentials according to the given type.
+std::shared_ptr<ServerCredentials> GetServerCredentials(
+ const grpc::string& type);
+
+// Provide a list of secure credentials type.
+std::vector<grpc::string> GetSecureCredentialsTypeList();
+
+} // namespace testing
+} // namespace grpc
+
+#endif // GRPC_TEST_CPP_UTIL_TEST_CREDENTIALS_PROVIDER_H
diff --git a/tools/distrib/check_copyright.py b/tools/distrib/check_copyright.py
index d1a34a9..99771f9 100755
--- a/tools/distrib/check_copyright.py
+++ b/tools/distrib/check_copyright.py
@@ -71,9 +71,9 @@
# that given a line of license text, returns what should
# be in the file
LICENSE_PREFIX = {
- '.c': r'\s*\*\s*',
- '.cc': r'\s*\*\s*',
- '.h': r'\s*\*\s*',
+ '.c': r'\s*(?://|\*)\s*',
+ '.cc': r'\s*(?://|\*)\s*',
+ '.h': r'\s*(?://|\*)\s*',
'.m': r'\s*\*\s*',
'.php': r'\s*\*\s*',
'.js': r'\s*\*\s*',
diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal
index e49c675..84250e7 100644
--- a/tools/doxygen/Doxyfile.core.internal
+++ b/tools/doxygen/Doxyfile.core.internal
@@ -799,6 +799,7 @@
src/core/client_config/resolvers/sockaddr_resolver.h \
src/core/client_config/subchannel.h \
src/core/client_config/subchannel_factory.h \
+src/core/client_config/subchannel_index.h \
src/core/client_config/uri_parser.h \
src/core/compression/algorithm_metadata.h \
src/core/compression/message_compress.h \
@@ -930,6 +931,7 @@
src/core/client_config/resolvers/sockaddr_resolver.c \
src/core/client_config/subchannel.c \
src/core/client_config/subchannel_factory.c \
+src/core/client_config/subchannel_index.c \
src/core/client_config/uri_parser.c \
src/core/compression/algorithm.c \
src/core/compression/message_compress.c \
diff --git a/tools/asan_suppressions.txt b/tools/lsan_suppressions.txt
similarity index 100%
rename from tools/asan_suppressions.txt
rename to tools/lsan_suppressions.txt
diff --git a/tools/run_tests/configs.json b/tools/run_tests/configs.json
index d508c63..9d7b8a3 100644
--- a/tools/run_tests/configs.json
+++ b/tools/run_tests/configs.json
@@ -45,8 +45,8 @@
{
"config": "asan",
"environ": {
- "ASAN_OPTIONS": "suppressions=tools/asan_suppressions.txt:detect_leaks=1:color=always",
- "LSAN_OPTIONS": "suppressions=tools/asan_suppressions.txt:report_objects=1"
+ "ASAN_OPTIONS": "detect_leaks=1:color=always",
+ "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1"
},
"timeout_multiplier": 1.5
},
diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py
index 76be932..df3ab90 100755
--- a/tools/run_tests/run_interop_tests.py
+++ b/tools/run_tests/run_interop_tests.py
@@ -422,7 +422,7 @@
time.sleep(2)
-def cloud_to_prod_jobspec(language, test_case, server_host_name,
+def cloud_to_prod_jobspec(language, test_case, server_host_name,
server_host_detail, docker_image=None, auth=False):
"""Creates jobspec for cloud-to-prod interop test"""
container_name = None
@@ -441,7 +441,7 @@
cwd = language.client_cwd
if docker_image:
- container_name = dockerjob.random_name('interop_client_%s' %
+ container_name = dockerjob.random_name('interop_client_%s' %
language.safename)
cmdline = docker_run_cmdline(cmdline,
image=docker_image,
@@ -457,7 +457,7 @@
cmdline=cmdline,
cwd=cwd,
environ=environ,
- shortname='%s:%s:%s:%s' % (suite_name, server_host_name, language,
+ shortname='%s:%s:%s:%s' % (suite_name, server_host_name, language,
test_case),
timeout_seconds=90,
flake_retries=5 if args.allow_flakes else 0,
@@ -575,18 +575,18 @@
'percent': 1.0 * passed / (passed + failed)
}
-# A dictionary of prod servers to test.
+# A dictionary of prod servers to test.
# Format: server_name: (server_host, server_host_override, errors_allowed)
# TODO(adelez): implement logic for errors_allowed where if the indicated tests
# fail, they don't impact the overall test result.
prod_servers = {
- 'default': ('grpc-test.sandbox.googleapis.com',
+ 'default': ('grpc-test.sandbox.googleapis.com',
'grpc-test.sandbox.googleapis.com', False),
- 'gateway_v2': ('grpc-test2.sandbox.googleapis.com',
+ 'gateway_v2': ('grpc-test2.sandbox.googleapis.com',
'grpc-test2.sandbox.googleapis.com', True),
- 'cloud_gateway': ('216.239.32.255', 'grpc-test.sandbox.googleapis.com',
+ 'cloud_gateway': ('216.239.32.255', 'grpc-test.sandbox.googleapis.com',
False),
- 'cloud_gateway_v2': ('216.239.32.255', 'grpc-test2.sandbox.googleapis.com',
+ 'cloud_gateway_v2': ('216.239.32.255', 'grpc-test2.sandbox.googleapis.com',
True)
}
@@ -720,7 +720,7 @@
if not test_case in language.unimplemented_test_cases():
if not test_case in _SKIP_ADVANCED + _SKIP_COMPRESSION:
test_job = cloud_to_prod_jobspec(
- language, test_case, server_host_name,
+ language, test_case, server_host_name,
prod_servers[server_host_name],
docker_image=docker_images.get(str(language)))
jobs.append(test_job)
@@ -728,7 +728,7 @@
if args.http2_interop:
for test_case in _HTTP2_TEST_CASES:
test_job = cloud_to_prod_jobspec(
- http2Interop, test_case, server_host_name,
+ http2Interop, test_case, server_host_name,
prod_servers[server_host_name],
docker_image=docker_images.get(str(http2Interop)))
jobs.append(test_job)
@@ -739,7 +739,7 @@
for test_case in _AUTH_TEST_CASES:
if not test_case in language.unimplemented_test_cases():
test_job = cloud_to_prod_jobspec(
- language, test_case, server_host_name,
+ language, test_case, server_host_name,
prod_servers[server_host_name],
docker_image=docker_images.get(str(language)), auth=True)
jobs.append(test_job)
@@ -802,7 +802,7 @@
report_utils.render_interop_html_report(
set([str(l) for l in languages]), servers, _TEST_CASES, _AUTH_TEST_CASES,
_HTTP2_TEST_CASES, resultset, num_failures,
- args.cloud_to_prod_auth or args.cloud_to_prod, args.prod_servers,
+ args.cloud_to_prod_auth or args.cloud_to_prod, args.prod_servers,
args.http2_interop)
finally:
diff --git a/tools/run_tests/run_node.bat b/tools/run_tests/run_node.bat
index f5cf01f..ad9ca14 100644
--- a/tools/run_tests/run_node.bat
+++ b/tools/run_tests/run_node.bat
@@ -29,4 +29,4 @@
set JUNIT_REPORT_PATH=src\node\reports.xml
set JUNIT_REPORT_STACK=1
-.\node_modules\.bin\mocha.cmd --reporter mocha-jenkins-reporter src\node\test
\ No newline at end of file
+.\node_modules\.bin\mocha.cmd --reporter mocha-jenkins-reporter --timeout 8000 src\node\test
\ No newline at end of file
diff --git a/tools/run_tests/run_node.sh b/tools/run_tests/run_node.sh
index 40f61d7..178584a 100755
--- a/tools/run_tests/run_node.sh
+++ b/tools/run_tests/run_node.sh
@@ -41,10 +41,13 @@
root=`pwd`
+test_directory='src/node/test'
+timeout=8000
+
if [ "$CONFIG" = "gcov" ]
then
./node_modules/.bin/istanbul cover --dir reports/node_coverage \
- -x **/interop/* ./node_modules/.bin/_mocha -- --timeout 8000 src/node/test
+ -x **/interop/* ./node_modules/.bin/_mocha -- --timeout $timeout $test_directory
cd build
gcov Release/obj.target/grpc/ext/*.o
lcov --base-directory . --directory . -c -o coverage.info
@@ -55,5 +58,7 @@
echo '<html><head><meta http-equiv="refresh" content="0;URL=lcov-report/index.html"></head></html>' > \
../reports/node_coverage/index.html
else
- JUNIT_REPORT_PATH=src/node/reports.xml JUNIT_REPORT_STACK=1 ./node_modules/.bin/mocha --reporter mocha-jenkins-reporter src/node/test
+ JUNIT_REPORT_PATH=src/node/reports.xml JUNIT_REPORT_STACK=1 \
+ ./node_modules/.bin/mocha --timeout $timeout \
+ --reporter mocha-jenkins-reporter $test_directory
fi
diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py
index de3716b..0b3efa2 100755
--- a/tools/run_tests/run_tests.py
+++ b/tools/run_tests/run_tests.py
@@ -334,13 +334,14 @@
def test_specs(self, config, args):
return [config.job_spec(['tools/run_tests/run_ruby.sh'], None,
+ timeout_seconds=10*60,
environ=_FORCE_ENVIRON_FOR_WRAPPERS)]
def pre_build_steps(self):
return [['tools/run_tests/pre_build_ruby.sh']]
def make_targets(self, test_regex):
- return ['static_c']
+ return []
def make_options(self):
return []
@@ -1197,4 +1198,3 @@
if BuildAndRunError.POST_TEST in errors:
exit_code |= 4
sys.exit(exit_code)
-
diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json
index c4a0774..3cdd7b4 100644
--- a/tools/run_tests/sources_and_headers.json
+++ b/tools/run_tests/sources_and_headers.json
@@ -3010,6 +3010,7 @@
"src/core/client_config/resolvers/sockaddr_resolver.h",
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.h",
+ "src/core/client_config/subchannel_index.h",
"src/core/client_config/uri_parser.h",
"src/core/compression/algorithm_metadata.h",
"src/core/compression/message_compress.h",
@@ -3190,6 +3191,8 @@
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.c",
"src/core/client_config/subchannel_factory.h",
+ "src/core/client_config/subchannel_index.c",
+ "src/core/client_config/subchannel_index.h",
"src/core/client_config/uri_parser.c",
"src/core/client_config/uri_parser.h",
"src/core/compression/algorithm.c",
@@ -3548,6 +3551,7 @@
"src/core/client_config/resolvers/sockaddr_resolver.h",
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.h",
+ "src/core/client_config/subchannel_index.h",
"src/core/client_config/uri_parser.h",
"src/core/compression/algorithm_metadata.h",
"src/core/compression/message_compress.h",
@@ -3713,6 +3717,8 @@
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.c",
"src/core/client_config/subchannel_factory.h",
+ "src/core/client_config/subchannel_index.c",
+ "src/core/client_config/subchannel_index.h",
"src/core/client_config/uri_parser.c",
"src/core/client_config/uri_parser.h",
"src/core/compression/algorithm.c",
@@ -4190,7 +4196,8 @@
"test/cpp/util/cli_call.h",
"test/cpp/util/create_test_channel.h",
"test/cpp/util/string_ref_helper.h",
- "test/cpp/util/subprocess.h"
+ "test/cpp/util/subprocess.h",
+ "test/cpp/util/test_credentials_provider.h"
],
"language": "c++",
"name": "grpc++_test_util",
@@ -4206,7 +4213,9 @@
"test/cpp/util/string_ref_helper.cc",
"test/cpp/util/string_ref_helper.h",
"test/cpp/util/subprocess.cc",
- "test/cpp/util/subprocess.h"
+ "test/cpp/util/subprocess.h",
+ "test/cpp/util/test_credentials_provider.cc",
+ "test/cpp/util/test_credentials_provider.h"
]
},
{
diff --git a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj
index 3d35371..33860af 100644
--- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj
+++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj
@@ -153,6 +153,7 @@
<ClInclude Include="$(SolutionDir)\..\test\cpp\util\create_test_channel.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\util\string_ref_helper.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\util\subprocess.h" />
+ <ClInclude Include="$(SolutionDir)\..\test\cpp\util\test_credentials_provider.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(SolutionDir)\..\src\proto\grpc\testing\echo_messages.pb.cc">
@@ -191,6 +192,8 @@
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\util\subprocess.cc">
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\test\cpp\util\test_credentials_provider.cc">
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\..\vsprojects\vcxproj\.\grpc++\grpc++.vcxproj">
diff --git a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters
index 27ac675..b35ba1f 100644
--- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters
+++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters
@@ -28,6 +28,9 @@
<ClCompile Include="$(SolutionDir)\..\test\cpp\util\subprocess.cc">
<Filter>test\cpp\util</Filter>
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\test\cpp\util\test_credentials_provider.cc">
+ <Filter>test\cpp\util</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(SolutionDir)\..\test\cpp\end2end\test_service_impl.h">
@@ -48,6 +51,9 @@
<ClInclude Include="$(SolutionDir)\..\test\cpp\util\subprocess.h">
<Filter>test\cpp\util</Filter>
</ClInclude>
+ <ClInclude Include="$(SolutionDir)\..\test\cpp\util\test_credentials_provider.h">
+ <Filter>test\cpp\util</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj
index b364bad..a426e41 100644
--- a/vsprojects/vcxproj/grpc/grpc.vcxproj
+++ b/vsprojects/vcxproj/grpc/grpc.vcxproj
@@ -308,6 +308,7 @@
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\resolvers\sockaddr_resolver.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\subchannel.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\subchannel_factory.h" />
+ <ClInclude Include="$(SolutionDir)\..\src\core\client_config\subchannel_index.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\uri_parser.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\compression\algorithm_metadata.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\compression\message_compress.h" />
@@ -468,6 +469,8 @@
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\client_config\subchannel_factory.c">
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\core\client_config\subchannel_index.c">
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\client_config\uri_parser.c">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\compression\algorithm.c">
diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters
index 7c19b8a..0b99cba 100644
--- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters
+++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters
@@ -82,6 +82,9 @@
<ClCompile Include="$(SolutionDir)\..\src\core\client_config\subchannel_factory.c">
<Filter>src\core\client_config</Filter>
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\core\client_config\subchannel_index.c">
+ <Filter>src\core\client_config</Filter>
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\client_config\uri_parser.c">
<Filter>src\core\client_config</Filter>
</ClCompile>
@@ -584,6 +587,9 @@
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\subchannel_factory.h">
<Filter>src\core\client_config</Filter>
</ClInclude>
+ <ClInclude Include="$(SolutionDir)\..\src\core\client_config\subchannel_index.h">
+ <Filter>src\core\client_config</Filter>
+ </ClInclude>
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\uri_parser.h">
<Filter>src\core\client_config</Filter>
</ClInclude>
diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj
index 4edcfab..2092397 100644
--- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj
+++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj
@@ -298,6 +298,7 @@
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\resolvers\sockaddr_resolver.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\subchannel.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\subchannel_factory.h" />
+ <ClInclude Include="$(SolutionDir)\..\src\core\client_config\subchannel_index.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\uri_parser.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\compression\algorithm_metadata.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\compression\message_compress.h" />
@@ -446,6 +447,8 @@
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\client_config\subchannel_factory.c">
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\core\client_config\subchannel_index.c">
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\client_config\uri_parser.c">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\compression\algorithm.c">
diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters
index 11510b5..f6e5275 100644
--- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters
+++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters
@@ -85,6 +85,9 @@
<ClCompile Include="$(SolutionDir)\..\src\core\client_config\subchannel_factory.c">
<Filter>src\core\client_config</Filter>
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\core\client_config\subchannel_index.c">
+ <Filter>src\core\client_config</Filter>
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\client_config\uri_parser.c">
<Filter>src\core\client_config</Filter>
</ClCompile>
@@ -521,6 +524,9 @@
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\subchannel_factory.h">
<Filter>src\core\client_config</Filter>
</ClInclude>
+ <ClInclude Include="$(SolutionDir)\..\src\core\client_config\subchannel_index.h">
+ <Filter>src\core\client_config</Filter>
+ </ClInclude>
<ClInclude Include="$(SolutionDir)\..\src\core\client_config\uri_parser.h">
<Filter>src\core\client_config</Filter>
</ClInclude>