diff options
author | Craig Tiller <ctiller@google.com> | 2016-03-31 13:08:49 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2016-03-31 13:08:49 -0700 |
commit | 65938df105732f9be3d379b69fbea91262761a23 (patch) | |
tree | 767c01531730de178d9a6f50ce0a31154da4d5b9 /src | |
parent | f3f099ada9dedd941e5a3f7a506a8152bab34a93 (diff) |
Optionalize name resolvers
Diffstat (limited to 'src')
15 files changed, 66 insertions, 164 deletions
diff --git a/src/core/ext/resolver/dns/native/README.md b/src/core/ext/resolver/dns/native/README.md new file mode 100644 index 0000000000..695de47b9f --- /dev/null +++ b/src/core/ext/resolver/dns/native/README.md @@ -0,0 +1,2 @@ +dns: scheme name resolution, using getaddrbyname +(or other OS specific implementation) diff --git a/src/core/lib/client_config/resolvers/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 62bccdd045..60028848bb 100644 --- a/src/core/lib/client_config/resolvers/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -31,8 +31,6 @@ * */ -#include "src/core/lib/client_config/resolvers/dns_resolver.h" - #include <string.h> #include <grpc/support/alloc.h> @@ -40,6 +38,7 @@ #include <grpc/support/string_util.h> #include "src/core/lib/client_config/lb_policy_registry.h" +#include "src/core/lib/client_config/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" @@ -277,8 +276,8 @@ static grpc_resolver *dns_factory_create_resolver( return dns_create(args, "https", "pick_first"); } -char *dns_factory_get_default_host_name(grpc_resolver_factory *factory, - grpc_uri *uri) { +static char *dns_factory_get_default_host_name(grpc_resolver_factory *factory, + grpc_uri *uri) { const char *path = uri->path; if (path[0] == '/') ++path; return gpr_strdup(path); @@ -289,6 +288,12 @@ static const grpc_resolver_factory_vtable dns_factory_vtable = { dns_factory_get_default_host_name, "dns"}; static grpc_resolver_factory dns_resolver_factory = {&dns_factory_vtable}; -grpc_resolver_factory *grpc_dns_resolver_factory_create() { +static grpc_resolver_factory *dns_resolver_factory_create() { return &dns_resolver_factory; } + +void grpc_resolver_dns_native_init(void) { + grpc_register_resolver_type(dns_resolver_factory_create()); +} + +void grpc_resolver_dns_native_shutdown(void) {} diff --git a/src/core/ext/resolver/sockaddr/README.md b/src/core/ext/resolver/sockaddr/README.md new file mode 100644 index 0000000000..e307ba88f5 --- /dev/null +++ b/src/core/ext/resolver/sockaddr/README.md @@ -0,0 +1 @@ +Support for resolving ipv4:, ipv6:, unix: schemes diff --git a/src/core/lib/client_config/resolvers/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index c787bd57d6..a416f10dcb 100644 --- a/src/core/lib/client_config/resolvers/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -33,8 +33,6 @@ #include <grpc/support/port_platform.h> -#include "src/core/lib/client_config/resolvers/sockaddr_resolver.h" - #include <stdio.h> #include <string.h> @@ -43,6 +41,7 @@ #include <grpc/support/string_util.h> #include "src/core/lib/client_config/lb_policy_registry.h" +#include "src/core/lib/client_config/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" @@ -343,12 +342,20 @@ static void sockaddr_factory_unref(grpc_resolver_factory *factory) {} name##_factory_create_resolver, prefix##name##_get_default_authority, \ #name}; \ static grpc_resolver_factory name##_resolver_factory = { \ - &name##_factory_vtable}; \ - grpc_resolver_factory *grpc_##name##_resolver_factory_create() { \ - return &name##_resolver_factory; \ - } + &name##_factory_vtable} #ifdef GPR_HAVE_UNIX_SOCKET -DECL_FACTORY(unix, grpc_) +DECL_FACTORY(unix, grpc_); #endif -DECL_FACTORY(ipv4, ) DECL_FACTORY(ipv6, ) +DECL_FACTORY(ipv4, ); +DECL_FACTORY(ipv6, ); + +void grpc_resolver_sockaddr_init(void) { + grpc_register_resolver_type(&ipv4_resolver_factory); + grpc_register_resolver_type(&ipv6_resolver_factory); +#ifdef GPR_HAVE_UNIX_SOCKET + grpc_register_resolver_type(&unix_resolver_factory); +#endif +} + +void grpc_resolver_sockaddr_shutdown(void) {} diff --git a/src/core/ext/resolver/zookeeper/README.md b/src/core/ext/resolver/zookeeper/README.md new file mode 100644 index 0000000000..ce6f39683b --- /dev/null +++ b/src/core/ext/resolver/zookeeper/README.md @@ -0,0 +1 @@ +Zookeeper based name resolver: WIP diff --git a/src/core/lib/client_config/resolvers/zookeeper_resolver.c b/src/core/ext/resolver/zookeeper/zookeeper_resolver.c index 404dfcd423..404dfcd423 100644 --- a/src/core/lib/client_config/resolvers/zookeeper_resolver.c +++ b/src/core/ext/resolver/zookeeper/zookeeper_resolver.c diff --git a/src/core/lib/client_config/resolver_registry.c b/src/core/lib/client_config/resolver_registry.c index 29bd00c284..fd49d49abc 100644 --- a/src/core/lib/client_config/resolver_registry.c +++ b/src/core/lib/client_config/resolver_registry.c @@ -70,14 +70,11 @@ void grpc_register_resolver_type(grpc_resolver_factory *factory) { g_all_of_the_resolvers[g_number_of_resolvers++] = factory; } -static grpc_resolver_factory *lookup_factory(grpc_uri *uri) { +static grpc_resolver_factory *lookup_factory(const char *name) { int i; - /* handling NULL uri's here simplifies grpc_resolver_create */ - if (!uri) return NULL; - for (i = 0; i < g_number_of_resolvers; i++) { - if (0 == strcmp(uri->scheme, g_all_of_the_resolvers[i]->vtable->scheme)) { + if (0 == strcmp(name, g_all_of_the_resolvers[i]->vtable->scheme)) { return g_all_of_the_resolvers[i]; } } @@ -85,6 +82,17 @@ static grpc_resolver_factory *lookup_factory(grpc_uri *uri) { 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; @@ -92,13 +100,13 @@ static grpc_resolver_factory *resolve_factory(const char *target, GPR_ASSERT(uri != NULL); *uri = grpc_uri_parse(target, 1); - factory = lookup_factory(*uri); + 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(*uri); + 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)); diff --git a/src/core/lib/client_config/resolver_registry.h b/src/core/lib/client_config/resolver_registry.h index 22289ca6bd..7d7009b9cd 100644 --- a/src/core/lib/client_config/resolver_registry.h +++ b/src/core/lib/client_config/resolver_registry.h @@ -58,6 +58,10 @@ void grpc_register_resolver_type(grpc_resolver_factory *factory); grpc_resolver *grpc_resolver_create( const char *target, grpc_subchannel_factory *subchannel_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); diff --git a/src/core/lib/client_config/resolvers/dns_resolver.h b/src/core/lib/client_config/resolvers/dns_resolver.h deleted file mode 100644 index eb46e41c77..0000000000 --- a/src/core/lib/client_config/resolvers/dns_resolver.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * Copyright 2015-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_LIB_CLIENT_CONFIG_RESOLVERS_DNS_RESOLVER_H -#define GRPC_CORE_LIB_CLIENT_CONFIG_RESOLVERS_DNS_RESOLVER_H - -#include "src/core/lib/client_config/resolver_factory.h" - -/** Create a dns resolver factory */ -grpc_resolver_factory *grpc_dns_resolver_factory_create(void); - -#endif /* GRPC_CORE_LIB_CLIENT_CONFIG_RESOLVERS_DNS_RESOLVER_H */ diff --git a/src/core/lib/client_config/resolvers/sockaddr_resolver.h b/src/core/lib/client_config/resolvers/sockaddr_resolver.h deleted file mode 100644 index 45c55bd160..0000000000 --- a/src/core/lib/client_config/resolvers/sockaddr_resolver.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * Copyright 2015-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_LIB_CLIENT_CONFIG_RESOLVERS_SOCKADDR_RESOLVER_H -#define GRPC_CORE_LIB_CLIENT_CONFIG_RESOLVERS_SOCKADDR_RESOLVER_H - -#include <grpc/support/port_platform.h> - -#include "src/core/lib/client_config/resolver_factory.h" - -grpc_resolver_factory *grpc_ipv4_resolver_factory_create(void); - -grpc_resolver_factory *grpc_ipv6_resolver_factory_create(void); - -#ifdef GPR_POSIX_SOCKET -/** Create a unix resolver factory */ -grpc_resolver_factory *grpc_unix_resolver_factory_create(void); -#endif - -#endif /* GRPC_CORE_LIB_CLIENT_CONFIG_RESOLVERS_SOCKADDR_RESOLVER_H */ diff --git a/src/core/lib/client_config/resolvers/zookeeper_resolver.h b/src/core/lib/client_config/resolvers/zookeeper_resolver.h deleted file mode 100644 index 7ee7604360..0000000000 --- a/src/core/lib/client_config/resolvers/zookeeper_resolver.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * Copyright 2015-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_LIB_CLIENT_CONFIG_RESOLVERS_ZOOKEEPER_RESOLVER_H -#define GRPC_CORE_LIB_CLIENT_CONFIG_RESOLVERS_ZOOKEEPER_RESOLVER_H - -#include "src/core/lib/client_config/resolver_factory.h" - -/** Create a zookeeper resolver factory */ -grpc_resolver_factory *grpc_zookeeper_resolver_factory_create(void); - -#endif /* GRPC_CORE_LIB_CLIENT_CONFIG_RESOLVERS_ZOOKEEPER_RESOLVER_H */ diff --git a/src/core/lib/surface/init.c b/src/core/lib/surface/init.c index 786bf1d5da..51d9625e2a 100644 --- a/src/core/lib/surface/init.c +++ b/src/core/lib/surface/init.c @@ -48,8 +48,6 @@ #include "src/core/lib/channel/http_server_filter.h" #include "src/core/lib/client_config/lb_policy_registry.h" #include "src/core/lib/client_config/resolver_registry.h" -#include "src/core/lib/client_config/resolvers/dns_resolver.h" -#include "src/core/lib/client_config/resolvers/sockaddr_resolver.h" #include "src/core/lib/client_config/subchannel.h" #include "src/core/lib/client_config/subchannel_index.h" #include "src/core/lib/debug/trace.h" @@ -165,12 +163,6 @@ void grpc_init(void) { grpc_channel_init_init(); grpc_lb_policy_registry_init(); grpc_resolver_registry_init(GRPC_DEFAULT_NAME_PREFIX); - grpc_register_resolver_type(grpc_dns_resolver_factory_create()); - grpc_register_resolver_type(grpc_ipv4_resolver_factory_create()); - grpc_register_resolver_type(grpc_ipv6_resolver_factory_create()); -#ifdef GPR_HAVE_UNIX_SOCKET - grpc_register_resolver_type(grpc_unix_resolver_factory_create()); -#endif grpc_register_tracer("api", &grpc_api_trace); grpc_register_tracer("channel", &grpc_trace_channel); grpc_register_tracer("http", &grpc_http_trace); diff --git a/src/core/plugin_registry/grpc_plugin_registry.c b/src/core/plugin_registry/grpc_plugin_registry.c index 422d3c92b8..79df85516e 100644 --- a/src/core/plugin_registry/grpc_plugin_registry.c +++ b/src/core/plugin_registry/grpc_plugin_registry.c @@ -37,6 +37,10 @@ extern void grpc_lb_policy_pick_first_init(void); extern void grpc_lb_policy_pick_first_shutdown(void); extern void grpc_lb_policy_round_robin_init(void); extern void grpc_lb_policy_round_robin_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); +extern void grpc_resolver_sockaddr_shutdown(void); extern void census_grpc_plugin_init(void); extern void census_grpc_plugin_shutdown(void); @@ -45,6 +49,10 @@ void grpc_register_built_in_plugins(void) { grpc_lb_policy_pick_first_shutdown); grpc_register_plugin(grpc_lb_policy_round_robin_init, grpc_lb_policy_round_robin_shutdown); + grpc_register_plugin(grpc_resolver_dns_native_init, + grpc_resolver_dns_native_shutdown); + grpc_register_plugin(grpc_resolver_sockaddr_init, + grpc_resolver_sockaddr_shutdown); grpc_register_plugin(census_grpc_plugin_init, census_grpc_plugin_shutdown); } diff --git a/src/core/plugin_registry/grpc_unsecure_plugin_registry.c b/src/core/plugin_registry/grpc_unsecure_plugin_registry.c index 422d3c92b8..b3786c927d 100644 --- a/src/core/plugin_registry/grpc_unsecure_plugin_registry.c +++ b/src/core/plugin_registry/grpc_unsecure_plugin_registry.c @@ -33,6 +33,10 @@ #include <grpc/grpc.h> +extern void grpc_resolver_dns_native_init(void); +extern void grpc_resolver_dns_native_shutdown(void); +extern void grpc_resolver_sockaddr_init(void); +extern void grpc_resolver_sockaddr_shutdown(void); extern void grpc_lb_policy_pick_first_init(void); extern void grpc_lb_policy_pick_first_shutdown(void); extern void grpc_lb_policy_round_robin_init(void); @@ -41,6 +45,10 @@ extern void census_grpc_plugin_init(void); extern void census_grpc_plugin_shutdown(void); void grpc_register_built_in_plugins(void) { + grpc_register_plugin(grpc_resolver_dns_native_init, + grpc_resolver_dns_native_shutdown); + grpc_register_plugin(grpc_resolver_sockaddr_init, + grpc_resolver_sockaddr_shutdown); grpc_register_plugin(grpc_lb_policy_pick_first_init, grpc_lb_policy_pick_first_shutdown); grpc_register_plugin(grpc_lb_policy_round_robin_init, diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 0a516ed534..882ce0bb03 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -87,6 +87,8 @@ CORE_SOURCE_FILES = [ 'src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0/load_balancer.pb.c', 'src/core/ext/lb_policy/pick_first/pick_first.c', 'src/core/ext/lb_policy/round_robin/round_robin.c', + 'src/core/ext/resolver/dns/native/dns_resolver.c', + 'src/core/ext/resolver/sockaddr/sockaddr_resolver.c', 'src/core/ext/transport/chttp2/client/insecure/channel_create.c', 'src/core/ext/transport/chttp2/client/secure/secure_channel_create.c', 'src/core/ext/transport/chttp2/server/insecure/server_chttp2.c', @@ -131,8 +133,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/client_config/resolver.c', 'src/core/lib/client_config/resolver_factory.c', 'src/core/lib/client_config/resolver_registry.c', - 'src/core/lib/client_config/resolvers/dns_resolver.c', - 'src/core/lib/client_config/resolvers/sockaddr_resolver.c', 'src/core/lib/client_config/subchannel.c', 'src/core/lib/client_config/subchannel_factory.c', 'src/core/lib/client_config/subchannel_index.c', |