Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 6496x 6496x 6496x 6496x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 1207x 1207x 1207x 1207x 1207x 153x 1191x 1191x 1191x 1191x 1191x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 1207x 1207x 1207x 1207x 1207x 1191x 1207x 153x 153x 1191x 1191x 1191x 153x 153x 6x 6x 153x 153x 11x 21x 21x 2x 21x 21x 11x 11x 153x 153x 76x 76x 76x 76x 76x 76x 76x 65x 65x 65x 65x 65x 29x 29x 29x 29x 41x 3x 3x 3x 3x 3x 3x 3x 3x 26x 26x 26x 26x 41x 25x 25x 25x 25x 25x 25x 17x 17x 17x 25x 9x 9x 76x 76x 76x 76x 153x 153x 27x 27x 27x 27x 1x 1x 1x 1x 1x 1x 26x 27x 27x 153x 153x 153x 11x 11x 11x 5x 5x 7x 7x 7x 11x 11x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 6254x 6254x 6254x 6251x 6254x 3x 3x 3x 6254x 6254x 6253x 6253x 1x 1x 1x 6254x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 1189x 1189x 1189x 1189x 1122x 1122x 1189x 1189x 153x 13x 13x 13x 153x 1189x 1189x 1189x 17835x 1189x 1189x 153x 5304x 5304x 5304x 11x 11x 5304x 153x 153x 29x 29x 3x 3x 3x 3x 3x 3x 3x 3x 29x 153x 6305x 6305x 6305x 153x 8x 8x 8x 8x 153x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 1164x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x 153x | 'use strict'; const { ArrayPrototypeForEach, ArrayPrototypeJoin, ArrayPrototypeMap, ArrayPrototypePush, FunctionPrototypeBind, NumberParseInt, RegExpPrototypeExec, RegExpPrototypeSymbolReplace, ObjectCreate, Symbol, } = primordials; const errors = require('internal/errors'); const { isIP } = require('internal/net'); const { getOptionValue } = require('internal/options'); const { validateArray, validateInt32, validateOneOf, validateString, } = require('internal/validators'); let binding; function lazyBinding() { binding ??= internalBinding('cares_wrap'); return binding; } const IANA_DNS_PORT = 53; const IPv6RE = /^\[([^[\]]*)\]/; const addrSplitRE = /(^.+?)(?::(\d+))?$/; const { ERR_DNS_SET_SERVERS_FAILED, ERR_INVALID_ARG_VALUE, ERR_INVALID_IP_ADDRESS, } = errors.codes; const { addSerializeCallback, addDeserializeCallback, isBuildingSnapshot, } = require('v8').startupSnapshot; function validateTimeout(options) { const { timeout = -1 } = { ...options }; validateInt32(timeout, 'options.timeout', -1); return timeout; } function validateTries(options) { const { tries = 4 } = { ...options }; validateInt32(tries, 'options.tries', 1); return tries; } const kSerializeResolver = Symbol('dns:resolver:serialize'); const kDeserializeResolver = Symbol('dns:resolver:deserialize'); const kSnapshotStates = Symbol('dns:resolver:config'); const kInitializeHandle = Symbol('dns:resolver:initializeHandle'); const kSetServersInteral = Symbol('dns:resolver:setServers'); // Resolver instances correspond 1:1 to c-ares channels. class ResolverBase { constructor(options = undefined) { const timeout = validateTimeout(options); const tries = validateTries(options); // If we are building snapshot, save the states of the resolver along // the way. if (isBuildingSnapshot()) { this[kSnapshotStates] = { timeout, tries }; } this[kInitializeHandle](timeout, tries); } [kInitializeHandle](timeout, tries) { const { ChannelWrap } = lazyBinding(); this._handle = new ChannelWrap(timeout, tries); } cancel() { this._handle.cancel(); } getServers() { return ArrayPrototypeMap(this._handle.getServers() || [], (val) => { if (!val[1] || val[1] === IANA_DNS_PORT) return val[0]; const host = isIP(val[0]) === 6 ? `[${val[0]}]` : val[0]; return `${host}:${val[1]}`; }); } setServers(servers) { validateArray(servers, 'servers'); // Cache the original servers because in the event of an error while // setting the servers, c-ares won't have any servers available for // resolution. const newSet = []; ArrayPrototypeForEach(servers, (serv, index) => { validateString(serv, `servers[${index}]`); let ipVersion = isIP(serv); if (ipVersion !== 0) return ArrayPrototypePush(newSet, [ipVersion, serv, IANA_DNS_PORT]); const match = RegExpPrototypeExec(IPv6RE, serv); // Check for an IPv6 in brackets. if (match) { ipVersion = isIP(match[1]); if (ipVersion !== 0) { const port = NumberParseInt( RegExpPrototypeSymbolReplace(addrSplitRE, serv, '$2')) || IANA_DNS_PORT; return ArrayPrototypePush(newSet, [ipVersion, match[1], port]); } } // addr::port const addrSplitMatch = RegExpPrototypeExec(addrSplitRE, serv); if (addrSplitMatch) { const hostIP = addrSplitMatch[1]; const port = addrSplitMatch[2] || IANA_DNS_PORT; ipVersion = isIP(hostIP); if (ipVersion !== 0) { return ArrayPrototypePush( newSet, [ipVersion, hostIP, NumberParseInt(port)]); } } throw new ERR_INVALID_IP_ADDRESS(serv); }); this[kSetServersInteral](newSet, servers); } [kSetServersInteral](newSet, servers) { const orig = this._handle.getServers() || []; const errorNumber = this._handle.setServers(newSet); if (errorNumber !== 0) { // Reset the servers to the old servers, because ares probably unset them. this._handle.setServers(ArrayPrototypeJoin(orig, ',')); const { strerror } = lazyBinding(); const err = strerror(errorNumber); throw new ERR_DNS_SET_SERVERS_FAILED(err, servers); } if (isBuildingSnapshot()) { this[kSnapshotStates].servers = newSet; } } setLocalAddress(ipv4, ipv6) { validateString(ipv4, 'ipv4'); if (ipv6 !== undefined) { validateString(ipv6, 'ipv6'); } this._handle.setLocalAddress(ipv4, ipv6); if (isBuildingSnapshot()) { this[kSnapshotStates].localAddress = { ipv4, ipv6 }; } } // TODO(joyeecheung): consider exposing this if custom DNS resolvers // end up being useful for snapshot users. [kSerializeResolver]() { this._handle = null; // We'll restore it during deserialization. addDeserializeCallback(function deserializeResolver(resolver) { resolver[kDeserializeResolver](); }, this); } [kDeserializeResolver]() { const { timeout, tries, localAddress, servers } = this[kSnapshotStates]; this[kInitializeHandle](timeout, tries); if (localAddress) { const { ipv4, ipv6 } = localAddress; this._handle.setLocalAddress(ipv4, ipv6); } if (servers) { this[kSetServersInteral](servers, servers); } } } let defaultResolver; let dnsOrder; function initializeDns() { const orderFromCLI = getOptionValue('--dns-result-order'); if (!orderFromCLI) { dnsOrder ??= 'verbatim'; } else { // Allow the deserialized application to override order from CLI. dnsOrder = orderFromCLI; } if (!isBuildingSnapshot()) { return; } addSerializeCallback(() => { defaultResolver?.[kSerializeResolver](); }); } const resolverKeys = [ 'getServers', 'resolve', 'resolve4', 'resolve6', 'resolveAny', 'resolveCaa', 'resolveCname', 'resolveMx', 'resolveNaptr', 'resolveNs', 'resolvePtr', 'resolveSoa', 'resolveSrv', 'resolveTxt', 'reverse', ]; function getDefaultResolver() { // We do this here instead of pre-execution so that the default resolver is // only ever created when the user loads any dns module. if (defaultResolver === undefined) { defaultResolver = new ResolverBase(); } return defaultResolver; } function setDefaultResolver(resolver) { defaultResolver = resolver; } function bindDefaultResolver(target, source) { const defaultResolver = getDefaultResolver(); ArrayPrototypeForEach(resolverKeys, (key) => { target[key] = FunctionPrototypeBind(source[key], defaultResolver); }); } function validateHints(hints) { const { AI_ADDRCONFIG, AI_ALL, AI_V4MAPPED } = lazyBinding(); if ((hints & ~(AI_ADDRCONFIG | AI_ALL | AI_V4MAPPED)) !== 0) { throw new ERR_INVALID_ARG_VALUE('hints', hints); } } let invalidHostnameWarningEmitted = false; function emitInvalidHostnameWarning(hostname) { if (!invalidHostnameWarningEmitted) { process.emitWarning( `The provided hostname "${hostname}" is not a valid ` + 'hostname, and is supported in the dns module solely for compatibility.', 'DeprecationWarning', 'DEP0118' ); invalidHostnameWarningEmitted = true; } } function getDefaultVerbatim() { return dnsOrder !== 'ipv4first'; } function setDefaultResultOrder(value) { validateOneOf(value, 'dnsOrder', ['verbatim', 'ipv4first']); dnsOrder = value; } function createResolverClass(resolver) { const resolveMap = ObjectCreate(null); class Resolver extends ResolverBase {} Resolver.prototype.resolveAny = resolveMap.ANY = resolver('queryAny'); Resolver.prototype.resolve4 = resolveMap.A = resolver('queryA'); Resolver.prototype.resolve6 = resolveMap.AAAA = resolver('queryAaaa'); Resolver.prototype.resolveCaa = resolveMap.CAA = resolver('queryCaa'); Resolver.prototype.resolveCname = resolveMap.CNAME = resolver('queryCname'); Resolver.prototype.resolveMx = resolveMap.MX = resolver('queryMx'); Resolver.prototype.resolveNs = resolveMap.NS = resolver('queryNs'); Resolver.prototype.resolveTxt = resolveMap.TXT = resolver('queryTxt'); Resolver.prototype.resolveSrv = resolveMap.SRV = resolver('querySrv'); Resolver.prototype.resolvePtr = resolveMap.PTR = resolver('queryPtr'); Resolver.prototype.resolveNaptr = resolveMap.NAPTR = resolver('queryNaptr'); Resolver.prototype.resolveSoa = resolveMap.SOA = resolver('querySoa'); Resolver.prototype.reverse = resolver('getHostByAddr'); return { resolveMap, Resolver }; } // ERROR CODES const errorCodes = { NODATA: 'ENODATA', FORMERR: 'EFORMERR', SERVFAIL: 'ESERVFAIL', NOTFOUND: 'ENOTFOUND', NOTIMP: 'ENOTIMP', REFUSED: 'EREFUSED', BADQUERY: 'EBADQUERY', BADNAME: 'EBADNAME', BADFAMILY: 'EBADFAMILY', BADRESP: 'EBADRESP', CONNREFUSED: 'ECONNREFUSED', TIMEOUT: 'ETIMEOUT', EOF: 'EOF', FILE: 'EFILE', NOMEM: 'ENOMEM', DESTRUCTION: 'EDESTRUCTION', BADSTR: 'EBADSTR', BADFLAGS: 'EBADFLAGS', NONAME: 'ENONAME', BADHINTS: 'EBADHINTS', NOTINITIALIZED: 'ENOTINITIALIZED', LOADIPHLPAPI: 'ELOADIPHLPAPI', ADDRGETNETWORKPARAMS: 'EADDRGETNETWORKPARAMS', CANCELLED: 'ECANCELLED', }; module.exports = { bindDefaultResolver, getDefaultResolver, setDefaultResolver, validateHints, validateTimeout, validateTries, emitInvalidHostnameWarning, getDefaultVerbatim, setDefaultResultOrder, errorCodes, createResolverClass, initializeDns }; |