Introduce --disable-ipv6 CLI option

This commit is contained in:
Fedor Indutny 2024-04-11 19:06:54 +02:00 committed by GitHub
parent da34ce5fe7
commit bcaf60a3b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 1 deletions

View file

@ -207,6 +207,8 @@ const defaultWebPrefs = {
const DISABLE_GPU =
OS.isLinux() && !process.argv.some(arg => arg === '--enable-gpu');
const DISABLE_IPV6 = process.argv.some(arg => arg === '--disable-ipv6');
const CLI_LANG = cliOptions.lang as string | undefined;
setupCrashReports(getLogger, showDebugLogWindow);
@ -1719,6 +1721,9 @@ if (DISABLE_GPU) {
let ready = false;
app.on('ready', async () => {
dns.setFallback(await getDNSFallback());
if (DISABLE_IPV6) {
dns.setIPv6Enabled(false);
}
const [userDataPath, crashDumpsPath, installPath] = await Promise.all([
realpath(app.getPath('userData')),
@ -2448,6 +2453,7 @@ ipc.on('get-config', async event => {
ciMode,
// Should be already computed and cached at this point
dnsFallback: await getDNSFallback(),
disableIPv6: DISABLE_IPV6,
ciBackupPath: config.get<string | null>('ciBackupPath') || undefined,
nodeVersion: process.versions.node,
hostname: os.hostname(),

View file

@ -41,6 +41,7 @@ export const rendererConfigSchema = z.object({
contentProxyUrl: configRequiredStringSchema,
crashDumpsPath: configRequiredStringSchema,
ciMode: z.enum(['full', 'benchmark']).or(z.literal(false)),
disableIPv6: z.boolean(),
dnsFallback: DNSFallbackSchema,
ciBackupPath: configOptionalStringSchema,
environment: environmentSchema,

View file

@ -26,6 +26,12 @@ export function setFallback(dnsFallback: DNSFallbackType): void {
}
}
let ipv6Enabled = true;
export function setIPv6Enabled(value: boolean): void {
ipv6Enabled = value;
}
function lookupAll(
hostname: string,
opts: LookupOneOptions | LookupAllOptions,
@ -77,7 +83,7 @@ function lookupAll(
}
}
const addresses = result.endpoints.map(({ address, family }) => {
let addresses = result.endpoints.map(({ address, family }) => {
let numericFamily = -1;
if (family === 'ipv4') {
numericFamily = 4;
@ -90,6 +96,13 @@ function lookupAll(
};
});
if (!ipv6Enabled) {
const ipv4Only = addresses.filter(({ family }) => family !== 6);
if (ipv4Only.length !== 0) {
addresses = ipv4Only;
}
}
if (!opts.all) {
const random = addresses.at(Math.floor(Math.random() * addresses.length));
if (random === undefined) {

View file

@ -74,6 +74,9 @@ if (config.crashDumpsPath) {
addSensitivePath(config.crashDumpsPath);
}
if (SignalContext.config.disableIPv6) {
dns.setIPv6Enabled(false);
}
dns.setFallback(SignalContext.config.dnsFallback);
window.Signal = setup({