From ecfc238a371b4639de9d95b0bf86beaf7e3b57a7 Mon Sep 17 00:00:00 2001 From: Robbie Shade Date: Fri, 5 Aug 2016 11:42:41 -0400 Subject: Add error log for invalid http2 headers --- src/core/lib/channel/http_server_filter.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 5ce51f9016..d0bada77c2 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -180,6 +180,9 @@ static void hs_on_recv(grpc_exec_ctx *exec_ctx, void *user_data, err, GRPC_ERROR_CREATE("Missing te: trailers header")); } /* Error this call out */ + const char *error_str = grpc_error_string(err); + gpr_log(GPR_ERROR, "Invalid http2 headers: %s", error_str); + grpc_error_free_string(error_str); grpc_call_element_send_cancel(exec_ctx, elem); } } else { -- cgit v1.2.3 From e898ee608cf3a989675aa5fcc18188f322246b50 Mon Sep 17 00:00:00 2001 From: Teodor Date: Tue, 23 Aug 2016 13:18:16 +0300 Subject: Fix example in ruby readme --- src/ruby/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ruby/README.md b/src/ruby/README.md index 3179575486..b30805106d 100644 --- a/src/ruby/README.md +++ b/src/ruby/README.md @@ -64,7 +64,7 @@ Directory structure is the layout for [ruby extensions][] - bin: example gRPC clients and servers, e.g, ```ruby - stub = Math::Math::Stub.new('my.test.math.server.com:8080') + stub = Math::Math::Stub.new('my.test.math.server.com:8080', :this_channel_is_insecure) req = Math::DivArgs.new(dividend: 7, divisor: 3) GRPC.logger.info("div(7/3): req=#{req.inspect}") resp = stub.div(req) -- cgit v1.2.3 From 2137cd8e9b84fd2f602a369ee5922a6fefce2efc Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 14 Sep 2016 09:04:00 -0700 Subject: Rename client_config directory to client_channel. --- BUILD | 264 +++--- CMakeLists.txt | 108 +-- Makefile | 140 +-- binding.gyp | 36 +- build.yaml | 102 +-- config.m4 | 38 +- gRPC-Core.podspec | 96 +-- grpc.gemspec | 66 +- package.xml | 66 +- src/core/ext/client_channel/README.md | 66 ++ src/core/ext/client_channel/channel_connectivity.c | 222 +++++ src/core/ext/client_channel/client_channel.c | 840 ++++++++++++++++++ src/core/ext/client_channel/client_channel.h | 63 ++ .../ext/client_channel/client_channel_factory.c | 57 ++ .../ext/client_channel/client_channel_factory.h | 85 ++ .../ext/client_channel/client_channel_plugin.c | 95 +++ src/core/ext/client_channel/connector.c | 55 ++ src/core/ext/client_channel/connector.h | 92 ++ .../default_initial_connect_string.c | 39 + .../ext/client_channel/initial_connect_string.c | 53 ++ .../ext/client_channel/initial_connect_string.h | 50 ++ src/core/ext/client_channel/lb_policy.c | 146 ++++ src/core/ext/client_channel/lb_policy.h | 166 ++++ src/core/ext/client_channel/lb_policy_factory.c | 49 ++ src/core/ext/client_channel/lb_policy_factory.h | 76 ++ src/core/ext/client_channel/lb_policy_registry.c | 83 ++ src/core/ext/client_channel/lb_policy_registry.h | 55 ++ src/core/ext/client_channel/parse_address.c | 137 +++ src/core/ext/client_channel/parse_address.h | 56 ++ src/core/ext/client_channel/resolver.c | 82 ++ src/core/ext/client_channel/resolver.h | 94 +++ src/core/ext/client_channel/resolver_factory.c | 55 ++ src/core/ext/client_channel/resolver_factory.h | 82 ++ src/core/ext/client_channel/resolver_registry.c | 151 ++++ src/core/ext/client_channel/resolver_registry.h | 69 ++ src/core/ext/client_channel/resolver_result.c | 75 ++ src/core/ext/client_channel/resolver_result.h | 52 ++ src/core/ext/client_channel/subchannel.c | 730 ++++++++++++++++ src/core/ext/client_channel/subchannel.h | 175 ++++ src/core/ext/client_channel/subchannel_factory.c | 49 ++ src/core/ext/client_channel/subchannel_factory.h | 66 ++ src/core/ext/client_channel/subchannel_index.c | 273 ++++++ src/core/ext/client_channel/subchannel_index.h | 77 ++ src/core/ext/client_channel/uri_parser.c | 310 +++++++ src/core/ext/client_channel/uri_parser.h | 63 ++ src/core/ext/client_config/README.md | 66 -- src/core/ext/client_config/channel_connectivity.c | 222 ----- src/core/ext/client_config/client_channel.c | 840 ------------------ src/core/ext/client_config/client_channel.h | 63 -- .../ext/client_config/client_channel_factory.c | 57 -- .../ext/client_config/client_channel_factory.h | 85 -- src/core/ext/client_config/client_config_plugin.c | 95 --- src/core/ext/client_config/connector.c | 55 -- src/core/ext/client_config/connector.h | 92 -- .../client_config/default_initial_connect_string.c | 39 - .../ext/client_config/initial_connect_string.c | 53 -- .../ext/client_config/initial_connect_string.h | 50 -- src/core/ext/client_config/lb_policy.c | 146 ---- src/core/ext/client_config/lb_policy.h | 166 ---- src/core/ext/client_config/lb_policy_factory.c | 49 -- src/core/ext/client_config/lb_policy_factory.h | 76 -- src/core/ext/client_config/lb_policy_registry.c | 83 -- src/core/ext/client_config/lb_policy_registry.h | 55 -- src/core/ext/client_config/parse_address.c | 137 --- src/core/ext/client_config/parse_address.h | 56 -- src/core/ext/client_config/resolver.c | 82 -- src/core/ext/client_config/resolver.h | 94 --- src/core/ext/client_config/resolver_factory.c | 55 -- src/core/ext/client_config/resolver_factory.h | 82 -- src/core/ext/client_config/resolver_registry.c | 151 ---- src/core/ext/client_config/resolver_registry.h | 69 -- src/core/ext/client_config/resolver_result.c | 75 -- src/core/ext/client_config/resolver_result.h | 52 -- src/core/ext/client_config/subchannel.c | 730 ---------------- src/core/ext/client_config/subchannel.h | 175 ---- src/core/ext/client_config/subchannel_factory.c | 49 -- src/core/ext/client_config/subchannel_factory.h | 66 -- src/core/ext/client_config/subchannel_index.c | 273 ------ src/core/ext/client_config/subchannel_index.h | 77 -- src/core/ext/client_config/uri_parser.c | 310 ------- src/core/ext/client_config/uri_parser.h | 63 -- src/core/ext/lb_policy/grpclb/grpclb.c | 6 +- src/core/ext/lb_policy/grpclb/grpclb.h | 2 +- src/core/ext/lb_policy/grpclb/load_balancer_api.h | 2 +- src/core/ext/lb_policy/pick_first/pick_first.c | 2 +- src/core/ext/lb_policy/round_robin/round_robin.c | 2 +- src/core/ext/resolver/dns/native/dns_resolver.c | 4 +- src/core/ext/resolver/sockaddr/sockaddr_resolver.c | 6 +- .../chttp2/client/insecure/channel_create.c | 4 +- .../chttp2/client/secure/secure_channel_create.c | 4 +- .../plugin_registry/grpc_cronet_plugin_registry.c | 8 +- src/core/plugin_registry/grpc_plugin_registry.c | 8 +- .../grpc_unsecure_plugin_registry.c | 8 +- src/python/grpcio/grpc_core_dependencies.py | 36 +- test/core/client_channel/lb_policies_test.c | 938 +++++++++++++++++++++ .../resolvers/dns_resolver_connectivity_test.c | 155 ++++ .../client_channel/resolvers/dns_resolver_test.c | 114 +++ .../resolvers/sockaddr_resolver_test.c | 125 +++ .../set_initial_connect_string_test.c | 257 ++++++ .../02d156dc5e6f2c11c90c2e06fcee04adf036a342 | 2 + .../042dc4512fa3d391c5170cf3aa61e6a638f84342 | 1 + .../0e9bbe975f2027e8c39c89f85f667530368e7d11 | 1 + .../1155aa6ea7ef262a81a63692513ea395f84dad6f | 2 + .../13856a5569ffd085a4d5c07af5f8e9310835a118 | 1 + .../14b57bcbf1e17b1db1de491ef2ba3768f704b7dc | 1 + .../1794310671a060eead6e5ee66ac978a18ec7e84f | 2 + .../1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 | 1 + .../1fcf5d9c333b70596cf5ba04d1f7affdf445b971 | 3 + .../23162c8a8936e20b195404c21337ee734d02a6bc | 1 + .../23f3198b815ca60bdadcaae682b9f965dda387f1 | 1 + .../2ef3893b43f1f60b77b59ce06a6bce9815d78eaf | 2 + .../356c3c129e203b5c74550b4209764d74b9caefce | 1 + .../396568fc41c8ccb31ec925b4a862e4d29ead1327 | 1 + .../3b1e7526a99918006b87e499d2beb6c4ac9c3c0c | 1 + .../3b58860f3451d3e7aad99690a8d39782ca5116fc | 4 + .../41963cc10752f70c3af7e3d85868efb097a0ea9c | 1 + .../47b5228404451fc9d4071fa69192514bb4ce33c1 | 1 + .../56a2da4b2e6fb795243901023ed8d0aa083d1aab | 1 + .../574c2f13858a9a6d724654bd913ede9ae3abf822 | 2 + .../582f789c19033a152094cbf8565f14154a778ddb | 1 + .../636c5606fc23713a1bae88c8899c0541cfad4fd8 | 4 + .../63fe493b270b17426d77a27cbf3abac5b2c2794a | 1 + .../655300a902b62662296a8e46bfb04fbcb07182cb | 1 + .../6ae3acd9d8507b61bf235748026080a4138dba58 | 1 + .../6b70979a70a038ff6607d6cf85485ee95baf58e6 | 1 + .../7314ab3545a7535a26e0e8aad67caea5534d68b1 | 2 + .../7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb | 1 + .../87daa131e0973b77a232a870ed749ef29cf58e6d | 2 + .../884dcaee2908ffe5f12b65b8eba81016099c4266 | 1 + .../8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb | 1 + .../9671149af0b444f59bbdf71340d3441dadd8a7b4 | 1 + .../96c8d266b7dc037288ef305c996608270f72e7fb | 2 + .../975536c71ade4800415a7e9c2f1b45c35a6d5ea8 | 1 + .../99750aa67d30beaea8af565c829d4999aa8cb91b | 1 + .../a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 | 1 + .../a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de | 1 + .../a296eb3d1d436ed7df7195b10aa3c4de3896f98d | 1 + .../a8b8e66050b424f1b8c07d46f868199fb7f60e38 | 1 + .../aba1472880406a318ce207ee79815b7acf087757 | 1 + .../af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 | 1 + .../b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd | 1 + .../c28a47409cf5d95bb372238d01e73d8b831408e4 | 1 + .../c3ef1d41888063a08700c3add1e4465aabcf8807 | 2 + .../c550a76af21f9b9cc92a386d5c8998b26f8f2e4d | 1 + .../c79721406d0ab80495f186fd88e37fba98637ae9 | 1 + .../ceb4e2264ba7a8d5be47d276b37ec09489e00245 | 1 + .../cf4395958f5bfb46fd6f535a39657d016c75114c | 1 + .../d46668372b7e20154a89409a7430a28e642afdca | 1 + .../d6fe7412a0a1d1c733160246f3fa425f4f97682a | 1 + test/core/client_channel/uri_corpus/dns.txt | 1 + .../e241f29957b0e30ec11aaaf91b2339f7015fa5fd | 1 + .../ea02d9fea9bad5b89cf353a0169238f584177e71 | 4 + .../ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee | 1 + .../ed2f78646f19fc47dd85ff0877c232b71913ece2 | 1 + .../f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 | 2 + .../f6f3bd030f0d321efe7c51ca3f057de23509af67 | 1 + .../f97598cff03306af3c70400608fec47268b5075d | 2 + .../f9e1ec1fc642b575bc9955618b7065747f56b101 | 1 + .../fe0630a3aeed2ec6f474f362e4c839478290d5c4 | 1 + test/core/client_channel/uri_corpus/ipv4.txt | 1 + test/core/client_channel/uri_corpus/ipv6.txt | 1 + test/core/client_channel/uri_corpus/unix.txt | 1 + test/core/client_channel/uri_fuzzer_test.c | 56 ++ test/core/client_channel/uri_parser_test.c | 154 ++++ test/core/client_config/lb_policies_test.c | 938 --------------------- .../resolvers/dns_resolver_connectivity_test.c | 155 ---- .../client_config/resolvers/dns_resolver_test.c | 114 --- .../resolvers/sockaddr_resolver_test.c | 125 --- .../set_initial_connect_string_test.c | 257 ------ .../02d156dc5e6f2c11c90c2e06fcee04adf036a342 | 2 - .../042dc4512fa3d391c5170cf3aa61e6a638f84342 | 1 - .../0e9bbe975f2027e8c39c89f85f667530368e7d11 | 1 - .../1155aa6ea7ef262a81a63692513ea395f84dad6f | 2 - .../13856a5569ffd085a4d5c07af5f8e9310835a118 | 1 - .../14b57bcbf1e17b1db1de491ef2ba3768f704b7dc | 1 - .../1794310671a060eead6e5ee66ac978a18ec7e84f | 2 - .../1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 | 1 - .../1fcf5d9c333b70596cf5ba04d1f7affdf445b971 | 3 - .../23162c8a8936e20b195404c21337ee734d02a6bc | 1 - .../23f3198b815ca60bdadcaae682b9f965dda387f1 | 1 - .../2ef3893b43f1f60b77b59ce06a6bce9815d78eaf | 2 - .../356c3c129e203b5c74550b4209764d74b9caefce | 1 - .../396568fc41c8ccb31ec925b4a862e4d29ead1327 | 1 - .../3b1e7526a99918006b87e499d2beb6c4ac9c3c0c | 1 - .../3b58860f3451d3e7aad99690a8d39782ca5116fc | 4 - .../41963cc10752f70c3af7e3d85868efb097a0ea9c | 1 - .../47b5228404451fc9d4071fa69192514bb4ce33c1 | 1 - .../56a2da4b2e6fb795243901023ed8d0aa083d1aab | 1 - .../574c2f13858a9a6d724654bd913ede9ae3abf822 | 2 - .../582f789c19033a152094cbf8565f14154a778ddb | 1 - .../636c5606fc23713a1bae88c8899c0541cfad4fd8 | 4 - .../63fe493b270b17426d77a27cbf3abac5b2c2794a | 1 - .../655300a902b62662296a8e46bfb04fbcb07182cb | 1 - .../6ae3acd9d8507b61bf235748026080a4138dba58 | 1 - .../6b70979a70a038ff6607d6cf85485ee95baf58e6 | 1 - .../7314ab3545a7535a26e0e8aad67caea5534d68b1 | 2 - .../7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb | 1 - .../87daa131e0973b77a232a870ed749ef29cf58e6d | 2 - .../884dcaee2908ffe5f12b65b8eba81016099c4266 | 1 - .../8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb | 1 - .../9671149af0b444f59bbdf71340d3441dadd8a7b4 | 1 - .../96c8d266b7dc037288ef305c996608270f72e7fb | 2 - .../975536c71ade4800415a7e9c2f1b45c35a6d5ea8 | 1 - .../99750aa67d30beaea8af565c829d4999aa8cb91b | 1 - .../a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 | 1 - .../a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de | 1 - .../a296eb3d1d436ed7df7195b10aa3c4de3896f98d | 1 - .../a8b8e66050b424f1b8c07d46f868199fb7f60e38 | 1 - .../aba1472880406a318ce207ee79815b7acf087757 | 1 - .../af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 | 1 - .../b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd | 1 - .../c28a47409cf5d95bb372238d01e73d8b831408e4 | 1 - .../c3ef1d41888063a08700c3add1e4465aabcf8807 | 2 - .../c550a76af21f9b9cc92a386d5c8998b26f8f2e4d | 1 - .../c79721406d0ab80495f186fd88e37fba98637ae9 | 1 - .../ceb4e2264ba7a8d5be47d276b37ec09489e00245 | 1 - .../cf4395958f5bfb46fd6f535a39657d016c75114c | 1 - .../d46668372b7e20154a89409a7430a28e642afdca | 1 - .../d6fe7412a0a1d1c733160246f3fa425f4f97682a | 1 - test/core/client_config/uri_corpus/dns.txt | 1 - .../e241f29957b0e30ec11aaaf91b2339f7015fa5fd | 1 - .../ea02d9fea9bad5b89cf353a0169238f584177e71 | 4 - .../ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee | 1 - .../ed2f78646f19fc47dd85ff0877c232b71913ece2 | 1 - .../f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 | 2 - .../f6f3bd030f0d321efe7c51ca3f057de23509af67 | 1 - .../f97598cff03306af3c70400608fec47268b5075d | 2 - .../f9e1ec1fc642b575bc9955618b7065747f56b101 | 1 - .../fe0630a3aeed2ec6f474f362e4c839478290d5c4 | 1 - test/core/client_config/uri_corpus/ipv4.txt | 1 - test/core/client_config/uri_corpus/ipv6.txt | 1 - test/core/client_config/uri_corpus/unix.txt | 1 - test/core/client_config/uri_fuzzer_test.c | 56 -- test/core/client_config/uri_parser_test.c | 154 ---- test/core/end2end/fixtures/h2_census.c | 2 +- test/core/end2end/fixtures/h2_compress.c | 2 +- test/core/end2end/fixtures/h2_full+pipe.c | 2 +- test/core/end2end/fixtures/h2_full+trace.c | 2 +- test/core/end2end/fixtures/h2_full.c | 2 +- test/core/end2end/fixtures/h2_load_reporting.c | 2 +- test/core/end2end/fixtures/h2_proxy.c | 2 +- test/core/end2end/fixtures/h2_sockpair+trace.c | 2 +- test/core/end2end/fixtures/h2_sockpair.c | 2 +- test/core/end2end/fixtures/h2_sockpair_1byte.c | 2 +- test/core/end2end/fixtures/h2_uds.c | 2 +- test/core/surface/channel_create_test.c | 2 +- test/core/surface/secure_channel_create_test.c | 2 +- tools/doxygen/Doxyfile.core.internal | 66 +- tools/fuzzer/runners/uri_fuzzer_test.sh | 2 +- tools/run_tests/sources_and_headers.json | 134 +-- tools/run_tests/tests.json | 126 +-- vsprojects/vcxproj/grpc/grpc.vcxproj | 66 +- vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 136 +-- .../vcxproj/grpc_unsecure/grpc_unsecure.vcxproj | 66 +- .../grpc_unsecure/grpc_unsecure.vcxproj.filters | 136 +-- .../dns_resolver_connectivity_test.vcxproj | 2 +- .../dns_resolver_connectivity_test.vcxproj.filters | 12 +- .../dns_resolver_test/dns_resolver_test.vcxproj | 2 +- .../dns_resolver_test.vcxproj.filters | 12 +- .../test/lb_policies_test/lb_policies_test.vcxproj | 2 +- .../lb_policies_test.vcxproj.filters | 8 +- .../set_initial_connect_string_test.vcxproj | 2 +- ...set_initial_connect_string_test.vcxproj.filters | 8 +- .../sockaddr_resolver_test.vcxproj | 2 +- .../sockaddr_resolver_test.vcxproj.filters | 12 +- .../test/uri_parser_test/uri_parser_test.vcxproj | 2 +- .../uri_parser_test.vcxproj.filters | 8 +- 267 files changed, 7691 insertions(+), 7691 deletions(-) create mode 100644 src/core/ext/client_channel/README.md create mode 100644 src/core/ext/client_channel/channel_connectivity.c create mode 100644 src/core/ext/client_channel/client_channel.c create mode 100644 src/core/ext/client_channel/client_channel.h create mode 100644 src/core/ext/client_channel/client_channel_factory.c create mode 100644 src/core/ext/client_channel/client_channel_factory.h create mode 100644 src/core/ext/client_channel/client_channel_plugin.c create mode 100644 src/core/ext/client_channel/connector.c create mode 100644 src/core/ext/client_channel/connector.h create mode 100644 src/core/ext/client_channel/default_initial_connect_string.c create mode 100644 src/core/ext/client_channel/initial_connect_string.c create mode 100644 src/core/ext/client_channel/initial_connect_string.h create mode 100644 src/core/ext/client_channel/lb_policy.c create mode 100644 src/core/ext/client_channel/lb_policy.h create mode 100644 src/core/ext/client_channel/lb_policy_factory.c create mode 100644 src/core/ext/client_channel/lb_policy_factory.h create mode 100644 src/core/ext/client_channel/lb_policy_registry.c create mode 100644 src/core/ext/client_channel/lb_policy_registry.h create mode 100644 src/core/ext/client_channel/parse_address.c create mode 100644 src/core/ext/client_channel/parse_address.h create mode 100644 src/core/ext/client_channel/resolver.c create mode 100644 src/core/ext/client_channel/resolver.h create mode 100644 src/core/ext/client_channel/resolver_factory.c create mode 100644 src/core/ext/client_channel/resolver_factory.h create mode 100644 src/core/ext/client_channel/resolver_registry.c create mode 100644 src/core/ext/client_channel/resolver_registry.h create mode 100644 src/core/ext/client_channel/resolver_result.c create mode 100644 src/core/ext/client_channel/resolver_result.h create mode 100644 src/core/ext/client_channel/subchannel.c create mode 100644 src/core/ext/client_channel/subchannel.h create mode 100644 src/core/ext/client_channel/subchannel_factory.c create mode 100644 src/core/ext/client_channel/subchannel_factory.h create mode 100644 src/core/ext/client_channel/subchannel_index.c create mode 100644 src/core/ext/client_channel/subchannel_index.h create mode 100644 src/core/ext/client_channel/uri_parser.c create mode 100644 src/core/ext/client_channel/uri_parser.h delete mode 100644 src/core/ext/client_config/README.md delete mode 100644 src/core/ext/client_config/channel_connectivity.c delete mode 100644 src/core/ext/client_config/client_channel.c delete mode 100644 src/core/ext/client_config/client_channel.h delete mode 100644 src/core/ext/client_config/client_channel_factory.c delete mode 100644 src/core/ext/client_config/client_channel_factory.h delete mode 100644 src/core/ext/client_config/client_config_plugin.c delete mode 100644 src/core/ext/client_config/connector.c delete mode 100644 src/core/ext/client_config/connector.h delete mode 100644 src/core/ext/client_config/default_initial_connect_string.c delete mode 100644 src/core/ext/client_config/initial_connect_string.c delete mode 100644 src/core/ext/client_config/initial_connect_string.h delete mode 100644 src/core/ext/client_config/lb_policy.c delete mode 100644 src/core/ext/client_config/lb_policy.h delete mode 100644 src/core/ext/client_config/lb_policy_factory.c delete mode 100644 src/core/ext/client_config/lb_policy_factory.h delete mode 100644 src/core/ext/client_config/lb_policy_registry.c delete mode 100644 src/core/ext/client_config/lb_policy_registry.h delete mode 100644 src/core/ext/client_config/parse_address.c delete mode 100644 src/core/ext/client_config/parse_address.h delete mode 100644 src/core/ext/client_config/resolver.c delete mode 100644 src/core/ext/client_config/resolver.h delete mode 100644 src/core/ext/client_config/resolver_factory.c delete mode 100644 src/core/ext/client_config/resolver_factory.h delete mode 100644 src/core/ext/client_config/resolver_registry.c delete mode 100644 src/core/ext/client_config/resolver_registry.h delete mode 100644 src/core/ext/client_config/resolver_result.c delete mode 100644 src/core/ext/client_config/resolver_result.h delete mode 100644 src/core/ext/client_config/subchannel.c delete mode 100644 src/core/ext/client_config/subchannel.h delete mode 100644 src/core/ext/client_config/subchannel_factory.c delete mode 100644 src/core/ext/client_config/subchannel_factory.h delete mode 100644 src/core/ext/client_config/subchannel_index.c delete mode 100644 src/core/ext/client_config/subchannel_index.h delete mode 100644 src/core/ext/client_config/uri_parser.c delete mode 100644 src/core/ext/client_config/uri_parser.h create mode 100644 test/core/client_channel/lb_policies_test.c create mode 100644 test/core/client_channel/resolvers/dns_resolver_connectivity_test.c create mode 100644 test/core/client_channel/resolvers/dns_resolver_test.c create mode 100644 test/core/client_channel/resolvers/sockaddr_resolver_test.c create mode 100644 test/core/client_channel/set_initial_connect_string_test.c create mode 100644 test/core/client_channel/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342 create mode 100644 test/core/client_channel/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342 create mode 100644 test/core/client_channel/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11 create mode 100644 test/core/client_channel/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f create mode 100644 test/core/client_channel/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118 create mode 100644 test/core/client_channel/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc create mode 100644 test/core/client_channel/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f create mode 100644 test/core/client_channel/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 create mode 100644 test/core/client_channel/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971 create mode 100644 test/core/client_channel/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc create mode 100644 test/core/client_channel/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1 create mode 100644 test/core/client_channel/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf create mode 100644 test/core/client_channel/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce create mode 100644 test/core/client_channel/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327 create mode 100644 test/core/client_channel/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c create mode 100644 test/core/client_channel/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc create mode 100644 test/core/client_channel/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c create mode 100644 test/core/client_channel/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1 create mode 100644 test/core/client_channel/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab create mode 100644 test/core/client_channel/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822 create mode 100644 test/core/client_channel/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb create mode 100644 test/core/client_channel/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8 create mode 100644 test/core/client_channel/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a create mode 100644 test/core/client_channel/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb create mode 100644 test/core/client_channel/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58 create mode 100644 test/core/client_channel/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6 create mode 100644 test/core/client_channel/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1 create mode 100644 test/core/client_channel/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb create mode 100644 test/core/client_channel/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d create mode 100644 test/core/client_channel/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266 create mode 100644 test/core/client_channel/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb create mode 100644 test/core/client_channel/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4 create mode 100644 test/core/client_channel/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb create mode 100644 test/core/client_channel/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8 create mode 100644 test/core/client_channel/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b create mode 100644 test/core/client_channel/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 create mode 100644 test/core/client_channel/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de create mode 100644 test/core/client_channel/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d create mode 100644 test/core/client_channel/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38 create mode 100644 test/core/client_channel/uri_corpus/aba1472880406a318ce207ee79815b7acf087757 create mode 100644 test/core/client_channel/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 create mode 100644 test/core/client_channel/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd create mode 100644 test/core/client_channel/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4 create mode 100644 test/core/client_channel/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807 create mode 100644 test/core/client_channel/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d create mode 100644 test/core/client_channel/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9 create mode 100644 test/core/client_channel/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245 create mode 100644 test/core/client_channel/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c create mode 100644 test/core/client_channel/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca create mode 100644 test/core/client_channel/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a create mode 100644 test/core/client_channel/uri_corpus/dns.txt create mode 100644 test/core/client_channel/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd create mode 100644 test/core/client_channel/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71 create mode 100644 test/core/client_channel/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee create mode 100644 test/core/client_channel/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2 create mode 100644 test/core/client_channel/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 create mode 100644 test/core/client_channel/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67 create mode 100644 test/core/client_channel/uri_corpus/f97598cff03306af3c70400608fec47268b5075d create mode 100644 test/core/client_channel/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101 create mode 100644 test/core/client_channel/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4 create mode 100644 test/core/client_channel/uri_corpus/ipv4.txt create mode 100644 test/core/client_channel/uri_corpus/ipv6.txt create mode 100644 test/core/client_channel/uri_corpus/unix.txt create mode 100644 test/core/client_channel/uri_fuzzer_test.c create mode 100644 test/core/client_channel/uri_parser_test.c delete mode 100644 test/core/client_config/lb_policies_test.c delete mode 100644 test/core/client_config/resolvers/dns_resolver_connectivity_test.c delete mode 100644 test/core/client_config/resolvers/dns_resolver_test.c delete mode 100644 test/core/client_config/resolvers/sockaddr_resolver_test.c delete mode 100644 test/core/client_config/set_initial_connect_string_test.c delete mode 100644 test/core/client_config/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342 delete mode 100644 test/core/client_config/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342 delete mode 100644 test/core/client_config/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11 delete mode 100644 test/core/client_config/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f delete mode 100644 test/core/client_config/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118 delete mode 100644 test/core/client_config/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc delete mode 100644 test/core/client_config/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f delete mode 100644 test/core/client_config/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 delete mode 100644 test/core/client_config/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971 delete mode 100644 test/core/client_config/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc delete mode 100644 test/core/client_config/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1 delete mode 100644 test/core/client_config/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf delete mode 100644 test/core/client_config/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce delete mode 100644 test/core/client_config/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327 delete mode 100644 test/core/client_config/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c delete mode 100644 test/core/client_config/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc delete mode 100644 test/core/client_config/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c delete mode 100644 test/core/client_config/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1 delete mode 100644 test/core/client_config/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab delete mode 100644 test/core/client_config/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822 delete mode 100644 test/core/client_config/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb delete mode 100644 test/core/client_config/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8 delete mode 100644 test/core/client_config/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a delete mode 100644 test/core/client_config/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb delete mode 100644 test/core/client_config/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58 delete mode 100644 test/core/client_config/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6 delete mode 100644 test/core/client_config/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1 delete mode 100644 test/core/client_config/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb delete mode 100644 test/core/client_config/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d delete mode 100644 test/core/client_config/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266 delete mode 100644 test/core/client_config/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb delete mode 100644 test/core/client_config/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4 delete mode 100644 test/core/client_config/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb delete mode 100644 test/core/client_config/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8 delete mode 100644 test/core/client_config/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b delete mode 100644 test/core/client_config/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 delete mode 100644 test/core/client_config/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de delete mode 100644 test/core/client_config/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d delete mode 100644 test/core/client_config/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38 delete mode 100644 test/core/client_config/uri_corpus/aba1472880406a318ce207ee79815b7acf087757 delete mode 100644 test/core/client_config/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 delete mode 100644 test/core/client_config/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd delete mode 100644 test/core/client_config/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4 delete mode 100644 test/core/client_config/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807 delete mode 100644 test/core/client_config/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d delete mode 100644 test/core/client_config/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9 delete mode 100644 test/core/client_config/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245 delete mode 100644 test/core/client_config/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c delete mode 100644 test/core/client_config/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca delete mode 100644 test/core/client_config/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a delete mode 100644 test/core/client_config/uri_corpus/dns.txt delete mode 100644 test/core/client_config/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd delete mode 100644 test/core/client_config/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71 delete mode 100644 test/core/client_config/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee delete mode 100644 test/core/client_config/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2 delete mode 100644 test/core/client_config/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 delete mode 100644 test/core/client_config/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67 delete mode 100644 test/core/client_config/uri_corpus/f97598cff03306af3c70400608fec47268b5075d delete mode 100644 test/core/client_config/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101 delete mode 100644 test/core/client_config/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4 delete mode 100644 test/core/client_config/uri_corpus/ipv4.txt delete mode 100644 test/core/client_config/uri_corpus/ipv6.txt delete mode 100644 test/core/client_config/uri_corpus/unix.txt delete mode 100644 test/core/client_config/uri_fuzzer_test.c delete mode 100644 test/core/client_config/uri_parser_test.c (limited to 'src') diff --git a/BUILD b/BUILD index ee41d1ab21..3046e5f3b4 100644 --- a/BUILD +++ b/BUILD @@ -288,21 +288,21 @@ cc_library( "src/core/lib/tsi/ssl_types.h", "src/core/lib/tsi/transport_security.h", "src/core/lib/tsi/transport_security_interface.h", - "src/core/ext/client_config/client_channel.h", - "src/core/ext/client_config/client_channel_factory.h", - "src/core/ext/client_config/connector.h", - "src/core/ext/client_config/initial_connect_string.h", - "src/core/ext/client_config/lb_policy.h", - "src/core/ext/client_config/lb_policy_factory.h", - "src/core/ext/client_config/lb_policy_registry.h", - "src/core/ext/client_config/parse_address.h", - "src/core/ext/client_config/resolver.h", - "src/core/ext/client_config/resolver_factory.h", - "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.h", - "src/core/ext/client_config/subchannel.h", - "src/core/ext/client_config/subchannel_index.h", - "src/core/ext/client_config/uri_parser.h", + "src/core/ext/client_channel/client_channel.h", + "src/core/ext/client_channel/client_channel_factory.h", + "src/core/ext/client_channel/connector.h", + "src/core/ext/client_channel/initial_connect_string.h", + "src/core/ext/client_channel/lb_policy.h", + "src/core/ext/client_channel/lb_policy_factory.h", + "src/core/ext/client_channel/lb_policy_registry.h", + "src/core/ext/client_channel/parse_address.h", + "src/core/ext/client_channel/resolver.h", + "src/core/ext/client_channel/resolver_factory.h", + "src/core/ext/client_channel/resolver_registry.h", + "src/core/ext/client_channel/resolver_result.h", + "src/core/ext/client_channel/subchannel.h", + "src/core/ext/client_channel/subchannel_index.h", + "src/core/ext/client_channel/uri_parser.h", "src/core/ext/lb_policy/grpclb/grpclb.h", "src/core/ext/lb_policy/grpclb/load_balancer_api.h", "src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h", @@ -460,24 +460,24 @@ cc_library( "src/core/lib/tsi/ssl_transport_security.c", "src/core/lib/tsi/transport_security.c", "src/core/ext/transport/chttp2/client/secure/secure_channel_create.c", - "src/core/ext/client_config/channel_connectivity.c", - "src/core/ext/client_config/client_channel.c", - "src/core/ext/client_config/client_channel_factory.c", - "src/core/ext/client_config/client_config_plugin.c", - "src/core/ext/client_config/connector.c", - "src/core/ext/client_config/default_initial_connect_string.c", - "src/core/ext/client_config/initial_connect_string.c", - "src/core/ext/client_config/lb_policy.c", - "src/core/ext/client_config/lb_policy_factory.c", - "src/core/ext/client_config/lb_policy_registry.c", - "src/core/ext/client_config/parse_address.c", - "src/core/ext/client_config/resolver.c", - "src/core/ext/client_config/resolver_factory.c", - "src/core/ext/client_config/resolver_registry.c", - "src/core/ext/client_config/resolver_result.c", - "src/core/ext/client_config/subchannel.c", - "src/core/ext/client_config/subchannel_index.c", - "src/core/ext/client_config/uri_parser.c", + "src/core/ext/client_channel/channel_connectivity.c", + "src/core/ext/client_channel/client_channel.c", + "src/core/ext/client_channel/client_channel_factory.c", + "src/core/ext/client_channel/client_channel_plugin.c", + "src/core/ext/client_channel/connector.c", + "src/core/ext/client_channel/default_initial_connect_string.c", + "src/core/ext/client_channel/initial_connect_string.c", + "src/core/ext/client_channel/lb_policy.c", + "src/core/ext/client_channel/lb_policy_factory.c", + "src/core/ext/client_channel/lb_policy_registry.c", + "src/core/ext/client_channel/parse_address.c", + "src/core/ext/client_channel/resolver.c", + "src/core/ext/client_channel/resolver_factory.c", + "src/core/ext/client_channel/resolver_registry.c", + "src/core/ext/client_channel/resolver_result.c", + "src/core/ext/client_channel/subchannel.c", + "src/core/ext/client_channel/subchannel_index.c", + "src/core/ext/client_channel/uri_parser.c", "src/core/ext/transport/chttp2/server/insecure/server_chttp2.c", "src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c", "src/core/ext/transport/chttp2/client/insecure/channel_create.c", @@ -660,21 +660,21 @@ cc_library( "src/core/ext/transport/chttp2/transport/stream_map.h", "src/core/ext/transport/chttp2/transport/varint.h", "src/core/ext/transport/chttp2/alpn/alpn.h", - "src/core/ext/client_config/client_channel.h", - "src/core/ext/client_config/client_channel_factory.h", - "src/core/ext/client_config/connector.h", - "src/core/ext/client_config/initial_connect_string.h", - "src/core/ext/client_config/lb_policy.h", - "src/core/ext/client_config/lb_policy_factory.h", - "src/core/ext/client_config/lb_policy_registry.h", - "src/core/ext/client_config/parse_address.h", - "src/core/ext/client_config/resolver.h", - "src/core/ext/client_config/resolver_factory.h", - "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.h", - "src/core/ext/client_config/subchannel.h", - "src/core/ext/client_config/subchannel_index.h", - "src/core/ext/client_config/uri_parser.h", + "src/core/ext/client_channel/client_channel.h", + "src/core/ext/client_channel/client_channel_factory.h", + "src/core/ext/client_channel/connector.h", + "src/core/ext/client_channel/initial_connect_string.h", + "src/core/ext/client_channel/lb_policy.h", + "src/core/ext/client_channel/lb_policy_factory.h", + "src/core/ext/client_channel/lb_policy_registry.h", + "src/core/ext/client_channel/parse_address.h", + "src/core/ext/client_channel/resolver.h", + "src/core/ext/client_channel/resolver_factory.h", + "src/core/ext/client_channel/resolver_registry.h", + "src/core/ext/client_channel/resolver_result.h", + "src/core/ext/client_channel/subchannel.h", + "src/core/ext/client_channel/subchannel_index.h", + "src/core/ext/client_channel/uri_parser.h", "src/core/lib/security/context/security_context.h", "src/core/lib/security/credentials/composite/composite_credentials.h", "src/core/lib/security/credentials/credentials.h", @@ -815,24 +815,24 @@ cc_library( "src/core/ext/transport/chttp2/transport/varint.c", "src/core/ext/transport/chttp2/transport/writing.c", "src/core/ext/transport/chttp2/alpn/alpn.c", - "src/core/ext/client_config/channel_connectivity.c", - "src/core/ext/client_config/client_channel.c", - "src/core/ext/client_config/client_channel_factory.c", - "src/core/ext/client_config/client_config_plugin.c", - "src/core/ext/client_config/connector.c", - "src/core/ext/client_config/default_initial_connect_string.c", - "src/core/ext/client_config/initial_connect_string.c", - "src/core/ext/client_config/lb_policy.c", - "src/core/ext/client_config/lb_policy_factory.c", - "src/core/ext/client_config/lb_policy_registry.c", - "src/core/ext/client_config/parse_address.c", - "src/core/ext/client_config/resolver.c", - "src/core/ext/client_config/resolver_factory.c", - "src/core/ext/client_config/resolver_registry.c", - "src/core/ext/client_config/resolver_result.c", - "src/core/ext/client_config/subchannel.c", - "src/core/ext/client_config/subchannel_index.c", - "src/core/ext/client_config/uri_parser.c", + "src/core/ext/client_channel/channel_connectivity.c", + "src/core/ext/client_channel/client_channel.c", + "src/core/ext/client_channel/client_channel_factory.c", + "src/core/ext/client_channel/client_channel_plugin.c", + "src/core/ext/client_channel/connector.c", + "src/core/ext/client_channel/default_initial_connect_string.c", + "src/core/ext/client_channel/initial_connect_string.c", + "src/core/ext/client_channel/lb_policy.c", + "src/core/ext/client_channel/lb_policy_factory.c", + "src/core/ext/client_channel/lb_policy_registry.c", + "src/core/ext/client_channel/parse_address.c", + "src/core/ext/client_channel/resolver.c", + "src/core/ext/client_channel/resolver_factory.c", + "src/core/ext/client_channel/resolver_registry.c", + "src/core/ext/client_channel/resolver_result.c", + "src/core/ext/client_channel/subchannel.c", + "src/core/ext/client_channel/subchannel_index.c", + "src/core/ext/client_channel/uri_parser.c", "src/core/lib/http/httpcli_security_connector.c", "src/core/lib/security/context/security_context.c", "src/core/lib/security/credentials/composite/composite_credentials.c", @@ -1011,21 +1011,21 @@ cc_library( "src/core/ext/transport/chttp2/transport/stream_map.h", "src/core/ext/transport/chttp2/transport/varint.h", "src/core/ext/transport/chttp2/alpn/alpn.h", - "src/core/ext/client_config/client_channel.h", - "src/core/ext/client_config/client_channel_factory.h", - "src/core/ext/client_config/connector.h", - "src/core/ext/client_config/initial_connect_string.h", - "src/core/ext/client_config/lb_policy.h", - "src/core/ext/client_config/lb_policy_factory.h", - "src/core/ext/client_config/lb_policy_registry.h", - "src/core/ext/client_config/parse_address.h", - "src/core/ext/client_config/resolver.h", - "src/core/ext/client_config/resolver_factory.h", - "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.h", - "src/core/ext/client_config/subchannel.h", - "src/core/ext/client_config/subchannel_index.h", - "src/core/ext/client_config/uri_parser.h", + "src/core/ext/client_channel/client_channel.h", + "src/core/ext/client_channel/client_channel_factory.h", + "src/core/ext/client_channel/connector.h", + "src/core/ext/client_channel/initial_connect_string.h", + "src/core/ext/client_channel/lb_policy.h", + "src/core/ext/client_channel/lb_policy_factory.h", + "src/core/ext/client_channel/lb_policy_registry.h", + "src/core/ext/client_channel/parse_address.h", + "src/core/ext/client_channel/resolver.h", + "src/core/ext/client_channel/resolver_factory.h", + "src/core/ext/client_channel/resolver_registry.h", + "src/core/ext/client_channel/resolver_result.h", + "src/core/ext/client_channel/subchannel.h", + "src/core/ext/client_channel/subchannel_index.h", + "src/core/ext/client_channel/uri_parser.h", "src/core/ext/load_reporting/load_reporting.h", "src/core/ext/load_reporting/load_reporting_filter.h", "src/core/ext/lb_policy/grpclb/grpclb.h", @@ -1158,24 +1158,24 @@ cc_library( "src/core/ext/transport/chttp2/alpn/alpn.c", "src/core/ext/transport/chttp2/client/insecure/channel_create.c", "src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c", - "src/core/ext/client_config/channel_connectivity.c", - "src/core/ext/client_config/client_channel.c", - "src/core/ext/client_config/client_channel_factory.c", - "src/core/ext/client_config/client_config_plugin.c", - "src/core/ext/client_config/connector.c", - "src/core/ext/client_config/default_initial_connect_string.c", - "src/core/ext/client_config/initial_connect_string.c", - "src/core/ext/client_config/lb_policy.c", - "src/core/ext/client_config/lb_policy_factory.c", - "src/core/ext/client_config/lb_policy_registry.c", - "src/core/ext/client_config/parse_address.c", - "src/core/ext/client_config/resolver.c", - "src/core/ext/client_config/resolver_factory.c", - "src/core/ext/client_config/resolver_registry.c", - "src/core/ext/client_config/resolver_result.c", - "src/core/ext/client_config/subchannel.c", - "src/core/ext/client_config/subchannel_index.c", - "src/core/ext/client_config/uri_parser.c", + "src/core/ext/client_channel/channel_connectivity.c", + "src/core/ext/client_channel/client_channel.c", + "src/core/ext/client_channel/client_channel_factory.c", + "src/core/ext/client_channel/client_channel_plugin.c", + "src/core/ext/client_channel/connector.c", + "src/core/ext/client_channel/default_initial_connect_string.c", + "src/core/ext/client_channel/initial_connect_string.c", + "src/core/ext/client_channel/lb_policy.c", + "src/core/ext/client_channel/lb_policy_factory.c", + "src/core/ext/client_channel/lb_policy_registry.c", + "src/core/ext/client_channel/parse_address.c", + "src/core/ext/client_channel/resolver.c", + "src/core/ext/client_channel/resolver_factory.c", + "src/core/ext/client_channel/resolver_registry.c", + "src/core/ext/client_channel/resolver_result.c", + "src/core/ext/client_channel/subchannel.c", + "src/core/ext/client_channel/subchannel_index.c", + "src/core/ext/client_channel/uri_parser.c", "src/core/ext/resolver/dns/native/dns_resolver.c", "src/core/ext/resolver/sockaddr/sockaddr_resolver.c", "src/core/ext/load_reporting/load_reporting.c", @@ -2306,24 +2306,24 @@ objc_library( "src/core/lib/tsi/ssl_transport_security.c", "src/core/lib/tsi/transport_security.c", "src/core/ext/transport/chttp2/client/secure/secure_channel_create.c", - "src/core/ext/client_config/channel_connectivity.c", - "src/core/ext/client_config/client_channel.c", - "src/core/ext/client_config/client_channel_factory.c", - "src/core/ext/client_config/client_config_plugin.c", - "src/core/ext/client_config/connector.c", - "src/core/ext/client_config/default_initial_connect_string.c", - "src/core/ext/client_config/initial_connect_string.c", - "src/core/ext/client_config/lb_policy.c", - "src/core/ext/client_config/lb_policy_factory.c", - "src/core/ext/client_config/lb_policy_registry.c", - "src/core/ext/client_config/parse_address.c", - "src/core/ext/client_config/resolver.c", - "src/core/ext/client_config/resolver_factory.c", - "src/core/ext/client_config/resolver_registry.c", - "src/core/ext/client_config/resolver_result.c", - "src/core/ext/client_config/subchannel.c", - "src/core/ext/client_config/subchannel_index.c", - "src/core/ext/client_config/uri_parser.c", + "src/core/ext/client_channel/channel_connectivity.c", + "src/core/ext/client_channel/client_channel.c", + "src/core/ext/client_channel/client_channel_factory.c", + "src/core/ext/client_channel/client_channel_plugin.c", + "src/core/ext/client_channel/connector.c", + "src/core/ext/client_channel/default_initial_connect_string.c", + "src/core/ext/client_channel/initial_connect_string.c", + "src/core/ext/client_channel/lb_policy.c", + "src/core/ext/client_channel/lb_policy_factory.c", + "src/core/ext/client_channel/lb_policy_registry.c", + "src/core/ext/client_channel/parse_address.c", + "src/core/ext/client_channel/resolver.c", + "src/core/ext/client_channel/resolver_factory.c", + "src/core/ext/client_channel/resolver_registry.c", + "src/core/ext/client_channel/resolver_result.c", + "src/core/ext/client_channel/subchannel.c", + "src/core/ext/client_channel/subchannel_index.c", + "src/core/ext/client_channel/uri_parser.c", "src/core/ext/transport/chttp2/server/insecure/server_chttp2.c", "src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c", "src/core/ext/transport/chttp2/client/insecure/channel_create.c", @@ -2508,21 +2508,21 @@ objc_library( "src/core/lib/tsi/ssl_types.h", "src/core/lib/tsi/transport_security.h", "src/core/lib/tsi/transport_security_interface.h", - "src/core/ext/client_config/client_channel.h", - "src/core/ext/client_config/client_channel_factory.h", - "src/core/ext/client_config/connector.h", - "src/core/ext/client_config/initial_connect_string.h", - "src/core/ext/client_config/lb_policy.h", - "src/core/ext/client_config/lb_policy_factory.h", - "src/core/ext/client_config/lb_policy_registry.h", - "src/core/ext/client_config/parse_address.h", - "src/core/ext/client_config/resolver.h", - "src/core/ext/client_config/resolver_factory.h", - "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.h", - "src/core/ext/client_config/subchannel.h", - "src/core/ext/client_config/subchannel_index.h", - "src/core/ext/client_config/uri_parser.h", + "src/core/ext/client_channel/client_channel.h", + "src/core/ext/client_channel/client_channel_factory.h", + "src/core/ext/client_channel/connector.h", + "src/core/ext/client_channel/initial_connect_string.h", + "src/core/ext/client_channel/lb_policy.h", + "src/core/ext/client_channel/lb_policy_factory.h", + "src/core/ext/client_channel/lb_policy_registry.h", + "src/core/ext/client_channel/parse_address.h", + "src/core/ext/client_channel/resolver.h", + "src/core/ext/client_channel/resolver_factory.h", + "src/core/ext/client_channel/resolver_registry.h", + "src/core/ext/client_channel/resolver_result.h", + "src/core/ext/client_channel/subchannel.h", + "src/core/ext/client_channel/subchannel_index.h", + "src/core/ext/client_channel/uri_parser.h", "src/core/ext/lb_policy/grpclb/grpclb.h", "src/core/ext/lb_policy/grpclb/load_balancer_api.h", "src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 05aa323ca9..0dec427bb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -433,24 +433,24 @@ add_library(grpc src/core/lib/tsi/ssl_transport_security.c src/core/lib/tsi/transport_security.c src/core/ext/transport/chttp2/client/secure/secure_channel_create.c - src/core/ext/client_config/channel_connectivity.c - src/core/ext/client_config/client_channel.c - src/core/ext/client_config/client_channel_factory.c - src/core/ext/client_config/client_config_plugin.c - src/core/ext/client_config/connector.c - src/core/ext/client_config/default_initial_connect_string.c - src/core/ext/client_config/initial_connect_string.c - src/core/ext/client_config/lb_policy.c - src/core/ext/client_config/lb_policy_factory.c - src/core/ext/client_config/lb_policy_registry.c - src/core/ext/client_config/parse_address.c - src/core/ext/client_config/resolver.c - src/core/ext/client_config/resolver_factory.c - src/core/ext/client_config/resolver_registry.c - src/core/ext/client_config/resolver_result.c - src/core/ext/client_config/subchannel.c - src/core/ext/client_config/subchannel_index.c - src/core/ext/client_config/uri_parser.c + src/core/ext/client_channel/channel_connectivity.c + src/core/ext/client_channel/client_channel.c + src/core/ext/client_channel/client_channel_factory.c + src/core/ext/client_channel/client_channel_plugin.c + src/core/ext/client_channel/connector.c + src/core/ext/client_channel/default_initial_connect_string.c + src/core/ext/client_channel/initial_connect_string.c + src/core/ext/client_channel/lb_policy.c + src/core/ext/client_channel/lb_policy_factory.c + src/core/ext/client_channel/lb_policy_registry.c + src/core/ext/client_channel/parse_address.c + src/core/ext/client_channel/resolver.c + src/core/ext/client_channel/resolver_factory.c + src/core/ext/client_channel/resolver_registry.c + src/core/ext/client_channel/resolver_result.c + src/core/ext/client_channel/subchannel.c + src/core/ext/client_channel/subchannel_index.c + src/core/ext/client_channel/uri_parser.c src/core/ext/transport/chttp2/server/insecure/server_chttp2.c src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c src/core/ext/transport/chttp2/client/insecure/channel_create.c @@ -665,24 +665,24 @@ add_library(grpc_cronet src/core/ext/transport/chttp2/transport/varint.c src/core/ext/transport/chttp2/transport/writing.c src/core/ext/transport/chttp2/alpn/alpn.c - src/core/ext/client_config/channel_connectivity.c - src/core/ext/client_config/client_channel.c - src/core/ext/client_config/client_channel_factory.c - src/core/ext/client_config/client_config_plugin.c - src/core/ext/client_config/connector.c - src/core/ext/client_config/default_initial_connect_string.c - src/core/ext/client_config/initial_connect_string.c - src/core/ext/client_config/lb_policy.c - src/core/ext/client_config/lb_policy_factory.c - src/core/ext/client_config/lb_policy_registry.c - src/core/ext/client_config/parse_address.c - src/core/ext/client_config/resolver.c - src/core/ext/client_config/resolver_factory.c - src/core/ext/client_config/resolver_registry.c - src/core/ext/client_config/resolver_result.c - src/core/ext/client_config/subchannel.c - src/core/ext/client_config/subchannel_index.c - src/core/ext/client_config/uri_parser.c + src/core/ext/client_channel/channel_connectivity.c + src/core/ext/client_channel/client_channel.c + src/core/ext/client_channel/client_channel_factory.c + src/core/ext/client_channel/client_channel_plugin.c + src/core/ext/client_channel/connector.c + src/core/ext/client_channel/default_initial_connect_string.c + src/core/ext/client_channel/initial_connect_string.c + src/core/ext/client_channel/lb_policy.c + src/core/ext/client_channel/lb_policy_factory.c + src/core/ext/client_channel/lb_policy_registry.c + src/core/ext/client_channel/parse_address.c + src/core/ext/client_channel/resolver.c + src/core/ext/client_channel/resolver_factory.c + src/core/ext/client_channel/resolver_registry.c + src/core/ext/client_channel/resolver_result.c + src/core/ext/client_channel/subchannel.c + src/core/ext/client_channel/subchannel_index.c + src/core/ext/client_channel/uri_parser.c src/core/lib/http/httpcli_security_connector.c src/core/lib/security/context/security_context.c src/core/lib/security/credentials/composite/composite_credentials.c @@ -896,24 +896,24 @@ add_library(grpc_unsecure src/core/ext/transport/chttp2/alpn/alpn.c src/core/ext/transport/chttp2/client/insecure/channel_create.c src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c - src/core/ext/client_config/channel_connectivity.c - src/core/ext/client_config/client_channel.c - src/core/ext/client_config/client_channel_factory.c - src/core/ext/client_config/client_config_plugin.c - src/core/ext/client_config/connector.c - src/core/ext/client_config/default_initial_connect_string.c - src/core/ext/client_config/initial_connect_string.c - src/core/ext/client_config/lb_policy.c - src/core/ext/client_config/lb_policy_factory.c - src/core/ext/client_config/lb_policy_registry.c - src/core/ext/client_config/parse_address.c - src/core/ext/client_config/resolver.c - src/core/ext/client_config/resolver_factory.c - src/core/ext/client_config/resolver_registry.c - src/core/ext/client_config/resolver_result.c - src/core/ext/client_config/subchannel.c - src/core/ext/client_config/subchannel_index.c - src/core/ext/client_config/uri_parser.c + src/core/ext/client_channel/channel_connectivity.c + src/core/ext/client_channel/client_channel.c + src/core/ext/client_channel/client_channel_factory.c + src/core/ext/client_channel/client_channel_plugin.c + src/core/ext/client_channel/connector.c + src/core/ext/client_channel/default_initial_connect_string.c + src/core/ext/client_channel/initial_connect_string.c + src/core/ext/client_channel/lb_policy.c + src/core/ext/client_channel/lb_policy_factory.c + src/core/ext/client_channel/lb_policy_registry.c + src/core/ext/client_channel/parse_address.c + src/core/ext/client_channel/resolver.c + src/core/ext/client_channel/resolver_factory.c + src/core/ext/client_channel/resolver_registry.c + src/core/ext/client_channel/resolver_result.c + src/core/ext/client_channel/subchannel.c + src/core/ext/client_channel/subchannel_index.c + src/core/ext/client_channel/uri_parser.c src/core/ext/resolver/dns/native/dns_resolver.c src/core/ext/resolver/sockaddr/sockaddr_resolver.c src/core/ext/load_reporting/load_reporting.c diff --git a/Makefile b/Makefile index e454ad6cd7..420a0552d5 100644 --- a/Makefile +++ b/Makefile @@ -2654,24 +2654,24 @@ LIBGRPC_SRC = \ src/core/lib/tsi/ssl_transport_security.c \ src/core/lib/tsi/transport_security.c \ src/core/ext/transport/chttp2/client/secure/secure_channel_create.c \ - src/core/ext/client_config/channel_connectivity.c \ - src/core/ext/client_config/client_channel.c \ - src/core/ext/client_config/client_channel_factory.c \ - src/core/ext/client_config/client_config_plugin.c \ - src/core/ext/client_config/connector.c \ - src/core/ext/client_config/default_initial_connect_string.c \ - src/core/ext/client_config/initial_connect_string.c \ - src/core/ext/client_config/lb_policy.c \ - src/core/ext/client_config/lb_policy_factory.c \ - src/core/ext/client_config/lb_policy_registry.c \ - src/core/ext/client_config/parse_address.c \ - src/core/ext/client_config/resolver.c \ - src/core/ext/client_config/resolver_factory.c \ - src/core/ext/client_config/resolver_registry.c \ - src/core/ext/client_config/resolver_result.c \ - src/core/ext/client_config/subchannel.c \ - src/core/ext/client_config/subchannel_index.c \ - src/core/ext/client_config/uri_parser.c \ + src/core/ext/client_channel/channel_connectivity.c \ + src/core/ext/client_channel/client_channel.c \ + src/core/ext/client_channel/client_channel_factory.c \ + src/core/ext/client_channel/client_channel_plugin.c \ + src/core/ext/client_channel/connector.c \ + src/core/ext/client_channel/default_initial_connect_string.c \ + src/core/ext/client_channel/initial_connect_string.c \ + src/core/ext/client_channel/lb_policy.c \ + src/core/ext/client_channel/lb_policy_factory.c \ + src/core/ext/client_channel/lb_policy_registry.c \ + src/core/ext/client_channel/parse_address.c \ + src/core/ext/client_channel/resolver.c \ + src/core/ext/client_channel/resolver_factory.c \ + src/core/ext/client_channel/resolver_registry.c \ + src/core/ext/client_channel/resolver_result.c \ + src/core/ext/client_channel/subchannel.c \ + src/core/ext/client_channel/subchannel_index.c \ + src/core/ext/client_channel/uri_parser.c \ src/core/ext/transport/chttp2/server/insecure/server_chttp2.c \ src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c \ src/core/ext/transport/chttp2/client/insecure/channel_create.c \ @@ -2904,24 +2904,24 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/transport/chttp2/transport/varint.c \ src/core/ext/transport/chttp2/transport/writing.c \ src/core/ext/transport/chttp2/alpn/alpn.c \ - src/core/ext/client_config/channel_connectivity.c \ - src/core/ext/client_config/client_channel.c \ - src/core/ext/client_config/client_channel_factory.c \ - src/core/ext/client_config/client_config_plugin.c \ - src/core/ext/client_config/connector.c \ - src/core/ext/client_config/default_initial_connect_string.c \ - src/core/ext/client_config/initial_connect_string.c \ - src/core/ext/client_config/lb_policy.c \ - src/core/ext/client_config/lb_policy_factory.c \ - src/core/ext/client_config/lb_policy_registry.c \ - src/core/ext/client_config/parse_address.c \ - src/core/ext/client_config/resolver.c \ - src/core/ext/client_config/resolver_factory.c \ - src/core/ext/client_config/resolver_registry.c \ - src/core/ext/client_config/resolver_result.c \ - src/core/ext/client_config/subchannel.c \ - src/core/ext/client_config/subchannel_index.c \ - src/core/ext/client_config/uri_parser.c \ + src/core/ext/client_channel/channel_connectivity.c \ + src/core/ext/client_channel/client_channel.c \ + src/core/ext/client_channel/client_channel_factory.c \ + src/core/ext/client_channel/client_channel_plugin.c \ + src/core/ext/client_channel/connector.c \ + src/core/ext/client_channel/default_initial_connect_string.c \ + src/core/ext/client_channel/initial_connect_string.c \ + src/core/ext/client_channel/lb_policy.c \ + src/core/ext/client_channel/lb_policy_factory.c \ + src/core/ext/client_channel/lb_policy_registry.c \ + src/core/ext/client_channel/parse_address.c \ + src/core/ext/client_channel/resolver.c \ + src/core/ext/client_channel/resolver_factory.c \ + src/core/ext/client_channel/resolver_registry.c \ + src/core/ext/client_channel/resolver_result.c \ + src/core/ext/client_channel/subchannel.c \ + src/core/ext/client_channel/subchannel_index.c \ + src/core/ext/client_channel/uri_parser.c \ src/core/lib/http/httpcli_security_connector.c \ src/core/lib/security/context/security_context.c \ src/core/lib/security/credentials/composite/composite_credentials.c \ @@ -3362,24 +3362,24 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/transport/chttp2/alpn/alpn.c \ src/core/ext/transport/chttp2/client/insecure/channel_create.c \ src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c \ - src/core/ext/client_config/channel_connectivity.c \ - src/core/ext/client_config/client_channel.c \ - src/core/ext/client_config/client_channel_factory.c \ - src/core/ext/client_config/client_config_plugin.c \ - src/core/ext/client_config/connector.c \ - src/core/ext/client_config/default_initial_connect_string.c \ - src/core/ext/client_config/initial_connect_string.c \ - src/core/ext/client_config/lb_policy.c \ - src/core/ext/client_config/lb_policy_factory.c \ - src/core/ext/client_config/lb_policy_registry.c \ - src/core/ext/client_config/parse_address.c \ - src/core/ext/client_config/resolver.c \ - src/core/ext/client_config/resolver_factory.c \ - src/core/ext/client_config/resolver_registry.c \ - src/core/ext/client_config/resolver_result.c \ - src/core/ext/client_config/subchannel.c \ - src/core/ext/client_config/subchannel_index.c \ - src/core/ext/client_config/uri_parser.c \ + src/core/ext/client_channel/channel_connectivity.c \ + src/core/ext/client_channel/client_channel.c \ + src/core/ext/client_channel/client_channel_factory.c \ + src/core/ext/client_channel/client_channel_plugin.c \ + src/core/ext/client_channel/connector.c \ + src/core/ext/client_channel/default_initial_connect_string.c \ + src/core/ext/client_channel/initial_connect_string.c \ + src/core/ext/client_channel/lb_policy.c \ + src/core/ext/client_channel/lb_policy_factory.c \ + src/core/ext/client_channel/lb_policy_registry.c \ + src/core/ext/client_channel/parse_address.c \ + src/core/ext/client_channel/resolver.c \ + src/core/ext/client_channel/resolver_factory.c \ + src/core/ext/client_channel/resolver_registry.c \ + src/core/ext/client_channel/resolver_result.c \ + src/core/ext/client_channel/subchannel.c \ + src/core/ext/client_channel/subchannel_index.c \ + src/core/ext/client_channel/uri_parser.c \ src/core/ext/resolver/dns/native/dns_resolver.c \ src/core/ext/resolver/sockaddr/sockaddr_resolver.c \ src/core/ext/load_reporting/load_reporting.c \ @@ -7478,7 +7478,7 @@ endif DNS_RESOLVER_CONNECTIVITY_TEST_SRC = \ - test/core/client_config/resolvers/dns_resolver_connectivity_test.c \ + test/core/client_channel/resolvers/dns_resolver_connectivity_test.c \ DNS_RESOLVER_CONNECTIVITY_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(DNS_RESOLVER_CONNECTIVITY_TEST_SRC)))) ifeq ($(NO_SECURE),true) @@ -7498,7 +7498,7 @@ $(BINDIR)/$(CONFIG)/dns_resolver_connectivity_test: $(DNS_RESOLVER_CONNECTIVITY_ endif -$(OBJDIR)/$(CONFIG)/test/core/client_config/resolvers/dns_resolver_connectivity_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/client_channel/resolvers/dns_resolver_connectivity_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_dns_resolver_connectivity_test: $(DNS_RESOLVER_CONNECTIVITY_TEST_OBJS:.o=.dep) @@ -7510,7 +7510,7 @@ endif DNS_RESOLVER_TEST_SRC = \ - test/core/client_config/resolvers/dns_resolver_test.c \ + test/core/client_channel/resolvers/dns_resolver_test.c \ DNS_RESOLVER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(DNS_RESOLVER_TEST_SRC)))) ifeq ($(NO_SECURE),true) @@ -7530,7 +7530,7 @@ $(BINDIR)/$(CONFIG)/dns_resolver_test: $(DNS_RESOLVER_TEST_OBJS) $(LIBDIR)/$(CON endif -$(OBJDIR)/$(CONFIG)/test/core/client_config/resolvers/dns_resolver_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/client_channel/resolvers/dns_resolver_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_dns_resolver_test: $(DNS_RESOLVER_TEST_OBJS:.o=.dep) @@ -9654,7 +9654,7 @@ endif LB_POLICIES_TEST_SRC = \ - test/core/client_config/lb_policies_test.c \ + test/core/client_channel/lb_policies_test.c \ LB_POLICIES_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LB_POLICIES_TEST_SRC)))) ifeq ($(NO_SECURE),true) @@ -9674,7 +9674,7 @@ $(BINDIR)/$(CONFIG)/lb_policies_test: $(LB_POLICIES_TEST_OBJS) $(LIBDIR)/$(CONFI endif -$(OBJDIR)/$(CONFIG)/test/core/client_config/lb_policies_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/client_channel/lb_policies_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_lb_policies_test: $(LB_POLICIES_TEST_OBJS:.o=.dep) @@ -10262,7 +10262,7 @@ endif SET_INITIAL_CONNECT_STRING_TEST_SRC = \ - test/core/client_config/set_initial_connect_string_test.c \ + test/core/client_channel/set_initial_connect_string_test.c \ SET_INITIAL_CONNECT_STRING_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(SET_INITIAL_CONNECT_STRING_TEST_SRC)))) ifeq ($(NO_SECURE),true) @@ -10282,7 +10282,7 @@ $(BINDIR)/$(CONFIG)/set_initial_connect_string_test: $(SET_INITIAL_CONNECT_STRIN endif -$(OBJDIR)/$(CONFIG)/test/core/client_config/set_initial_connect_string_test.o: $(LIBDIR)/$(CONFIG)/libtest_tcp_server.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/client_channel/set_initial_connect_string_test.o: $(LIBDIR)/$(CONFIG)/libtest_tcp_server.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_set_initial_connect_string_test: $(SET_INITIAL_CONNECT_STRING_TEST_OBJS:.o=.dep) @@ -10294,7 +10294,7 @@ endif SOCKADDR_RESOLVER_TEST_SRC = \ - test/core/client_config/resolvers/sockaddr_resolver_test.c \ + test/core/client_channel/resolvers/sockaddr_resolver_test.c \ SOCKADDR_RESOLVER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(SOCKADDR_RESOLVER_TEST_SRC)))) ifeq ($(NO_SECURE),true) @@ -10314,7 +10314,7 @@ $(BINDIR)/$(CONFIG)/sockaddr_resolver_test: $(SOCKADDR_RESOLVER_TEST_OBJS) $(LIB endif -$(OBJDIR)/$(CONFIG)/test/core/client_config/resolvers/sockaddr_resolver_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/client_channel/resolvers/sockaddr_resolver_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_sockaddr_resolver_test: $(SOCKADDR_RESOLVER_TEST_OBJS:.o=.dep) @@ -10742,7 +10742,7 @@ endif URI_FUZZER_TEST_SRC = \ - test/core/client_config/uri_fuzzer_test.c \ + test/core/client_channel/uri_fuzzer_test.c \ URI_FUZZER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(URI_FUZZER_TEST_SRC)))) ifeq ($(NO_SECURE),true) @@ -10762,7 +10762,7 @@ $(BINDIR)/$(CONFIG)/uri_fuzzer_test: $(URI_FUZZER_TEST_OBJS) $(LIBDIR)/$(CONFIG) endif -$(OBJDIR)/$(CONFIG)/test/core/client_config/uri_fuzzer_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/client_channel/uri_fuzzer_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_uri_fuzzer_test: $(URI_FUZZER_TEST_OBJS:.o=.dep) @@ -10774,7 +10774,7 @@ endif URI_PARSER_TEST_SRC = \ - test/core/client_config/uri_parser_test.c \ + test/core/client_channel/uri_parser_test.c \ URI_PARSER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(URI_PARSER_TEST_SRC)))) ifeq ($(NO_SECURE),true) @@ -10794,7 +10794,7 @@ $(BINDIR)/$(CONFIG)/uri_parser_test: $(URI_PARSER_TEST_OBJS) $(LIBDIR)/$(CONFIG) endif -$(OBJDIR)/$(CONFIG)/test/core/client_config/uri_parser_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/client_channel/uri_parser_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_uri_parser_test: $(URI_PARSER_TEST_OBJS:.o=.dep) @@ -15552,7 +15552,7 @@ endif URI_FUZZER_TEST_ONE_ENTRY_SRC = \ - test/core/client_config/uri_fuzzer_test.c \ + test/core/client_channel/uri_fuzzer_test.c \ test/core/util/one_corpus_entry_fuzzer.c \ URI_FUZZER_TEST_ONE_ENTRY_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(URI_FUZZER_TEST_ONE_ENTRY_SRC)))) @@ -15573,7 +15573,7 @@ $(BINDIR)/$(CONFIG)/uri_fuzzer_test_one_entry: $(URI_FUZZER_TEST_ONE_ENTRY_OBJS) endif -$(OBJDIR)/$(CONFIG)/test/core/client_config/uri_fuzzer_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/core/client_channel/uri_fuzzer_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(OBJDIR)/$(CONFIG)/test/core/util/one_corpus_entry_fuzzer.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a diff --git a/binding.gyp b/binding.gyp index 7cc8a58c01..41a97bbf59 100644 --- a/binding.gyp +++ b/binding.gyp @@ -705,24 +705,24 @@ 'src/core/lib/tsi/ssl_transport_security.c', 'src/core/lib/tsi/transport_security.c', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.c', - 'src/core/ext/client_config/channel_connectivity.c', - 'src/core/ext/client_config/client_channel.c', - 'src/core/ext/client_config/client_channel_factory.c', - 'src/core/ext/client_config/client_config_plugin.c', - 'src/core/ext/client_config/connector.c', - 'src/core/ext/client_config/default_initial_connect_string.c', - 'src/core/ext/client_config/initial_connect_string.c', - 'src/core/ext/client_config/lb_policy.c', - 'src/core/ext/client_config/lb_policy_factory.c', - 'src/core/ext/client_config/lb_policy_registry.c', - 'src/core/ext/client_config/parse_address.c', - 'src/core/ext/client_config/resolver.c', - 'src/core/ext/client_config/resolver_factory.c', - 'src/core/ext/client_config/resolver_registry.c', - 'src/core/ext/client_config/resolver_result.c', - 'src/core/ext/client_config/subchannel.c', - 'src/core/ext/client_config/subchannel_index.c', - 'src/core/ext/client_config/uri_parser.c', + 'src/core/ext/client_channel/channel_connectivity.c', + 'src/core/ext/client_channel/client_channel.c', + 'src/core/ext/client_channel/client_channel_factory.c', + 'src/core/ext/client_channel/client_channel_plugin.c', + 'src/core/ext/client_channel/connector.c', + 'src/core/ext/client_channel/default_initial_connect_string.c', + 'src/core/ext/client_channel/initial_connect_string.c', + 'src/core/ext/client_channel/lb_policy.c', + 'src/core/ext/client_channel/lb_policy_factory.c', + 'src/core/ext/client_channel/lb_policy_registry.c', + 'src/core/ext/client_channel/parse_address.c', + 'src/core/ext/client_channel/resolver.c', + 'src/core/ext/client_channel/resolver_factory.c', + 'src/core/ext/client_channel/resolver_registry.c', + 'src/core/ext/client_channel/resolver_result.c', + 'src/core/ext/client_channel/subchannel.c', + 'src/core/ext/client_channel/subchannel_index.c', + 'src/core/ext/client_channel/uri_parser.c', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.c', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c', 'src/core/ext/transport/chttp2/client/insecure/channel_create.c', diff --git a/build.yaml b/build.yaml index 6eb23d6fb7..9b951346c9 100644 --- a/build.yaml +++ b/build.yaml @@ -339,43 +339,43 @@ filegroups: - gpr uses: - grpc_codegen -- name: grpc_client_config +- name: grpc_client_channel headers: - - src/core/ext/client_config/client_channel.h - - src/core/ext/client_config/client_channel_factory.h - - src/core/ext/client_config/connector.h - - src/core/ext/client_config/initial_connect_string.h - - src/core/ext/client_config/lb_policy.h - - src/core/ext/client_config/lb_policy_factory.h - - src/core/ext/client_config/lb_policy_registry.h - - src/core/ext/client_config/parse_address.h - - src/core/ext/client_config/resolver.h - - src/core/ext/client_config/resolver_factory.h - - src/core/ext/client_config/resolver_registry.h - - src/core/ext/client_config/resolver_result.h - - src/core/ext/client_config/subchannel.h - - src/core/ext/client_config/subchannel_index.h - - src/core/ext/client_config/uri_parser.h - src: - - src/core/ext/client_config/channel_connectivity.c - - src/core/ext/client_config/client_channel.c - - src/core/ext/client_config/client_channel_factory.c - - src/core/ext/client_config/client_config_plugin.c - - src/core/ext/client_config/connector.c - - src/core/ext/client_config/default_initial_connect_string.c - - src/core/ext/client_config/initial_connect_string.c - - src/core/ext/client_config/lb_policy.c - - src/core/ext/client_config/lb_policy_factory.c - - src/core/ext/client_config/lb_policy_registry.c - - src/core/ext/client_config/parse_address.c - - src/core/ext/client_config/resolver.c - - src/core/ext/client_config/resolver_factory.c - - src/core/ext/client_config/resolver_registry.c - - src/core/ext/client_config/resolver_result.c - - src/core/ext/client_config/subchannel.c - - src/core/ext/client_config/subchannel_index.c - - src/core/ext/client_config/uri_parser.c - plugin: grpc_client_config + - src/core/ext/client_channel/client_channel.h + - src/core/ext/client_channel/client_channel_factory.h + - src/core/ext/client_channel/connector.h + - src/core/ext/client_channel/initial_connect_string.h + - src/core/ext/client_channel/lb_policy.h + - src/core/ext/client_channel/lb_policy_factory.h + - src/core/ext/client_channel/lb_policy_registry.h + - src/core/ext/client_channel/parse_address.h + - src/core/ext/client_channel/resolver.h + - src/core/ext/client_channel/resolver_factory.h + - src/core/ext/client_channel/resolver_registry.h + - src/core/ext/client_channel/resolver_result.h + - src/core/ext/client_channel/subchannel.h + - src/core/ext/client_channel/subchannel_index.h + - src/core/ext/client_channel/uri_parser.h + src: + - src/core/ext/client_channel/channel_connectivity.c + - src/core/ext/client_channel/client_channel.c + - src/core/ext/client_channel/client_channel_factory.c + - src/core/ext/client_channel/client_channel_plugin.c + - src/core/ext/client_channel/connector.c + - src/core/ext/client_channel/default_initial_connect_string.c + - src/core/ext/client_channel/initial_connect_string.c + - src/core/ext/client_channel/lb_policy.c + - src/core/ext/client_channel/lb_policy_factory.c + - src/core/ext/client_channel/lb_policy_registry.c + - src/core/ext/client_channel/parse_address.c + - src/core/ext/client_channel/resolver.c + - src/core/ext/client_channel/resolver_factory.c + - src/core/ext/client_channel/resolver_registry.c + - src/core/ext/client_channel/resolver_result.c + - src/core/ext/client_channel/subchannel.c + - src/core/ext/client_channel/subchannel_index.c + - src/core/ext/client_channel/uri_parser.c + plugin: grpc_client_channel uses: - grpc_base - name: grpc_codegen @@ -401,7 +401,7 @@ filegroups: plugin: grpc_lb_policy_grpclb uses: - grpc_base - - grpc_client_config + - grpc_client_channel - nanopb - name: grpc_lb_policy_pick_first src: @@ -409,14 +409,14 @@ filegroups: plugin: grpc_lb_policy_pick_first uses: - grpc_base - - grpc_client_config + - grpc_client_channel - name: grpc_lb_policy_round_robin src: - src/core/ext/lb_policy/round_robin/round_robin.c plugin: grpc_lb_policy_round_robin uses: - grpc_base - - grpc_client_config + - grpc_client_channel - name: grpc_load_reporting headers: - src/core/ext/load_reporting/load_reporting.h @@ -433,14 +433,14 @@ filegroups: plugin: grpc_resolver_dns_native uses: - grpc_base - - grpc_client_config + - grpc_client_channel - name: grpc_resolver_sockaddr src: - src/core/ext/resolver/sockaddr/sockaddr_resolver.c plugin: grpc_resolver_sockaddr uses: - grpc_base - - grpc_client_config + - grpc_client_channel - name: grpc_secure public_headers: - include/grpc/grpc_security.h @@ -587,14 +587,14 @@ filegroups: uses: - grpc_transport_chttp2 - grpc_base - - grpc_client_config + - grpc_client_channel - name: grpc_transport_chttp2_client_secure src: - src/core/ext/transport/chttp2/client/secure/secure_channel_create.c uses: - grpc_transport_chttp2 - grpc_base - - grpc_client_config + - grpc_client_channel - grpc_secure - name: grpc_transport_chttp2_server_insecure src: @@ -1433,7 +1433,7 @@ targets: build: test language: c src: - - test/core/client_config/resolvers/dns_resolver_connectivity_test.c + - test/core/client_channel/resolvers/dns_resolver_connectivity_test.c deps: - grpc_test_util - grpc @@ -1443,7 +1443,7 @@ targets: build: test language: c src: - - test/core/client_config/resolvers/dns_resolver_test.c + - test/core/client_channel/resolvers/dns_resolver_test.c deps: - grpc_test_util - grpc @@ -2128,7 +2128,7 @@ targets: build: test language: c src: - - test/core/client_config/lb_policies_test.c + - test/core/client_channel/lb_policies_test.c deps: - grpc_test_util - grpc @@ -2339,7 +2339,7 @@ targets: build: test language: c src: - - test/core/client_config/set_initial_connect_string_test.c + - test/core/client_channel/set_initial_connect_string_test.c deps: - test_tcp_server - grpc_test_util @@ -2350,7 +2350,7 @@ targets: build: test language: c src: - - test/core/client_config/resolvers/sockaddr_resolver_test.c + - test/core/client_channel/resolvers/sockaddr_resolver_test.c deps: - grpc_test_util - grpc @@ -2516,20 +2516,20 @@ targets: build: fuzzer language: c src: - - test/core/client_config/uri_fuzzer_test.c + - test/core/client_channel/uri_fuzzer_test.c deps: - grpc_test_util - grpc - gpr_test_util - gpr corpus_dirs: - - test/core/client_config/uri_corpus + - test/core/client_channel/uri_corpus maxlen: 128 - name: uri_parser_test build: test language: c src: - - test/core/client_config/uri_parser_test.c + - test/core/client_channel/uri_parser_test.c deps: - grpc_test_util - grpc diff --git a/config.m4 b/config.m4 index 5384585dd6..ce27f8aeab 100644 --- a/config.m4 +++ b/config.m4 @@ -224,24 +224,24 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/tsi/ssl_transport_security.c \ src/core/lib/tsi/transport_security.c \ src/core/ext/transport/chttp2/client/secure/secure_channel_create.c \ - src/core/ext/client_config/channel_connectivity.c \ - src/core/ext/client_config/client_channel.c \ - src/core/ext/client_config/client_channel_factory.c \ - src/core/ext/client_config/client_config_plugin.c \ - src/core/ext/client_config/connector.c \ - src/core/ext/client_config/default_initial_connect_string.c \ - src/core/ext/client_config/initial_connect_string.c \ - src/core/ext/client_config/lb_policy.c \ - src/core/ext/client_config/lb_policy_factory.c \ - src/core/ext/client_config/lb_policy_registry.c \ - src/core/ext/client_config/parse_address.c \ - src/core/ext/client_config/resolver.c \ - src/core/ext/client_config/resolver_factory.c \ - src/core/ext/client_config/resolver_registry.c \ - src/core/ext/client_config/resolver_result.c \ - src/core/ext/client_config/subchannel.c \ - src/core/ext/client_config/subchannel_index.c \ - src/core/ext/client_config/uri_parser.c \ + src/core/ext/client_channel/channel_connectivity.c \ + src/core/ext/client_channel/client_channel.c \ + src/core/ext/client_channel/client_channel_factory.c \ + src/core/ext/client_channel/client_channel_plugin.c \ + src/core/ext/client_channel/connector.c \ + src/core/ext/client_channel/default_initial_connect_string.c \ + src/core/ext/client_channel/initial_connect_string.c \ + src/core/ext/client_channel/lb_policy.c \ + src/core/ext/client_channel/lb_policy_factory.c \ + src/core/ext/client_channel/lb_policy_registry.c \ + src/core/ext/client_channel/parse_address.c \ + src/core/ext/client_channel/resolver.c \ + src/core/ext/client_channel/resolver_factory.c \ + src/core/ext/client_channel/resolver_registry.c \ + src/core/ext/client_channel/resolver_result.c \ + src/core/ext/client_channel/subchannel.c \ + src/core/ext/client_channel/subchannel_index.c \ + src/core/ext/client_channel/uri_parser.c \ src/core/ext/transport/chttp2/server/insecure/server_chttp2.c \ src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c \ src/core/ext/transport/chttp2/client/insecure/channel_create.c \ @@ -579,7 +579,7 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/src/boringssl) PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/census) PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/census/gen) - PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/client_config) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/client_channel) PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/lb_policy/grpclb) PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1) PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/lb_policy/pick_first) diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index deffa1653e..8b8fe236ac 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -379,21 +379,21 @@ Pod::Spec.new do |s| 'src/core/lib/tsi/ssl_types.h', 'src/core/lib/tsi/transport_security.h', 'src/core/lib/tsi/transport_security_interface.h', - 'src/core/ext/client_config/client_channel.h', - 'src/core/ext/client_config/client_channel_factory.h', - 'src/core/ext/client_config/connector.h', - 'src/core/ext/client_config/initial_connect_string.h', - 'src/core/ext/client_config/lb_policy.h', - 'src/core/ext/client_config/lb_policy_factory.h', - 'src/core/ext/client_config/lb_policy_registry.h', - 'src/core/ext/client_config/parse_address.h', - 'src/core/ext/client_config/resolver.h', - 'src/core/ext/client_config/resolver_factory.h', - 'src/core/ext/client_config/resolver_registry.h', - 'src/core/ext/client_config/resolver_result.h', - 'src/core/ext/client_config/subchannel.h', - 'src/core/ext/client_config/subchannel_index.h', - 'src/core/ext/client_config/uri_parser.h', + 'src/core/ext/client_channel/client_channel.h', + 'src/core/ext/client_channel/client_channel_factory.h', + 'src/core/ext/client_channel/connector.h', + 'src/core/ext/client_channel/initial_connect_string.h', + 'src/core/ext/client_channel/lb_policy.h', + 'src/core/ext/client_channel/lb_policy_factory.h', + 'src/core/ext/client_channel/lb_policy_registry.h', + 'src/core/ext/client_channel/parse_address.h', + 'src/core/ext/client_channel/resolver.h', + 'src/core/ext/client_channel/resolver_factory.h', + 'src/core/ext/client_channel/resolver_registry.h', + 'src/core/ext/client_channel/resolver_result.h', + 'src/core/ext/client_channel/subchannel.h', + 'src/core/ext/client_channel/subchannel_index.h', + 'src/core/ext/client_channel/uri_parser.h', 'src/core/ext/lb_policy/grpclb/grpclb.h', 'src/core/ext/lb_policy/grpclb/load_balancer_api.h', 'src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', @@ -555,24 +555,24 @@ Pod::Spec.new do |s| 'src/core/lib/tsi/ssl_transport_security.c', 'src/core/lib/tsi/transport_security.c', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.c', - 'src/core/ext/client_config/channel_connectivity.c', - 'src/core/ext/client_config/client_channel.c', - 'src/core/ext/client_config/client_channel_factory.c', - 'src/core/ext/client_config/client_config_plugin.c', - 'src/core/ext/client_config/connector.c', - 'src/core/ext/client_config/default_initial_connect_string.c', - 'src/core/ext/client_config/initial_connect_string.c', - 'src/core/ext/client_config/lb_policy.c', - 'src/core/ext/client_config/lb_policy_factory.c', - 'src/core/ext/client_config/lb_policy_registry.c', - 'src/core/ext/client_config/parse_address.c', - 'src/core/ext/client_config/resolver.c', - 'src/core/ext/client_config/resolver_factory.c', - 'src/core/ext/client_config/resolver_registry.c', - 'src/core/ext/client_config/resolver_result.c', - 'src/core/ext/client_config/subchannel.c', - 'src/core/ext/client_config/subchannel_index.c', - 'src/core/ext/client_config/uri_parser.c', + 'src/core/ext/client_channel/channel_connectivity.c', + 'src/core/ext/client_channel/client_channel.c', + 'src/core/ext/client_channel/client_channel_factory.c', + 'src/core/ext/client_channel/client_channel_plugin.c', + 'src/core/ext/client_channel/connector.c', + 'src/core/ext/client_channel/default_initial_connect_string.c', + 'src/core/ext/client_channel/initial_connect_string.c', + 'src/core/ext/client_channel/lb_policy.c', + 'src/core/ext/client_channel/lb_policy_factory.c', + 'src/core/ext/client_channel/lb_policy_registry.c', + 'src/core/ext/client_channel/parse_address.c', + 'src/core/ext/client_channel/resolver.c', + 'src/core/ext/client_channel/resolver_factory.c', + 'src/core/ext/client_channel/resolver_registry.c', + 'src/core/ext/client_channel/resolver_result.c', + 'src/core/ext/client_channel/subchannel.c', + 'src/core/ext/client_channel/subchannel_index.c', + 'src/core/ext/client_channel/uri_parser.c', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.c', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c', 'src/core/ext/transport/chttp2/client/insecure/channel_create.c', @@ -741,21 +741,21 @@ Pod::Spec.new do |s| 'src/core/lib/tsi/ssl_types.h', 'src/core/lib/tsi/transport_security.h', 'src/core/lib/tsi/transport_security_interface.h', - 'src/core/ext/client_config/client_channel.h', - 'src/core/ext/client_config/client_channel_factory.h', - 'src/core/ext/client_config/connector.h', - 'src/core/ext/client_config/initial_connect_string.h', - 'src/core/ext/client_config/lb_policy.h', - 'src/core/ext/client_config/lb_policy_factory.h', - 'src/core/ext/client_config/lb_policy_registry.h', - 'src/core/ext/client_config/parse_address.h', - 'src/core/ext/client_config/resolver.h', - 'src/core/ext/client_config/resolver_factory.h', - 'src/core/ext/client_config/resolver_registry.h', - 'src/core/ext/client_config/resolver_result.h', - 'src/core/ext/client_config/subchannel.h', - 'src/core/ext/client_config/subchannel_index.h', - 'src/core/ext/client_config/uri_parser.h', + 'src/core/ext/client_channel/client_channel.h', + 'src/core/ext/client_channel/client_channel_factory.h', + 'src/core/ext/client_channel/connector.h', + 'src/core/ext/client_channel/initial_connect_string.h', + 'src/core/ext/client_channel/lb_policy.h', + 'src/core/ext/client_channel/lb_policy_factory.h', + 'src/core/ext/client_channel/lb_policy_registry.h', + 'src/core/ext/client_channel/parse_address.h', + 'src/core/ext/client_channel/resolver.h', + 'src/core/ext/client_channel/resolver_factory.h', + 'src/core/ext/client_channel/resolver_registry.h', + 'src/core/ext/client_channel/resolver_result.h', + 'src/core/ext/client_channel/subchannel.h', + 'src/core/ext/client_channel/subchannel_index.h', + 'src/core/ext/client_channel/uri_parser.h', 'src/core/ext/lb_policy/grpclb/grpclb.h', 'src/core/ext/lb_policy/grpclb/load_balancer_api.h', 'src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h', diff --git a/grpc.gemspec b/grpc.gemspec index f249006065..b327077244 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -299,21 +299,21 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/tsi/ssl_types.h ) s.files += %w( src/core/lib/tsi/transport_security.h ) s.files += %w( src/core/lib/tsi/transport_security_interface.h ) - s.files += %w( src/core/ext/client_config/client_channel.h ) - s.files += %w( src/core/ext/client_config/client_channel_factory.h ) - s.files += %w( src/core/ext/client_config/connector.h ) - s.files += %w( src/core/ext/client_config/initial_connect_string.h ) - s.files += %w( src/core/ext/client_config/lb_policy.h ) - s.files += %w( src/core/ext/client_config/lb_policy_factory.h ) - s.files += %w( src/core/ext/client_config/lb_policy_registry.h ) - s.files += %w( src/core/ext/client_config/parse_address.h ) - s.files += %w( src/core/ext/client_config/resolver.h ) - s.files += %w( src/core/ext/client_config/resolver_factory.h ) - s.files += %w( src/core/ext/client_config/resolver_registry.h ) - s.files += %w( src/core/ext/client_config/resolver_result.h ) - s.files += %w( src/core/ext/client_config/subchannel.h ) - s.files += %w( src/core/ext/client_config/subchannel_index.h ) - s.files += %w( src/core/ext/client_config/uri_parser.h ) + s.files += %w( src/core/ext/client_channel/client_channel.h ) + s.files += %w( src/core/ext/client_channel/client_channel_factory.h ) + s.files += %w( src/core/ext/client_channel/connector.h ) + s.files += %w( src/core/ext/client_channel/initial_connect_string.h ) + s.files += %w( src/core/ext/client_channel/lb_policy.h ) + s.files += %w( src/core/ext/client_channel/lb_policy_factory.h ) + s.files += %w( src/core/ext/client_channel/lb_policy_registry.h ) + s.files += %w( src/core/ext/client_channel/parse_address.h ) + s.files += %w( src/core/ext/client_channel/resolver.h ) + s.files += %w( src/core/ext/client_channel/resolver_factory.h ) + s.files += %w( src/core/ext/client_channel/resolver_registry.h ) + s.files += %w( src/core/ext/client_channel/resolver_result.h ) + s.files += %w( src/core/ext/client_channel/subchannel.h ) + s.files += %w( src/core/ext/client_channel/subchannel_index.h ) + s.files += %w( src/core/ext/client_channel/uri_parser.h ) s.files += %w( src/core/ext/lb_policy/grpclb/grpclb.h ) s.files += %w( src/core/ext/lb_policy/grpclb/load_balancer_api.h ) s.files += %w( src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h ) @@ -475,24 +475,24 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/tsi/ssl_transport_security.c ) s.files += %w( src/core/lib/tsi/transport_security.c ) s.files += %w( src/core/ext/transport/chttp2/client/secure/secure_channel_create.c ) - s.files += %w( src/core/ext/client_config/channel_connectivity.c ) - s.files += %w( src/core/ext/client_config/client_channel.c ) - s.files += %w( src/core/ext/client_config/client_channel_factory.c ) - s.files += %w( src/core/ext/client_config/client_config_plugin.c ) - s.files += %w( src/core/ext/client_config/connector.c ) - s.files += %w( src/core/ext/client_config/default_initial_connect_string.c ) - s.files += %w( src/core/ext/client_config/initial_connect_string.c ) - s.files += %w( src/core/ext/client_config/lb_policy.c ) - s.files += %w( src/core/ext/client_config/lb_policy_factory.c ) - s.files += %w( src/core/ext/client_config/lb_policy_registry.c ) - s.files += %w( src/core/ext/client_config/parse_address.c ) - s.files += %w( src/core/ext/client_config/resolver.c ) - s.files += %w( src/core/ext/client_config/resolver_factory.c ) - s.files += %w( src/core/ext/client_config/resolver_registry.c ) - s.files += %w( src/core/ext/client_config/resolver_result.c ) - s.files += %w( src/core/ext/client_config/subchannel.c ) - s.files += %w( src/core/ext/client_config/subchannel_index.c ) - s.files += %w( src/core/ext/client_config/uri_parser.c ) + s.files += %w( src/core/ext/client_channel/channel_connectivity.c ) + s.files += %w( src/core/ext/client_channel/client_channel.c ) + s.files += %w( src/core/ext/client_channel/client_channel_factory.c ) + s.files += %w( src/core/ext/client_channel/client_channel_plugin.c ) + s.files += %w( src/core/ext/client_channel/connector.c ) + s.files += %w( src/core/ext/client_channel/default_initial_connect_string.c ) + s.files += %w( src/core/ext/client_channel/initial_connect_string.c ) + s.files += %w( src/core/ext/client_channel/lb_policy.c ) + s.files += %w( src/core/ext/client_channel/lb_policy_factory.c ) + s.files += %w( src/core/ext/client_channel/lb_policy_registry.c ) + s.files += %w( src/core/ext/client_channel/parse_address.c ) + s.files += %w( src/core/ext/client_channel/resolver.c ) + s.files += %w( src/core/ext/client_channel/resolver_factory.c ) + s.files += %w( src/core/ext/client_channel/resolver_registry.c ) + s.files += %w( src/core/ext/client_channel/resolver_result.c ) + s.files += %w( src/core/ext/client_channel/subchannel.c ) + s.files += %w( src/core/ext/client_channel/subchannel_index.c ) + s.files += %w( src/core/ext/client_channel/uri_parser.c ) s.files += %w( src/core/ext/transport/chttp2/server/insecure/server_chttp2.c ) s.files += %w( src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c ) s.files += %w( src/core/ext/transport/chttp2/client/insecure/channel_create.c ) diff --git a/package.xml b/package.xml index 93210ee47b..3139a267fe 100644 --- a/package.xml +++ b/package.xml @@ -306,21 +306,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -482,24 +482,24 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/src/core/ext/client_channel/README.md b/src/core/ext/client_channel/README.md new file mode 100644 index 0000000000..eda01e3e71 --- /dev/null +++ b/src/core/ext/client_channel/README.md @@ -0,0 +1,66 @@ +Client Configuration Support for GRPC +===================================== + +This library provides high level configuration machinery to construct client +channels and load balance between them. + +Each grpc_channel is created with a grpc_resolver. It is the resolver's duty +to resolve a name into configuration data for the channel. Such configuration +data might include: + +- a list of (ip, port) addresses to connect to +- a load balancing policy to decide which server to send a request to +- a set of filters to mutate outgoing requests (say, by adding metadata) + +The resolver provides this data as a stream of grpc_resolver_result objects to +the channel. We represent configuration as a stream so that it can be changed +by the resolver during execution, by reacting to external events (such as a +new configuration file being pushed to some store). + + +Load Balancing +-------------- + +Load balancing configuration is provided by a grpc_lb_policy object, stored as +part of grpc_resolver_result. + +The primary job of the load balancing policies is to pick a target server given only the +initial metadata for a request. It does this by providing a grpc_subchannel +object to the owning channel. + + +Sub-Channels +------------ + +A sub-channel provides a connection to a server for a client channel. It has a +connectivity state like a regular channel, and so can be connected or +disconnected. This connectivity state can be used to inform load balancing +decisions (for example, by avoiding disconnected backends). + +Configured sub-channels are fully setup to participate in the grpc data plane. +Their behavior is specified by a set of grpc channel filters defined at their +construction. To customize this behavior, resolvers build +grpc_client_channel_factory objects, which use the decorator pattern to customize +construction arguments for concrete grpc_subchannel instances. + + +Naming for GRPC +=============== + +Names in GRPC are represented by a URI (as defined in +[RFC 3986](https://tools.ietf.org/html/rfc3986)). + +The following schemes are currently supported: + +dns:///host:port - dns schemes are currently supported so long as authority is + empty (authority based dns resolution is expected in a future + release) + +unix:path - the unix scheme is used to create and connect to unix domain + sockets - the authority must be empty, and the path + represents the absolute or relative path to the desired + socket + +ipv4:host:port - a pre-resolved ipv4 dotted decimal address/port combination + +ipv6:[host]:port - a pre-resolved ipv6 address/port combination diff --git a/src/core/ext/client_channel/channel_connectivity.c b/src/core/ext/client_channel/channel_connectivity.c new file mode 100644 index 0000000000..9797e66564 --- /dev/null +++ b/src/core/ext/client_channel/channel_connectivity.c @@ -0,0 +1,222 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/lib/surface/channel.h" + +#include +#include + +#include "src/core/ext/client_channel/client_channel.h" +#include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/surface/api_trace.h" +#include "src/core/lib/surface/completion_queue.h" + +grpc_connectivity_state grpc_channel_check_connectivity_state( + grpc_channel *channel, int try_to_connect) { + /* forward through to the underlying client channel */ + grpc_channel_element *client_channel_elem = + grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_connectivity_state state; + GRPC_API_TRACE( + "grpc_channel_check_connectivity_state(channel=%p, try_to_connect=%d)", 2, + (channel, try_to_connect)); + if (client_channel_elem->filter == &grpc_client_channel_filter) { + state = grpc_client_channel_check_connectivity_state( + &exec_ctx, client_channel_elem, try_to_connect); + grpc_exec_ctx_finish(&exec_ctx); + return state; + } + gpr_log(GPR_ERROR, + "grpc_channel_check_connectivity_state called on something that is " + "not a client channel, but '%s'", + client_channel_elem->filter->name); + grpc_exec_ctx_finish(&exec_ctx); + return GRPC_CHANNEL_SHUTDOWN; +} + +typedef enum { + WAITING, + CALLING_BACK, + CALLING_BACK_AND_FINISHED, + CALLED_BACK +} callback_phase; + +typedef struct { + gpr_mu mu; + callback_phase phase; + grpc_closure on_complete; + grpc_timer alarm; + grpc_connectivity_state state; + grpc_completion_queue *cq; + grpc_cq_completion completion_storage; + grpc_channel *channel; + void *tag; +} state_watcher; + +static void delete_state_watcher(grpc_exec_ctx *exec_ctx, state_watcher *w) { + grpc_channel_element *client_channel_elem = grpc_channel_stack_last_element( + grpc_channel_get_channel_stack(w->channel)); + if (client_channel_elem->filter == &grpc_client_channel_filter) { + GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, w->channel, + "watch_channel_connectivity"); + } else { + abort(); + } + gpr_mu_destroy(&w->mu); + gpr_free(w); +} + +static void finished_completion(grpc_exec_ctx *exec_ctx, void *pw, + grpc_cq_completion *ignored) { + int delete = 0; + state_watcher *w = pw; + gpr_mu_lock(&w->mu); + switch (w->phase) { + case WAITING: + case CALLED_BACK: + GPR_UNREACHABLE_CODE(return ); + case CALLING_BACK: + w->phase = CALLED_BACK; + break; + case CALLING_BACK_AND_FINISHED: + delete = 1; + break; + } + gpr_mu_unlock(&w->mu); + + if (delete) { + delete_state_watcher(exec_ctx, w); + } +} + +static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w, + bool due_to_completion, grpc_error *error) { + int delete = 0; + + if (due_to_completion) { + grpc_timer_cancel(exec_ctx, &w->alarm); + } + + gpr_mu_lock(&w->mu); + + if (due_to_completion) { + if (grpc_trace_operation_failures) { + GRPC_LOG_IF_ERROR("watch_completion_error", GRPC_ERROR_REF(error)); + } + GRPC_ERROR_UNREF(error); + error = GRPC_ERROR_NONE; + } else { + if (error == GRPC_ERROR_NONE) { + error = + GRPC_ERROR_CREATE("Timed out waiting for connection state change"); + } else if (error == GRPC_ERROR_CANCELLED) { + error = GRPC_ERROR_NONE; + } + } + switch (w->phase) { + case WAITING: + w->phase = CALLING_BACK; + grpc_cq_end_op(exec_ctx, w->cq, w->tag, GRPC_ERROR_REF(error), + finished_completion, w, &w->completion_storage); + break; + case CALLING_BACK: + w->phase = CALLING_BACK_AND_FINISHED; + break; + case CALLING_BACK_AND_FINISHED: + GPR_UNREACHABLE_CODE(return ); + case CALLED_BACK: + delete = 1; + break; + } + gpr_mu_unlock(&w->mu); + + if (delete) { + delete_state_watcher(exec_ctx, w); + } + + GRPC_ERROR_UNREF(error); +} + +static void watch_complete(grpc_exec_ctx *exec_ctx, void *pw, + grpc_error *error) { + partly_done(exec_ctx, pw, true, GRPC_ERROR_REF(error)); +} + +static void timeout_complete(grpc_exec_ctx *exec_ctx, void *pw, + grpc_error *error) { + partly_done(exec_ctx, pw, false, GRPC_ERROR_REF(error)); +} + +void grpc_channel_watch_connectivity_state( + grpc_channel *channel, grpc_connectivity_state last_observed_state, + gpr_timespec deadline, grpc_completion_queue *cq, void *tag) { + grpc_channel_element *client_channel_elem = + grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + state_watcher *w = gpr_malloc(sizeof(*w)); + + GRPC_API_TRACE( + "grpc_channel_watch_connectivity_state(" + "channel=%p, last_observed_state=%d, " + "deadline=gpr_timespec { tv_sec: %" PRId64 + ", tv_nsec: %d, clock_type: %d }, " + "cq=%p, tag=%p)", + 7, (channel, (int)last_observed_state, deadline.tv_sec, deadline.tv_nsec, + (int)deadline.clock_type, cq, tag)); + + grpc_cq_begin_op(cq, tag); + + gpr_mu_init(&w->mu); + grpc_closure_init(&w->on_complete, watch_complete, w); + w->phase = WAITING; + w->state = last_observed_state; + w->cq = cq; + w->tag = tag; + w->channel = channel; + + grpc_timer_init(&exec_ctx, &w->alarm, + gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC), + timeout_complete, w, gpr_now(GPR_CLOCK_MONOTONIC)); + + if (client_channel_elem->filter == &grpc_client_channel_filter) { + GRPC_CHANNEL_INTERNAL_REF(channel, "watch_channel_connectivity"); + grpc_client_channel_watch_connectivity_state(&exec_ctx, client_channel_elem, + grpc_cq_pollset(cq), &w->state, + &w->on_complete); + } else { + abort(); + } + + grpc_exec_ctx_finish(&exec_ctx); +} diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c new file mode 100644 index 0000000000..7e8579de60 --- /dev/null +++ b/src/core/ext/client_channel/client_channel.c @@ -0,0 +1,840 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/client_channel.h" + +#include +#include +#include + +#include +#include +#include +#include + +#include "src/core/ext/client_channel/subchannel.h" +#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/channel/connected_channel.h" +#include "src/core/lib/iomgr/iomgr.h" +#include "src/core/lib/iomgr/polling_entity.h" +#include "src/core/lib/profiling/timers.h" +#include "src/core/lib/support/string.h" +#include "src/core/lib/surface/channel.h" +#include "src/core/lib/transport/connectivity_state.h" + +/* Client channel implementation */ + +/************************************************************************* + * CHANNEL-WIDE FUNCTIONS + */ + +typedef struct client_channel_channel_data { + /** resolver for this channel */ + grpc_resolver *resolver; + /** have we started resolving this channel */ + bool started_resolving; + + /** mutex protecting client configuration, including all + variables below in this data structure */ + gpr_mu mu; + /** currently active load balancer - guarded by mu */ + grpc_lb_policy *lb_policy; + /** incoming resolver result - set by resolver.next(), guarded by mu */ + grpc_resolver_result *resolver_result; + /** a list of closures that are all waiting for config to come in */ + grpc_closure_list waiting_for_config_closures; + /** resolver callback */ + grpc_closure on_resolver_result_changed; + /** connectivity state being tracked */ + grpc_connectivity_state_tracker state_tracker; + /** when an lb_policy arrives, should we try to exit idle */ + bool exit_idle_when_lb_policy_arrives; + /** owning stack */ + grpc_channel_stack *owning_stack; + /** interested parties (owned) */ + grpc_pollset_set *interested_parties; +} channel_data; + +/** We create one watcher for each new lb_policy that is returned from a + resolver, to watch for state changes from the lb_policy. When a state + change is seen, we update the channel, and create a new watcher. */ +typedef struct { + channel_data *chand; + grpc_closure on_changed; + grpc_connectivity_state state; + grpc_lb_policy *lb_policy; +} lb_policy_connectivity_watcher; + +static void watch_lb_policy(grpc_exec_ctx *exec_ctx, channel_data *chand, + grpc_lb_policy *lb_policy, + grpc_connectivity_state current_state); + +static void set_channel_connectivity_state_locked(grpc_exec_ctx *exec_ctx, + channel_data *chand, + grpc_connectivity_state state, + grpc_error *error, + const char *reason) { + if ((state == GRPC_CHANNEL_TRANSIENT_FAILURE || + state == GRPC_CHANNEL_SHUTDOWN) && + chand->lb_policy != NULL) { + /* cancel fail-fast picks */ + grpc_lb_policy_cancel_picks( + exec_ctx, chand->lb_policy, + /* mask= */ GRPC_INITIAL_METADATA_IGNORE_CONNECTIVITY, + /* check= */ 0); + } + grpc_connectivity_state_set(exec_ctx, &chand->state_tracker, state, error, + reason); +} + +static void on_lb_policy_state_changed_locked(grpc_exec_ctx *exec_ctx, + lb_policy_connectivity_watcher *w, + grpc_error *error) { + grpc_connectivity_state publish_state = w->state; + /* check if the notification is for a stale policy */ + if (w->lb_policy != w->chand->lb_policy) return; + + if (publish_state == GRPC_CHANNEL_SHUTDOWN && w->chand->resolver != NULL) { + publish_state = GRPC_CHANNEL_TRANSIENT_FAILURE; + grpc_resolver_channel_saw_error(exec_ctx, w->chand->resolver); + GRPC_LB_POLICY_UNREF(exec_ctx, w->chand->lb_policy, "channel"); + w->chand->lb_policy = NULL; + } + set_channel_connectivity_state_locked(exec_ctx, w->chand, publish_state, + GRPC_ERROR_REF(error), "lb_changed"); + if (w->state != GRPC_CHANNEL_SHUTDOWN) { + watch_lb_policy(exec_ctx, w->chand, w->lb_policy, w->state); + } +} + +static void on_lb_policy_state_changed(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error) { + lb_policy_connectivity_watcher *w = arg; + + gpr_mu_lock(&w->chand->mu); + on_lb_policy_state_changed_locked(exec_ctx, w, error); + gpr_mu_unlock(&w->chand->mu); + + GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, "watch_lb_policy"); + gpr_free(w); +} + +static void watch_lb_policy(grpc_exec_ctx *exec_ctx, channel_data *chand, + grpc_lb_policy *lb_policy, + grpc_connectivity_state current_state) { + lb_policy_connectivity_watcher *w = gpr_malloc(sizeof(*w)); + GRPC_CHANNEL_STACK_REF(chand->owning_stack, "watch_lb_policy"); + + w->chand = chand; + grpc_closure_init(&w->on_changed, on_lb_policy_state_changed, w); + w->state = current_state; + w->lb_policy = lb_policy; + grpc_lb_policy_notify_on_state_change(exec_ctx, lb_policy, &w->state, + &w->on_changed); +} + +static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error) { + channel_data *chand = arg; + grpc_lb_policy *lb_policy = NULL; + grpc_lb_policy *old_lb_policy; + grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; + bool exit_idle = false; + grpc_error *state_error = GRPC_ERROR_CREATE("No load balancing policy"); + + if (chand->resolver_result != NULL) { + lb_policy = grpc_resolver_result_get_lb_policy(chand->resolver_result); + if (lb_policy != NULL) { + GRPC_LB_POLICY_REF(lb_policy, "channel"); + GRPC_LB_POLICY_REF(lb_policy, "config_change"); + GRPC_ERROR_UNREF(state_error); + state = + grpc_lb_policy_check_connectivity(exec_ctx, lb_policy, &state_error); + } + + grpc_resolver_result_unref(exec_ctx, chand->resolver_result); + } + + chand->resolver_result = NULL; + + if (lb_policy != NULL) { + grpc_pollset_set_add_pollset_set(exec_ctx, lb_policy->interested_parties, + chand->interested_parties); + } + + gpr_mu_lock(&chand->mu); + old_lb_policy = chand->lb_policy; + chand->lb_policy = lb_policy; + if (lb_policy != NULL) { + grpc_exec_ctx_enqueue_list(exec_ctx, &chand->waiting_for_config_closures, + NULL); + } else if (chand->resolver == NULL /* disconnected */) { + grpc_closure_list_fail_all( + &chand->waiting_for_config_closures, + GRPC_ERROR_CREATE_REFERENCING("Channel disconnected", &error, 1)); + grpc_exec_ctx_enqueue_list(exec_ctx, &chand->waiting_for_config_closures, + NULL); + } + if (lb_policy != NULL && chand->exit_idle_when_lb_policy_arrives) { + GRPC_LB_POLICY_REF(lb_policy, "exit_idle"); + exit_idle = true; + chand->exit_idle_when_lb_policy_arrives = false; + } + + if (error == GRPC_ERROR_NONE && chand->resolver) { + set_channel_connectivity_state_locked( + exec_ctx, chand, state, GRPC_ERROR_REF(state_error), "new_lb+resolver"); + if (lb_policy != NULL) { + watch_lb_policy(exec_ctx, chand, lb_policy, state); + } + GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); + grpc_resolver_next(exec_ctx, chand->resolver, &chand->resolver_result, + &chand->on_resolver_result_changed); + gpr_mu_unlock(&chand->mu); + } else { + if (chand->resolver != NULL) { + grpc_resolver_shutdown(exec_ctx, chand->resolver); + GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); + chand->resolver = NULL; + } + grpc_error *refs[] = {error, state_error}; + set_channel_connectivity_state_locked( + exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, + GRPC_ERROR_CREATE_REFERENCING("Got config after disconnection", refs, + GPR_ARRAY_SIZE(refs)), + "resolver_gone"); + gpr_mu_unlock(&chand->mu); + } + + if (exit_idle) { + grpc_lb_policy_exit_idle(exec_ctx, lb_policy); + GRPC_LB_POLICY_UNREF(exec_ctx, lb_policy, "exit_idle"); + } + + if (old_lb_policy != NULL) { + grpc_pollset_set_del_pollset_set( + exec_ctx, old_lb_policy->interested_parties, chand->interested_parties); + GRPC_LB_POLICY_UNREF(exec_ctx, old_lb_policy, "channel"); + } + + if (lb_policy != NULL) { + GRPC_LB_POLICY_UNREF(exec_ctx, lb_policy, "config_change"); + } + + GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "resolver"); + GRPC_ERROR_UNREF(state_error); +} + +static void cc_start_transport_op(grpc_exec_ctx *exec_ctx, + grpc_channel_element *elem, + grpc_transport_op *op) { + channel_data *chand = elem->channel_data; + + grpc_exec_ctx_sched(exec_ctx, op->on_consumed, GRPC_ERROR_NONE, NULL); + + GPR_ASSERT(op->set_accept_stream == false); + if (op->bind_pollset != NULL) { + grpc_pollset_set_add_pollset(exec_ctx, chand->interested_parties, + op->bind_pollset); + } + + gpr_mu_lock(&chand->mu); + if (op->on_connectivity_state_change != NULL) { + grpc_connectivity_state_notify_on_state_change( + exec_ctx, &chand->state_tracker, op->connectivity_state, + op->on_connectivity_state_change); + op->on_connectivity_state_change = NULL; + op->connectivity_state = NULL; + } + + if (op->send_ping != NULL) { + if (chand->lb_policy == NULL) { + grpc_exec_ctx_sched(exec_ctx, op->send_ping, + GRPC_ERROR_CREATE("Ping with no load balancing"), + NULL); + } else { + grpc_lb_policy_ping_one(exec_ctx, chand->lb_policy, op->send_ping); + op->bind_pollset = NULL; + } + op->send_ping = NULL; + } + + if (op->disconnect_with_error != GRPC_ERROR_NONE) { + if (chand->resolver != NULL) { + set_channel_connectivity_state_locked( + exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, + GRPC_ERROR_REF(op->disconnect_with_error), "disconnect"); + grpc_resolver_shutdown(exec_ctx, chand->resolver); + GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); + chand->resolver = NULL; + if (!chand->started_resolving) { + grpc_closure_list_fail_all(&chand->waiting_for_config_closures, + GRPC_ERROR_REF(op->disconnect_with_error)); + grpc_exec_ctx_enqueue_list(exec_ctx, + &chand->waiting_for_config_closures, NULL); + } + if (chand->lb_policy != NULL) { + grpc_pollset_set_del_pollset_set(exec_ctx, + chand->lb_policy->interested_parties, + chand->interested_parties); + GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); + chand->lb_policy = NULL; + } + } + GRPC_ERROR_UNREF(op->disconnect_with_error); + } + gpr_mu_unlock(&chand->mu); +} + +/* Constructor for channel_data */ +static void cc_init_channel_elem(grpc_exec_ctx *exec_ctx, + grpc_channel_element *elem, + grpc_channel_element_args *args) { + channel_data *chand = elem->channel_data; + + memset(chand, 0, sizeof(*chand)); + + GPR_ASSERT(args->is_last); + GPR_ASSERT(elem->filter == &grpc_client_channel_filter); + + gpr_mu_init(&chand->mu); + grpc_closure_init(&chand->on_resolver_result_changed, + on_resolver_result_changed, chand); + chand->owning_stack = args->channel_stack; + + grpc_connectivity_state_init(&chand->state_tracker, GRPC_CHANNEL_IDLE, + "client_channel"); + chand->interested_parties = grpc_pollset_set_create(); +} + +/* Destructor for channel_data */ +static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx, + grpc_channel_element *elem) { + channel_data *chand = elem->channel_data; + + if (chand->resolver != NULL) { + grpc_resolver_shutdown(exec_ctx, chand->resolver); + GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); + } + if (chand->lb_policy != NULL) { + grpc_pollset_set_del_pollset_set(exec_ctx, + chand->lb_policy->interested_parties, + chand->interested_parties); + GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); + } + grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker); + grpc_pollset_set_destroy(chand->interested_parties); + gpr_mu_destroy(&chand->mu); +} + +/************************************************************************* + * PER-CALL FUNCTIONS + */ + +#define GET_CALL(call_data) \ + ((grpc_subchannel_call *)(gpr_atm_acq_load(&(call_data)->subchannel_call))) + +#define CANCELLED_CALL ((grpc_subchannel_call *)1) + +typedef enum { + GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING, + GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL +} subchannel_creation_phase; + +/** Call data. Holds a pointer to grpc_subchannel_call and the + associated machinery to create such a pointer. + Handles queueing of stream ops until a call object is ready, waiting + for initial metadata before trying to create a call object, + and handling cancellation gracefully. */ +typedef struct client_channel_call_data { + /** either 0 for no call, 1 for cancelled, or a pointer to a + grpc_subchannel_call */ + gpr_atm subchannel_call; + + gpr_mu mu; + + subchannel_creation_phase creation_phase; + grpc_connected_subchannel *connected_subchannel; + grpc_polling_entity *pollent; + + grpc_transport_stream_op *waiting_ops; + size_t waiting_ops_count; + size_t waiting_ops_capacity; + + grpc_closure next_step; + + grpc_call_stack *owning_call; +} call_data; + +static void add_waiting_locked(call_data *calld, grpc_transport_stream_op *op) { + GPR_TIMER_BEGIN("add_waiting_locked", 0); + if (calld->waiting_ops_count == calld->waiting_ops_capacity) { + calld->waiting_ops_capacity = GPR_MAX(3, 2 * calld->waiting_ops_capacity); + calld->waiting_ops = + gpr_realloc(calld->waiting_ops, + calld->waiting_ops_capacity * sizeof(*calld->waiting_ops)); + } + calld->waiting_ops[calld->waiting_ops_count++] = *op; + GPR_TIMER_END("add_waiting_locked", 0); +} + +static void fail_locked(grpc_exec_ctx *exec_ctx, call_data *calld, + grpc_error *error) { + size_t i; + for (i = 0; i < calld->waiting_ops_count; i++) { + grpc_transport_stream_op_finish_with_failure( + exec_ctx, &calld->waiting_ops[i], GRPC_ERROR_REF(error)); + } + calld->waiting_ops_count = 0; + GRPC_ERROR_UNREF(error); +} + +typedef struct { + grpc_transport_stream_op *ops; + size_t nops; + grpc_subchannel_call *call; +} retry_ops_args; + +static void retry_ops(grpc_exec_ctx *exec_ctx, void *args, grpc_error *error) { + retry_ops_args *a = args; + size_t i; + for (i = 0; i < a->nops; i++) { + grpc_subchannel_call_process_op(exec_ctx, a->call, &a->ops[i]); + } + GRPC_SUBCHANNEL_CALL_UNREF(exec_ctx, a->call, "retry_ops"); + gpr_free(a->ops); + gpr_free(a); +} + +static void retry_waiting_locked(grpc_exec_ctx *exec_ctx, call_data *calld) { + retry_ops_args *a = gpr_malloc(sizeof(*a)); + a->ops = calld->waiting_ops; + a->nops = calld->waiting_ops_count; + a->call = GET_CALL(calld); + if (a->call == CANCELLED_CALL) { + gpr_free(a); + fail_locked(exec_ctx, calld, GRPC_ERROR_CANCELLED); + return; + } + calld->waiting_ops = NULL; + calld->waiting_ops_count = 0; + calld->waiting_ops_capacity = 0; + GRPC_SUBCHANNEL_CALL_REF(a->call, "retry_ops"); + grpc_exec_ctx_sched(exec_ctx, grpc_closure_create(retry_ops, a), + GRPC_ERROR_NONE, NULL); +} + +static void subchannel_ready(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error) { + call_data *calld = arg; + gpr_mu_lock(&calld->mu); + GPR_ASSERT(calld->creation_phase == + GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL); + calld->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING; + if (calld->connected_subchannel == NULL) { + gpr_atm_no_barrier_store(&calld->subchannel_call, 1); + fail_locked(exec_ctx, calld, GRPC_ERROR_CREATE_REFERENCING( + "Failed to create subchannel", &error, 1)); + } else if (1 == gpr_atm_acq_load(&calld->subchannel_call)) { + /* already cancelled before subchannel became ready */ + fail_locked(exec_ctx, calld, + GRPC_ERROR_CREATE_REFERENCING( + "Cancelled before creating subchannel", &error, 1)); + } else { + grpc_subchannel_call *subchannel_call = NULL; + grpc_error *new_error = grpc_connected_subchannel_create_call( + exec_ctx, calld->connected_subchannel, calld->pollent, + &subchannel_call); + if (new_error != GRPC_ERROR_NONE) { + new_error = grpc_error_add_child(new_error, error); + subchannel_call = CANCELLED_CALL; + fail_locked(exec_ctx, calld, new_error); + } + gpr_atm_rel_store(&calld->subchannel_call, + (gpr_atm)(uintptr_t)subchannel_call); + retry_waiting_locked(exec_ctx, calld); + } + gpr_mu_unlock(&calld->mu); + GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "pick_subchannel"); +} + +static char *cc_get_peer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { + call_data *calld = elem->call_data; + grpc_subchannel_call *subchannel_call = GET_CALL(calld); + if (subchannel_call == NULL || subchannel_call == CANCELLED_CALL) { + return NULL; + } else { + return grpc_subchannel_call_get_peer(exec_ctx, subchannel_call); + } +} + +typedef struct { + grpc_metadata_batch *initial_metadata; + uint32_t initial_metadata_flags; + grpc_connected_subchannel **connected_subchannel; + grpc_closure *on_ready; + grpc_call_element *elem; + grpc_closure closure; +} continue_picking_args; + +static bool pick_subchannel(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + grpc_metadata_batch *initial_metadata, + uint32_t initial_metadata_flags, + grpc_connected_subchannel **connected_subchannel, + grpc_closure *on_ready); + +static void continue_picking(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error) { + continue_picking_args *cpa = arg; + if (cpa->connected_subchannel == NULL) { + /* cancelled, do nothing */ + } else if (error != GRPC_ERROR_NONE) { + grpc_exec_ctx_sched(exec_ctx, cpa->on_ready, GRPC_ERROR_REF(error), NULL); + } else if (pick_subchannel(exec_ctx, cpa->elem, cpa->initial_metadata, + cpa->initial_metadata_flags, + cpa->connected_subchannel, cpa->on_ready)) { + grpc_exec_ctx_sched(exec_ctx, cpa->on_ready, GRPC_ERROR_NONE, NULL); + } + gpr_free(cpa); +} + +static bool pick_subchannel(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + grpc_metadata_batch *initial_metadata, + uint32_t initial_metadata_flags, + grpc_connected_subchannel **connected_subchannel, + grpc_closure *on_ready) { + GPR_TIMER_BEGIN("pick_subchannel", 0); + + channel_data *chand = elem->channel_data; + call_data *calld = elem->call_data; + continue_picking_args *cpa; + grpc_closure *closure; + + GPR_ASSERT(connected_subchannel); + + gpr_mu_lock(&chand->mu); + if (initial_metadata == NULL) { + if (chand->lb_policy != NULL) { + grpc_lb_policy_cancel_pick(exec_ctx, chand->lb_policy, + connected_subchannel); + } + for (closure = chand->waiting_for_config_closures.head; closure != NULL; + closure = closure->next_data.next) { + cpa = closure->cb_arg; + if (cpa->connected_subchannel == connected_subchannel) { + cpa->connected_subchannel = NULL; + grpc_exec_ctx_sched(exec_ctx, cpa->on_ready, + GRPC_ERROR_CREATE("Pick cancelled"), NULL); + } + } + gpr_mu_unlock(&chand->mu); + GPR_TIMER_END("pick_subchannel", 0); + return true; + } + if (chand->lb_policy != NULL) { + grpc_lb_policy *lb_policy = chand->lb_policy; + int r; + GRPC_LB_POLICY_REF(lb_policy, "pick_subchannel"); + gpr_mu_unlock(&chand->mu); + r = grpc_lb_policy_pick(exec_ctx, lb_policy, calld->pollent, + initial_metadata, initial_metadata_flags, + connected_subchannel, on_ready); + GRPC_LB_POLICY_UNREF(exec_ctx, lb_policy, "pick_subchannel"); + GPR_TIMER_END("pick_subchannel", 0); + return r; + } + if (chand->resolver != NULL && !chand->started_resolving) { + chand->started_resolving = true; + GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); + grpc_resolver_next(exec_ctx, chand->resolver, &chand->resolver_result, + &chand->on_resolver_result_changed); + } + if (chand->resolver != NULL) { + cpa = gpr_malloc(sizeof(*cpa)); + cpa->initial_metadata = initial_metadata; + cpa->initial_metadata_flags = initial_metadata_flags; + cpa->connected_subchannel = connected_subchannel; + cpa->on_ready = on_ready; + cpa->elem = elem; + grpc_closure_init(&cpa->closure, continue_picking, cpa); + grpc_closure_list_append(&chand->waiting_for_config_closures, &cpa->closure, + GRPC_ERROR_NONE); + } else { + grpc_exec_ctx_sched(exec_ctx, on_ready, GRPC_ERROR_CREATE("Disconnected"), + NULL); + } + gpr_mu_unlock(&chand->mu); + + GPR_TIMER_END("pick_subchannel", 0); + return false; +} + +// The logic here is fairly complicated, due to (a) the fact that we +// need to handle the case where we receive the send op before the +// initial metadata op, and (b) the need for efficiency, especially in +// the streaming case. +// TODO(ctiller): Explain this more thoroughly. +static void cc_start_transport_stream_op(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + grpc_transport_stream_op *op) { + call_data *calld = elem->call_data; + GRPC_CALL_LOG_OP(GPR_INFO, elem, op); + /* try to (atomically) get the call */ + grpc_subchannel_call *call = GET_CALL(calld); + GPR_TIMER_BEGIN("cc_start_transport_stream_op", 0); + if (call == CANCELLED_CALL) { + grpc_transport_stream_op_finish_with_failure(exec_ctx, op, + GRPC_ERROR_CANCELLED); + GPR_TIMER_END("cc_start_transport_stream_op", 0); + return; + } + if (call != NULL) { + grpc_subchannel_call_process_op(exec_ctx, call, op); + GPR_TIMER_END("cc_start_transport_stream_op", 0); + return; + } + /* we failed; lock and figure out what to do */ + gpr_mu_lock(&calld->mu); +retry: + /* need to recheck that another thread hasn't set the call */ + call = GET_CALL(calld); + if (call == CANCELLED_CALL) { + gpr_mu_unlock(&calld->mu); + grpc_transport_stream_op_finish_with_failure(exec_ctx, op, + GRPC_ERROR_CANCELLED); + GPR_TIMER_END("cc_start_transport_stream_op", 0); + return; + } + if (call != NULL) { + gpr_mu_unlock(&calld->mu); + grpc_subchannel_call_process_op(exec_ctx, call, op); + GPR_TIMER_END("cc_start_transport_stream_op", 0); + return; + } + /* if this is a cancellation, then we can raise our cancelled flag */ + if (op->cancel_error != GRPC_ERROR_NONE) { + if (!gpr_atm_rel_cas(&calld->subchannel_call, 0, + (gpr_atm)(uintptr_t)CANCELLED_CALL)) { + goto retry; + } else { + switch (calld->creation_phase) { + case GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING: + fail_locked(exec_ctx, calld, GRPC_ERROR_REF(op->cancel_error)); + break; + case GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL: + pick_subchannel(exec_ctx, elem, NULL, 0, &calld->connected_subchannel, + NULL); + break; + } + gpr_mu_unlock(&calld->mu); + grpc_transport_stream_op_finish_with_failure(exec_ctx, op, + GRPC_ERROR_CANCELLED); + GPR_TIMER_END("cc_start_transport_stream_op", 0); + return; + } + } + /* if we don't have a subchannel, try to get one */ + if (calld->creation_phase == GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING && + calld->connected_subchannel == NULL && + op->send_initial_metadata != NULL) { + calld->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL; + grpc_closure_init(&calld->next_step, subchannel_ready, calld); + GRPC_CALL_STACK_REF(calld->owning_call, "pick_subchannel"); + if (pick_subchannel(exec_ctx, elem, op->send_initial_metadata, + op->send_initial_metadata_flags, + &calld->connected_subchannel, &calld->next_step)) { + calld->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING; + GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "pick_subchannel"); + } + } + /* if we've got a subchannel, then let's ask it to create a call */ + if (calld->creation_phase == GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING && + calld->connected_subchannel != NULL) { + grpc_subchannel_call *subchannel_call = NULL; + grpc_error *error = grpc_connected_subchannel_create_call( + exec_ctx, calld->connected_subchannel, calld->pollent, + &subchannel_call); + if (error != GRPC_ERROR_NONE) { + subchannel_call = CANCELLED_CALL; + fail_locked(exec_ctx, calld, GRPC_ERROR_REF(error)); + grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); + } + gpr_atm_rel_store(&calld->subchannel_call, + (gpr_atm)(uintptr_t)subchannel_call); + retry_waiting_locked(exec_ctx, calld); + goto retry; + } + /* nothing to be done but wait */ + add_waiting_locked(calld, op); + gpr_mu_unlock(&calld->mu); + GPR_TIMER_END("cc_start_transport_stream_op", 0); +} + +/* Constructor for call_data */ +static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + grpc_call_element_args *args) { + call_data *calld = elem->call_data; + gpr_atm_rel_store(&calld->subchannel_call, 0); + gpr_mu_init(&calld->mu); + calld->connected_subchannel = NULL; + calld->waiting_ops = NULL; + calld->waiting_ops_count = 0; + calld->waiting_ops_capacity = 0; + calld->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING; + calld->owning_call = args->call_stack; + calld->pollent = NULL; + return GRPC_ERROR_NONE; +} + +/* Destructor for call_data */ +static void cc_destroy_call_elem(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + const grpc_call_final_info *final_info, + void *and_free_memory) { + call_data *calld = elem->call_data; + grpc_subchannel_call *call = GET_CALL(calld); + if (call != NULL && call != CANCELLED_CALL) { + GRPC_SUBCHANNEL_CALL_UNREF(exec_ctx, call, "client_channel_destroy_call"); + } + GPR_ASSERT(calld->creation_phase == GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING); + gpr_mu_destroy(&calld->mu); + GPR_ASSERT(calld->waiting_ops_count == 0); + gpr_free(calld->waiting_ops); + gpr_free(and_free_memory); +} + +static void cc_set_pollset_or_pollset_set(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + grpc_polling_entity *pollent) { + call_data *calld = elem->call_data; + calld->pollent = pollent; +} + +/************************************************************************* + * EXPORTED SYMBOLS + */ + +const grpc_channel_filter grpc_client_channel_filter = { + cc_start_transport_stream_op, + cc_start_transport_op, + sizeof(call_data), + cc_init_call_elem, + cc_set_pollset_or_pollset_set, + cc_destroy_call_elem, + sizeof(channel_data), + cc_init_channel_elem, + cc_destroy_channel_elem, + cc_get_peer, + "client-channel", +}; + +void grpc_client_channel_set_resolver(grpc_exec_ctx *exec_ctx, + grpc_channel_stack *channel_stack, + grpc_resolver *resolver) { + /* post construction initialization: set the transport setup pointer */ + grpc_channel_element *elem = grpc_channel_stack_last_element(channel_stack); + channel_data *chand = elem->channel_data; + gpr_mu_lock(&chand->mu); + GPR_ASSERT(!chand->resolver); + chand->resolver = resolver; + GRPC_RESOLVER_REF(resolver, "channel"); + if (!grpc_closure_list_empty(chand->waiting_for_config_closures) || + chand->exit_idle_when_lb_policy_arrives) { + chand->started_resolving = true; + GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); + grpc_resolver_next(exec_ctx, resolver, &chand->resolver_result, + &chand->on_resolver_result_changed); + } + gpr_mu_unlock(&chand->mu); +} + +grpc_connectivity_state grpc_client_channel_check_connectivity_state( + grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, int try_to_connect) { + channel_data *chand = elem->channel_data; + grpc_connectivity_state out; + gpr_mu_lock(&chand->mu); + out = grpc_connectivity_state_check(&chand->state_tracker, NULL); + if (out == GRPC_CHANNEL_IDLE && try_to_connect) { + if (chand->lb_policy != NULL) { + grpc_lb_policy_exit_idle(exec_ctx, chand->lb_policy); + } else { + chand->exit_idle_when_lb_policy_arrives = true; + if (!chand->started_resolving && chand->resolver != NULL) { + GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); + chand->started_resolving = true; + grpc_resolver_next(exec_ctx, chand->resolver, &chand->resolver_result, + &chand->on_resolver_result_changed); + } + } + } + gpr_mu_unlock(&chand->mu); + return out; +} + +typedef struct { + channel_data *chand; + grpc_pollset *pollset; + grpc_closure *on_complete; + grpc_closure my_closure; +} external_connectivity_watcher; + +static void on_external_watch_complete(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error) { + external_connectivity_watcher *w = arg; + grpc_closure *follow_up = w->on_complete; + grpc_pollset_set_del_pollset(exec_ctx, w->chand->interested_parties, + w->pollset); + GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, + "external_connectivity_watcher"); + gpr_free(w); + follow_up->cb(exec_ctx, follow_up->cb_arg, error); +} + +void grpc_client_channel_watch_connectivity_state( + grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, grpc_pollset *pollset, + grpc_connectivity_state *state, grpc_closure *on_complete) { + channel_data *chand = elem->channel_data; + external_connectivity_watcher *w = gpr_malloc(sizeof(*w)); + w->chand = chand; + w->pollset = pollset; + w->on_complete = on_complete; + grpc_pollset_set_add_pollset(exec_ctx, chand->interested_parties, pollset); + grpc_closure_init(&w->my_closure, on_external_watch_complete, w); + GRPC_CHANNEL_STACK_REF(w->chand->owning_stack, + "external_connectivity_watcher"); + gpr_mu_lock(&chand->mu); + grpc_connectivity_state_notify_on_state_change( + exec_ctx, &chand->state_tracker, state, &w->my_closure); + gpr_mu_unlock(&chand->mu); +} diff --git a/src/core/ext/client_channel/client_channel.h b/src/core/ext/client_channel/client_channel.h new file mode 100644 index 0000000000..5dea45de43 --- /dev/null +++ b/src/core/ext/client_channel/client_channel.h @@ -0,0 +1,63 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_H + +#include "src/core/ext/client_channel/resolver.h" +#include "src/core/lib/channel/channel_stack.h" + +/* A client channel is a channel that begins disconnected, and can connect + to some endpoint on demand. If that endpoint disconnects, it will be + connected to again later. + + Calls on a disconnected client channel are queued until a connection is + established. */ + +extern const grpc_channel_filter grpc_client_channel_filter; + +/* post-construction initializer to let the client channel know which + transport setup it should cancel upon destruction, or initiate when it needs + a connection */ +void grpc_client_channel_set_resolver(grpc_exec_ctx *exec_ctx, + grpc_channel_stack *channel_stack, + grpc_resolver *resolver); + +grpc_connectivity_state grpc_client_channel_check_connectivity_state( + grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, int try_to_connect); + +void grpc_client_channel_watch_connectivity_state( + grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, grpc_pollset *pollset, + grpc_connectivity_state *state, grpc_closure *on_complete); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_H */ diff --git a/src/core/ext/client_channel/client_channel_factory.c b/src/core/ext/client_channel/client_channel_factory.c new file mode 100644 index 0000000000..db1cc9093c --- /dev/null +++ b/src/core/ext/client_channel/client_channel_factory.c @@ -0,0 +1,57 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/client_channel_factory.h" + +void grpc_client_channel_factory_ref(grpc_client_channel_factory* factory) { + factory->vtable->ref(factory); +} + +void grpc_client_channel_factory_unref(grpc_exec_ctx* exec_ctx, + grpc_client_channel_factory* factory) { + factory->vtable->unref(exec_ctx, factory); +} + +grpc_subchannel* grpc_client_channel_factory_create_subchannel( + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, + grpc_subchannel_args* args) { + return factory->vtable->create_subchannel(exec_ctx, factory, args); +} + +grpc_channel* grpc_client_channel_factory_create_channel( + grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, + const char* target, grpc_client_channel_type type, + grpc_channel_args* args) { + return factory->vtable->create_client_channel(exec_ctx, factory, target, type, + args); +} diff --git a/src/core/ext/client_channel/client_channel_factory.h b/src/core/ext/client_channel/client_channel_factory.h new file mode 100644 index 0000000000..cf6724a24b --- /dev/null +++ b/src/core/ext/client_channel/client_channel_factory.h @@ -0,0 +1,85 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_FACTORY_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_FACTORY_H + +#include + +#include "src/core/ext/client_channel/subchannel.h" +#include "src/core/lib/channel/channel_stack.h" + +typedef struct grpc_client_channel_factory grpc_client_channel_factory; +typedef struct grpc_client_channel_factory_vtable + grpc_client_channel_factory_vtable; + +typedef enum { + GRPC_CLIENT_CHANNEL_TYPE_REGULAR, /** for the user-level regular calls */ + GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, /** for communication with a load + balancing service */ +} grpc_client_channel_type; + +/** Constructor for new configured channels. + Creating decorators around this type is encouraged to adapt behavior. */ +struct grpc_client_channel_factory { + const grpc_client_channel_factory_vtable *vtable; +}; + +struct grpc_client_channel_factory_vtable { + void (*ref)(grpc_client_channel_factory *factory); + void (*unref)(grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory); + grpc_subchannel *(*create_subchannel)(grpc_exec_ctx *exec_ctx, + grpc_client_channel_factory *factory, + grpc_subchannel_args *args); + grpc_channel *(*create_client_channel)(grpc_exec_ctx *exec_ctx, + grpc_client_channel_factory *factory, + const char *target, + grpc_client_channel_type type, + grpc_channel_args *args); +}; + +void grpc_client_channel_factory_ref(grpc_client_channel_factory *factory); +void grpc_client_channel_factory_unref(grpc_exec_ctx *exec_ctx, + grpc_client_channel_factory *factory); + +/** Create a new grpc_subchannel */ +grpc_subchannel *grpc_client_channel_factory_create_subchannel( + grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, + grpc_subchannel_args *args); + +/** Create a new grpc_channel */ +grpc_channel *grpc_client_channel_factory_create_channel( + grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, + const char *target, grpc_client_channel_type type, grpc_channel_args *args); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_FACTORY_H */ diff --git a/src/core/ext/client_channel/client_channel_plugin.c b/src/core/ext/client_channel/client_channel_plugin.c new file mode 100644 index 0000000000..954f0db3bb --- /dev/null +++ b/src/core/ext/client_channel/client_channel_plugin.c @@ -0,0 +1,95 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include + +#include + +#include "src/core/ext/client_channel/client_channel.h" +#include "src/core/ext/client_channel/lb_policy_registry.h" +#include "src/core/ext/client_channel/resolver_registry.h" +#include "src/core/ext/client_channel/subchannel_index.h" +#include "src/core/lib/surface/channel_init.h" + +#ifndef GRPC_DEFAULT_NAME_PREFIX +#define GRPC_DEFAULT_NAME_PREFIX "dns:///" +#endif + +static bool append_filter(grpc_channel_stack_builder *builder, void *arg) { + return grpc_channel_stack_builder_append_filter( + builder, (const grpc_channel_filter *)arg, NULL, NULL); +} + +static bool set_default_host_if_unset(grpc_channel_stack_builder *builder, + void *unused) { + const grpc_channel_args *args = + grpc_channel_stack_builder_get_channel_arguments(builder); + for (size_t i = 0; i < args->num_args; i++) { + if (0 == strcmp(args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY) || + 0 == strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) { + return true; + } + } + char *default_authority = grpc_get_default_authority( + grpc_channel_stack_builder_get_target(builder)); + if (default_authority != NULL) { + grpc_arg arg; + arg.type = GRPC_ARG_STRING; + arg.key = GRPC_ARG_DEFAULT_AUTHORITY; + arg.value.string = default_authority; + grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1); + grpc_channel_stack_builder_set_channel_arguments(builder, new_args); + gpr_free(default_authority); + grpc_channel_args_destroy(new_args); + } + return true; +} + +void grpc_client_channel_init(void) { + grpc_lb_policy_registry_init(); + grpc_resolver_registry_init(GRPC_DEFAULT_NAME_PREFIX); + grpc_subchannel_index_init(); + grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MIN, + set_default_host_if_unset, NULL); + grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, append_filter, + (void *)&grpc_client_channel_filter); +} + +void grpc_client_channel_shutdown(void) { + grpc_subchannel_index_shutdown(); + grpc_channel_init_shutdown(); + grpc_resolver_registry_shutdown(); + grpc_lb_policy_registry_shutdown(); +} diff --git a/src/core/ext/client_channel/connector.c b/src/core/ext/client_channel/connector.c new file mode 100644 index 0000000000..0582e5b372 --- /dev/null +++ b/src/core/ext/client_channel/connector.c @@ -0,0 +1,55 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/connector.h" + +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) { + connector->vtable->unref(exec_ctx, connector); +} + +void grpc_connector_connect(grpc_exec_ctx* exec_ctx, grpc_connector* connector, + const grpc_connect_in_args* in_args, + grpc_connect_out_args* out_args, + grpc_closure* notify) { + connector->vtable->connect(exec_ctx, connector, in_args, out_args, notify); +} + +void grpc_connector_shutdown(grpc_exec_ctx* exec_ctx, + grpc_connector* connector) { + connector->vtable->shutdown(exec_ctx, connector); +} diff --git a/src/core/ext/client_channel/connector.h b/src/core/ext/client_channel/connector.h new file mode 100644 index 0000000000..ea9d23706e --- /dev/null +++ b/src/core/ext/client_channel/connector.h @@ -0,0 +1,92 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_CONNECTOR_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_CONNECTOR_H + +#include "src/core/lib/channel/channel_stack.h" +#include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/transport/transport.h" + +typedef struct grpc_connector grpc_connector; +typedef struct grpc_connector_vtable grpc_connector_vtable; + +struct grpc_connector { + const grpc_connector_vtable *vtable; +}; + +typedef struct { + /** set of pollsets interested in this connection */ + grpc_pollset_set *interested_parties; + /** address to connect to */ + const struct sockaddr *addr; + size_t addr_len; + /** initial connect string to send */ + gpr_slice initial_connect_string; + /** deadline for connection */ + gpr_timespec deadline; + /** channel arguments (to be passed to transport) */ + const grpc_channel_args *channel_args; +} grpc_connect_in_args; + +typedef struct { + /** the connected transport */ + grpc_transport *transport; + + /** channel arguments (to be passed to the filters) */ + grpc_channel_args *channel_args; +} grpc_connect_out_args; + +struct grpc_connector_vtable { + void (*ref)(grpc_connector *connector); + void (*unref)(grpc_exec_ctx *exec_ctx, grpc_connector *connector); + /** Implementation of grpc_connector_shutdown */ + void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_connector *connector); + /** Implementation of grpc_connector_connect */ + void (*connect)(grpc_exec_ctx *exec_ctx, grpc_connector *connector, + const grpc_connect_in_args *in_args, + grpc_connect_out_args *out_args, grpc_closure *notify); +}; + +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, + const grpc_connect_in_args *in_args, + grpc_connect_out_args *out_args, + grpc_closure *notify); +/** Cancel any pending connection */ +void grpc_connector_shutdown(grpc_exec_ctx *exec_ctx, + grpc_connector *connector); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_CONNECTOR_H */ diff --git a/src/core/ext/client_channel/default_initial_connect_string.c b/src/core/ext/client_channel/default_initial_connect_string.c new file mode 100644 index 0000000000..a70da4a84a --- /dev/null +++ b/src/core/ext/client_channel/default_initial_connect_string.c @@ -0,0 +1,39 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include "src/core/lib/iomgr/sockaddr.h" + +void grpc_set_default_initial_connect_string(struct sockaddr **addr, + size_t *addr_len, + gpr_slice *initial_str) {} diff --git a/src/core/ext/client_channel/initial_connect_string.c b/src/core/ext/client_channel/initial_connect_string.c new file mode 100644 index 0000000000..fd8ddb83a8 --- /dev/null +++ b/src/core/ext/client_channel/initial_connect_string.c @@ -0,0 +1,53 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/initial_connect_string.h" + +#include + +extern void grpc_set_default_initial_connect_string(struct sockaddr **addr, + size_t *addr_len, + gpr_slice *initial_str); + +static grpc_set_initial_connect_string_func g_set_initial_connect_string_func = + grpc_set_default_initial_connect_string; + +void grpc_test_set_initial_connect_string_function( + grpc_set_initial_connect_string_func func) { + g_set_initial_connect_string_func = func; +} + +void grpc_set_initial_connect_string(struct sockaddr **addr, size_t *addr_len, + gpr_slice *initial_str) { + g_set_initial_connect_string_func(addr, addr_len, initial_str); +} diff --git a/src/core/ext/client_channel/initial_connect_string.h b/src/core/ext/client_channel/initial_connect_string.h new file mode 100644 index 0000000000..06f0767832 --- /dev/null +++ b/src/core/ext/client_channel/initial_connect_string.h @@ -0,0 +1,50 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_INITIAL_CONNECT_STRING_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_INITIAL_CONNECT_STRING_H + +#include +#include "src/core/lib/iomgr/sockaddr.h" + +typedef void (*grpc_set_initial_connect_string_func)(struct sockaddr **addr, + size_t *addr_len, + gpr_slice *initial_str); +void grpc_test_set_initial_connect_string_function( + grpc_set_initial_connect_string_func func); + +/** Set a string to be sent once connected. Optionally reset addr. */ +void grpc_set_initial_connect_string(struct sockaddr **addr, size_t *addr_len, + gpr_slice *connect_string); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_INITIAL_CONNECT_STRING_H */ diff --git a/src/core/ext/client_channel/lb_policy.c b/src/core/ext/client_channel/lb_policy.c new file mode 100644 index 0000000000..9ca895ec6c --- /dev/null +++ b/src/core/ext/client_channel/lb_policy.c @@ -0,0 +1,146 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/lb_policy.h" + +#define WEAK_REF_BITS 16 + +void grpc_lb_policy_init(grpc_lb_policy *policy, + const grpc_lb_policy_vtable *vtable) { + policy->vtable = vtable; + gpr_atm_no_barrier_store(&policy->ref_pair, 1 << WEAK_REF_BITS); + policy->interested_parties = grpc_pollset_set_create(); +} + +#ifdef GRPC_LB_POLICY_REFCOUNT_DEBUG +#define REF_FUNC_EXTRA_ARGS , const char *file, int line, const char *reason +#define REF_MUTATE_EXTRA_ARGS REF_FUNC_EXTRA_ARGS, const char *purpose +#define REF_FUNC_PASS_ARGS(new_reason) , file, line, new_reason +#define REF_MUTATE_PASS_ARGS(purpose) , file, line, reason, purpose +#else +#define REF_FUNC_EXTRA_ARGS +#define REF_MUTATE_EXTRA_ARGS +#define REF_FUNC_PASS_ARGS(new_reason) +#define REF_MUTATE_PASS_ARGS(x) +#endif + +static gpr_atm ref_mutate(grpc_lb_policy *c, gpr_atm delta, + int barrier REF_MUTATE_EXTRA_ARGS) { + gpr_atm old_val = barrier ? gpr_atm_full_fetch_add(&c->ref_pair, delta) + : gpr_atm_no_barrier_fetch_add(&c->ref_pair, delta); +#ifdef GRPC_LB_POLICY_REFCOUNT_DEBUG + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, + "LB_POLICY: 0x%" PRIxPTR " %12s 0x%" PRIxPTR " -> 0x%" PRIxPTR + " [%s]", + (intptr_t)c, purpose, old_val, old_val + delta, reason); +#endif + return old_val; +} + +void grpc_lb_policy_ref(grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { + ref_mutate(policy, 1 << WEAK_REF_BITS, 0 REF_MUTATE_PASS_ARGS("STRONG_REF")); +} + +void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx, + grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { + gpr_atm old_val = + ref_mutate(policy, (gpr_atm)1 - (gpr_atm)(1 << WEAK_REF_BITS), + 1 REF_MUTATE_PASS_ARGS("STRONG_UNREF")); + gpr_atm mask = ~(gpr_atm)((1 << WEAK_REF_BITS) - 1); + gpr_atm check = 1 << WEAK_REF_BITS; + if ((old_val & mask) == check) { + policy->vtable->shutdown(exec_ctx, policy); + } + grpc_lb_policy_weak_unref(exec_ctx, + policy REF_FUNC_PASS_ARGS("strong-unref")); +} + +void grpc_lb_policy_weak_ref(grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { + ref_mutate(policy, 1, 0 REF_MUTATE_PASS_ARGS("WEAK_REF")); +} + +void grpc_lb_policy_weak_unref(grpc_exec_ctx *exec_ctx, + grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { + gpr_atm old_val = + ref_mutate(policy, -(gpr_atm)1, 1 REF_MUTATE_PASS_ARGS("WEAK_UNREF")); + if (old_val == 1) { + grpc_pollset_set_destroy(policy->interested_parties); + policy->vtable->destroy(exec_ctx, policy); + } +} + +int grpc_lb_policy_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_polling_entity *pollent, + grpc_metadata_batch *initial_metadata, + uint32_t initial_metadata_flags, + grpc_connected_subchannel **target, + grpc_closure *on_complete) { + return policy->vtable->pick(exec_ctx, policy, pollent, initial_metadata, + initial_metadata_flags, target, on_complete); +} + +void grpc_lb_policy_cancel_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_connected_subchannel **target) { + policy->vtable->cancel_pick(exec_ctx, policy, target); +} + +void grpc_lb_policy_cancel_picks(grpc_exec_ctx *exec_ctx, + grpc_lb_policy *policy, + uint32_t initial_metadata_flags_mask, + uint32_t initial_metadata_flags_eq) { + policy->vtable->cancel_picks(exec_ctx, policy, initial_metadata_flags_mask, + initial_metadata_flags_eq); +} + +void grpc_lb_policy_exit_idle(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy) { + policy->vtable->exit_idle(exec_ctx, policy); +} + +void grpc_lb_policy_ping_one(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_closure *closure) { + policy->vtable->ping_one(exec_ctx, policy, closure); +} + +void grpc_lb_policy_notify_on_state_change(grpc_exec_ctx *exec_ctx, + grpc_lb_policy *policy, + grpc_connectivity_state *state, + grpc_closure *closure) { + policy->vtable->notify_on_state_change(exec_ctx, policy, state, closure); +} + +grpc_connectivity_state grpc_lb_policy_check_connectivity( + grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_error **connectivity_error) { + return policy->vtable->check_connectivity(exec_ctx, policy, + connectivity_error); +} diff --git a/src/core/ext/client_channel/lb_policy.h b/src/core/ext/client_channel/lb_policy.h new file mode 100644 index 0000000000..a5838cdb9f --- /dev/null +++ b/src/core/ext/client_channel/lb_policy.h @@ -0,0 +1,166 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_H + +#include "src/core/ext/client_channel/subchannel.h" +#include "src/core/lib/iomgr/polling_entity.h" +#include "src/core/lib/transport/connectivity_state.h" + +/** A load balancing policy: specified by a vtable and a struct (which + is expected to be extended to contain some parameters) */ +typedef struct grpc_lb_policy grpc_lb_policy; +typedef struct grpc_lb_policy_vtable grpc_lb_policy_vtable; + +typedef void (*grpc_lb_completion)(void *cb_arg, grpc_subchannel *subchannel, + grpc_status_code status, const char *errmsg); + +struct grpc_lb_policy { + const grpc_lb_policy_vtable *vtable; + gpr_atm ref_pair; + /* owned pointer to interested parties in load balancing decisions */ + grpc_pollset_set *interested_parties; +}; + +struct grpc_lb_policy_vtable { + void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); + + void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); + + /** implement grpc_lb_policy_pick */ + int (*pick)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_polling_entity *pollent, + grpc_metadata_batch *initial_metadata, + uint32_t initial_metadata_flags, + grpc_connected_subchannel **target, grpc_closure *on_complete); + void (*cancel_pick)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_connected_subchannel **target); + void (*cancel_picks)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + uint32_t initial_metadata_flags_mask, + uint32_t initial_metadata_flags_eq); + + void (*ping_one)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_closure *closure); + + /** Try to enter a READY connectivity state */ + void (*exit_idle)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); + + /** check the current connectivity of the lb_policy */ + grpc_connectivity_state (*check_connectivity)( + grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_error **connectivity_error); + + /** call notify when the connectivity state of a channel changes from *state. + Updates *state with the new state of the policy. Calling with a NULL \a + state cancels the subscription. + */ + void (*notify_on_state_change)(grpc_exec_ctx *exec_ctx, + grpc_lb_policy *policy, + grpc_connectivity_state *state, + grpc_closure *closure); +}; + +/*#define GRPC_LB_POLICY_REFCOUNT_DEBUG*/ +#ifdef GRPC_LB_POLICY_REFCOUNT_DEBUG +#define GRPC_LB_POLICY_REF(p, r) \ + grpc_lb_policy_ref((p), __FILE__, __LINE__, (r)) +#define GRPC_LB_POLICY_UNREF(exec_ctx, p, r) \ + grpc_lb_policy_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) +#define GRPC_LB_POLICY_WEAK_REF(p, r) \ + grpc_lb_policy_weak_ref((p), __FILE__, __LINE__, (r)) +#define GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, p, r) \ + grpc_lb_policy_weak_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) +void grpc_lb_policy_ref(grpc_lb_policy *policy, const char *file, int line, + const char *reason); +void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + const char *file, int line, const char *reason); +void grpc_lb_policy_weak_ref(grpc_lb_policy *policy, const char *file, int line, + const char *reason); +void grpc_lb_policy_weak_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + const char *file, int line, const char *reason); +#else +#define GRPC_LB_POLICY_REF(p, r) grpc_lb_policy_ref((p)) +#define GRPC_LB_POLICY_UNREF(cl, p, r) grpc_lb_policy_unref((cl), (p)) +#define GRPC_LB_POLICY_WEAK_REF(p, r) grpc_lb_policy_weak_ref((p)) +#define GRPC_LB_POLICY_WEAK_UNREF(cl, p, r) grpc_lb_policy_weak_unref((cl), (p)) +void grpc_lb_policy_ref(grpc_lb_policy *policy); +void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); +void grpc_lb_policy_weak_ref(grpc_lb_policy *policy); +void grpc_lb_policy_weak_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); +#endif + +/** called by concrete implementations to initialize the base struct */ +void grpc_lb_policy_init(grpc_lb_policy *policy, + const grpc_lb_policy_vtable *vtable); + +/** Given initial metadata in \a initial_metadata, find an appropriate + target for this rpc, and 'return' it by calling \a on_complete after setting + \a target. + Picking can be asynchronous. Any IO should be done under \a pollent. */ +int grpc_lb_policy_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_polling_entity *pollent, + grpc_metadata_batch *initial_metadata, + uint32_t initial_metadata_flags, + grpc_connected_subchannel **target, + grpc_closure *on_complete); + +void grpc_lb_policy_ping_one(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_closure *closure); + +void grpc_lb_policy_cancel_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_connected_subchannel **target); + +/** Cancel all pending picks which have: + (initial_metadata_flags & initial_metadata_flags_mask) == + initial_metadata_flags_eq */ +void grpc_lb_policy_cancel_picks(grpc_exec_ctx *exec_ctx, + grpc_lb_policy *policy, + uint32_t initial_metadata_flags_mask, + uint32_t initial_metadata_flags_eq); + +/** Try to enter a READY connectivity state */ +void grpc_lb_policy_exit_idle(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); + +/* Call notify when the connectivity state of a channel changes from \a *state. + * Updates \a *state with the new state of the policy */ +void grpc_lb_policy_notify_on_state_change(grpc_exec_ctx *exec_ctx, + grpc_lb_policy *policy, + grpc_connectivity_state *state, + grpc_closure *closure); + +grpc_connectivity_state grpc_lb_policy_check_connectivity( + grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, + grpc_error **connectivity_error); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_H */ diff --git a/src/core/ext/client_channel/lb_policy_factory.c b/src/core/ext/client_channel/lb_policy_factory.c new file mode 100644 index 0000000000..56deac7d3d --- /dev/null +++ b/src/core/ext/client_channel/lb_policy_factory.c @@ -0,0 +1,49 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/lb_policy_factory.h" + +void grpc_lb_policy_factory_ref(grpc_lb_policy_factory* factory) { + factory->vtable->ref(factory); +} + +void grpc_lb_policy_factory_unref(grpc_lb_policy_factory* factory) { + factory->vtable->unref(factory); +} + +grpc_lb_policy* grpc_lb_policy_factory_create_lb_policy( + grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, + grpc_lb_policy_args* args) { + if (factory == NULL) return NULL; + return factory->vtable->create_lb_policy(exec_ctx, factory, args); +} diff --git a/src/core/ext/client_channel/lb_policy_factory.h b/src/core/ext/client_channel/lb_policy_factory.h new file mode 100644 index 0000000000..eedade191d --- /dev/null +++ b/src/core/ext/client_channel/lb_policy_factory.h @@ -0,0 +1,76 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_FACTORY_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_FACTORY_H + +#include "src/core/ext/client_channel/client_channel_factory.h" +#include "src/core/ext/client_channel/lb_policy.h" +#include "src/core/lib/iomgr/resolve_address.h" + +#include "src/core/lib/iomgr/exec_ctx.h" + +typedef struct grpc_lb_policy_factory grpc_lb_policy_factory; +typedef struct grpc_lb_policy_factory_vtable grpc_lb_policy_factory_vtable; + +struct grpc_lb_policy_factory { + const grpc_lb_policy_factory_vtable *vtable; +}; + +typedef struct grpc_lb_policy_args { + grpc_resolved_addresses *addresses; + grpc_client_channel_factory *client_channel_factory; +} grpc_lb_policy_args; + +struct grpc_lb_policy_factory_vtable { + void (*ref)(grpc_lb_policy_factory *factory); + void (*unref)(grpc_lb_policy_factory *factory); + + /** Implementation of grpc_lb_policy_factory_create_lb_policy */ + grpc_lb_policy *(*create_lb_policy)(grpc_exec_ctx *exec_ctx, + grpc_lb_policy_factory *factory, + grpc_lb_policy_args *args); + + /** Name for the LB policy this factory implements */ + const char *name; +}; + +void grpc_lb_policy_factory_ref(grpc_lb_policy_factory *factory); +void grpc_lb_policy_factory_unref(grpc_lb_policy_factory *factory); + +/** Create a lb_policy instance. */ +grpc_lb_policy *grpc_lb_policy_factory_create_lb_policy( + grpc_exec_ctx *exec_ctx, grpc_lb_policy_factory *factory, + grpc_lb_policy_args *args); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_FACTORY_H */ diff --git a/src/core/ext/client_channel/lb_policy_registry.c b/src/core/ext/client_channel/lb_policy_registry.c new file mode 100644 index 0000000000..f46a721f9d --- /dev/null +++ b/src/core/ext/client_channel/lb_policy_registry.c @@ -0,0 +1,83 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/lb_policy_registry.h" + +#include + +#define MAX_POLICIES 10 + +static grpc_lb_policy_factory *g_all_of_the_lb_policies[MAX_POLICIES]; +static int g_number_of_lb_policies = 0; + +void grpc_lb_policy_registry_init(void) { g_number_of_lb_policies = 0; } + +void grpc_lb_policy_registry_shutdown(void) { + int i; + for (i = 0; i < g_number_of_lb_policies; i++) { + grpc_lb_policy_factory_unref(g_all_of_the_lb_policies[i]); + } +} + +void grpc_register_lb_policy(grpc_lb_policy_factory *factory) { + int i; + for (i = 0; i < g_number_of_lb_policies; i++) { + GPR_ASSERT(0 != strcmp(factory->vtable->name, + g_all_of_the_lb_policies[i]->vtable->name)); + } + GPR_ASSERT(g_number_of_lb_policies != MAX_POLICIES); + grpc_lb_policy_factory_ref(factory); + g_all_of_the_lb_policies[g_number_of_lb_policies++] = factory; +} + +static grpc_lb_policy_factory *lookup_factory(const char *name) { + int i; + + if (name == NULL) return NULL; + + for (i = 0; i < g_number_of_lb_policies; i++) { + if (0 == strcmp(name, g_all_of_the_lb_policies[i]->vtable->name)) { + return g_all_of_the_lb_policies[i]; + } + } + + return NULL; +} + +grpc_lb_policy *grpc_lb_policy_create(grpc_exec_ctx *exec_ctx, const char *name, + grpc_lb_policy_args *args) { + grpc_lb_policy_factory *factory = lookup_factory(name); + grpc_lb_policy *lb_policy = + grpc_lb_policy_factory_create_lb_policy(exec_ctx, factory, args); + return lb_policy; +} diff --git a/src/core/ext/client_channel/lb_policy_registry.h b/src/core/ext/client_channel/lb_policy_registry.h new file mode 100644 index 0000000000..301861553a --- /dev/null +++ b/src/core/ext/client_channel/lb_policy_registry.h @@ -0,0 +1,55 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_REGISTRY_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_REGISTRY_H + +#include "src/core/ext/client_channel/lb_policy_factory.h" +#include "src/core/lib/iomgr/exec_ctx.h" + +/** Initialize the registry and set \a default_factory as the factory to be + * returned when no name is provided in a lookup */ +void grpc_lb_policy_registry_init(void); +void grpc_lb_policy_registry_shutdown(void); + +/** Register a LB policy factory. */ +void grpc_register_lb_policy(grpc_lb_policy_factory *factory); + +/** Create a \a grpc_lb_policy instance. + * + * If \a name is NULL, the default factory from \a grpc_lb_policy_registry_init + * will be returned. */ +grpc_lb_policy *grpc_lb_policy_create(grpc_exec_ctx *exec_ctx, const char *name, + grpc_lb_policy_args *args); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_REGISTRY_H */ diff --git a/src/core/ext/client_channel/parse_address.c b/src/core/ext/client_channel/parse_address.c new file mode 100644 index 0000000000..31ca44299b --- /dev/null +++ b/src/core/ext/client_channel/parse_address.c @@ -0,0 +1,137 @@ +/* + * + * 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/ext/client_channel/parse_address.h" + +#include +#include +#ifdef GPR_HAVE_UNIX_SOCKET +#include +#endif + +#include +#include +#include +#include + +#ifdef GPR_HAVE_UNIX_SOCKET +int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) { + struct sockaddr_un *un = (struct sockaddr_un *)addr; + + un->sun_family = AF_UNIX; + strcpy(un->sun_path, uri->path); + *len = strlen(un->sun_path) + sizeof(un->sun_family) + 1; + + return 1; +} +#endif + +int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) { + const char *host_port = uri->path; + char *host; + char *port; + int port_num; + int result = 0; + struct sockaddr_in *in = (struct sockaddr_in *)addr; + + if (*host_port == '/') ++host_port; + if (!gpr_split_host_port(host_port, &host, &port)) { + return 0; + } + + memset(in, 0, sizeof(*in)); + *len = sizeof(*in); + in->sin_family = AF_INET; + if (inet_pton(AF_INET, host, &in->sin_addr) == 0) { + gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host); + goto done; + } + + if (port != NULL) { + if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || + port_num > 65535) { + gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port); + goto done; + } + in->sin_port = htons((uint16_t)port_num); + } else { + gpr_log(GPR_ERROR, "no port given for ipv4 scheme"); + goto done; + } + + result = 1; +done: + gpr_free(host); + gpr_free(port); + return result; +} + +int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) { + const char *host_port = uri->path; + char *host; + char *port; + int port_num; + int result = 0; + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr; + + if (*host_port == '/') ++host_port; + if (!gpr_split_host_port(host_port, &host, &port)) { + return 0; + } + + memset(in6, 0, sizeof(*in6)); + *len = sizeof(*in6); + in6->sin6_family = AF_INET6; + if (inet_pton(AF_INET6, host, &in6->sin6_addr) == 0) { + gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host); + goto done; + } + + if (port != NULL) { + if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || + port_num > 65535) { + gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port); + goto done; + } + in6->sin6_port = htons((uint16_t)port_num); + } else { + gpr_log(GPR_ERROR, "no port given for ipv6 scheme"); + goto done; + } + + result = 1; +done: + gpr_free(host); + gpr_free(port); + return result; +} diff --git a/src/core/ext/client_channel/parse_address.h b/src/core/ext/client_channel/parse_address.h new file mode 100644 index 0000000000..1504d3916d --- /dev/null +++ b/src/core/ext/client_channel/parse_address.h @@ -0,0 +1,56 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_PARSE_ADDRESS_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_PARSE_ADDRESS_H + +#include + +#include "src/core/ext/client_channel/uri_parser.h" +#include "src/core/lib/iomgr/sockaddr.h" + +#ifdef GPR_HAVE_UNIX_SOCKET +/** Populate \a addr and \a len from \a uri, whose path is expected to contain a + * unix socket path. Returns true upon success. */ +int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len); +#endif + +/** Populate /a addr and \a len from \a uri, whose path is expected to contain a + * host:port pair. Returns true upon success. */ +int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len); + +/** Populate /a addr and \a len from \a uri, whose path is expected to contain a + * host:port pair. Returns true upon success. */ +int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_PARSE_ADDRESS_H */ diff --git a/src/core/ext/client_channel/resolver.c b/src/core/ext/client_channel/resolver.c new file mode 100644 index 0000000000..0c26d95f2f --- /dev/null +++ b/src/core/ext/client_channel/resolver.c @@ -0,0 +1,82 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/resolver.h" + +void grpc_resolver_init(grpc_resolver *resolver, + const grpc_resolver_vtable *vtable) { + resolver->vtable = vtable; + gpr_ref_init(&resolver->refs, 1); +} + +#ifdef GRPC_RESOLVER_REFCOUNT_DEBUG +void grpc_resolver_ref(grpc_resolver *resolver, grpc_closure_list *closure_list, + const char *file, int line, const char *reason) { + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "RESOLVER:%p ref %d -> %d %s", + resolver, (int)resolver->refs.count, (int)resolver->refs.count + 1, + reason); +#else +void grpc_resolver_ref(grpc_resolver *resolver) { +#endif + gpr_ref(&resolver->refs); +} + +#ifdef GRPC_RESOLVER_REFCOUNT_DEBUG +void grpc_resolver_unref(grpc_resolver *resolver, + grpc_closure_list *closure_list, const char *file, + int line, const char *reason) { + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "RESOLVER:%p unref %d -> %d %s", + resolver, (int)resolver->refs.count, (int)resolver->refs.count - 1, + reason); +#else +void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver) { +#endif + if (gpr_unref(&resolver->refs)) { + resolver->vtable->destroy(exec_ctx, resolver); + } +} + +void grpc_resolver_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver) { + resolver->vtable->shutdown(exec_ctx, resolver); +} + +void grpc_resolver_channel_saw_error(grpc_exec_ctx *exec_ctx, + grpc_resolver *resolver) { + resolver->vtable->channel_saw_error(exec_ctx, resolver); +} + +void grpc_resolver_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, + grpc_resolver_result **result, + grpc_closure *on_complete) { + resolver->vtable->next(exec_ctx, resolver, result, on_complete); +} diff --git a/src/core/ext/client_channel/resolver.h b/src/core/ext/client_channel/resolver.h new file mode 100644 index 0000000000..017c55bb80 --- /dev/null +++ b/src/core/ext/client_channel/resolver.h @@ -0,0 +1,94 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_H + +#include "src/core/ext/client_channel/resolver_result.h" +#include "src/core/ext/client_channel/subchannel.h" +#include "src/core/lib/iomgr/iomgr.h" + +typedef struct grpc_resolver grpc_resolver; +typedef struct grpc_resolver_vtable grpc_resolver_vtable; + +/** grpc_resolver provides grpc_resolver_result objects to grpc_channel + objects */ +struct grpc_resolver { + const grpc_resolver_vtable *vtable; + gpr_refcount refs; +}; + +struct grpc_resolver_vtable { + void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); + void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); + void (*channel_saw_error)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); + void (*next)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, + grpc_resolver_result **result, grpc_closure *on_complete); +}; + +#ifdef GRPC_RESOLVER_REFCOUNT_DEBUG +#define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p), __FILE__, __LINE__, (r)) +#define GRPC_RESOLVER_UNREF(cl, p, r) \ + grpc_resolver_unref((cl), (p), __FILE__, __LINE__, (r)) +void grpc_resolver_ref(grpc_resolver *policy, const char *file, int line, + const char *reason); +void grpc_resolver_unref(grpc_resolver *policy, grpc_closure_list *closure_list, + const char *file, int line, const char *reason); +#else +#define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p)) +#define GRPC_RESOLVER_UNREF(cl, p, r) grpc_resolver_unref((cl), (p)) +void grpc_resolver_ref(grpc_resolver *policy); +void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *policy); +#endif + +void grpc_resolver_init(grpc_resolver *resolver, + const grpc_resolver_vtable *vtable); + +void grpc_resolver_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); + +/** Notification that the channel has seen an error on some address. + Can be used as a hint that re-resolution is desirable soon. */ +void grpc_resolver_channel_saw_error(grpc_exec_ctx *exec_ctx, + grpc_resolver *resolver); + +/** Get the next client config. Called by the channel to fetch a new + configuration. Expected to set *result with a new configuration, + and then schedule on_complete for execution. + + If resolution is fatally broken, set *result to NULL and + schedule on_complete. */ +void grpc_resolver_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, + grpc_resolver_result **result, + grpc_closure *on_complete); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_H */ diff --git a/src/core/ext/client_channel/resolver_factory.c b/src/core/ext/client_channel/resolver_factory.c new file mode 100644 index 0000000000..7c3d644257 --- /dev/null +++ b/src/core/ext/client_channel/resolver_factory.c @@ -0,0 +1,55 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/resolver_factory.h" + +void grpc_resolver_factory_ref(grpc_resolver_factory* factory) { + factory->vtable->ref(factory); +} + +void grpc_resolver_factory_unref(grpc_resolver_factory* factory) { + factory->vtable->unref(factory); +} + +/** Create a resolver instance for a name */ +grpc_resolver* grpc_resolver_factory_create_resolver( + grpc_resolver_factory* factory, grpc_resolver_args* args) { + if (factory == NULL) return NULL; + return factory->vtable->create_resolver(factory, args); +} + +char* grpc_resolver_factory_get_default_authority( + grpc_resolver_factory* factory, grpc_uri* uri) { + if (factory == NULL) return NULL; + return factory->vtable->get_default_authority(factory, uri); +} diff --git a/src/core/ext/client_channel/resolver_factory.h b/src/core/ext/client_channel/resolver_factory.h new file mode 100644 index 0000000000..1068acfdd4 --- /dev/null +++ b/src/core/ext/client_channel/resolver_factory.h @@ -0,0 +1,82 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_FACTORY_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_FACTORY_H + +#include "src/core/ext/client_channel/client_channel_factory.h" +#include "src/core/ext/client_channel/resolver.h" +#include "src/core/ext/client_channel/uri_parser.h" + +typedef struct grpc_resolver_factory grpc_resolver_factory; +typedef struct grpc_resolver_factory_vtable grpc_resolver_factory_vtable; + +/** grpc_resolver provides grpc_resolver_result objects to grpc_channel + objects */ +struct grpc_resolver_factory { + const grpc_resolver_factory_vtable *vtable; +}; + +typedef struct grpc_resolver_args { + grpc_uri *uri; + grpc_client_channel_factory *client_channel_factory; +} grpc_resolver_args; + +struct grpc_resolver_factory_vtable { + void (*ref)(grpc_resolver_factory *factory); + void (*unref)(grpc_resolver_factory *factory); + + /** Implementation of grpc_resolver_factory_create_resolver */ + grpc_resolver *(*create_resolver)(grpc_resolver_factory *factory, + grpc_resolver_args *args); + + /** Implementation of grpc_resolver_factory_get_default_authority */ + char *(*get_default_authority)(grpc_resolver_factory *factory, grpc_uri *uri); + + /** URI scheme that this factory implements */ + const char *scheme; +}; + +void grpc_resolver_factory_ref(grpc_resolver_factory *resolver); +void grpc_resolver_factory_unref(grpc_resolver_factory *resolver); + +/** Create a resolver instance for a name */ +grpc_resolver *grpc_resolver_factory_create_resolver( + grpc_resolver_factory *factory, grpc_resolver_args *args); + +/** Return a (freshly allocated with gpr_malloc) string representing + the default authority to use for this scheme. */ +char *grpc_resolver_factory_get_default_authority( + grpc_resolver_factory *factory, grpc_uri *uri); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_FACTORY_H */ diff --git a/src/core/ext/client_channel/resolver_registry.c b/src/core/ext/client_channel/resolver_registry.c new file mode 100644 index 0000000000..5827819efb --- /dev/null +++ b/src/core/ext/client_channel/resolver_registry.c @@ -0,0 +1,151 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/resolver_registry.h" + +#include + +#include +#include +#include + +#define MAX_RESOLVERS 10 + +static grpc_resolver_factory *g_all_of_the_resolvers[MAX_RESOLVERS]; +static int g_number_of_resolvers = 0; + +static char *g_default_resolver_prefix; + +void grpc_resolver_registry_init(const char *default_resolver_prefix) { + g_default_resolver_prefix = gpr_strdup(default_resolver_prefix); +} + +void grpc_resolver_registry_shutdown(void) { + int i; + for (i = 0; i < g_number_of_resolvers; i++) { + grpc_resolver_factory_unref(g_all_of_the_resolvers[i]); + } + gpr_free(g_default_resolver_prefix); + // FIXME(ctiller): this should live in grpc_resolver_registry_init, + // however that would have the client_channel plugin call this AFTER we start + // registering resolvers from third party plugins, and so they'd never show + // up. + // We likely need some kind of dependency system for plugins.... what form + // that takes is TBD. + g_number_of_resolvers = 0; +} + +void grpc_register_resolver_type(grpc_resolver_factory *factory) { + int i; + for (i = 0; i < g_number_of_resolvers; i++) { + GPR_ASSERT(0 != strcmp(factory->vtable->scheme, + g_all_of_the_resolvers[i]->vtable->scheme)); + } + GPR_ASSERT(g_number_of_resolvers != MAX_RESOLVERS); + grpc_resolver_factory_ref(factory); + g_all_of_the_resolvers[g_number_of_resolvers++] = factory; +} + +static grpc_resolver_factory *lookup_factory(const char *name) { + int i; + + for (i = 0; i < g_number_of_resolvers; i++) { + if (0 == strcmp(name, g_all_of_the_resolvers[i]->vtable->scheme)) { + return g_all_of_the_resolvers[i]; + } + } + + return NULL; +} + +grpc_resolver_factory *grpc_resolver_factory_lookup(const char *name) { + grpc_resolver_factory *f = lookup_factory(name); + if (f) grpc_resolver_factory_ref(f); + return f; +} + +static grpc_resolver_factory *lookup_factory_by_uri(grpc_uri *uri) { + if (!uri) return NULL; + return lookup_factory(uri->scheme); +} + +static grpc_resolver_factory *resolve_factory(const char *target, + grpc_uri **uri) { + char *tmp; + grpc_resolver_factory *factory = NULL; + + GPR_ASSERT(uri != NULL); + *uri = grpc_uri_parse(target, 1); + factory = lookup_factory_by_uri(*uri); + if (factory == NULL) { + if (g_default_resolver_prefix != NULL) { + grpc_uri_destroy(*uri); + gpr_asprintf(&tmp, "%s%s", g_default_resolver_prefix, target); + *uri = grpc_uri_parse(tmp, 1); + factory = lookup_factory_by_uri(*uri); + if (factory == NULL) { + grpc_uri_destroy(grpc_uri_parse(target, 0)); + grpc_uri_destroy(grpc_uri_parse(tmp, 0)); + gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target, + tmp); + } + gpr_free(tmp); + } else { + grpc_uri_destroy(grpc_uri_parse(target, 0)); + gpr_log(GPR_ERROR, "don't know how to resolve '%s'", target); + } + } + return factory; +} + +grpc_resolver *grpc_resolver_create( + const char *target, grpc_client_channel_factory *client_channel_factory) { + grpc_uri *uri = NULL; + grpc_resolver_factory *factory = resolve_factory(target, &uri); + grpc_resolver *resolver; + grpc_resolver_args args; + memset(&args, 0, sizeof(args)); + args.uri = uri; + args.client_channel_factory = client_channel_factory; + resolver = grpc_resolver_factory_create_resolver(factory, &args); + grpc_uri_destroy(uri); + return resolver; +} + +char *grpc_get_default_authority(const char *target) { + grpc_uri *uri = NULL; + grpc_resolver_factory *factory = resolve_factory(target, &uri); + char *authority = grpc_resolver_factory_get_default_authority(factory, uri); + grpc_uri_destroy(uri); + return authority; +} diff --git a/src/core/ext/client_channel/resolver_registry.h b/src/core/ext/client_channel/resolver_registry.h new file mode 100644 index 0000000000..cdf5dff8ba --- /dev/null +++ b/src/core/ext/client_channel/resolver_registry.h @@ -0,0 +1,69 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_REGISTRY_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_REGISTRY_H + +#include "src/core/ext/client_channel/resolver_factory.h" + +void grpc_resolver_registry_init(const char *default_prefix); +void grpc_resolver_registry_shutdown(void); + +/** Register a resolver type. + URI's of \a scheme will be resolved with the given resolver. + If \a priority is greater than zero, then the resolver will be eligible + to resolve names that are passed in with no scheme. Higher priority + resolvers will be tried before lower priority schemes. */ +void grpc_register_resolver_type(grpc_resolver_factory *factory); + +/** Create a resolver given \a target. + First tries to parse \a target as a URI. If this succeeds, tries + to locate a registered resolver factory based on the URI scheme. + If parsing or location fails, prefixes default_prefix from + grpc_resolver_registry_init to target, and tries again (if default_prefix + was not NULL). + If a resolver factory was found, use it to instantiate a resolver and + return it. + If a resolver factory was not found, return NULL. */ +grpc_resolver *grpc_resolver_create( + const char *target, grpc_client_channel_factory *client_channel_factory); + +/** Find a resolver factory given a name and return an (owned-by-the-caller) + * reference to it */ +grpc_resolver_factory *grpc_resolver_factory_lookup(const char *name); + +/** Given a target, return a (freshly allocated with gpr_malloc) string + representing the default authority to pass from a client. */ +char *grpc_get_default_authority(const char *target); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_REGISTRY_H */ diff --git a/src/core/ext/client_channel/resolver_result.c b/src/core/ext/client_channel/resolver_result.c new file mode 100644 index 0000000000..3a4162b0ff --- /dev/null +++ b/src/core/ext/client_channel/resolver_result.c @@ -0,0 +1,75 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/resolver_result.h" + +#include + +#include + +struct grpc_resolver_result { + gpr_refcount refs; + grpc_lb_policy *lb_policy; +}; + +grpc_resolver_result *grpc_resolver_result_create() { + grpc_resolver_result *c = gpr_malloc(sizeof(*c)); + memset(c, 0, sizeof(*c)); + gpr_ref_init(&c->refs, 1); + return c; +} + +void grpc_resolver_result_ref(grpc_resolver_result *c) { gpr_ref(&c->refs); } + +void grpc_resolver_result_unref(grpc_exec_ctx *exec_ctx, + grpc_resolver_result *c) { + if (gpr_unref(&c->refs)) { + if (c->lb_policy != NULL) { + GRPC_LB_POLICY_UNREF(exec_ctx, c->lb_policy, "resolver_result"); + } + gpr_free(c); + } +} + +void grpc_resolver_result_set_lb_policy(grpc_resolver_result *c, + grpc_lb_policy *lb_policy) { + GPR_ASSERT(c->lb_policy == NULL); + if (lb_policy) { + GRPC_LB_POLICY_REF(lb_policy, "resolver_result"); + } + c->lb_policy = lb_policy; +} + +grpc_lb_policy *grpc_resolver_result_get_lb_policy(grpc_resolver_result *c) { + return c->lb_policy; +} diff --git a/src/core/ext/client_channel/resolver_result.h b/src/core/ext/client_channel/resolver_result.h new file mode 100644 index 0000000000..258ac7c36f --- /dev/null +++ b/src/core/ext/client_channel/resolver_result.h @@ -0,0 +1,52 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H + +#include "src/core/ext/client_channel/lb_policy.h" + +/** Results reported from a grpc_resolver. */ +typedef struct grpc_resolver_result grpc_resolver_result; + +grpc_resolver_result *grpc_resolver_result_create(); +void grpc_resolver_result_ref(grpc_resolver_result *client_config); +void grpc_resolver_result_unref(grpc_exec_ctx *exec_ctx, + grpc_resolver_result *client_config); + +void grpc_resolver_result_set_lb_policy(grpc_resolver_result *client_config, + grpc_lb_policy *lb_policy); +grpc_lb_policy *grpc_resolver_result_get_lb_policy( + grpc_resolver_result *client_config); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H */ diff --git a/src/core/ext/client_channel/subchannel.c b/src/core/ext/client_channel/subchannel.c new file mode 100644 index 0000000000..c97ff39e40 --- /dev/null +++ b/src/core/ext/client_channel/subchannel.c @@ -0,0 +1,730 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/subchannel.h" + +#include + +#include +#include + +#include "src/core/ext/client_channel/client_channel.h" +#include "src/core/ext/client_channel/initial_connect_string.h" +#include "src/core/ext/client_channel/subchannel_index.h" +#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/channel/connected_channel.h" +#include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/profiling/timers.h" +#include "src/core/lib/support/backoff.h" +#include "src/core/lib/surface/channel.h" +#include "src/core/lib/surface/channel_init.h" +#include "src/core/lib/transport/connectivity_state.h" + +#define INTERNAL_REF_BITS 16 +#define STRONG_REF_MASK (~(gpr_atm)((1 << INTERNAL_REF_BITS) - 1)) + +#define GRPC_SUBCHANNEL_MIN_CONNECT_TIMEOUT_SECONDS 20 +#define GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS 1 +#define GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER 1.6 +#define GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS 120 +#define GRPC_SUBCHANNEL_RECONNECT_JITTER 0.2 + +#define GET_CONNECTED_SUBCHANNEL(subchannel, barrier) \ + ((grpc_connected_subchannel *)(gpr_atm_##barrier##_load( \ + &(subchannel)->connected_subchannel))) + +typedef struct { + grpc_closure closure; + grpc_subchannel *subchannel; + grpc_connectivity_state connectivity_state; +} state_watcher; + +typedef struct external_state_watcher { + grpc_subchannel *subchannel; + grpc_pollset_set *pollset_set; + grpc_closure *notify; + grpc_closure closure; + struct external_state_watcher *next; + struct external_state_watcher *prev; +} external_state_watcher; + +struct grpc_subchannel { + grpc_connector *connector; + + /** refcount + - lower INTERNAL_REF_BITS bits are for internal references: + these do not keep the subchannel open. + - upper remaining bits are for public references: these do + keep the subchannel open */ + gpr_atm ref_pair; + + /** non-transport related channel filters */ + const grpc_channel_filter **filters; + size_t num_filters; + /** channel arguments */ + grpc_channel_args *args; + /** address to connect to */ + struct sockaddr *addr; + size_t addr_len; + + grpc_subchannel_key *key; + + /** initial string to send to peer */ + gpr_slice initial_connect_string; + + /** set during connection */ + grpc_connect_out_args connecting_result; + + /** callback for connection finishing */ + grpc_closure connected; + + /** pollset_set tracking who's interested in a connection + being setup */ + grpc_pollset_set *pollset_set; + + /** active connection, or null; of type grpc_connected_subchannel */ + gpr_atm connected_subchannel; + + /** mutex protecting remaining elements */ + gpr_mu mu; + + /** have we seen a disconnection? */ + int disconnected; + /** are we connecting */ + int connecting; + /** connectivity state tracking */ + grpc_connectivity_state_tracker state_tracker; + + external_state_watcher root_external_state_watcher; + + /** next connect attempt time */ + gpr_timespec next_attempt; + /** backoff state */ + gpr_backoff backoff_state; + /** do we have an active alarm? */ + int have_alarm; + /** our alarm */ + grpc_timer alarm; +}; + +struct grpc_subchannel_call { + grpc_connected_subchannel *connection; +}; + +#define SUBCHANNEL_CALL_TO_CALL_STACK(call) ((grpc_call_stack *)((call) + 1)) +#define CHANNEL_STACK_FROM_CONNECTION(con) ((grpc_channel_stack *)(con)) +#define CALLSTACK_TO_SUBCHANNEL_CALL(callstack) \ + (((grpc_subchannel_call *)(callstack)) - 1) + +static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *subchannel, + grpc_error *error); + +#ifdef GRPC_STREAM_REFCOUNT_DEBUG +#define REF_REASON reason +#define REF_LOG(name, p) \ + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "%s: %p ref %d -> %d %s", \ + (name), (p), (p)->refs.count, (p)->refs.count + 1, reason) +#define UNREF_LOG(name, p) \ + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "%s: %p unref %d -> %d %s", \ + (name), (p), (p)->refs.count, (p)->refs.count - 1, reason) +#define REF_MUTATE_EXTRA_ARGS \ + GRPC_SUBCHANNEL_REF_EXTRA_ARGS, const char *purpose +#define REF_MUTATE_PURPOSE(x) , file, line, reason, x +#else +#define REF_REASON "" +#define REF_LOG(name, p) \ + do { \ + } while (0) +#define UNREF_LOG(name, p) \ + do { \ + } while (0) +#define REF_MUTATE_EXTRA_ARGS +#define REF_MUTATE_PURPOSE(x) +#endif + +/* + * connection implementation + */ + +static void connection_destroy(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error) { + grpc_connected_subchannel *c = arg; + grpc_channel_stack_destroy(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c)); + gpr_free(c); +} + +void grpc_connected_subchannel_ref( + grpc_connected_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { + GRPC_CHANNEL_STACK_REF(CHANNEL_STACK_FROM_CONNECTION(c), REF_REASON); +} + +void grpc_connected_subchannel_unref(grpc_exec_ctx *exec_ctx, + grpc_connected_subchannel *c + GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { + GRPC_CHANNEL_STACK_UNREF(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c), + REF_REASON); +} + +/* + * grpc_subchannel implementation + */ + +static void subchannel_destroy(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error) { + grpc_subchannel *c = arg; + gpr_free((void *)c->filters); + grpc_channel_args_destroy(c->args); + gpr_free(c->addr); + gpr_slice_unref(c->initial_connect_string); + 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); +} + +static gpr_atm ref_mutate(grpc_subchannel *c, gpr_atm delta, + int barrier REF_MUTATE_EXTRA_ARGS) { + gpr_atm old_val = barrier ? gpr_atm_full_fetch_add(&c->ref_pair, delta) + : gpr_atm_no_barrier_fetch_add(&c->ref_pair, delta); +#ifdef GRPC_STREAM_REFCOUNT_DEBUG + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, + "SUBCHANNEL: %p % 12s 0x%08x -> 0x%08x [%s]", c, purpose, old_val, + old_val + delta, reason); +#endif + return old_val; +} + +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; +} + +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; + grpc_connector_shutdown(exec_ctx, c->connector); + con = GET_CONNECTED_SUBCHANNEL(c, no_barrier); + if (con != NULL) { + GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, con, "connection"); + gpr_atm_no_barrier_store(&c->connected_subchannel, (gpr_atm)0xdeadbeef); + } + gpr_mu_unlock(&c->mu); +} + +void grpc_subchannel_unref(grpc_exec_ctx *exec_ctx, + grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { + gpr_atm old_refs; + old_refs = ref_mutate(c, (gpr_atm)1 - (gpr_atm)(1 << INTERNAL_REF_BITS), + 1 REF_MUTATE_PURPOSE("STRONG_UNREF")); + if ((old_refs & STRONG_REF_MASK) == (1 << INTERNAL_REF_BITS)) { + disconnect(exec_ctx, c); + } + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "strong-unref"); +} + +void grpc_subchannel_weak_unref(grpc_exec_ctx *exec_ctx, + grpc_subchannel *c + GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { + gpr_atm old_refs; + old_refs = ref_mutate(c, -(gpr_atm)1, 1 REF_MUTATE_PURPOSE("WEAK_UNREF")); + if (old_refs == 1) { + grpc_exec_ctx_sched(exec_ctx, grpc_closure_create(subchannel_destroy, c), + GRPC_ERROR_NONE, NULL); + } +} + +grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, + grpc_connector *connector, + grpc_subchannel_args *args) { + 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); + c->num_filters = args->filter_count; + if (c->num_filters > 0) { + c->filters = gpr_malloc(sizeof(grpc_channel_filter *) * c->num_filters); + memcpy((void *)c->filters, args->filters, + sizeof(grpc_channel_filter *) * c->num_filters); + } else { + c->filters = NULL; + } + c->addr = gpr_malloc(args->addr_len); + if (args->addr_len) memcpy(c->addr, args->addr, args->addr_len); + c->pollset_set = grpc_pollset_set_create(); + c->addr_len = args->addr_len; + grpc_set_initial_connect_string(&c->addr, &c->addr_len, + &c->initial_connect_string); + c->args = grpc_channel_args_copy(args->args); + c->root_external_state_watcher.next = c->root_external_state_watcher.prev = + &c->root_external_state_watcher; + grpc_closure_init(&c->connected, subchannel_connected, c); + grpc_connectivity_state_init(&c->state_tracker, GRPC_CHANNEL_IDLE, + "subchannel"); + gpr_backoff_init(&c->backoff_state, + GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER, + GRPC_SUBCHANNEL_RECONNECT_JITTER, + GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS * 1000, + GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS * 1000); + if (c->args) { + for (size_t i = 0; i < c->args->num_args; i++) { + if (0 == strcmp(c->args->args[i].key, + "grpc.testing.fixed_reconnect_backoff")) { + GPR_ASSERT(c->args->args[i].type == GRPC_ARG_INTEGER); + gpr_backoff_init(&c->backoff_state, 1.0, 0.0, + c->args->args[i].value.integer, + c->args->args[i].value.integer); + } + if (0 == + strcmp(c->args->args[i].key, GRPC_ARG_MAX_RECONNECT_BACKOFF_MS)) { + if (c->args->args[i].type == GRPC_ARG_INTEGER) { + if (c->args->args[i].value.integer >= 0) { + gpr_backoff_init( + &c->backoff_state, GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER, + GRPC_SUBCHANNEL_RECONNECT_JITTER, + GPR_MIN(c->args->args[i].value.integer, + GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS * 1000), + c->args->args[i].value.integer); + } else { + gpr_log(GPR_ERROR, GRPC_ARG_MAX_RECONNECT_BACKOFF_MS + " : must be non-negative"); + } + } else { + gpr_log(GPR_ERROR, + GRPC_ARG_MAX_RECONNECT_BACKOFF_MS " : must be an integer"); + } + } + } + } + gpr_mu_init(&c->mu); + + return grpc_subchannel_index_register(exec_ctx, key, c); +} + +static void continue_connect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) { + grpc_connect_in_args args; + + args.interested_parties = c->pollset_set; + args.addr = c->addr; + args.addr_len = c->addr_len; + args.deadline = c->next_attempt; + args.channel_args = c->args; + args.initial_connect_string = c->initial_connect_string; + + grpc_connectivity_state_set(exec_ctx, &c->state_tracker, + GRPC_CHANNEL_CONNECTING, GRPC_ERROR_NONE, + "state_change"); + grpc_connector_connect(exec_ctx, c->connector, &args, &c->connecting_result, + &c->connected); +} + +static void start_connect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) { + c->next_attempt = + gpr_backoff_begin(&c->backoff_state, gpr_now(GPR_CLOCK_MONOTONIC)); + continue_connect(exec_ctx, c); +} + +grpc_connectivity_state grpc_subchannel_check_connectivity(grpc_subchannel *c, + grpc_error **error) { + grpc_connectivity_state state; + gpr_mu_lock(&c->mu); + state = grpc_connectivity_state_check(&c->state_tracker, error); + gpr_mu_unlock(&c->mu); + return state; +} + +static void on_external_state_watcher_done(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error) { + external_state_watcher *w = arg; + grpc_closure *follow_up = w->notify; + if (w->pollset_set != NULL) { + grpc_pollset_set_del_pollset_set(exec_ctx, w->subchannel->pollset_set, + w->pollset_set); + } + gpr_mu_lock(&w->subchannel->mu); + w->next->prev = w->prev; + w->prev->next = w->next; + gpr_mu_unlock(&w->subchannel->mu); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, w->subchannel, "external_state_watcher"); + gpr_free(w); + follow_up->cb(exec_ctx, follow_up->cb_arg, error); +} + +void grpc_subchannel_notify_on_state_change( + grpc_exec_ctx *exec_ctx, grpc_subchannel *c, + grpc_pollset_set *interested_parties, grpc_connectivity_state *state, + grpc_closure *notify) { + external_state_watcher *w; + + if (state == NULL) { + gpr_mu_lock(&c->mu); + for (w = c->root_external_state_watcher.next; + w != &c->root_external_state_watcher; w = w->next) { + if (w->notify == notify) { + grpc_connectivity_state_notify_on_state_change( + exec_ctx, &c->state_tracker, NULL, &w->closure); + } + } + gpr_mu_unlock(&c->mu); + } else { + w = gpr_malloc(sizeof(*w)); + w->subchannel = c; + w->pollset_set = interested_parties; + w->notify = notify; + grpc_closure_init(&w->closure, on_external_state_watcher_done, w); + if (interested_parties != NULL) { + grpc_pollset_set_add_pollset_set(exec_ctx, c->pollset_set, + interested_parties); + } + GRPC_SUBCHANNEL_WEAK_REF(c, "external_state_watcher"); + gpr_mu_lock(&c->mu); + w->next = &c->root_external_state_watcher; + w->prev = w->next->prev; + w->next->prev = w->prev->next = w; + if (grpc_connectivity_state_notify_on_state_change( + exec_ctx, &c->state_tracker, state, &w->closure)) { + c->connecting = 1; + /* released by connection */ + GRPC_SUBCHANNEL_WEAK_REF(c, "connecting"); + start_connect(exec_ctx, c); + } + gpr_mu_unlock(&c->mu); + } +} + +void grpc_connected_subchannel_process_transport_op( + grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, + grpc_transport_op *op) { + grpc_channel_stack *channel_stack = CHANNEL_STACK_FROM_CONNECTION(con); + grpc_channel_element *top_elem = grpc_channel_stack_element(channel_stack, 0); + top_elem->filter->start_transport_op(exec_ctx, top_elem, op); +} + +static void subchannel_on_child_state_changed(grpc_exec_ctx *exec_ctx, void *p, + grpc_error *error) { + state_watcher *sw = p; + grpc_subchannel *c = sw->subchannel; + gpr_mu *mu = &c->mu; + + gpr_mu_lock(mu); + + /* if we failed just leave this closure */ + if (sw->connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) { + /* any errors on a subchannel ==> we're done, create a new one */ + sw->connectivity_state = GRPC_CHANNEL_SHUTDOWN; + } + grpc_connectivity_state_set(exec_ctx, &c->state_tracker, + sw->connectivity_state, GRPC_ERROR_REF(error), + "reflect_child"); + if (sw->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { + grpc_connected_subchannel_notify_on_state_change( + exec_ctx, GET_CONNECTED_SUBCHANNEL(c, no_barrier), NULL, + &sw->connectivity_state, &sw->closure); + GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher"); + sw = NULL; + } + + gpr_mu_unlock(mu); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "state_watcher"); + gpr_free(sw); +} + +static void connected_subchannel_state_op(grpc_exec_ctx *exec_ctx, + grpc_connected_subchannel *con, + grpc_pollset_set *interested_parties, + grpc_connectivity_state *state, + grpc_closure *closure) { + grpc_transport_op op; + grpc_channel_element *elem; + memset(&op, 0, sizeof(op)); + op.connectivity_state = state; + op.on_connectivity_state_change = closure; + op.bind_pollset_set = interested_parties; + elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); + elem->filter->start_transport_op(exec_ctx, elem, &op); +} + +void grpc_connected_subchannel_notify_on_state_change( + grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, + grpc_pollset_set *interested_parties, grpc_connectivity_state *state, + grpc_closure *closure) { + connected_subchannel_state_op(exec_ctx, con, interested_parties, state, + closure); +} + +void grpc_connected_subchannel_ping(grpc_exec_ctx *exec_ctx, + grpc_connected_subchannel *con, + grpc_closure *closure) { + grpc_transport_op op; + grpc_channel_element *elem; + memset(&op, 0, sizeof(op)); + op.send_ping = closure; + elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); + elem->filter->start_transport_op(exec_ctx, elem, &op); +} + +static void publish_transport_locked(grpc_exec_ctx *exec_ctx, + grpc_subchannel *c) { + grpc_connected_subchannel *con; + grpc_channel_stack *stk; + state_watcher *sw_subchannel; + + /* construct channel stack */ + grpc_channel_stack_builder *builder = grpc_channel_stack_builder_create(); + grpc_channel_stack_builder_set_channel_arguments( + builder, c->connecting_result.channel_args); + grpc_channel_stack_builder_set_transport(builder, + c->connecting_result.transport); + + if (grpc_channel_init_create_stack(exec_ctx, builder, + GRPC_CLIENT_SUBCHANNEL)) { + con = grpc_channel_stack_builder_finish(exec_ctx, builder, 0, 1, + connection_destroy, NULL); + } else { + grpc_channel_stack_builder_destroy(builder); + abort(); /* TODO(ctiller): what to do here (previously we just crashed) */ + } + stk = CHANNEL_STACK_FROM_CONNECTION(con); + memset(&c->connecting_result, 0, sizeof(c->connecting_result)); + + /* initialize state watcher */ + sw_subchannel = gpr_malloc(sizeof(*sw_subchannel)); + sw_subchannel->subchannel = c; + sw_subchannel->connectivity_state = GRPC_CHANNEL_READY; + grpc_closure_init(&sw_subchannel->closure, subchannel_on_child_state_changed, + sw_subchannel); + + if (c->disconnected) { + gpr_free(sw_subchannel); + grpc_channel_stack_destroy(exec_ctx, stk); + gpr_free(con); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); + return; + } + + /* publish */ + /* TODO(ctiller): this full barrier seems to clear up a TSAN failure. + I'd have expected the rel_cas below to be enough, but + seemingly it's not. + Re-evaluate if we really need this. */ + gpr_atm_full_barrier(); + GPR_ASSERT(gpr_atm_rel_cas(&c->connected_subchannel, 0, (gpr_atm)con)); + c->connecting = 0; + + /* setup subchannel watching connected subchannel for changes; subchannel + ref + for connecting is donated + to the state watcher */ + GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher"); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); + grpc_connected_subchannel_notify_on_state_change( + exec_ctx, con, c->pollset_set, &sw_subchannel->connectivity_state, + &sw_subchannel->closure); + + /* signal completion */ + grpc_connectivity_state_set(exec_ctx, &c->state_tracker, GRPC_CHANNEL_READY, + GRPC_ERROR_NONE, "connected"); +} + +static void on_alarm(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { + grpc_subchannel *c = arg; + gpr_mu_lock(&c->mu); + c->have_alarm = 0; + if (c->disconnected) { + error = GRPC_ERROR_CREATE_REFERENCING("Disconnected", &error, 1); + } else { + GRPC_ERROR_REF(error); + } + if (error == GRPC_ERROR_NONE) { + gpr_log(GPR_INFO, "Failed to connect to channel, retrying"); + c->next_attempt = + gpr_backoff_step(&c->backoff_state, gpr_now(GPR_CLOCK_MONOTONIC)); + continue_connect(exec_ctx, c); + gpr_mu_unlock(&c->mu); + } else { + gpr_mu_unlock(&c->mu); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); + } + GRPC_ERROR_UNREF(error); +} + +static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error) { + grpc_subchannel *c = arg; + grpc_channel_args *delete_channel_args = c->connecting_result.channel_args; + + GRPC_SUBCHANNEL_WEAK_REF(c, "connected"); + gpr_mu_lock(&c->mu); + if (c->connecting_result.transport != NULL) { + publish_transport_locked(exec_ctx, c); + } else if (c->disconnected) { + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); + } else { + gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); + GPR_ASSERT(!c->have_alarm); + c->have_alarm = 1; + grpc_connectivity_state_set( + exec_ctx, &c->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, + GRPC_ERROR_CREATE_REFERENCING("Connect Failed", &error, 1), + "connect_failed"); + gpr_timespec time_til_next = gpr_time_sub(c->next_attempt, now); + const char *errmsg = grpc_error_string(error); + gpr_log(GPR_INFO, "Connect failed: %s", errmsg); + if (gpr_time_cmp(time_til_next, gpr_time_0(time_til_next.clock_type)) <= + 0) { + gpr_log(GPR_INFO, "Retry immediately"); + } else { + gpr_log(GPR_INFO, "Retry in %" PRId64 ".%09d seconds", + time_til_next.tv_sec, time_til_next.tv_nsec); + } + grpc_timer_init(exec_ctx, &c->alarm, c->next_attempt, on_alarm, c, now); + grpc_error_free_string(errmsg); + } + gpr_mu_unlock(&c->mu); + GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); + grpc_channel_args_destroy(delete_channel_args); +} + +/* + * grpc_subchannel_call implementation + */ + +static void subchannel_call_destroy(grpc_exec_ctx *exec_ctx, void *call, + grpc_error *error) { + grpc_subchannel_call *c = call; + GPR_TIMER_BEGIN("grpc_subchannel_call_unref.destroy", 0); + grpc_connected_subchannel *connection = c->connection; + grpc_call_stack_destroy(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), NULL, c); + GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, connection, "subchannel_call"); + GPR_TIMER_END("grpc_subchannel_call_unref.destroy", 0); +} + +void grpc_subchannel_call_ref( + grpc_subchannel_call *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { + GRPC_CALL_STACK_REF(SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); +} + +void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, + grpc_subchannel_call *c + GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { + GRPC_CALL_STACK_UNREF(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); +} + +char *grpc_subchannel_call_get_peer(grpc_exec_ctx *exec_ctx, + grpc_subchannel_call *call) { + grpc_call_stack *call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call); + grpc_call_element *top_elem = grpc_call_stack_element(call_stack, 0); + return top_elem->filter->get_peer(exec_ctx, top_elem); +} + +void grpc_subchannel_call_process_op(grpc_exec_ctx *exec_ctx, + grpc_subchannel_call *call, + grpc_transport_stream_op *op) { + GPR_TIMER_BEGIN("grpc_subchannel_call_process_op", 0); + grpc_call_stack *call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call); + grpc_call_element *top_elem = grpc_call_stack_element(call_stack, 0); + top_elem->filter->start_transport_stream_op(exec_ctx, top_elem, op); + GPR_TIMER_END("grpc_subchannel_call_process_op", 0); +} + +grpc_connected_subchannel *grpc_subchannel_get_connected_subchannel( + grpc_subchannel *c) { + return GET_CONNECTED_SUBCHANNEL(c, acq); +} + +grpc_error *grpc_connected_subchannel_create_call( + grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, + grpc_polling_entity *pollent, grpc_subchannel_call **call) { + grpc_channel_stack *chanstk = CHANNEL_STACK_FROM_CONNECTION(con); + *call = gpr_malloc(sizeof(grpc_subchannel_call) + chanstk->call_stack_size); + grpc_call_stack *callstk = SUBCHANNEL_CALL_TO_CALL_STACK(*call); + (*call)->connection = con; // Ref is added below. + grpc_error *error = + grpc_call_stack_init(exec_ctx, chanstk, 1, subchannel_call_destroy, *call, + NULL, NULL, callstk); + if (error != GRPC_ERROR_NONE) { + const char *error_string = grpc_error_string(error); + gpr_log(GPR_ERROR, "error: %s", error_string); + grpc_error_free_string(error_string); + gpr_free(*call); + return error; + } + GRPC_CONNECTED_SUBCHANNEL_REF(con, "subchannel_call"); + grpc_call_stack_set_pollset_or_pollset_set(exec_ctx, callstk, pollent); + return GRPC_ERROR_NONE; +} + +grpc_call_stack *grpc_subchannel_call_get_call_stack( + grpc_subchannel_call *subchannel_call) { + return SUBCHANNEL_CALL_TO_CALL_STACK(subchannel_call); +} diff --git a/src/core/ext/client_channel/subchannel.h b/src/core/ext/client_channel/subchannel.h new file mode 100644 index 0000000000..b4183b459f --- /dev/null +++ b/src/core/ext/client_channel/subchannel.h @@ -0,0 +1,175 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_H + +#include "src/core/ext/client_channel/connector.h" +#include "src/core/lib/channel/channel_stack.h" +#include "src/core/lib/iomgr/polling_entity.h" +#include "src/core/lib/transport/connectivity_state.h" + +/** A (sub-)channel that knows how to connect to exactly one target + address. Provides a target for load balancing. */ +typedef struct grpc_subchannel grpc_subchannel; +typedef struct grpc_connected_subchannel grpc_connected_subchannel; +typedef struct grpc_subchannel_call grpc_subchannel_call; +typedef struct grpc_subchannel_args grpc_subchannel_args; + +#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) \ + grpc_subchannel_weak_ref((p), __FILE__, __LINE__, (r)) +#define GRPC_SUBCHANNEL_WEAK_UNREF(cl, p, r) \ + grpc_subchannel_weak_unref((cl), (p), __FILE__, __LINE__, (r)) +#define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) \ + grpc_connected_subchannel_ref((p), __FILE__, __LINE__, (r)) +#define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ + grpc_connected_subchannel_unref((cl), (p), __FILE__, __LINE__, (r)) +#define GRPC_SUBCHANNEL_CALL_REF(p, r) \ + grpc_subchannel_call_ref((p), __FILE__, __LINE__, (r)) +#define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ + grpc_subchannel_call_unref((cl), (p), __FILE__, __LINE__, (r)) +#define GRPC_SUBCHANNEL_REF_EXTRA_ARGS \ + , 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) \ + grpc_subchannel_weak_unref((cl), (p)) +#define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) grpc_connected_subchannel_ref((p)) +#define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ + grpc_connected_subchannel_unref((cl), (p)) +#define GRPC_SUBCHANNEL_CALL_REF(p, r) grpc_subchannel_call_ref((p)) +#define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ + grpc_subchannel_call_unref((cl), (p)) +#define GRPC_SUBCHANNEL_REF_EXTRA_ARGS +#endif + +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); +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); +void grpc_connected_subchannel_ref( + grpc_connected_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_connected_subchannel_unref(grpc_exec_ctx *exec_ctx, + grpc_connected_subchannel *channel + GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_subchannel_call_ref( + grpc_subchannel_call *call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); +void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, + grpc_subchannel_call *call + GRPC_SUBCHANNEL_REF_EXTRA_ARGS); + +/** construct a subchannel call */ +grpc_error *grpc_connected_subchannel_create_call( + grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *connected_subchannel, + grpc_polling_entity *pollent, grpc_subchannel_call **subchannel_call); + +/** process a transport level op */ +void grpc_connected_subchannel_process_transport_op( + grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *subchannel, + grpc_transport_op *op); + +/** poll the current connectivity state of a channel */ +grpc_connectivity_state grpc_subchannel_check_connectivity( + grpc_subchannel *channel, grpc_error **error); + +/** call notify when the connectivity state of a channel changes from *state. + Updates *state with the new state of the channel */ +void grpc_subchannel_notify_on_state_change( + grpc_exec_ctx *exec_ctx, grpc_subchannel *channel, + grpc_pollset_set *interested_parties, grpc_connectivity_state *state, + grpc_closure *notify); +void grpc_connected_subchannel_notify_on_state_change( + grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *channel, + grpc_pollset_set *interested_parties, grpc_connectivity_state *state, + grpc_closure *notify); +void grpc_connected_subchannel_ping(grpc_exec_ctx *exec_ctx, + grpc_connected_subchannel *channel, + grpc_closure *notify); + +/** retrieve the grpc_connected_subchannel - or NULL if called before + the subchannel becomes connected */ +grpc_connected_subchannel *grpc_subchannel_get_connected_subchannel( + grpc_subchannel *subchannel); + +/** continue processing a transport op */ +void grpc_subchannel_call_process_op(grpc_exec_ctx *exec_ctx, + grpc_subchannel_call *subchannel_call, + grpc_transport_stream_op *op); + +/** continue querying for peer */ +char *grpc_subchannel_call_get_peer(grpc_exec_ctx *exec_ctx, + grpc_subchannel_call *subchannel_call); + +grpc_call_stack *grpc_subchannel_call_get_call_stack( + 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; + /** The number of filters in the above array */ + size_t filter_count; + /** Channel arguments to be supplied to the newly created channel */ + const grpc_channel_args *args; + /** Address to connect to */ + struct sockaddr *addr; + size_t addr_len; +}; + +/** create a subchannel given a connector */ +grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, + grpc_connector *connector, + grpc_subchannel_args *args); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_H */ diff --git a/src/core/ext/client_channel/subchannel_factory.c b/src/core/ext/client_channel/subchannel_factory.c new file mode 100644 index 0000000000..bfb979159b --- /dev/null +++ b/src/core/ext/client_channel/subchannel_factory.c @@ -0,0 +1,49 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/subchannel_factory.h" + +void grpc_subchannel_factory_ref(grpc_subchannel_factory* factory) { + factory->vtable->ref(factory); +} + +void grpc_subchannel_factory_unref(grpc_exec_ctx* exec_ctx, + grpc_subchannel_factory* factory) { + factory->vtable->unref(exec_ctx, factory); +} + +grpc_subchannel* grpc_subchannel_factory_create_subchannel( + grpc_exec_ctx* exec_ctx, grpc_subchannel_factory* factory, + grpc_subchannel_args* args) { + return factory->vtable->create_subchannel(exec_ctx, factory, args); +} diff --git a/src/core/ext/client_channel/subchannel_factory.h b/src/core/ext/client_channel/subchannel_factory.h new file mode 100644 index 0000000000..2b67806767 --- /dev/null +++ b/src/core/ext/client_channel/subchannel_factory.h @@ -0,0 +1,66 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_FACTORY_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_FACTORY_H + +#include "src/core/ext/client_channel/subchannel.h" +#include "src/core/lib/channel/channel_stack.h" + +typedef struct grpc_subchannel_factory grpc_subchannel_factory; +typedef struct grpc_subchannel_factory_vtable grpc_subchannel_factory_vtable; + +/** Constructor for new configured channels. + Creating decorators around this type is encouraged to adapt behavior. */ +struct grpc_subchannel_factory { + const grpc_subchannel_factory_vtable *vtable; +}; + +struct grpc_subchannel_factory_vtable { + void (*ref)(grpc_subchannel_factory *factory); + void (*unref)(grpc_exec_ctx *exec_ctx, grpc_subchannel_factory *factory); + grpc_subchannel *(*create_subchannel)(grpc_exec_ctx *exec_ctx, + grpc_subchannel_factory *factory, + grpc_subchannel_args *args); +}; + +void grpc_subchannel_factory_ref(grpc_subchannel_factory *factory); +void grpc_subchannel_factory_unref(grpc_exec_ctx *exec_ctx, + grpc_subchannel_factory *factory); + +/** Create a new grpc_subchannel */ +grpc_subchannel *grpc_subchannel_factory_create_subchannel( + grpc_exec_ctx *exec_ctx, grpc_subchannel_factory *factory, + grpc_subchannel_args *args); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_FACTORY_H */ diff --git a/src/core/ext/client_channel/subchannel_index.c b/src/core/ext/client_channel/subchannel_index.c new file mode 100644 index 0000000000..daf62eac17 --- /dev/null +++ b/src/core/ext/client_channel/subchannel_index.c @@ -0,0 +1,273 @@ +// +// +// 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/ext/client_channel/subchannel_index.h" + +#include +#include + +#include +#include +#include + +#include "src/core/lib/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; + if (k->args.filter_count > 0) { + 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); + } else { + k->args.filters = NULL; + } + k->args.addr_len = args->addr_len; + k->args.addr = gpr_malloc(args->addr_len); + if (k->args.addr_len > 0) { + 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; + if (a->args.addr_len) { + c = memcmp(a->args.addr, b->args.addr, a->args.addr_len); + if (c != 0) return c; + } + if (a->args.filter_count > 0) { + c = memcmp(a->args.filters, b->args.filters, + a->args.filter_count * sizeof(*a->args.filters)); + if (c != 0) return c; + } + 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); + gpr_tls_init(&subchannel_index_exec_ctx); +} + +void grpc_subchannel_index_shutdown(void) { + gpr_mu_destroy(&g_mu); + gpr_avl_unref(g_subchannel_index); + gpr_tls_destroy(&subchannel_index_exec_ctx); +} + +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/ext/client_channel/subchannel_index.h b/src/core/ext/client_channel/subchannel_index.h new file mode 100644 index 0000000000..a34389d564 --- /dev/null +++ b/src/core/ext/client_channel/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_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H + +#include "src/core/ext/client_channel/connector.h" +#include "src/core/ext/client_channel/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_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H */ diff --git a/src/core/ext/client_channel/uri_parser.c b/src/core/ext/client_channel/uri_parser.c new file mode 100644 index 0000000000..bcb6a1dee4 --- /dev/null +++ b/src/core/ext/client_channel/uri_parser.c @@ -0,0 +1,310 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/uri_parser.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include "src/core/lib/support/string.h" + +/** a size_t default value... maps to all 1's */ +#define NOT_SET (~(size_t)0) + +static grpc_uri *bad_uri(const char *uri_text, size_t pos, const char *section, + int suppress_errors) { + char *line_prefix; + size_t pfx_len; + + if (!suppress_errors) { + gpr_asprintf(&line_prefix, "bad uri.%s: '", section); + pfx_len = strlen(line_prefix) + pos; + gpr_log(GPR_ERROR, "%s%s'", line_prefix, uri_text); + gpr_free(line_prefix); + + line_prefix = gpr_malloc(pfx_len + 1); + memset(line_prefix, ' ', pfx_len); + line_prefix[pfx_len] = 0; + gpr_log(GPR_ERROR, "%s^ here", line_prefix); + gpr_free(line_prefix); + } + + return NULL; +} + +/** Returns a copy of \a src[begin, end) */ +static char *copy_component(const char *src, size_t begin, size_t end) { + char *out = gpr_malloc(end - begin + 1); + memcpy(out, src + begin, end - begin); + out[end - begin] = 0; + return out; +} + +/** Returns how many chars to advance if \a uri_text[i] begins a valid \a pchar + * production. If \a uri_text[i] introduces an invalid \a pchar (such as percent + * sign not followed by two hex digits), NOT_SET is returned. */ +static size_t parse_pchar(const char *uri_text, size_t i) { + /* pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * pct-encoded = "%" HEXDIG HEXDIG + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + / "*" / "+" / "," / ";" / "=" */ + char c = uri_text[i]; + if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) || + ((c >= '0') && (c <= '9')) || + (c == '-' || c == '.' || c == '_' || c == '~') || /* unreserved */ + (c == '!' || c == '$' || c == '&' || c == '\'' || c == '$' || c == '&' || + c == '(' || c == ')' || c == '*' || c == '+' || c == ',' || c == ';' || + c == '=') /* sub-delims */) { + return 1; + } + if (c == '%') { /* pct-encoded */ + size_t j; + if (uri_text[i + 1] == 0 || uri_text[i + 2] == 0) { + return NOT_SET; + } + for (j = i + 1; j < 2; j++) { + c = uri_text[j]; + if (!(((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) || + ((c >= 'A') && (c <= 'F')))) { + return NOT_SET; + } + } + return 2; + } + return 0; +} + +/* *( pchar / "?" / "/" ) */ +static int parse_fragment_or_query(const char *uri_text, size_t *i) { + char c; + while ((c = uri_text[*i]) != 0) { + const size_t advance = parse_pchar(uri_text, *i); /* pchar */ + switch (advance) { + case 0: /* uri_text[i] isn't in pchar */ + /* maybe it's ? or / */ + if (uri_text[*i] == '?' || uri_text[*i] == '/') { + (*i)++; + break; + } else { + return 1; + } + GPR_UNREACHABLE_CODE(return 0); + default: + (*i) += advance; + break; + case NOT_SET: /* uri_text[i] introduces an invalid URI */ + return 0; + } + } + /* *i is the first uri_text position past the \a query production, maybe \0 */ + return 1; +} + +static void do_nothing(void *ignored) {} +static void parse_query_parts(grpc_uri *uri) { + static const char *QUERY_PARTS_SEPARATOR = "&"; + static const char *QUERY_PARTS_VALUE_SEPARATOR = "="; + GPR_ASSERT(uri->query != NULL); + if (uri->query[0] == '\0') { + uri->query_parts = NULL; + uri->query_parts_values = NULL; + uri->num_query_parts = 0; + return; + } + gpr_slice query_slice = + gpr_slice_new(uri->query, strlen(uri->query), do_nothing); + gpr_slice_buffer query_parts; /* the &-separated elements of the query */ + gpr_slice_buffer query_param_parts; /* the =-separated subelements */ + + gpr_slice_buffer_init(&query_parts); + gpr_slice_buffer_init(&query_param_parts); + + gpr_slice_split(query_slice, QUERY_PARTS_SEPARATOR, &query_parts); + uri->query_parts = gpr_malloc(query_parts.count * sizeof(char *)); + uri->query_parts_values = gpr_malloc(query_parts.count * sizeof(char *)); + uri->num_query_parts = query_parts.count; + for (size_t i = 0; i < query_parts.count; i++) { + gpr_slice_split(query_parts.slices[i], QUERY_PARTS_VALUE_SEPARATOR, + &query_param_parts); + GPR_ASSERT(query_param_parts.count > 0); + uri->query_parts[i] = + gpr_dump_slice(query_param_parts.slices[0], GPR_DUMP_ASCII); + if (query_param_parts.count > 1) { + /* TODO(dgq): only the first value after the separator is considered. + * Perhaps all chars after the first separator for the query part should + * be included, even if they include the separator. */ + uri->query_parts_values[i] = + gpr_dump_slice(query_param_parts.slices[1], GPR_DUMP_ASCII); + } else { + uri->query_parts_values[i] = NULL; + } + gpr_slice_buffer_reset_and_unref(&query_param_parts); + } + gpr_slice_buffer_destroy(&query_parts); + gpr_slice_buffer_destroy(&query_param_parts); + gpr_slice_unref(query_slice); +} + +grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) { + grpc_uri *uri; + size_t scheme_begin = 0; + size_t scheme_end = NOT_SET; + size_t authority_begin = NOT_SET; + size_t authority_end = NOT_SET; + size_t path_begin = NOT_SET; + size_t path_end = NOT_SET; + size_t query_begin = NOT_SET; + size_t query_end = NOT_SET; + size_t fragment_begin = NOT_SET; + size_t fragment_end = NOT_SET; + size_t i; + + for (i = scheme_begin; uri_text[i] != 0; i++) { + if (uri_text[i] == ':') { + scheme_end = i; + break; + } + if (uri_text[i] >= 'a' && uri_text[i] <= 'z') continue; + if (uri_text[i] >= 'A' && uri_text[i] <= 'Z') continue; + if (i != scheme_begin) { + if (uri_text[i] >= '0' && uri_text[i] <= '9') continue; + if (uri_text[i] == '+') continue; + if (uri_text[i] == '-') continue; + if (uri_text[i] == '.') continue; + } + break; + } + if (scheme_end == NOT_SET) { + return bad_uri(uri_text, i, "scheme", suppress_errors); + } + + if (uri_text[scheme_end + 1] == '/' && uri_text[scheme_end + 2] == '/') { + authority_begin = scheme_end + 3; + for (i = authority_begin; uri_text[i] != 0 && authority_end == NOT_SET; + i++) { + if (uri_text[i] == '/' || uri_text[i] == '?' || uri_text[i] == '#') { + authority_end = i; + } + } + if (authority_end == NOT_SET && uri_text[i] == 0) { + authority_end = i; + } + if (authority_end == NOT_SET) { + return bad_uri(uri_text, i, "authority", suppress_errors); + } + /* TODO(ctiller): parse the authority correctly */ + path_begin = authority_end; + } else { + path_begin = scheme_end + 1; + } + + for (i = path_begin; uri_text[i] != 0; i++) { + if (uri_text[i] == '?' || uri_text[i] == '#') { + path_end = i; + break; + } + } + if (path_end == NOT_SET && uri_text[i] == 0) { + path_end = i; + } + if (path_end == NOT_SET) { + return bad_uri(uri_text, i, "path", suppress_errors); + } + + if (uri_text[i] == '?') { + query_begin = ++i; + if (!parse_fragment_or_query(uri_text, &i)) { + return bad_uri(uri_text, i, "query", suppress_errors); + } else if (uri_text[i] != 0 && uri_text[i] != '#') { + /* We must be at the end or at the beginning of a fragment */ + return bad_uri(uri_text, i, "query", suppress_errors); + } + query_end = i; + } + if (uri_text[i] == '#') { + fragment_begin = ++i; + if (!parse_fragment_or_query(uri_text, &i)) { + return bad_uri(uri_text, i - fragment_end, "fragment", suppress_errors); + } else if (uri_text[i] != 0) { + /* We must be at the end */ + return bad_uri(uri_text, i, "fragment", suppress_errors); + } + fragment_end = i; + } + + uri = gpr_malloc(sizeof(*uri)); + memset(uri, 0, sizeof(*uri)); + uri->scheme = copy_component(uri_text, scheme_begin, scheme_end); + uri->authority = copy_component(uri_text, authority_begin, authority_end); + uri->path = copy_component(uri_text, path_begin, path_end); + uri->query = copy_component(uri_text, query_begin, query_end); + uri->fragment = copy_component(uri_text, fragment_begin, fragment_end); + parse_query_parts(uri); + + return uri; +} + +const char *grpc_uri_get_query_arg(const grpc_uri *uri, const char *key) { + GPR_ASSERT(key != NULL); + if (key[0] == '\0') return NULL; + + for (size_t i = 0; i < uri->num_query_parts; ++i) { + if (0 == strcmp(key, uri->query_parts[i])) { + return uri->query_parts_values[i]; + } + } + return NULL; +} + +void grpc_uri_destroy(grpc_uri *uri) { + if (!uri) return; + gpr_free(uri->scheme); + gpr_free(uri->authority); + gpr_free(uri->path); + gpr_free(uri->query); + for (size_t i = 0; i < uri->num_query_parts; ++i) { + gpr_free(uri->query_parts[i]); + gpr_free(uri->query_parts_values[i]); + } + gpr_free(uri->query_parts); + gpr_free(uri->query_parts_values); + gpr_free(uri->fragment); + gpr_free(uri); +} diff --git a/src/core/ext/client_channel/uri_parser.h b/src/core/ext/client_channel/uri_parser.h new file mode 100644 index 0000000000..875a7cb07c --- /dev/null +++ b/src/core/ext/client_channel/uri_parser.h @@ -0,0 +1,63 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_URI_PARSER_H +#define GRPC_CORE_EXT_CLIENT_CONFIG_URI_PARSER_H + +#include + +typedef struct { + char *scheme; + char *authority; + char *path; + char *query; + /** Query substrings separated by '&' */ + char **query_parts; + /** Number of elements in \a query_parts and \a query_parts_values */ + size_t num_query_parts; + /** Split each query part by '='. NULL if not present. */ + char **query_parts_values; + char *fragment; +} grpc_uri; + +/** parse a uri, return NULL on failure */ +grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors); + +/** return the part of a query string after the '=' in "?key=xxx&...", or NULL + * if key is not present */ +const char *grpc_uri_get_query_arg(const grpc_uri *uri, const char *key); + +/** destroy a uri */ +void grpc_uri_destroy(grpc_uri *uri); + +#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_URI_PARSER_H */ diff --git a/src/core/ext/client_config/README.md b/src/core/ext/client_config/README.md deleted file mode 100644 index eda01e3e71..0000000000 --- a/src/core/ext/client_config/README.md +++ /dev/null @@ -1,66 +0,0 @@ -Client Configuration Support for GRPC -===================================== - -This library provides high level configuration machinery to construct client -channels and load balance between them. - -Each grpc_channel is created with a grpc_resolver. It is the resolver's duty -to resolve a name into configuration data for the channel. Such configuration -data might include: - -- a list of (ip, port) addresses to connect to -- a load balancing policy to decide which server to send a request to -- a set of filters to mutate outgoing requests (say, by adding metadata) - -The resolver provides this data as a stream of grpc_resolver_result objects to -the channel. We represent configuration as a stream so that it can be changed -by the resolver during execution, by reacting to external events (such as a -new configuration file being pushed to some store). - - -Load Balancing --------------- - -Load balancing configuration is provided by a grpc_lb_policy object, stored as -part of grpc_resolver_result. - -The primary job of the load balancing policies is to pick a target server given only the -initial metadata for a request. It does this by providing a grpc_subchannel -object to the owning channel. - - -Sub-Channels ------------- - -A sub-channel provides a connection to a server for a client channel. It has a -connectivity state like a regular channel, and so can be connected or -disconnected. This connectivity state can be used to inform load balancing -decisions (for example, by avoiding disconnected backends). - -Configured sub-channels are fully setup to participate in the grpc data plane. -Their behavior is specified by a set of grpc channel filters defined at their -construction. To customize this behavior, resolvers build -grpc_client_channel_factory objects, which use the decorator pattern to customize -construction arguments for concrete grpc_subchannel instances. - - -Naming for GRPC -=============== - -Names in GRPC are represented by a URI (as defined in -[RFC 3986](https://tools.ietf.org/html/rfc3986)). - -The following schemes are currently supported: - -dns:///host:port - dns schemes are currently supported so long as authority is - empty (authority based dns resolution is expected in a future - release) - -unix:path - the unix scheme is used to create and connect to unix domain - sockets - the authority must be empty, and the path - represents the absolute or relative path to the desired - socket - -ipv4:host:port - a pre-resolved ipv4 dotted decimal address/port combination - -ipv6:[host]:port - a pre-resolved ipv6 address/port combination diff --git a/src/core/ext/client_config/channel_connectivity.c b/src/core/ext/client_config/channel_connectivity.c deleted file mode 100644 index ce3c13a4ee..0000000000 --- a/src/core/ext/client_config/channel_connectivity.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/lib/surface/channel.h" - -#include -#include - -#include "src/core/ext/client_config/client_channel.h" -#include "src/core/lib/iomgr/timer.h" -#include "src/core/lib/surface/api_trace.h" -#include "src/core/lib/surface/completion_queue.h" - -grpc_connectivity_state grpc_channel_check_connectivity_state( - grpc_channel *channel, int try_to_connect) { - /* forward through to the underlying client channel */ - grpc_channel_element *client_channel_elem = - grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_connectivity_state state; - GRPC_API_TRACE( - "grpc_channel_check_connectivity_state(channel=%p, try_to_connect=%d)", 2, - (channel, try_to_connect)); - if (client_channel_elem->filter == &grpc_client_channel_filter) { - state = grpc_client_channel_check_connectivity_state( - &exec_ctx, client_channel_elem, try_to_connect); - grpc_exec_ctx_finish(&exec_ctx); - return state; - } - gpr_log(GPR_ERROR, - "grpc_channel_check_connectivity_state called on something that is " - "not a client channel, but '%s'", - client_channel_elem->filter->name); - grpc_exec_ctx_finish(&exec_ctx); - return GRPC_CHANNEL_SHUTDOWN; -} - -typedef enum { - WAITING, - CALLING_BACK, - CALLING_BACK_AND_FINISHED, - CALLED_BACK -} callback_phase; - -typedef struct { - gpr_mu mu; - callback_phase phase; - grpc_closure on_complete; - grpc_timer alarm; - grpc_connectivity_state state; - grpc_completion_queue *cq; - grpc_cq_completion completion_storage; - grpc_channel *channel; - void *tag; -} state_watcher; - -static void delete_state_watcher(grpc_exec_ctx *exec_ctx, state_watcher *w) { - grpc_channel_element *client_channel_elem = grpc_channel_stack_last_element( - grpc_channel_get_channel_stack(w->channel)); - if (client_channel_elem->filter == &grpc_client_channel_filter) { - GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, w->channel, - "watch_channel_connectivity"); - } else { - abort(); - } - gpr_mu_destroy(&w->mu); - gpr_free(w); -} - -static void finished_completion(grpc_exec_ctx *exec_ctx, void *pw, - grpc_cq_completion *ignored) { - int delete = 0; - state_watcher *w = pw; - gpr_mu_lock(&w->mu); - switch (w->phase) { - case WAITING: - case CALLED_BACK: - GPR_UNREACHABLE_CODE(return ); - case CALLING_BACK: - w->phase = CALLED_BACK; - break; - case CALLING_BACK_AND_FINISHED: - delete = 1; - break; - } - gpr_mu_unlock(&w->mu); - - if (delete) { - delete_state_watcher(exec_ctx, w); - } -} - -static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w, - bool due_to_completion, grpc_error *error) { - int delete = 0; - - if (due_to_completion) { - grpc_timer_cancel(exec_ctx, &w->alarm); - } - - gpr_mu_lock(&w->mu); - - if (due_to_completion) { - if (grpc_trace_operation_failures) { - GRPC_LOG_IF_ERROR("watch_completion_error", GRPC_ERROR_REF(error)); - } - GRPC_ERROR_UNREF(error); - error = GRPC_ERROR_NONE; - } else { - if (error == GRPC_ERROR_NONE) { - error = - GRPC_ERROR_CREATE("Timed out waiting for connection state change"); - } else if (error == GRPC_ERROR_CANCELLED) { - error = GRPC_ERROR_NONE; - } - } - switch (w->phase) { - case WAITING: - w->phase = CALLING_BACK; - grpc_cq_end_op(exec_ctx, w->cq, w->tag, GRPC_ERROR_REF(error), - finished_completion, w, &w->completion_storage); - break; - case CALLING_BACK: - w->phase = CALLING_BACK_AND_FINISHED; - break; - case CALLING_BACK_AND_FINISHED: - GPR_UNREACHABLE_CODE(return ); - case CALLED_BACK: - delete = 1; - break; - } - gpr_mu_unlock(&w->mu); - - if (delete) { - delete_state_watcher(exec_ctx, w); - } - - GRPC_ERROR_UNREF(error); -} - -static void watch_complete(grpc_exec_ctx *exec_ctx, void *pw, - grpc_error *error) { - partly_done(exec_ctx, pw, true, GRPC_ERROR_REF(error)); -} - -static void timeout_complete(grpc_exec_ctx *exec_ctx, void *pw, - grpc_error *error) { - partly_done(exec_ctx, pw, false, GRPC_ERROR_REF(error)); -} - -void grpc_channel_watch_connectivity_state( - grpc_channel *channel, grpc_connectivity_state last_observed_state, - gpr_timespec deadline, grpc_completion_queue *cq, void *tag) { - grpc_channel_element *client_channel_elem = - grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - state_watcher *w = gpr_malloc(sizeof(*w)); - - GRPC_API_TRACE( - "grpc_channel_watch_connectivity_state(" - "channel=%p, last_observed_state=%d, " - "deadline=gpr_timespec { tv_sec: %" PRId64 - ", tv_nsec: %d, clock_type: %d }, " - "cq=%p, tag=%p)", - 7, (channel, (int)last_observed_state, deadline.tv_sec, deadline.tv_nsec, - (int)deadline.clock_type, cq, tag)); - - grpc_cq_begin_op(cq, tag); - - gpr_mu_init(&w->mu); - grpc_closure_init(&w->on_complete, watch_complete, w); - w->phase = WAITING; - w->state = last_observed_state; - w->cq = cq; - w->tag = tag; - w->channel = channel; - - grpc_timer_init(&exec_ctx, &w->alarm, - gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC), - timeout_complete, w, gpr_now(GPR_CLOCK_MONOTONIC)); - - if (client_channel_elem->filter == &grpc_client_channel_filter) { - GRPC_CHANNEL_INTERNAL_REF(channel, "watch_channel_connectivity"); - grpc_client_channel_watch_connectivity_state(&exec_ctx, client_channel_elem, - grpc_cq_pollset(cq), &w->state, - &w->on_complete); - } else { - abort(); - } - - grpc_exec_ctx_finish(&exec_ctx); -} diff --git a/src/core/ext/client_config/client_channel.c b/src/core/ext/client_config/client_channel.c deleted file mode 100644 index 61e012578e..0000000000 --- a/src/core/ext/client_config/client_channel.c +++ /dev/null @@ -1,840 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/client_channel.h" - -#include -#include -#include - -#include -#include -#include -#include - -#include "src/core/ext/client_config/subchannel.h" -#include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/channel/connected_channel.h" -#include "src/core/lib/iomgr/iomgr.h" -#include "src/core/lib/iomgr/polling_entity.h" -#include "src/core/lib/profiling/timers.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/surface/channel.h" -#include "src/core/lib/transport/connectivity_state.h" - -/* Client channel implementation */ - -/************************************************************************* - * CHANNEL-WIDE FUNCTIONS - */ - -typedef struct client_channel_channel_data { - /** resolver for this channel */ - grpc_resolver *resolver; - /** have we started resolving this channel */ - bool started_resolving; - - /** mutex protecting client configuration, including all - variables below in this data structure */ - gpr_mu mu; - /** currently active load balancer - guarded by mu */ - grpc_lb_policy *lb_policy; - /** incoming resolver result - set by resolver.next(), guarded by mu */ - grpc_resolver_result *resolver_result; - /** a list of closures that are all waiting for config to come in */ - grpc_closure_list waiting_for_config_closures; - /** resolver callback */ - grpc_closure on_resolver_result_changed; - /** connectivity state being tracked */ - grpc_connectivity_state_tracker state_tracker; - /** when an lb_policy arrives, should we try to exit idle */ - bool exit_idle_when_lb_policy_arrives; - /** owning stack */ - grpc_channel_stack *owning_stack; - /** interested parties (owned) */ - grpc_pollset_set *interested_parties; -} channel_data; - -/** We create one watcher for each new lb_policy that is returned from a - resolver, to watch for state changes from the lb_policy. When a state - change is seen, we update the channel, and create a new watcher. */ -typedef struct { - channel_data *chand; - grpc_closure on_changed; - grpc_connectivity_state state; - grpc_lb_policy *lb_policy; -} lb_policy_connectivity_watcher; - -static void watch_lb_policy(grpc_exec_ctx *exec_ctx, channel_data *chand, - grpc_lb_policy *lb_policy, - grpc_connectivity_state current_state); - -static void set_channel_connectivity_state_locked(grpc_exec_ctx *exec_ctx, - channel_data *chand, - grpc_connectivity_state state, - grpc_error *error, - const char *reason) { - if ((state == GRPC_CHANNEL_TRANSIENT_FAILURE || - state == GRPC_CHANNEL_SHUTDOWN) && - chand->lb_policy != NULL) { - /* cancel fail-fast picks */ - grpc_lb_policy_cancel_picks( - exec_ctx, chand->lb_policy, - /* mask= */ GRPC_INITIAL_METADATA_IGNORE_CONNECTIVITY, - /* check= */ 0); - } - grpc_connectivity_state_set(exec_ctx, &chand->state_tracker, state, error, - reason); -} - -static void on_lb_policy_state_changed_locked(grpc_exec_ctx *exec_ctx, - lb_policy_connectivity_watcher *w, - grpc_error *error) { - grpc_connectivity_state publish_state = w->state; - /* check if the notification is for a stale policy */ - if (w->lb_policy != w->chand->lb_policy) return; - - if (publish_state == GRPC_CHANNEL_SHUTDOWN && w->chand->resolver != NULL) { - publish_state = GRPC_CHANNEL_TRANSIENT_FAILURE; - grpc_resolver_channel_saw_error(exec_ctx, w->chand->resolver); - GRPC_LB_POLICY_UNREF(exec_ctx, w->chand->lb_policy, "channel"); - w->chand->lb_policy = NULL; - } - set_channel_connectivity_state_locked(exec_ctx, w->chand, publish_state, - GRPC_ERROR_REF(error), "lb_changed"); - if (w->state != GRPC_CHANNEL_SHUTDOWN) { - watch_lb_policy(exec_ctx, w->chand, w->lb_policy, w->state); - } -} - -static void on_lb_policy_state_changed(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - lb_policy_connectivity_watcher *w = arg; - - gpr_mu_lock(&w->chand->mu); - on_lb_policy_state_changed_locked(exec_ctx, w, error); - gpr_mu_unlock(&w->chand->mu); - - GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, "watch_lb_policy"); - gpr_free(w); -} - -static void watch_lb_policy(grpc_exec_ctx *exec_ctx, channel_data *chand, - grpc_lb_policy *lb_policy, - grpc_connectivity_state current_state) { - lb_policy_connectivity_watcher *w = gpr_malloc(sizeof(*w)); - GRPC_CHANNEL_STACK_REF(chand->owning_stack, "watch_lb_policy"); - - w->chand = chand; - grpc_closure_init(&w->on_changed, on_lb_policy_state_changed, w); - w->state = current_state; - w->lb_policy = lb_policy; - grpc_lb_policy_notify_on_state_change(exec_ctx, lb_policy, &w->state, - &w->on_changed); -} - -static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - channel_data *chand = arg; - grpc_lb_policy *lb_policy = NULL; - grpc_lb_policy *old_lb_policy; - grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; - bool exit_idle = false; - grpc_error *state_error = GRPC_ERROR_CREATE("No load balancing policy"); - - if (chand->resolver_result != NULL) { - lb_policy = grpc_resolver_result_get_lb_policy(chand->resolver_result); - if (lb_policy != NULL) { - GRPC_LB_POLICY_REF(lb_policy, "channel"); - GRPC_LB_POLICY_REF(lb_policy, "config_change"); - GRPC_ERROR_UNREF(state_error); - state = - grpc_lb_policy_check_connectivity(exec_ctx, lb_policy, &state_error); - } - - grpc_resolver_result_unref(exec_ctx, chand->resolver_result); - } - - chand->resolver_result = NULL; - - if (lb_policy != NULL) { - grpc_pollset_set_add_pollset_set(exec_ctx, lb_policy->interested_parties, - chand->interested_parties); - } - - gpr_mu_lock(&chand->mu); - old_lb_policy = chand->lb_policy; - chand->lb_policy = lb_policy; - if (lb_policy != NULL) { - grpc_exec_ctx_enqueue_list(exec_ctx, &chand->waiting_for_config_closures, - NULL); - } else if (chand->resolver == NULL /* disconnected */) { - grpc_closure_list_fail_all( - &chand->waiting_for_config_closures, - GRPC_ERROR_CREATE_REFERENCING("Channel disconnected", &error, 1)); - grpc_exec_ctx_enqueue_list(exec_ctx, &chand->waiting_for_config_closures, - NULL); - } - if (lb_policy != NULL && chand->exit_idle_when_lb_policy_arrives) { - GRPC_LB_POLICY_REF(lb_policy, "exit_idle"); - exit_idle = true; - chand->exit_idle_when_lb_policy_arrives = false; - } - - if (error == GRPC_ERROR_NONE && chand->resolver) { - set_channel_connectivity_state_locked( - exec_ctx, chand, state, GRPC_ERROR_REF(state_error), "new_lb+resolver"); - if (lb_policy != NULL) { - watch_lb_policy(exec_ctx, chand, lb_policy, state); - } - GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); - grpc_resolver_next(exec_ctx, chand->resolver, &chand->resolver_result, - &chand->on_resolver_result_changed); - gpr_mu_unlock(&chand->mu); - } else { - if (chand->resolver != NULL) { - grpc_resolver_shutdown(exec_ctx, chand->resolver); - GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); - chand->resolver = NULL; - } - grpc_error *refs[] = {error, state_error}; - set_channel_connectivity_state_locked( - exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, - GRPC_ERROR_CREATE_REFERENCING("Got config after disconnection", refs, - GPR_ARRAY_SIZE(refs)), - "resolver_gone"); - gpr_mu_unlock(&chand->mu); - } - - if (exit_idle) { - grpc_lb_policy_exit_idle(exec_ctx, lb_policy); - GRPC_LB_POLICY_UNREF(exec_ctx, lb_policy, "exit_idle"); - } - - if (old_lb_policy != NULL) { - grpc_pollset_set_del_pollset_set( - exec_ctx, old_lb_policy->interested_parties, chand->interested_parties); - GRPC_LB_POLICY_UNREF(exec_ctx, old_lb_policy, "channel"); - } - - if (lb_policy != NULL) { - GRPC_LB_POLICY_UNREF(exec_ctx, lb_policy, "config_change"); - } - - GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->owning_stack, "resolver"); - GRPC_ERROR_UNREF(state_error); -} - -static void cc_start_transport_op(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_transport_op *op) { - channel_data *chand = elem->channel_data; - - grpc_exec_ctx_sched(exec_ctx, op->on_consumed, GRPC_ERROR_NONE, NULL); - - GPR_ASSERT(op->set_accept_stream == false); - if (op->bind_pollset != NULL) { - grpc_pollset_set_add_pollset(exec_ctx, chand->interested_parties, - op->bind_pollset); - } - - gpr_mu_lock(&chand->mu); - if (op->on_connectivity_state_change != NULL) { - grpc_connectivity_state_notify_on_state_change( - exec_ctx, &chand->state_tracker, op->connectivity_state, - op->on_connectivity_state_change); - op->on_connectivity_state_change = NULL; - op->connectivity_state = NULL; - } - - if (op->send_ping != NULL) { - if (chand->lb_policy == NULL) { - grpc_exec_ctx_sched(exec_ctx, op->send_ping, - GRPC_ERROR_CREATE("Ping with no load balancing"), - NULL); - } else { - grpc_lb_policy_ping_one(exec_ctx, chand->lb_policy, op->send_ping); - op->bind_pollset = NULL; - } - op->send_ping = NULL; - } - - if (op->disconnect_with_error != GRPC_ERROR_NONE) { - if (chand->resolver != NULL) { - set_channel_connectivity_state_locked( - exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, - GRPC_ERROR_REF(op->disconnect_with_error), "disconnect"); - grpc_resolver_shutdown(exec_ctx, chand->resolver); - GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); - chand->resolver = NULL; - if (!chand->started_resolving) { - grpc_closure_list_fail_all(&chand->waiting_for_config_closures, - GRPC_ERROR_REF(op->disconnect_with_error)); - grpc_exec_ctx_enqueue_list(exec_ctx, - &chand->waiting_for_config_closures, NULL); - } - if (chand->lb_policy != NULL) { - grpc_pollset_set_del_pollset_set(exec_ctx, - chand->lb_policy->interested_parties, - chand->interested_parties); - GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); - chand->lb_policy = NULL; - } - } - GRPC_ERROR_UNREF(op->disconnect_with_error); - } - gpr_mu_unlock(&chand->mu); -} - -/* Constructor for channel_data */ -static void cc_init_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem, - grpc_channel_element_args *args) { - channel_data *chand = elem->channel_data; - - memset(chand, 0, sizeof(*chand)); - - GPR_ASSERT(args->is_last); - GPR_ASSERT(elem->filter == &grpc_client_channel_filter); - - gpr_mu_init(&chand->mu); - grpc_closure_init(&chand->on_resolver_result_changed, - on_resolver_result_changed, chand); - chand->owning_stack = args->channel_stack; - - grpc_connectivity_state_init(&chand->state_tracker, GRPC_CHANNEL_IDLE, - "client_channel"); - chand->interested_parties = grpc_pollset_set_create(); -} - -/* Destructor for channel_data */ -static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx, - grpc_channel_element *elem) { - channel_data *chand = elem->channel_data; - - if (chand->resolver != NULL) { - grpc_resolver_shutdown(exec_ctx, chand->resolver); - GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); - } - if (chand->lb_policy != NULL) { - grpc_pollset_set_del_pollset_set(exec_ctx, - chand->lb_policy->interested_parties, - chand->interested_parties); - GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); - } - grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker); - grpc_pollset_set_destroy(chand->interested_parties); - gpr_mu_destroy(&chand->mu); -} - -/************************************************************************* - * PER-CALL FUNCTIONS - */ - -#define GET_CALL(call_data) \ - ((grpc_subchannel_call *)(gpr_atm_acq_load(&(call_data)->subchannel_call))) - -#define CANCELLED_CALL ((grpc_subchannel_call *)1) - -typedef enum { - GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING, - GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL -} subchannel_creation_phase; - -/** Call data. Holds a pointer to grpc_subchannel_call and the - associated machinery to create such a pointer. - Handles queueing of stream ops until a call object is ready, waiting - for initial metadata before trying to create a call object, - and handling cancellation gracefully. */ -typedef struct client_channel_call_data { - /** either 0 for no call, 1 for cancelled, or a pointer to a - grpc_subchannel_call */ - gpr_atm subchannel_call; - - gpr_mu mu; - - subchannel_creation_phase creation_phase; - grpc_connected_subchannel *connected_subchannel; - grpc_polling_entity *pollent; - - grpc_transport_stream_op *waiting_ops; - size_t waiting_ops_count; - size_t waiting_ops_capacity; - - grpc_closure next_step; - - grpc_call_stack *owning_call; -} call_data; - -static void add_waiting_locked(call_data *calld, grpc_transport_stream_op *op) { - GPR_TIMER_BEGIN("add_waiting_locked", 0); - if (calld->waiting_ops_count == calld->waiting_ops_capacity) { - calld->waiting_ops_capacity = GPR_MAX(3, 2 * calld->waiting_ops_capacity); - calld->waiting_ops = - gpr_realloc(calld->waiting_ops, - calld->waiting_ops_capacity * sizeof(*calld->waiting_ops)); - } - calld->waiting_ops[calld->waiting_ops_count++] = *op; - GPR_TIMER_END("add_waiting_locked", 0); -} - -static void fail_locked(grpc_exec_ctx *exec_ctx, call_data *calld, - grpc_error *error) { - size_t i; - for (i = 0; i < calld->waiting_ops_count; i++) { - grpc_transport_stream_op_finish_with_failure( - exec_ctx, &calld->waiting_ops[i], GRPC_ERROR_REF(error)); - } - calld->waiting_ops_count = 0; - GRPC_ERROR_UNREF(error); -} - -typedef struct { - grpc_transport_stream_op *ops; - size_t nops; - grpc_subchannel_call *call; -} retry_ops_args; - -static void retry_ops(grpc_exec_ctx *exec_ctx, void *args, grpc_error *error) { - retry_ops_args *a = args; - size_t i; - for (i = 0; i < a->nops; i++) { - grpc_subchannel_call_process_op(exec_ctx, a->call, &a->ops[i]); - } - GRPC_SUBCHANNEL_CALL_UNREF(exec_ctx, a->call, "retry_ops"); - gpr_free(a->ops); - gpr_free(a); -} - -static void retry_waiting_locked(grpc_exec_ctx *exec_ctx, call_data *calld) { - retry_ops_args *a = gpr_malloc(sizeof(*a)); - a->ops = calld->waiting_ops; - a->nops = calld->waiting_ops_count; - a->call = GET_CALL(calld); - if (a->call == CANCELLED_CALL) { - gpr_free(a); - fail_locked(exec_ctx, calld, GRPC_ERROR_CANCELLED); - return; - } - calld->waiting_ops = NULL; - calld->waiting_ops_count = 0; - calld->waiting_ops_capacity = 0; - GRPC_SUBCHANNEL_CALL_REF(a->call, "retry_ops"); - grpc_exec_ctx_sched(exec_ctx, grpc_closure_create(retry_ops, a), - GRPC_ERROR_NONE, NULL); -} - -static void subchannel_ready(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - call_data *calld = arg; - gpr_mu_lock(&calld->mu); - GPR_ASSERT(calld->creation_phase == - GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL); - calld->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING; - if (calld->connected_subchannel == NULL) { - gpr_atm_no_barrier_store(&calld->subchannel_call, 1); - fail_locked(exec_ctx, calld, GRPC_ERROR_CREATE_REFERENCING( - "Failed to create subchannel", &error, 1)); - } else if (1 == gpr_atm_acq_load(&calld->subchannel_call)) { - /* already cancelled before subchannel became ready */ - fail_locked(exec_ctx, calld, - GRPC_ERROR_CREATE_REFERENCING( - "Cancelled before creating subchannel", &error, 1)); - } else { - grpc_subchannel_call *subchannel_call = NULL; - grpc_error *new_error = grpc_connected_subchannel_create_call( - exec_ctx, calld->connected_subchannel, calld->pollent, - &subchannel_call); - if (new_error != GRPC_ERROR_NONE) { - new_error = grpc_error_add_child(new_error, error); - subchannel_call = CANCELLED_CALL; - fail_locked(exec_ctx, calld, new_error); - } - gpr_atm_rel_store(&calld->subchannel_call, - (gpr_atm)(uintptr_t)subchannel_call); - retry_waiting_locked(exec_ctx, calld); - } - gpr_mu_unlock(&calld->mu); - GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "pick_subchannel"); -} - -static char *cc_get_peer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { - call_data *calld = elem->call_data; - grpc_subchannel_call *subchannel_call = GET_CALL(calld); - if (subchannel_call == NULL || subchannel_call == CANCELLED_CALL) { - return NULL; - } else { - return grpc_subchannel_call_get_peer(exec_ctx, subchannel_call); - } -} - -typedef struct { - grpc_metadata_batch *initial_metadata; - uint32_t initial_metadata_flags; - grpc_connected_subchannel **connected_subchannel; - grpc_closure *on_ready; - grpc_call_element *elem; - grpc_closure closure; -} continue_picking_args; - -static bool pick_subchannel(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_metadata_batch *initial_metadata, - uint32_t initial_metadata_flags, - grpc_connected_subchannel **connected_subchannel, - grpc_closure *on_ready); - -static void continue_picking(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - continue_picking_args *cpa = arg; - if (cpa->connected_subchannel == NULL) { - /* cancelled, do nothing */ - } else if (error != GRPC_ERROR_NONE) { - grpc_exec_ctx_sched(exec_ctx, cpa->on_ready, GRPC_ERROR_REF(error), NULL); - } else if (pick_subchannel(exec_ctx, cpa->elem, cpa->initial_metadata, - cpa->initial_metadata_flags, - cpa->connected_subchannel, cpa->on_ready)) { - grpc_exec_ctx_sched(exec_ctx, cpa->on_ready, GRPC_ERROR_NONE, NULL); - } - gpr_free(cpa); -} - -static bool pick_subchannel(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_metadata_batch *initial_metadata, - uint32_t initial_metadata_flags, - grpc_connected_subchannel **connected_subchannel, - grpc_closure *on_ready) { - GPR_TIMER_BEGIN("pick_subchannel", 0); - - channel_data *chand = elem->channel_data; - call_data *calld = elem->call_data; - continue_picking_args *cpa; - grpc_closure *closure; - - GPR_ASSERT(connected_subchannel); - - gpr_mu_lock(&chand->mu); - if (initial_metadata == NULL) { - if (chand->lb_policy != NULL) { - grpc_lb_policy_cancel_pick(exec_ctx, chand->lb_policy, - connected_subchannel); - } - for (closure = chand->waiting_for_config_closures.head; closure != NULL; - closure = closure->next_data.next) { - cpa = closure->cb_arg; - if (cpa->connected_subchannel == connected_subchannel) { - cpa->connected_subchannel = NULL; - grpc_exec_ctx_sched(exec_ctx, cpa->on_ready, - GRPC_ERROR_CREATE("Pick cancelled"), NULL); - } - } - gpr_mu_unlock(&chand->mu); - GPR_TIMER_END("pick_subchannel", 0); - return true; - } - if (chand->lb_policy != NULL) { - grpc_lb_policy *lb_policy = chand->lb_policy; - int r; - GRPC_LB_POLICY_REF(lb_policy, "pick_subchannel"); - gpr_mu_unlock(&chand->mu); - r = grpc_lb_policy_pick(exec_ctx, lb_policy, calld->pollent, - initial_metadata, initial_metadata_flags, - connected_subchannel, on_ready); - GRPC_LB_POLICY_UNREF(exec_ctx, lb_policy, "pick_subchannel"); - GPR_TIMER_END("pick_subchannel", 0); - return r; - } - if (chand->resolver != NULL && !chand->started_resolving) { - chand->started_resolving = true; - GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); - grpc_resolver_next(exec_ctx, chand->resolver, &chand->resolver_result, - &chand->on_resolver_result_changed); - } - if (chand->resolver != NULL) { - cpa = gpr_malloc(sizeof(*cpa)); - cpa->initial_metadata = initial_metadata; - cpa->initial_metadata_flags = initial_metadata_flags; - cpa->connected_subchannel = connected_subchannel; - cpa->on_ready = on_ready; - cpa->elem = elem; - grpc_closure_init(&cpa->closure, continue_picking, cpa); - grpc_closure_list_append(&chand->waiting_for_config_closures, &cpa->closure, - GRPC_ERROR_NONE); - } else { - grpc_exec_ctx_sched(exec_ctx, on_ready, GRPC_ERROR_CREATE("Disconnected"), - NULL); - } - gpr_mu_unlock(&chand->mu); - - GPR_TIMER_END("pick_subchannel", 0); - return false; -} - -// The logic here is fairly complicated, due to (a) the fact that we -// need to handle the case where we receive the send op before the -// initial metadata op, and (b) the need for efficiency, especially in -// the streaming case. -// TODO(ctiller): Explain this more thoroughly. -static void cc_start_transport_stream_op(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_transport_stream_op *op) { - call_data *calld = elem->call_data; - GRPC_CALL_LOG_OP(GPR_INFO, elem, op); - /* try to (atomically) get the call */ - grpc_subchannel_call *call = GET_CALL(calld); - GPR_TIMER_BEGIN("cc_start_transport_stream_op", 0); - if (call == CANCELLED_CALL) { - grpc_transport_stream_op_finish_with_failure(exec_ctx, op, - GRPC_ERROR_CANCELLED); - GPR_TIMER_END("cc_start_transport_stream_op", 0); - return; - } - if (call != NULL) { - grpc_subchannel_call_process_op(exec_ctx, call, op); - GPR_TIMER_END("cc_start_transport_stream_op", 0); - return; - } - /* we failed; lock and figure out what to do */ - gpr_mu_lock(&calld->mu); -retry: - /* need to recheck that another thread hasn't set the call */ - call = GET_CALL(calld); - if (call == CANCELLED_CALL) { - gpr_mu_unlock(&calld->mu); - grpc_transport_stream_op_finish_with_failure(exec_ctx, op, - GRPC_ERROR_CANCELLED); - GPR_TIMER_END("cc_start_transport_stream_op", 0); - return; - } - if (call != NULL) { - gpr_mu_unlock(&calld->mu); - grpc_subchannel_call_process_op(exec_ctx, call, op); - GPR_TIMER_END("cc_start_transport_stream_op", 0); - return; - } - /* if this is a cancellation, then we can raise our cancelled flag */ - if (op->cancel_error != GRPC_ERROR_NONE) { - if (!gpr_atm_rel_cas(&calld->subchannel_call, 0, - (gpr_atm)(uintptr_t)CANCELLED_CALL)) { - goto retry; - } else { - switch (calld->creation_phase) { - case GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING: - fail_locked(exec_ctx, calld, GRPC_ERROR_REF(op->cancel_error)); - break; - case GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL: - pick_subchannel(exec_ctx, elem, NULL, 0, &calld->connected_subchannel, - NULL); - break; - } - gpr_mu_unlock(&calld->mu); - grpc_transport_stream_op_finish_with_failure(exec_ctx, op, - GRPC_ERROR_CANCELLED); - GPR_TIMER_END("cc_start_transport_stream_op", 0); - return; - } - } - /* if we don't have a subchannel, try to get one */ - if (calld->creation_phase == GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING && - calld->connected_subchannel == NULL && - op->send_initial_metadata != NULL) { - calld->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL; - grpc_closure_init(&calld->next_step, subchannel_ready, calld); - GRPC_CALL_STACK_REF(calld->owning_call, "pick_subchannel"); - if (pick_subchannel(exec_ctx, elem, op->send_initial_metadata, - op->send_initial_metadata_flags, - &calld->connected_subchannel, &calld->next_step)) { - calld->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING; - GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "pick_subchannel"); - } - } - /* if we've got a subchannel, then let's ask it to create a call */ - if (calld->creation_phase == GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING && - calld->connected_subchannel != NULL) { - grpc_subchannel_call *subchannel_call = NULL; - grpc_error *error = grpc_connected_subchannel_create_call( - exec_ctx, calld->connected_subchannel, calld->pollent, - &subchannel_call); - if (error != GRPC_ERROR_NONE) { - subchannel_call = CANCELLED_CALL; - fail_locked(exec_ctx, calld, GRPC_ERROR_REF(error)); - grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); - } - gpr_atm_rel_store(&calld->subchannel_call, - (gpr_atm)(uintptr_t)subchannel_call); - retry_waiting_locked(exec_ctx, calld); - goto retry; - } - /* nothing to be done but wait */ - add_waiting_locked(calld, op); - gpr_mu_unlock(&calld->mu); - GPR_TIMER_END("cc_start_transport_stream_op", 0); -} - -/* Constructor for call_data */ -static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_call_element_args *args) { - call_data *calld = elem->call_data; - gpr_atm_rel_store(&calld->subchannel_call, 0); - gpr_mu_init(&calld->mu); - calld->connected_subchannel = NULL; - calld->waiting_ops = NULL; - calld->waiting_ops_count = 0; - calld->waiting_ops_capacity = 0; - calld->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING; - calld->owning_call = args->call_stack; - calld->pollent = NULL; - return GRPC_ERROR_NONE; -} - -/* Destructor for call_data */ -static void cc_destroy_call_elem(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - const grpc_call_final_info *final_info, - void *and_free_memory) { - call_data *calld = elem->call_data; - grpc_subchannel_call *call = GET_CALL(calld); - if (call != NULL && call != CANCELLED_CALL) { - GRPC_SUBCHANNEL_CALL_UNREF(exec_ctx, call, "client_channel_destroy_call"); - } - GPR_ASSERT(calld->creation_phase == GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING); - gpr_mu_destroy(&calld->mu); - GPR_ASSERT(calld->waiting_ops_count == 0); - gpr_free(calld->waiting_ops); - gpr_free(and_free_memory); -} - -static void cc_set_pollset_or_pollset_set(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_polling_entity *pollent) { - call_data *calld = elem->call_data; - calld->pollent = pollent; -} - -/************************************************************************* - * EXPORTED SYMBOLS - */ - -const grpc_channel_filter grpc_client_channel_filter = { - cc_start_transport_stream_op, - cc_start_transport_op, - sizeof(call_data), - cc_init_call_elem, - cc_set_pollset_or_pollset_set, - cc_destroy_call_elem, - sizeof(channel_data), - cc_init_channel_elem, - cc_destroy_channel_elem, - cc_get_peer, - "client-channel", -}; - -void grpc_client_channel_set_resolver(grpc_exec_ctx *exec_ctx, - grpc_channel_stack *channel_stack, - grpc_resolver *resolver) { - /* post construction initialization: set the transport setup pointer */ - grpc_channel_element *elem = grpc_channel_stack_last_element(channel_stack); - channel_data *chand = elem->channel_data; - gpr_mu_lock(&chand->mu); - GPR_ASSERT(!chand->resolver); - chand->resolver = resolver; - GRPC_RESOLVER_REF(resolver, "channel"); - if (!grpc_closure_list_empty(chand->waiting_for_config_closures) || - chand->exit_idle_when_lb_policy_arrives) { - chand->started_resolving = true; - GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); - grpc_resolver_next(exec_ctx, resolver, &chand->resolver_result, - &chand->on_resolver_result_changed); - } - gpr_mu_unlock(&chand->mu); -} - -grpc_connectivity_state grpc_client_channel_check_connectivity_state( - grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, int try_to_connect) { - channel_data *chand = elem->channel_data; - grpc_connectivity_state out; - gpr_mu_lock(&chand->mu); - out = grpc_connectivity_state_check(&chand->state_tracker, NULL); - if (out == GRPC_CHANNEL_IDLE && try_to_connect) { - if (chand->lb_policy != NULL) { - grpc_lb_policy_exit_idle(exec_ctx, chand->lb_policy); - } else { - chand->exit_idle_when_lb_policy_arrives = true; - if (!chand->started_resolving && chand->resolver != NULL) { - GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); - chand->started_resolving = true; - grpc_resolver_next(exec_ctx, chand->resolver, &chand->resolver_result, - &chand->on_resolver_result_changed); - } - } - } - gpr_mu_unlock(&chand->mu); - return out; -} - -typedef struct { - channel_data *chand; - grpc_pollset *pollset; - grpc_closure *on_complete; - grpc_closure my_closure; -} external_connectivity_watcher; - -static void on_external_watch_complete(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - external_connectivity_watcher *w = arg; - grpc_closure *follow_up = w->on_complete; - grpc_pollset_set_del_pollset(exec_ctx, w->chand->interested_parties, - w->pollset); - GRPC_CHANNEL_STACK_UNREF(exec_ctx, w->chand->owning_stack, - "external_connectivity_watcher"); - gpr_free(w); - follow_up->cb(exec_ctx, follow_up->cb_arg, error); -} - -void grpc_client_channel_watch_connectivity_state( - grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, grpc_pollset *pollset, - grpc_connectivity_state *state, grpc_closure *on_complete) { - channel_data *chand = elem->channel_data; - external_connectivity_watcher *w = gpr_malloc(sizeof(*w)); - w->chand = chand; - w->pollset = pollset; - w->on_complete = on_complete; - grpc_pollset_set_add_pollset(exec_ctx, chand->interested_parties, pollset); - grpc_closure_init(&w->my_closure, on_external_watch_complete, w); - GRPC_CHANNEL_STACK_REF(w->chand->owning_stack, - "external_connectivity_watcher"); - gpr_mu_lock(&chand->mu); - grpc_connectivity_state_notify_on_state_change( - exec_ctx, &chand->state_tracker, state, &w->my_closure); - gpr_mu_unlock(&chand->mu); -} diff --git a/src/core/ext/client_config/client_channel.h b/src/core/ext/client_config/client_channel.h deleted file mode 100644 index 1e47ad34ad..0000000000 --- a/src/core/ext/client_config/client_channel.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_H - -#include "src/core/ext/client_config/resolver.h" -#include "src/core/lib/channel/channel_stack.h" - -/* A client channel is a channel that begins disconnected, and can connect - to some endpoint on demand. If that endpoint disconnects, it will be - connected to again later. - - Calls on a disconnected client channel are queued until a connection is - established. */ - -extern const grpc_channel_filter grpc_client_channel_filter; - -/* post-construction initializer to let the client channel know which - transport setup it should cancel upon destruction, or initiate when it needs - a connection */ -void grpc_client_channel_set_resolver(grpc_exec_ctx *exec_ctx, - grpc_channel_stack *channel_stack, - grpc_resolver *resolver); - -grpc_connectivity_state grpc_client_channel_check_connectivity_state( - grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, int try_to_connect); - -void grpc_client_channel_watch_connectivity_state( - grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, grpc_pollset *pollset, - grpc_connectivity_state *state, grpc_closure *on_complete); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_H */ diff --git a/src/core/ext/client_config/client_channel_factory.c b/src/core/ext/client_config/client_channel_factory.c deleted file mode 100644 index 71c64c0da1..0000000000 --- a/src/core/ext/client_config/client_channel_factory.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/client_channel_factory.h" - -void grpc_client_channel_factory_ref(grpc_client_channel_factory* factory) { - factory->vtable->ref(factory); -} - -void grpc_client_channel_factory_unref(grpc_exec_ctx* exec_ctx, - grpc_client_channel_factory* factory) { - factory->vtable->unref(exec_ctx, factory); -} - -grpc_subchannel* grpc_client_channel_factory_create_subchannel( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, - grpc_subchannel_args* args) { - return factory->vtable->create_subchannel(exec_ctx, factory, args); -} - -grpc_channel* grpc_client_channel_factory_create_channel( - grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* factory, - const char* target, grpc_client_channel_type type, - grpc_channel_args* args) { - return factory->vtable->create_client_channel(exec_ctx, factory, target, type, - args); -} diff --git a/src/core/ext/client_config/client_channel_factory.h b/src/core/ext/client_config/client_channel_factory.h deleted file mode 100644 index 1241b9b781..0000000000 --- a/src/core/ext/client_config/client_channel_factory.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_FACTORY_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_FACTORY_H - -#include - -#include "src/core/ext/client_config/subchannel.h" -#include "src/core/lib/channel/channel_stack.h" - -typedef struct grpc_client_channel_factory grpc_client_channel_factory; -typedef struct grpc_client_channel_factory_vtable - grpc_client_channel_factory_vtable; - -typedef enum { - GRPC_CLIENT_CHANNEL_TYPE_REGULAR, /** for the user-level regular calls */ - GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, /** for communication with a load - balancing service */ -} grpc_client_channel_type; - -/** Constructor for new configured channels. - Creating decorators around this type is encouraged to adapt behavior. */ -struct grpc_client_channel_factory { - const grpc_client_channel_factory_vtable *vtable; -}; - -struct grpc_client_channel_factory_vtable { - void (*ref)(grpc_client_channel_factory *factory); - void (*unref)(grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory); - grpc_subchannel *(*create_subchannel)(grpc_exec_ctx *exec_ctx, - grpc_client_channel_factory *factory, - grpc_subchannel_args *args); - grpc_channel *(*create_client_channel)(grpc_exec_ctx *exec_ctx, - grpc_client_channel_factory *factory, - const char *target, - grpc_client_channel_type type, - grpc_channel_args *args); -}; - -void grpc_client_channel_factory_ref(grpc_client_channel_factory *factory); -void grpc_client_channel_factory_unref(grpc_exec_ctx *exec_ctx, - grpc_client_channel_factory *factory); - -/** Create a new grpc_subchannel */ -grpc_subchannel *grpc_client_channel_factory_create_subchannel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, - grpc_subchannel_args *args); - -/** Create a new grpc_channel */ -grpc_channel *grpc_client_channel_factory_create_channel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, - const char *target, grpc_client_channel_type type, grpc_channel_args *args); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_CLIENT_CHANNEL_FACTORY_H */ diff --git a/src/core/ext/client_config/client_config_plugin.c b/src/core/ext/client_config/client_config_plugin.c deleted file mode 100644 index 5e31613420..0000000000 --- a/src/core/ext/client_config/client_config_plugin.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include -#include -#include - -#include - -#include "src/core/ext/client_config/client_channel.h" -#include "src/core/ext/client_config/lb_policy_registry.h" -#include "src/core/ext/client_config/resolver_registry.h" -#include "src/core/ext/client_config/subchannel_index.h" -#include "src/core/lib/surface/channel_init.h" - -#ifndef GRPC_DEFAULT_NAME_PREFIX -#define GRPC_DEFAULT_NAME_PREFIX "dns:///" -#endif - -static bool append_filter(grpc_channel_stack_builder *builder, void *arg) { - return grpc_channel_stack_builder_append_filter( - builder, (const grpc_channel_filter *)arg, NULL, NULL); -} - -static bool set_default_host_if_unset(grpc_channel_stack_builder *builder, - void *unused) { - const grpc_channel_args *args = - grpc_channel_stack_builder_get_channel_arguments(builder); - for (size_t i = 0; i < args->num_args; i++) { - if (0 == strcmp(args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY) || - 0 == strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) { - return true; - } - } - char *default_authority = grpc_get_default_authority( - grpc_channel_stack_builder_get_target(builder)); - if (default_authority != NULL) { - grpc_arg arg; - arg.type = GRPC_ARG_STRING; - arg.key = GRPC_ARG_DEFAULT_AUTHORITY; - arg.value.string = default_authority; - grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1); - grpc_channel_stack_builder_set_channel_arguments(builder, new_args); - gpr_free(default_authority); - grpc_channel_args_destroy(new_args); - } - return true; -} - -void grpc_client_config_init(void) { - grpc_lb_policy_registry_init(); - grpc_resolver_registry_init(GRPC_DEFAULT_NAME_PREFIX); - grpc_subchannel_index_init(); - grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MIN, - set_default_host_if_unset, NULL); - grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX, append_filter, - (void *)&grpc_client_channel_filter); -} - -void grpc_client_config_shutdown(void) { - grpc_subchannel_index_shutdown(); - grpc_channel_init_shutdown(); - grpc_resolver_registry_shutdown(); - grpc_lb_policy_registry_shutdown(); -} diff --git a/src/core/ext/client_config/connector.c b/src/core/ext/client_config/connector.c deleted file mode 100644 index 5b629ed5fb..0000000000 --- a/src/core/ext/client_config/connector.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/connector.h" - -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) { - connector->vtable->unref(exec_ctx, connector); -} - -void grpc_connector_connect(grpc_exec_ctx* exec_ctx, grpc_connector* connector, - const grpc_connect_in_args* in_args, - grpc_connect_out_args* out_args, - grpc_closure* notify) { - connector->vtable->connect(exec_ctx, connector, in_args, out_args, notify); -} - -void grpc_connector_shutdown(grpc_exec_ctx* exec_ctx, - grpc_connector* connector) { - connector->vtable->shutdown(exec_ctx, connector); -} diff --git a/src/core/ext/client_config/connector.h b/src/core/ext/client_config/connector.h deleted file mode 100644 index ea9d23706e..0000000000 --- a/src/core/ext/client_config/connector.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_CONNECTOR_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_CONNECTOR_H - -#include "src/core/lib/channel/channel_stack.h" -#include "src/core/lib/iomgr/sockaddr.h" -#include "src/core/lib/transport/transport.h" - -typedef struct grpc_connector grpc_connector; -typedef struct grpc_connector_vtable grpc_connector_vtable; - -struct grpc_connector { - const grpc_connector_vtable *vtable; -}; - -typedef struct { - /** set of pollsets interested in this connection */ - grpc_pollset_set *interested_parties; - /** address to connect to */ - const struct sockaddr *addr; - size_t addr_len; - /** initial connect string to send */ - gpr_slice initial_connect_string; - /** deadline for connection */ - gpr_timespec deadline; - /** channel arguments (to be passed to transport) */ - const grpc_channel_args *channel_args; -} grpc_connect_in_args; - -typedef struct { - /** the connected transport */ - grpc_transport *transport; - - /** channel arguments (to be passed to the filters) */ - grpc_channel_args *channel_args; -} grpc_connect_out_args; - -struct grpc_connector_vtable { - void (*ref)(grpc_connector *connector); - void (*unref)(grpc_exec_ctx *exec_ctx, grpc_connector *connector); - /** Implementation of grpc_connector_shutdown */ - void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_connector *connector); - /** Implementation of grpc_connector_connect */ - void (*connect)(grpc_exec_ctx *exec_ctx, grpc_connector *connector, - const grpc_connect_in_args *in_args, - grpc_connect_out_args *out_args, grpc_closure *notify); -}; - -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, - const grpc_connect_in_args *in_args, - grpc_connect_out_args *out_args, - grpc_closure *notify); -/** Cancel any pending connection */ -void grpc_connector_shutdown(grpc_exec_ctx *exec_ctx, - grpc_connector *connector); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_CONNECTOR_H */ diff --git a/src/core/ext/client_config/default_initial_connect_string.c b/src/core/ext/client_config/default_initial_connect_string.c deleted file mode 100644 index a70da4a84a..0000000000 --- a/src/core/ext/client_config/default_initial_connect_string.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include -#include "src/core/lib/iomgr/sockaddr.h" - -void grpc_set_default_initial_connect_string(struct sockaddr **addr, - size_t *addr_len, - gpr_slice *initial_str) {} diff --git a/src/core/ext/client_config/initial_connect_string.c b/src/core/ext/client_config/initial_connect_string.c deleted file mode 100644 index 41580d2106..0000000000 --- a/src/core/ext/client_config/initial_connect_string.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/initial_connect_string.h" - -#include - -extern void grpc_set_default_initial_connect_string(struct sockaddr **addr, - size_t *addr_len, - gpr_slice *initial_str); - -static grpc_set_initial_connect_string_func g_set_initial_connect_string_func = - grpc_set_default_initial_connect_string; - -void grpc_test_set_initial_connect_string_function( - grpc_set_initial_connect_string_func func) { - g_set_initial_connect_string_func = func; -} - -void grpc_set_initial_connect_string(struct sockaddr **addr, size_t *addr_len, - gpr_slice *initial_str) { - g_set_initial_connect_string_func(addr, addr_len, initial_str); -} diff --git a/src/core/ext/client_config/initial_connect_string.h b/src/core/ext/client_config/initial_connect_string.h deleted file mode 100644 index 06f0767832..0000000000 --- a/src/core/ext/client_config/initial_connect_string.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_INITIAL_CONNECT_STRING_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_INITIAL_CONNECT_STRING_H - -#include -#include "src/core/lib/iomgr/sockaddr.h" - -typedef void (*grpc_set_initial_connect_string_func)(struct sockaddr **addr, - size_t *addr_len, - gpr_slice *initial_str); -void grpc_test_set_initial_connect_string_function( - grpc_set_initial_connect_string_func func); - -/** Set a string to be sent once connected. Optionally reset addr. */ -void grpc_set_initial_connect_string(struct sockaddr **addr, size_t *addr_len, - gpr_slice *connect_string); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_INITIAL_CONNECT_STRING_H */ diff --git a/src/core/ext/client_config/lb_policy.c b/src/core/ext/client_config/lb_policy.c deleted file mode 100644 index 8b980b2cca..0000000000 --- a/src/core/ext/client_config/lb_policy.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/lb_policy.h" - -#define WEAK_REF_BITS 16 - -void grpc_lb_policy_init(grpc_lb_policy *policy, - const grpc_lb_policy_vtable *vtable) { - policy->vtable = vtable; - gpr_atm_no_barrier_store(&policy->ref_pair, 1 << WEAK_REF_BITS); - policy->interested_parties = grpc_pollset_set_create(); -} - -#ifdef GRPC_LB_POLICY_REFCOUNT_DEBUG -#define REF_FUNC_EXTRA_ARGS , const char *file, int line, const char *reason -#define REF_MUTATE_EXTRA_ARGS REF_FUNC_EXTRA_ARGS, const char *purpose -#define REF_FUNC_PASS_ARGS(new_reason) , file, line, new_reason -#define REF_MUTATE_PASS_ARGS(purpose) , file, line, reason, purpose -#else -#define REF_FUNC_EXTRA_ARGS -#define REF_MUTATE_EXTRA_ARGS -#define REF_FUNC_PASS_ARGS(new_reason) -#define REF_MUTATE_PASS_ARGS(x) -#endif - -static gpr_atm ref_mutate(grpc_lb_policy *c, gpr_atm delta, - int barrier REF_MUTATE_EXTRA_ARGS) { - gpr_atm old_val = barrier ? gpr_atm_full_fetch_add(&c->ref_pair, delta) - : gpr_atm_no_barrier_fetch_add(&c->ref_pair, delta); -#ifdef GRPC_LB_POLICY_REFCOUNT_DEBUG - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "LB_POLICY: 0x%" PRIxPTR " %12s 0x%" PRIxPTR " -> 0x%" PRIxPTR - " [%s]", - (intptr_t)c, purpose, old_val, old_val + delta, reason); -#endif - return old_val; -} - -void grpc_lb_policy_ref(grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { - ref_mutate(policy, 1 << WEAK_REF_BITS, 0 REF_MUTATE_PASS_ARGS("STRONG_REF")); -} - -void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { - gpr_atm old_val = - ref_mutate(policy, (gpr_atm)1 - (gpr_atm)(1 << WEAK_REF_BITS), - 1 REF_MUTATE_PASS_ARGS("STRONG_UNREF")); - gpr_atm mask = ~(gpr_atm)((1 << WEAK_REF_BITS) - 1); - gpr_atm check = 1 << WEAK_REF_BITS; - if ((old_val & mask) == check) { - policy->vtable->shutdown(exec_ctx, policy); - } - grpc_lb_policy_weak_unref(exec_ctx, - policy REF_FUNC_PASS_ARGS("strong-unref")); -} - -void grpc_lb_policy_weak_ref(grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { - ref_mutate(policy, 1, 0 REF_MUTATE_PASS_ARGS("WEAK_REF")); -} - -void grpc_lb_policy_weak_unref(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) { - gpr_atm old_val = - ref_mutate(policy, -(gpr_atm)1, 1 REF_MUTATE_PASS_ARGS("WEAK_UNREF")); - if (old_val == 1) { - grpc_pollset_set_destroy(policy->interested_parties); - policy->vtable->destroy(exec_ctx, policy); - } -} - -int grpc_lb_policy_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_polling_entity *pollent, - grpc_metadata_batch *initial_metadata, - uint32_t initial_metadata_flags, - grpc_connected_subchannel **target, - grpc_closure *on_complete) { - return policy->vtable->pick(exec_ctx, policy, pollent, initial_metadata, - initial_metadata_flags, target, on_complete); -} - -void grpc_lb_policy_cancel_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_connected_subchannel **target) { - policy->vtable->cancel_pick(exec_ctx, policy, target); -} - -void grpc_lb_policy_cancel_picks(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - uint32_t initial_metadata_flags_mask, - uint32_t initial_metadata_flags_eq) { - policy->vtable->cancel_picks(exec_ctx, policy, initial_metadata_flags_mask, - initial_metadata_flags_eq); -} - -void grpc_lb_policy_exit_idle(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy) { - policy->vtable->exit_idle(exec_ctx, policy); -} - -void grpc_lb_policy_ping_one(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_closure *closure) { - policy->vtable->ping_one(exec_ctx, policy, closure); -} - -void grpc_lb_policy_notify_on_state_change(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - grpc_connectivity_state *state, - grpc_closure *closure) { - policy->vtable->notify_on_state_change(exec_ctx, policy, state, closure); -} - -grpc_connectivity_state grpc_lb_policy_check_connectivity( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_error **connectivity_error) { - return policy->vtable->check_connectivity(exec_ctx, policy, - connectivity_error); -} diff --git a/src/core/ext/client_config/lb_policy.h b/src/core/ext/client_config/lb_policy.h deleted file mode 100644 index a2f5446fc6..0000000000 --- a/src/core/ext/client_config/lb_policy.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_H - -#include "src/core/ext/client_config/subchannel.h" -#include "src/core/lib/iomgr/polling_entity.h" -#include "src/core/lib/transport/connectivity_state.h" - -/** A load balancing policy: specified by a vtable and a struct (which - is expected to be extended to contain some parameters) */ -typedef struct grpc_lb_policy grpc_lb_policy; -typedef struct grpc_lb_policy_vtable grpc_lb_policy_vtable; - -typedef void (*grpc_lb_completion)(void *cb_arg, grpc_subchannel *subchannel, - grpc_status_code status, const char *errmsg); - -struct grpc_lb_policy { - const grpc_lb_policy_vtable *vtable; - gpr_atm ref_pair; - /* owned pointer to interested parties in load balancing decisions */ - grpc_pollset_set *interested_parties; -}; - -struct grpc_lb_policy_vtable { - void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); - - void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); - - /** implement grpc_lb_policy_pick */ - int (*pick)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_polling_entity *pollent, - grpc_metadata_batch *initial_metadata, - uint32_t initial_metadata_flags, - grpc_connected_subchannel **target, grpc_closure *on_complete); - void (*cancel_pick)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_connected_subchannel **target); - void (*cancel_picks)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - uint32_t initial_metadata_flags_mask, - uint32_t initial_metadata_flags_eq); - - void (*ping_one)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_closure *closure); - - /** Try to enter a READY connectivity state */ - void (*exit_idle)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); - - /** check the current connectivity of the lb_policy */ - grpc_connectivity_state (*check_connectivity)( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_error **connectivity_error); - - /** call notify when the connectivity state of a channel changes from *state. - Updates *state with the new state of the policy. Calling with a NULL \a - state cancels the subscription. - */ - void (*notify_on_state_change)(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - grpc_connectivity_state *state, - grpc_closure *closure); -}; - -/*#define GRPC_LB_POLICY_REFCOUNT_DEBUG*/ -#ifdef GRPC_LB_POLICY_REFCOUNT_DEBUG -#define GRPC_LB_POLICY_REF(p, r) \ - grpc_lb_policy_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_LB_POLICY_UNREF(exec_ctx, p, r) \ - grpc_lb_policy_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) -#define GRPC_LB_POLICY_WEAK_REF(p, r) \ - grpc_lb_policy_weak_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, p, r) \ - grpc_lb_policy_weak_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) -void grpc_lb_policy_ref(grpc_lb_policy *policy, const char *file, int line, - const char *reason); -void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - const char *file, int line, const char *reason); -void grpc_lb_policy_weak_ref(grpc_lb_policy *policy, const char *file, int line, - const char *reason); -void grpc_lb_policy_weak_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - const char *file, int line, const char *reason); -#else -#define GRPC_LB_POLICY_REF(p, r) grpc_lb_policy_ref((p)) -#define GRPC_LB_POLICY_UNREF(cl, p, r) grpc_lb_policy_unref((cl), (p)) -#define GRPC_LB_POLICY_WEAK_REF(p, r) grpc_lb_policy_weak_ref((p)) -#define GRPC_LB_POLICY_WEAK_UNREF(cl, p, r) grpc_lb_policy_weak_unref((cl), (p)) -void grpc_lb_policy_ref(grpc_lb_policy *policy); -void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); -void grpc_lb_policy_weak_ref(grpc_lb_policy *policy); -void grpc_lb_policy_weak_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); -#endif - -/** called by concrete implementations to initialize the base struct */ -void grpc_lb_policy_init(grpc_lb_policy *policy, - const grpc_lb_policy_vtable *vtable); - -/** Given initial metadata in \a initial_metadata, find an appropriate - target for this rpc, and 'return' it by calling \a on_complete after setting - \a target. - Picking can be asynchronous. Any IO should be done under \a pollent. */ -int grpc_lb_policy_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_polling_entity *pollent, - grpc_metadata_batch *initial_metadata, - uint32_t initial_metadata_flags, - grpc_connected_subchannel **target, - grpc_closure *on_complete); - -void grpc_lb_policy_ping_one(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_closure *closure); - -void grpc_lb_policy_cancel_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_connected_subchannel **target); - -/** Cancel all pending picks which have: - (initial_metadata_flags & initial_metadata_flags_mask) == - initial_metadata_flags_eq */ -void grpc_lb_policy_cancel_picks(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - uint32_t initial_metadata_flags_mask, - uint32_t initial_metadata_flags_eq); - -/** Try to enter a READY connectivity state */ -void grpc_lb_policy_exit_idle(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy); - -/* Call notify when the connectivity state of a channel changes from \a *state. - * Updates \a *state with the new state of the policy */ -void grpc_lb_policy_notify_on_state_change(grpc_exec_ctx *exec_ctx, - grpc_lb_policy *policy, - grpc_connectivity_state *state, - grpc_closure *closure); - -grpc_connectivity_state grpc_lb_policy_check_connectivity( - grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, - grpc_error **connectivity_error); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_H */ diff --git a/src/core/ext/client_config/lb_policy_factory.c b/src/core/ext/client_config/lb_policy_factory.c deleted file mode 100644 index 70e46ef3cf..0000000000 --- a/src/core/ext/client_config/lb_policy_factory.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/lb_policy_factory.h" - -void grpc_lb_policy_factory_ref(grpc_lb_policy_factory* factory) { - factory->vtable->ref(factory); -} - -void grpc_lb_policy_factory_unref(grpc_lb_policy_factory* factory) { - factory->vtable->unref(factory); -} - -grpc_lb_policy* grpc_lb_policy_factory_create_lb_policy( - grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, - grpc_lb_policy_args* args) { - if (factory == NULL) return NULL; - return factory->vtable->create_lb_policy(exec_ctx, factory, args); -} diff --git a/src/core/ext/client_config/lb_policy_factory.h b/src/core/ext/client_config/lb_policy_factory.h deleted file mode 100644 index da1de3579a..0000000000 --- a/src/core/ext/client_config/lb_policy_factory.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_FACTORY_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_FACTORY_H - -#include "src/core/ext/client_config/client_channel_factory.h" -#include "src/core/ext/client_config/lb_policy.h" -#include "src/core/lib/iomgr/resolve_address.h" - -#include "src/core/lib/iomgr/exec_ctx.h" - -typedef struct grpc_lb_policy_factory grpc_lb_policy_factory; -typedef struct grpc_lb_policy_factory_vtable grpc_lb_policy_factory_vtable; - -struct grpc_lb_policy_factory { - const grpc_lb_policy_factory_vtable *vtable; -}; - -typedef struct grpc_lb_policy_args { - grpc_resolved_addresses *addresses; - grpc_client_channel_factory *client_channel_factory; -} grpc_lb_policy_args; - -struct grpc_lb_policy_factory_vtable { - void (*ref)(grpc_lb_policy_factory *factory); - void (*unref)(grpc_lb_policy_factory *factory); - - /** Implementation of grpc_lb_policy_factory_create_lb_policy */ - grpc_lb_policy *(*create_lb_policy)(grpc_exec_ctx *exec_ctx, - grpc_lb_policy_factory *factory, - grpc_lb_policy_args *args); - - /** Name for the LB policy this factory implements */ - const char *name; -}; - -void grpc_lb_policy_factory_ref(grpc_lb_policy_factory *factory); -void grpc_lb_policy_factory_unref(grpc_lb_policy_factory *factory); - -/** Create a lb_policy instance. */ -grpc_lb_policy *grpc_lb_policy_factory_create_lb_policy( - grpc_exec_ctx *exec_ctx, grpc_lb_policy_factory *factory, - grpc_lb_policy_args *args); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_FACTORY_H */ diff --git a/src/core/ext/client_config/lb_policy_registry.c b/src/core/ext/client_config/lb_policy_registry.c deleted file mode 100644 index a23643ecc6..0000000000 --- a/src/core/ext/client_config/lb_policy_registry.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/lb_policy_registry.h" - -#include - -#define MAX_POLICIES 10 - -static grpc_lb_policy_factory *g_all_of_the_lb_policies[MAX_POLICIES]; -static int g_number_of_lb_policies = 0; - -void grpc_lb_policy_registry_init(void) { g_number_of_lb_policies = 0; } - -void grpc_lb_policy_registry_shutdown(void) { - int i; - for (i = 0; i < g_number_of_lb_policies; i++) { - grpc_lb_policy_factory_unref(g_all_of_the_lb_policies[i]); - } -} - -void grpc_register_lb_policy(grpc_lb_policy_factory *factory) { - int i; - for (i = 0; i < g_number_of_lb_policies; i++) { - GPR_ASSERT(0 != strcmp(factory->vtable->name, - g_all_of_the_lb_policies[i]->vtable->name)); - } - GPR_ASSERT(g_number_of_lb_policies != MAX_POLICIES); - grpc_lb_policy_factory_ref(factory); - g_all_of_the_lb_policies[g_number_of_lb_policies++] = factory; -} - -static grpc_lb_policy_factory *lookup_factory(const char *name) { - int i; - - if (name == NULL) return NULL; - - for (i = 0; i < g_number_of_lb_policies; i++) { - if (0 == strcmp(name, g_all_of_the_lb_policies[i]->vtable->name)) { - return g_all_of_the_lb_policies[i]; - } - } - - return NULL; -} - -grpc_lb_policy *grpc_lb_policy_create(grpc_exec_ctx *exec_ctx, const char *name, - grpc_lb_policy_args *args) { - grpc_lb_policy_factory *factory = lookup_factory(name); - grpc_lb_policy *lb_policy = - grpc_lb_policy_factory_create_lb_policy(exec_ctx, factory, args); - return lb_policy; -} diff --git a/src/core/ext/client_config/lb_policy_registry.h b/src/core/ext/client_config/lb_policy_registry.h deleted file mode 100644 index 92f38d6de6..0000000000 --- a/src/core/ext/client_config/lb_policy_registry.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_REGISTRY_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_REGISTRY_H - -#include "src/core/ext/client_config/lb_policy_factory.h" -#include "src/core/lib/iomgr/exec_ctx.h" - -/** Initialize the registry and set \a default_factory as the factory to be - * returned when no name is provided in a lookup */ -void grpc_lb_policy_registry_init(void); -void grpc_lb_policy_registry_shutdown(void); - -/** Register a LB policy factory. */ -void grpc_register_lb_policy(grpc_lb_policy_factory *factory); - -/** Create a \a grpc_lb_policy instance. - * - * If \a name is NULL, the default factory from \a grpc_lb_policy_registry_init - * will be returned. */ -grpc_lb_policy *grpc_lb_policy_create(grpc_exec_ctx *exec_ctx, const char *name, - grpc_lb_policy_args *args); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_LB_POLICY_REGISTRY_H */ diff --git a/src/core/ext/client_config/parse_address.c b/src/core/ext/client_config/parse_address.c deleted file mode 100644 index 8b4abe24a6..0000000000 --- a/src/core/ext/client_config/parse_address.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * - * 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/ext/client_config/parse_address.h" - -#include -#include -#ifdef GPR_HAVE_UNIX_SOCKET -#include -#endif - -#include -#include -#include -#include - -#ifdef GPR_HAVE_UNIX_SOCKET -int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) { - struct sockaddr_un *un = (struct sockaddr_un *)addr; - - un->sun_family = AF_UNIX; - strcpy(un->sun_path, uri->path); - *len = strlen(un->sun_path) + sizeof(un->sun_family) + 1; - - return 1; -} -#endif - -int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) { - const char *host_port = uri->path; - char *host; - char *port; - int port_num; - int result = 0; - struct sockaddr_in *in = (struct sockaddr_in *)addr; - - if (*host_port == '/') ++host_port; - if (!gpr_split_host_port(host_port, &host, &port)) { - return 0; - } - - memset(in, 0, sizeof(*in)); - *len = sizeof(*in); - in->sin_family = AF_INET; - if (inet_pton(AF_INET, host, &in->sin_addr) == 0) { - gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host); - goto done; - } - - if (port != NULL) { - if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || - port_num > 65535) { - gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port); - goto done; - } - in->sin_port = htons((uint16_t)port_num); - } else { - gpr_log(GPR_ERROR, "no port given for ipv4 scheme"); - goto done; - } - - result = 1; -done: - gpr_free(host); - gpr_free(port); - return result; -} - -int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len) { - const char *host_port = uri->path; - char *host; - char *port; - int port_num; - int result = 0; - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr; - - if (*host_port == '/') ++host_port; - if (!gpr_split_host_port(host_port, &host, &port)) { - return 0; - } - - memset(in6, 0, sizeof(*in6)); - *len = sizeof(*in6); - in6->sin6_family = AF_INET6; - if (inet_pton(AF_INET6, host, &in6->sin6_addr) == 0) { - gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host); - goto done; - } - - if (port != NULL) { - if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || - port_num > 65535) { - gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port); - goto done; - } - in6->sin6_port = htons((uint16_t)port_num); - } else { - gpr_log(GPR_ERROR, "no port given for ipv6 scheme"); - goto done; - } - - result = 1; -done: - gpr_free(host); - gpr_free(port); - return result; -} diff --git a/src/core/ext/client_config/parse_address.h b/src/core/ext/client_config/parse_address.h deleted file mode 100644 index 74c86f4d93..0000000000 --- a/src/core/ext/client_config/parse_address.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_PARSE_ADDRESS_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_PARSE_ADDRESS_H - -#include - -#include "src/core/ext/client_config/uri_parser.h" -#include "src/core/lib/iomgr/sockaddr.h" - -#ifdef GPR_HAVE_UNIX_SOCKET -/** Populate \a addr and \a len from \a uri, whose path is expected to contain a - * unix socket path. Returns true upon success. */ -int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len); -#endif - -/** Populate /a addr and \a len from \a uri, whose path is expected to contain a - * host:port pair. Returns true upon success. */ -int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len); - -/** Populate /a addr and \a len from \a uri, whose path is expected to contain a - * host:port pair. Returns true upon success. */ -int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr, size_t *len); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_PARSE_ADDRESS_H */ diff --git a/src/core/ext/client_config/resolver.c b/src/core/ext/client_config/resolver.c deleted file mode 100644 index 7534ea62af..0000000000 --- a/src/core/ext/client_config/resolver.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/resolver.h" - -void grpc_resolver_init(grpc_resolver *resolver, - const grpc_resolver_vtable *vtable) { - resolver->vtable = vtable; - gpr_ref_init(&resolver->refs, 1); -} - -#ifdef GRPC_RESOLVER_REFCOUNT_DEBUG -void grpc_resolver_ref(grpc_resolver *resolver, grpc_closure_list *closure_list, - const char *file, int line, const char *reason) { - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "RESOLVER:%p ref %d -> %d %s", - resolver, (int)resolver->refs.count, (int)resolver->refs.count + 1, - reason); -#else -void grpc_resolver_ref(grpc_resolver *resolver) { -#endif - gpr_ref(&resolver->refs); -} - -#ifdef GRPC_RESOLVER_REFCOUNT_DEBUG -void grpc_resolver_unref(grpc_resolver *resolver, - grpc_closure_list *closure_list, const char *file, - int line, const char *reason) { - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "RESOLVER:%p unref %d -> %d %s", - resolver, (int)resolver->refs.count, (int)resolver->refs.count - 1, - reason); -#else -void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver) { -#endif - if (gpr_unref(&resolver->refs)) { - resolver->vtable->destroy(exec_ctx, resolver); - } -} - -void grpc_resolver_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver) { - resolver->vtable->shutdown(exec_ctx, resolver); -} - -void grpc_resolver_channel_saw_error(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver) { - resolver->vtable->channel_saw_error(exec_ctx, resolver); -} - -void grpc_resolver_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_resolver_result **result, - grpc_closure *on_complete) { - resolver->vtable->next(exec_ctx, resolver, result, on_complete); -} diff --git a/src/core/ext/client_config/resolver.h b/src/core/ext/client_config/resolver.h deleted file mode 100644 index 88ac262d51..0000000000 --- a/src/core/ext/client_config/resolver.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_H - -#include "src/core/ext/client_config/resolver_result.h" -#include "src/core/ext/client_config/subchannel.h" -#include "src/core/lib/iomgr/iomgr.h" - -typedef struct grpc_resolver grpc_resolver; -typedef struct grpc_resolver_vtable grpc_resolver_vtable; - -/** grpc_resolver provides grpc_resolver_result objects to grpc_channel - objects */ -struct grpc_resolver { - const grpc_resolver_vtable *vtable; - gpr_refcount refs; -}; - -struct grpc_resolver_vtable { - void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); - void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); - void (*channel_saw_error)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); - void (*next)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_resolver_result **result, grpc_closure *on_complete); -}; - -#ifdef GRPC_RESOLVER_REFCOUNT_DEBUG -#define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_RESOLVER_UNREF(cl, p, r) \ - grpc_resolver_unref((cl), (p), __FILE__, __LINE__, (r)) -void grpc_resolver_ref(grpc_resolver *policy, const char *file, int line, - const char *reason); -void grpc_resolver_unref(grpc_resolver *policy, grpc_closure_list *closure_list, - const char *file, int line, const char *reason); -#else -#define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p)) -#define GRPC_RESOLVER_UNREF(cl, p, r) grpc_resolver_unref((cl), (p)) -void grpc_resolver_ref(grpc_resolver *policy); -void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *policy); -#endif - -void grpc_resolver_init(grpc_resolver *resolver, - const grpc_resolver_vtable *vtable); - -void grpc_resolver_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); - -/** Notification that the channel has seen an error on some address. - Can be used as a hint that re-resolution is desirable soon. */ -void grpc_resolver_channel_saw_error(grpc_exec_ctx *exec_ctx, - grpc_resolver *resolver); - -/** Get the next client config. Called by the channel to fetch a new - configuration. Expected to set *result with a new configuration, - and then schedule on_complete for execution. - - If resolution is fatally broken, set *result to NULL and - schedule on_complete. */ -void grpc_resolver_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, - grpc_resolver_result **result, - grpc_closure *on_complete); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_H */ diff --git a/src/core/ext/client_config/resolver_factory.c b/src/core/ext/client_config/resolver_factory.c deleted file mode 100644 index 67832dcf59..0000000000 --- a/src/core/ext/client_config/resolver_factory.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/resolver_factory.h" - -void grpc_resolver_factory_ref(grpc_resolver_factory* factory) { - factory->vtable->ref(factory); -} - -void grpc_resolver_factory_unref(grpc_resolver_factory* factory) { - factory->vtable->unref(factory); -} - -/** Create a resolver instance for a name */ -grpc_resolver* grpc_resolver_factory_create_resolver( - grpc_resolver_factory* factory, grpc_resolver_args* args) { - if (factory == NULL) return NULL; - return factory->vtable->create_resolver(factory, args); -} - -char* grpc_resolver_factory_get_default_authority( - grpc_resolver_factory* factory, grpc_uri* uri) { - if (factory == NULL) return NULL; - return factory->vtable->get_default_authority(factory, uri); -} diff --git a/src/core/ext/client_config/resolver_factory.h b/src/core/ext/client_config/resolver_factory.h deleted file mode 100644 index f69bf79564..0000000000 --- a/src/core/ext/client_config/resolver_factory.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_FACTORY_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_FACTORY_H - -#include "src/core/ext/client_config/client_channel_factory.h" -#include "src/core/ext/client_config/resolver.h" -#include "src/core/ext/client_config/uri_parser.h" - -typedef struct grpc_resolver_factory grpc_resolver_factory; -typedef struct grpc_resolver_factory_vtable grpc_resolver_factory_vtable; - -/** grpc_resolver provides grpc_resolver_result objects to grpc_channel - objects */ -struct grpc_resolver_factory { - const grpc_resolver_factory_vtable *vtable; -}; - -typedef struct grpc_resolver_args { - grpc_uri *uri; - grpc_client_channel_factory *client_channel_factory; -} grpc_resolver_args; - -struct grpc_resolver_factory_vtable { - void (*ref)(grpc_resolver_factory *factory); - void (*unref)(grpc_resolver_factory *factory); - - /** Implementation of grpc_resolver_factory_create_resolver */ - grpc_resolver *(*create_resolver)(grpc_resolver_factory *factory, - grpc_resolver_args *args); - - /** Implementation of grpc_resolver_factory_get_default_authority */ - char *(*get_default_authority)(grpc_resolver_factory *factory, grpc_uri *uri); - - /** URI scheme that this factory implements */ - const char *scheme; -}; - -void grpc_resolver_factory_ref(grpc_resolver_factory *resolver); -void grpc_resolver_factory_unref(grpc_resolver_factory *resolver); - -/** Create a resolver instance for a name */ -grpc_resolver *grpc_resolver_factory_create_resolver( - grpc_resolver_factory *factory, grpc_resolver_args *args); - -/** Return a (freshly allocated with gpr_malloc) string representing - the default authority to use for this scheme. */ -char *grpc_resolver_factory_get_default_authority( - grpc_resolver_factory *factory, grpc_uri *uri); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_FACTORY_H */ diff --git a/src/core/ext/client_config/resolver_registry.c b/src/core/ext/client_config/resolver_registry.c deleted file mode 100644 index e7a4abd568..0000000000 --- a/src/core/ext/client_config/resolver_registry.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/resolver_registry.h" - -#include - -#include -#include -#include - -#define MAX_RESOLVERS 10 - -static grpc_resolver_factory *g_all_of_the_resolvers[MAX_RESOLVERS]; -static int g_number_of_resolvers = 0; - -static char *g_default_resolver_prefix; - -void grpc_resolver_registry_init(const char *default_resolver_prefix) { - g_default_resolver_prefix = gpr_strdup(default_resolver_prefix); -} - -void grpc_resolver_registry_shutdown(void) { - int i; - for (i = 0; i < g_number_of_resolvers; i++) { - grpc_resolver_factory_unref(g_all_of_the_resolvers[i]); - } - gpr_free(g_default_resolver_prefix); - // FIXME(ctiller): this should live in grpc_resolver_registry_init, - // however that would have the client_config plugin call this AFTER we start - // registering resolvers from third party plugins, and so they'd never show - // up. - // We likely need some kind of dependency system for plugins.... what form - // that takes is TBD. - g_number_of_resolvers = 0; -} - -void grpc_register_resolver_type(grpc_resolver_factory *factory) { - int i; - for (i = 0; i < g_number_of_resolvers; i++) { - GPR_ASSERT(0 != strcmp(factory->vtable->scheme, - g_all_of_the_resolvers[i]->vtable->scheme)); - } - GPR_ASSERT(g_number_of_resolvers != MAX_RESOLVERS); - grpc_resolver_factory_ref(factory); - g_all_of_the_resolvers[g_number_of_resolvers++] = factory; -} - -static grpc_resolver_factory *lookup_factory(const char *name) { - int i; - - for (i = 0; i < g_number_of_resolvers; i++) { - if (0 == strcmp(name, g_all_of_the_resolvers[i]->vtable->scheme)) { - return g_all_of_the_resolvers[i]; - } - } - - return NULL; -} - -grpc_resolver_factory *grpc_resolver_factory_lookup(const char *name) { - grpc_resolver_factory *f = lookup_factory(name); - if (f) grpc_resolver_factory_ref(f); - return f; -} - -static grpc_resolver_factory *lookup_factory_by_uri(grpc_uri *uri) { - if (!uri) return NULL; - return lookup_factory(uri->scheme); -} - -static grpc_resolver_factory *resolve_factory(const char *target, - grpc_uri **uri) { - char *tmp; - grpc_resolver_factory *factory = NULL; - - GPR_ASSERT(uri != NULL); - *uri = grpc_uri_parse(target, 1); - factory = lookup_factory_by_uri(*uri); - if (factory == NULL) { - if (g_default_resolver_prefix != NULL) { - grpc_uri_destroy(*uri); - gpr_asprintf(&tmp, "%s%s", g_default_resolver_prefix, target); - *uri = grpc_uri_parse(tmp, 1); - factory = lookup_factory_by_uri(*uri); - if (factory == NULL) { - grpc_uri_destroy(grpc_uri_parse(target, 0)); - grpc_uri_destroy(grpc_uri_parse(tmp, 0)); - gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target, - tmp); - } - gpr_free(tmp); - } else { - grpc_uri_destroy(grpc_uri_parse(target, 0)); - gpr_log(GPR_ERROR, "don't know how to resolve '%s'", target); - } - } - return factory; -} - -grpc_resolver *grpc_resolver_create( - const char *target, grpc_client_channel_factory *client_channel_factory) { - grpc_uri *uri = NULL; - grpc_resolver_factory *factory = resolve_factory(target, &uri); - grpc_resolver *resolver; - grpc_resolver_args args; - memset(&args, 0, sizeof(args)); - args.uri = uri; - args.client_channel_factory = client_channel_factory; - resolver = grpc_resolver_factory_create_resolver(factory, &args); - grpc_uri_destroy(uri); - return resolver; -} - -char *grpc_get_default_authority(const char *target) { - grpc_uri *uri = NULL; - grpc_resolver_factory *factory = resolve_factory(target, &uri); - char *authority = grpc_resolver_factory_get_default_authority(factory, uri); - grpc_uri_destroy(uri); - return authority; -} diff --git a/src/core/ext/client_config/resolver_registry.h b/src/core/ext/client_config/resolver_registry.h deleted file mode 100644 index 5ef1383cd3..0000000000 --- a/src/core/ext/client_config/resolver_registry.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_REGISTRY_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_REGISTRY_H - -#include "src/core/ext/client_config/resolver_factory.h" - -void grpc_resolver_registry_init(const char *default_prefix); -void grpc_resolver_registry_shutdown(void); - -/** Register a resolver type. - URI's of \a scheme will be resolved with the given resolver. - If \a priority is greater than zero, then the resolver will be eligible - to resolve names that are passed in with no scheme. Higher priority - resolvers will be tried before lower priority schemes. */ -void grpc_register_resolver_type(grpc_resolver_factory *factory); - -/** Create a resolver given \a target. - First tries to parse \a target as a URI. If this succeeds, tries - to locate a registered resolver factory based on the URI scheme. - If parsing or location fails, prefixes default_prefix from - grpc_resolver_registry_init to target, and tries again (if default_prefix - was not NULL). - If a resolver factory was found, use it to instantiate a resolver and - return it. - If a resolver factory was not found, return NULL. */ -grpc_resolver *grpc_resolver_create( - const char *target, grpc_client_channel_factory *client_channel_factory); - -/** Find a resolver factory given a name and return an (owned-by-the-caller) - * reference to it */ -grpc_resolver_factory *grpc_resolver_factory_lookup(const char *name); - -/** Given a target, return a (freshly allocated with gpr_malloc) string - representing the default authority to pass from a client. */ -char *grpc_get_default_authority(const char *target); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_REGISTRY_H */ diff --git a/src/core/ext/client_config/resolver_result.c b/src/core/ext/client_config/resolver_result.c deleted file mode 100644 index c6c4166e83..0000000000 --- a/src/core/ext/client_config/resolver_result.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/resolver_result.h" - -#include - -#include - -struct grpc_resolver_result { - gpr_refcount refs; - grpc_lb_policy *lb_policy; -}; - -grpc_resolver_result *grpc_resolver_result_create() { - grpc_resolver_result *c = gpr_malloc(sizeof(*c)); - memset(c, 0, sizeof(*c)); - gpr_ref_init(&c->refs, 1); - return c; -} - -void grpc_resolver_result_ref(grpc_resolver_result *c) { gpr_ref(&c->refs); } - -void grpc_resolver_result_unref(grpc_exec_ctx *exec_ctx, - grpc_resolver_result *c) { - if (gpr_unref(&c->refs)) { - if (c->lb_policy != NULL) { - GRPC_LB_POLICY_UNREF(exec_ctx, c->lb_policy, "resolver_result"); - } - gpr_free(c); - } -} - -void grpc_resolver_result_set_lb_policy(grpc_resolver_result *c, - grpc_lb_policy *lb_policy) { - GPR_ASSERT(c->lb_policy == NULL); - if (lb_policy) { - GRPC_LB_POLICY_REF(lb_policy, "resolver_result"); - } - c->lb_policy = lb_policy; -} - -grpc_lb_policy *grpc_resolver_result_get_lb_policy(grpc_resolver_result *c) { - return c->lb_policy; -} diff --git a/src/core/ext/client_config/resolver_result.h b/src/core/ext/client_config/resolver_result.h deleted file mode 100644 index 402f7dbd7e..0000000000 --- a/src/core/ext/client_config/resolver_result.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H - -#include "src/core/ext/client_config/lb_policy.h" - -/** Results reported from a grpc_resolver. */ -typedef struct grpc_resolver_result grpc_resolver_result; - -grpc_resolver_result *grpc_resolver_result_create(); -void grpc_resolver_result_ref(grpc_resolver_result *client_config); -void grpc_resolver_result_unref(grpc_exec_ctx *exec_ctx, - grpc_resolver_result *client_config); - -void grpc_resolver_result_set_lb_policy(grpc_resolver_result *client_config, - grpc_lb_policy *lb_policy); -grpc_lb_policy *grpc_resolver_result_get_lb_policy( - grpc_resolver_result *client_config); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_RESOLVER_RESULT_H */ diff --git a/src/core/ext/client_config/subchannel.c b/src/core/ext/client_config/subchannel.c deleted file mode 100644 index df35904b85..0000000000 --- a/src/core/ext/client_config/subchannel.c +++ /dev/null @@ -1,730 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/subchannel.h" - -#include - -#include -#include - -#include "src/core/ext/client_config/client_channel.h" -#include "src/core/ext/client_config/initial_connect_string.h" -#include "src/core/ext/client_config/subchannel_index.h" -#include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/channel/connected_channel.h" -#include "src/core/lib/iomgr/timer.h" -#include "src/core/lib/profiling/timers.h" -#include "src/core/lib/support/backoff.h" -#include "src/core/lib/surface/channel.h" -#include "src/core/lib/surface/channel_init.h" -#include "src/core/lib/transport/connectivity_state.h" - -#define INTERNAL_REF_BITS 16 -#define STRONG_REF_MASK (~(gpr_atm)((1 << INTERNAL_REF_BITS) - 1)) - -#define GRPC_SUBCHANNEL_MIN_CONNECT_TIMEOUT_SECONDS 20 -#define GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS 1 -#define GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER 1.6 -#define GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS 120 -#define GRPC_SUBCHANNEL_RECONNECT_JITTER 0.2 - -#define GET_CONNECTED_SUBCHANNEL(subchannel, barrier) \ - ((grpc_connected_subchannel *)(gpr_atm_##barrier##_load( \ - &(subchannel)->connected_subchannel))) - -typedef struct { - grpc_closure closure; - grpc_subchannel *subchannel; - grpc_connectivity_state connectivity_state; -} state_watcher; - -typedef struct external_state_watcher { - grpc_subchannel *subchannel; - grpc_pollset_set *pollset_set; - grpc_closure *notify; - grpc_closure closure; - struct external_state_watcher *next; - struct external_state_watcher *prev; -} external_state_watcher; - -struct grpc_subchannel { - grpc_connector *connector; - - /** refcount - - lower INTERNAL_REF_BITS bits are for internal references: - these do not keep the subchannel open. - - upper remaining bits are for public references: these do - keep the subchannel open */ - gpr_atm ref_pair; - - /** non-transport related channel filters */ - const grpc_channel_filter **filters; - size_t num_filters; - /** channel arguments */ - grpc_channel_args *args; - /** address to connect to */ - struct sockaddr *addr; - size_t addr_len; - - grpc_subchannel_key *key; - - /** initial string to send to peer */ - gpr_slice initial_connect_string; - - /** set during connection */ - grpc_connect_out_args connecting_result; - - /** callback for connection finishing */ - grpc_closure connected; - - /** pollset_set tracking who's interested in a connection - being setup */ - grpc_pollset_set *pollset_set; - - /** active connection, or null; of type grpc_connected_subchannel */ - gpr_atm connected_subchannel; - - /** mutex protecting remaining elements */ - gpr_mu mu; - - /** have we seen a disconnection? */ - int disconnected; - /** are we connecting */ - int connecting; - /** connectivity state tracking */ - grpc_connectivity_state_tracker state_tracker; - - external_state_watcher root_external_state_watcher; - - /** next connect attempt time */ - gpr_timespec next_attempt; - /** backoff state */ - gpr_backoff backoff_state; - /** do we have an active alarm? */ - int have_alarm; - /** our alarm */ - grpc_timer alarm; -}; - -struct grpc_subchannel_call { - grpc_connected_subchannel *connection; -}; - -#define SUBCHANNEL_CALL_TO_CALL_STACK(call) ((grpc_call_stack *)((call) + 1)) -#define CHANNEL_STACK_FROM_CONNECTION(con) ((grpc_channel_stack *)(con)) -#define CALLSTACK_TO_SUBCHANNEL_CALL(callstack) \ - (((grpc_subchannel_call *)(callstack)) - 1) - -static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *subchannel, - grpc_error *error); - -#ifdef GRPC_STREAM_REFCOUNT_DEBUG -#define REF_REASON reason -#define REF_LOG(name, p) \ - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "%s: %p ref %d -> %d %s", \ - (name), (p), (p)->refs.count, (p)->refs.count + 1, reason) -#define UNREF_LOG(name, p) \ - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "%s: %p unref %d -> %d %s", \ - (name), (p), (p)->refs.count, (p)->refs.count - 1, reason) -#define REF_MUTATE_EXTRA_ARGS \ - GRPC_SUBCHANNEL_REF_EXTRA_ARGS, const char *purpose -#define REF_MUTATE_PURPOSE(x) , file, line, reason, x -#else -#define REF_REASON "" -#define REF_LOG(name, p) \ - do { \ - } while (0) -#define UNREF_LOG(name, p) \ - do { \ - } while (0) -#define REF_MUTATE_EXTRA_ARGS -#define REF_MUTATE_PURPOSE(x) -#endif - -/* - * connection implementation - */ - -static void connection_destroy(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_connected_subchannel *c = arg; - grpc_channel_stack_destroy(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c)); - gpr_free(c); -} - -void grpc_connected_subchannel_ref( - grpc_connected_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { - GRPC_CHANNEL_STACK_REF(CHANNEL_STACK_FROM_CONNECTION(c), REF_REASON); -} - -void grpc_connected_subchannel_unref(grpc_exec_ctx *exec_ctx, - grpc_connected_subchannel *c - GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { - GRPC_CHANNEL_STACK_UNREF(exec_ctx, CHANNEL_STACK_FROM_CONNECTION(c), - REF_REASON); -} - -/* - * grpc_subchannel implementation - */ - -static void subchannel_destroy(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_subchannel *c = arg; - gpr_free((void *)c->filters); - grpc_channel_args_destroy(c->args); - gpr_free(c->addr); - gpr_slice_unref(c->initial_connect_string); - 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); -} - -static gpr_atm ref_mutate(grpc_subchannel *c, gpr_atm delta, - int barrier REF_MUTATE_EXTRA_ARGS) { - gpr_atm old_val = barrier ? gpr_atm_full_fetch_add(&c->ref_pair, delta) - : gpr_atm_no_barrier_fetch_add(&c->ref_pair, delta); -#ifdef GRPC_STREAM_REFCOUNT_DEBUG - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "SUBCHANNEL: %p % 12s 0x%08x -> 0x%08x [%s]", c, purpose, old_val, - old_val + delta, reason); -#endif - return old_val; -} - -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; -} - -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; - grpc_connector_shutdown(exec_ctx, c->connector); - con = GET_CONNECTED_SUBCHANNEL(c, no_barrier); - if (con != NULL) { - GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, con, "connection"); - gpr_atm_no_barrier_store(&c->connected_subchannel, (gpr_atm)0xdeadbeef); - } - gpr_mu_unlock(&c->mu); -} - -void grpc_subchannel_unref(grpc_exec_ctx *exec_ctx, - grpc_subchannel *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { - gpr_atm old_refs; - old_refs = ref_mutate(c, (gpr_atm)1 - (gpr_atm)(1 << INTERNAL_REF_BITS), - 1 REF_MUTATE_PURPOSE("STRONG_UNREF")); - if ((old_refs & STRONG_REF_MASK) == (1 << INTERNAL_REF_BITS)) { - disconnect(exec_ctx, c); - } - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "strong-unref"); -} - -void grpc_subchannel_weak_unref(grpc_exec_ctx *exec_ctx, - grpc_subchannel *c - GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { - gpr_atm old_refs; - old_refs = ref_mutate(c, -(gpr_atm)1, 1 REF_MUTATE_PURPOSE("WEAK_UNREF")); - if (old_refs == 1) { - grpc_exec_ctx_sched(exec_ctx, grpc_closure_create(subchannel_destroy, c), - GRPC_ERROR_NONE, NULL); - } -} - -grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, - grpc_connector *connector, - grpc_subchannel_args *args) { - 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); - c->num_filters = args->filter_count; - if (c->num_filters > 0) { - c->filters = gpr_malloc(sizeof(grpc_channel_filter *) * c->num_filters); - memcpy((void *)c->filters, args->filters, - sizeof(grpc_channel_filter *) * c->num_filters); - } else { - c->filters = NULL; - } - c->addr = gpr_malloc(args->addr_len); - if (args->addr_len) memcpy(c->addr, args->addr, args->addr_len); - c->pollset_set = grpc_pollset_set_create(); - c->addr_len = args->addr_len; - grpc_set_initial_connect_string(&c->addr, &c->addr_len, - &c->initial_connect_string); - c->args = grpc_channel_args_copy(args->args); - c->root_external_state_watcher.next = c->root_external_state_watcher.prev = - &c->root_external_state_watcher; - grpc_closure_init(&c->connected, subchannel_connected, c); - grpc_connectivity_state_init(&c->state_tracker, GRPC_CHANNEL_IDLE, - "subchannel"); - gpr_backoff_init(&c->backoff_state, - GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER, - GRPC_SUBCHANNEL_RECONNECT_JITTER, - GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS * 1000, - GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS * 1000); - if (c->args) { - for (size_t i = 0; i < c->args->num_args; i++) { - if (0 == strcmp(c->args->args[i].key, - "grpc.testing.fixed_reconnect_backoff")) { - GPR_ASSERT(c->args->args[i].type == GRPC_ARG_INTEGER); - gpr_backoff_init(&c->backoff_state, 1.0, 0.0, - c->args->args[i].value.integer, - c->args->args[i].value.integer); - } - if (0 == - strcmp(c->args->args[i].key, GRPC_ARG_MAX_RECONNECT_BACKOFF_MS)) { - if (c->args->args[i].type == GRPC_ARG_INTEGER) { - if (c->args->args[i].value.integer >= 0) { - gpr_backoff_init( - &c->backoff_state, GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER, - GRPC_SUBCHANNEL_RECONNECT_JITTER, - GPR_MIN(c->args->args[i].value.integer, - GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS * 1000), - c->args->args[i].value.integer); - } else { - gpr_log(GPR_ERROR, GRPC_ARG_MAX_RECONNECT_BACKOFF_MS - " : must be non-negative"); - } - } else { - gpr_log(GPR_ERROR, - GRPC_ARG_MAX_RECONNECT_BACKOFF_MS " : must be an integer"); - } - } - } - } - gpr_mu_init(&c->mu); - - return grpc_subchannel_index_register(exec_ctx, key, c); -} - -static void continue_connect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) { - grpc_connect_in_args args; - - args.interested_parties = c->pollset_set; - args.addr = c->addr; - args.addr_len = c->addr_len; - args.deadline = c->next_attempt; - args.channel_args = c->args; - args.initial_connect_string = c->initial_connect_string; - - grpc_connectivity_state_set(exec_ctx, &c->state_tracker, - GRPC_CHANNEL_CONNECTING, GRPC_ERROR_NONE, - "state_change"); - grpc_connector_connect(exec_ctx, c->connector, &args, &c->connecting_result, - &c->connected); -} - -static void start_connect(grpc_exec_ctx *exec_ctx, grpc_subchannel *c) { - c->next_attempt = - gpr_backoff_begin(&c->backoff_state, gpr_now(GPR_CLOCK_MONOTONIC)); - continue_connect(exec_ctx, c); -} - -grpc_connectivity_state grpc_subchannel_check_connectivity(grpc_subchannel *c, - grpc_error **error) { - grpc_connectivity_state state; - gpr_mu_lock(&c->mu); - state = grpc_connectivity_state_check(&c->state_tracker, error); - gpr_mu_unlock(&c->mu); - return state; -} - -static void on_external_state_watcher_done(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - external_state_watcher *w = arg; - grpc_closure *follow_up = w->notify; - if (w->pollset_set != NULL) { - grpc_pollset_set_del_pollset_set(exec_ctx, w->subchannel->pollset_set, - w->pollset_set); - } - gpr_mu_lock(&w->subchannel->mu); - w->next->prev = w->prev; - w->prev->next = w->next; - gpr_mu_unlock(&w->subchannel->mu); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, w->subchannel, "external_state_watcher"); - gpr_free(w); - follow_up->cb(exec_ctx, follow_up->cb_arg, error); -} - -void grpc_subchannel_notify_on_state_change( - grpc_exec_ctx *exec_ctx, grpc_subchannel *c, - grpc_pollset_set *interested_parties, grpc_connectivity_state *state, - grpc_closure *notify) { - external_state_watcher *w; - - if (state == NULL) { - gpr_mu_lock(&c->mu); - for (w = c->root_external_state_watcher.next; - w != &c->root_external_state_watcher; w = w->next) { - if (w->notify == notify) { - grpc_connectivity_state_notify_on_state_change( - exec_ctx, &c->state_tracker, NULL, &w->closure); - } - } - gpr_mu_unlock(&c->mu); - } else { - w = gpr_malloc(sizeof(*w)); - w->subchannel = c; - w->pollset_set = interested_parties; - w->notify = notify; - grpc_closure_init(&w->closure, on_external_state_watcher_done, w); - if (interested_parties != NULL) { - grpc_pollset_set_add_pollset_set(exec_ctx, c->pollset_set, - interested_parties); - } - GRPC_SUBCHANNEL_WEAK_REF(c, "external_state_watcher"); - gpr_mu_lock(&c->mu); - w->next = &c->root_external_state_watcher; - w->prev = w->next->prev; - w->next->prev = w->prev->next = w; - if (grpc_connectivity_state_notify_on_state_change( - exec_ctx, &c->state_tracker, state, &w->closure)) { - c->connecting = 1; - /* released by connection */ - GRPC_SUBCHANNEL_WEAK_REF(c, "connecting"); - start_connect(exec_ctx, c); - } - gpr_mu_unlock(&c->mu); - } -} - -void grpc_connected_subchannel_process_transport_op( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, - grpc_transport_op *op) { - grpc_channel_stack *channel_stack = CHANNEL_STACK_FROM_CONNECTION(con); - grpc_channel_element *top_elem = grpc_channel_stack_element(channel_stack, 0); - top_elem->filter->start_transport_op(exec_ctx, top_elem, op); -} - -static void subchannel_on_child_state_changed(grpc_exec_ctx *exec_ctx, void *p, - grpc_error *error) { - state_watcher *sw = p; - grpc_subchannel *c = sw->subchannel; - gpr_mu *mu = &c->mu; - - gpr_mu_lock(mu); - - /* if we failed just leave this closure */ - if (sw->connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) { - /* any errors on a subchannel ==> we're done, create a new one */ - sw->connectivity_state = GRPC_CHANNEL_SHUTDOWN; - } - grpc_connectivity_state_set(exec_ctx, &c->state_tracker, - sw->connectivity_state, GRPC_ERROR_REF(error), - "reflect_child"); - if (sw->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { - grpc_connected_subchannel_notify_on_state_change( - exec_ctx, GET_CONNECTED_SUBCHANNEL(c, no_barrier), NULL, - &sw->connectivity_state, &sw->closure); - GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher"); - sw = NULL; - } - - gpr_mu_unlock(mu); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "state_watcher"); - gpr_free(sw); -} - -static void connected_subchannel_state_op(grpc_exec_ctx *exec_ctx, - grpc_connected_subchannel *con, - grpc_pollset_set *interested_parties, - grpc_connectivity_state *state, - grpc_closure *closure) { - grpc_transport_op op; - grpc_channel_element *elem; - memset(&op, 0, sizeof(op)); - op.connectivity_state = state; - op.on_connectivity_state_change = closure; - op.bind_pollset_set = interested_parties; - elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); - elem->filter->start_transport_op(exec_ctx, elem, &op); -} - -void grpc_connected_subchannel_notify_on_state_change( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, - grpc_pollset_set *interested_parties, grpc_connectivity_state *state, - grpc_closure *closure) { - connected_subchannel_state_op(exec_ctx, con, interested_parties, state, - closure); -} - -void grpc_connected_subchannel_ping(grpc_exec_ctx *exec_ctx, - grpc_connected_subchannel *con, - grpc_closure *closure) { - grpc_transport_op op; - grpc_channel_element *elem; - memset(&op, 0, sizeof(op)); - op.send_ping = closure; - elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); - elem->filter->start_transport_op(exec_ctx, elem, &op); -} - -static void publish_transport_locked(grpc_exec_ctx *exec_ctx, - grpc_subchannel *c) { - grpc_connected_subchannel *con; - grpc_channel_stack *stk; - state_watcher *sw_subchannel; - - /* construct channel stack */ - grpc_channel_stack_builder *builder = grpc_channel_stack_builder_create(); - grpc_channel_stack_builder_set_channel_arguments( - builder, c->connecting_result.channel_args); - grpc_channel_stack_builder_set_transport(builder, - c->connecting_result.transport); - - if (grpc_channel_init_create_stack(exec_ctx, builder, - GRPC_CLIENT_SUBCHANNEL)) { - con = grpc_channel_stack_builder_finish(exec_ctx, builder, 0, 1, - connection_destroy, NULL); - } else { - grpc_channel_stack_builder_destroy(builder); - abort(); /* TODO(ctiller): what to do here (previously we just crashed) */ - } - stk = CHANNEL_STACK_FROM_CONNECTION(con); - memset(&c->connecting_result, 0, sizeof(c->connecting_result)); - - /* initialize state watcher */ - sw_subchannel = gpr_malloc(sizeof(*sw_subchannel)); - sw_subchannel->subchannel = c; - sw_subchannel->connectivity_state = GRPC_CHANNEL_READY; - grpc_closure_init(&sw_subchannel->closure, subchannel_on_child_state_changed, - sw_subchannel); - - if (c->disconnected) { - gpr_free(sw_subchannel); - grpc_channel_stack_destroy(exec_ctx, stk); - gpr_free(con); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); - return; - } - - /* publish */ - /* TODO(ctiller): this full barrier seems to clear up a TSAN failure. - I'd have expected the rel_cas below to be enough, but - seemingly it's not. - Re-evaluate if we really need this. */ - gpr_atm_full_barrier(); - GPR_ASSERT(gpr_atm_rel_cas(&c->connected_subchannel, 0, (gpr_atm)con)); - c->connecting = 0; - - /* setup subchannel watching connected subchannel for changes; subchannel - ref - for connecting is donated - to the state watcher */ - GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher"); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); - grpc_connected_subchannel_notify_on_state_change( - exec_ctx, con, c->pollset_set, &sw_subchannel->connectivity_state, - &sw_subchannel->closure); - - /* signal completion */ - grpc_connectivity_state_set(exec_ctx, &c->state_tracker, GRPC_CHANNEL_READY, - GRPC_ERROR_NONE, "connected"); -} - -static void on_alarm(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - grpc_subchannel *c = arg; - gpr_mu_lock(&c->mu); - c->have_alarm = 0; - if (c->disconnected) { - error = GRPC_ERROR_CREATE_REFERENCING("Disconnected", &error, 1); - } else { - GRPC_ERROR_REF(error); - } - if (error == GRPC_ERROR_NONE) { - gpr_log(GPR_INFO, "Failed to connect to channel, retrying"); - c->next_attempt = - gpr_backoff_step(&c->backoff_state, gpr_now(GPR_CLOCK_MONOTONIC)); - continue_connect(exec_ctx, c); - gpr_mu_unlock(&c->mu); - } else { - gpr_mu_unlock(&c->mu); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); - } - GRPC_ERROR_UNREF(error); -} - -static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - grpc_subchannel *c = arg; - grpc_channel_args *delete_channel_args = c->connecting_result.channel_args; - - GRPC_SUBCHANNEL_WEAK_REF(c, "connected"); - gpr_mu_lock(&c->mu); - if (c->connecting_result.transport != NULL) { - publish_transport_locked(exec_ctx, c); - } else if (c->disconnected) { - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); - } else { - gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); - GPR_ASSERT(!c->have_alarm); - c->have_alarm = 1; - grpc_connectivity_state_set( - exec_ctx, &c->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, - GRPC_ERROR_CREATE_REFERENCING("Connect Failed", &error, 1), - "connect_failed"); - gpr_timespec time_til_next = gpr_time_sub(c->next_attempt, now); - const char *errmsg = grpc_error_string(error); - gpr_log(GPR_INFO, "Connect failed: %s", errmsg); - if (gpr_time_cmp(time_til_next, gpr_time_0(time_til_next.clock_type)) <= - 0) { - gpr_log(GPR_INFO, "Retry immediately"); - } else { - gpr_log(GPR_INFO, "Retry in %" PRId64 ".%09d seconds", - time_til_next.tv_sec, time_til_next.tv_nsec); - } - grpc_timer_init(exec_ctx, &c->alarm, c->next_attempt, on_alarm, c, now); - grpc_error_free_string(errmsg); - } - gpr_mu_unlock(&c->mu); - GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); - grpc_channel_args_destroy(delete_channel_args); -} - -/* - * grpc_subchannel_call implementation - */ - -static void subchannel_call_destroy(grpc_exec_ctx *exec_ctx, void *call, - grpc_error *error) { - grpc_subchannel_call *c = call; - GPR_TIMER_BEGIN("grpc_subchannel_call_unref.destroy", 0); - grpc_connected_subchannel *connection = c->connection; - grpc_call_stack_destroy(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), NULL, c); - GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, connection, "subchannel_call"); - GPR_TIMER_END("grpc_subchannel_call_unref.destroy", 0); -} - -void grpc_subchannel_call_ref( - grpc_subchannel_call *c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { - GRPC_CALL_STACK_REF(SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); -} - -void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, - grpc_subchannel_call *c - GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { - GRPC_CALL_STACK_UNREF(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), REF_REASON); -} - -char *grpc_subchannel_call_get_peer(grpc_exec_ctx *exec_ctx, - grpc_subchannel_call *call) { - grpc_call_stack *call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call); - grpc_call_element *top_elem = grpc_call_stack_element(call_stack, 0); - return top_elem->filter->get_peer(exec_ctx, top_elem); -} - -void grpc_subchannel_call_process_op(grpc_exec_ctx *exec_ctx, - grpc_subchannel_call *call, - grpc_transport_stream_op *op) { - GPR_TIMER_BEGIN("grpc_subchannel_call_process_op", 0); - grpc_call_stack *call_stack = SUBCHANNEL_CALL_TO_CALL_STACK(call); - grpc_call_element *top_elem = grpc_call_stack_element(call_stack, 0); - top_elem->filter->start_transport_stream_op(exec_ctx, top_elem, op); - GPR_TIMER_END("grpc_subchannel_call_process_op", 0); -} - -grpc_connected_subchannel *grpc_subchannel_get_connected_subchannel( - grpc_subchannel *c) { - return GET_CONNECTED_SUBCHANNEL(c, acq); -} - -grpc_error *grpc_connected_subchannel_create_call( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, - grpc_polling_entity *pollent, grpc_subchannel_call **call) { - grpc_channel_stack *chanstk = CHANNEL_STACK_FROM_CONNECTION(con); - *call = gpr_malloc(sizeof(grpc_subchannel_call) + chanstk->call_stack_size); - grpc_call_stack *callstk = SUBCHANNEL_CALL_TO_CALL_STACK(*call); - (*call)->connection = con; // Ref is added below. - grpc_error *error = - grpc_call_stack_init(exec_ctx, chanstk, 1, subchannel_call_destroy, *call, - NULL, NULL, callstk); - if (error != GRPC_ERROR_NONE) { - const char *error_string = grpc_error_string(error); - gpr_log(GPR_ERROR, "error: %s", error_string); - grpc_error_free_string(error_string); - gpr_free(*call); - return error; - } - GRPC_CONNECTED_SUBCHANNEL_REF(con, "subchannel_call"); - grpc_call_stack_set_pollset_or_pollset_set(exec_ctx, callstk, pollent); - return GRPC_ERROR_NONE; -} - -grpc_call_stack *grpc_subchannel_call_get_call_stack( - grpc_subchannel_call *subchannel_call) { - return SUBCHANNEL_CALL_TO_CALL_STACK(subchannel_call); -} diff --git a/src/core/ext/client_config/subchannel.h b/src/core/ext/client_config/subchannel.h deleted file mode 100644 index ae1d96e640..0000000000 --- a/src/core/ext/client_config/subchannel.h +++ /dev/null @@ -1,175 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_H - -#include "src/core/ext/client_config/connector.h" -#include "src/core/lib/channel/channel_stack.h" -#include "src/core/lib/iomgr/polling_entity.h" -#include "src/core/lib/transport/connectivity_state.h" - -/** A (sub-)channel that knows how to connect to exactly one target - address. Provides a target for load balancing. */ -typedef struct grpc_subchannel grpc_subchannel; -typedef struct grpc_connected_subchannel grpc_connected_subchannel; -typedef struct grpc_subchannel_call grpc_subchannel_call; -typedef struct grpc_subchannel_args grpc_subchannel_args; - -#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) \ - grpc_subchannel_weak_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_SUBCHANNEL_WEAK_UNREF(cl, p, r) \ - grpc_subchannel_weak_unref((cl), (p), __FILE__, __LINE__, (r)) -#define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) \ - grpc_connected_subchannel_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ - grpc_connected_subchannel_unref((cl), (p), __FILE__, __LINE__, (r)) -#define GRPC_SUBCHANNEL_CALL_REF(p, r) \ - grpc_subchannel_call_ref((p), __FILE__, __LINE__, (r)) -#define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ - grpc_subchannel_call_unref((cl), (p), __FILE__, __LINE__, (r)) -#define GRPC_SUBCHANNEL_REF_EXTRA_ARGS \ - , 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) \ - grpc_subchannel_weak_unref((cl), (p)) -#define GRPC_CONNECTED_SUBCHANNEL_REF(p, r) grpc_connected_subchannel_ref((p)) -#define GRPC_CONNECTED_SUBCHANNEL_UNREF(cl, p, r) \ - grpc_connected_subchannel_unref((cl), (p)) -#define GRPC_SUBCHANNEL_CALL_REF(p, r) grpc_subchannel_call_ref((p)) -#define GRPC_SUBCHANNEL_CALL_UNREF(cl, p, r) \ - grpc_subchannel_call_unref((cl), (p)) -#define GRPC_SUBCHANNEL_REF_EXTRA_ARGS -#endif - -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); -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); -void grpc_connected_subchannel_ref( - grpc_connected_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_connected_subchannel_unref(grpc_exec_ctx *exec_ctx, - grpc_connected_subchannel *channel - GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_subchannel_call_ref( - grpc_subchannel_call *call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); -void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, - grpc_subchannel_call *call - GRPC_SUBCHANNEL_REF_EXTRA_ARGS); - -/** construct a subchannel call */ -grpc_error *grpc_connected_subchannel_create_call( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *connected_subchannel, - grpc_polling_entity *pollent, grpc_subchannel_call **subchannel_call); - -/** process a transport level op */ -void grpc_connected_subchannel_process_transport_op( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *subchannel, - grpc_transport_op *op); - -/** poll the current connectivity state of a channel */ -grpc_connectivity_state grpc_subchannel_check_connectivity( - grpc_subchannel *channel, grpc_error **error); - -/** call notify when the connectivity state of a channel changes from *state. - Updates *state with the new state of the channel */ -void grpc_subchannel_notify_on_state_change( - grpc_exec_ctx *exec_ctx, grpc_subchannel *channel, - grpc_pollset_set *interested_parties, grpc_connectivity_state *state, - grpc_closure *notify); -void grpc_connected_subchannel_notify_on_state_change( - grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *channel, - grpc_pollset_set *interested_parties, grpc_connectivity_state *state, - grpc_closure *notify); -void grpc_connected_subchannel_ping(grpc_exec_ctx *exec_ctx, - grpc_connected_subchannel *channel, - grpc_closure *notify); - -/** retrieve the grpc_connected_subchannel - or NULL if called before - the subchannel becomes connected */ -grpc_connected_subchannel *grpc_subchannel_get_connected_subchannel( - grpc_subchannel *subchannel); - -/** continue processing a transport op */ -void grpc_subchannel_call_process_op(grpc_exec_ctx *exec_ctx, - grpc_subchannel_call *subchannel_call, - grpc_transport_stream_op *op); - -/** continue querying for peer */ -char *grpc_subchannel_call_get_peer(grpc_exec_ctx *exec_ctx, - grpc_subchannel_call *subchannel_call); - -grpc_call_stack *grpc_subchannel_call_get_call_stack( - 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; - /** The number of filters in the above array */ - size_t filter_count; - /** Channel arguments to be supplied to the newly created channel */ - const grpc_channel_args *args; - /** Address to connect to */ - struct sockaddr *addr; - size_t addr_len; -}; - -/** create a subchannel given a connector */ -grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, - grpc_connector *connector, - grpc_subchannel_args *args); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_H */ diff --git a/src/core/ext/client_config/subchannel_factory.c b/src/core/ext/client_config/subchannel_factory.c deleted file mode 100644 index d1e4d75a02..0000000000 --- a/src/core/ext/client_config/subchannel_factory.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/subchannel_factory.h" - -void grpc_subchannel_factory_ref(grpc_subchannel_factory* factory) { - factory->vtable->ref(factory); -} - -void grpc_subchannel_factory_unref(grpc_exec_ctx* exec_ctx, - grpc_subchannel_factory* factory) { - factory->vtable->unref(exec_ctx, factory); -} - -grpc_subchannel* grpc_subchannel_factory_create_subchannel( - grpc_exec_ctx* exec_ctx, grpc_subchannel_factory* factory, - grpc_subchannel_args* args) { - return factory->vtable->create_subchannel(exec_ctx, factory, args); -} diff --git a/src/core/ext/client_config/subchannel_factory.h b/src/core/ext/client_config/subchannel_factory.h deleted file mode 100644 index 0fb806d081..0000000000 --- a/src/core/ext/client_config/subchannel_factory.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_FACTORY_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_FACTORY_H - -#include "src/core/ext/client_config/subchannel.h" -#include "src/core/lib/channel/channel_stack.h" - -typedef struct grpc_subchannel_factory grpc_subchannel_factory; -typedef struct grpc_subchannel_factory_vtable grpc_subchannel_factory_vtable; - -/** Constructor for new configured channels. - Creating decorators around this type is encouraged to adapt behavior. */ -struct grpc_subchannel_factory { - const grpc_subchannel_factory_vtable *vtable; -}; - -struct grpc_subchannel_factory_vtable { - void (*ref)(grpc_subchannel_factory *factory); - void (*unref)(grpc_exec_ctx *exec_ctx, grpc_subchannel_factory *factory); - grpc_subchannel *(*create_subchannel)(grpc_exec_ctx *exec_ctx, - grpc_subchannel_factory *factory, - grpc_subchannel_args *args); -}; - -void grpc_subchannel_factory_ref(grpc_subchannel_factory *factory); -void grpc_subchannel_factory_unref(grpc_exec_ctx *exec_ctx, - grpc_subchannel_factory *factory); - -/** Create a new grpc_subchannel */ -grpc_subchannel *grpc_subchannel_factory_create_subchannel( - grpc_exec_ctx *exec_ctx, grpc_subchannel_factory *factory, - grpc_subchannel_args *args); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_FACTORY_H */ diff --git a/src/core/ext/client_config/subchannel_index.c b/src/core/ext/client_config/subchannel_index.c deleted file mode 100644 index 690cb16b96..0000000000 --- a/src/core/ext/client_config/subchannel_index.c +++ /dev/null @@ -1,273 +0,0 @@ -// -// -// 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/ext/client_config/subchannel_index.h" - -#include -#include - -#include -#include -#include - -#include "src/core/lib/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; - if (k->args.filter_count > 0) { - 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); - } else { - k->args.filters = NULL; - } - k->args.addr_len = args->addr_len; - k->args.addr = gpr_malloc(args->addr_len); - if (k->args.addr_len > 0) { - 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; - if (a->args.addr_len) { - c = memcmp(a->args.addr, b->args.addr, a->args.addr_len); - if (c != 0) return c; - } - if (a->args.filter_count > 0) { - c = memcmp(a->args.filters, b->args.filters, - a->args.filter_count * sizeof(*a->args.filters)); - if (c != 0) return c; - } - 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); - gpr_tls_init(&subchannel_index_exec_ctx); -} - -void grpc_subchannel_index_shutdown(void) { - gpr_mu_destroy(&g_mu); - gpr_avl_unref(g_subchannel_index); - gpr_tls_destroy(&subchannel_index_exec_ctx); -} - -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/ext/client_config/subchannel_index.h b/src/core/ext/client_config/subchannel_index.h deleted file mode 100644 index 6b8d063855..0000000000 --- a/src/core/ext/client_config/subchannel_index.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * - * 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_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H - -#include "src/core/ext/client_config/connector.h" -#include "src/core/ext/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_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H */ diff --git a/src/core/ext/client_config/uri_parser.c b/src/core/ext/client_config/uri_parser.c deleted file mode 100644 index 3ca1a58e69..0000000000 --- a/src/core/ext/client_config/uri_parser.c +++ /dev/null @@ -1,310 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/uri_parser.h" - -#include - -#include -#include -#include -#include -#include -#include - -#include "src/core/lib/support/string.h" - -/** a size_t default value... maps to all 1's */ -#define NOT_SET (~(size_t)0) - -static grpc_uri *bad_uri(const char *uri_text, size_t pos, const char *section, - int suppress_errors) { - char *line_prefix; - size_t pfx_len; - - if (!suppress_errors) { - gpr_asprintf(&line_prefix, "bad uri.%s: '", section); - pfx_len = strlen(line_prefix) + pos; - gpr_log(GPR_ERROR, "%s%s'", line_prefix, uri_text); - gpr_free(line_prefix); - - line_prefix = gpr_malloc(pfx_len + 1); - memset(line_prefix, ' ', pfx_len); - line_prefix[pfx_len] = 0; - gpr_log(GPR_ERROR, "%s^ here", line_prefix); - gpr_free(line_prefix); - } - - return NULL; -} - -/** Returns a copy of \a src[begin, end) */ -static char *copy_component(const char *src, size_t begin, size_t end) { - char *out = gpr_malloc(end - begin + 1); - memcpy(out, src + begin, end - begin); - out[end - begin] = 0; - return out; -} - -/** Returns how many chars to advance if \a uri_text[i] begins a valid \a pchar - * production. If \a uri_text[i] introduces an invalid \a pchar (such as percent - * sign not followed by two hex digits), NOT_SET is returned. */ -static size_t parse_pchar(const char *uri_text, size_t i) { - /* pchar = unreserved / pct-encoded / sub-delims / ":" / "@" - * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" - * pct-encoded = "%" HEXDIG HEXDIG - * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" - / "*" / "+" / "," / ";" / "=" */ - char c = uri_text[i]; - if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) || - ((c >= '0') && (c <= '9')) || - (c == '-' || c == '.' || c == '_' || c == '~') || /* unreserved */ - (c == '!' || c == '$' || c == '&' || c == '\'' || c == '$' || c == '&' || - c == '(' || c == ')' || c == '*' || c == '+' || c == ',' || c == ';' || - c == '=') /* sub-delims */) { - return 1; - } - if (c == '%') { /* pct-encoded */ - size_t j; - if (uri_text[i + 1] == 0 || uri_text[i + 2] == 0) { - return NOT_SET; - } - for (j = i + 1; j < 2; j++) { - c = uri_text[j]; - if (!(((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) || - ((c >= 'A') && (c <= 'F')))) { - return NOT_SET; - } - } - return 2; - } - return 0; -} - -/* *( pchar / "?" / "/" ) */ -static int parse_fragment_or_query(const char *uri_text, size_t *i) { - char c; - while ((c = uri_text[*i]) != 0) { - const size_t advance = parse_pchar(uri_text, *i); /* pchar */ - switch (advance) { - case 0: /* uri_text[i] isn't in pchar */ - /* maybe it's ? or / */ - if (uri_text[*i] == '?' || uri_text[*i] == '/') { - (*i)++; - break; - } else { - return 1; - } - GPR_UNREACHABLE_CODE(return 0); - default: - (*i) += advance; - break; - case NOT_SET: /* uri_text[i] introduces an invalid URI */ - return 0; - } - } - /* *i is the first uri_text position past the \a query production, maybe \0 */ - return 1; -} - -static void do_nothing(void *ignored) {} -static void parse_query_parts(grpc_uri *uri) { - static const char *QUERY_PARTS_SEPARATOR = "&"; - static const char *QUERY_PARTS_VALUE_SEPARATOR = "="; - GPR_ASSERT(uri->query != NULL); - if (uri->query[0] == '\0') { - uri->query_parts = NULL; - uri->query_parts_values = NULL; - uri->num_query_parts = 0; - return; - } - gpr_slice query_slice = - gpr_slice_new(uri->query, strlen(uri->query), do_nothing); - gpr_slice_buffer query_parts; /* the &-separated elements of the query */ - gpr_slice_buffer query_param_parts; /* the =-separated subelements */ - - gpr_slice_buffer_init(&query_parts); - gpr_slice_buffer_init(&query_param_parts); - - gpr_slice_split(query_slice, QUERY_PARTS_SEPARATOR, &query_parts); - uri->query_parts = gpr_malloc(query_parts.count * sizeof(char *)); - uri->query_parts_values = gpr_malloc(query_parts.count * sizeof(char *)); - uri->num_query_parts = query_parts.count; - for (size_t i = 0; i < query_parts.count; i++) { - gpr_slice_split(query_parts.slices[i], QUERY_PARTS_VALUE_SEPARATOR, - &query_param_parts); - GPR_ASSERT(query_param_parts.count > 0); - uri->query_parts[i] = - gpr_dump_slice(query_param_parts.slices[0], GPR_DUMP_ASCII); - if (query_param_parts.count > 1) { - /* TODO(dgq): only the first value after the separator is considered. - * Perhaps all chars after the first separator for the query part should - * be included, even if they include the separator. */ - uri->query_parts_values[i] = - gpr_dump_slice(query_param_parts.slices[1], GPR_DUMP_ASCII); - } else { - uri->query_parts_values[i] = NULL; - } - gpr_slice_buffer_reset_and_unref(&query_param_parts); - } - gpr_slice_buffer_destroy(&query_parts); - gpr_slice_buffer_destroy(&query_param_parts); - gpr_slice_unref(query_slice); -} - -grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) { - grpc_uri *uri; - size_t scheme_begin = 0; - size_t scheme_end = NOT_SET; - size_t authority_begin = NOT_SET; - size_t authority_end = NOT_SET; - size_t path_begin = NOT_SET; - size_t path_end = NOT_SET; - size_t query_begin = NOT_SET; - size_t query_end = NOT_SET; - size_t fragment_begin = NOT_SET; - size_t fragment_end = NOT_SET; - size_t i; - - for (i = scheme_begin; uri_text[i] != 0; i++) { - if (uri_text[i] == ':') { - scheme_end = i; - break; - } - if (uri_text[i] >= 'a' && uri_text[i] <= 'z') continue; - if (uri_text[i] >= 'A' && uri_text[i] <= 'Z') continue; - if (i != scheme_begin) { - if (uri_text[i] >= '0' && uri_text[i] <= '9') continue; - if (uri_text[i] == '+') continue; - if (uri_text[i] == '-') continue; - if (uri_text[i] == '.') continue; - } - break; - } - if (scheme_end == NOT_SET) { - return bad_uri(uri_text, i, "scheme", suppress_errors); - } - - if (uri_text[scheme_end + 1] == '/' && uri_text[scheme_end + 2] == '/') { - authority_begin = scheme_end + 3; - for (i = authority_begin; uri_text[i] != 0 && authority_end == NOT_SET; - i++) { - if (uri_text[i] == '/' || uri_text[i] == '?' || uri_text[i] == '#') { - authority_end = i; - } - } - if (authority_end == NOT_SET && uri_text[i] == 0) { - authority_end = i; - } - if (authority_end == NOT_SET) { - return bad_uri(uri_text, i, "authority", suppress_errors); - } - /* TODO(ctiller): parse the authority correctly */ - path_begin = authority_end; - } else { - path_begin = scheme_end + 1; - } - - for (i = path_begin; uri_text[i] != 0; i++) { - if (uri_text[i] == '?' || uri_text[i] == '#') { - path_end = i; - break; - } - } - if (path_end == NOT_SET && uri_text[i] == 0) { - path_end = i; - } - if (path_end == NOT_SET) { - return bad_uri(uri_text, i, "path", suppress_errors); - } - - if (uri_text[i] == '?') { - query_begin = ++i; - if (!parse_fragment_or_query(uri_text, &i)) { - return bad_uri(uri_text, i, "query", suppress_errors); - } else if (uri_text[i] != 0 && uri_text[i] != '#') { - /* We must be at the end or at the beginning of a fragment */ - return bad_uri(uri_text, i, "query", suppress_errors); - } - query_end = i; - } - if (uri_text[i] == '#') { - fragment_begin = ++i; - if (!parse_fragment_or_query(uri_text, &i)) { - return bad_uri(uri_text, i - fragment_end, "fragment", suppress_errors); - } else if (uri_text[i] != 0) { - /* We must be at the end */ - return bad_uri(uri_text, i, "fragment", suppress_errors); - } - fragment_end = i; - } - - uri = gpr_malloc(sizeof(*uri)); - memset(uri, 0, sizeof(*uri)); - uri->scheme = copy_component(uri_text, scheme_begin, scheme_end); - uri->authority = copy_component(uri_text, authority_begin, authority_end); - uri->path = copy_component(uri_text, path_begin, path_end); - uri->query = copy_component(uri_text, query_begin, query_end); - uri->fragment = copy_component(uri_text, fragment_begin, fragment_end); - parse_query_parts(uri); - - return uri; -} - -const char *grpc_uri_get_query_arg(const grpc_uri *uri, const char *key) { - GPR_ASSERT(key != NULL); - if (key[0] == '\0') return NULL; - - for (size_t i = 0; i < uri->num_query_parts; ++i) { - if (0 == strcmp(key, uri->query_parts[i])) { - return uri->query_parts_values[i]; - } - } - return NULL; -} - -void grpc_uri_destroy(grpc_uri *uri) { - if (!uri) return; - gpr_free(uri->scheme); - gpr_free(uri->authority); - gpr_free(uri->path); - gpr_free(uri->query); - for (size_t i = 0; i < uri->num_query_parts; ++i) { - gpr_free(uri->query_parts[i]); - gpr_free(uri->query_parts_values[i]); - } - gpr_free(uri->query_parts); - gpr_free(uri->query_parts_values); - gpr_free(uri->fragment); - gpr_free(uri); -} diff --git a/src/core/ext/client_config/uri_parser.h b/src/core/ext/client_config/uri_parser.h deleted file mode 100644 index 875a7cb07c..0000000000 --- a/src/core/ext/client_config/uri_parser.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_URI_PARSER_H -#define GRPC_CORE_EXT_CLIENT_CONFIG_URI_PARSER_H - -#include - -typedef struct { - char *scheme; - char *authority; - char *path; - char *query; - /** Query substrings separated by '&' */ - char **query_parts; - /** Number of elements in \a query_parts and \a query_parts_values */ - size_t num_query_parts; - /** Split each query part by '='. NULL if not present. */ - char **query_parts_values; - char *fragment; -} grpc_uri; - -/** parse a uri, return NULL on failure */ -grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors); - -/** return the part of a query string after the '=' in "?key=xxx&...", or NULL - * if key is not present */ -const char *grpc_uri_get_query_arg(const grpc_uri *uri, const char *key); - -/** destroy a uri */ -void grpc_uri_destroy(grpc_uri *uri); - -#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_URI_PARSER_H */ diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index af913d8a9d..5006e7e3f0 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -104,9 +104,9 @@ #include #include -#include "src/core/ext/client_config/client_channel_factory.h" -#include "src/core/ext/client_config/lb_policy_registry.h" -#include "src/core/ext/client_config/parse_address.h" +#include "src/core/ext/client_channel/client_channel_factory.h" +#include "src/core/ext/client_channel/lb_policy_registry.h" +#include "src/core/ext/client_channel/parse_address.h" #include "src/core/ext/lb_policy/grpclb/grpclb.h" #include "src/core/ext/lb_policy/grpclb/load_balancer_api.h" #include "src/core/lib/iomgr/sockaddr_utils.h" diff --git a/src/core/ext/lb_policy/grpclb/grpclb.h b/src/core/ext/lb_policy/grpclb/grpclb.h index 83552b4fa0..ff23f3a545 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.h +++ b/src/core/ext/lb_policy/grpclb/grpclb.h @@ -34,7 +34,7 @@ #ifndef GRPC_CORE_EXT_LB_POLICY_GRPCLB_GRPCLB_H #define GRPC_CORE_EXT_LB_POLICY_GRPCLB_GRPCLB_H -#include "src/core/ext/client_config/lb_policy_factory.h" +#include "src/core/ext/client_channel/lb_policy_factory.h" /** Returns a load balancing factory for the glb policy, which tries to connect * to a load balancing server to decide the next successfully connected diff --git a/src/core/ext/lb_policy/grpclb/load_balancer_api.h b/src/core/ext/lb_policy/grpclb/load_balancer_api.h index 9726c87a37..a63a4c40aa 100644 --- a/src/core/ext/lb_policy/grpclb/load_balancer_api.h +++ b/src/core/ext/lb_policy/grpclb/load_balancer_api.h @@ -36,7 +36,7 @@ #include -#include "src/core/ext/client_config/lb_policy_factory.h" +#include "src/core/ext/client_channel/lb_policy_factory.h" #include "src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h" #ifdef __cplusplus diff --git a/src/core/ext/lb_policy/pick_first/pick_first.c b/src/core/ext/lb_policy/pick_first/pick_first.c index 9decf70692..276189689e 100644 --- a/src/core/ext/lb_policy/pick_first/pick_first.c +++ b/src/core/ext/lb_policy/pick_first/pick_first.c @@ -34,7 +34,7 @@ #include #include -#include "src/core/ext/client_config/lb_policy_registry.h" +#include "src/core/ext/client_channel/lb_policy_registry.h" #include "src/core/lib/transport/connectivity_state.h" typedef struct pending_pick { diff --git a/src/core/ext/lb_policy/round_robin/round_robin.c b/src/core/ext/lb_policy/round_robin/round_robin.c index 7bcf608ab9..b2ee834b52 100644 --- a/src/core/ext/lb_policy/round_robin/round_robin.c +++ b/src/core/ext/lb_policy/round_robin/round_robin.c @@ -63,7 +63,7 @@ #include -#include "src/core/ext/client_config/lb_policy_registry.h" +#include "src/core/ext/client_channel/lb_policy_registry.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/transport/connectivity_state.h" diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 79682e78b5..d70b498ae8 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -37,8 +37,8 @@ #include #include -#include "src/core/ext/client_config/lb_policy_registry.h" -#include "src/core/ext/client_config/resolver_registry.h" +#include "src/core/ext/client_channel/lb_policy_registry.h" +#include "src/core/ext/client_channel/resolver_registry.h" #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/support/backoff.h" diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index 3807522d2b..f18e10a754 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -40,9 +40,9 @@ #include #include -#include "src/core/ext/client_config/lb_policy_registry.h" -#include "src/core/ext/client_config/parse_address.h" -#include "src/core/ext/client_config/resolver_registry.h" +#include "src/core/ext/client_channel/lb_policy_registry.h" +#include "src/core/ext/client_channel/parse_address.h" +#include "src/core/ext/client_channel/resolver_registry.h" #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/unix_sockets_posix.h" #include "src/core/lib/support/string.h" diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.c b/src/core/ext/transport/chttp2/client/insecure/channel_create.c index cbaa75a90a..f848335f67 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.c +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.c @@ -40,8 +40,8 @@ #include #include -#include "src/core/ext/client_config/client_channel.h" -#include "src/core/ext/client_config/resolver_registry.h" +#include "src/core/ext/client_channel/client_channel.h" +#include "src/core/ext/client_channel/resolver_registry.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/compress_filter.h" diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c index 9e2bdd758f..b3f7cf4efb 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c @@ -40,8 +40,8 @@ #include #include -#include "src/core/ext/client_config/client_channel.h" -#include "src/core/ext/client_config/resolver_registry.h" +#include "src/core/ext/client_channel/client_channel.h" +#include "src/core/ext/client_channel/resolver_registry.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/handshaker.h" diff --git a/src/core/plugin_registry/grpc_cronet_plugin_registry.c b/src/core/plugin_registry/grpc_cronet_plugin_registry.c index d0b5f5c702..d339ed327f 100644 --- a/src/core/plugin_registry/grpc_cronet_plugin_registry.c +++ b/src/core/plugin_registry/grpc_cronet_plugin_registry.c @@ -35,12 +35,12 @@ extern void grpc_chttp2_plugin_init(void); extern void grpc_chttp2_plugin_shutdown(void); -extern void grpc_client_config_init(void); -extern void grpc_client_config_shutdown(void); +extern void grpc_client_channel_init(void); +extern void grpc_client_channel_shutdown(void); void grpc_register_built_in_plugins(void) { grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown); - grpc_register_plugin(grpc_client_config_init, - grpc_client_config_shutdown); + grpc_register_plugin(grpc_client_channel_init, + grpc_client_channel_shutdown); } diff --git a/src/core/plugin_registry/grpc_plugin_registry.c b/src/core/plugin_registry/grpc_plugin_registry.c index 7a7a9ce477..2efd9cd1ad 100644 --- a/src/core/plugin_registry/grpc_plugin_registry.c +++ b/src/core/plugin_registry/grpc_plugin_registry.c @@ -35,8 +35,8 @@ extern void grpc_chttp2_plugin_init(void); extern void grpc_chttp2_plugin_shutdown(void); -extern void grpc_client_config_init(void); -extern void grpc_client_config_shutdown(void); +extern void grpc_client_channel_init(void); +extern void grpc_client_channel_shutdown(void); extern void grpc_lb_policy_grpclb_init(void); extern void grpc_lb_policy_grpclb_shutdown(void); extern void grpc_lb_policy_pick_first_init(void); @@ -55,8 +55,8 @@ extern void census_grpc_plugin_shutdown(void); void grpc_register_built_in_plugins(void) { grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown); - grpc_register_plugin(grpc_client_config_init, - grpc_client_config_shutdown); + grpc_register_plugin(grpc_client_channel_init, + grpc_client_channel_shutdown); grpc_register_plugin(grpc_lb_policy_grpclb_init, grpc_lb_policy_grpclb_shutdown); grpc_register_plugin(grpc_lb_policy_pick_first_init, diff --git a/src/core/plugin_registry/grpc_unsecure_plugin_registry.c b/src/core/plugin_registry/grpc_unsecure_plugin_registry.c index ad4ddf0ff4..8b18af699d 100644 --- a/src/core/plugin_registry/grpc_unsecure_plugin_registry.c +++ b/src/core/plugin_registry/grpc_unsecure_plugin_registry.c @@ -35,8 +35,8 @@ extern void grpc_chttp2_plugin_init(void); extern void grpc_chttp2_plugin_shutdown(void); -extern void grpc_client_config_init(void); -extern void grpc_client_config_shutdown(void); +extern void grpc_client_channel_init(void); +extern void grpc_client_channel_shutdown(void); extern void grpc_resolver_dns_native_init(void); extern void grpc_resolver_dns_native_shutdown(void); extern void grpc_resolver_sockaddr_init(void); @@ -55,8 +55,8 @@ extern void census_grpc_plugin_shutdown(void); void grpc_register_built_in_plugins(void) { grpc_register_plugin(grpc_chttp2_plugin_init, grpc_chttp2_plugin_shutdown); - grpc_register_plugin(grpc_client_config_init, - grpc_client_config_shutdown); + grpc_register_plugin(grpc_client_channel_init, + grpc_client_channel_shutdown); grpc_register_plugin(grpc_resolver_dns_native_init, grpc_resolver_dns_native_shutdown); grpc_register_plugin(grpc_resolver_sockaddr_init, diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index be7f30c29b..ec85cf11c5 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -218,24 +218,24 @@ CORE_SOURCE_FILES = [ 'src/core/lib/tsi/ssl_transport_security.c', 'src/core/lib/tsi/transport_security.c', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.c', - 'src/core/ext/client_config/channel_connectivity.c', - 'src/core/ext/client_config/client_channel.c', - 'src/core/ext/client_config/client_channel_factory.c', - 'src/core/ext/client_config/client_config_plugin.c', - 'src/core/ext/client_config/connector.c', - 'src/core/ext/client_config/default_initial_connect_string.c', - 'src/core/ext/client_config/initial_connect_string.c', - 'src/core/ext/client_config/lb_policy.c', - 'src/core/ext/client_config/lb_policy_factory.c', - 'src/core/ext/client_config/lb_policy_registry.c', - 'src/core/ext/client_config/parse_address.c', - 'src/core/ext/client_config/resolver.c', - 'src/core/ext/client_config/resolver_factory.c', - 'src/core/ext/client_config/resolver_registry.c', - 'src/core/ext/client_config/resolver_result.c', - 'src/core/ext/client_config/subchannel.c', - 'src/core/ext/client_config/subchannel_index.c', - 'src/core/ext/client_config/uri_parser.c', + 'src/core/ext/client_channel/channel_connectivity.c', + 'src/core/ext/client_channel/client_channel.c', + 'src/core/ext/client_channel/client_channel_factory.c', + 'src/core/ext/client_channel/client_channel_plugin.c', + 'src/core/ext/client_channel/connector.c', + 'src/core/ext/client_channel/default_initial_connect_string.c', + 'src/core/ext/client_channel/initial_connect_string.c', + 'src/core/ext/client_channel/lb_policy.c', + 'src/core/ext/client_channel/lb_policy_factory.c', + 'src/core/ext/client_channel/lb_policy_registry.c', + 'src/core/ext/client_channel/parse_address.c', + 'src/core/ext/client_channel/resolver.c', + 'src/core/ext/client_channel/resolver_factory.c', + 'src/core/ext/client_channel/resolver_registry.c', + 'src/core/ext/client_channel/resolver_result.c', + 'src/core/ext/client_channel/subchannel.c', + 'src/core/ext/client_channel/subchannel_index.c', + 'src/core/ext/client_channel/uri_parser.c', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.c', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c', 'src/core/ext/transport/chttp2/client/insecure/channel_create.c', diff --git a/test/core/client_channel/lb_policies_test.c b/test/core/client_channel/lb_policies_test.c new file mode 100644 index 0000000000..76254d3955 --- /dev/null +++ b/test/core/client_channel/lb_policies_test.c @@ -0,0 +1,938 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "src/core/ext/client_channel/client_channel.h" +#include "src/core/ext/client_channel/lb_policy_registry.h" +#include "src/core/lib/channel/channel_stack.h" +#include "src/core/lib/support/string.h" +#include "src/core/lib/surface/channel.h" +#include "src/core/lib/surface/server.h" +#include "test/core/end2end/cq_verifier.h" +#include "test/core/util/port.h" +#include "test/core/util/test_config.h" + +#define RETRY_TIMEOUT 300 + +typedef struct servers_fixture { + size_t num_servers; + grpc_server **servers; + grpc_call **server_calls; + grpc_completion_queue *cq; + char **servers_hostports; + grpc_metadata_array *request_metadata_recv; +} servers_fixture; + +typedef void (*verifier_fn)(const servers_fixture *, grpc_channel *, + const int *, const size_t); + +typedef struct test_spec { + size_t num_iters; + size_t num_servers; + + int **kill_at; + int **revive_at; + + const char *description; + + verifier_fn verifier; + +} test_spec; + +static void test_spec_reset(test_spec *spec) { + size_t i, j; + + for (i = 0; i < spec->num_iters; i++) { + for (j = 0; j < spec->num_servers; j++) { + spec->kill_at[i][j] = 0; + spec->revive_at[i][j] = 0; + } + } +} + +static test_spec *test_spec_create(size_t num_iters, size_t num_servers) { + test_spec *spec; + size_t i; + + spec = gpr_malloc(sizeof(test_spec)); + spec->num_iters = num_iters; + spec->num_servers = num_servers; + spec->kill_at = gpr_malloc(sizeof(int *) * num_iters); + spec->revive_at = gpr_malloc(sizeof(int *) * num_iters); + for (i = 0; i < num_iters; i++) { + spec->kill_at[i] = gpr_malloc(sizeof(int) * num_servers); + spec->revive_at[i] = gpr_malloc(sizeof(int) * num_servers); + } + + test_spec_reset(spec); + return spec; +} + +static void test_spec_destroy(test_spec *spec) { + size_t i; + for (i = 0; i < spec->num_iters; i++) { + gpr_free(spec->kill_at[i]); + gpr_free(spec->revive_at[i]); + } + + gpr_free(spec->kill_at); + gpr_free(spec->revive_at); + + gpr_free(spec); +} + +static void *tag(intptr_t t) { return (void *)t; } + +static gpr_timespec n_millis_time(int n) { + return gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_millis(n, GPR_TIMESPAN)); +} + +static void drain_cq(grpc_completion_queue *cq) { + grpc_event ev; + do { + ev = grpc_completion_queue_next(cq, n_millis_time(5000), NULL); + } while (ev.type != GRPC_QUEUE_SHUTDOWN); +} + +static void kill_server(const servers_fixture *f, size_t i) { + gpr_log(GPR_INFO, "KILLING SERVER %" PRIuPTR, i); + GPR_ASSERT(f->servers[i] != NULL); + grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); + GPR_ASSERT( + grpc_completion_queue_pluck(f->cq, tag(10000), n_millis_time(5000), NULL) + .type == GRPC_OP_COMPLETE); + grpc_server_destroy(f->servers[i]); + f->servers[i] = NULL; +} + +typedef struct request_data { + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + char *details; + size_t details_capacity; + grpc_status_code status; + grpc_call_details *call_details; +} request_data; + +static void revive_server(const servers_fixture *f, request_data *rdata, + size_t i) { + int got_port; + gpr_log(GPR_INFO, "RAISE AGAIN SERVER %" PRIuPTR, i); + GPR_ASSERT(f->servers[i] == NULL); + + gpr_log(GPR_DEBUG, "revive: %s", f->servers_hostports[i]); + + f->servers[i] = grpc_server_create(NULL, NULL); + grpc_server_register_completion_queue(f->servers[i], f->cq, NULL); + GPR_ASSERT((got_port = grpc_server_add_insecure_http2_port( + f->servers[i], f->servers_hostports[i])) > 0); + grpc_server_start(f->servers[i]); + + GPR_ASSERT(GRPC_CALL_OK == + grpc_server_request_call(f->servers[i], &f->server_calls[i], + &rdata->call_details[i], + &f->request_metadata_recv[i], f->cq, + f->cq, tag(1000 + (int)i))); +} + +static servers_fixture *setup_servers(const char *server_host, + request_data *rdata, + const size_t num_servers) { + servers_fixture *f = gpr_malloc(sizeof(servers_fixture)); + size_t i; + + f->num_servers = num_servers; + f->server_calls = gpr_malloc(sizeof(grpc_call *) * num_servers); + f->request_metadata_recv = + gpr_malloc(sizeof(grpc_metadata_array) * num_servers); + /* Create servers. */ + f->servers = gpr_malloc(sizeof(grpc_server *) * num_servers); + f->servers_hostports = gpr_malloc(sizeof(char *) * num_servers); + f->cq = grpc_completion_queue_create(NULL); + for (i = 0; i < num_servers; i++) { + grpc_metadata_array_init(&f->request_metadata_recv[i]); + gpr_join_host_port(&f->servers_hostports[i], server_host, + grpc_pick_unused_port_or_die()); + f->servers[i] = 0; + revive_server(f, rdata, i); + } + return f; +} + +static void teardown_servers(servers_fixture *f) { + size_t i; + /* Destroy server. */ + for (i = 0; i < f->num_servers; i++) { + if (f->servers[i] == NULL) continue; + grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); + GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(10000), + n_millis_time(5000), NULL) + .type == GRPC_OP_COMPLETE); + grpc_server_destroy(f->servers[i]); + } + grpc_completion_queue_shutdown(f->cq); + drain_cq(f->cq); + grpc_completion_queue_destroy(f->cq); + + gpr_free(f->servers); + + for (i = 0; i < f->num_servers; i++) { + gpr_free(f->servers_hostports[i]); + grpc_metadata_array_destroy(&f->request_metadata_recv[i]); + } + + gpr_free(f->servers_hostports); + gpr_free(f->request_metadata_recv); + gpr_free(f->server_calls); + gpr_free(f); +} + +/** Returns connection sequence (server indices), which must be freed */ +static int *perform_request(servers_fixture *f, grpc_channel *client, + request_data *rdata, const test_spec *spec) { + grpc_call *c; + int s_idx; + int *s_valid; + grpc_op ops[6]; + grpc_op *op; + int was_cancelled; + size_t i, iter_num; + grpc_event ev; + int read_tag; + int *connection_sequence; + int completed_client; + + s_valid = gpr_malloc(sizeof(int) * f->num_servers); + connection_sequence = gpr_malloc(sizeof(int) * spec->num_iters); + + for (iter_num = 0; iter_num < spec->num_iters; iter_num++) { + cq_verifier *cqv = cq_verifier_create(f->cq); + rdata->details = NULL; + rdata->details_capacity = 0; + was_cancelled = 2; + + for (i = 0; i < f->num_servers; i++) { + if (spec->kill_at[iter_num][i] != 0) { + kill_server(f, i); + } else if (spec->revive_at[iter_num][i] != 0) { + /* killing takes precedence */ + revive_server(f, rdata, i); + } + } + + connection_sequence[iter_num] = -1; + grpc_metadata_array_init(&rdata->initial_metadata_recv); + grpc_metadata_array_init(&rdata->trailing_metadata_recv); + + for (i = 0; i < f->num_servers; i++) { + grpc_call_details_init(&rdata->call_details[i]); + } + memset(s_valid, 0, f->num_servers * sizeof(int)); + + c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, + "/foo", "foo.test.google.fr", + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + GPR_ASSERT(c); + completed_client = 0; + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata = &rdata->initial_metadata_recv; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = + &rdata->trailing_metadata_recv; + op->data.recv_status_on_client.status = &rdata->status; + op->data.recv_status_on_client.status_details = &rdata->details; + op->data.recv_status_on_client.status_details_capacity = + &rdata->details_capacity; + op->flags = 0; + op->reserved = NULL; + op++; + GPR_ASSERT(GRPC_CALL_OK == + grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL)); + + s_idx = -1; + while ( + (ev = grpc_completion_queue_next( + f->cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10 * RETRY_TIMEOUT), NULL)) + .type != GRPC_QUEUE_TIMEOUT) { + GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); + read_tag = ((int)(intptr_t)ev.tag); + gpr_log(GPR_DEBUG, "EVENT: success:%d, type:%d, tag:%d iter:%" PRIuPTR, + ev.success, ev.type, read_tag, iter_num); + if (ev.success && read_tag >= 1000) { + GPR_ASSERT(s_idx == -1); /* only one server must reply */ + /* only server notifications for non-shutdown events */ + s_idx = read_tag - 1000; + s_valid[s_idx] = 1; + connection_sequence[iter_num] = s_idx; + break; + } else if (read_tag == 1) { + gpr_log(GPR_DEBUG, "client timed out"); + GPR_ASSERT(ev.success); + completed_client = 1; + } + } + + if (s_idx >= 0) { + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; + op->data.send_status_from_server.trailing_metadata_count = 0; + op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; + op->data.send_status_from_server.status_details = "xyz"; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; + op->data.recv_close_on_server.cancelled = &was_cancelled; + op->flags = 0; + op->reserved = NULL; + op++; + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(f->server_calls[s_idx], + ops, (size_t)(op - ops), + tag(102), NULL)); + + CQ_EXPECT_COMPLETION(cqv, tag(102), 1); + if (!completed_client) { + CQ_EXPECT_COMPLETION(cqv, tag(1), 1); + } + cq_verify(cqv); + + gpr_log(GPR_DEBUG, "status=%d; %s", rdata->status, rdata->details); + GPR_ASSERT(rdata->status == GRPC_STATUS_UNIMPLEMENTED); + GPR_ASSERT(0 == strcmp(rdata->details, "xyz")); + GPR_ASSERT(0 == strcmp(rdata->call_details[s_idx].method, "/foo")); + GPR_ASSERT(0 == + strcmp(rdata->call_details[s_idx].host, "foo.test.google.fr")); + GPR_ASSERT(was_cancelled == 1); + + grpc_call_destroy(f->server_calls[s_idx]); + + /* ask for the next request on this server */ + GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( + f->servers[s_idx], &f->server_calls[s_idx], + &rdata->call_details[s_idx], + &f->request_metadata_recv[s_idx], f->cq, + f->cq, tag(1000 + (int)s_idx))); + } else { /* no response from server */ + grpc_call_cancel(c, NULL); + if (!completed_client) { + CQ_EXPECT_COMPLETION(cqv, tag(1), 1); + cq_verify(cqv); + } + } + + GPR_ASSERT( + grpc_completion_queue_next( + f->cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(2 * RETRY_TIMEOUT), NULL) + .type == GRPC_QUEUE_TIMEOUT); + + grpc_metadata_array_destroy(&rdata->initial_metadata_recv); + grpc_metadata_array_destroy(&rdata->trailing_metadata_recv); + + cq_verifier_destroy(cqv); + + grpc_call_destroy(c); + + for (i = 0; i < f->num_servers; i++) { + grpc_call_details_destroy(&rdata->call_details[i]); + } + gpr_free(rdata->details); + } + + gpr_free(s_valid); + + return connection_sequence; +} + +static grpc_call **perform_multirequest(servers_fixture *f, + grpc_channel *client, + size_t concurrent_calls) { + grpc_call **calls; + grpc_op ops[6]; + grpc_op *op; + size_t i; + + calls = gpr_malloc(sizeof(grpc_call *) * concurrent_calls); + for (i = 0; i < f->num_servers; i++) { + kill_server(f, i); + } + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = NULL; + + for (i = 0; i < concurrent_calls; i++) { + calls[i] = grpc_channel_create_call( + client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, "/foo", + "foo.test.google.fr", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + GPR_ASSERT(calls[i]); + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[i], ops, + (size_t)(op - ops), tag(1), + NULL)); + } + + return calls; +} + +static void assert_channel_connectivity(grpc_channel *ch, + size_t num_accepted_conn_states, + int accepted_conn_state, ...) { + size_t i; + grpc_channel_stack *client_stack; + grpc_channel_element *client_channel_filter; + grpc_connectivity_state actual_conn_state; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + va_list ap; + + client_stack = grpc_channel_get_channel_stack(ch); + client_channel_filter = grpc_channel_stack_last_element(client_stack); + + actual_conn_state = grpc_client_channel_check_connectivity_state( + &exec_ctx, client_channel_filter, 0 /* don't try to connect */); + grpc_exec_ctx_finish(&exec_ctx); + va_start(ap, accepted_conn_state); + for (i = 0; i < num_accepted_conn_states; i++) { + if ((int)actual_conn_state == accepted_conn_state) { + break; + } + accepted_conn_state = va_arg(ap, grpc_connectivity_state); + } + va_end(ap); + if (i == num_accepted_conn_states) { + char **accepted_strs = + gpr_malloc(sizeof(char *) * num_accepted_conn_states); + char *accepted_str_joined; + va_start(ap, accepted_conn_state); + for (i = 0; i < num_accepted_conn_states; i++) { + GPR_ASSERT(gpr_asprintf(&accepted_strs[i], "%d", accepted_conn_state) > + 0); + accepted_conn_state = va_arg(ap, grpc_connectivity_state); + } + va_end(ap); + accepted_str_joined = gpr_strjoin_sep((const char **)accepted_strs, + num_accepted_conn_states, ", ", NULL); + gpr_log( + GPR_ERROR, + "Channel connectivity assertion failed: expected , got %d", + accepted_str_joined, actual_conn_state); + + for (i = 0; i < num_accepted_conn_states; i++) { + gpr_free(accepted_strs[i]); + } + gpr_free(accepted_strs); + gpr_free(accepted_str_joined); + abort(); + } +} + +void run_spec(const test_spec *spec) { + grpc_channel *client; + char *client_hostport; + char *servers_hostports_str; + int *actual_connection_sequence; + request_data rdata; + servers_fixture *f; + grpc_channel_args args; + grpc_arg arg; + rdata.call_details = + gpr_malloc(sizeof(grpc_call_details) * spec->num_servers); + f = setup_servers("127.0.0.1", &rdata, spec->num_servers); + + /* Create client. */ + servers_hostports_str = gpr_strjoin_sep((const char **)f->servers_hostports, + f->num_servers, ",", NULL); + gpr_asprintf(&client_hostport, "ipv4:%s?lb_policy=round_robin", + servers_hostports_str); + + arg.type = GRPC_ARG_INTEGER; + arg.key = "grpc.testing.fixed_reconnect_backoff"; + arg.value.integer = RETRY_TIMEOUT; + args.num_args = 1; + args.args = &arg; + + client = grpc_insecure_channel_create(client_hostport, &args, NULL); + + gpr_log(GPR_INFO, "Testing '%s' with servers=%s client=%s", spec->description, + servers_hostports_str, client_hostport); + + actual_connection_sequence = perform_request(f, client, &rdata, spec); + + spec->verifier(f, client, actual_connection_sequence, spec->num_iters); + + gpr_free(client_hostport); + gpr_free(servers_hostports_str); + gpr_free(actual_connection_sequence); + gpr_free(rdata.call_details); + + grpc_channel_destroy(client); /* calls the LB's shutdown func */ + teardown_servers(f); +} + +static grpc_channel *create_client(const servers_fixture *f) { + grpc_channel *client; + char *client_hostport; + char *servers_hostports_str; + grpc_arg arg; + grpc_channel_args args; + + servers_hostports_str = gpr_strjoin_sep((const char **)f->servers_hostports, + f->num_servers, ",", NULL); + gpr_asprintf(&client_hostport, "ipv4:%s?lb_policy=round_robin", + servers_hostports_str); + + arg.type = GRPC_ARG_INTEGER; + arg.key = "grpc.testing.fixed_reconnect_backoff"; + arg.value.integer = RETRY_TIMEOUT; + args.num_args = 1; + args.args = &arg; + + client = grpc_insecure_channel_create(client_hostport, &args, NULL); + gpr_free(client_hostport); + gpr_free(servers_hostports_str); + + return client; +} + +static void test_ping() { + grpc_channel *client; + request_data rdata; + servers_fixture *f; + cq_verifier *cqv; + grpc_connectivity_state state = GRPC_CHANNEL_IDLE; + const size_t num_servers = 1; + int i; + + rdata.call_details = gpr_malloc(sizeof(grpc_call_details) * num_servers); + f = setup_servers("127.0.0.1", &rdata, num_servers); + cqv = cq_verifier_create(f->cq); + + client = create_client(f); + + grpc_channel_ping(client, f->cq, tag(0), NULL); + CQ_EXPECT_COMPLETION(cqv, tag(0), 0); + + /* check that we're still in idle, and start connecting */ + GPR_ASSERT(grpc_channel_check_connectivity_state(client, 1) == + GRPC_CHANNEL_IDLE); + /* we'll go through some set of transitions (some might be missed), until + READY is reached */ + while (state != GRPC_CHANNEL_READY) { + grpc_channel_watch_connectivity_state( + client, state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f->cq, tag(99)); + CQ_EXPECT_COMPLETION(cqv, tag(99), 1); + cq_verify(cqv); + state = grpc_channel_check_connectivity_state(client, 0); + GPR_ASSERT(state == GRPC_CHANNEL_READY || + state == GRPC_CHANNEL_CONNECTING || + state == GRPC_CHANNEL_TRANSIENT_FAILURE); + } + + for (i = 1; i <= 5; i++) { + grpc_channel_ping(client, f->cq, tag(i), NULL); + CQ_EXPECT_COMPLETION(cqv, tag(i), 1); + cq_verify(cqv); + } + gpr_free(rdata.call_details); + + grpc_channel_destroy(client); + teardown_servers(f); + + cq_verifier_destroy(cqv); +} + +static void test_pending_calls(size_t concurrent_calls) { + size_t i; + grpc_call **calls; + grpc_channel *client; + request_data rdata; + servers_fixture *f; + test_spec *spec = test_spec_create(0, 4); + rdata.call_details = + gpr_malloc(sizeof(grpc_call_details) * spec->num_servers); + f = setup_servers("127.0.0.1", &rdata, spec->num_servers); + + client = create_client(f); + calls = perform_multirequest(f, client, concurrent_calls); + grpc_call_cancel( + calls[0], + NULL); /* exercise the cancel pick path whilst there are pending picks */ + + gpr_free(rdata.call_details); + + grpc_channel_destroy(client); /* calls the LB's shutdown func */ + /* destroy the calls after the channel so that they are still around for the + * LB's shutdown func to process */ + for (i = 0; i < concurrent_calls; i++) { + grpc_call_destroy(calls[i]); + } + gpr_free(calls); + teardown_servers(f); + test_spec_destroy(spec); +} + +static void print_failed_expectations(const int *expected_connection_sequence, + const int *actual_connection_sequence, + const size_t expected_seq_length, + const size_t num_iters) { + size_t i; + for (i = 0; i < num_iters; i++) { + gpr_log(GPR_ERROR, + "FAILURE: Iter (expected, actual): %" PRIuPTR " (%d, %d)", i, + expected_connection_sequence[i % expected_seq_length], + actual_connection_sequence[i]); + } +} + +static void verify_vanilla_round_robin(const servers_fixture *f, + grpc_channel *client, + const int *actual_connection_sequence, + const size_t num_iters) { + int *expected_connection_sequence; + size_t i; + const size_t expected_seq_length = f->num_servers; + + /* verify conn. seq. expectation */ + /* get the first sequence of "num_servers" elements */ + expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); + memcpy(expected_connection_sequence, actual_connection_sequence, + sizeof(int) * expected_seq_length); + + for (i = 0; i < num_iters; i++) { + const int actual = actual_connection_sequence[i]; + const int expected = expected_connection_sequence[i % expected_seq_length]; + if (actual != expected) { + print_failed_expectations(expected_connection_sequence, + actual_connection_sequence, expected_seq_length, + num_iters); + abort(); + } + } + assert_channel_connectivity(client, 1, GRPC_CHANNEL_READY); + + gpr_free(expected_connection_sequence); +} + +/* At the start of the second iteration, all but the first and last servers (as + * given in "f") are killed */ +static void verify_vanishing_floor_round_robin( + const servers_fixture *f, grpc_channel *client, + const int *actual_connection_sequence, const size_t num_iters) { + int *expected_connection_sequence; + const size_t expected_seq_length = 2; + size_t i; + + /* verify conn. seq. expectation */ + /* copy the first full sequence (without -1s) */ + expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); + memcpy(expected_connection_sequence, actual_connection_sequence + 2, + expected_seq_length * sizeof(int)); + + /* first two elements of the sequence should be [0 (1st server), -1 (failure)] + */ + GPR_ASSERT(actual_connection_sequence[0] == 0); + GPR_ASSERT(actual_connection_sequence[1] == -1); + + /* the next two element must be [3, 0], repeating from that point: the 3 is + * brought forth by servers 1 and 2 disappearing after the intial pick of 0 */ + GPR_ASSERT(actual_connection_sequence[2] == 3); + GPR_ASSERT(actual_connection_sequence[3] == 0); + + /* make sure that the expectation obliges */ + for (i = 2; i < num_iters; i++) { + const int actual = actual_connection_sequence[i]; + const int expected = expected_connection_sequence[i % expected_seq_length]; + if (actual != expected) { + print_failed_expectations(expected_connection_sequence, + actual_connection_sequence, expected_seq_length, + num_iters); + abort(); + } + } + gpr_free(expected_connection_sequence); +} + +static void verify_total_carnage_round_robin( + const servers_fixture *f, grpc_channel *client, + const int *actual_connection_sequence, const size_t num_iters) { + size_t i; + + for (i = 0; i < num_iters; i++) { + const int actual = actual_connection_sequence[i]; + const int expected = -1; + if (actual != expected) { + gpr_log(GPR_ERROR, "FAILURE: expected %d, actual %d at iter %" PRIuPTR, + expected, actual, i); + abort(); + } + } + + /* even though we know all the servers are dead, the client is still trying + * retrying, believing it's in a transient failure situation */ + assert_channel_connectivity(client, 2, GRPC_CHANNEL_TRANSIENT_FAILURE, + GRPC_CHANNEL_CONNECTING); +} + +static void verify_partial_carnage_round_robin( + const servers_fixture *f, grpc_channel *client, + const int *actual_connection_sequence, const size_t num_iters) { + int *expected_connection_sequence; + size_t i; + const size_t expected_seq_length = f->num_servers; + + /* verify conn. seq. expectation */ + /* get the first sequence of "num_servers" elements */ + expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); + memcpy(expected_connection_sequence, actual_connection_sequence, + sizeof(int) * expected_seq_length); + + for (i = 0; i < num_iters / 2; i++) { + const int actual = actual_connection_sequence[i]; + const int expected = expected_connection_sequence[i % expected_seq_length]; + if (actual != expected) { + print_failed_expectations(expected_connection_sequence, + actual_connection_sequence, expected_seq_length, + num_iters); + abort(); + } + } + + /* second half of the iterations go without response */ + for (; i < num_iters; i++) { + GPR_ASSERT(actual_connection_sequence[i] == -1); + } + + /* even though we know all the servers are dead, the client is still trying + * retrying, believing it's in a transient failure situation */ + assert_channel_connectivity(client, 2, GRPC_CHANNEL_TRANSIENT_FAILURE, + GRPC_CHANNEL_CONNECTING); + gpr_free(expected_connection_sequence); +} + +static void dump_array(const char *desc, const int *data, const size_t count) { + gpr_strvec s; + char *tmp; + size_t i; + gpr_strvec_init(&s); + gpr_strvec_add(&s, gpr_strdup(desc)); + gpr_strvec_add(&s, gpr_strdup(":")); + for (i = 0; i < count; i++) { + gpr_asprintf(&tmp, " %d", data[i]); + gpr_strvec_add(&s, tmp); + } + tmp = gpr_strvec_flatten(&s, NULL); + gpr_strvec_destroy(&s); + gpr_log(GPR_DEBUG, "%s", tmp); + gpr_free(tmp); +} + +static void verify_rebirth_round_robin(const servers_fixture *f, + grpc_channel *client, + const int *actual_connection_sequence, + const size_t num_iters) { + int *expected_connection_sequence; + size_t i, j, unique_seq_last_idx, unique_seq_first_idx; + const size_t expected_seq_length = f->num_servers; + int *seen_elements; + + dump_array("actual_connection_sequence", actual_connection_sequence, + num_iters); + + /* verify conn. seq. expectation */ + /* get the first unique run of length "num_servers". */ + expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); + seen_elements = gpr_malloc(sizeof(int) * expected_seq_length); + + unique_seq_last_idx = ~(size_t)0; + + memset(seen_elements, 0, sizeof(int) * expected_seq_length); + for (i = 0; i < num_iters; i++) { + if (actual_connection_sequence[i] < 0 || + seen_elements[actual_connection_sequence[i]] != 0) { + /* if anything breaks the uniqueness of the run, back to square zero */ + memset(seen_elements, 0, sizeof(int) * expected_seq_length); + continue; + } + seen_elements[actual_connection_sequence[i]] = 1; + for (j = 0; j < expected_seq_length; j++) { + if (seen_elements[j] == 0) break; + } + if (j == expected_seq_length) { /* seen all the elements */ + unique_seq_last_idx = i; + break; + } + } + /* make sure we found a valid run */ + dump_array("seen_elements", seen_elements, expected_seq_length); + for (j = 0; j < expected_seq_length; j++) { + GPR_ASSERT(seen_elements[j] != 0); + } + + GPR_ASSERT(unique_seq_last_idx != ~(size_t)0); + + unique_seq_first_idx = (unique_seq_last_idx - expected_seq_length + 1); + memcpy(expected_connection_sequence, + actual_connection_sequence + unique_seq_first_idx, + sizeof(int) * expected_seq_length); + + /* first iteration succeeds */ + GPR_ASSERT(actual_connection_sequence[0] != -1); + /* then we fail for a while... */ + GPR_ASSERT(actual_connection_sequence[1] == -1); + /* ... but should be up at "unique_seq_first_idx" */ + GPR_ASSERT(actual_connection_sequence[unique_seq_first_idx] != -1); + + for (j = 0, i = unique_seq_first_idx; i < num_iters; i++) { + const int actual = actual_connection_sequence[i]; + const int expected = + expected_connection_sequence[j++ % expected_seq_length]; + if (actual != expected) { + print_failed_expectations(expected_connection_sequence, + actual_connection_sequence, expected_seq_length, + num_iters); + abort(); + } + } + + /* things are fine once the servers are brought back up */ + assert_channel_connectivity(client, 1, GRPC_CHANNEL_READY); + gpr_free(expected_connection_sequence); + gpr_free(seen_elements); +} + +int main(int argc, char **argv) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + test_spec *spec; + size_t i; + const size_t NUM_ITERS = 10; + const size_t NUM_SERVERS = 4; + + grpc_test_init(argc, argv); + grpc_init(); + grpc_tracer_set_enabled("round_robin", 1); + + GPR_ASSERT(grpc_lb_policy_create(&exec_ctx, "this-lb-policy-does-not-exist", + NULL) == NULL); + GPR_ASSERT(grpc_lb_policy_create(&exec_ctx, NULL, NULL) == NULL); + + spec = test_spec_create(NUM_ITERS, NUM_SERVERS); + /* everything is fine, all servers stay up the whole time and life's peachy + */ + spec->verifier = verify_vanilla_round_robin; + spec->description = "test_all_server_up"; + run_spec(spec); + + /* Kill all servers first thing in the morning */ + test_spec_reset(spec); + spec->verifier = verify_total_carnage_round_robin; + spec->description = "test_kill_all_server"; + for (i = 0; i < NUM_SERVERS; i++) { + spec->kill_at[0][i] = 1; + } + run_spec(spec); + + /* at the start of the 2nd iteration, kill all but the first and last + * servers. + * This should knock down the server bound to be selected next */ + test_spec_reset(spec); + spec->verifier = verify_vanishing_floor_round_robin; + spec->description = "test_kill_all_server_at_2nd_iteration"; + for (i = 1; i < NUM_SERVERS - 1; i++) { + spec->kill_at[1][i] = 1; + } + run_spec(spec); + + /* Midway, kill all servers. */ + test_spec_reset(spec); + spec->verifier = verify_partial_carnage_round_robin; + spec->description = "test_kill_all_server_midway"; + for (i = 0; i < NUM_SERVERS; i++) { + spec->kill_at[spec->num_iters / 2][i] = 1; + } + run_spec(spec); + + /* After first iteration, kill all servers. On the third one, bring them all + * back up. */ + test_spec_reset(spec); + spec->verifier = verify_rebirth_round_robin; + spec->description = "test_kill_all_server_after_1st_resurrect_at_3rd"; + for (i = 0; i < NUM_SERVERS; i++) { + spec->kill_at[1][i] = 1; + spec->revive_at[3][i] = 1; + } + run_spec(spec); + test_spec_destroy(spec); + + test_pending_calls(4); + test_ping(); + + grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); + return 0; +} diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c new file mode 100644 index 0000000000..c24a03b0a4 --- /dev/null +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c @@ -0,0 +1,155 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include +#include + +#include "src/core/ext/client_channel/resolver_registry.h" +#include "src/core/lib/iomgr/resolve_address.h" +#include "src/core/lib/iomgr/timer.h" +#include "test/core/util/test_config.h" + +static void client_channel_factory_ref(grpc_client_channel_factory *scv) {} +static void client_channel_factory_unref(grpc_exec_ctx *exec_ctx, + grpc_client_channel_factory *scv) {} +static grpc_subchannel *client_channel_factory_create_subchannel( + grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, + grpc_subchannel_args *args) { + return NULL; +} + +static grpc_channel *client_channel_factory_create_channel( + grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, + const char *target, grpc_client_channel_type type, + grpc_channel_args *args) { + GPR_UNREACHABLE_CODE(return NULL); +} + +static const grpc_client_channel_factory_vtable sc_vtable = { + client_channel_factory_ref, client_channel_factory_unref, + client_channel_factory_create_subchannel, + client_channel_factory_create_channel}; + +static grpc_client_channel_factory cc_factory = {&sc_vtable}; + +static gpr_mu g_mu; +static bool g_fail_resolution = true; + +static grpc_error *my_resolve_address(const char *name, const char *addr, + grpc_resolved_addresses **addrs) { + gpr_mu_lock(&g_mu); + GPR_ASSERT(0 == strcmp("test", name)); + if (g_fail_resolution) { + g_fail_resolution = false; + gpr_mu_unlock(&g_mu); + return GRPC_ERROR_CREATE("Forced Failure"); + } else { + gpr_mu_unlock(&g_mu); + *addrs = gpr_malloc(sizeof(**addrs)); + (*addrs)->naddrs = 1; + (*addrs)->addrs = gpr_malloc(sizeof(*(*addrs)->addrs)); + (*addrs)->addrs[0].len = 123; + return GRPC_ERROR_NONE; + } +} + +static grpc_resolver *create_resolver(const char *name) { + grpc_resolver_factory *factory = grpc_resolver_factory_lookup("dns"); + grpc_uri *uri = grpc_uri_parse(name, 0); + GPR_ASSERT(uri); + grpc_resolver_args args; + memset(&args, 0, sizeof(args)); + args.uri = uri; + args.client_channel_factory = &cc_factory; + grpc_resolver *resolver = + grpc_resolver_factory_create_resolver(factory, &args); + grpc_resolver_factory_unref(factory); + grpc_uri_destroy(uri); + return resolver; +} + +static void on_done(grpc_exec_ctx *exec_ctx, void *ev, grpc_error *error) { + gpr_event_set(ev, (void *)1); +} + +// interleave waiting for an event with a timer check +static bool wait_loop(int deadline_seconds, gpr_event *ev) { + while (deadline_seconds) { + gpr_log(GPR_DEBUG, "Test: waiting for %d more seconds", deadline_seconds); + if (gpr_event_wait(ev, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1))) return true; + deadline_seconds--; + + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_timer_check(&exec_ctx, gpr_now(GPR_CLOCK_MONOTONIC), NULL); + grpc_exec_ctx_finish(&exec_ctx); + } + return false; +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + grpc_init(); + gpr_mu_init(&g_mu); + grpc_blocking_resolve_address = my_resolve_address; + + grpc_resolver *resolver = create_resolver("dns:test"); + + grpc_resolver_result *result = (grpc_resolver_result *)1; + + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + gpr_event ev1; + gpr_event_init(&ev1); + grpc_resolver_next(&exec_ctx, resolver, &result, + grpc_closure_create(on_done, &ev1)); + grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(wait_loop(5, &ev1)); + GPR_ASSERT(result == NULL); + + gpr_event ev2; + gpr_event_init(&ev2); + grpc_resolver_next(&exec_ctx, resolver, &result, + grpc_closure_create(on_done, &ev2)); + grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(wait_loop(30, &ev2)); + GPR_ASSERT(result != NULL); + + grpc_resolver_result_unref(&exec_ctx, result); + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test"); + grpc_exec_ctx_finish(&exec_ctx); + + grpc_shutdown(); + gpr_mu_destroy(&g_mu); +} diff --git a/test/core/client_channel/resolvers/dns_resolver_test.c b/test/core/client_channel/resolvers/dns_resolver_test.c new file mode 100644 index 0000000000..ae3b3df950 --- /dev/null +++ b/test/core/client_channel/resolvers/dns_resolver_test.c @@ -0,0 +1,114 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include + +#include "src/core/ext/client_channel/resolver_registry.h" +#include "test/core/util/test_config.h" + +static void client_channel_factory_ref(grpc_client_channel_factory *scv) {} +static void client_channel_factory_unref(grpc_exec_ctx *exec_ctx, + grpc_client_channel_factory *scv) {} +static grpc_subchannel *client_channel_factory_create_subchannel( + grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, + grpc_subchannel_args *args) { + GPR_UNREACHABLE_CODE(return NULL); +} + +static grpc_channel *client_channel_factory_create_channel( + grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, + const char *target, grpc_client_channel_type type, + grpc_channel_args *args) { + GPR_UNREACHABLE_CODE(return NULL); +} + +static const grpc_client_channel_factory_vtable sc_vtable = { + client_channel_factory_ref, client_channel_factory_unref, + client_channel_factory_create_subchannel, + client_channel_factory_create_channel}; + +static grpc_client_channel_factory cc_factory = {&sc_vtable}; + +static void test_succeeds(grpc_resolver_factory *factory, const char *string) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri *uri = grpc_uri_parse(string, 0); + grpc_resolver_args args; + grpc_resolver *resolver; + gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, + factory->vtable->scheme); + GPR_ASSERT(uri); + memset(&args, 0, sizeof(args)); + args.uri = uri; + args.client_channel_factory = &cc_factory; + resolver = grpc_resolver_factory_create_resolver(factory, &args); + GPR_ASSERT(resolver != NULL); + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); + grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); +} + +static void test_fails(grpc_resolver_factory *factory, const char *string) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri *uri = grpc_uri_parse(string, 0); + grpc_resolver_args args; + grpc_resolver *resolver; + gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, + factory->vtable->scheme); + GPR_ASSERT(uri); + memset(&args, 0, sizeof(args)); + args.uri = uri; + resolver = grpc_resolver_factory_create_resolver(factory, &args); + GPR_ASSERT(resolver == NULL); + grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); +} + +int main(int argc, char **argv) { + grpc_resolver_factory *dns; + grpc_test_init(argc, argv); + grpc_init(); + + dns = grpc_resolver_factory_lookup("dns"); + + test_succeeds(dns, "dns:10.2.1.1"); + test_succeeds(dns, "dns:10.2.1.1:1234"); + test_succeeds(dns, "ipv4:www.google.com"); + test_fails(dns, "ipv4://8.8.8.8/8.8.8.8:8888"); + + grpc_resolver_factory_unref(dns); + grpc_shutdown(); + + return 0; +} diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.c b/test/core/client_channel/resolvers/sockaddr_resolver_test.c new file mode 100644 index 0000000000..781d730855 --- /dev/null +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.c @@ -0,0 +1,125 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include + +#include "src/core/ext/client_channel/resolver_registry.h" +#include "test/core/util/test_config.h" + +static void client_channel_factory_ref(grpc_client_channel_factory *scv) {} +static void client_channel_factory_unref(grpc_exec_ctx *exec_ctx, + grpc_client_channel_factory *scv) {} +static grpc_subchannel *client_channel_factory_create_subchannel( + grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, + grpc_subchannel_args *args) { + GPR_UNREACHABLE_CODE(return NULL); +} + +static grpc_channel *client_channel_factory_create_channel( + grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, + const char *target, grpc_client_channel_type type, + grpc_channel_args *args) { + GPR_UNREACHABLE_CODE(return NULL); +} + +static const grpc_client_channel_factory_vtable sc_vtable = { + client_channel_factory_ref, client_channel_factory_unref, + client_channel_factory_create_subchannel, + client_channel_factory_create_channel}; + +static grpc_client_channel_factory cc_factory = {&sc_vtable}; + +static void test_succeeds(grpc_resolver_factory *factory, const char *string) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri *uri = grpc_uri_parse(string, 0); + grpc_resolver_args args; + grpc_resolver *resolver; + gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, + factory->vtable->scheme); + GPR_ASSERT(uri); + memset(&args, 0, sizeof(args)); + args.uri = uri; + args.client_channel_factory = &cc_factory; + resolver = grpc_resolver_factory_create_resolver(factory, &args); + GPR_ASSERT(resolver != NULL); + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); + grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); +} + +static void test_fails(grpc_resolver_factory *factory, const char *string) { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri *uri = grpc_uri_parse(string, 0); + grpc_resolver_args args; + grpc_resolver *resolver; + gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, + factory->vtable->scheme); + GPR_ASSERT(uri); + memset(&args, 0, sizeof(args)); + args.uri = uri; + resolver = grpc_resolver_factory_create_resolver(factory, &args); + GPR_ASSERT(resolver == NULL); + grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); +} + +int main(int argc, char **argv) { + grpc_resolver_factory *ipv4, *ipv6; + grpc_test_init(argc, argv); + grpc_init(); + + ipv4 = grpc_resolver_factory_lookup("ipv4"); + ipv6 = grpc_resolver_factory_lookup("ipv6"); + + test_fails(ipv4, "ipv4:10.2.1.1"); + test_succeeds(ipv4, "ipv4:10.2.1.1:1234"); + test_succeeds(ipv4, "ipv4:10.2.1.1:1234,127.0.0.1:4321"); + test_fails(ipv4, "ipv4:10.2.1.1:123456"); + test_fails(ipv4, "ipv4:www.google.com"); + test_fails(ipv4, "ipv4:["); + test_fails(ipv4, "ipv4://8.8.8.8/8.8.8.8:8888"); + + test_fails(ipv6, "ipv6:["); + test_fails(ipv6, "ipv6:[::]"); + test_succeeds(ipv6, "ipv6:[::]:1234"); + test_fails(ipv6, "ipv6:[::]:123456"); + test_fails(ipv6, "ipv6:www.google.com"); + + grpc_resolver_factory_unref(ipv4); + grpc_resolver_factory_unref(ipv6); + grpc_shutdown(); + + return 0; +} diff --git a/test/core/client_channel/set_initial_connect_string_test.c b/test/core/client_channel/set_initial_connect_string_test.c new file mode 100644 index 0000000000..b7bd67567c --- /dev/null +++ b/test/core/client_channel/set_initial_connect_string_test.c @@ -0,0 +1,257 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include + +#include +#include +#include +#include +#include +#include + +#include "src/core/ext/client_channel/initial_connect_string.h" +#include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/security/credentials/fake/fake_credentials.h" +#include "src/core/lib/support/string.h" +#include "test/core/util/port.h" +#include "test/core/util/test_config.h" +#include "test/core/util/test_tcp_server.h" + +struct rpc_state { + char *target; + grpc_channel_credentials *creds; + grpc_completion_queue *cq; + grpc_channel *channel; + grpc_call *call; + grpc_op op; + gpr_slice_buffer incoming_buffer; + gpr_slice_buffer temp_incoming_buffer; + grpc_endpoint *tcp; + gpr_atm done_atm; +}; + +static const char *magic_connect_string = "magic initial string"; +static int server_port; +static struct rpc_state state; +static grpc_closure on_read; + +static void handle_read(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { + GPR_ASSERT(error == GRPC_ERROR_NONE); + gpr_slice_buffer_move_into(&state.temp_incoming_buffer, + &state.incoming_buffer); + gpr_log(GPR_DEBUG, "got %" PRIuPTR " bytes, magic is %" PRIuPTR " bytes", + state.incoming_buffer.length, strlen(magic_connect_string)); + if (state.incoming_buffer.length > strlen(magic_connect_string)) { + gpr_atm_rel_store(&state.done_atm, 1); + grpc_endpoint_shutdown(exec_ctx, state.tcp); + grpc_endpoint_destroy(exec_ctx, state.tcp); + } else { + grpc_endpoint_read(exec_ctx, state.tcp, &state.temp_incoming_buffer, + &on_read); + } +} + +static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp, + grpc_pollset *accepting_pollset, + grpc_tcp_server_acceptor *acceptor) { + test_tcp_server *server = arg; + grpc_closure_init(&on_read, handle_read, NULL); + gpr_slice_buffer_init(&state.incoming_buffer); + gpr_slice_buffer_init(&state.temp_incoming_buffer); + state.tcp = tcp; + grpc_endpoint_add_to_pollset(exec_ctx, tcp, server->pollset); + grpc_endpoint_read(exec_ctx, tcp, &state.temp_incoming_buffer, &on_read); +} + +static void set_magic_initial_string(struct sockaddr **addr, size_t *addr_len, + gpr_slice *connect_string) { + GPR_ASSERT(addr); + GPR_ASSERT(addr_len); + *connect_string = gpr_slice_from_copied_string(magic_connect_string); +} + +static void reset_addr_and_set_magic_string(struct sockaddr **addr, + size_t *addr_len, + gpr_slice *connect_string) { + struct sockaddr_in target; + *connect_string = gpr_slice_from_copied_string(magic_connect_string); + gpr_free(*addr); + target.sin_family = AF_INET; + target.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + target.sin_port = htons((uint16_t)server_port); + *addr_len = sizeof(target); + *addr = (struct sockaddr *)gpr_malloc(sizeof(target)); + memcpy(*addr, &target, sizeof(target)); +} + +static gpr_timespec n_sec_deadline(int seconds) { + return gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(seconds, GPR_TIMESPAN)); +} + +static void start_rpc(int use_creds, int target_port) { + state.cq = grpc_completion_queue_create(NULL); + if (use_creds) { + state.creds = grpc_fake_transport_security_credentials_create(); + } else { + state.creds = NULL; + } + gpr_join_host_port(&state.target, "127.0.0.1", target_port); + if (use_creds) { + state.channel = + grpc_secure_channel_create(state.creds, state.target, NULL, NULL); + } else { + state.channel = grpc_insecure_channel_create(state.target, NULL, NULL); + } + state.call = grpc_channel_create_call( + state.channel, NULL, GRPC_PROPAGATE_DEFAULTS, state.cq, "/Service/Method", + "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + memset(&state.op, 0, sizeof(state.op)); + state.op.op = GRPC_OP_SEND_INITIAL_METADATA; + state.op.data.send_initial_metadata.count = 0; + state.op.flags = 0; + state.op.reserved = NULL; + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(state.call, &state.op, + (size_t)(1), NULL, NULL)); + grpc_completion_queue_next(state.cq, n_sec_deadline(5), NULL); +} + +static void cleanup_rpc(void) { + grpc_event ev; + gpr_slice_buffer_destroy(&state.incoming_buffer); + gpr_slice_buffer_destroy(&state.temp_incoming_buffer); + grpc_channel_credentials_unref(state.creds); + grpc_call_destroy(state.call); + grpc_completion_queue_shutdown(state.cq); + do { + ev = grpc_completion_queue_next(state.cq, n_sec_deadline(1), NULL); + } while (ev.type != GRPC_QUEUE_SHUTDOWN); + grpc_completion_queue_destroy(state.cq); + grpc_channel_destroy(state.channel); + gpr_free(state.target); +} + +typedef struct { + test_tcp_server *server; + gpr_event *signal_when_done; +} poll_args; + +static void actually_poll_server(void *arg) { + poll_args *pa = arg; + gpr_timespec deadline = n_sec_deadline(10); + while (true) { + bool done = gpr_atm_acq_load(&state.done_atm) != 0; + gpr_timespec time_left = + gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME)); + gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRId64 ".%09" PRId32, done, + time_left.tv_sec, time_left.tv_nsec); + if (done || gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) < 0) { + break; + } + test_tcp_server_poll(pa->server, 1); + } + gpr_event_set(pa->signal_when_done, (void *)1); + gpr_free(pa); +} + +static void poll_server_until_read_done(test_tcp_server *server, + gpr_event *signal_when_done) { + gpr_atm_rel_store(&state.done_atm, 0); + gpr_thd_id id; + poll_args *pa = gpr_malloc(sizeof(*pa)); + pa->server = server; + pa->signal_when_done = signal_when_done; + gpr_thd_new(&id, actually_poll_server, pa, NULL); +} + +static void match_initial_magic_string(gpr_slice_buffer *buffer) { + size_t i, j, cmp_length; + size_t magic_length = strlen(magic_connect_string); + GPR_ASSERT(buffer->length >= magic_length); + for (i = 0, j = 0; i < state.incoming_buffer.count && j < magic_length; i++) { + char *dump = + gpr_dump_slice(state.incoming_buffer.slices[i], GPR_DUMP_ASCII); + cmp_length = GPR_MIN(strlen(dump), magic_length - j); + GPR_ASSERT(strncmp(dump, magic_connect_string + j, cmp_length) == 0); + j += cmp_length; + gpr_free(dump); + } +} + +static void test_initial_string(test_tcp_server *server, int secure) { + gpr_event ev; + gpr_event_init(&ev); + grpc_test_set_initial_connect_string_function(set_magic_initial_string); + poll_server_until_read_done(server, &ev); + start_rpc(secure, server_port); + gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME)); + match_initial_magic_string(&state.incoming_buffer); + cleanup_rpc(); +} + +static void test_initial_string_with_redirect(test_tcp_server *server, + int secure) { + gpr_event ev; + gpr_event_init(&ev); + int another_port = grpc_pick_unused_port_or_die(); + grpc_test_set_initial_connect_string_function( + reset_addr_and_set_magic_string); + poll_server_until_read_done(server, &ev); + start_rpc(secure, another_port); + gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME)); + match_initial_magic_string(&state.incoming_buffer); + cleanup_rpc(); +} + +static void run_test(void (*test)(test_tcp_server *server, int secure), + int secure) { + test_tcp_server test_server; + server_port = grpc_pick_unused_port_or_die(); + test_tcp_server_init(&test_server, on_connect, &test_server); + test_tcp_server_start(&test_server, server_port); + test(&test_server, secure); + test_tcp_server_destroy(&test_server); +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + grpc_init(); + + run_test(test_initial_string, 0); + run_test(test_initial_string, 1); + run_test(test_initial_string_with_redirect, 0); + run_test(test_initial_string_with_redirect, 1); + + grpc_shutdown(); + return 0; +} diff --git a/test/core/client_channel/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342 b/test/core/client_channel/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342 new file mode 100644 index 0000000000..a85e7a8c21 --- /dev/null +++ b/test/core/client_channel/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342 @@ -0,0 +1,2 @@ +::nix::ii///ii/\a‡?=n;iI_!';&b.cii??nn!%i!*% +*; \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342 b/test/core/client_channel/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342 new file mode 100644 index 0000000000..597a6db294 --- /dev/null +++ b/test/core/client_channel/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342 @@ -0,0 +1 @@ +i \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11 b/test/core/client_channel/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11 new file mode 100644 index 0000000000..d56b8fc6c8 --- /dev/null +++ b/test/core/client_channel/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11 @@ -0,0 +1 @@ +:iiiÐ?+n!ij \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f b/test/core/client_channel/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f new file mode 100644 index 0000000000..5b913f1bb8 --- /dev/null +++ b/test/core/client_channel/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f @@ -0,0 +1,2 @@ +:ipip~6:‡i:::1 +v:miP/ii:::/iu?n?n)i!= \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118 b/test/core/client_channel/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118 new file mode 100644 index 0000000000..76f157cda5 --- /dev/null +++ b/test/core/client_channel/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118 @@ -0,0 +1 @@ +i:i:‡ii:i?nip~??ni=niI&6.u/n_!'p~ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc b/test/core/client_channel/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc new file mode 100644 index 0000000000..3936e8964c --- /dev/null +++ b/test/core/client_channel/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc @@ -0,0 +1 @@ +:‡i?=niI_!';ñ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f b/test/core/client_channel/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f new file mode 100644 index 0000000000..a94c4cf58d --- /dev/null +++ b/test/core/client_channel/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f @@ -0,0 +1,2 @@ +~ipip~6::1 +v:Ð:1 diff --git a/test/core/client_channel/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 b/test/core/client_channel/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 new file mode 100644 index 0000000000..875ac2a4f9 --- /dev/null +++ b/test/core/client_channel/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 @@ -0,0 +1 @@ +:il0P/8?n!$i: \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971 b/test/core/client_channel/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971 new file mode 100644 index 0000000000..59469af528 --- /dev/null +++ b/test/core/client_channel/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971 @@ -0,0 +1,3 @@ +iiP*v:::pip~6:::0 +v:::11 + diff --git a/test/core/client_channel/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc b/test/core/client_channel/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc new file mode 100644 index 0000000000..2f902351bd --- /dev/null +++ b/test/core/client_channel/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc @@ -0,0 +1 @@ +:ii/i?n!%i* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1 b/test/core/client_channel/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1 new file mode 100644 index 0000000000..4bdc3f60c0 --- /dev/null +++ b/test/core/client_channel/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1 @@ -0,0 +1 @@ +uni::.i?n(!ipR6/ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf b/test/core/client_channel/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf new file mode 100644 index 0000000000..fb7665d0cc --- /dev/null +++ b/test/core/client_channel/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf @@ -0,0 +1,2 @@ +:/i?n!ipv6:./::abc.* + diff --git a/test/core/client_channel/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce b/test/core/client_channel/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce new file mode 100644 index 0000000000..6c1e22fa32 --- /dev/null +++ b/test/core/client_channel/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce @@ -0,0 +1 @@ +unix://ii:#v6i?n! \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327 b/test/core/client_channel/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327 new file mode 100644 index 0000000000..694d51dc9a --- /dev/null +++ b/test/core/client_channel/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327 @@ -0,0 +1 @@ +uni:/i:i:‡i:i:‡i??ni=niIi??ni=niI__!!i?n!i'p'pR2p~~ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c b/test/core/client_channel/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c new file mode 100644 index 0000000000..af80f07d19 --- /dev/null +++ b/test/core/client_channel/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c @@ -0,0 +1 @@ +i:i:‡i??ni=niI_!'p~ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc b/test/core/client_channel/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc new file mode 100644 index 0000000000..725b2086c5 --- /dev/null +++ b/test/core/client_channel/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc @@ -0,0 +1,4 @@ +i:i?nip~&2./:::abipip~6c.* + +::1 +v:Ð:1 diff --git a/test/core/client_channel/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c b/test/core/client_channel/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c new file mode 100644 index 0000000000..7f0f2ea6ea --- /dev/null +++ b/test/core/client_channel/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c @@ -0,0 +1 @@ +:‡i?=niI_!';; \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1 b/test/core/client_channel/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1 new file mode 100644 index 0000000000..23d52e19a8 --- /dev/null +++ b/test/core/client_channel/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1 @@ -0,0 +1 @@ +:iiP/i?n!'i* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab b/test/core/client_channel/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab new file mode 100644 index 0000000000..f975f97059 --- /dev/null +++ b/test/core/client_channel/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab @@ -0,0 +1 @@ +i:i?nip~&6.u/n \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822 b/test/core/client_channel/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822 new file mode 100644 index 0000000000..d5fb7ba274 --- /dev/null +++ b/test/core/client_channel/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822 @@ -0,0 +1,2 @@ +:unix://ii//a.b.ci?n!% +* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb b/test/core/client_channel/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb new file mode 100644 index 0000000000..1860e1c5b4 --- /dev/null +++ b/test/core/client_channel/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb @@ -0,0 +1 @@ +:‡i?P=niIii-i?%n'!%*i= \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8 b/test/core/client_channel/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8 new file mode 100644 index 0000000000..1dc4931ac6 --- /dev/null +++ b/test/core/client_channel/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8 @@ -0,0 +1,4 @@ +:i?n!ip~f2:./::abipip~6c.* + +::1 +v:Ð:1 diff --git a/test/core/client_channel/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a b/test/core/client_channel/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a new file mode 100644 index 0000000000..7b9532914e --- /dev/null +++ b/test/core/client_channel/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a @@ -0,0 +1 @@ +:‡i?=niI!';ñ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb b/test/core/client_channel/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb new file mode 100644 index 0000000000..4eaca39265 --- /dev/null +++ b/test/core/client_channel/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb @@ -0,0 +1 @@ +unix://ii:pv6i?n! \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58 b/test/core/client_channel/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58 new file mode 100644 index 0000000000..fe908d213a --- /dev/null +++ b/test/core/client_channel/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58 @@ -0,0 +1 @@ +uni::.ilP:%:%i:i‡i:‡i?=nii?n(!ipRI_&/.i;;!?=ii/?n#lniiI_!*Kii!/?ni* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6 b/test/core/client_channel/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6 new file mode 100644 index 0000000000..57cbd72dbc --- /dev/null +++ b/test/core/client_channel/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6 @@ -0,0 +1 @@ +uni::/i?n!ipR6/ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1 b/test/core/client_channel/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1 new file mode 100644 index 0000000000..e13cf5a8e6 --- /dev/null +++ b/test/core/client_channel/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1 @@ -0,0 +1,2 @@ +ipip~6:::1 +v:::1 diff --git a/test/core/client_channel/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb b/test/core/client_channel/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb new file mode 100644 index 0000000000..0e7f44caf2 --- /dev/null +++ b/test/core/client_channel/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb @@ -0,0 +1 @@ +i:i:‡i:i:‡i??ni=niIi??ni=niI__!!'p'p~~ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d b/test/core/client_channel/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d new file mode 100644 index 0000000000..679f13e307 --- /dev/null +++ b/test/core/client_channel/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d @@ -0,0 +1,2 @@ +unix:///a/:.:ii/i?nc!% +i* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266 b/test/core/client_channel/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266 new file mode 100644 index 0000000000..58ecc7e2af --- /dev/null +++ b/test/core/client_channel/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266 @@ -0,0 +1 @@ +ip*v:::1 diff --git a/test/core/client_channel/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb b/test/core/client_channel/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb new file mode 100644 index 0000000000..ffd807b39e --- /dev/null +++ b/test/core/client_channel/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb @@ -0,0 +1 @@ +ilP:%i:‡i?=niI_.i;;!ii/?nni*! \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4 b/test/core/client_channel/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4 new file mode 100644 index 0000000000..8ad79f9eb9 --- /dev/null +++ b/test/core/client_channel/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4 @@ -0,0 +1 @@ +:‡i?P-niI%'i= \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb b/test/core/client_channel/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb new file mode 100644 index 0000000000..efb392b7d9 --- /dev/null +++ b/test/core/client_channel/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb @@ -0,0 +1,2 @@ +:/i/n!ipv6:::/a.b.c1 + diff --git a/test/core/client_channel/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8 b/test/core/client_channel/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8 new file mode 100644 index 0000000000..7155222547 --- /dev/null +++ b/test/core/client_channel/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8 @@ -0,0 +1 @@ +ilP.i;?n!#i!; \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b b/test/core/client_channel/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b new file mode 100644 index 0000000000..4061e02189 --- /dev/null +++ b/test/core/client_channel/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b @@ -0,0 +1 @@ +unix::/i?n!ipv6/ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 b/test/core/client_channel/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 new file mode 100644 index 0000000000..facb11c5ed --- /dev/null +++ b/test/core/client_channel/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 @@ -0,0 +1 @@ +:%i:‡i?=niI_!ii/?ni*! \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de b/test/core/client_channel/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de new file mode 100644 index 0000000000..736e63e7e7 --- /dev/null +++ b/test/core/client_channel/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de @@ -0,0 +1 @@ +:¢ilP/i;n!#i: \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d b/test/core/client_channel/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d new file mode 100644 index 0000000000..dff2f8920d --- /dev/null +++ b/test/core/client_channel/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d @@ -0,0 +1 @@ +u+ni::/i?n!ipR3/ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38 b/test/core/client_channel/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38 new file mode 100644 index 0000000000..13a115481d --- /dev/null +++ b/test/core/client_channel/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38 @@ -0,0 +1 @@ +uni::pi:miP/?ni.!(Ri?)8/n!'i* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/aba1472880406a318ce207ee79815b7acf087757 b/test/core/client_channel/uri_corpus/aba1472880406a318ce207ee79815b7acf087757 new file mode 100644 index 0000000000..b7e7e970f8 --- /dev/null +++ b/test/core/client_channel/uri_corpus/aba1472880406a318ce207ee79815b7acf087757 @@ -0,0 +1 @@ +:iI/i?n!%š* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 b/test/core/client_channel/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 new file mode 100644 index 0000000000..fe019fc409 --- /dev/null +++ b/test/core/client_channel/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 @@ -0,0 +1 @@ +uni::.i!in:/i/n!ipv6ž:?(pR;::/a.2b \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd b/test/core/client_channel/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd new file mode 100644 index 0000000000..6e12167b52 --- /dev/null +++ b/test/core/client_channel/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd @@ -0,0 +1 @@ +:ii/iilP.i;?n?n!#i!;!%* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4 b/test/core/client_channel/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4 new file mode 100644 index 0000000000..119b0808c9 --- /dev/null +++ b/test/core/client_channel/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4 @@ -0,0 +1 @@ +:%i:i‡?=#liI_!Kii/?ni* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807 b/test/core/client_channel/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807 new file mode 100644 index 0000000000..01db5d8aa4 --- /dev/null +++ b/test/core/client_channel/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807 @@ -0,0 +1,2 @@ +::unix://ii//a‡?=niI_!';.b.ci?n!% +*; \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d b/test/core/client_channel/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d new file mode 100644 index 0000000000..2ccb535449 --- /dev/null +++ b/test/core/client_channel/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d @@ -0,0 +1 @@ +uni::.i?n(!ipR&/ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9 b/test/core/client_channel/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9 new file mode 100644 index 0000000000..f3c0404be7 --- /dev/null +++ b/test/core/client_channel/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9 @@ -0,0 +1 @@ +::nix::ii///ii/\a:‡?=n;iI_!';&b.ciii \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245 b/test/core/client_channel/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245 new file mode 100644 index 0000000000..b5655220d7 --- /dev/null +++ b/test/core/client_channel/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245 @@ -0,0 +1 @@ +:‡i?P-niI!'iñ \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c b/test/core/client_channel/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c new file mode 100644 index 0000000000..a7656724f5 --- /dev/null +++ b/test/core/client_channel/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c @@ -0,0 +1 @@ +unix://ipv6::: \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca b/test/core/client_channel/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca new file mode 100644 index 0000000000..d658fb8ee0 --- /dev/null +++ b/test/core/client_channel/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca @@ -0,0 +1 @@ +:ilP/i?n!#i: \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a b/test/core/client_channel/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a new file mode 100644 index 0000000000..6d37b5fd45 --- /dev/null +++ b/test/core/client_channel/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a @@ -0,0 +1 @@ +:ilP/i?n,!#i: \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/dns.txt b/test/core/client_channel/uri_corpus/dns.txt new file mode 100644 index 0000000000..577e1054e4 --- /dev/null +++ b/test/core/client_channel/uri_corpus/dns.txt @@ -0,0 +1 @@ +dns:10.2.1.1 diff --git a/test/core/client_channel/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd b/test/core/client_channel/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd new file mode 100644 index 0000000000..497bfd37ee --- /dev/null +++ b/test/core/client_channel/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd @@ -0,0 +1 @@ +ilP:%:%i:i‡i:‡i?=niI_.i;;!?=ii/?n#lniiI_!*Kii!/?ni* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71 b/test/core/client_channel/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71 new file mode 100644 index 0000000000..52f5a2382a --- /dev/null +++ b/test/core/client_channel/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71 @@ -0,0 +1,4 @@ +i:i?n!ip~f2.:/::abipip~6c.* + +::1 +v:Ð:1 diff --git a/test/core/client_channel/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee b/test/core/client_channel/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee new file mode 100644 index 0000000000..c3c93fed6a --- /dev/null +++ b/test/core/client_channel/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee @@ -0,0 +1 @@ +ii-i?n!%* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2 b/test/core/client_channel/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2 new file mode 100644 index 0000000000..45065e2f00 --- /dev/null +++ b/test/core/client_channel/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2 @@ -0,0 +1 @@ +:ii/i?n!%* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 b/test/core/client_channel/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 new file mode 100644 index 0000000000..02151c8b6a --- /dev/null +++ b/test/core/client_channel/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 @@ -0,0 +1,2 @@ +:ipip~6:::1 +vii/:::iunix:?n/1/ipv6!% \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67 b/test/core/client_channel/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67 new file mode 100644 index 0000000000..8034e133d7 --- /dev/null +++ b/test/core/client_channel/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67 @@ -0,0 +1 @@ +:iiP/i?n!i* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/f97598cff03306af3c70400608fec47268b5075d b/test/core/client_channel/uri_corpus/f97598cff03306af3c70400608fec47268b5075d new file mode 100644 index 0000000000..240946dbaa --- /dev/null +++ b/test/core/client_channel/uri_corpus/f97598cff03306af3c70400608fec47268b5075d @@ -0,0 +1,2 @@ +unix://ipv6:::/a.b.c1 + diff --git a/test/core/client_channel/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101 b/test/core/client_channel/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101 new file mode 100644 index 0000000000..d089a59346 --- /dev/null +++ b/test/core/client_channel/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101 @@ -0,0 +1 @@ +:ilP.i;?n!#i; \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4 b/test/core/client_channel/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4 new file mode 100644 index 0000000000..66eefbcc14 --- /dev/null +++ b/test/core/client_channel/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4 @@ -0,0 +1 @@ +:miP/i?)n!'i* \ No newline at end of file diff --git a/test/core/client_channel/uri_corpus/ipv4.txt b/test/core/client_channel/uri_corpus/ipv4.txt new file mode 100644 index 0000000000..fe29486b6e --- /dev/null +++ b/test/core/client_channel/uri_corpus/ipv4.txt @@ -0,0 +1 @@ +ipv4:10.2.1.1 diff --git a/test/core/client_channel/uri_corpus/ipv6.txt b/test/core/client_channel/uri_corpus/ipv6.txt new file mode 100644 index 0000000000..7b6932be00 --- /dev/null +++ b/test/core/client_channel/uri_corpus/ipv6.txt @@ -0,0 +1 @@ +ipv6:::1 diff --git a/test/core/client_channel/uri_corpus/unix.txt b/test/core/client_channel/uri_corpus/unix.txt new file mode 100644 index 0000000000..7a0997ec9a --- /dev/null +++ b/test/core/client_channel/uri_corpus/unix.txt @@ -0,0 +1 @@ +unix:///a.b.c diff --git a/test/core/client_channel/uri_fuzzer_test.c b/test/core/client_channel/uri_fuzzer_test.c new file mode 100644 index 0000000000..d2e3fb40ea --- /dev/null +++ b/test/core/client_channel/uri_fuzzer_test.c @@ -0,0 +1,56 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include + +#include + +#include "src/core/ext/client_channel/uri_parser.h" + +bool squelch = true; +bool leak_check = true; + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + char *s = gpr_malloc(size + 1); + memcpy(s, data, size); + s[size] = 0; + + grpc_uri *x; + if ((x = grpc_uri_parse(s, 1))) { + grpc_uri_destroy(x); + } + gpr_free(s); + return 0; +} diff --git a/test/core/client_channel/uri_parser_test.c b/test/core/client_channel/uri_parser_test.c new file mode 100644 index 0000000000..5f32d3270c --- /dev/null +++ b/test/core/client_channel/uri_parser_test.c @@ -0,0 +1,154 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/ext/client_channel/uri_parser.h" + +#include + +#include + +#include "test/core/util/test_config.h" + +static void test_succeeds(const char *uri_text, const char *scheme, + const char *authority, const char *path, + const char *query, const char *fragment) { + grpc_uri *uri = grpc_uri_parse(uri_text, 0); + GPR_ASSERT(uri); + GPR_ASSERT(0 == strcmp(scheme, uri->scheme)); + GPR_ASSERT(0 == strcmp(authority, uri->authority)); + GPR_ASSERT(0 == strcmp(path, uri->path)); + GPR_ASSERT(0 == strcmp(query, uri->query)); + GPR_ASSERT(0 == strcmp(fragment, uri->fragment)); + grpc_uri_destroy(uri); +} + +static void test_fails(const char *uri_text) { + GPR_ASSERT(NULL == grpc_uri_parse(uri_text, 0)); +} + +static void test_query_parts() { + { + const char *uri_text = "http://foo/path?a&b=B&c=&#frag"; + grpc_uri *uri = grpc_uri_parse(uri_text, 0); + GPR_ASSERT(uri); + + GPR_ASSERT(0 == strcmp("http", uri->scheme)); + GPR_ASSERT(0 == strcmp("foo", uri->authority)); + GPR_ASSERT(0 == strcmp("/path", uri->path)); + GPR_ASSERT(0 == strcmp("a&b=B&c=&", uri->query)); + GPR_ASSERT(4 == uri->num_query_parts); + + GPR_ASSERT(0 == strcmp("a", uri->query_parts[0])); + GPR_ASSERT(NULL == uri->query_parts_values[0]); + + GPR_ASSERT(0 == strcmp("b", uri->query_parts[1])); + GPR_ASSERT(0 == strcmp("B", uri->query_parts_values[1])); + + GPR_ASSERT(0 == strcmp("c", uri->query_parts[2])); + GPR_ASSERT(0 == strcmp("", uri->query_parts_values[2])); + + GPR_ASSERT(0 == strcmp("", uri->query_parts[3])); + GPR_ASSERT(NULL == uri->query_parts_values[3]); + + GPR_ASSERT(NULL == grpc_uri_get_query_arg(uri, "a")); + GPR_ASSERT(0 == strcmp("B", grpc_uri_get_query_arg(uri, "b"))); + GPR_ASSERT(0 == strcmp("", grpc_uri_get_query_arg(uri, "c"))); + GPR_ASSERT(NULL == grpc_uri_get_query_arg(uri, "")); + + GPR_ASSERT(0 == strcmp("frag", uri->fragment)); + grpc_uri_destroy(uri); + } + { + /* test the current behavior of multiple query part values */ + const char *uri_text = "http://auth/path?foo=bar=baz&foobar=="; + grpc_uri *uri = grpc_uri_parse(uri_text, 0); + GPR_ASSERT(uri); + + GPR_ASSERT(0 == strcmp("http", uri->scheme)); + GPR_ASSERT(0 == strcmp("auth", uri->authority)); + GPR_ASSERT(0 == strcmp("/path", uri->path)); + GPR_ASSERT(0 == strcmp("foo=bar=baz&foobar==", uri->query)); + GPR_ASSERT(2 == uri->num_query_parts); + + GPR_ASSERT(0 == strcmp("bar", grpc_uri_get_query_arg(uri, "foo"))); + GPR_ASSERT(0 == strcmp("", grpc_uri_get_query_arg(uri, "foobar"))); + + grpc_uri_destroy(uri); + } + { + /* empty query */ + const char *uri_text = "http://foo/path"; + grpc_uri *uri = grpc_uri_parse(uri_text, 0); + GPR_ASSERT(uri); + + GPR_ASSERT(0 == strcmp("http", uri->scheme)); + GPR_ASSERT(0 == strcmp("foo", uri->authority)); + GPR_ASSERT(0 == strcmp("/path", uri->path)); + GPR_ASSERT(0 == strcmp("", uri->query)); + GPR_ASSERT(0 == uri->num_query_parts); + GPR_ASSERT(NULL == uri->query_parts); + GPR_ASSERT(NULL == uri->query_parts_values); + GPR_ASSERT(0 == strcmp("", uri->fragment)); + grpc_uri_destroy(uri); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + test_succeeds("http://www.google.com", "http", "www.google.com", "", "", ""); + test_succeeds("dns:///foo", "dns", "", "/foo", "", ""); + test_succeeds("http://www.google.com:90", "http", "www.google.com:90", "", "", + ""); + test_succeeds("a192.4-df:foo.coom", "a192.4-df", "", "foo.coom", "", ""); + test_succeeds("a+b:foo.coom", "a+b", "", "foo.coom", "", ""); + test_succeeds("zookeeper://127.0.0.1:2181/foo/bar", "zookeeper", + "127.0.0.1:2181", "/foo/bar", "", ""); + test_succeeds("http://www.google.com?yay-i'm-using-queries", "http", + "www.google.com", "", "yay-i'm-using-queries", ""); + test_succeeds("dns:foo.com#fragment-all-the-things", "dns", "", "foo.com", "", + "fragment-all-the-things"); + test_succeeds("http:?legit", "http", "", "", "legit", ""); + test_succeeds("unix:#this-is-ok-too", "unix", "", "", "", "this-is-ok-too"); + test_succeeds("http:?legit#twice", "http", "", "", "legit", "twice"); + test_succeeds("http://foo?bar#lol?", "http", "foo", "", "bar", "lol?"); + test_succeeds("http://foo?bar#lol?/", "http", "foo", "", "bar", "lol?/"); + + test_fails("xyz"); + test_fails("http:?dangling-pct-%0"); + test_fails("http://foo?[bar]"); + test_fails("http://foo?x[bar]"); + test_fails("http://foo?bar#lol#"); + + test_query_parts(); + return 0; +} diff --git a/test/core/client_config/lb_policies_test.c b/test/core/client_config/lb_policies_test.c deleted file mode 100644 index 0b9648b7e1..0000000000 --- a/test/core/client_config/lb_policies_test.c +++ /dev/null @@ -1,938 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "src/core/ext/client_config/client_channel.h" -#include "src/core/ext/client_config/lb_policy_registry.h" -#include "src/core/lib/channel/channel_stack.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/surface/channel.h" -#include "src/core/lib/surface/server.h" -#include "test/core/end2end/cq_verifier.h" -#include "test/core/util/port.h" -#include "test/core/util/test_config.h" - -#define RETRY_TIMEOUT 300 - -typedef struct servers_fixture { - size_t num_servers; - grpc_server **servers; - grpc_call **server_calls; - grpc_completion_queue *cq; - char **servers_hostports; - grpc_metadata_array *request_metadata_recv; -} servers_fixture; - -typedef void (*verifier_fn)(const servers_fixture *, grpc_channel *, - const int *, const size_t); - -typedef struct test_spec { - size_t num_iters; - size_t num_servers; - - int **kill_at; - int **revive_at; - - const char *description; - - verifier_fn verifier; - -} test_spec; - -static void test_spec_reset(test_spec *spec) { - size_t i, j; - - for (i = 0; i < spec->num_iters; i++) { - for (j = 0; j < spec->num_servers; j++) { - spec->kill_at[i][j] = 0; - spec->revive_at[i][j] = 0; - } - } -} - -static test_spec *test_spec_create(size_t num_iters, size_t num_servers) { - test_spec *spec; - size_t i; - - spec = gpr_malloc(sizeof(test_spec)); - spec->num_iters = num_iters; - spec->num_servers = num_servers; - spec->kill_at = gpr_malloc(sizeof(int *) * num_iters); - spec->revive_at = gpr_malloc(sizeof(int *) * num_iters); - for (i = 0; i < num_iters; i++) { - spec->kill_at[i] = gpr_malloc(sizeof(int) * num_servers); - spec->revive_at[i] = gpr_malloc(sizeof(int) * num_servers); - } - - test_spec_reset(spec); - return spec; -} - -static void test_spec_destroy(test_spec *spec) { - size_t i; - for (i = 0; i < spec->num_iters; i++) { - gpr_free(spec->kill_at[i]); - gpr_free(spec->revive_at[i]); - } - - gpr_free(spec->kill_at); - gpr_free(spec->revive_at); - - gpr_free(spec); -} - -static void *tag(intptr_t t) { return (void *)t; } - -static gpr_timespec n_millis_time(int n) { - return gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_millis(n, GPR_TIMESPAN)); -} - -static void drain_cq(grpc_completion_queue *cq) { - grpc_event ev; - do { - ev = grpc_completion_queue_next(cq, n_millis_time(5000), NULL); - } while (ev.type != GRPC_QUEUE_SHUTDOWN); -} - -static void kill_server(const servers_fixture *f, size_t i) { - gpr_log(GPR_INFO, "KILLING SERVER %" PRIuPTR, i); - GPR_ASSERT(f->servers[i] != NULL); - grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); - GPR_ASSERT( - grpc_completion_queue_pluck(f->cq, tag(10000), n_millis_time(5000), NULL) - .type == GRPC_OP_COMPLETE); - grpc_server_destroy(f->servers[i]); - f->servers[i] = NULL; -} - -typedef struct request_data { - grpc_metadata_array initial_metadata_recv; - grpc_metadata_array trailing_metadata_recv; - char *details; - size_t details_capacity; - grpc_status_code status; - grpc_call_details *call_details; -} request_data; - -static void revive_server(const servers_fixture *f, request_data *rdata, - size_t i) { - int got_port; - gpr_log(GPR_INFO, "RAISE AGAIN SERVER %" PRIuPTR, i); - GPR_ASSERT(f->servers[i] == NULL); - - gpr_log(GPR_DEBUG, "revive: %s", f->servers_hostports[i]); - - f->servers[i] = grpc_server_create(NULL, NULL); - grpc_server_register_completion_queue(f->servers[i], f->cq, NULL); - GPR_ASSERT((got_port = grpc_server_add_insecure_http2_port( - f->servers[i], f->servers_hostports[i])) > 0); - grpc_server_start(f->servers[i]); - - GPR_ASSERT(GRPC_CALL_OK == - grpc_server_request_call(f->servers[i], &f->server_calls[i], - &rdata->call_details[i], - &f->request_metadata_recv[i], f->cq, - f->cq, tag(1000 + (int)i))); -} - -static servers_fixture *setup_servers(const char *server_host, - request_data *rdata, - const size_t num_servers) { - servers_fixture *f = gpr_malloc(sizeof(servers_fixture)); - size_t i; - - f->num_servers = num_servers; - f->server_calls = gpr_malloc(sizeof(grpc_call *) * num_servers); - f->request_metadata_recv = - gpr_malloc(sizeof(grpc_metadata_array) * num_servers); - /* Create servers. */ - f->servers = gpr_malloc(sizeof(grpc_server *) * num_servers); - f->servers_hostports = gpr_malloc(sizeof(char *) * num_servers); - f->cq = grpc_completion_queue_create(NULL); - for (i = 0; i < num_servers; i++) { - grpc_metadata_array_init(&f->request_metadata_recv[i]); - gpr_join_host_port(&f->servers_hostports[i], server_host, - grpc_pick_unused_port_or_die()); - f->servers[i] = 0; - revive_server(f, rdata, i); - } - return f; -} - -static void teardown_servers(servers_fixture *f) { - size_t i; - /* Destroy server. */ - for (i = 0; i < f->num_servers; i++) { - if (f->servers[i] == NULL) continue; - grpc_server_shutdown_and_notify(f->servers[i], f->cq, tag(10000)); - GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(10000), - n_millis_time(5000), NULL) - .type == GRPC_OP_COMPLETE); - grpc_server_destroy(f->servers[i]); - } - grpc_completion_queue_shutdown(f->cq); - drain_cq(f->cq); - grpc_completion_queue_destroy(f->cq); - - gpr_free(f->servers); - - for (i = 0; i < f->num_servers; i++) { - gpr_free(f->servers_hostports[i]); - grpc_metadata_array_destroy(&f->request_metadata_recv[i]); - } - - gpr_free(f->servers_hostports); - gpr_free(f->request_metadata_recv); - gpr_free(f->server_calls); - gpr_free(f); -} - -/** Returns connection sequence (server indices), which must be freed */ -static int *perform_request(servers_fixture *f, grpc_channel *client, - request_data *rdata, const test_spec *spec) { - grpc_call *c; - int s_idx; - int *s_valid; - grpc_op ops[6]; - grpc_op *op; - int was_cancelled; - size_t i, iter_num; - grpc_event ev; - int read_tag; - int *connection_sequence; - int completed_client; - - s_valid = gpr_malloc(sizeof(int) * f->num_servers); - connection_sequence = gpr_malloc(sizeof(int) * spec->num_iters); - - for (iter_num = 0; iter_num < spec->num_iters; iter_num++) { - cq_verifier *cqv = cq_verifier_create(f->cq); - rdata->details = NULL; - rdata->details_capacity = 0; - was_cancelled = 2; - - for (i = 0; i < f->num_servers; i++) { - if (spec->kill_at[iter_num][i] != 0) { - kill_server(f, i); - } else if (spec->revive_at[iter_num][i] != 0) { - /* killing takes precedence */ - revive_server(f, rdata, i); - } - } - - connection_sequence[iter_num] = -1; - grpc_metadata_array_init(&rdata->initial_metadata_recv); - grpc_metadata_array_init(&rdata->trailing_metadata_recv); - - for (i = 0; i < f->num_servers; i++) { - grpc_call_details_init(&rdata->call_details[i]); - } - memset(s_valid, 0, f->num_servers * sizeof(int)); - - c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, - "/foo", "foo.test.google.fr", - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); - GPR_ASSERT(c); - completed_client = 0; - - memset(ops, 0, sizeof(ops)); - op = ops; - op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->data.send_initial_metadata.count = 0; - op->flags = 0; - op->reserved = NULL; - op++; - op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; - op->flags = 0; - op->reserved = NULL; - op++; - op->op = GRPC_OP_RECV_INITIAL_METADATA; - op->data.recv_initial_metadata = &rdata->initial_metadata_recv; - op->flags = 0; - op->reserved = NULL; - op++; - op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; - op->data.recv_status_on_client.trailing_metadata = - &rdata->trailing_metadata_recv; - op->data.recv_status_on_client.status = &rdata->status; - op->data.recv_status_on_client.status_details = &rdata->details; - op->data.recv_status_on_client.status_details_capacity = - &rdata->details_capacity; - op->flags = 0; - op->reserved = NULL; - op++; - GPR_ASSERT(GRPC_CALL_OK == - grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL)); - - s_idx = -1; - while ( - (ev = grpc_completion_queue_next( - f->cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10 * RETRY_TIMEOUT), NULL)) - .type != GRPC_QUEUE_TIMEOUT) { - GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); - read_tag = ((int)(intptr_t)ev.tag); - gpr_log(GPR_DEBUG, "EVENT: success:%d, type:%d, tag:%d iter:%" PRIuPTR, - ev.success, ev.type, read_tag, iter_num); - if (ev.success && read_tag >= 1000) { - GPR_ASSERT(s_idx == -1); /* only one server must reply */ - /* only server notifications for non-shutdown events */ - s_idx = read_tag - 1000; - s_valid[s_idx] = 1; - connection_sequence[iter_num] = s_idx; - break; - } else if (read_tag == 1) { - gpr_log(GPR_DEBUG, "client timed out"); - GPR_ASSERT(ev.success); - completed_client = 1; - } - } - - if (s_idx >= 0) { - memset(ops, 0, sizeof(ops)); - op = ops; - op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->data.send_initial_metadata.count = 0; - op->flags = 0; - op->reserved = NULL; - op++; - op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; - op->data.send_status_from_server.trailing_metadata_count = 0; - op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; - op->flags = 0; - op->reserved = NULL; - op++; - op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; - op->data.recv_close_on_server.cancelled = &was_cancelled; - op->flags = 0; - op->reserved = NULL; - op++; - GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(f->server_calls[s_idx], - ops, (size_t)(op - ops), - tag(102), NULL)); - - CQ_EXPECT_COMPLETION(cqv, tag(102), 1); - if (!completed_client) { - CQ_EXPECT_COMPLETION(cqv, tag(1), 1); - } - cq_verify(cqv); - - gpr_log(GPR_DEBUG, "status=%d; %s", rdata->status, rdata->details); - GPR_ASSERT(rdata->status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(rdata->details, "xyz")); - GPR_ASSERT(0 == strcmp(rdata->call_details[s_idx].method, "/foo")); - GPR_ASSERT(0 == - strcmp(rdata->call_details[s_idx].host, "foo.test.google.fr")); - GPR_ASSERT(was_cancelled == 1); - - grpc_call_destroy(f->server_calls[s_idx]); - - /* ask for the next request on this server */ - GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( - f->servers[s_idx], &f->server_calls[s_idx], - &rdata->call_details[s_idx], - &f->request_metadata_recv[s_idx], f->cq, - f->cq, tag(1000 + (int)s_idx))); - } else { /* no response from server */ - grpc_call_cancel(c, NULL); - if (!completed_client) { - CQ_EXPECT_COMPLETION(cqv, tag(1), 1); - cq_verify(cqv); - } - } - - GPR_ASSERT( - grpc_completion_queue_next( - f->cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(2 * RETRY_TIMEOUT), NULL) - .type == GRPC_QUEUE_TIMEOUT); - - grpc_metadata_array_destroy(&rdata->initial_metadata_recv); - grpc_metadata_array_destroy(&rdata->trailing_metadata_recv); - - cq_verifier_destroy(cqv); - - grpc_call_destroy(c); - - for (i = 0; i < f->num_servers; i++) { - grpc_call_details_destroy(&rdata->call_details[i]); - } - gpr_free(rdata->details); - } - - gpr_free(s_valid); - - return connection_sequence; -} - -static grpc_call **perform_multirequest(servers_fixture *f, - grpc_channel *client, - size_t concurrent_calls) { - grpc_call **calls; - grpc_op ops[6]; - grpc_op *op; - size_t i; - - calls = gpr_malloc(sizeof(grpc_call *) * concurrent_calls); - for (i = 0; i < f->num_servers; i++) { - kill_server(f, i); - } - - memset(ops, 0, sizeof(ops)); - op = ops; - op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->data.send_initial_metadata.count = 0; - op->flags = 0; - op->reserved = NULL; - op++; - op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; - op->flags = 0; - op->reserved = NULL; - - for (i = 0; i < concurrent_calls; i++) { - calls[i] = grpc_channel_create_call( - client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, "/foo", - "foo.test.google.fr", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); - GPR_ASSERT(calls[i]); - GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[i], ops, - (size_t)(op - ops), tag(1), - NULL)); - } - - return calls; -} - -static void assert_channel_connectivity(grpc_channel *ch, - size_t num_accepted_conn_states, - int accepted_conn_state, ...) { - size_t i; - grpc_channel_stack *client_stack; - grpc_channel_element *client_channel_filter; - grpc_connectivity_state actual_conn_state; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - va_list ap; - - client_stack = grpc_channel_get_channel_stack(ch); - client_channel_filter = grpc_channel_stack_last_element(client_stack); - - actual_conn_state = grpc_client_channel_check_connectivity_state( - &exec_ctx, client_channel_filter, 0 /* don't try to connect */); - grpc_exec_ctx_finish(&exec_ctx); - va_start(ap, accepted_conn_state); - for (i = 0; i < num_accepted_conn_states; i++) { - if ((int)actual_conn_state == accepted_conn_state) { - break; - } - accepted_conn_state = va_arg(ap, grpc_connectivity_state); - } - va_end(ap); - if (i == num_accepted_conn_states) { - char **accepted_strs = - gpr_malloc(sizeof(char *) * num_accepted_conn_states); - char *accepted_str_joined; - va_start(ap, accepted_conn_state); - for (i = 0; i < num_accepted_conn_states; i++) { - GPR_ASSERT(gpr_asprintf(&accepted_strs[i], "%d", accepted_conn_state) > - 0); - accepted_conn_state = va_arg(ap, grpc_connectivity_state); - } - va_end(ap); - accepted_str_joined = gpr_strjoin_sep((const char **)accepted_strs, - num_accepted_conn_states, ", ", NULL); - gpr_log( - GPR_ERROR, - "Channel connectivity assertion failed: expected , got %d", - accepted_str_joined, actual_conn_state); - - for (i = 0; i < num_accepted_conn_states; i++) { - gpr_free(accepted_strs[i]); - } - gpr_free(accepted_strs); - gpr_free(accepted_str_joined); - abort(); - } -} - -void run_spec(const test_spec *spec) { - grpc_channel *client; - char *client_hostport; - char *servers_hostports_str; - int *actual_connection_sequence; - request_data rdata; - servers_fixture *f; - grpc_channel_args args; - grpc_arg arg; - rdata.call_details = - gpr_malloc(sizeof(grpc_call_details) * spec->num_servers); - f = setup_servers("127.0.0.1", &rdata, spec->num_servers); - - /* Create client. */ - servers_hostports_str = gpr_strjoin_sep((const char **)f->servers_hostports, - f->num_servers, ",", NULL); - gpr_asprintf(&client_hostport, "ipv4:%s?lb_policy=round_robin", - servers_hostports_str); - - arg.type = GRPC_ARG_INTEGER; - arg.key = "grpc.testing.fixed_reconnect_backoff"; - arg.value.integer = RETRY_TIMEOUT; - args.num_args = 1; - args.args = &arg; - - client = grpc_insecure_channel_create(client_hostport, &args, NULL); - - gpr_log(GPR_INFO, "Testing '%s' with servers=%s client=%s", spec->description, - servers_hostports_str, client_hostport); - - actual_connection_sequence = perform_request(f, client, &rdata, spec); - - spec->verifier(f, client, actual_connection_sequence, spec->num_iters); - - gpr_free(client_hostport); - gpr_free(servers_hostports_str); - gpr_free(actual_connection_sequence); - gpr_free(rdata.call_details); - - grpc_channel_destroy(client); /* calls the LB's shutdown func */ - teardown_servers(f); -} - -static grpc_channel *create_client(const servers_fixture *f) { - grpc_channel *client; - char *client_hostport; - char *servers_hostports_str; - grpc_arg arg; - grpc_channel_args args; - - servers_hostports_str = gpr_strjoin_sep((const char **)f->servers_hostports, - f->num_servers, ",", NULL); - gpr_asprintf(&client_hostport, "ipv4:%s?lb_policy=round_robin", - servers_hostports_str); - - arg.type = GRPC_ARG_INTEGER; - arg.key = "grpc.testing.fixed_reconnect_backoff"; - arg.value.integer = RETRY_TIMEOUT; - args.num_args = 1; - args.args = &arg; - - client = grpc_insecure_channel_create(client_hostport, &args, NULL); - gpr_free(client_hostport); - gpr_free(servers_hostports_str); - - return client; -} - -static void test_ping() { - grpc_channel *client; - request_data rdata; - servers_fixture *f; - cq_verifier *cqv; - grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - const size_t num_servers = 1; - int i; - - rdata.call_details = gpr_malloc(sizeof(grpc_call_details) * num_servers); - f = setup_servers("127.0.0.1", &rdata, num_servers); - cqv = cq_verifier_create(f->cq); - - client = create_client(f); - - grpc_channel_ping(client, f->cq, tag(0), NULL); - CQ_EXPECT_COMPLETION(cqv, tag(0), 0); - - /* check that we're still in idle, and start connecting */ - GPR_ASSERT(grpc_channel_check_connectivity_state(client, 1) == - GRPC_CHANNEL_IDLE); - /* we'll go through some set of transitions (some might be missed), until - READY is reached */ - while (state != GRPC_CHANNEL_READY) { - grpc_channel_watch_connectivity_state( - client, state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f->cq, tag(99)); - CQ_EXPECT_COMPLETION(cqv, tag(99), 1); - cq_verify(cqv); - state = grpc_channel_check_connectivity_state(client, 0); - GPR_ASSERT(state == GRPC_CHANNEL_READY || - state == GRPC_CHANNEL_CONNECTING || - state == GRPC_CHANNEL_TRANSIENT_FAILURE); - } - - for (i = 1; i <= 5; i++) { - grpc_channel_ping(client, f->cq, tag(i), NULL); - CQ_EXPECT_COMPLETION(cqv, tag(i), 1); - cq_verify(cqv); - } - gpr_free(rdata.call_details); - - grpc_channel_destroy(client); - teardown_servers(f); - - cq_verifier_destroy(cqv); -} - -static void test_pending_calls(size_t concurrent_calls) { - size_t i; - grpc_call **calls; - grpc_channel *client; - request_data rdata; - servers_fixture *f; - test_spec *spec = test_spec_create(0, 4); - rdata.call_details = - gpr_malloc(sizeof(grpc_call_details) * spec->num_servers); - f = setup_servers("127.0.0.1", &rdata, spec->num_servers); - - client = create_client(f); - calls = perform_multirequest(f, client, concurrent_calls); - grpc_call_cancel( - calls[0], - NULL); /* exercise the cancel pick path whilst there are pending picks */ - - gpr_free(rdata.call_details); - - grpc_channel_destroy(client); /* calls the LB's shutdown func */ - /* destroy the calls after the channel so that they are still around for the - * LB's shutdown func to process */ - for (i = 0; i < concurrent_calls; i++) { - grpc_call_destroy(calls[i]); - } - gpr_free(calls); - teardown_servers(f); - test_spec_destroy(spec); -} - -static void print_failed_expectations(const int *expected_connection_sequence, - const int *actual_connection_sequence, - const size_t expected_seq_length, - const size_t num_iters) { - size_t i; - for (i = 0; i < num_iters; i++) { - gpr_log(GPR_ERROR, - "FAILURE: Iter (expected, actual): %" PRIuPTR " (%d, %d)", i, - expected_connection_sequence[i % expected_seq_length], - actual_connection_sequence[i]); - } -} - -static void verify_vanilla_round_robin(const servers_fixture *f, - grpc_channel *client, - const int *actual_connection_sequence, - const size_t num_iters) { - int *expected_connection_sequence; - size_t i; - const size_t expected_seq_length = f->num_servers; - - /* verify conn. seq. expectation */ - /* get the first sequence of "num_servers" elements */ - expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); - memcpy(expected_connection_sequence, actual_connection_sequence, - sizeof(int) * expected_seq_length); - - for (i = 0; i < num_iters; i++) { - const int actual = actual_connection_sequence[i]; - const int expected = expected_connection_sequence[i % expected_seq_length]; - if (actual != expected) { - print_failed_expectations(expected_connection_sequence, - actual_connection_sequence, expected_seq_length, - num_iters); - abort(); - } - } - assert_channel_connectivity(client, 1, GRPC_CHANNEL_READY); - - gpr_free(expected_connection_sequence); -} - -/* At the start of the second iteration, all but the first and last servers (as - * given in "f") are killed */ -static void verify_vanishing_floor_round_robin( - const servers_fixture *f, grpc_channel *client, - const int *actual_connection_sequence, const size_t num_iters) { - int *expected_connection_sequence; - const size_t expected_seq_length = 2; - size_t i; - - /* verify conn. seq. expectation */ - /* copy the first full sequence (without -1s) */ - expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); - memcpy(expected_connection_sequence, actual_connection_sequence + 2, - expected_seq_length * sizeof(int)); - - /* first two elements of the sequence should be [0 (1st server), -1 (failure)] - */ - GPR_ASSERT(actual_connection_sequence[0] == 0); - GPR_ASSERT(actual_connection_sequence[1] == -1); - - /* the next two element must be [3, 0], repeating from that point: the 3 is - * brought forth by servers 1 and 2 disappearing after the intial pick of 0 */ - GPR_ASSERT(actual_connection_sequence[2] == 3); - GPR_ASSERT(actual_connection_sequence[3] == 0); - - /* make sure that the expectation obliges */ - for (i = 2; i < num_iters; i++) { - const int actual = actual_connection_sequence[i]; - const int expected = expected_connection_sequence[i % expected_seq_length]; - if (actual != expected) { - print_failed_expectations(expected_connection_sequence, - actual_connection_sequence, expected_seq_length, - num_iters); - abort(); - } - } - gpr_free(expected_connection_sequence); -} - -static void verify_total_carnage_round_robin( - const servers_fixture *f, grpc_channel *client, - const int *actual_connection_sequence, const size_t num_iters) { - size_t i; - - for (i = 0; i < num_iters; i++) { - const int actual = actual_connection_sequence[i]; - const int expected = -1; - if (actual != expected) { - gpr_log(GPR_ERROR, "FAILURE: expected %d, actual %d at iter %" PRIuPTR, - expected, actual, i); - abort(); - } - } - - /* even though we know all the servers are dead, the client is still trying - * retrying, believing it's in a transient failure situation */ - assert_channel_connectivity(client, 2, GRPC_CHANNEL_TRANSIENT_FAILURE, - GRPC_CHANNEL_CONNECTING); -} - -static void verify_partial_carnage_round_robin( - const servers_fixture *f, grpc_channel *client, - const int *actual_connection_sequence, const size_t num_iters) { - int *expected_connection_sequence; - size_t i; - const size_t expected_seq_length = f->num_servers; - - /* verify conn. seq. expectation */ - /* get the first sequence of "num_servers" elements */ - expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); - memcpy(expected_connection_sequence, actual_connection_sequence, - sizeof(int) * expected_seq_length); - - for (i = 0; i < num_iters / 2; i++) { - const int actual = actual_connection_sequence[i]; - const int expected = expected_connection_sequence[i % expected_seq_length]; - if (actual != expected) { - print_failed_expectations(expected_connection_sequence, - actual_connection_sequence, expected_seq_length, - num_iters); - abort(); - } - } - - /* second half of the iterations go without response */ - for (; i < num_iters; i++) { - GPR_ASSERT(actual_connection_sequence[i] == -1); - } - - /* even though we know all the servers are dead, the client is still trying - * retrying, believing it's in a transient failure situation */ - assert_channel_connectivity(client, 2, GRPC_CHANNEL_TRANSIENT_FAILURE, - GRPC_CHANNEL_CONNECTING); - gpr_free(expected_connection_sequence); -} - -static void dump_array(const char *desc, const int *data, const size_t count) { - gpr_strvec s; - char *tmp; - size_t i; - gpr_strvec_init(&s); - gpr_strvec_add(&s, gpr_strdup(desc)); - gpr_strvec_add(&s, gpr_strdup(":")); - for (i = 0; i < count; i++) { - gpr_asprintf(&tmp, " %d", data[i]); - gpr_strvec_add(&s, tmp); - } - tmp = gpr_strvec_flatten(&s, NULL); - gpr_strvec_destroy(&s); - gpr_log(GPR_DEBUG, "%s", tmp); - gpr_free(tmp); -} - -static void verify_rebirth_round_robin(const servers_fixture *f, - grpc_channel *client, - const int *actual_connection_sequence, - const size_t num_iters) { - int *expected_connection_sequence; - size_t i, j, unique_seq_last_idx, unique_seq_first_idx; - const size_t expected_seq_length = f->num_servers; - int *seen_elements; - - dump_array("actual_connection_sequence", actual_connection_sequence, - num_iters); - - /* verify conn. seq. expectation */ - /* get the first unique run of length "num_servers". */ - expected_connection_sequence = gpr_malloc(sizeof(int) * expected_seq_length); - seen_elements = gpr_malloc(sizeof(int) * expected_seq_length); - - unique_seq_last_idx = ~(size_t)0; - - memset(seen_elements, 0, sizeof(int) * expected_seq_length); - for (i = 0; i < num_iters; i++) { - if (actual_connection_sequence[i] < 0 || - seen_elements[actual_connection_sequence[i]] != 0) { - /* if anything breaks the uniqueness of the run, back to square zero */ - memset(seen_elements, 0, sizeof(int) * expected_seq_length); - continue; - } - seen_elements[actual_connection_sequence[i]] = 1; - for (j = 0; j < expected_seq_length; j++) { - if (seen_elements[j] == 0) break; - } - if (j == expected_seq_length) { /* seen all the elements */ - unique_seq_last_idx = i; - break; - } - } - /* make sure we found a valid run */ - dump_array("seen_elements", seen_elements, expected_seq_length); - for (j = 0; j < expected_seq_length; j++) { - GPR_ASSERT(seen_elements[j] != 0); - } - - GPR_ASSERT(unique_seq_last_idx != ~(size_t)0); - - unique_seq_first_idx = (unique_seq_last_idx - expected_seq_length + 1); - memcpy(expected_connection_sequence, - actual_connection_sequence + unique_seq_first_idx, - sizeof(int) * expected_seq_length); - - /* first iteration succeeds */ - GPR_ASSERT(actual_connection_sequence[0] != -1); - /* then we fail for a while... */ - GPR_ASSERT(actual_connection_sequence[1] == -1); - /* ... but should be up at "unique_seq_first_idx" */ - GPR_ASSERT(actual_connection_sequence[unique_seq_first_idx] != -1); - - for (j = 0, i = unique_seq_first_idx; i < num_iters; i++) { - const int actual = actual_connection_sequence[i]; - const int expected = - expected_connection_sequence[j++ % expected_seq_length]; - if (actual != expected) { - print_failed_expectations(expected_connection_sequence, - actual_connection_sequence, expected_seq_length, - num_iters); - abort(); - } - } - - /* things are fine once the servers are brought back up */ - assert_channel_connectivity(client, 1, GRPC_CHANNEL_READY); - gpr_free(expected_connection_sequence); - gpr_free(seen_elements); -} - -int main(int argc, char **argv) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - test_spec *spec; - size_t i; - const size_t NUM_ITERS = 10; - const size_t NUM_SERVERS = 4; - - grpc_test_init(argc, argv); - grpc_init(); - grpc_tracer_set_enabled("round_robin", 1); - - GPR_ASSERT(grpc_lb_policy_create(&exec_ctx, "this-lb-policy-does-not-exist", - NULL) == NULL); - GPR_ASSERT(grpc_lb_policy_create(&exec_ctx, NULL, NULL) == NULL); - - spec = test_spec_create(NUM_ITERS, NUM_SERVERS); - /* everything is fine, all servers stay up the whole time and life's peachy - */ - spec->verifier = verify_vanilla_round_robin; - spec->description = "test_all_server_up"; - run_spec(spec); - - /* Kill all servers first thing in the morning */ - test_spec_reset(spec); - spec->verifier = verify_total_carnage_round_robin; - spec->description = "test_kill_all_server"; - for (i = 0; i < NUM_SERVERS; i++) { - spec->kill_at[0][i] = 1; - } - run_spec(spec); - - /* at the start of the 2nd iteration, kill all but the first and last - * servers. - * This should knock down the server bound to be selected next */ - test_spec_reset(spec); - spec->verifier = verify_vanishing_floor_round_robin; - spec->description = "test_kill_all_server_at_2nd_iteration"; - for (i = 1; i < NUM_SERVERS - 1; i++) { - spec->kill_at[1][i] = 1; - } - run_spec(spec); - - /* Midway, kill all servers. */ - test_spec_reset(spec); - spec->verifier = verify_partial_carnage_round_robin; - spec->description = "test_kill_all_server_midway"; - for (i = 0; i < NUM_SERVERS; i++) { - spec->kill_at[spec->num_iters / 2][i] = 1; - } - run_spec(spec); - - /* After first iteration, kill all servers. On the third one, bring them all - * back up. */ - test_spec_reset(spec); - spec->verifier = verify_rebirth_round_robin; - spec->description = "test_kill_all_server_after_1st_resurrect_at_3rd"; - for (i = 0; i < NUM_SERVERS; i++) { - spec->kill_at[1][i] = 1; - spec->revive_at[3][i] = 1; - } - run_spec(spec); - test_spec_destroy(spec); - - test_pending_calls(4); - test_ping(); - - grpc_exec_ctx_finish(&exec_ctx); - grpc_shutdown(); - return 0; -} diff --git a/test/core/client_config/resolvers/dns_resolver_connectivity_test.c b/test/core/client_config/resolvers/dns_resolver_connectivity_test.c deleted file mode 100644 index 6a33525f62..0000000000 --- a/test/core/client_config/resolvers/dns_resolver_connectivity_test.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#include -#include - -#include "src/core/ext/client_config/resolver_registry.h" -#include "src/core/lib/iomgr/resolve_address.h" -#include "src/core/lib/iomgr/timer.h" -#include "test/core/util/test_config.h" - -static void client_channel_factory_ref(grpc_client_channel_factory *scv) {} -static void client_channel_factory_unref(grpc_exec_ctx *exec_ctx, - grpc_client_channel_factory *scv) {} -static grpc_subchannel *client_channel_factory_create_subchannel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, - grpc_subchannel_args *args) { - return NULL; -} - -static grpc_channel *client_channel_factory_create_channel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, - const char *target, grpc_client_channel_type type, - grpc_channel_args *args) { - GPR_UNREACHABLE_CODE(return NULL); -} - -static const grpc_client_channel_factory_vtable sc_vtable = { - client_channel_factory_ref, client_channel_factory_unref, - client_channel_factory_create_subchannel, - client_channel_factory_create_channel}; - -static grpc_client_channel_factory cc_factory = {&sc_vtable}; - -static gpr_mu g_mu; -static bool g_fail_resolution = true; - -static grpc_error *my_resolve_address(const char *name, const char *addr, - grpc_resolved_addresses **addrs) { - gpr_mu_lock(&g_mu); - GPR_ASSERT(0 == strcmp("test", name)); - if (g_fail_resolution) { - g_fail_resolution = false; - gpr_mu_unlock(&g_mu); - return GRPC_ERROR_CREATE("Forced Failure"); - } else { - gpr_mu_unlock(&g_mu); - *addrs = gpr_malloc(sizeof(**addrs)); - (*addrs)->naddrs = 1; - (*addrs)->addrs = gpr_malloc(sizeof(*(*addrs)->addrs)); - (*addrs)->addrs[0].len = 123; - return GRPC_ERROR_NONE; - } -} - -static grpc_resolver *create_resolver(const char *name) { - grpc_resolver_factory *factory = grpc_resolver_factory_lookup("dns"); - grpc_uri *uri = grpc_uri_parse(name, 0); - GPR_ASSERT(uri); - grpc_resolver_args args; - memset(&args, 0, sizeof(args)); - args.uri = uri; - args.client_channel_factory = &cc_factory; - grpc_resolver *resolver = - grpc_resolver_factory_create_resolver(factory, &args); - grpc_resolver_factory_unref(factory); - grpc_uri_destroy(uri); - return resolver; -} - -static void on_done(grpc_exec_ctx *exec_ctx, void *ev, grpc_error *error) { - gpr_event_set(ev, (void *)1); -} - -// interleave waiting for an event with a timer check -static bool wait_loop(int deadline_seconds, gpr_event *ev) { - while (deadline_seconds) { - gpr_log(GPR_DEBUG, "Test: waiting for %d more seconds", deadline_seconds); - if (gpr_event_wait(ev, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1))) return true; - deadline_seconds--; - - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_timer_check(&exec_ctx, gpr_now(GPR_CLOCK_MONOTONIC), NULL); - grpc_exec_ctx_finish(&exec_ctx); - } - return false; -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - grpc_init(); - gpr_mu_init(&g_mu); - grpc_blocking_resolve_address = my_resolve_address; - - grpc_resolver *resolver = create_resolver("dns:test"); - - grpc_resolver_result *result = (grpc_resolver_result *)1; - - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - gpr_event ev1; - gpr_event_init(&ev1); - grpc_resolver_next(&exec_ctx, resolver, &result, - grpc_closure_create(on_done, &ev1)); - grpc_exec_ctx_flush(&exec_ctx); - GPR_ASSERT(wait_loop(5, &ev1)); - GPR_ASSERT(result == NULL); - - gpr_event ev2; - gpr_event_init(&ev2); - grpc_resolver_next(&exec_ctx, resolver, &result, - grpc_closure_create(on_done, &ev2)); - grpc_exec_ctx_flush(&exec_ctx); - GPR_ASSERT(wait_loop(30, &ev2)); - GPR_ASSERT(result != NULL); - - grpc_resolver_result_unref(&exec_ctx, result); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test"); - grpc_exec_ctx_finish(&exec_ctx); - - grpc_shutdown(); - gpr_mu_destroy(&g_mu); -} diff --git a/test/core/client_config/resolvers/dns_resolver_test.c b/test/core/client_config/resolvers/dns_resolver_test.c deleted file mode 100644 index 21dc99cadd..0000000000 --- a/test/core/client_config/resolvers/dns_resolver_test.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#include - -#include "src/core/ext/client_config/resolver_registry.h" -#include "test/core/util/test_config.h" - -static void client_channel_factory_ref(grpc_client_channel_factory *scv) {} -static void client_channel_factory_unref(grpc_exec_ctx *exec_ctx, - grpc_client_channel_factory *scv) {} -static grpc_subchannel *client_channel_factory_create_subchannel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, - grpc_subchannel_args *args) { - GPR_UNREACHABLE_CODE(return NULL); -} - -static grpc_channel *client_channel_factory_create_channel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, - const char *target, grpc_client_channel_type type, - grpc_channel_args *args) { - GPR_UNREACHABLE_CODE(return NULL); -} - -static const grpc_client_channel_factory_vtable sc_vtable = { - client_channel_factory_ref, client_channel_factory_unref, - client_channel_factory_create_subchannel, - client_channel_factory_create_channel}; - -static grpc_client_channel_factory cc_factory = {&sc_vtable}; - -static void test_succeeds(grpc_resolver_factory *factory, const char *string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri *uri = grpc_uri_parse(string, 0); - grpc_resolver_args args; - grpc_resolver *resolver; - gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, - factory->vtable->scheme); - GPR_ASSERT(uri); - memset(&args, 0, sizeof(args)); - args.uri = uri; - args.client_channel_factory = &cc_factory; - resolver = grpc_resolver_factory_create_resolver(factory, &args); - GPR_ASSERT(resolver != NULL); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); - grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); -} - -static void test_fails(grpc_resolver_factory *factory, const char *string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri *uri = grpc_uri_parse(string, 0); - grpc_resolver_args args; - grpc_resolver *resolver; - gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, - factory->vtable->scheme); - GPR_ASSERT(uri); - memset(&args, 0, sizeof(args)); - args.uri = uri; - resolver = grpc_resolver_factory_create_resolver(factory, &args); - GPR_ASSERT(resolver == NULL); - grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); -} - -int main(int argc, char **argv) { - grpc_resolver_factory *dns; - grpc_test_init(argc, argv); - grpc_init(); - - dns = grpc_resolver_factory_lookup("dns"); - - test_succeeds(dns, "dns:10.2.1.1"); - test_succeeds(dns, "dns:10.2.1.1:1234"); - test_succeeds(dns, "ipv4:www.google.com"); - test_fails(dns, "ipv4://8.8.8.8/8.8.8.8:8888"); - - grpc_resolver_factory_unref(dns); - grpc_shutdown(); - - return 0; -} diff --git a/test/core/client_config/resolvers/sockaddr_resolver_test.c b/test/core/client_config/resolvers/sockaddr_resolver_test.c deleted file mode 100644 index b11546b6b1..0000000000 --- a/test/core/client_config/resolvers/sockaddr_resolver_test.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include - -#include - -#include "src/core/ext/client_config/resolver_registry.h" -#include "test/core/util/test_config.h" - -static void client_channel_factory_ref(grpc_client_channel_factory *scv) {} -static void client_channel_factory_unref(grpc_exec_ctx *exec_ctx, - grpc_client_channel_factory *scv) {} -static grpc_subchannel *client_channel_factory_create_subchannel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *factory, - grpc_subchannel_args *args) { - GPR_UNREACHABLE_CODE(return NULL); -} - -static grpc_channel *client_channel_factory_create_channel( - grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory, - const char *target, grpc_client_channel_type type, - grpc_channel_args *args) { - GPR_UNREACHABLE_CODE(return NULL); -} - -static const grpc_client_channel_factory_vtable sc_vtable = { - client_channel_factory_ref, client_channel_factory_unref, - client_channel_factory_create_subchannel, - client_channel_factory_create_channel}; - -static grpc_client_channel_factory cc_factory = {&sc_vtable}; - -static void test_succeeds(grpc_resolver_factory *factory, const char *string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri *uri = grpc_uri_parse(string, 0); - grpc_resolver_args args; - grpc_resolver *resolver; - gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, - factory->vtable->scheme); - GPR_ASSERT(uri); - memset(&args, 0, sizeof(args)); - args.uri = uri; - args.client_channel_factory = &cc_factory; - resolver = grpc_resolver_factory_create_resolver(factory, &args); - GPR_ASSERT(resolver != NULL); - GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); - grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); -} - -static void test_fails(grpc_resolver_factory *factory, const char *string) { - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_uri *uri = grpc_uri_parse(string, 0); - grpc_resolver_args args; - grpc_resolver *resolver; - gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, - factory->vtable->scheme); - GPR_ASSERT(uri); - memset(&args, 0, sizeof(args)); - args.uri = uri; - resolver = grpc_resolver_factory_create_resolver(factory, &args); - GPR_ASSERT(resolver == NULL); - grpc_uri_destroy(uri); - grpc_exec_ctx_finish(&exec_ctx); -} - -int main(int argc, char **argv) { - grpc_resolver_factory *ipv4, *ipv6; - grpc_test_init(argc, argv); - grpc_init(); - - ipv4 = grpc_resolver_factory_lookup("ipv4"); - ipv6 = grpc_resolver_factory_lookup("ipv6"); - - test_fails(ipv4, "ipv4:10.2.1.1"); - test_succeeds(ipv4, "ipv4:10.2.1.1:1234"); - test_succeeds(ipv4, "ipv4:10.2.1.1:1234,127.0.0.1:4321"); - test_fails(ipv4, "ipv4:10.2.1.1:123456"); - test_fails(ipv4, "ipv4:www.google.com"); - test_fails(ipv4, "ipv4:["); - test_fails(ipv4, "ipv4://8.8.8.8/8.8.8.8:8888"); - - test_fails(ipv6, "ipv6:["); - test_fails(ipv6, "ipv6:[::]"); - test_succeeds(ipv6, "ipv6:[::]:1234"); - test_fails(ipv6, "ipv6:[::]:123456"); - test_fails(ipv6, "ipv6:www.google.com"); - - grpc_resolver_factory_unref(ipv4); - grpc_resolver_factory_unref(ipv6); - grpc_shutdown(); - - return 0; -} diff --git a/test/core/client_config/set_initial_connect_string_test.c b/test/core/client_config/set_initial_connect_string_test.c deleted file mode 100644 index 1b51424f7e..0000000000 --- a/test/core/client_config/set_initial_connect_string_test.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ -#include - -#include -#include -#include -#include -#include -#include - -#include "src/core/ext/client_config/initial_connect_string.h" -#include "src/core/lib/iomgr/sockaddr.h" -#include "src/core/lib/security/credentials/fake/fake_credentials.h" -#include "src/core/lib/support/string.h" -#include "test/core/util/port.h" -#include "test/core/util/test_config.h" -#include "test/core/util/test_tcp_server.h" - -struct rpc_state { - char *target; - grpc_channel_credentials *creds; - grpc_completion_queue *cq; - grpc_channel *channel; - grpc_call *call; - grpc_op op; - gpr_slice_buffer incoming_buffer; - gpr_slice_buffer temp_incoming_buffer; - grpc_endpoint *tcp; - gpr_atm done_atm; -}; - -static const char *magic_connect_string = "magic initial string"; -static int server_port; -static struct rpc_state state; -static grpc_closure on_read; - -static void handle_read(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - GPR_ASSERT(error == GRPC_ERROR_NONE); - gpr_slice_buffer_move_into(&state.temp_incoming_buffer, - &state.incoming_buffer); - gpr_log(GPR_DEBUG, "got %" PRIuPTR " bytes, magic is %" PRIuPTR " bytes", - state.incoming_buffer.length, strlen(magic_connect_string)); - if (state.incoming_buffer.length > strlen(magic_connect_string)) { - gpr_atm_rel_store(&state.done_atm, 1); - grpc_endpoint_shutdown(exec_ctx, state.tcp); - grpc_endpoint_destroy(exec_ctx, state.tcp); - } else { - grpc_endpoint_read(exec_ctx, state.tcp, &state.temp_incoming_buffer, - &on_read); - } -} - -static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp, - grpc_pollset *accepting_pollset, - grpc_tcp_server_acceptor *acceptor) { - test_tcp_server *server = arg; - grpc_closure_init(&on_read, handle_read, NULL); - gpr_slice_buffer_init(&state.incoming_buffer); - gpr_slice_buffer_init(&state.temp_incoming_buffer); - state.tcp = tcp; - grpc_endpoint_add_to_pollset(exec_ctx, tcp, server->pollset); - grpc_endpoint_read(exec_ctx, tcp, &state.temp_incoming_buffer, &on_read); -} - -static void set_magic_initial_string(struct sockaddr **addr, size_t *addr_len, - gpr_slice *connect_string) { - GPR_ASSERT(addr); - GPR_ASSERT(addr_len); - *connect_string = gpr_slice_from_copied_string(magic_connect_string); -} - -static void reset_addr_and_set_magic_string(struct sockaddr **addr, - size_t *addr_len, - gpr_slice *connect_string) { - struct sockaddr_in target; - *connect_string = gpr_slice_from_copied_string(magic_connect_string); - gpr_free(*addr); - target.sin_family = AF_INET; - target.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - target.sin_port = htons((uint16_t)server_port); - *addr_len = sizeof(target); - *addr = (struct sockaddr *)gpr_malloc(sizeof(target)); - memcpy(*addr, &target, sizeof(target)); -} - -static gpr_timespec n_sec_deadline(int seconds) { - return gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_seconds(seconds, GPR_TIMESPAN)); -} - -static void start_rpc(int use_creds, int target_port) { - state.cq = grpc_completion_queue_create(NULL); - if (use_creds) { - state.creds = grpc_fake_transport_security_credentials_create(); - } else { - state.creds = NULL; - } - gpr_join_host_port(&state.target, "127.0.0.1", target_port); - if (use_creds) { - state.channel = - grpc_secure_channel_create(state.creds, state.target, NULL, NULL); - } else { - state.channel = grpc_insecure_channel_create(state.target, NULL, NULL); - } - state.call = grpc_channel_create_call( - state.channel, NULL, GRPC_PROPAGATE_DEFAULTS, state.cq, "/Service/Method", - "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); - memset(&state.op, 0, sizeof(state.op)); - state.op.op = GRPC_OP_SEND_INITIAL_METADATA; - state.op.data.send_initial_metadata.count = 0; - state.op.flags = 0; - state.op.reserved = NULL; - GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(state.call, &state.op, - (size_t)(1), NULL, NULL)); - grpc_completion_queue_next(state.cq, n_sec_deadline(5), NULL); -} - -static void cleanup_rpc(void) { - grpc_event ev; - gpr_slice_buffer_destroy(&state.incoming_buffer); - gpr_slice_buffer_destroy(&state.temp_incoming_buffer); - grpc_channel_credentials_unref(state.creds); - grpc_call_destroy(state.call); - grpc_completion_queue_shutdown(state.cq); - do { - ev = grpc_completion_queue_next(state.cq, n_sec_deadline(1), NULL); - } while (ev.type != GRPC_QUEUE_SHUTDOWN); - grpc_completion_queue_destroy(state.cq); - grpc_channel_destroy(state.channel); - gpr_free(state.target); -} - -typedef struct { - test_tcp_server *server; - gpr_event *signal_when_done; -} poll_args; - -static void actually_poll_server(void *arg) { - poll_args *pa = arg; - gpr_timespec deadline = n_sec_deadline(10); - while (true) { - bool done = gpr_atm_acq_load(&state.done_atm) != 0; - gpr_timespec time_left = - gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME)); - gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRId64 ".%09" PRId32, done, - time_left.tv_sec, time_left.tv_nsec); - if (done || gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) < 0) { - break; - } - test_tcp_server_poll(pa->server, 1); - } - gpr_event_set(pa->signal_when_done, (void *)1); - gpr_free(pa); -} - -static void poll_server_until_read_done(test_tcp_server *server, - gpr_event *signal_when_done) { - gpr_atm_rel_store(&state.done_atm, 0); - gpr_thd_id id; - poll_args *pa = gpr_malloc(sizeof(*pa)); - pa->server = server; - pa->signal_when_done = signal_when_done; - gpr_thd_new(&id, actually_poll_server, pa, NULL); -} - -static void match_initial_magic_string(gpr_slice_buffer *buffer) { - size_t i, j, cmp_length; - size_t magic_length = strlen(magic_connect_string); - GPR_ASSERT(buffer->length >= magic_length); - for (i = 0, j = 0; i < state.incoming_buffer.count && j < magic_length; i++) { - char *dump = - gpr_dump_slice(state.incoming_buffer.slices[i], GPR_DUMP_ASCII); - cmp_length = GPR_MIN(strlen(dump), magic_length - j); - GPR_ASSERT(strncmp(dump, magic_connect_string + j, cmp_length) == 0); - j += cmp_length; - gpr_free(dump); - } -} - -static void test_initial_string(test_tcp_server *server, int secure) { - gpr_event ev; - gpr_event_init(&ev); - grpc_test_set_initial_connect_string_function(set_magic_initial_string); - poll_server_until_read_done(server, &ev); - start_rpc(secure, server_port); - gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME)); - match_initial_magic_string(&state.incoming_buffer); - cleanup_rpc(); -} - -static void test_initial_string_with_redirect(test_tcp_server *server, - int secure) { - gpr_event ev; - gpr_event_init(&ev); - int another_port = grpc_pick_unused_port_or_die(); - grpc_test_set_initial_connect_string_function( - reset_addr_and_set_magic_string); - poll_server_until_read_done(server, &ev); - start_rpc(secure, another_port); - gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME)); - match_initial_magic_string(&state.incoming_buffer); - cleanup_rpc(); -} - -static void run_test(void (*test)(test_tcp_server *server, int secure), - int secure) { - test_tcp_server test_server; - server_port = grpc_pick_unused_port_or_die(); - test_tcp_server_init(&test_server, on_connect, &test_server); - test_tcp_server_start(&test_server, server_port); - test(&test_server, secure); - test_tcp_server_destroy(&test_server); -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - grpc_init(); - - run_test(test_initial_string, 0); - run_test(test_initial_string, 1); - run_test(test_initial_string_with_redirect, 0); - run_test(test_initial_string_with_redirect, 1); - - grpc_shutdown(); - return 0; -} diff --git a/test/core/client_config/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342 b/test/core/client_config/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342 deleted file mode 100644 index a85e7a8c21..0000000000 --- a/test/core/client_config/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342 +++ /dev/null @@ -1,2 +0,0 @@ -::nix::ii///ii/\a‡?=n;iI_!';&b.cii??nn!%i!*% -*; \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342 b/test/core/client_config/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342 deleted file mode 100644 index 597a6db294..0000000000 --- a/test/core/client_config/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342 +++ /dev/null @@ -1 +0,0 @@ -i \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11 b/test/core/client_config/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11 deleted file mode 100644 index d56b8fc6c8..0000000000 --- a/test/core/client_config/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11 +++ /dev/null @@ -1 +0,0 @@ -:iiiÐ?+n!ij \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f b/test/core/client_config/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f deleted file mode 100644 index 5b913f1bb8..0000000000 --- a/test/core/client_config/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f +++ /dev/null @@ -1,2 +0,0 @@ -:ipip~6:‡i:::1 -v:miP/ii:::/iu?n?n)i!= \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118 b/test/core/client_config/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118 deleted file mode 100644 index 76f157cda5..0000000000 --- a/test/core/client_config/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118 +++ /dev/null @@ -1 +0,0 @@ -i:i:‡ii:i?nip~??ni=niI&6.u/n_!'p~ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc b/test/core/client_config/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc deleted file mode 100644 index 3936e8964c..0000000000 --- a/test/core/client_config/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc +++ /dev/null @@ -1 +0,0 @@ -:‡i?=niI_!';ñ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f b/test/core/client_config/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f deleted file mode 100644 index a94c4cf58d..0000000000 --- a/test/core/client_config/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f +++ /dev/null @@ -1,2 +0,0 @@ -~ipip~6::1 -v:Ð:1 diff --git a/test/core/client_config/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 b/test/core/client_config/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 deleted file mode 100644 index 875ac2a4f9..0000000000 --- a/test/core/client_config/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80 +++ /dev/null @@ -1 +0,0 @@ -:il0P/8?n!$i: \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971 b/test/core/client_config/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971 deleted file mode 100644 index 59469af528..0000000000 --- a/test/core/client_config/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971 +++ /dev/null @@ -1,3 +0,0 @@ -iiP*v:::pip~6:::0 -v:::11 - diff --git a/test/core/client_config/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc b/test/core/client_config/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc deleted file mode 100644 index 2f902351bd..0000000000 --- a/test/core/client_config/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc +++ /dev/null @@ -1 +0,0 @@ -:ii/i?n!%i* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1 b/test/core/client_config/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1 deleted file mode 100644 index 4bdc3f60c0..0000000000 --- a/test/core/client_config/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1 +++ /dev/null @@ -1 +0,0 @@ -uni::.i?n(!ipR6/ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf b/test/core/client_config/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf deleted file mode 100644 index fb7665d0cc..0000000000 --- a/test/core/client_config/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf +++ /dev/null @@ -1,2 +0,0 @@ -:/i?n!ipv6:./::abc.* - diff --git a/test/core/client_config/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce b/test/core/client_config/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce deleted file mode 100644 index 6c1e22fa32..0000000000 --- a/test/core/client_config/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce +++ /dev/null @@ -1 +0,0 @@ -unix://ii:#v6i?n! \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327 b/test/core/client_config/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327 deleted file mode 100644 index 694d51dc9a..0000000000 --- a/test/core/client_config/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327 +++ /dev/null @@ -1 +0,0 @@ -uni:/i:i:‡i:i:‡i??ni=niIi??ni=niI__!!i?n!i'p'pR2p~~ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c b/test/core/client_config/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c deleted file mode 100644 index af80f07d19..0000000000 --- a/test/core/client_config/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c +++ /dev/null @@ -1 +0,0 @@ -i:i:‡i??ni=niI_!'p~ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc b/test/core/client_config/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc deleted file mode 100644 index 725b2086c5..0000000000 --- a/test/core/client_config/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc +++ /dev/null @@ -1,4 +0,0 @@ -i:i?nip~&2./:::abipip~6c.* - -::1 -v:Ð:1 diff --git a/test/core/client_config/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c b/test/core/client_config/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c deleted file mode 100644 index 7f0f2ea6ea..0000000000 --- a/test/core/client_config/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c +++ /dev/null @@ -1 +0,0 @@ -:‡i?=niI_!';; \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1 b/test/core/client_config/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1 deleted file mode 100644 index 23d52e19a8..0000000000 --- a/test/core/client_config/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1 +++ /dev/null @@ -1 +0,0 @@ -:iiP/i?n!'i* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab b/test/core/client_config/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab deleted file mode 100644 index f975f97059..0000000000 --- a/test/core/client_config/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab +++ /dev/null @@ -1 +0,0 @@ -i:i?nip~&6.u/n \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822 b/test/core/client_config/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822 deleted file mode 100644 index d5fb7ba274..0000000000 --- a/test/core/client_config/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822 +++ /dev/null @@ -1,2 +0,0 @@ -:unix://ii//a.b.ci?n!% -* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb b/test/core/client_config/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb deleted file mode 100644 index 1860e1c5b4..0000000000 --- a/test/core/client_config/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb +++ /dev/null @@ -1 +0,0 @@ -:‡i?P=niIii-i?%n'!%*i= \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8 b/test/core/client_config/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8 deleted file mode 100644 index 1dc4931ac6..0000000000 --- a/test/core/client_config/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8 +++ /dev/null @@ -1,4 +0,0 @@ -:i?n!ip~f2:./::abipip~6c.* - -::1 -v:Ð:1 diff --git a/test/core/client_config/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a b/test/core/client_config/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a deleted file mode 100644 index 7b9532914e..0000000000 --- a/test/core/client_config/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a +++ /dev/null @@ -1 +0,0 @@ -:‡i?=niI!';ñ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb b/test/core/client_config/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb deleted file mode 100644 index 4eaca39265..0000000000 --- a/test/core/client_config/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb +++ /dev/null @@ -1 +0,0 @@ -unix://ii:pv6i?n! \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58 b/test/core/client_config/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58 deleted file mode 100644 index fe908d213a..0000000000 --- a/test/core/client_config/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58 +++ /dev/null @@ -1 +0,0 @@ -uni::.ilP:%:%i:i‡i:‡i?=nii?n(!ipRI_&/.i;;!?=ii/?n#lniiI_!*Kii!/?ni* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6 b/test/core/client_config/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6 deleted file mode 100644 index 57cbd72dbc..0000000000 --- a/test/core/client_config/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6 +++ /dev/null @@ -1 +0,0 @@ -uni::/i?n!ipR6/ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1 b/test/core/client_config/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1 deleted file mode 100644 index e13cf5a8e6..0000000000 --- a/test/core/client_config/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1 +++ /dev/null @@ -1,2 +0,0 @@ -ipip~6:::1 -v:::1 diff --git a/test/core/client_config/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb b/test/core/client_config/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb deleted file mode 100644 index 0e7f44caf2..0000000000 --- a/test/core/client_config/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb +++ /dev/null @@ -1 +0,0 @@ -i:i:‡i:i:‡i??ni=niIi??ni=niI__!!'p'p~~ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d b/test/core/client_config/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d deleted file mode 100644 index 679f13e307..0000000000 --- a/test/core/client_config/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d +++ /dev/null @@ -1,2 +0,0 @@ -unix:///a/:.:ii/i?nc!% -i* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266 b/test/core/client_config/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266 deleted file mode 100644 index 58ecc7e2af..0000000000 --- a/test/core/client_config/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266 +++ /dev/null @@ -1 +0,0 @@ -ip*v:::1 diff --git a/test/core/client_config/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb b/test/core/client_config/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb deleted file mode 100644 index ffd807b39e..0000000000 --- a/test/core/client_config/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb +++ /dev/null @@ -1 +0,0 @@ -ilP:%i:‡i?=niI_.i;;!ii/?nni*! \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4 b/test/core/client_config/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4 deleted file mode 100644 index 8ad79f9eb9..0000000000 --- a/test/core/client_config/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4 +++ /dev/null @@ -1 +0,0 @@ -:‡i?P-niI%'i= \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb b/test/core/client_config/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb deleted file mode 100644 index efb392b7d9..0000000000 --- a/test/core/client_config/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb +++ /dev/null @@ -1,2 +0,0 @@ -:/i/n!ipv6:::/a.b.c1 - diff --git a/test/core/client_config/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8 b/test/core/client_config/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8 deleted file mode 100644 index 7155222547..0000000000 --- a/test/core/client_config/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8 +++ /dev/null @@ -1 +0,0 @@ -ilP.i;?n!#i!; \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b b/test/core/client_config/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b deleted file mode 100644 index 4061e02189..0000000000 --- a/test/core/client_config/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b +++ /dev/null @@ -1 +0,0 @@ -unix::/i?n!ipv6/ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 b/test/core/client_config/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 deleted file mode 100644 index facb11c5ed..0000000000 --- a/test/core/client_config/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6 +++ /dev/null @@ -1 +0,0 @@ -:%i:‡i?=niI_!ii/?ni*! \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de b/test/core/client_config/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de deleted file mode 100644 index 736e63e7e7..0000000000 --- a/test/core/client_config/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de +++ /dev/null @@ -1 +0,0 @@ -:¢ilP/i;n!#i: \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d b/test/core/client_config/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d deleted file mode 100644 index dff2f8920d..0000000000 --- a/test/core/client_config/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d +++ /dev/null @@ -1 +0,0 @@ -u+ni::/i?n!ipR3/ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38 b/test/core/client_config/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38 deleted file mode 100644 index 13a115481d..0000000000 --- a/test/core/client_config/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38 +++ /dev/null @@ -1 +0,0 @@ -uni::pi:miP/?ni.!(Ri?)8/n!'i* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/aba1472880406a318ce207ee79815b7acf087757 b/test/core/client_config/uri_corpus/aba1472880406a318ce207ee79815b7acf087757 deleted file mode 100644 index b7e7e970f8..0000000000 --- a/test/core/client_config/uri_corpus/aba1472880406a318ce207ee79815b7acf087757 +++ /dev/null @@ -1 +0,0 @@ -:iI/i?n!%š* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 b/test/core/client_config/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 deleted file mode 100644 index fe019fc409..0000000000 --- a/test/core/client_config/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2 +++ /dev/null @@ -1 +0,0 @@ -uni::.i!in:/i/n!ipv6ž:?(pR;::/a.2b \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd b/test/core/client_config/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd deleted file mode 100644 index 6e12167b52..0000000000 --- a/test/core/client_config/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd +++ /dev/null @@ -1 +0,0 @@ -:ii/iilP.i;?n?n!#i!;!%* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4 b/test/core/client_config/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4 deleted file mode 100644 index 119b0808c9..0000000000 --- a/test/core/client_config/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4 +++ /dev/null @@ -1 +0,0 @@ -:%i:i‡?=#liI_!Kii/?ni* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807 b/test/core/client_config/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807 deleted file mode 100644 index 01db5d8aa4..0000000000 --- a/test/core/client_config/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807 +++ /dev/null @@ -1,2 +0,0 @@ -::unix://ii//a‡?=niI_!';.b.ci?n!% -*; \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d b/test/core/client_config/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d deleted file mode 100644 index 2ccb535449..0000000000 --- a/test/core/client_config/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d +++ /dev/null @@ -1 +0,0 @@ -uni::.i?n(!ipR&/ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9 b/test/core/client_config/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9 deleted file mode 100644 index f3c0404be7..0000000000 --- a/test/core/client_config/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9 +++ /dev/null @@ -1 +0,0 @@ -::nix::ii///ii/\a:‡?=n;iI_!';&b.ciii \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245 b/test/core/client_config/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245 deleted file mode 100644 index b5655220d7..0000000000 --- a/test/core/client_config/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245 +++ /dev/null @@ -1 +0,0 @@ -:‡i?P-niI!'iñ \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c b/test/core/client_config/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c deleted file mode 100644 index a7656724f5..0000000000 --- a/test/core/client_config/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c +++ /dev/null @@ -1 +0,0 @@ -unix://ipv6::: \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca b/test/core/client_config/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca deleted file mode 100644 index d658fb8ee0..0000000000 --- a/test/core/client_config/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca +++ /dev/null @@ -1 +0,0 @@ -:ilP/i?n!#i: \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a b/test/core/client_config/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a deleted file mode 100644 index 6d37b5fd45..0000000000 --- a/test/core/client_config/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a +++ /dev/null @@ -1 +0,0 @@ -:ilP/i?n,!#i: \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/dns.txt b/test/core/client_config/uri_corpus/dns.txt deleted file mode 100644 index 577e1054e4..0000000000 --- a/test/core/client_config/uri_corpus/dns.txt +++ /dev/null @@ -1 +0,0 @@ -dns:10.2.1.1 diff --git a/test/core/client_config/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd b/test/core/client_config/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd deleted file mode 100644 index 497bfd37ee..0000000000 --- a/test/core/client_config/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd +++ /dev/null @@ -1 +0,0 @@ -ilP:%:%i:i‡i:‡i?=niI_.i;;!?=ii/?n#lniiI_!*Kii!/?ni* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71 b/test/core/client_config/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71 deleted file mode 100644 index 52f5a2382a..0000000000 --- a/test/core/client_config/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71 +++ /dev/null @@ -1,4 +0,0 @@ -i:i?n!ip~f2.:/::abipip~6c.* - -::1 -v:Ð:1 diff --git a/test/core/client_config/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee b/test/core/client_config/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee deleted file mode 100644 index c3c93fed6a..0000000000 --- a/test/core/client_config/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee +++ /dev/null @@ -1 +0,0 @@ -ii-i?n!%* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2 b/test/core/client_config/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2 deleted file mode 100644 index 45065e2f00..0000000000 --- a/test/core/client_config/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2 +++ /dev/null @@ -1 +0,0 @@ -:ii/i?n!%* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 b/test/core/client_config/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 deleted file mode 100644 index 02151c8b6a..0000000000 --- a/test/core/client_config/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3 +++ /dev/null @@ -1,2 +0,0 @@ -:ipip~6:::1 -vii/:::iunix:?n/1/ipv6!% \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67 b/test/core/client_config/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67 deleted file mode 100644 index 8034e133d7..0000000000 --- a/test/core/client_config/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67 +++ /dev/null @@ -1 +0,0 @@ -:iiP/i?n!i* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/f97598cff03306af3c70400608fec47268b5075d b/test/core/client_config/uri_corpus/f97598cff03306af3c70400608fec47268b5075d deleted file mode 100644 index 240946dbaa..0000000000 --- a/test/core/client_config/uri_corpus/f97598cff03306af3c70400608fec47268b5075d +++ /dev/null @@ -1,2 +0,0 @@ -unix://ipv6:::/a.b.c1 - diff --git a/test/core/client_config/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101 b/test/core/client_config/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101 deleted file mode 100644 index d089a59346..0000000000 --- a/test/core/client_config/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101 +++ /dev/null @@ -1 +0,0 @@ -:ilP.i;?n!#i; \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4 b/test/core/client_config/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4 deleted file mode 100644 index 66eefbcc14..0000000000 --- a/test/core/client_config/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4 +++ /dev/null @@ -1 +0,0 @@ -:miP/i?)n!'i* \ No newline at end of file diff --git a/test/core/client_config/uri_corpus/ipv4.txt b/test/core/client_config/uri_corpus/ipv4.txt deleted file mode 100644 index fe29486b6e..0000000000 --- a/test/core/client_config/uri_corpus/ipv4.txt +++ /dev/null @@ -1 +0,0 @@ -ipv4:10.2.1.1 diff --git a/test/core/client_config/uri_corpus/ipv6.txt b/test/core/client_config/uri_corpus/ipv6.txt deleted file mode 100644 index 7b6932be00..0000000000 --- a/test/core/client_config/uri_corpus/ipv6.txt +++ /dev/null @@ -1 +0,0 @@ -ipv6:::1 diff --git a/test/core/client_config/uri_corpus/unix.txt b/test/core/client_config/uri_corpus/unix.txt deleted file mode 100644 index 7a0997ec9a..0000000000 --- a/test/core/client_config/uri_corpus/unix.txt +++ /dev/null @@ -1 +0,0 @@ -unix:///a.b.c diff --git a/test/core/client_config/uri_fuzzer_test.c b/test/core/client_config/uri_fuzzer_test.c deleted file mode 100644 index f297140559..0000000000 --- a/test/core/client_config/uri_fuzzer_test.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include -#include -#include - -#include - -#include "src/core/ext/client_config/uri_parser.h" - -bool squelch = true; -bool leak_check = true; - -int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - char *s = gpr_malloc(size + 1); - memcpy(s, data, size); - s[size] = 0; - - grpc_uri *x; - if ((x = grpc_uri_parse(s, 1))) { - grpc_uri_destroy(x); - } - gpr_free(s); - return 0; -} diff --git a/test/core/client_config/uri_parser_test.c b/test/core/client_config/uri_parser_test.c deleted file mode 100644 index 323e8b6f70..0000000000 --- a/test/core/client_config/uri_parser_test.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "src/core/ext/client_config/uri_parser.h" - -#include - -#include - -#include "test/core/util/test_config.h" - -static void test_succeeds(const char *uri_text, const char *scheme, - const char *authority, const char *path, - const char *query, const char *fragment) { - grpc_uri *uri = grpc_uri_parse(uri_text, 0); - GPR_ASSERT(uri); - GPR_ASSERT(0 == strcmp(scheme, uri->scheme)); - GPR_ASSERT(0 == strcmp(authority, uri->authority)); - GPR_ASSERT(0 == strcmp(path, uri->path)); - GPR_ASSERT(0 == strcmp(query, uri->query)); - GPR_ASSERT(0 == strcmp(fragment, uri->fragment)); - grpc_uri_destroy(uri); -} - -static void test_fails(const char *uri_text) { - GPR_ASSERT(NULL == grpc_uri_parse(uri_text, 0)); -} - -static void test_query_parts() { - { - const char *uri_text = "http://foo/path?a&b=B&c=&#frag"; - grpc_uri *uri = grpc_uri_parse(uri_text, 0); - GPR_ASSERT(uri); - - GPR_ASSERT(0 == strcmp("http", uri->scheme)); - GPR_ASSERT(0 == strcmp("foo", uri->authority)); - GPR_ASSERT(0 == strcmp("/path", uri->path)); - GPR_ASSERT(0 == strcmp("a&b=B&c=&", uri->query)); - GPR_ASSERT(4 == uri->num_query_parts); - - GPR_ASSERT(0 == strcmp("a", uri->query_parts[0])); - GPR_ASSERT(NULL == uri->query_parts_values[0]); - - GPR_ASSERT(0 == strcmp("b", uri->query_parts[1])); - GPR_ASSERT(0 == strcmp("B", uri->query_parts_values[1])); - - GPR_ASSERT(0 == strcmp("c", uri->query_parts[2])); - GPR_ASSERT(0 == strcmp("", uri->query_parts_values[2])); - - GPR_ASSERT(0 == strcmp("", uri->query_parts[3])); - GPR_ASSERT(NULL == uri->query_parts_values[3]); - - GPR_ASSERT(NULL == grpc_uri_get_query_arg(uri, "a")); - GPR_ASSERT(0 == strcmp("B", grpc_uri_get_query_arg(uri, "b"))); - GPR_ASSERT(0 == strcmp("", grpc_uri_get_query_arg(uri, "c"))); - GPR_ASSERT(NULL == grpc_uri_get_query_arg(uri, "")); - - GPR_ASSERT(0 == strcmp("frag", uri->fragment)); - grpc_uri_destroy(uri); - } - { - /* test the current behavior of multiple query part values */ - const char *uri_text = "http://auth/path?foo=bar=baz&foobar=="; - grpc_uri *uri = grpc_uri_parse(uri_text, 0); - GPR_ASSERT(uri); - - GPR_ASSERT(0 == strcmp("http", uri->scheme)); - GPR_ASSERT(0 == strcmp("auth", uri->authority)); - GPR_ASSERT(0 == strcmp("/path", uri->path)); - GPR_ASSERT(0 == strcmp("foo=bar=baz&foobar==", uri->query)); - GPR_ASSERT(2 == uri->num_query_parts); - - GPR_ASSERT(0 == strcmp("bar", grpc_uri_get_query_arg(uri, "foo"))); - GPR_ASSERT(0 == strcmp("", grpc_uri_get_query_arg(uri, "foobar"))); - - grpc_uri_destroy(uri); - } - { - /* empty query */ - const char *uri_text = "http://foo/path"; - grpc_uri *uri = grpc_uri_parse(uri_text, 0); - GPR_ASSERT(uri); - - GPR_ASSERT(0 == strcmp("http", uri->scheme)); - GPR_ASSERT(0 == strcmp("foo", uri->authority)); - GPR_ASSERT(0 == strcmp("/path", uri->path)); - GPR_ASSERT(0 == strcmp("", uri->query)); - GPR_ASSERT(0 == uri->num_query_parts); - GPR_ASSERT(NULL == uri->query_parts); - GPR_ASSERT(NULL == uri->query_parts_values); - GPR_ASSERT(0 == strcmp("", uri->fragment)); - grpc_uri_destroy(uri); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - test_succeeds("http://www.google.com", "http", "www.google.com", "", "", ""); - test_succeeds("dns:///foo", "dns", "", "/foo", "", ""); - test_succeeds("http://www.google.com:90", "http", "www.google.com:90", "", "", - ""); - test_succeeds("a192.4-df:foo.coom", "a192.4-df", "", "foo.coom", "", ""); - test_succeeds("a+b:foo.coom", "a+b", "", "foo.coom", "", ""); - test_succeeds("zookeeper://127.0.0.1:2181/foo/bar", "zookeeper", - "127.0.0.1:2181", "/foo/bar", "", ""); - test_succeeds("http://www.google.com?yay-i'm-using-queries", "http", - "www.google.com", "", "yay-i'm-using-queries", ""); - test_succeeds("dns:foo.com#fragment-all-the-things", "dns", "", "foo.com", "", - "fragment-all-the-things"); - test_succeeds("http:?legit", "http", "", "", "legit", ""); - test_succeeds("unix:#this-is-ok-too", "unix", "", "", "", "this-is-ok-too"); - test_succeeds("http:?legit#twice", "http", "", "", "legit", "twice"); - test_succeeds("http://foo?bar#lol?", "http", "foo", "", "bar", "lol?"); - test_succeeds("http://foo?bar#lol?/", "http", "foo", "", "bar", "lol?/"); - - test_fails("xyz"); - test_fails("http:?dangling-pct-%0"); - test_fails("http://foo?[bar]"); - test_fails("http://foo?x[bar]"); - test_fails("http://foo?bar#lol#"); - - test_query_parts(); - return 0; -} diff --git a/test/core/end2end/fixtures/h2_census.c b/test/core/end2end/fixtures/h2_census.c index e46b39e476..ffeac652c9 100644 --- a/test/core/end2end/fixtures/h2_census.c +++ b/test/core/end2end/fixtures/h2_census.c @@ -41,7 +41,7 @@ #include #include #include -#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/connected_channel.h" diff --git a/test/core/end2end/fixtures/h2_compress.c b/test/core/end2end/fixtures/h2_compress.c index 8f9b7c9cd9..4ffbda62ca 100644 --- a/test/core/end2end/fixtures/h2_compress.c +++ b/test/core/end2end/fixtures/h2_compress.c @@ -41,7 +41,7 @@ #include #include #include -#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/connected_channel.h" diff --git a/test/core/end2end/fixtures/h2_full+pipe.c b/test/core/end2end/fixtures/h2_full+pipe.c index e7dfc561a1..ba3e5ba521 100644 --- a/test/core/end2end/fixtures/h2_full+pipe.c +++ b/test/core/end2end/fixtures/h2_full+pipe.c @@ -41,7 +41,7 @@ #include #include #include -#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/http_server_filter.h" diff --git a/test/core/end2end/fixtures/h2_full+trace.c b/test/core/end2end/fixtures/h2_full+trace.c index c4dc5b9bc1..34aa802d33 100644 --- a/test/core/end2end/fixtures/h2_full+trace.c +++ b/test/core/end2end/fixtures/h2_full+trace.c @@ -41,7 +41,7 @@ #include #include #include -#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/http_server_filter.h" diff --git a/test/core/end2end/fixtures/h2_full.c b/test/core/end2end/fixtures/h2_full.c index 4a2f17eb91..dee2493cab 100644 --- a/test/core/end2end/fixtures/h2_full.c +++ b/test/core/end2end/fixtures/h2_full.c @@ -41,7 +41,7 @@ #include #include #include -#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/http_server_filter.h" diff --git a/test/core/end2end/fixtures/h2_load_reporting.c b/test/core/end2end/fixtures/h2_load_reporting.c index f6d3923db9..3b70da03b0 100644 --- a/test/core/end2end/fixtures/h2_load_reporting.c +++ b/test/core/end2end/fixtures/h2_load_reporting.c @@ -41,7 +41,7 @@ #include #include #include -#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/load_reporting/load_reporting.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/channel_args.h" diff --git a/test/core/end2end/fixtures/h2_proxy.c b/test/core/end2end/fixtures/h2_proxy.c index c7b99863f0..e1a5f6b7f1 100644 --- a/test/core/end2end/fixtures/h2_proxy.c +++ b/test/core/end2end/fixtures/h2_proxy.c @@ -41,7 +41,7 @@ #include #include #include -#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/http_server_filter.h" diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.c b/test/core/end2end/fixtures/h2_sockpair+trace.c index b8a5257ab2..659f5a7262 100644 --- a/test/core/end2end/fixtures/h2_sockpair+trace.c +++ b/test/core/end2end/fixtures/h2_sockpair+trace.c @@ -40,7 +40,7 @@ #include #include #include -#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/compress_filter.h" #include "src/core/lib/channel/connected_channel.h" diff --git a/test/core/end2end/fixtures/h2_sockpair.c b/test/core/end2end/fixtures/h2_sockpair.c index a57990d6e7..c591c274b7 100644 --- a/test/core/end2end/fixtures/h2_sockpair.c +++ b/test/core/end2end/fixtures/h2_sockpair.c @@ -40,7 +40,7 @@ #include #include #include -#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/compress_filter.h" #include "src/core/lib/channel/connected_channel.h" diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.c b/test/core/end2end/fixtures/h2_sockpair_1byte.c index 50aac8045a..a4560bb150 100644 --- a/test/core/end2end/fixtures/h2_sockpair_1byte.c +++ b/test/core/end2end/fixtures/h2_sockpair_1byte.c @@ -40,7 +40,7 @@ #include #include #include -#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/compress_filter.h" #include "src/core/lib/channel/connected_channel.h" diff --git a/test/core/end2end/fixtures/h2_uds.c b/test/core/end2end/fixtures/h2_uds.c index cffbeaf045..4d5b1a3117 100644 --- a/test/core/end2end/fixtures/h2_uds.c +++ b/test/core/end2end/fixtures/h2_uds.c @@ -44,7 +44,7 @@ #include #include #include -#include "src/core/ext/client_config/client_channel.h" +#include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/http_server_filter.h" diff --git a/test/core/surface/channel_create_test.c b/test/core/surface/channel_create_test.c index 450cc37233..eada82d949 100644 --- a/test/core/surface/channel_create_test.c +++ b/test/core/surface/channel_create_test.c @@ -33,7 +33,7 @@ #include #include -#include "src/core/ext/client_config/resolver_registry.h" +#include "src/core/ext/client_channel/resolver_registry.h" #include "test/core/util/test_config.h" void test_unknown_scheme_target(void) { diff --git a/test/core/surface/secure_channel_create_test.c b/test/core/surface/secure_channel_create_test.c index b952503167..42fca8cff7 100644 --- a/test/core/surface/secure_channel_create_test.c +++ b/test/core/surface/secure_channel_create_test.c @@ -36,7 +36,7 @@ #include #include #include -#include "src/core/ext/client_config/resolver_registry.h" +#include "src/core/ext/client_channel/resolver_registry.h" #include "src/core/lib/security/credentials/fake/fake_credentials.h" #include "src/core/lib/security/transport/security_connector.h" #include "src/core/lib/surface/channel.h" diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 02590db421..6046e8b6ff 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -915,21 +915,21 @@ src/core/lib/tsi/ssl_transport_security.h \ src/core/lib/tsi/ssl_types.h \ src/core/lib/tsi/transport_security.h \ src/core/lib/tsi/transport_security_interface.h \ -src/core/ext/client_config/client_channel.h \ -src/core/ext/client_config/client_channel_factory.h \ -src/core/ext/client_config/connector.h \ -src/core/ext/client_config/initial_connect_string.h \ -src/core/ext/client_config/lb_policy.h \ -src/core/ext/client_config/lb_policy_factory.h \ -src/core/ext/client_config/lb_policy_registry.h \ -src/core/ext/client_config/parse_address.h \ -src/core/ext/client_config/resolver.h \ -src/core/ext/client_config/resolver_factory.h \ -src/core/ext/client_config/resolver_registry.h \ -src/core/ext/client_config/resolver_result.h \ -src/core/ext/client_config/subchannel.h \ -src/core/ext/client_config/subchannel_index.h \ -src/core/ext/client_config/uri_parser.h \ +src/core/ext/client_channel/client_channel.h \ +src/core/ext/client_channel/client_channel_factory.h \ +src/core/ext/client_channel/connector.h \ +src/core/ext/client_channel/initial_connect_string.h \ +src/core/ext/client_channel/lb_policy.h \ +src/core/ext/client_channel/lb_policy_factory.h \ +src/core/ext/client_channel/lb_policy_registry.h \ +src/core/ext/client_channel/parse_address.h \ +src/core/ext/client_channel/resolver.h \ +src/core/ext/client_channel/resolver_factory.h \ +src/core/ext/client_channel/resolver_registry.h \ +src/core/ext/client_channel/resolver_result.h \ +src/core/ext/client_channel/subchannel.h \ +src/core/ext/client_channel/subchannel_index.h \ +src/core/ext/client_channel/uri_parser.h \ src/core/ext/lb_policy/grpclb/grpclb.h \ src/core/ext/lb_policy/grpclb/load_balancer_api.h \ src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h \ @@ -1091,24 +1091,24 @@ src/core/lib/tsi/fake_transport_security.c \ src/core/lib/tsi/ssl_transport_security.c \ src/core/lib/tsi/transport_security.c \ src/core/ext/transport/chttp2/client/secure/secure_channel_create.c \ -src/core/ext/client_config/channel_connectivity.c \ -src/core/ext/client_config/client_channel.c \ -src/core/ext/client_config/client_channel_factory.c \ -src/core/ext/client_config/client_config_plugin.c \ -src/core/ext/client_config/connector.c \ -src/core/ext/client_config/default_initial_connect_string.c \ -src/core/ext/client_config/initial_connect_string.c \ -src/core/ext/client_config/lb_policy.c \ -src/core/ext/client_config/lb_policy_factory.c \ -src/core/ext/client_config/lb_policy_registry.c \ -src/core/ext/client_config/parse_address.c \ -src/core/ext/client_config/resolver.c \ -src/core/ext/client_config/resolver_factory.c \ -src/core/ext/client_config/resolver_registry.c \ -src/core/ext/client_config/resolver_result.c \ -src/core/ext/client_config/subchannel.c \ -src/core/ext/client_config/subchannel_index.c \ -src/core/ext/client_config/uri_parser.c \ +src/core/ext/client_channel/channel_connectivity.c \ +src/core/ext/client_channel/client_channel.c \ +src/core/ext/client_channel/client_channel_factory.c \ +src/core/ext/client_channel/client_channel_plugin.c \ +src/core/ext/client_channel/connector.c \ +src/core/ext/client_channel/default_initial_connect_string.c \ +src/core/ext/client_channel/initial_connect_string.c \ +src/core/ext/client_channel/lb_policy.c \ +src/core/ext/client_channel/lb_policy_factory.c \ +src/core/ext/client_channel/lb_policy_registry.c \ +src/core/ext/client_channel/parse_address.c \ +src/core/ext/client_channel/resolver.c \ +src/core/ext/client_channel/resolver_factory.c \ +src/core/ext/client_channel/resolver_registry.c \ +src/core/ext/client_channel/resolver_result.c \ +src/core/ext/client_channel/subchannel.c \ +src/core/ext/client_channel/subchannel_index.c \ +src/core/ext/client_channel/uri_parser.c \ src/core/ext/transport/chttp2/server/insecure/server_chttp2.c \ src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c \ src/core/ext/transport/chttp2/client/insecure/channel_create.c \ diff --git a/tools/fuzzer/runners/uri_fuzzer_test.sh b/tools/fuzzer/runners/uri_fuzzer_test.sh index 84d63bf414..316f6c2599 100644 --- a/tools/fuzzer/runners/uri_fuzzer_test.sh +++ b/tools/fuzzer/runners/uri_fuzzer_test.sh @@ -42,4 +42,4 @@ then flags="-use_traces=1 $flags" fi -bins/$config/uri_fuzzer_test $flags fuzzer_output test/core/client_config/uri_corpus +bins/$config/uri_fuzzer_test $flags fuzzer_output test/core/client_channel/uri_corpus diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index db84f21968..619de5b318 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -295,7 +295,7 @@ "language": "c", "name": "dns_resolver_connectivity_test", "src": [ - "test/core/client_config/resolvers/dns_resolver_connectivity_test.c" + "test/core/client_channel/resolvers/dns_resolver_connectivity_test.c" ], "third_party": false, "type": "target" @@ -311,7 +311,7 @@ "language": "c", "name": "dns_resolver_test", "src": [ - "test/core/client_config/resolvers/dns_resolver_test.c" + "test/core/client_channel/resolvers/dns_resolver_test.c" ], "third_party": false, "type": "target" @@ -1327,7 +1327,7 @@ "language": "c", "name": "lb_policies_test", "src": [ - "test/core/client_config/lb_policies_test.c" + "test/core/client_channel/lb_policies_test.c" ], "third_party": false, "type": "target" @@ -1630,7 +1630,7 @@ "language": "c", "name": "set_initial_connect_string_test", "src": [ - "test/core/client_config/set_initial_connect_string_test.c" + "test/core/client_channel/set_initial_connect_string_test.c" ], "third_party": false, "type": "target" @@ -1646,7 +1646,7 @@ "language": "c", "name": "sockaddr_resolver_test", "src": [ - "test/core/client_config/resolvers/sockaddr_resolver_test.c" + "test/core/client_channel/resolvers/sockaddr_resolver_test.c" ], "third_party": false, "type": "target" @@ -1870,7 +1870,7 @@ "language": "c", "name": "uri_fuzzer_test", "src": [ - "test/core/client_config/uri_fuzzer_test.c" + "test/core/client_channel/uri_fuzzer_test.c" ], "third_party": false, "type": "target" @@ -1886,7 +1886,7 @@ "language": "c", "name": "uri_parser_test", "src": [ - "test/core/client_config/uri_parser_test.c" + "test/core/client_channel/uri_parser_test.c" ], "third_party": false, "type": "target" @@ -4278,7 +4278,7 @@ "language": "c", "name": "uri_fuzzer_test_one_entry", "src": [ - "test/core/client_config/uri_fuzzer_test.c", + "test/core/client_channel/uri_fuzzer_test.c", "test/core/util/one_corpus_entry_fuzzer.c" ], "third_party": false, @@ -6159,58 +6159,58 @@ "grpc_base" ], "headers": [ - "src/core/ext/client_config/client_channel.h", - "src/core/ext/client_config/client_channel_factory.h", - "src/core/ext/client_config/connector.h", - "src/core/ext/client_config/initial_connect_string.h", - "src/core/ext/client_config/lb_policy.h", - "src/core/ext/client_config/lb_policy_factory.h", - "src/core/ext/client_config/lb_policy_registry.h", - "src/core/ext/client_config/parse_address.h", - "src/core/ext/client_config/resolver.h", - "src/core/ext/client_config/resolver_factory.h", - "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.h", - "src/core/ext/client_config/subchannel.h", - "src/core/ext/client_config/subchannel_index.h", - "src/core/ext/client_config/uri_parser.h" - ], - "language": "c", - "name": "grpc_client_config", - "src": [ - "src/core/ext/client_config/channel_connectivity.c", - "src/core/ext/client_config/client_channel.c", - "src/core/ext/client_config/client_channel.h", - "src/core/ext/client_config/client_channel_factory.c", - "src/core/ext/client_config/client_channel_factory.h", - "src/core/ext/client_config/client_config_plugin.c", - "src/core/ext/client_config/connector.c", - "src/core/ext/client_config/connector.h", - "src/core/ext/client_config/default_initial_connect_string.c", - "src/core/ext/client_config/initial_connect_string.c", - "src/core/ext/client_config/initial_connect_string.h", - "src/core/ext/client_config/lb_policy.c", - "src/core/ext/client_config/lb_policy.h", - "src/core/ext/client_config/lb_policy_factory.c", - "src/core/ext/client_config/lb_policy_factory.h", - "src/core/ext/client_config/lb_policy_registry.c", - "src/core/ext/client_config/lb_policy_registry.h", - "src/core/ext/client_config/parse_address.c", - "src/core/ext/client_config/parse_address.h", - "src/core/ext/client_config/resolver.c", - "src/core/ext/client_config/resolver.h", - "src/core/ext/client_config/resolver_factory.c", - "src/core/ext/client_config/resolver_factory.h", - "src/core/ext/client_config/resolver_registry.c", - "src/core/ext/client_config/resolver_registry.h", - "src/core/ext/client_config/resolver_result.c", - "src/core/ext/client_config/resolver_result.h", - "src/core/ext/client_config/subchannel.c", - "src/core/ext/client_config/subchannel.h", - "src/core/ext/client_config/subchannel_index.c", - "src/core/ext/client_config/subchannel_index.h", - "src/core/ext/client_config/uri_parser.c", - "src/core/ext/client_config/uri_parser.h" + "src/core/ext/client_channel/client_channel.h", + "src/core/ext/client_channel/client_channel_factory.h", + "src/core/ext/client_channel/connector.h", + "src/core/ext/client_channel/initial_connect_string.h", + "src/core/ext/client_channel/lb_policy.h", + "src/core/ext/client_channel/lb_policy_factory.h", + "src/core/ext/client_channel/lb_policy_registry.h", + "src/core/ext/client_channel/parse_address.h", + "src/core/ext/client_channel/resolver.h", + "src/core/ext/client_channel/resolver_factory.h", + "src/core/ext/client_channel/resolver_registry.h", + "src/core/ext/client_channel/resolver_result.h", + "src/core/ext/client_channel/subchannel.h", + "src/core/ext/client_channel/subchannel_index.h", + "src/core/ext/client_channel/uri_parser.h" + ], + "language": "c", + "name": "grpc_client_channel", + "src": [ + "src/core/ext/client_channel/channel_connectivity.c", + "src/core/ext/client_channel/client_channel.c", + "src/core/ext/client_channel/client_channel.h", + "src/core/ext/client_channel/client_channel_factory.c", + "src/core/ext/client_channel/client_channel_factory.h", + "src/core/ext/client_channel/client_channel_plugin.c", + "src/core/ext/client_channel/connector.c", + "src/core/ext/client_channel/connector.h", + "src/core/ext/client_channel/default_initial_connect_string.c", + "src/core/ext/client_channel/initial_connect_string.c", + "src/core/ext/client_channel/initial_connect_string.h", + "src/core/ext/client_channel/lb_policy.c", + "src/core/ext/client_channel/lb_policy.h", + "src/core/ext/client_channel/lb_policy_factory.c", + "src/core/ext/client_channel/lb_policy_factory.h", + "src/core/ext/client_channel/lb_policy_registry.c", + "src/core/ext/client_channel/lb_policy_registry.h", + "src/core/ext/client_channel/parse_address.c", + "src/core/ext/client_channel/parse_address.h", + "src/core/ext/client_channel/resolver.c", + "src/core/ext/client_channel/resolver.h", + "src/core/ext/client_channel/resolver_factory.c", + "src/core/ext/client_channel/resolver_factory.h", + "src/core/ext/client_channel/resolver_registry.c", + "src/core/ext/client_channel/resolver_registry.h", + "src/core/ext/client_channel/resolver_result.c", + "src/core/ext/client_channel/resolver_result.h", + "src/core/ext/client_channel/subchannel.c", + "src/core/ext/client_channel/subchannel.h", + "src/core/ext/client_channel/subchannel_index.c", + "src/core/ext/client_channel/subchannel_index.h", + "src/core/ext/client_channel/uri_parser.c", + "src/core/ext/client_channel/uri_parser.h" ], "third_party": false, "type": "filegroup" @@ -6246,7 +6246,7 @@ "deps": [ "gpr", "grpc_base", - "grpc_client_config", + "grpc_client_channel", "nanopb" ], "headers": [ @@ -6271,7 +6271,7 @@ "deps": [ "gpr", "grpc_base", - "grpc_client_config" + "grpc_client_channel" ], "headers": [], "language": "c", @@ -6286,7 +6286,7 @@ "deps": [ "gpr", "grpc_base", - "grpc_client_config" + "grpc_client_channel" ], "headers": [], "language": "c", @@ -6321,7 +6321,7 @@ "deps": [ "gpr", "grpc_base", - "grpc_client_config" + "grpc_client_channel" ], "headers": [], "language": "c", @@ -6336,7 +6336,7 @@ "deps": [ "gpr", "grpc_base", - "grpc_client_config" + "grpc_client_channel" ], "headers": [], "language": "c", @@ -6572,7 +6572,7 @@ "deps": [ "gpr", "grpc_base", - "grpc_client_config", + "grpc_client_channel", "grpc_transport_chttp2" ], "headers": [], @@ -6589,7 +6589,7 @@ "deps": [ "gpr", "grpc_base", - "grpc_client_config", + "grpc_client_channel", "grpc_secure", "grpc_transport_chttp2" ], diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index 51e1dff96e..8dde78897b 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -94361,7 +94361,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342" + "test/core/client_channel/uri_corpus/02d156dc5e6f2c11c90c2e06fcee04adf036a342" ], "ci_platforms": [ "linux" @@ -94380,7 +94380,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342" + "test/core/client_channel/uri_corpus/042dc4512fa3d391c5170cf3aa61e6a638f84342" ], "ci_platforms": [ "linux" @@ -94399,7 +94399,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11" + "test/core/client_channel/uri_corpus/0e9bbe975f2027e8c39c89f85f667530368e7d11" ], "ci_platforms": [ "linux" @@ -94418,7 +94418,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f" + "test/core/client_channel/uri_corpus/1155aa6ea7ef262a81a63692513ea395f84dad6f" ], "ci_platforms": [ "linux" @@ -94437,7 +94437,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118" + "test/core/client_channel/uri_corpus/13856a5569ffd085a4d5c07af5f8e9310835a118" ], "ci_platforms": [ "linux" @@ -94456,7 +94456,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc" + "test/core/client_channel/uri_corpus/14b57bcbf1e17b1db1de491ef2ba3768f704b7dc" ], "ci_platforms": [ "linux" @@ -94475,7 +94475,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f" + "test/core/client_channel/uri_corpus/1794310671a060eead6e5ee66ac978a18ec7e84f" ], "ci_platforms": [ "linux" @@ -94494,7 +94494,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80" + "test/core/client_channel/uri_corpus/1d30b2a79afbaf2828ff42b9a9647e942ba1ab80" ], "ci_platforms": [ "linux" @@ -94513,7 +94513,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971" + "test/core/client_channel/uri_corpus/1fcf5d9c333b70596cf5ba04d1f7affdf445b971" ], "ci_platforms": [ "linux" @@ -94532,7 +94532,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc" + "test/core/client_channel/uri_corpus/23162c8a8936e20b195404c21337ee734d02a6bc" ], "ci_platforms": [ "linux" @@ -94551,7 +94551,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1" + "test/core/client_channel/uri_corpus/23f3198b815ca60bdadcaae682b9f965dda387f1" ], "ci_platforms": [ "linux" @@ -94570,7 +94570,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf" + "test/core/client_channel/uri_corpus/2ef3893b43f1f60b77b59ce06a6bce9815d78eaf" ], "ci_platforms": [ "linux" @@ -94589,7 +94589,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce" + "test/core/client_channel/uri_corpus/356c3c129e203b5c74550b4209764d74b9caefce" ], "ci_platforms": [ "linux" @@ -94608,7 +94608,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327" + "test/core/client_channel/uri_corpus/396568fc41c8ccb31ec925b4a862e4d29ead1327" ], "ci_platforms": [ "linux" @@ -94627,7 +94627,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c" + "test/core/client_channel/uri_corpus/3b1e7526a99918006b87e499d2beb6c4ac9c3c0c" ], "ci_platforms": [ "linux" @@ -94646,7 +94646,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc" + "test/core/client_channel/uri_corpus/3b58860f3451d3e7aad99690a8d39782ca5116fc" ], "ci_platforms": [ "linux" @@ -94665,7 +94665,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c" + "test/core/client_channel/uri_corpus/41963cc10752f70c3af7e3d85868efb097a0ea9c" ], "ci_platforms": [ "linux" @@ -94684,7 +94684,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1" + "test/core/client_channel/uri_corpus/47b5228404451fc9d4071fa69192514bb4ce33c1" ], "ci_platforms": [ "linux" @@ -94703,7 +94703,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab" + "test/core/client_channel/uri_corpus/56a2da4b2e6fb795243901023ed8d0aa083d1aab" ], "ci_platforms": [ "linux" @@ -94722,7 +94722,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822" + "test/core/client_channel/uri_corpus/574c2f13858a9a6d724654bd913ede9ae3abf822" ], "ci_platforms": [ "linux" @@ -94741,7 +94741,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb" + "test/core/client_channel/uri_corpus/582f789c19033a152094cbf8565f14154a778ddb" ], "ci_platforms": [ "linux" @@ -94760,7 +94760,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8" + "test/core/client_channel/uri_corpus/636c5606fc23713a1bae88c8899c0541cfad4fd8" ], "ci_platforms": [ "linux" @@ -94779,7 +94779,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a" + "test/core/client_channel/uri_corpus/63fe493b270b17426d77a27cbf3abac5b2c2794a" ], "ci_platforms": [ "linux" @@ -94798,7 +94798,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb" + "test/core/client_channel/uri_corpus/655300a902b62662296a8e46bfb04fbcb07182cb" ], "ci_platforms": [ "linux" @@ -94817,7 +94817,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58" + "test/core/client_channel/uri_corpus/6ae3acd9d8507b61bf235748026080a4138dba58" ], "ci_platforms": [ "linux" @@ -94836,7 +94836,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6" + "test/core/client_channel/uri_corpus/6b70979a70a038ff6607d6cf85485ee95baf58e6" ], "ci_platforms": [ "linux" @@ -94855,7 +94855,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1" + "test/core/client_channel/uri_corpus/7314ab3545a7535a26e0e8aad67caea5534d68b1" ], "ci_platforms": [ "linux" @@ -94874,7 +94874,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb" + "test/core/client_channel/uri_corpus/7ff4d8b8d1ffd0d42c48bbb91e5856a9ec31aecb" ], "ci_platforms": [ "linux" @@ -94893,7 +94893,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d" + "test/core/client_channel/uri_corpus/87daa131e0973b77a232a870ed749ef29cf58e6d" ], "ci_platforms": [ "linux" @@ -94912,7 +94912,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266" + "test/core/client_channel/uri_corpus/884dcaee2908ffe5f12b65b8eba81016099c4266" ], "ci_platforms": [ "linux" @@ -94931,7 +94931,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb" + "test/core/client_channel/uri_corpus/8d7e944fd5d0ede94097fcc98b47b09a3f9c76cb" ], "ci_platforms": [ "linux" @@ -94950,7 +94950,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4" + "test/core/client_channel/uri_corpus/9671149af0b444f59bbdf71340d3441dadd8a7b4" ], "ci_platforms": [ "linux" @@ -94969,7 +94969,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb" + "test/core/client_channel/uri_corpus/96c8d266b7dc037288ef305c996608270f72e7fb" ], "ci_platforms": [ "linux" @@ -94988,7 +94988,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8" + "test/core/client_channel/uri_corpus/975536c71ade4800415a7e9c2f1b45c35a6d5ea8" ], "ci_platforms": [ "linux" @@ -95007,7 +95007,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b" + "test/core/client_channel/uri_corpus/99750aa67d30beaea8af565c829d4999aa8cb91b" ], "ci_platforms": [ "linux" @@ -95026,7 +95026,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6" + "test/core/client_channel/uri_corpus/a1140f3f8b5cffc1010221b9a4084a25fb75c1f6" ], "ci_platforms": [ "linux" @@ -95045,7 +95045,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de" + "test/core/client_channel/uri_corpus/a1f0f9b75bb354eb063d7cba4fcfa2d0b88d63de" ], "ci_platforms": [ "linux" @@ -95064,7 +95064,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d" + "test/core/client_channel/uri_corpus/a296eb3d1d436ed7df7195b10aa3c4de3896f98d" ], "ci_platforms": [ "linux" @@ -95083,7 +95083,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38" + "test/core/client_channel/uri_corpus/a8b8e66050b424f1b8c07d46f868199fb7f60e38" ], "ci_platforms": [ "linux" @@ -95102,7 +95102,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/aba1472880406a318ce207ee79815b7acf087757" + "test/core/client_channel/uri_corpus/aba1472880406a318ce207ee79815b7acf087757" ], "ci_platforms": [ "linux" @@ -95121,7 +95121,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2" + "test/core/client_channel/uri_corpus/af55baf8c8855e563befdf1eefbcbd46c5ddb8d2" ], "ci_platforms": [ "linux" @@ -95140,7 +95140,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd" + "test/core/client_channel/uri_corpus/b3c0bf66c2bf5d24ef1daf4cc5a9d6d5bd0e8bfd" ], "ci_platforms": [ "linux" @@ -95159,7 +95159,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4" + "test/core/client_channel/uri_corpus/c28a47409cf5d95bb372238d01e73d8b831408e4" ], "ci_platforms": [ "linux" @@ -95178,7 +95178,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807" + "test/core/client_channel/uri_corpus/c3ef1d41888063a08700c3add1e4465aabcf8807" ], "ci_platforms": [ "linux" @@ -95197,7 +95197,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d" + "test/core/client_channel/uri_corpus/c550a76af21f9b9cc92a386d5c8998b26f8f2e4d" ], "ci_platforms": [ "linux" @@ -95216,7 +95216,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9" + "test/core/client_channel/uri_corpus/c79721406d0ab80495f186fd88e37fba98637ae9" ], "ci_platforms": [ "linux" @@ -95235,7 +95235,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245" + "test/core/client_channel/uri_corpus/ceb4e2264ba7a8d5be47d276b37ec09489e00245" ], "ci_platforms": [ "linux" @@ -95254,7 +95254,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c" + "test/core/client_channel/uri_corpus/cf4395958f5bfb46fd6f535a39657d016c75114c" ], "ci_platforms": [ "linux" @@ -95273,7 +95273,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca" + "test/core/client_channel/uri_corpus/d46668372b7e20154a89409a7430a28e642afdca" ], "ci_platforms": [ "linux" @@ -95292,7 +95292,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a" + "test/core/client_channel/uri_corpus/d6fe7412a0a1d1c733160246f3fa425f4f97682a" ], "ci_platforms": [ "linux" @@ -95311,7 +95311,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/dns.txt" + "test/core/client_channel/uri_corpus/dns.txt" ], "ci_platforms": [ "linux" @@ -95330,7 +95330,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd" + "test/core/client_channel/uri_corpus/e241f29957b0e30ec11aaaf91b2339f7015fa5fd" ], "ci_platforms": [ "linux" @@ -95349,7 +95349,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71" + "test/core/client_channel/uri_corpus/ea02d9fea9bad5b89cf353a0169238f584177e71" ], "ci_platforms": [ "linux" @@ -95368,7 +95368,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee" + "test/core/client_channel/uri_corpus/ec4731dddf94ed3ea92ae4d5a71f145ab6e3f6ee" ], "ci_platforms": [ "linux" @@ -95387,7 +95387,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2" + "test/core/client_channel/uri_corpus/ed2f78646f19fc47dd85ff0877c232b71913ece2" ], "ci_platforms": [ "linux" @@ -95406,7 +95406,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3" + "test/core/client_channel/uri_corpus/f6889f4a6350fea1596a3adea5cdac02bd5d1ff3" ], "ci_platforms": [ "linux" @@ -95425,7 +95425,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67" + "test/core/client_channel/uri_corpus/f6f3bd030f0d321efe7c51ca3f057de23509af67" ], "ci_platforms": [ "linux" @@ -95444,7 +95444,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/f97598cff03306af3c70400608fec47268b5075d" + "test/core/client_channel/uri_corpus/f97598cff03306af3c70400608fec47268b5075d" ], "ci_platforms": [ "linux" @@ -95463,7 +95463,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101" + "test/core/client_channel/uri_corpus/f9e1ec1fc642b575bc9955618b7065747f56b101" ], "ci_platforms": [ "linux" @@ -95482,7 +95482,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4" + "test/core/client_channel/uri_corpus/fe0630a3aeed2ec6f474f362e4c839478290d5c4" ], "ci_platforms": [ "linux" @@ -95501,7 +95501,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/ipv4.txt" + "test/core/client_channel/uri_corpus/ipv4.txt" ], "ci_platforms": [ "linux" @@ -95520,7 +95520,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/ipv6.txt" + "test/core/client_channel/uri_corpus/ipv6.txt" ], "ci_platforms": [ "linux" @@ -95539,7 +95539,7 @@ }, { "args": [ - "test/core/client_config/uri_corpus/unix.txt" + "test/core/client_channel/uri_corpus/unix.txt" ], "ci_platforms": [ "linux" diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index 7c120bcf02..9dc0e14995 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -424,21 +424,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -744,41 +744,41 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index 9cbb2ce45b..abe48faa0b 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -427,59 +427,59 @@ src\core\ext\transport\chttp2\client\secure - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel src\core\ext\transport\chttp2\server\insecure @@ -1040,50 +1040,50 @@ src\core\lib\tsi - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel src\core\ext\lb_policy\grpclb @@ -1172,8 +1172,8 @@ {4a14dd37-5868-c656-7333-fa80574cbb07} - - {003725f8-37fc-80b5-deba-baae32caf915} + + {36eee53a-cd19-738a-c387-20c44a2bfd07} {030f00ff-6c54-76c8-12df-37e3008335d1} diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index d4a85768c3..37fdc41e7a 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -390,21 +390,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -660,41 +660,41 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index fba5a02099..cc483bba5f 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -352,59 +352,59 @@ src\core\ext\transport\chttp2\client\insecure - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel src\core\ext\resolver\dns\native @@ -878,50 +878,50 @@ src\core\ext\transport\chttp2\alpn - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel - - src\core\ext\client_config + + src\core\ext\client_channel src\core\ext\load_reporting @@ -1010,8 +1010,8 @@ {dfe53168-57b0-3ac4-d8ba-07fd958cc8f5} - - {25fa8af3-0a05-987c-741f-fa8ff9d65d51} + + {2edd1aad-34cf-0c66-e03e-b1b2dd81d9a8} {a23781d2-27e4-7cb0-12cd-59782ecb21ce} diff --git a/vsprojects/vcxproj/test/dns_resolver_connectivity_test/dns_resolver_connectivity_test.vcxproj b/vsprojects/vcxproj/test/dns_resolver_connectivity_test/dns_resolver_connectivity_test.vcxproj index 76ac196dda..e8958bbe32 100644 --- a/vsprojects/vcxproj/test/dns_resolver_connectivity_test/dns_resolver_connectivity_test.vcxproj +++ b/vsprojects/vcxproj/test/dns_resolver_connectivity_test/dns_resolver_connectivity_test.vcxproj @@ -158,7 +158,7 @@ - + diff --git a/vsprojects/vcxproj/test/dns_resolver_connectivity_test/dns_resolver_connectivity_test.vcxproj.filters b/vsprojects/vcxproj/test/dns_resolver_connectivity_test/dns_resolver_connectivity_test.vcxproj.filters index e49318df11..eb80b8eed5 100644 --- a/vsprojects/vcxproj/test/dns_resolver_connectivity_test/dns_resolver_connectivity_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/dns_resolver_connectivity_test/dns_resolver_connectivity_test.vcxproj.filters @@ -1,8 +1,8 @@ - - test\core\client_config\resolvers + + test\core\client_channel\resolvers @@ -13,11 +13,11 @@ {cc06b800-cd26-f7a8-7ecf-ec789e78881b} - - {4fbd5c0a-d1e3-6658-5788-2fc6f2cc9071} + + {0998596f-2aa1-8205-173b-0bd27b7617d1} - - {eab637a2-7ac1-f6be-4fc2-c8989c66070b} + + {8925594d-dbe2-fee6-1553-d3258d9361da} diff --git a/vsprojects/vcxproj/test/dns_resolver_test/dns_resolver_test.vcxproj b/vsprojects/vcxproj/test/dns_resolver_test/dns_resolver_test.vcxproj index 1f3089b9aa..83375104ab 100644 --- a/vsprojects/vcxproj/test/dns_resolver_test/dns_resolver_test.vcxproj +++ b/vsprojects/vcxproj/test/dns_resolver_test/dns_resolver_test.vcxproj @@ -158,7 +158,7 @@ - + diff --git a/vsprojects/vcxproj/test/dns_resolver_test/dns_resolver_test.vcxproj.filters b/vsprojects/vcxproj/test/dns_resolver_test/dns_resolver_test.vcxproj.filters index ea6e7077f2..540da557e6 100644 --- a/vsprojects/vcxproj/test/dns_resolver_test/dns_resolver_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/dns_resolver_test/dns_resolver_test.vcxproj.filters @@ -1,8 +1,8 @@ - - test\core\client_config\resolvers + + test\core\client_channel\resolvers @@ -13,11 +13,11 @@ {edc57049-e918-50c2-5ba9-04771a506c89} - - {7922598e-4d7b-3a07-85d1-467b736756f6} + + {227838e2-4ac8-f960-68b6-e82cc6e0cefa} - - {fb24db82-f42b-3f44-fb9b-b540e8f9c6ab} + + {5d51c3a6-a50e-4d84-53b3-44ee7c39f36c} diff --git a/vsprojects/vcxproj/test/lb_policies_test/lb_policies_test.vcxproj b/vsprojects/vcxproj/test/lb_policies_test/lb_policies_test.vcxproj index 22b364f35c..b4da0194db 100644 --- a/vsprojects/vcxproj/test/lb_policies_test/lb_policies_test.vcxproj +++ b/vsprojects/vcxproj/test/lb_policies_test/lb_policies_test.vcxproj @@ -158,7 +158,7 @@ - + diff --git a/vsprojects/vcxproj/test/lb_policies_test/lb_policies_test.vcxproj.filters b/vsprojects/vcxproj/test/lb_policies_test/lb_policies_test.vcxproj.filters index d606813812..362cfab89d 100644 --- a/vsprojects/vcxproj/test/lb_policies_test/lb_policies_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/lb_policies_test/lb_policies_test.vcxproj.filters @@ -1,8 +1,8 @@ - - test\core\client_config + + test\core\client_channel @@ -13,8 +13,8 @@ {6e194f4b-ceb1-0e6b-e77a-8149b0411d99} - - {f948fe8f-47f8-fcce-2740-6c390af3c30b} + + {c4b19e85-1a5c-066b-9503-b58971695a58} diff --git a/vsprojects/vcxproj/test/set_initial_connect_string_test/set_initial_connect_string_test.vcxproj b/vsprojects/vcxproj/test/set_initial_connect_string_test/set_initial_connect_string_test.vcxproj index 5fda720526..a438391f25 100644 --- a/vsprojects/vcxproj/test/set_initial_connect_string_test/set_initial_connect_string_test.vcxproj +++ b/vsprojects/vcxproj/test/set_initial_connect_string_test/set_initial_connect_string_test.vcxproj @@ -158,7 +158,7 @@ - + diff --git a/vsprojects/vcxproj/test/set_initial_connect_string_test/set_initial_connect_string_test.vcxproj.filters b/vsprojects/vcxproj/test/set_initial_connect_string_test/set_initial_connect_string_test.vcxproj.filters index 8abfa1991a..4422a3e792 100644 --- a/vsprojects/vcxproj/test/set_initial_connect_string_test/set_initial_connect_string_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/set_initial_connect_string_test/set_initial_connect_string_test.vcxproj.filters @@ -1,8 +1,8 @@ - - test\core\client_config + + test\core\client_channel @@ -13,8 +13,8 @@ {a554b5ef-0c80-ac03-1848-bccd947a06a6} - - {a6c4917f-b1b0-e958-6ea8-34950c2f8f36} + + {4726253c-a562-0ace-2798-996807381208} diff --git a/vsprojects/vcxproj/test/sockaddr_resolver_test/sockaddr_resolver_test.vcxproj b/vsprojects/vcxproj/test/sockaddr_resolver_test/sockaddr_resolver_test.vcxproj index 1062132c60..8d5d02e707 100644 --- a/vsprojects/vcxproj/test/sockaddr_resolver_test/sockaddr_resolver_test.vcxproj +++ b/vsprojects/vcxproj/test/sockaddr_resolver_test/sockaddr_resolver_test.vcxproj @@ -158,7 +158,7 @@ - + diff --git a/vsprojects/vcxproj/test/sockaddr_resolver_test/sockaddr_resolver_test.vcxproj.filters b/vsprojects/vcxproj/test/sockaddr_resolver_test/sockaddr_resolver_test.vcxproj.filters index 50de4b3777..aa63da1502 100644 --- a/vsprojects/vcxproj/test/sockaddr_resolver_test/sockaddr_resolver_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/sockaddr_resolver_test/sockaddr_resolver_test.vcxproj.filters @@ -1,8 +1,8 @@ - - test\core\client_config\resolvers + + test\core\client_channel\resolvers @@ -13,11 +13,11 @@ {efc6f7cf-eb13-376c-85bb-64fae70baf03} - - {cba53434-a270-8e21-2976-5f7950730eb8} + + {a3fef8b1-3b99-63c9-5f35-feff99af1381} - - {79868613-ffd2-ead6-5b23-fc1d8d0709ba} + + {d32b4315-4e08-e492-5e10-4dc0c5c8cd55} diff --git a/vsprojects/vcxproj/test/uri_parser_test/uri_parser_test.vcxproj b/vsprojects/vcxproj/test/uri_parser_test/uri_parser_test.vcxproj index 51c4a274a8..d5229e06cb 100644 --- a/vsprojects/vcxproj/test/uri_parser_test/uri_parser_test.vcxproj +++ b/vsprojects/vcxproj/test/uri_parser_test/uri_parser_test.vcxproj @@ -158,7 +158,7 @@ - + diff --git a/vsprojects/vcxproj/test/uri_parser_test/uri_parser_test.vcxproj.filters b/vsprojects/vcxproj/test/uri_parser_test/uri_parser_test.vcxproj.filters index e95dd1d9d2..bafab6af63 100644 --- a/vsprojects/vcxproj/test/uri_parser_test/uri_parser_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/uri_parser_test/uri_parser_test.vcxproj.filters @@ -1,8 +1,8 @@ - - test\core\client_config + + test\core\client_channel @@ -13,8 +13,8 @@ {5e9a3063-bec4-a26c-b10d-13c866d4e639} - - {65156042-def7-b09c-d76e-38ba78456f20} + + {1d9f3085-019b-9673-74b6-55a857b824af} -- cgit v1.2.3 From 7e642e333b47f069a0fa8c2565ad30aa165ced89 Mon Sep 17 00:00:00 2001 From: Tim Ryan Date: Mon, 26 Sep 2016 19:11:06 -0400 Subject: Compiles with npm install --debug option. --- src/node/ext/node_grpc.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/node/ext/node_grpc.cc b/src/node/ext/node_grpc.cc index 745b5023d5..848c601587 100644 --- a/src/node/ext/node_grpc.cc +++ b/src/node/ext/node_grpc.cc @@ -261,10 +261,10 @@ void InitLogConstants(Local exports) { Nan::HandleScope scope; Local log_verbosity = Nan::New(); Nan::Set(exports, Nan::New("logVerbosity").ToLocalChecked(), log_verbosity); - Local DEBUG(Nan::New(GPR_LOG_SEVERITY_DEBUG)); - Nan::Set(log_verbosity, Nan::New("DEBUG").ToLocalChecked(), DEBUG); - Local INFO(Nan::New(GPR_LOG_SEVERITY_INFO)); - Nan::Set(log_verbosity, Nan::New("INFO").ToLocalChecked(), INFO); + Local LOG_DEBUG(Nan::New(GPR_LOG_SEVERITY_DEBUG)); + Nan::Set(log_verbosity, Nan::New("DEBUG").ToLocalChecked(), LOG_DEBUG); + Local LOG_INFO(Nan::New(GPR_LOG_SEVERITY_INFO)); + Nan::Set(log_verbosity, Nan::New("INFO").ToLocalChecked(), LOG_INFO); Local LOG_ERROR(Nan::New(GPR_LOG_SEVERITY_ERROR)); Nan::Set(log_verbosity, Nan::New("ERROR").ToLocalChecked(), LOG_ERROR); } -- cgit v1.2.3 From 3c9728fa247dc9294a423311f50f55463af93b33 Mon Sep 17 00:00:00 2001 From: Robbie Shade Date: Tue, 27 Sep 2016 12:02:03 -0400 Subject: Wrapped logs in grpc_http_trace --- src/core/lib/channel/http_server_filter.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 607fc48105..f2221fb0fb 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -42,6 +42,8 @@ #define EXPECTED_CONTENT_TYPE "application/grpc" #define EXPECTED_CONTENT_TYPE_LENGTH sizeof(EXPECTED_CONTENT_TYPE) - 1 +extern int grpc_http_trace; + typedef struct call_data { uint8_t seen_path; uint8_t seen_method; @@ -209,9 +211,11 @@ static void hs_on_recv(grpc_exec_ctx *exec_ctx, void *user_data, err, GRPC_ERROR_CREATE("Missing te: trailers header")); } /* Error this call out */ - const char *error_str = grpc_error_string(err); - gpr_log(GPR_ERROR, "Invalid http2 headers: %s", error_str); - grpc_error_free_string(error_str); + if (grpc_http_trace) { + const char *error_str = grpc_error_string(err); + gpr_log(GPR_ERROR, "Invalid http2 headers: %s", error_str); + grpc_error_free_string(error_str); + } grpc_call_element_send_cancel(exec_ctx, elem); } } else { -- cgit v1.2.3 From db5b1cbc9483b78458ca529df5603bb15c982d63 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Mon, 3 Oct 2016 09:18:46 -0700 Subject: Add all plumbing and typedef's for controlled server-side streaming --- include/grpc++/impl/codegen/method_handler_impl.h | 14 ++++ include/grpc++/impl/codegen/service_type.h | 12 +-- include/grpc++/impl/codegen/sync_stream.h | 39 ++++++++- src/compiler/cpp_generator.cc | 97 ++++++++++++++++++++++- 4 files changed, 154 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/include/grpc++/impl/codegen/method_handler_impl.h b/include/grpc++/impl/codegen/method_handler_impl.h index 52f927631c..8f417f671a 100644 --- a/include/grpc++/impl/codegen/method_handler_impl.h +++ b/include/grpc++/impl/codegen/method_handler_impl.h @@ -236,6 +236,20 @@ class StreamedUnaryHandler ServerUnaryStreamer, true>(func) {} }; +template +class SplitServerStreamingHandler + : public TemplatedBidiStreamingHandler< + ServerSplitStreamer, false> { + public: + explicit SplitServerStreamingHandler( + std::function*)> + func) + : TemplatedBidiStreamingHandler< + ServerSplitStreamer, false>(func) {} +}; + // Handle unknown method by returning UNIMPLEMENTED error. class UnknownMethodHandler : public MethodHandler { public: diff --git a/include/grpc++/impl/codegen/service_type.h b/include/grpc++/impl/codegen/service_type.h index 72b2225312..de0862fce2 100644 --- a/include/grpc++/impl/codegen/service_type.h +++ b/include/grpc++/impl/codegen/service_type.h @@ -147,14 +147,16 @@ class Service { methods_[index].reset(); } - void MarkMethodStreamedUnary(int index, - MethodHandler* streamed_unary_method) { + void MarkMethodStreamed(int index, + MethodHandler* streamed_method) { GPR_CODEGEN_ASSERT(methods_[index] && methods_[index]->handler() && - "Cannot mark an async or generic method Streamed Unary"); - methods_[index]->SetHandler(streamed_unary_method); + "Cannot mark an async or generic method Streamed"); + methods_[index]->SetHandler(streamed_method); // From the server's point of view, streamed unary is a special - // case of BIDI_STREAMING that has 1 read and 1 write, in that order. + // case of BIDI_STREAMING that has 1 read and 1 write, in that order, + // and split server-side streaming is BIDI_STREAMING with 1 read and + // any number of writes, in that order methods_[index]->SetMethodType(::grpc::RpcMethod::BIDI_STREAMING); } diff --git a/include/grpc++/impl/codegen/sync_stream.h b/include/grpc++/impl/codegen/sync_stream.h index e3c5a919b1..f2b1e9a3ad 100644 --- a/include/grpc++/impl/codegen/sync_stream.h +++ b/include/grpc++/impl/codegen/sync_stream.h @@ -538,7 +538,7 @@ class ServerReaderWriter GRPC_FINAL : public ServerReaderWriterInterface { /// the \a NextMessageSize method to determine an upper-bound on the size of /// the message. /// A key difference relative to streaming: ServerUnaryStreamer -/// must have exactly 1 Read and exactly 1 Write, in that order, to function +/// must have exactly 1 Read and exactly 1 Write, in that order, to function /// correctly. Otherwise, the RPC is in error. template class ServerUnaryStreamer GRPC_FINAL @@ -577,6 +577,43 @@ class ServerUnaryStreamer GRPC_FINAL bool write_done_; }; +/// A class to represent a flow-controlled server-side streaming call. +/// This is something of a hybrid between server-side and bidi streaming. +/// This is invoked through a server-side streaming call on the client side, +/// but the server responds to it as though it were a bidi streaming call that +/// must first have exactly 1 Read and then any number of Writes. +template +class ServerSplitStreamer GRPC_FINAL + : public ServerReaderWriterInterface { + public: + ServerSplitStreamer(Call* call, ServerContext* ctx) + : body_(call, ctx), read_done_(false) {} + + void SendInitialMetadata() GRPC_OVERRIDE { body_.SendInitialMetadata(); } + + bool NextMessageSize(uint32_t* sz) GRPC_OVERRIDE { + return body_.NextMessageSize(sz); + } + + bool Read(RequestType* request) GRPC_OVERRIDE { + if (read_done_) { + return false; + } + read_done_ = true; + return body_.Read(request); + } + + using WriterInterface::Write; + bool Write(const ResponseType& response, + const WriteOptions& options) GRPC_OVERRIDE { + return !read_done_ && body_.Write(response, options); + } + + private: + internal::ServerReaderWriterBody body_; + bool read_done_; +}; + } // namespace grpc #endif // GRPCXX_IMPL_CODEGEN_SYNC_STREAM_H diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index d0c35ea1ab..d0f164e58d 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -605,7 +605,7 @@ void PrintHeaderServerMethodAsync(Printer *printer, const Method *method, printer->Print(*vars, "};\n"); } -void PrintHeaderServerMethodStreamedUnary( + void PrintHeaderServerMethodStreamedUnary( Printer *printer, const Method *method, std::map *vars) { (*vars)["Method"] = method->name(); @@ -624,7 +624,7 @@ void PrintHeaderServerMethodStreamedUnary( printer->Indent(); printer->Print(*vars, "WithStreamedUnaryMethod_$Method$() {\n" - " ::grpc::Service::MarkMethodStreamedUnary($Idx$,\n" + " ::grpc::Service::MarkMethodStreamed($Idx$,\n" " new ::grpc::StreamedUnaryHandler< $Request$, " "$Response$>(std::bind" "(&WithStreamedUnaryMethod_$Method$::" @@ -656,6 +656,57 @@ void PrintHeaderServerMethodStreamedUnary( } } +void PrintHeaderServerMethodSplitStreaming( + Printer *printer, const Method *method, + std::map *vars) { + (*vars)["Method"] = method->name(); + (*vars)["Request"] = method->input_type_name(); + (*vars)["Response"] = method->output_type_name(); + if (method->ServerOnlyStreaming()) { + printer->Print(*vars, "template \n"); + printer->Print(*vars, + "class WithSplitStreamingMethod_$Method$ : " + "public BaseClass {\n"); + printer->Print( + " private:\n" + " void BaseClassMustBeDerivedFromService(const Service *service) " + "{}\n"); + printer->Print(" public:\n"); + printer->Indent(); + printer->Print(*vars, + "WithSplitStreamingMethod_$Method$() {\n" + " ::grpc::Service::MarkMethodStreamed($Idx$,\n" + " new ::grpc::SplitServerStreamingHandler< $Request$, " + "$Response$>(std::bind" + "(&WithSplitStreamingMethod_$Method$::" + "Streamed$Method$, this, std::placeholders::_1, " + "std::placeholders::_2)));\n" + "}\n"); + printer->Print(*vars, + "~WithSplitStreamingMethod_$Method$() GRPC_OVERRIDE {\n" + " BaseClassMustBeDerivedFromService(this);\n" + "}\n"); + printer->Print( + *vars, + "// disable regular version of this method\n" + "::grpc::Status $Method$(" + "::grpc::ServerContext* context, const $Request$* request, " + "$Response$* response) GRPC_FINAL GRPC_OVERRIDE {\n" + " abort();\n" + " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" + "}\n"); + printer->Print(*vars, + "// replace default version of method with split streamed\n" + "virtual ::grpc::Status Streamed$Method$(" + "::grpc::ServerContext* context, " + "::grpc::ServerSplitStreamer< " + "$Request$,$Response$>* server_split_streamer)" + " = 0;\n"); + printer->Outdent(); + printer->Print(*vars, "};\n"); + } +} + void PrintHeaderServerMethodGeneric( Printer *printer, const Method *method, std::map *vars) { @@ -844,6 +895,48 @@ void PrintHeaderService(Printer *printer, const Service *service, } printer->Print(" StreamedUnaryService;\n"); + // Server side - controlled server-side streaming + for (int i = 0; i < service->method_count(); ++i) { + (*vars)["Idx"] = as_string(i); + PrintHeaderServerMethodSplitStreaming(printer, service->method(i).get(), + vars); + } + + printer->Print("typedef "); + for (int i = 0; i < service->method_count(); ++i) { + (*vars)["method_name"] = service->method(i).get()->name(); + if (service->method(i)->ServerOnlyStreaming()) { + printer->Print(*vars, "WithSplitStreamingMethod_$method_name$<"); + } + } + printer->Print("Service"); + for (int i = 0; i < service->method_count(); ++i) { + if (service->method(i)->ServerOnlyStreaming()) { + printer->Print(" >"); + } + } + printer->Print(" SplitStreamedService;\n"); + + // Server side - typedef for controlled both unary and server-side streaming + printer->Print("typedef "); + for (int i = 0; i < service->method_count(); ++i) { + (*vars)["method_name"] = service->method(i).get()->name(); + if (service->method(i)->ServerOnlyStreaming()) { + printer->Print(*vars, "WithSplitStreamingMethod_$method_name$<"); + } + if (service->method(i)->NoStreaming()) { + printer->Print(*vars, "WithStreamedUnaryMethod_$method_name$<"); + } + } + printer->Print("Service"); + for (int i = 0; i < service->method_count(); ++i) { + if (service->method(i)->NoStreaming() || + service->method(i)->ServerOnlyStreaming()) { + printer->Print(" >"); + } + } + printer->Print(" StreamedService;\n"); + printer->Outdent(); printer->Print("};\n"); printer->Print(service->GetTrailingComments().c_str()); -- cgit v1.2.3 From 61536a737176e5429b0b1f336e054f9743a03b91 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 13 Oct 2016 11:04:35 -0700 Subject: Making split streaming testable --- include/grpc++/impl/codegen/method_handler_impl.h | 3 +- src/compiler/cpp_generator.cc | 2 +- .../grpc/testing/duplicate/echo_duplicate.proto | 1 + test/cpp/end2end/hybrid_end2end_test.cc | 61 ++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/include/grpc++/impl/codegen/method_handler_impl.h b/include/grpc++/impl/codegen/method_handler_impl.h index 8f417f671a..bb992f0e18 100644 --- a/include/grpc++/impl/codegen/method_handler_impl.h +++ b/include/grpc++/impl/codegen/method_handler_impl.h @@ -243,8 +243,7 @@ class SplitServerStreamingHandler public: explicit SplitServerStreamingHandler( std::function*)> + ServerSplitStreamer*)> func) : TemplatedBidiStreamingHandler< ServerSplitStreamer, false>(func) {} diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index d0f164e58d..8525a6a2c9 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -691,7 +691,7 @@ void PrintHeaderServerMethodSplitStreaming( "// disable regular version of this method\n" "::grpc::Status $Method$(" "::grpc::ServerContext* context, const $Request$* request, " - "$Response$* response) GRPC_FINAL GRPC_OVERRIDE {\n" + "::grpc::ServerWriter< $Response$>* writer) GRPC_FINAL GRPC_OVERRIDE {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); diff --git a/src/proto/grpc/testing/duplicate/echo_duplicate.proto b/src/proto/grpc/testing/duplicate/echo_duplicate.proto index 94130ea767..97fdbc4fd3 100644 --- a/src/proto/grpc/testing/duplicate/echo_duplicate.proto +++ b/src/proto/grpc/testing/duplicate/echo_duplicate.proto @@ -38,4 +38,5 @@ package grpc.testing.duplicate; service EchoTestService { rpc Echo(grpc.testing.EchoRequest) returns (grpc.testing.EchoResponse); + rpc ResponseStream(EchoRequest) returns (stream EchoResponse); } diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index 8cd2e66347..1ef2af2e2e 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -320,6 +320,26 @@ class HybridEnd2endTest : public ::testing::Test { EXPECT_TRUE(s.ok()); } + void SendSimpleServerStreamingToDupService() { + EchoRequest request; + EchoResponse response; + ClientContext context; + context.set_wait_for_ready(true); + request.set_message("hello"); + + auto stream = stub_->ResponseStream(&context, request); + EXPECT_TRUE(stream->Read(&response)); + EXPECT_EQ(response.message(), request.message() + "0_dup"); + EXPECT_TRUE(stream->Read(&response)); + EXPECT_EQ(response.message(), request.message() + "1_dup"); + EXPECT_TRUE(stream->Read(&response)); + EXPECT_EQ(response.message(), request.message() + "2_dup"); + EXPECT_FALSE(stream->Read(&response)); + + Status s = stream->Finish(); + EXPECT_TRUE(s.ok()); + } + void SendBidiStreaming() { EchoRequest request; EchoResponse response; @@ -498,6 +518,47 @@ TEST_F(HybridEnd2endTest, request_stream_handler_thread.join(); } +// Add a second service with one sync split server streaming method. +class SplitResponseStreamDupPkg + : public duplicate::EchoTestService::WithSplitStreamingMethod_ResponseStream< + TestServiceImplDupPkg> { + public: + Status StreamedResponseStream(ServerContext* context, + ServerSplitStreamer* stream) + GRPC_OVERRIDE { + EchoRequest req; + EchoResponse resp; + uint32_t next_msg_sz; + stream->NextMessageSize(&next_msg_sz); + gpr_log(GPR_INFO, "Split Streamed Next Message Size is %u", next_msg_sz); + GPR_ASSERT(stream->Read(&req)); + for (int i = 0; i < kNumResponseStreamsMsgs; i++) { + resp.set_message(req.message() + grpc::to_string(i) + "_dup"); + GPR_ASSERT(stream->Write(resp)); + } + return Status::OK; + } +}; + +TEST_F(HybridEnd2endTest, + AsyncRequestStreamResponseStream_SyncSplitStreamedDupService) { + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithAsyncMethod_ResponseStream> + SType; + SType service; + SplitResponseStreamDupPkg dup_service; + SetUpServer(&service, &dup_service, nullptr, 8192); + ResetStub(); + std::thread response_stream_handler_thread(HandleServerStreaming, + &service, cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming, + &service, cqs_[1].get()); + TestAllMethods(); + SendSimpleServerStreamingToDupService(); + response_stream_handler_thread.join(); + request_stream_handler_thread.join(); +} + // Add a second service with one async method. TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_AsyncDupService) { typedef EchoTestService::WithAsyncMethod_RequestStream< -- cgit v1.2.3 From 96e03110db4d01b09e69f1f275adea6facec6fcb Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 13 Oct 2016 14:09:16 -0700 Subject: clang-format --- include/grpc++/impl/codegen/service_type.h | 3 +-- src/compiler/cpp_generator.cc | 9 +++++---- test/cpp/end2end/hybrid_end2end_test.cc | 25 ++++++++++++------------- 3 files changed, 18 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/include/grpc++/impl/codegen/service_type.h b/include/grpc++/impl/codegen/service_type.h index de0862fce2..bd65ea009e 100644 --- a/include/grpc++/impl/codegen/service_type.h +++ b/include/grpc++/impl/codegen/service_type.h @@ -147,8 +147,7 @@ class Service { methods_[index].reset(); } - void MarkMethodStreamed(int index, - MethodHandler* streamed_method) { + void MarkMethodStreamed(int index, MethodHandler* streamed_method) { GPR_CODEGEN_ASSERT(methods_[index] && methods_[index]->handler() && "Cannot mark an async or generic method Streamed"); methods_[index]->SetHandler(streamed_method); diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index 8525a6a2c9..fa72f9b0d9 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -605,7 +605,7 @@ void PrintHeaderServerMethodAsync(Printer *printer, const Method *method, printer->Print(*vars, "};\n"); } - void PrintHeaderServerMethodStreamedUnary( +void PrintHeaderServerMethodStreamedUnary( Printer *printer, const Method *method, std::map *vars) { (*vars)["Method"] = method->name(); @@ -691,7 +691,8 @@ void PrintHeaderServerMethodSplitStreaming( "// disable regular version of this method\n" "::grpc::Status $Method$(" "::grpc::ServerContext* context, const $Request$* request, " - "::grpc::ServerWriter< $Response$>* writer) GRPC_FINAL GRPC_OVERRIDE {\n" + "::grpc::ServerWriter< $Response$>* writer) GRPC_FINAL GRPC_OVERRIDE " + "{\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -899,7 +900,7 @@ void PrintHeaderService(Printer *printer, const Service *service, for (int i = 0; i < service->method_count(); ++i) { (*vars)["Idx"] = as_string(i); PrintHeaderServerMethodSplitStreaming(printer, service->method(i).get(), - vars); + vars); } printer->Print("typedef "); @@ -931,7 +932,7 @@ void PrintHeaderService(Printer *printer, const Service *service, printer->Print("Service"); for (int i = 0; i < service->method_count(); ++i) { if (service->method(i)->NoStreaming() || - service->method(i)->ServerOnlyStreaming()) { + service->method(i)->ServerOnlyStreaming()) { printer->Print(" >"); } } diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index 381ac543c6..76a5732f33 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -523,12 +523,12 @@ TEST_F(HybridEnd2endTest, // Add a second service with one sync split server streaming method. class SplitResponseStreamDupPkg - : public duplicate::EchoTestService::WithSplitStreamingMethod_ResponseStream< - TestServiceImplDupPkg> { + : public duplicate::EchoTestService:: + WithSplitStreamingMethod_ResponseStream { public: - Status StreamedResponseStream(ServerContext* context, - ServerSplitStreamer* stream) - GRPC_OVERRIDE { + Status StreamedResponseStream( + ServerContext* context, + ServerSplitStreamer* stream) GRPC_OVERRIDE { EchoRequest req; EchoResponse resp; uint32_t next_msg_sz; @@ -566,9 +566,9 @@ TEST_F(HybridEnd2endTest, class FullySplitStreamedDupPkg : public duplicate::EchoTestService::SplitStreamedService { public: - Status StreamedResponseStream(ServerContext* context, - ServerSplitStreamer* stream) - GRPC_OVERRIDE { + Status StreamedResponseStream( + ServerContext* context, + ServerSplitStreamer* stream) GRPC_OVERRIDE { EchoRequest req; EchoResponse resp; uint32_t next_msg_sz; @@ -603,8 +603,7 @@ TEST_F(HybridEnd2endTest, } // Add a second service that is fully server streamed -class FullyStreamedDupPkg - : public duplicate::EchoTestService::StreamedService { +class FullyStreamedDupPkg : public duplicate::EchoTestService::StreamedService { public: Status StreamedEcho(ServerContext* context, ServerUnaryStreamer* stream) @@ -619,9 +618,9 @@ class FullyStreamedDupPkg GPR_ASSERT(stream->Write(resp)); return Status::OK; } - Status StreamedResponseStream(ServerContext* context, - ServerSplitStreamer* stream) - GRPC_OVERRIDE { + Status StreamedResponseStream( + ServerContext* context, + ServerSplitStreamer* stream) GRPC_OVERRIDE { EchoRequest req; EchoResponse resp; uint32_t next_msg_sz; -- cgit v1.2.3 From d8fe334d5b92ef50e44c75ac19d8dced53efc476 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Sat, 15 Oct 2016 15:25:51 -0700 Subject: s/lb-cost/lb-cost-bin --- src/core/ext/load_reporting/load_reporting.h | 2 +- src/core/lib/transport/static_metadata.c | 2 +- src/core/lib/transport/static_metadata.h | 8 ++++---- test/core/end2end/fuzzers/hpack.dictionary | 4 ++-- tools/codegen/core/gen_static_metadata.py | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/core/ext/load_reporting/load_reporting.h b/src/core/ext/load_reporting/load_reporting.h index e13097654d..a157844734 100644 --- a/src/core/ext/load_reporting/load_reporting.h +++ b/src/core/ext/load_reporting/load_reporting.h @@ -51,7 +51,7 @@ * The value corresponding to this key is an opaque binary blob reported by the * backend as part of its trailing metadata containing cost information for the * call. */ -#define GRPC_LB_COST_MD_KEY "lb-cost" +#define GRPC_LB_COST_MD_KEY "lb-cost-bin" /** Identifiers for the invocation point of the users LR callback */ typedef enum grpc_load_reporting_source { diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index f019ef156a..8b22592b45 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -126,7 +126,7 @@ const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT] = { "if-range", "if-unmodified-since", "last-modified", - "lb-cost", + "lb-cost-bin", "lb-token", "link", "location", diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index e0a8196419..28ad6f2961 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -175,8 +175,8 @@ extern grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT]; #define GRPC_MDSTR_IF_UNMODIFIED_SINCE (&grpc_static_mdstr_table[62]) /* "last-modified" */ #define GRPC_MDSTR_LAST_MODIFIED (&grpc_static_mdstr_table[63]) -/* "lb-cost" */ -#define GRPC_MDSTR_LB_COST (&grpc_static_mdstr_table[64]) +/* "lb-cost-bin" */ +#define GRPC_MDSTR_LB_COST_BIN (&grpc_static_mdstr_table[64]) /* "lb-token" */ #define GRPC_MDSTR_LB_TOKEN (&grpc_static_mdstr_table[65]) /* "link" */ @@ -337,8 +337,8 @@ extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; #define GRPC_MDELEM_IF_UNMODIFIED_SINCE_EMPTY (&grpc_static_mdelem_table[44]) /* "last-modified": "" */ #define GRPC_MDELEM_LAST_MODIFIED_EMPTY (&grpc_static_mdelem_table[45]) -/* "lb-cost": "" */ -#define GRPC_MDELEM_LB_COST_EMPTY (&grpc_static_mdelem_table[46]) +/* "lb-cost-bin": "" */ +#define GRPC_MDELEM_LB_COST_BIN_EMPTY (&grpc_static_mdelem_table[46]) /* "lb-token": "" */ #define GRPC_MDELEM_LB_TOKEN_EMPTY (&grpc_static_mdelem_table[47]) /* "link": "" */ diff --git a/test/core/end2end/fuzzers/hpack.dictionary b/test/core/end2end/fuzzers/hpack.dictionary index 181bbe845e..12db0ff024 100644 --- a/test/core/end2end/fuzzers/hpack.dictionary +++ b/test/core/end2end/fuzzers/hpack.dictionary @@ -63,7 +63,7 @@ "\x08if-range" "\x13if-unmodified-since" "\x0Dlast-modified" -"\x07lb-cost" +"\x0Blb-cost-bin" "\x08lb-token" "\x04link" "\x08location" @@ -138,7 +138,7 @@ "\x00\x08if-range\x00" "\x00\x13if-unmodified-since\x00" "\x00\x0Dlast-modified\x00" -"\x00\x07lb-cost\x00" +"\x00\x0Blb-cost-bin\x00" "\x00\x08lb-token\x00" "\x00\x04link\x00" "\x00\x08location\x00" diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 6f8cad279c..cf3762dbb8 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -110,7 +110,7 @@ CONFIG = [ ('if-unmodified-since', ''), ('last-modified', ''), ('lb-token', ''), - ('lb-cost', ''), + ('lb-cost-bin', ''), ('link', ''), ('location', ''), ('max-forwards', ''), -- cgit v1.2.3 From 7ab83b59bedbb9bfd0917a7f5429e3150751e3d6 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 17 Oct 2016 12:43:10 -0700 Subject: fixed missing variable rename --- src/core/ext/load_reporting/load_reporting_filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/ext/load_reporting/load_reporting_filter.c b/src/core/ext/load_reporting/load_reporting_filter.c index 22bf36367f..eeae2400fb 100644 --- a/src/core/ext/load_reporting/load_reporting_filter.c +++ b/src/core/ext/load_reporting/load_reporting_filter.c @@ -193,7 +193,7 @@ static grpc_mdelem *lr_trailing_md_filter(void *user_data, grpc_mdelem *md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; - if (md->key == GRPC_MDSTR_LB_COST) { + if (md->key == GRPC_MDSTR_LB_COST_BIN) { calld->trailing_md_string = gpr_strdup(grpc_mdstr_as_c_string(md->value)); return NULL; } -- cgit v1.2.3 From 32eee7739bddb88e28cde2ead35d65bf4d5cdd7e Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Wed, 19 Oct 2016 10:04:38 -0700 Subject: Changed name of rpc method to fit with the conventional naming. Also fixed type in interop client flag help message --- src/proto/grpc/testing/test.proto | 2 +- test/cpp/interop/client.cc | 2 +- test/cpp/interop/interop_client.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/proto/grpc/testing/test.proto b/src/proto/grpc/testing/test.proto index d6ef58ab12..2b0dcde5a9 100644 --- a/src/proto/grpc/testing/test.proto +++ b/src/proto/grpc/testing/test.proto @@ -77,7 +77,7 @@ service TestService { // The test server will not implement this method. It will be used // to test the behavior when clients call unimplemented methods. - rpc UnimplementedMethod(grpc.testing.Empty) returns (grpc.testing.Empty); + rpc UnimplementedCall(grpc.testing.Empty) returns (grpc.testing.Empty); } // A simple service NOT implemented at servers so clients can test for diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 245e27b2bb..4197ba8bab 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -80,7 +80,7 @@ DEFINE_string(test_case, "large_unary", "slow client consumer;\n" "status_code_and_message: verify status code & message;\n" "timeout_on_sleeping_server: deadline exceeds on stream;\n" - "unimplemented_method: client calls an unimplemented_method;\n"); + "unimplemented_method: client calls an unimplemented method;\n"); DEFINE_string(default_service_account, "", "Email of GCE default service account"); DEFINE_string(service_account_key_file, "", diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index f95d8c6ef6..1668589cc4 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -1010,7 +1010,7 @@ bool InteropClient::DoUnimplementedMethod() { ClientContext context; Status s = - serviceStub_.Get()->UnimplementedMethod(&context, request, &response); + serviceStub_.Get()->UnimplementedCall(&context, request, &response); if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED)) { return false; -- cgit v1.2.3 From a17b9bda5aa9d1f55dd879cec61998a9293be560 Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Thu, 20 Oct 2016 11:49:42 -0700 Subject: removed check on the returned message from calling an unimplemented method --- src/csharp/Grpc.IntegrationTesting/InteropClient.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs index cb926328e0..7a46a55a5b 100644 --- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs +++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs @@ -583,7 +583,6 @@ namespace Grpc.IntegrationTesting var e = Assert.Throws(() => client.UnimplementedCall(new Empty())); Assert.AreEqual(StatusCode.Unimplemented, e.Status.StatusCode); - Assert.AreEqual("", e.Status.Detail); Console.WriteLine("Passed!"); } -- cgit v1.2.3 From 7ef9f641877d1f488aab7c2e25e64fae44fb2748 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 20 Oct 2016 23:36:45 +0200 Subject: use Server mode for GC in C# QpsWorker --- src/csharp/Grpc.IntegrationTesting.QpsWorker/project.json | 5 +++++ .../csharp/Grpc.IntegrationTesting.QpsWorker/project.json.template | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'src') diff --git a/src/csharp/Grpc.IntegrationTesting.QpsWorker/project.json b/src/csharp/Grpc.IntegrationTesting.QpsWorker/project.json index 1b900c8af3..fe200f8d44 100644 --- a/src/csharp/Grpc.IntegrationTesting.QpsWorker/project.json +++ b/src/csharp/Grpc.IntegrationTesting.QpsWorker/project.json @@ -67,5 +67,10 @@ } } } + }, + "runtimeOptions": { + "configProperties": { + "System.GC.Server": true + } } } diff --git a/templates/src/csharp/Grpc.IntegrationTesting.QpsWorker/project.json.template b/templates/src/csharp/Grpc.IntegrationTesting.QpsWorker/project.json.template index 83b8a9befa..8304d20f2e 100644 --- a/templates/src/csharp/Grpc.IntegrationTesting.QpsWorker/project.json.template +++ b/templates/src/csharp/Grpc.IntegrationTesting.QpsWorker/project.json.template @@ -20,5 +20,10 @@ } } } + }, + "runtimeOptions": { + "configProperties": { + "System.GC.Server": true + } } } -- cgit v1.2.3 From 4a08e7146468e4195912476e71fdb8427292def5 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Thu, 20 Oct 2016 15:26:01 -0700 Subject: Revert PR #8425 --- .../Sample/Sample.xcodeproj/project.pbxproj | 12 +++-------- .../xcshareddata/xcschemes/Sample.xcscheme | 2 +- .../SwiftSample.xcodeproj/project.pbxproj | 18 +++++----------- .../xcshareddata/xcschemes/SwiftSample.xcscheme | 2 +- .../examples/SwiftSample/ViewController.swift | 25 +++++++++++----------- src/objective-c/tests/Info.plist | 2 +- .../tests/Tests.xcodeproj/project.pbxproj | 16 +++----------- .../xcshareddata/xcschemes/AllTests.xcscheme | 2 +- .../xcschemes/CoreCronetEnd2EndTests.xcscheme | 2 +- .../xcschemes/InteropTestsLocalCleartext.xcscheme | 2 +- .../xcschemes/InteropTestsLocalSSL.xcscheme | 2 +- .../xcschemes/InteropTestsRemote.xcscheme | 2 +- .../InteropTestsRemoteWithCronet.xcscheme | 2 +- .../xcschemes/RxLibraryUnitTests.xcscheme | 2 +- 14 files changed, 34 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/objective-c/examples/Sample/Sample.xcodeproj/project.pbxproj b/src/objective-c/examples/Sample/Sample.xcodeproj/project.pbxproj index 8d34b26c4f..ab7159cda2 100644 --- a/src/objective-c/examples/Sample/Sample.xcodeproj/project.pbxproj +++ b/src/objective-c/examples/Sample/Sample.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 48; + objectVersion = 46; objects = { /* Begin PBXBuildFile section */ @@ -129,7 +129,7 @@ 6369A2621A9322E20015FC5C /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0730; ORGANIZATIONNAME = gRPC; TargetAttributes = { 6369A2691A9322E20015FC5C = { @@ -138,7 +138,7 @@ }; }; buildConfigurationList = 6369A2651A9322E20015FC5C /* Build configuration list for PBXProject "Sample" */; - compatibilityVersion = "Xcode 8.0"; + compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( @@ -253,10 +253,8 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -265,7 +263,6 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -299,10 +296,8 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -310,7 +305,6 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; diff --git a/src/objective-c/examples/Sample/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme b/src/objective-c/examples/Sample/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme index 881474b111..d399e22e46 100644 --- a/src/objective-c/examples/Sample/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme +++ b/src/objective-c/examples/Sample/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme @@ -1,6 +1,6 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) + gRPC.$(PRODUCT_NAME:rfc1034identifier) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/src/objective-c/tests/Tests.xcodeproj/project.pbxproj b/src/objective-c/tests/Tests.xcodeproj/project.pbxproj index 8dccbf0f72..c4a6567ae0 100644 --- a/src/objective-c/tests/Tests.xcodeproj/project.pbxproj +++ b/src/objective-c/tests/Tests.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 48; + objectVersion = 46; objects = { /* Begin PBXBuildFile section */ @@ -535,7 +535,7 @@ 635697BF1B14FC11007A7283 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0630; ORGANIZATIONNAME = gRPC; TargetAttributes = { 5E8A5DA31D3840B4000F8BC4 = { @@ -565,7 +565,7 @@ }; }; buildConfigurationList = 635697C21B14FC11007A7283 /* Build configuration list for PBXProject "Tests" */; - compatibilityVersion = "Xcode 8.0"; + compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( @@ -1151,10 +1151,8 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; @@ -1207,7 +1205,6 @@ ); INFOPLIST_FILE = Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "gRPC.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Cronet; @@ -1365,7 +1362,6 @@ ); INFOPLIST_FILE = Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "gRPC.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -1380,7 +1376,6 @@ ); INFOPLIST_FILE = Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "gRPC.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -1398,16 +1393,13 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -1444,10 +1436,8 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; diff --git a/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/AllTests.xcscheme b/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/AllTests.xcscheme index 740a1c0672..d1d616c4cf 100644 --- a/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/AllTests.xcscheme +++ b/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/AllTests.xcscheme @@ -1,6 +1,6 @@ Date: Thu, 20 Oct 2016 20:12:51 -0700 Subject: Moved unref of security connector outside of grpc_secure_channel_create --- src/core/ext/transport/chttp2/client/secure/secure_channel_create.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c index 31c54ff74c..cba7ec472a 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c @@ -290,8 +290,6 @@ static grpc_channel *client_channel_factory_create_channel( channel = NULL; } - GRPC_SECURITY_CONNECTOR_UNREF(&f->security_connector->base, - "client_channel_factory_create_channel"); return channel; } @@ -360,6 +358,9 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds, grpc_channel *channel = client_channel_factory_create_channel( &exec_ctx, &f->base, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, NULL); + GRPC_SECURITY_CONNECTOR_UNREF(&f->security_connector->base, + "client_channel_factory_create_channel"); + grpc_client_channel_factory_unref(&exec_ctx, &f->base); grpc_exec_ctx_finish(&exec_ctx); -- cgit v1.2.3