Skip to content

Commit 284a869

Browse files
anonrigtargos
authored andcommitted
dns: call ada::idna::to_ascii directly from c++
PR-URL: #47920 Fixes: nodejs/performance#77 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 6f0458d commit 284a869

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

lib/dns.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const {
2828
} = primordials;
2929

3030
const cares = internalBinding('cares_wrap');
31-
const { toASCII } = require('internal/idna');
3231
const { isIP } = require('internal/net');
3332
const { customPromisifyArgs } = require('internal/util');
3433
const errors = require('internal/errors');
@@ -220,7 +219,7 @@ function lookup(hostname, options, callback) {
220219
req.oncomplete = all ? onlookupall : onlookup;
221220

222221
const err = cares.getaddrinfo(
223-
req, toASCII(hostname), family, hints, verbatim,
222+
req, hostname, family, hints, verbatim,
224223
);
225224
if (err) {
226225
process.nextTick(callback, dnsException(err, 'getaddrinfo', hostname));

lib/internal/dns/callback_resolver.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const {
77
Symbol,
88
} = primordials;
99

10-
const { toASCII } = require('internal/idna');
11-
1210
const {
1311
codes: {
1412
ERR_INVALID_ARG_TYPE,
@@ -70,7 +68,7 @@ function resolver(bindingName) {
7068
req.hostname = name;
7169
req.oncomplete = onresolve;
7270
req.ttl = !!(options && options.ttl);
73-
const err = this._handle[bindingName](req, toASCII(name));
71+
const err = this._handle[bindingName](req, name);
7472
if (err) throw dnsException(err, bindingName, name);
7573
if (hasObserver('dns')) {
7674
startPerf(req, kPerfHooksDnsLookupResolveContext, {

lib/internal/dns/promises.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const {
4646
CANCELLED,
4747
} = dnsErrorCodes;
4848
const { codes, dnsException } = require('internal/errors');
49-
const { toASCII } = require('internal/idna');
5049
const { isIP } = require('internal/net');
5150
const {
5251
getaddrinfo,
@@ -138,7 +137,7 @@ function createLookupPromise(family, hostname, all, hints, verbatim) {
138137
req.resolve = resolve;
139138
req.reject = reject;
140139

141-
const err = getaddrinfo(req, toASCII(hostname), family, hints, verbatim);
140+
const err = getaddrinfo(req, hostname, family, hints, verbatim);
142141

143142
if (err) {
144143
reject(dnsException(err, 'getaddrinfo', hostname));
@@ -274,7 +273,7 @@ function createResolverPromise(resolver, bindingName, hostname, ttl) {
274273
req.reject = reject;
275274
req.ttl = ttl;
276275

277-
const err = resolver._handle[bindingName](req, toASCII(hostname));
276+
const err = resolver._handle[bindingName](req, hostname);
278277

279278
if (err)
280279
reject(dnsException(err, bindingName, hostname));

src/cares_wrap.cc

+14-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
#include "cares_wrap.h"
23+
#include "ada.h"
2324
#include "async_wrap-inl.h"
2425
#include "base64-inl.h"
2526
#include "base_object-inl.h"
@@ -1558,6 +1559,7 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
15581559
CHECK(args[4]->IsBoolean());
15591560
Local<Object> req_wrap_obj = args[0].As<Object>();
15601561
node::Utf8Value hostname(env->isolate(), args[1]);
1562+
std::string ascii_hostname = ada::idna::to_ascii(hostname.ToStringView());
15611563

15621564
int32_t flags = 0;
15631565
if (args[3]->IsInt32()) {
@@ -1590,17 +1592,18 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
15901592
hints.ai_socktype = SOCK_STREAM;
15911593
hints.ai_flags = flags;
15921594

1593-
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(
1594-
TRACING_CATEGORY_NODE2(dns, native), "lookup", req_wrap.get(),
1595-
"hostname", TRACE_STR_COPY(*hostname),
1596-
"family",
1597-
family == AF_INET ? "ipv4" : family == AF_INET6 ? "ipv6" : "unspec");
1598-
1599-
int err = req_wrap->Dispatch(uv_getaddrinfo,
1600-
AfterGetAddrInfo,
1601-
*hostname,
1602-
nullptr,
1603-
&hints);
1595+
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(TRACING_CATEGORY_NODE2(dns, native),
1596+
"lookup",
1597+
req_wrap.get(),
1598+
"hostname",
1599+
TRACE_STR_COPY(ascii_hostname.data()),
1600+
"family",
1601+
family == AF_INET ? "ipv4"
1602+
: family == AF_INET6 ? "ipv6"
1603+
: "unspec");
1604+
1605+
int err = req_wrap->Dispatch(
1606+
uv_getaddrinfo, AfterGetAddrInfo, ascii_hostname.data(), nullptr, &hints);
16041607
if (err == 0)
16051608
// Release ownership of the pointer allowing the ownership to be transferred
16061609
USE(req_wrap.release());

0 commit comments

Comments
 (0)