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
|
// Copyright 2024 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { join } from 'path';
|
import { resolve4 as resolve4Cb, resolve6 as resolve6Cb } from 'dns';
|
||||||
import { lookup as lookupCb } from 'dns';
|
|
||||||
import { writeFile } from 'fs/promises';
|
import { writeFile } from 'fs/promises';
|
||||||
|
import { join } from 'path';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import type { ResolvedEndpoint } from 'electron';
|
|
||||||
|
|
||||||
import { isNotNil } from '../util/isNotNil';
|
import { isNotNil } from '../util/isNotNil';
|
||||||
|
|
||||||
const lookup = promisify(lookupCb);
|
const resolve4 = promisify(resolve4Cb);
|
||||||
|
const resolve6 = promisify(resolve6Cb);
|
||||||
|
|
||||||
const FALLBACK_DOMAINS = [
|
const FALLBACK_DOMAINS = [
|
||||||
'chat.signal.org',
|
'chat.signal.org',
|
||||||
|
@ -25,35 +25,31 @@ const FALLBACK_DOMAINS = [
|
||||||
async function main() {
|
async function main() {
|
||||||
const config = await Promise.all(
|
const config = await Promise.all(
|
||||||
FALLBACK_DOMAINS.sort().map(async domain => {
|
FALLBACK_DOMAINS.sort().map(async domain => {
|
||||||
const addresses = await lookup(domain, { all: true });
|
|
||||||
|
|
||||||
const endpoints = addresses
|
const ipv4endpoints = (await resolve4(domain))
|
||||||
.map(({ address, family }): ResolvedEndpoint | null => {
|
.map(a => ({"family": "ipv4", "address": a}))
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.address < b.address) {
|
const ipv6endpoints = (await resolve6(domain))
|
||||||
return -1;
|
.map(a => ({"family": "ipv6", "address": a}))
|
||||||
}
|
|
||||||
if (a.address > b.address) {
|
const endpoints = [...ipv4endpoints, ...ipv6endpoints]
|
||||||
return 1;
|
.filter(isNotNil)
|
||||||
}
|
.sort((a, b) => {
|
||||||
return 0;
|
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 };
|
return { domain, endpoints };
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue