build: use resolve4
/resolve6
in build:dns-fallback
.
`dns.lookup` relies on making syscalls to the underlying system using `getaddrinfo`, which can sometimes fail in proxy situations. This is an equivalent implementation using the native NodeJS DNS functions.
This commit is contained in:
parent
02e7a9e1a5
commit
cb5e7a029b
1 changed files with 27 additions and 31 deletions
|
@ -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 };
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue