dns: call ada::idna::to_ascii directly from c++

PR-URL: https://github.com/nodejs/node/pull/47920
Fixes: https://github.com/nodejs/performance/issues/77
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Yagiz Nizipli authored and Michaël Zasso committed 2023-05-12 11:57:21 +02:00
1 parent d81c54e3a8
commit 9be922892f
4 files changed
+17 -18

No files matched your search

+1 -2
View File
@@ -28,7 +28,6 @@ const {
} = primordials;
const cares = internalBinding('cares_wrap');
const { toASCII } = require('internal/idna');
const { isIP } = require('internal/net');
const { customPromisifyArgs } = require('internal/util');
const errors = require('internal/errors');
@@ -220,7 +219,7 @@ function lookup(hostname, options, callback) {
req.oncomplete = all ? onlookupall : onlookup;
const err = cares.getaddrinfo(
req, toASCII(hostname), family, hints, verbatim,
req, hostname, family, hints, verbatim,
);
if (err) {
process.nextTick(callback, dnsException(err, 'getaddrinfo', hostname));
+1 -3
View File
@@ -7,8 +7,6 @@ const {
Symbol,
} = primordials;
const { toASCII } = require('internal/idna');
const {
codes: {
ERR_INVALID_ARG_TYPE,
@@ -70,7 +68,7 @@ function resolver(bindingName) {
req.hostname = name;
req.oncomplete = onresolve;
req.ttl = !!(options && options.ttl);
const err = this._handle[bindingName](req, toASCII(name));
const err = this._handle[bindingName](req, name);
if (err) throw dnsException(err, bindingName, name);
if (hasObserver('dns')) {
startPerf(req, kPerfHooksDnsLookupResolveContext, {
+2 -3
View File
@@ -46,7 +46,6 @@ const {
CANCELLED,
} = dnsErrorCodes;
const { codes, dnsException } = require('internal/errors');
const { toASCII } = require('internal/idna');
const { isIP } = require('internal/net');
const {
getaddrinfo,
@@ -138,7 +137,7 @@ function createLookupPromise(family, hostname, all, hints, verbatim) {
req.resolve = resolve;
req.reject = reject;
const err = getaddrinfo(req, toASCII(hostname), family, hints, verbatim);
const err = getaddrinfo(req, hostname, family, hints, verbatim);
if (err) {
reject(dnsException(err, 'getaddrinfo', hostname));
@@ -274,7 +273,7 @@ function createResolverPromise(resolver, bindingName, hostname, ttl) {
req.reject = reject;
req.ttl = ttl;
const err = resolver._handle[bindingName](req, toASCII(hostname));
const err = resolver._handle[bindingName](req, hostname);
if (err)
reject(dnsException(err, bindingName, hostname));
+13 -10
View File
@@ -20,6 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "cares_wrap.h"
#include "ada.h"
#include "async_wrap-inl.h"
#include "base64-inl.h"
#include "base_object-inl.h"
@@ -1558,6 +1559,7 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
CHECK(args[4]->IsBoolean());
Local<Object> req_wrap_obj = args[0].As<Object>();
node::Utf8Value hostname(env->isolate(), args[1]);
std::string ascii_hostname = ada::idna::to_ascii(hostname.ToStringView());
int32_t flags = 0;
if (args[3]->IsInt32()) {
@@ -1590,17 +1592,18 @@ void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = flags;
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(
TRACING_CATEGORY_NODE2(dns, native), "lookup", req_wrap.get(),
"hostname", TRACE_STR_COPY(*hostname),
"family",
family == AF_INET ? "ipv4" : family == AF_INET6 ? "ipv6" : "unspec");
TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(TRACING_CATEGORY_NODE2(dns, native),
"lookup",
req_wrap.get(),
"hostname",
TRACE_STR_COPY(ascii_hostname.data()),
"family",
family == AF_INET ? "ipv4"
: family == AF_INET6 ? "ipv6"
: "unspec");
int err = req_wrap->Dispatch(uv_getaddrinfo,
AfterGetAddrInfo,
*hostname,
nullptr,
&hints);
int err = req_wrap->Dispatch(
uv_getaddrinfo, AfterGetAddrInfo, ascii_hostname.data(), nullptr, &hints);
if (err == 0)
// Release ownership of the pointer allowing the ownership to be transferred
USE(req_wrap.release());