Skip to content

Commit

Permalink
dns: move setServers to internal/dns/promise.js
Browse files Browse the repository at this point in the history
  • Loading branch information
F3n67u committed May 28, 2022
1 parent 29ff235 commit ef9f748
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
1 change: 0 additions & 1 deletion lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ ObjectDefineProperties(module.exports, {
get() {
if (promises === null) {
promises = require('internal/dns/promises');
promises.setServers = defaultResolverSetServers;
}
return promises;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/dns/promises.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const dnsPromises = require('internal/dns/promises');
dnsPromises.setServers = require('dns').setServers;
module.exports = dnsPromises;
module.exports = require('internal/dns/promises');
34 changes: 16 additions & 18 deletions lib/internal/dns/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ const {

const {
bindDefaultResolver,
Resolver: CallbackResolver,
Resolver,
validateHints,
validateTimeout,
validateTries,
emitInvalidHostnameWarning,
getDefaultVerbatim,
setDefaultResultOrder,
setDefaultResolver,
} = require('internal/dns/utils');
const { codes, dnsException } = require('internal/errors');
const { toASCII } = require('internal/idna');
const { isIP } = require('internal/net');
const {
getaddrinfo,
getnameinfo,
ChannelWrap,
GetAddrInfoReqWrap,
GetNameInfoReqWrap,
QueryReqWrap
Expand Down Expand Up @@ -270,19 +268,6 @@ function resolver(bindingName) {

const resolveMap = ObjectCreate(null);

// Resolver instances correspond 1:1 to c-ares channels.
class Resolver {
constructor(options = undefined) {
const timeout = validateTimeout(options);
const tries = validateTries(options);
this._handle = new ChannelWrap(timeout, tries);
}
}

Resolver.prototype.getServers = CallbackResolver.prototype.getServers;
Resolver.prototype.setServers = CallbackResolver.prototype.setServers;
Resolver.prototype.cancel = CallbackResolver.prototype.cancel;
Resolver.prototype.setLocalAddress = CallbackResolver.prototype.setLocalAddress;
Resolver.prototype.resolveAny = resolveMap.ANY = resolver('queryAny');
Resolver.prototype.resolve4 = resolveMap.A = resolver('queryA');
Resolver.prototype.resolve6 = resolveMap.AAAA = resolver('queryAaaa');
Expand Down Expand Up @@ -313,6 +298,19 @@ Resolver.prototype.resolve = function resolve(hostname, rrtype) {
return ReflectApply(resolver, this, [hostname]);
};

function defaultResolverSetServers(servers) {
const resolver = new Resolver();

module.exports = { lookup, lookupService, Resolver, setDefaultResultOrder };
resolver.setServers(servers);
setDefaultResolver(resolver);
bindDefaultResolver(module.exports, Resolver.prototype);
}

module.exports = {
lookup,
lookupService,
Resolver,
setDefaultResultOrder,
setServers: defaultResolverSetServers,
};
bindDefaultResolver(module.exports, Resolver.prototype);

0 comments on commit ef9f748

Please sign in to comment.