diff --git a/ts/scripts/generate-dns-fallback.ts b/ts/scripts/generate-dns-fallback.ts index 39f442f4b..f204fe784 100644 --- a/ts/scripts/generate-dns-fallback.ts +++ b/ts/scripts/generate-dns-fallback.ts @@ -1,15 +1,15 @@ // Copyright 2024 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -import { join } from 'path'; -import { lookup as lookupCb } from 'dns'; +import { resolve4 as resolve4Cb, resolve6 as resolve6Cb } from 'dns'; import { writeFile } from 'fs/promises'; +import { join } from 'path'; import { promisify } from 'util'; -import type { ResolvedEndpoint } from 'electron'; import { isNotNil } from '../util/isNotNil'; -const lookup = promisify(lookupCb); +const resolve4 = promisify(resolve4Cb); +const resolve6 = promisify(resolve6Cb); const FALLBACK_DOMAINS = [ 'chat.signal.org', @@ -25,35 +25,31 @@ const FALLBACK_DOMAINS = [ async function main() { const config = await Promise.all( FALLBACK_DOMAINS.sort().map(async domain => { - const addresses = await lookup(domain, { all: true }); - const endpoints = addresses - .map(({ address, family }): ResolvedEndpoint | null => { - if (family === 4) { - return { family: 'ipv4', address }; - } - if (family === 6) { - return { family: 'ipv6', address }; - } - return null; - }) - .filter(isNotNil) - .sort((a, b) => { - if (a.family < b.family) { - return -1; - } - if (a.family > b.family) { - return 1; - } + const ipv4endpoints = (await resolve4(domain)) + .map(a => ({"family": "ipv4", "address": a})) - if (a.address < b.address) { - return -1; - } - if (a.address > b.address) { - return 1; - } - return 0; - }); + const ipv6endpoints = (await resolve6(domain)) + .map(a => ({"family": "ipv6", "address": a})) + + const endpoints = [...ipv4endpoints, ...ipv6endpoints] + .filter(isNotNil) + .sort((a, b) => { + if (a.family < b.family) { + return -1; + } + if (a.family > b.family) { + return 1; + } + + if (a.address < b.address) { + return -1; + } + if (a.address > b.address) { + return 1; + } + return 0; + }) return { domain, endpoints }; })