Skip to content

Commit 2e13f46

Browse files
authored
Merge pull request #864 from murgatroid99/native_cares_activation
Enable use of cares resolver
2 parents 7ffeafb + 863539c commit 2e13f46

File tree

6 files changed

+255
-17
lines changed

6 files changed

+255
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"all": true
6363
},
6464
"scripts": {
65-
"test": "nyc gulp test",
65+
"test": "nyc gulp test && GRPC_DNS_RESOLVER=ares nyc gulp nativeTestOnly",
6666
"coverage": "nyc report --reporter=text-lcov | coveralls"
6767
}
6868
}

packages/grpc-native-core/binding.gyp

Lines changed: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,20 @@
8383
'include_dirs': [
8484
'deps/grpc',
8585
'deps/grpc/include',
86+
'deps/grpc/third_party/address_sorting/include',
87+
'deps/grpc/third_party/cares',
88+
'deps/grpc/third_party/cares/cares',
8689
'deps/grpc/third_party/abseil-cpp',
87-
'deps/grpc/third_party/nanopb'
90+
'deps/grpc/third_party/nanopb',
8891
],
8992
'defines': [
9093
'PB_FIELD_32BIT',
9194
'GPR_BACKWARDS_COMPATIBILITY_MODE',
92-
'GRPC_ARES=0',
95+
'GRPC_ARES=1',
9396
'GRPC_UV',
94-
'GRPC_NODE_VERSION="1.22.0-dev"'
97+
'GRPC_NODE_VERSION="1.22.0-dev"',
98+
'CARES_STATICLIB',
99+
'CARES_SYMBOL_HIDING'
95100
],
96101
'defines!': [
97102
'OPENSSL_THREADS'
@@ -156,8 +161,7 @@
156161
}],
157162
['OS == "win"', {
158163
"include_dirs": [
159-
"deps/grpc/third_party/zlib",
160-
"deps/grpc/third_party/cares/cares"
164+
"deps/grpc/third_party/zlib"
161165
],
162166
"defines": [
163167
'_WIN32_WINNT=0x0600',
@@ -177,8 +181,7 @@
177181
]
178182
}, { # OS != "win"
179183
'include_dirs': [
180-
'<(node_root_dir)/deps/zlib',
181-
'<(node_root_dir)/deps/cares/include'
184+
'<(node_root_dir)/deps/zlib'
182185
]
183186
}],
184187
['OS == "mac"', {
@@ -561,6 +564,114 @@
561564
}]
562565
],
563566
'targets': [
567+
{
568+
'target_name': 'ares',
569+
'product_prefix': 'lib',
570+
'type': 'static_library',
571+
'sources': [
572+
'deps/grpc/third_party/cares/cares/ares__close_sockets.c',
573+
'deps/grpc/third_party/cares/cares/ares__get_hostent.c',
574+
'deps/grpc/third_party/cares/cares/ares__read_line.c',
575+
'deps/grpc/third_party/cares/cares/ares__timeval.c',
576+
'deps/grpc/third_party/cares/cares/ares_cancel.c',
577+
'deps/grpc/third_party/cares/cares/ares_create_query.c',
578+
'deps/grpc/third_party/cares/cares/ares_data.c',
579+
'deps/grpc/third_party/cares/cares/ares_destroy.c',
580+
'deps/grpc/third_party/cares/cares/ares_expand_name.c',
581+
'deps/grpc/third_party/cares/cares/ares_expand_string.c',
582+
'deps/grpc/third_party/cares/cares/ares_fds.c',
583+
'deps/grpc/third_party/cares/cares/ares_free_hostent.c',
584+
'deps/grpc/third_party/cares/cares/ares_free_string.c',
585+
'deps/grpc/third_party/cares/cares/ares_getenv.c',
586+
'deps/grpc/third_party/cares/cares/ares_gethostbyaddr.c',
587+
'deps/grpc/third_party/cares/cares/ares_gethostbyname.c',
588+
'deps/grpc/third_party/cares/cares/ares_getnameinfo.c',
589+
'deps/grpc/third_party/cares/cares/ares_getopt.c',
590+
'deps/grpc/third_party/cares/cares/ares_getsock.c',
591+
'deps/grpc/third_party/cares/cares/ares_init.c',
592+
'deps/grpc/third_party/cares/cares/ares_library_init.c',
593+
'deps/grpc/third_party/cares/cares/ares_llist.c',
594+
'deps/grpc/third_party/cares/cares/ares_mkquery.c',
595+
'deps/grpc/third_party/cares/cares/ares_nowarn.c',
596+
'deps/grpc/third_party/cares/cares/ares_options.c',
597+
'deps/grpc/third_party/cares/cares/ares_parse_a_reply.c',
598+
'deps/grpc/third_party/cares/cares/ares_parse_aaaa_reply.c',
599+
'deps/grpc/third_party/cares/cares/ares_parse_mx_reply.c',
600+
'deps/grpc/third_party/cares/cares/ares_parse_naptr_reply.c',
601+
'deps/grpc/third_party/cares/cares/ares_parse_ns_reply.c',
602+
'deps/grpc/third_party/cares/cares/ares_parse_ptr_reply.c',
603+
'deps/grpc/third_party/cares/cares/ares_parse_soa_reply.c',
604+
'deps/grpc/third_party/cares/cares/ares_parse_srv_reply.c',
605+
'deps/grpc/third_party/cares/cares/ares_parse_txt_reply.c',
606+
'deps/grpc/third_party/cares/cares/ares_platform.c',
607+
'deps/grpc/third_party/cares/cares/ares_process.c',
608+
'deps/grpc/third_party/cares/cares/ares_query.c',
609+
'deps/grpc/third_party/cares/cares/ares_search.c',
610+
'deps/grpc/third_party/cares/cares/ares_send.c',
611+
'deps/grpc/third_party/cares/cares/ares_strcasecmp.c',
612+
'deps/grpc/third_party/cares/cares/ares_strdup.c',
613+
'deps/grpc/third_party/cares/cares/ares_strerror.c',
614+
'deps/grpc/third_party/cares/cares/ares_strsplit.c',
615+
'deps/grpc/third_party/cares/cares/ares_timeout.c',
616+
'deps/grpc/third_party/cares/cares/ares_version.c',
617+
'deps/grpc/third_party/cares/cares/ares_writev.c',
618+
'deps/grpc/third_party/cares/cares/bitncmp.c',
619+
'deps/grpc/third_party/cares/cares/inet_net_pton.c',
620+
'deps/grpc/third_party/cares/cares/inet_ntop.c',
621+
'deps/grpc/third_party/cares/cares/windows_port.c',
622+
],
623+
'defines': [
624+
'_GNU_SOURCE'
625+
],
626+
'conditions': [
627+
['OS == "mac"', {
628+
'xcode_settings': {
629+
'MACOSX_DEPLOYMENT_TARGET': '10.9'
630+
},
631+
'include_dirs': [
632+
'deps/grpc/third_party/cares/config_darwin'
633+
],
634+
'defines': [
635+
'HAVE_CONFIG_H'
636+
]
637+
}],
638+
['OS == "linux"', {
639+
'include_dirs': [
640+
'deps/grpc/third_party/cares/config_linux'
641+
],
642+
'defines': [
643+
'HAVE_CONFIG_H'
644+
]
645+
}],
646+
['OS == "win"', {
647+
'include_dirs': [
648+
'deps/grpc/third_party/cares/config_windows'
649+
],
650+
'defines': [
651+
'HAVE_CONFIG_H'
652+
]
653+
}]
654+
]
655+
},
656+
{
657+
'target_name': 'address_sorting',
658+
'product_prefix': 'lib',
659+
'type': 'static_library',
660+
'dependencies': [
661+
],
662+
'sources': [
663+
'deps/grpc/third_party/address_sorting/address_sorting.c',
664+
'deps/grpc/third_party/address_sorting/address_sorting_posix.c',
665+
'deps/grpc/third_party/address_sorting/address_sorting_windows.c',
666+
],
667+
'conditions': [
668+
['OS == "mac"', {
669+
'xcode_settings': {
670+
'MACOSX_DEPLOYMENT_TARGET': '10.9'
671+
}
672+
}]
673+
]
674+
},
564675
{
565676
'target_name': 'gpr',
566677
'product_prefix': 'lib',
@@ -1009,6 +1120,8 @@
10091120
"dependencies": [
10101121
"grpc",
10111122
"gpr",
1123+
"ares",
1124+
"address_sorting"
10121125
]
10131126
},
10141127
{
Submodule grpc updated 91 files

packages/grpc-native-core/templates/binding.gyp.template

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,20 @@
7575
'include_dirs': [
7676
'deps/grpc',
7777
'deps/grpc/include',
78+
'deps/grpc/third_party/address_sorting/include',
79+
'deps/grpc/third_party/cares',
80+
'deps/grpc/third_party/cares/cares',
7881
'deps/grpc/third_party/abseil-cpp',
79-
'deps/grpc/third_party/nanopb'
82+
'deps/grpc/third_party/nanopb',
8083
],
8184
'defines': [
8285
'PB_FIELD_32BIT',
8386
'GPR_BACKWARDS_COMPATIBILITY_MODE',
84-
'GRPC_ARES=0',
87+
'GRPC_ARES=1',
8588
'GRPC_UV',
86-
'GRPC_NODE_VERSION="${settings.get('node_version', settings.version)}"'
89+
'GRPC_NODE_VERSION="${settings.get('node_version', settings.version)}"',
90+
'CARES_STATICLIB',
91+
'CARES_SYMBOL_HIDING'
8792
],
8893
'defines!': [
8994
'OPENSSL_THREADS'
@@ -140,8 +145,7 @@
140145
}],
141146
['OS == "win"', {
142147
"include_dirs": [
143-
"deps/grpc/third_party/zlib",
144-
"deps/grpc/third_party/cares/cares"
148+
"deps/grpc/third_party/zlib"
145149
],
146150
"defines": [
147151
'_WIN32_WINNT=0x0600',
@@ -161,8 +165,7 @@
161165
]
162166
}, { # OS != "win"
163167
'include_dirs': [
164-
'<(node_root_dir)/deps/zlib',
165-
'<(node_root_dir)/deps/cares/include'
168+
'<(node_root_dir)/deps/zlib'
166169
]
167170
}],
168171
['OS == "mac"', {
@@ -279,8 +282,54 @@
279282
}]
280283
],
281284
'targets': [
285+
% for lib in libs:
286+
% if lib.name == 'ares':
287+
{
288+
'target_name': '${lib.name}',
289+
'product_prefix': 'lib',
290+
'type': 'static_library',
291+
'sources': [
292+
% for source in lib.src:
293+
'deps/grpc/${source}',
294+
% endfor
295+
],
296+
'defines': [
297+
'_GNU_SOURCE'
298+
],
299+
'conditions': [
300+
['OS == "mac"', {
301+
'xcode_settings': {
302+
'MACOSX_DEPLOYMENT_TARGET': '10.9'
303+
},
304+
'include_dirs': [
305+
'deps/grpc/third_party/cares/config_darwin'
306+
],
307+
'defines': [
308+
'HAVE_CONFIG_H'
309+
]
310+
}],
311+
['OS == "linux"', {
312+
'include_dirs': [
313+
'deps/grpc/third_party/cares/config_linux'
314+
],
315+
'defines': [
316+
'HAVE_CONFIG_H'
317+
]
318+
}],
319+
['OS == "win"', {
320+
'include_dirs': [
321+
'deps/grpc/third_party/cares/config_windows'
322+
],
323+
'defines': [
324+
'HAVE_CONFIG_H'
325+
]
326+
}]
327+
]
328+
},
329+
% endif
330+
% endfor
282331
% for core in libs:
283-
% if core.name == 'grpc':
332+
% if core.name == 'grpc' or core.name == 'address_sorting':
284333
% for lib in libs:
285334
% if lib.name == core.name or (lib.name in core.transitive_deps and lib.name not in ('boringssl', 'z')):
286335
{
@@ -347,6 +396,8 @@
347396
"dependencies": [
348397
"grpc",
349398
"gpr",
399+
"ares",
400+
"address_sorting"
350401
]
351402
},
352403
{
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
*
3+
* Copyright 2019 gRPC authors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
'use strict';
20+
21+
var assert = require('assert');
22+
var _ = require('lodash');
23+
24+
var grpc = require('..');
25+
26+
const insecureCreds = grpc.credentials.createInsecure();
27+
28+
describe('Name resolver', function() {
29+
let server;
30+
let port;
31+
before(function(done) {
32+
const insecureServerCreds = grpc.ServerCredentials.createInsecure();
33+
server = new grpc.Server();
34+
server.bindAsync('localhost:0', insecureServerCreds, (error, portVal) => {
35+
port = portVal;
36+
done(error);
37+
});
38+
});
39+
after(function() {
40+
server.forceShutdown();
41+
});
42+
// This test also seems to have problems with the native resolver on Windows
43+
it.skip('Should resolve a target to IPv4 addresses', function(done) {
44+
const client = new grpc.Client(`loopback4.unittest.grpc.io:${port}`, insecureCreds);
45+
let deadline = new Date();
46+
deadline.setSeconds(deadline.getSeconds() + 1);
47+
client.waitForReady(deadline, (error) => {
48+
assert.ifError(error);
49+
done();
50+
});
51+
});
52+
/* This test doesn't work with the native resolver on Windows on our test
53+
* machines because they don't have IPv6 addresses, so Windows omits IPv6
54+
* addresses from getaddrinfo results. */
55+
it.skip('Should resolve a target to IPv6 addresses', function(done) {
56+
const client = new grpc.Client(`loopback6.unittest.grpc.io:${port}`, insecureCreds);
57+
let deadline = new Date();
58+
deadline.setSeconds(deadline.getSeconds() + 1);
59+
client.waitForReady(deadline, (error) => {
60+
assert.ifError(error);
61+
done();
62+
});
63+
});
64+
it('Should resolve a target to IPv4 and IPv6 addresses', function(done) {
65+
const client = new grpc.Client(`loopback46.unittest.grpc.io:${port}`, insecureCreds);
66+
let deadline = new Date();
67+
deadline.setSeconds(deadline.getSeconds() + 1);
68+
client.waitForReady(deadline, (error) => {
69+
assert.ifError(error);
70+
done();
71+
});
72+
});
73+
});

run-tests.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ for %%v in (6 7 8 9 10 11 12) do (
5656
call .\node_modules\.bin\gulp cleanAll || SET FAILED=1
5757
call .\node_modules\.bin\gulp setupWindows || SET FAILED=1
5858
call .\node_modules\.bin\gulp test || SET FAILED=1
59+
cmd.exe /c "SET GRPC_DNS_RESOLVER=ares& call .\node_modules\.bin\gulp nativeTestOnly" || SET FAILED=1
5960
)
6061

6162
node merge_kokoro_logs.js

0 commit comments

Comments
 (0)