File Explorer

/var/runtime/node_modules/@aws-sdk/util-dns/dist-cjs

This explorer reads the filesystem of the server it runs on, so /workspace/user isn't present here. Browsing and the terminal still work against this server's own disk from /.

2 dirs
3 files
NodeDnsLookupHostResolver.js3.5 KB · 92 lines
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.NodeDnsLookupHostResolver = void 0;const types_1 = require("@aws-sdk/types");const dns_1 = require("dns");const HostEntryTable_1 = require("./util/HostEntryTable");const NODE_DNS_FAMILY_TO_HOST_ADDRESS_TYPE = {    4: types_1.HostAddressType.A,    6: types_1.HostAddressType.AAAA,};const DNS_LOOKUP_OPTIONS = {    all: true,    hints: dns_1.V4MAPPED | dns_1.ALL,    verbatim: true,};class NodeDnsLookupHostResolver {    static DEFAULT_TTL_MS = 30_000;    static createDefaultCacheProvider = () => new HostEntryTable_1.HostEntryTable();    static DEFAULT_NODE_DNS_LOOKUP = dns_1.promises.lookup;    ttlMs;    cache;    nodeDnsLookup;    constructor({ ttlMs = NodeDnsLookupHostResolver.DEFAULT_TTL_MS, cache = NodeDnsLookupHostResolver.createDefaultCacheProvider(), nodeDnsLookup = NodeDnsLookupHostResolver.DEFAULT_NODE_DNS_LOOKUP, } = {}) {        this.ttlMs = ttlMs;        this.cache = cache;        this.nodeDnsLookup = nodeDnsLookup;    }    async resolveAddress(args) {        const possibleHostEntry = this.cache.get(args.hostName);        const newNextTimestampToUpdateMs = Date.now() + this.ttlMs;        if (possibleHostEntry === undefined) {            const addresses = await this.nodeDnsLookupResolveAddress(args);            this.cache.set(args, addresses, newNextTimestampToUpdateMs);        }        const hostEntry = this.cache.get(args.hostName);        if (possibleHostEntry !== undefined && Date.now() >= hostEntry.nextTimestampToUpdateMs) {            try {                const addresses = await this.nodeDnsLookupResolveAddress(args);                hostEntry.updateRecords(addresses, newNextTimestampToUpdateMs);            }            catch (error) {                console.error(`Could not update DNS address cache for "${args.hostName}": ${error}`);            }        }        hostEntry.processRecords();        const result = [];        if (hostEntry.aRecords.length > 0) {            result.push(hostEntry.aRecords.cycle());        }        if (hostEntry.aaaaRecords.length > 0) {            result.push(hostEntry.aaaaRecords.cycle());        }        if (result.length === 0) {            throw new Error(`Could not resolve addresses for "${args.hostName}"`);        }        return result;    }    reportFailureOnAddress(addr) {        const hostEntry = this.cache.get(addr.hostName);        if (hostEntry === undefined) {            throw new Error(`Could not find cached host name "${addr.hostName}"`);        }        hostEntry.failAddressInRecords(addr);    }    purgeCache(args) {        if (args?.hostName) {            this.cache.delete(args.hostName);        }        else {            this.cache.clear();        }    }    async nodeDnsLookupResolveAddress(args) {        const addresses = [];        const ipEntries = await this.nodeDnsLookup(args.hostName, DNS_LOOKUP_OPTIONS);        for (const { address, family } of ipEntries) {            const addressType = NODE_DNS_FAMILY_TO_HOST_ADDRESS_TYPE[family];            if (addressType === undefined) {                throw new Error(`dns.lookup() Node DNS family \`${family}\` is not supported`);            }            addresses.push({                addressType,                address,                hostName: args.hostName,                service: args.service,            });        }        return addresses;    }}exports.NodeDnsLookupHostResolver = NodeDnsLookupHostResolver;