Merge branch 'cares_fork' into cares

pull/7654/head
Yuchen Zeng 9 years ago
commit 21e0a61528
  1. 6
      include/grpc/impl/codegen/port_platform.h
  2. 2
      package.json
  3. 7
      setup.py
  4. 1
      src/c-ares/gen_build_yaml.py
  5. 29
      src/core/ext/resolver/dns/c_ares/dns_resolver.c
  6. 5
      src/core/ext/resolver/dns/c_ares/grpc_ares_ev_driver.h
  7. 4
      src/core/ext/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c
  8. 36
      src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.c
  9. 17
      src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.h
  10. 2
      templates/package.json.template
  11. 12
      test/core/end2end/fuzzers/api_fuzzer.c
  12. 2
      tools/run_tests/sources_and_headers.json
  13. 2
      vsprojects/vcxproj/ares/ares.vcxproj
  14. 2
      vsprojects/vcxproj/ares/ares.vcxproj.filters

@ -431,6 +431,12 @@ typedef unsigned __int64 uint64_t;
power of two */
#define GPR_MAX_ALIGNMENT 16
#ifdef GPR_WINDOWS
#ifndef GRPC_NATIVE_ADDRESS_RESOLVE
#define GRPC_NATIVE_ADDRESS_RESOLVE
#endif
#endif
#ifndef GRPC_MUST_USE_RESULT
#ifdef __GNUC__
#define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result))

@ -23,7 +23,7 @@
"test": "./node_modules/.bin/mocha src/node/test && npm run-script lint",
"gen_docs": "./node_modules/.bin/jsdoc -c src/node/jsdoc_conf.json",
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha src/node/test",
"install": "./node_modules/.bin/node-pre-gyp install --fallback-to-build --library='static_library'"
"install": "./node_modules/.bin/node-pre-gyp install --fallback-to-build --library=static_library"
},
"bundledDependencies": ["node-pre-gyp"],
"dependencies": {

@ -148,11 +148,14 @@ if "win32" in sys.platform:
DEFINE_MACROS = (
('OPENSSL_NO_ASM', 1), ('_WIN32_WINNT', 0x600),
('GPR_BACKWARDS_COMPATIBILITY_MODE', 1), ('HAVE_CONFIG_H', 1),)
('GPR_BACKWARDS_COMPATIBILITY_MODE', 1),)
if "win32" in sys.platform:
DEFINE_MACROS += (('OPENSSL_WINDOWS', 1), ('WIN32_LEAN_AND_MEAN', 1),)
DEFINE_MACROS += (('OPENSSL_WINDOWS', 1), ('WIN32_LEAN_AND_MEAN', 1),
('CARES_STATICLIB', 1),)
if '64bit' in platform.architecture()[0]:
DEFINE_MACROS += (('MS_WIN64', 1),)
else:
DEFINE_MACROS += (('HAVE_CONFIG_H', 1),)
LDFLAGS = tuple(EXTRA_LINK_ARGS)
CFLAGS = tuple(EXTRA_COMPILE_ARGS)

@ -136,6 +136,7 @@ try:
"third_party/c-ares/ares_strdup.h",
"third_party/c-ares/ares_version.h",
"third_party/c-ares/bitncmp.h",
"third_party/c-ares/config-win32.h",
"third_party/c-ares/setup_once.h",
"src/c-ares/ares_build.h",
"src/c-ares/config_linux/ares_config.h",

@ -88,8 +88,6 @@ typedef struct {
/** currently resolving addresses */
grpc_resolved_addresses *addresses;
grpc_ares_request *request;
grpc_polling_entity *pollent;
} dns_resolver;
@ -229,19 +227,25 @@ static void dns_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
gpr_log(GPR_ERROR, "dns_start_resolving_locked");
GRPC_RESOLVER_REF(&r->base, "dns-resolving");
GPR_ASSERT(!r->resolving);
r->resolving = 1;
r->addresses = NULL;
r->pollent = NULL;
#ifdef GRPC_NATIVE_ADDRESS_RESOLVE
grpc_resolve_address(exec_ctx, r->name, r->default_port,
grpc_closure_create(dns_on_resolved, r),
&r->addresses);
#else
if (pollent) {
r->pollent = pollent;
grpc_polling_entity_add_to_pollset_set(exec_ctx, pollent,
r->base.pollset_set);
} else {
gpr_log(GPR_ERROR, "pollent is NULL");
r->pollent = NULL;
}
r->resolving = 1;
r->addresses = NULL;
r->request = grpc_resolve_address_ares(
grpc_resolve_address_ares(
exec_ctx, r->name, r->default_port, r->base.pollset_set,
grpc_closure_create(dns_on_resolved, r), &r->addresses);
#endif
} else {
dns_maybe_finish_next_locked(exec_ctx, r);
}
@ -255,9 +259,14 @@ static void dns_start_resolving_locked(grpc_exec_ctx *exec_ctx,
GPR_ASSERT(!r->resolving);
r->resolving = 1;
r->addresses = NULL;
r->request = grpc_resolve_address_ares(
#ifdef GRPC_NATIVE_ADDRESS_RESOLVE
grpc_resolve_address(exec_ctx, r->name, r->default_port,
grpc_closure_create(dns_on_resolved, r), &r->addresses);
#else
grpc_resolve_address_ares(
exec_ctx, r->name, r->default_port, r->base.pollset_set,
grpc_closure_create(dns_on_resolved, r), &r->addresses);
#endif
// grpc_resolve_address(exec_ctx, r->name, r->default_port,
// grpc_closure_create(dns_on_resolved, r), &r->addresses);
}
@ -279,7 +288,9 @@ static void dns_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
dns_resolver *r = (dns_resolver *)gr;
gpr_mu_destroy(&r->mu);
#ifndef GRPC_NATIVE_ADDRESS_RESOLVE
grpc_ares_cleanup();
#endif
if (r->resolved_config) {
grpc_client_config_unref(exec_ctx, r->resolved_config);
}
@ -294,7 +305,7 @@ static grpc_resolver *dns_create(grpc_resolver_args *args,
const char *default_port,
const char *lb_policy_name) {
dns_resolver *r;
grpc_error *error;
grpc_error *error = GRPC_ERROR_NONE;
const char *path = args->uri->path;
if (0 != strcmp(args->uri->authority, "")) {
@ -302,7 +313,9 @@ static grpc_resolver *dns_create(grpc_resolver_args *args,
return NULL;
}
#ifndef GRPC_NATIVE_ADDRESS_RESOLVE
error = grpc_ares_init();
#endif
if (error != GRPC_ERROR_NONE) {
GRPC_LOG_IF_ERROR("ares_library_init() failed", error);
return NULL;

@ -34,6 +34,9 @@
#ifndef GRPC_CORE_EXT_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H
#define GRPC_CORE_EXT_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H
#include <grpc/support/port_platform.h>
#ifndef GRPC_NATIVE_ADDRESS_RESOLVE
#include <ares.h>
#include "src/core/lib/iomgr/exec_ctx.h"
@ -51,4 +54,6 @@ grpc_error *grpc_ares_ev_driver_create(grpc_ares_ev_driver **ev_driver,
grpc_pollset_set *pollset_set);
void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver *ev_driver);
#endif /* GRPC_NATIVE_ADDRESS_RESOLVE */
#endif /* GRPC_CORE_EXT_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H */

@ -31,6 +31,7 @@
*
*/
#include <grpc/support/port_platform.h>
#ifndef GRPC_NATIVE_ADDRESS_RESOLVE
#ifdef GPR_POSIX_SOCKET
#include "src/core/ext/resolver/dns/c_ares/grpc_ares_ev_driver.h"
@ -200,4 +201,5 @@ void grpc_ares_notify_on_event(grpc_exec_ctx *exec_ctx,
gpr_log(GPR_ERROR, "eof notify_on_event");
}
#endif
#endif /* GPR_POSIX_SOCKET */
#endif /* GRPC_NATIVE_ADDRESS_RESOLVE */

@ -32,18 +32,10 @@
*/
#include <grpc/support/port_platform.h>
#ifdef GPR_POSIX_SOCKET
#include <arpa/inet.h>
#endif
#ifdef GPR_WINSOCK_SOCKET
#include <winsock2.h>
#endif
#ifndef GRPC_NATIVE_ADDRESS_RESOLVE
#include "src/core/ext/resolver/dns/c_ares/grpc_ares_wrapper.h"
// #include "src/core/lib/iomgr/ev_posix.h"
// #include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include <string.h>
#include <sys/types.h>
@ -67,7 +59,7 @@
static gpr_once g_basic_init = GPR_ONCE_INIT;
static gpr_mu g_init_mu;
struct grpc_ares_request {
typedef struct grpc_ares_request {
char *name;
char *host;
char *port;
@ -79,7 +71,7 @@ struct grpc_ares_request {
void *arg;
int pending_quries;
grpc_ares_ev_driver *ev_driver;
};
} grpc_ares_request;
static void do_basic_init(void) { gpr_mu_init(&g_init_mu); }
@ -237,10 +229,11 @@ static int try_fake_resolve(const char *name, const char *port,
return 0;
}
grpc_ares_request *grpc_resolve_address_ares_impl(
grpc_exec_ctx *exec_ctx, const char *name, const char *default_port,
grpc_pollset_set *pollset_set, grpc_closure *on_done,
grpc_resolved_addresses **addrs) {
void grpc_resolve_address_ares_impl(grpc_exec_ctx *exec_ctx, const char *name,
const char *default_port,
grpc_pollset_set *pollset_set,
grpc_closure *on_done,
grpc_resolved_addresses **addrs) {
char *host;
char *port;
grpc_error *err;
@ -250,7 +243,7 @@ grpc_ares_request *grpc_resolve_address_ares_impl(
if ((err = grpc_customized_resolve_address(name, default_port, addrs)) !=
GRPC_ERROR_CANCELLED) {
grpc_exec_ctx_sched(exec_ctx, on_done, err, NULL);
return NULL;
return;
}
if (name[0] == 'u' && name[1] == 'n' && name[2] == 'i' && name[3] == 'x' &&
@ -258,7 +251,7 @@ grpc_ares_request *grpc_resolve_address_ares_impl(
grpc_exec_ctx_sched(exec_ctx, on_done,
grpc_resolve_unix_domain_address(name + 5, addrs),
NULL);
return NULL;
return;
}
/* parse name, splitting it into host and port parts */
@ -284,7 +277,7 @@ grpc_ares_request *grpc_resolve_address_ares_impl(
err = grpc_ares_ev_driver_create(&ev_driver, pollset_set);
if (err != GRPC_ERROR_NONE) {
grpc_exec_ctx_sched(exec_ctx, on_done, err, NULL);
return NULL;
return;
}
r = gpr_malloc(sizeof(grpc_ares_request));
r->ev_driver = ev_driver;
@ -302,10 +295,9 @@ grpc_ares_request *grpc_resolve_address_ares_impl(
done:
gpr_free(host);
gpr_free(port);
return r;
}
grpc_ares_request *(*grpc_resolve_address_ares)(
void (*grpc_resolve_address_ares)(
grpc_exec_ctx *exec_ctx, const char *name, const char *default_port,
grpc_pollset_set *pollset_set, grpc_closure *on_done,
grpc_resolved_addresses **addrs) = grpc_resolve_address_ares_impl;
@ -327,3 +319,5 @@ void grpc_ares_cleanup(void) {
ares_library_cleanup();
gpr_mu_unlock(&g_init_mu);
}
#endif /* GRPC_NATIVE_ADDRESS_RESOLVE */

@ -34,21 +34,28 @@
#ifndef GRPC_CORE_EXT_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H
#define GRPC_CORE_EXT_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H
#include <grpc/support/port_platform.h>
#ifndef GRPC_NATIVE_ADDRESS_RESOLVE
#include <stddef.h>
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/polling_entity.h"
#include "src/core/lib/iomgr/resolve_address.h"
typedef struct grpc_ares_request grpc_ares_request;
// typedef struct grpc_ares_request grpc_ares_request;
extern grpc_ares_request *(*grpc_resolve_address_ares)(
grpc_exec_ctx *exec_ctx, const char *addr, const char *default_port,
grpc_pollset_set *pollset_set, grpc_closure *on_done,
grpc_resolved_addresses **addresses);
extern void (*grpc_resolve_address_ares)(grpc_exec_ctx *exec_ctx,
const char *addr,
const char *default_port,
grpc_pollset_set *pollset_set,
grpc_closure *on_done,
grpc_resolved_addresses **addresses);
grpc_error *grpc_ares_init(void);
void grpc_ares_cleanup(void);
#endif /* GRPC_NATIVE_ADDRESS_RESOLVE */
#endif /* GRPC_CORE_EXT_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H */

@ -25,7 +25,7 @@
"test": "./node_modules/.bin/mocha src/node/test && npm run-script lint",
"gen_docs": "./node_modules/.bin/jsdoc -c src/node/jsdoc_conf.json",
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha src/node/test",
"install": "./node_modules/.bin/node-pre-gyp install --fallback-to-build --library='static_library'"
"install": "./node_modules/.bin/node-pre-gyp install --fallback-to-build --library=static_library"
},
"bundledDependencies": ["node-pre-gyp"],
"dependencies": {

@ -226,12 +226,12 @@ void my_resolve_address(grpc_exec_ctx *exec_ctx, const char *addr,
finish_resolve, r, gpr_now(GPR_CLOCK_MONOTONIC));
}
grpc_ares_request *my_resolve_address_async(
grpc_exec_ctx *exec_ctx, const char *addr, const char *default_port,
grpc_pollset_set *pollset_set, grpc_closure *on_done,
grpc_resolved_addresses **addresses) {
void my_resolve_address_async(grpc_exec_ctx *exec_ctx, const char *addr,
const char *default_port,
grpc_pollset_set *pollset_set,
grpc_closure *on_done,
grpc_resolved_addresses **addresses) {
my_resolve_address(exec_ctx, addr, default_port, on_done, addresses);
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
@ -516,7 +516,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (squelch) gpr_set_log_function(dont_log);
input_stream inp = {data, data + size};
grpc_resolve_address = my_resolve_address;
#ifndef GRPC_NATIVE_ADDRESS_RESOLVE
grpc_resolve_address_ares = my_resolve_address_async;
#endif
grpc_tcp_client_connect_impl = my_tcp_client_connect;
gpr_now_impl = now_impl;
grpc_init();

@ -5409,7 +5409,7 @@
"third_party/c-ares/ares_strdup.h",
"third_party/c-ares/ares_version.h",
"third_party/c-ares/bitncmp.h",
"third_party/c-ares/selectbridge.h",
"third_party/c-ares/config-win32.h",
"third_party/c-ares/setup_once.h"
],
"language": "c",

@ -166,7 +166,7 @@
<ClInclude Include="$(SolutionDir)\..\third_party\c-ares\ares_strdup.h" />
<ClInclude Include="$(SolutionDir)\..\third_party\c-ares\ares_version.h" />
<ClInclude Include="$(SolutionDir)\..\third_party\c-ares\bitncmp.h" />
<ClInclude Include="$(SolutionDir)\..\third_party\c-ares\selectbridge.h" />
<ClInclude Include="$(SolutionDir)\..\third_party\c-ares\config-win32.h" />
<ClInclude Include="$(SolutionDir)\..\third_party\c-ares\setup_once.h" />
<ClInclude Include="$(SolutionDir)\..\src\c-ares\ares_build.h" />
<ClInclude Include="$(SolutionDir)\..\src\c-ares\config_linux\ares_config.h" />

@ -207,7 +207,7 @@
<ClInclude Include="$(SolutionDir)\..\third_party\c-ares\bitncmp.h">
<Filter>third_party\c-ares</Filter>
</ClInclude>
<ClInclude Include="$(SolutionDir)\..\third_party\c-ares\selectbridge.h">
<ClInclude Include="$(SolutionDir)\..\third_party\c-ares\config-win32.h">
<Filter>third_party\c-ares</Filter>
</ClInclude>
<ClInclude Include="$(SolutionDir)\..\third_party\c-ares\setup_once.h">

Loading…
Cancel
Save