2024-02-28 00:53:58 +00:00
|
|
|
// Copyright 2024 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-08-01 16:00:36 +00:00
|
|
|
import { resolve4 as resolve4Cb, resolve6 as resolve6Cb } from 'dns';
|
2024-02-28 00:53:58 +00:00
|
|
|
import { writeFile } from 'fs/promises';
|
2024-08-01 16:00:36 +00:00
|
|
|
import { join } from 'path';
|
2024-02-28 00:53:58 +00:00
|
|
|
import { promisify } from 'util';
|
|
|
|
|
|
|
|
import { isNotNil } from '../util/isNotNil';
|
|
|
|
|
2024-08-01 16:00:36 +00:00
|
|
|
const resolve4 = promisify(resolve4Cb);
|
|
|
|
const resolve6 = promisify(resolve6Cb);
|
2024-02-28 00:53:58 +00:00
|
|
|
|
|
|
|
const FALLBACK_DOMAINS = [
|
|
|
|
'chat.signal.org',
|
|
|
|
'storage.signal.org',
|
|
|
|
'cdsi.signal.org',
|
|
|
|
'cdn.signal.org',
|
|
|
|
'cdn2.signal.org',
|
|
|
|
'cdn3.signal.org',
|
|
|
|
'updates2.signal.org',
|
|
|
|
'sfu.voip.signal.org',
|
|
|
|
];
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const config = await Promise.all(
|
|
|
|
FALLBACK_DOMAINS.sort().map(async domain => {
|
2024-08-02 22:08:50 +00:00
|
|
|
const ipv4endpoints = (await resolve4(domain)).map(a => ({
|
|
|
|
family: 'ipv4',
|
|
|
|
address: a,
|
|
|
|
}));
|
2024-02-28 00:53:58 +00:00
|
|
|
|
2024-08-02 22:08:50 +00:00
|
|
|
const ipv6endpoints = (await resolve6(domain)).map(a => ({
|
|
|
|
family: 'ipv6',
|
|
|
|
address: a,
|
|
|
|
}));
|
2024-08-01 16:00:36 +00:00
|
|
|
|
|
|
|
const endpoints = [...ipv4endpoints, ...ipv6endpoints]
|
2024-08-02 22:08:50 +00:00
|
|
|
.filter(isNotNil)
|
|
|
|
.sort((a, b) => {
|
|
|
|
if (a.family < b.family) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.family > b.family) {
|
|
|
|
return 1;
|
|
|
|
}
|
2024-02-28 00:53:58 +00:00
|
|
|
|
2024-08-02 22:08:50 +00:00
|
|
|
if (a.address < b.address) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.address > b.address) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
2024-02-28 00:53:58 +00:00
|
|
|
|
|
|
|
return { domain, endpoints };
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
const outPath = join(__dirname, '../../build/dns-fallback.json');
|
|
|
|
|
2024-08-05 20:37:53 +00:00
|
|
|
await writeFile(outPath, `${JSON.stringify(config, null, 2)}\n`);
|
2024-02-28 00:53:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main().catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|