diff --git a/package.json b/package.json index 00c647ef3..e910715a5 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "all": true }, "scripts": { - "test": "nyc gulp test", + "test": "nyc gulp test && GRPC_DNS_RESOLVER=ares nyc gulp nativeTestOnly", "coverage": "nyc report --reporter=text-lcov | coveralls" } } diff --git a/packages/grpc-native-core/binding.gyp b/packages/grpc-native-core/binding.gyp index c27050242..11ecbf7f5 100644 --- a/packages/grpc-native-core/binding.gyp +++ b/packages/grpc-native-core/binding.gyp @@ -83,15 +83,20 @@ 'include_dirs': [ 'deps/grpc', 'deps/grpc/include', + 'deps/grpc/third_party/address_sorting/include', + 'deps/grpc/third_party/cares', + 'deps/grpc/third_party/cares/cares', 'deps/grpc/third_party/abseil-cpp', - 'deps/grpc/third_party/nanopb' + 'deps/grpc/third_party/nanopb', ], 'defines': [ 'PB_FIELD_32BIT', 'GPR_BACKWARDS_COMPATIBILITY_MODE', - 'GRPC_ARES=0', + 'GRPC_ARES=1', 'GRPC_UV', - 'GRPC_NODE_VERSION="1.22.0-dev"' + 'GRPC_NODE_VERSION="1.22.0-dev"', + 'CARES_STATICLIB', + 'CARES_SYMBOL_HIDING' ], 'defines!': [ 'OPENSSL_THREADS' @@ -156,8 +161,7 @@ }], ['OS == "win"', { "include_dirs": [ - "deps/grpc/third_party/zlib", - "deps/grpc/third_party/cares/cares" + "deps/grpc/third_party/zlib" ], "defines": [ '_WIN32_WINNT=0x0600', @@ -177,8 +181,7 @@ ] }, { # OS != "win" 'include_dirs': [ - '<(node_root_dir)/deps/zlib', - '<(node_root_dir)/deps/cares/include' + '<(node_root_dir)/deps/zlib' ] }], ['OS == "mac"', { @@ -561,6 +564,114 @@ }] ], 'targets': [ + { + 'target_name': 'ares', + 'product_prefix': 'lib', + 'type': 'static_library', + 'sources': [ + 'deps/grpc/third_party/cares/cares/ares__close_sockets.c', + 'deps/grpc/third_party/cares/cares/ares__get_hostent.c', + 'deps/grpc/third_party/cares/cares/ares__read_line.c', + 'deps/grpc/third_party/cares/cares/ares__timeval.c', + 'deps/grpc/third_party/cares/cares/ares_cancel.c', + 'deps/grpc/third_party/cares/cares/ares_create_query.c', + 'deps/grpc/third_party/cares/cares/ares_data.c', + 'deps/grpc/third_party/cares/cares/ares_destroy.c', + 'deps/grpc/third_party/cares/cares/ares_expand_name.c', + 'deps/grpc/third_party/cares/cares/ares_expand_string.c', + 'deps/grpc/third_party/cares/cares/ares_fds.c', + 'deps/grpc/third_party/cares/cares/ares_free_hostent.c', + 'deps/grpc/third_party/cares/cares/ares_free_string.c', + 'deps/grpc/third_party/cares/cares/ares_getenv.c', + 'deps/grpc/third_party/cares/cares/ares_gethostbyaddr.c', + 'deps/grpc/third_party/cares/cares/ares_gethostbyname.c', + 'deps/grpc/third_party/cares/cares/ares_getnameinfo.c', + 'deps/grpc/third_party/cares/cares/ares_getopt.c', + 'deps/grpc/third_party/cares/cares/ares_getsock.c', + 'deps/grpc/third_party/cares/cares/ares_init.c', + 'deps/grpc/third_party/cares/cares/ares_library_init.c', + 'deps/grpc/third_party/cares/cares/ares_llist.c', + 'deps/grpc/third_party/cares/cares/ares_mkquery.c', + 'deps/grpc/third_party/cares/cares/ares_nowarn.c', + 'deps/grpc/third_party/cares/cares/ares_options.c', + 'deps/grpc/third_party/cares/cares/ares_parse_a_reply.c', + 'deps/grpc/third_party/cares/cares/ares_parse_aaaa_reply.c', + 'deps/grpc/third_party/cares/cares/ares_parse_mx_reply.c', + 'deps/grpc/third_party/cares/cares/ares_parse_naptr_reply.c', + 'deps/grpc/third_party/cares/cares/ares_parse_ns_reply.c', + 'deps/grpc/third_party/cares/cares/ares_parse_ptr_reply.c', + 'deps/grpc/third_party/cares/cares/ares_parse_soa_reply.c', + 'deps/grpc/third_party/cares/cares/ares_parse_srv_reply.c', + 'deps/grpc/third_party/cares/cares/ares_parse_txt_reply.c', + 'deps/grpc/third_party/cares/cares/ares_platform.c', + 'deps/grpc/third_party/cares/cares/ares_process.c', + 'deps/grpc/third_party/cares/cares/ares_query.c', + 'deps/grpc/third_party/cares/cares/ares_search.c', + 'deps/grpc/third_party/cares/cares/ares_send.c', + 'deps/grpc/third_party/cares/cares/ares_strcasecmp.c', + 'deps/grpc/third_party/cares/cares/ares_strdup.c', + 'deps/grpc/third_party/cares/cares/ares_strerror.c', + 'deps/grpc/third_party/cares/cares/ares_strsplit.c', + 'deps/grpc/third_party/cares/cares/ares_timeout.c', + 'deps/grpc/third_party/cares/cares/ares_version.c', + 'deps/grpc/third_party/cares/cares/ares_writev.c', + 'deps/grpc/third_party/cares/cares/bitncmp.c', + 'deps/grpc/third_party/cares/cares/inet_net_pton.c', + 'deps/grpc/third_party/cares/cares/inet_ntop.c', + 'deps/grpc/third_party/cares/cares/windows_port.c', + ], + 'defines': [ + '_GNU_SOURCE' + ], + 'conditions': [ + ['OS == "mac"', { + 'xcode_settings': { + 'MACOSX_DEPLOYMENT_TARGET': '10.9' + }, + 'include_dirs': [ + 'deps/grpc/third_party/cares/config_darwin' + ], + 'defines': [ + 'HAVE_CONFIG_H' + ] + }], + ['OS == "linux"', { + 'include_dirs': [ + 'deps/grpc/third_party/cares/config_linux' + ], + 'defines': [ + 'HAVE_CONFIG_H' + ] + }], + ['OS == "win"', { + 'include_dirs': [ + 'deps/grpc/third_party/cares/config_windows' + ], + 'defines': [ + 'HAVE_CONFIG_H' + ] + }] + ] + }, + { + 'target_name': 'address_sorting', + 'product_prefix': 'lib', + 'type': 'static_library', + 'dependencies': [ + ], + 'sources': [ + 'deps/grpc/third_party/address_sorting/address_sorting.c', + 'deps/grpc/third_party/address_sorting/address_sorting_posix.c', + 'deps/grpc/third_party/address_sorting/address_sorting_windows.c', + ], + 'conditions': [ + ['OS == "mac"', { + 'xcode_settings': { + 'MACOSX_DEPLOYMENT_TARGET': '10.9' + } + }] + ] + }, { 'target_name': 'gpr', 'product_prefix': 'lib', @@ -1009,6 +1120,8 @@ "dependencies": [ "grpc", "gpr", + "ares", + "address_sorting" ] }, { diff --git a/packages/grpc-native-core/deps/grpc b/packages/grpc-native-core/deps/grpc index bb6a97b0c..64ec7201f 160000 --- a/packages/grpc-native-core/deps/grpc +++ b/packages/grpc-native-core/deps/grpc @@ -1 +1 @@ -Subproject commit bb6a97b0c8fc11a5c27b03e2058dc383bbfc1e64 +Subproject commit 64ec7201fd50c41a67ca3064833309f4e259cf06 diff --git a/packages/grpc-native-core/templates/binding.gyp.template b/packages/grpc-native-core/templates/binding.gyp.template index b5e54ff21..8c145d4aa 100644 --- a/packages/grpc-native-core/templates/binding.gyp.template +++ b/packages/grpc-native-core/templates/binding.gyp.template @@ -75,15 +75,20 @@ 'include_dirs': [ 'deps/grpc', 'deps/grpc/include', + 'deps/grpc/third_party/address_sorting/include', + 'deps/grpc/third_party/cares', + 'deps/grpc/third_party/cares/cares', 'deps/grpc/third_party/abseil-cpp', - 'deps/grpc/third_party/nanopb' + 'deps/grpc/third_party/nanopb', ], 'defines': [ 'PB_FIELD_32BIT', 'GPR_BACKWARDS_COMPATIBILITY_MODE', - 'GRPC_ARES=0', + 'GRPC_ARES=1', 'GRPC_UV', - 'GRPC_NODE_VERSION="${settings.get('node_version', settings.version)}"' + 'GRPC_NODE_VERSION="${settings.get('node_version', settings.version)}"', + 'CARES_STATICLIB', + 'CARES_SYMBOL_HIDING' ], 'defines!': [ 'OPENSSL_THREADS' @@ -140,8 +145,7 @@ }], ['OS == "win"', { "include_dirs": [ - "deps/grpc/third_party/zlib", - "deps/grpc/third_party/cares/cares" + "deps/grpc/third_party/zlib" ], "defines": [ '_WIN32_WINNT=0x0600', @@ -161,8 +165,7 @@ ] }, { # OS != "win" 'include_dirs': [ - '<(node_root_dir)/deps/zlib', - '<(node_root_dir)/deps/cares/include' + '<(node_root_dir)/deps/zlib' ] }], ['OS == "mac"', { @@ -279,8 +282,54 @@ }] ], 'targets': [ + % for lib in libs: + % if lib.name == 'ares': + { + 'target_name': '${lib.name}', + 'product_prefix': 'lib', + 'type': 'static_library', + 'sources': [ + % for source in lib.src: + 'deps/grpc/${source}', + % endfor + ], + 'defines': [ + '_GNU_SOURCE' + ], + 'conditions': [ + ['OS == "mac"', { + 'xcode_settings': { + 'MACOSX_DEPLOYMENT_TARGET': '10.9' + }, + 'include_dirs': [ + 'deps/grpc/third_party/cares/config_darwin' + ], + 'defines': [ + 'HAVE_CONFIG_H' + ] + }], + ['OS == "linux"', { + 'include_dirs': [ + 'deps/grpc/third_party/cares/config_linux' + ], + 'defines': [ + 'HAVE_CONFIG_H' + ] + }], + ['OS == "win"', { + 'include_dirs': [ + 'deps/grpc/third_party/cares/config_windows' + ], + 'defines': [ + 'HAVE_CONFIG_H' + ] + }] + ] + }, + % endif + % endfor % for core in libs: - % if core.name == 'grpc': + % if core.name == 'grpc' or core.name == 'address_sorting': % for lib in libs: % if lib.name == core.name or (lib.name in core.transitive_deps and lib.name not in ('boringssl', 'z')): { @@ -347,6 +396,8 @@ "dependencies": [ "grpc", "gpr", + "ares", + "address_sorting" ] }, { diff --git a/packages/grpc-native-core/test/resolver_test.js b/packages/grpc-native-core/test/resolver_test.js new file mode 100644 index 000000000..e9532857a --- /dev/null +++ b/packages/grpc-native-core/test/resolver_test.js @@ -0,0 +1,73 @@ +/* + * + * Copyright 2019 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +'use strict'; + +var assert = require('assert'); +var _ = require('lodash'); + +var grpc = require('..'); + +const insecureCreds = grpc.credentials.createInsecure(); + +describe('Name resolver', function() { + let server; + let port; + before(function(done) { + const insecureServerCreds = grpc.ServerCredentials.createInsecure(); + server = new grpc.Server(); + server.bindAsync('localhost:0', insecureServerCreds, (error, portVal) => { + port = portVal; + done(error); + }); + }); + after(function() { + server.forceShutdown(); + }); + // This test also seems to have problems with the native resolver on Windows + it.skip('Should resolve a target to IPv4 addresses', function(done) { + const client = new grpc.Client(`loopback4.unittest.grpc.io:${port}`, insecureCreds); + let deadline = new Date(); + deadline.setSeconds(deadline.getSeconds() + 1); + client.waitForReady(deadline, (error) => { + assert.ifError(error); + done(); + }); + }); + /* This test doesn't work with the native resolver on Windows on our test + * machines because they don't have IPv6 addresses, so Windows omits IPv6 + * addresses from getaddrinfo results. */ + it.skip('Should resolve a target to IPv6 addresses', function(done) { + const client = new grpc.Client(`loopback6.unittest.grpc.io:${port}`, insecureCreds); + let deadline = new Date(); + deadline.setSeconds(deadline.getSeconds() + 1); + client.waitForReady(deadline, (error) => { + assert.ifError(error); + done(); + }); + }); + it('Should resolve a target to IPv4 and IPv6 addresses', function(done) { + const client = new grpc.Client(`loopback46.unittest.grpc.io:${port}`, insecureCreds); + let deadline = new Date(); + deadline.setSeconds(deadline.getSeconds() + 1); + client.waitForReady(deadline, (error) => { + assert.ifError(error); + done(); + }); + }); +}); \ No newline at end of file diff --git a/run-tests.bat b/run-tests.bat index fa2b71833..d2484ae35 100644 --- a/run-tests.bat +++ b/run-tests.bat @@ -56,6 +56,7 @@ for %%v in (6 7 8 9 10 11 12) do ( call .\node_modules\.bin\gulp cleanAll || SET FAILED=1 call .\node_modules\.bin\gulp setupWindows || SET FAILED=1 call .\node_modules\.bin\gulp test || SET FAILED=1 + cmd.exe /c "SET GRPC_DNS_RESOLVER=ares& call .\node_modules\.bin\gulp nativeTestOnly" || SET FAILED=1 ) node merge_kokoro_logs.js