Use custom fallback DNS servers
This commit is contained in:
parent
56145fabcc
commit
2f691f3dd0
1 changed files with 12 additions and 1 deletions
|
@ -1,13 +1,22 @@
|
||||||
// Copyright 2023 Signal Messenger, LLC
|
// Copyright 2023 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { lookup as nativeLookup, resolve4, resolve6 } from 'dns';
|
import {
|
||||||
|
lookup as nativeLookup,
|
||||||
|
resolve4,
|
||||||
|
resolve6,
|
||||||
|
getServers,
|
||||||
|
setServers,
|
||||||
|
} from 'dns';
|
||||||
import type { LookupOneOptions } from 'dns';
|
import type { LookupOneOptions } from 'dns';
|
||||||
|
|
||||||
import * as log from '../logging/log';
|
import * as log from '../logging/log';
|
||||||
import * as Errors from '../types/errors';
|
import * as Errors from '../types/errors';
|
||||||
import { strictAssert } from './assert';
|
import { strictAssert } from './assert';
|
||||||
|
|
||||||
|
const ORIGINAL_SERVERS = getServers();
|
||||||
|
const FALLBACK_SERVERS = ['1.1.1.1'];
|
||||||
|
|
||||||
export function lookupWithFallback(
|
export function lookupWithFallback(
|
||||||
hostname: string,
|
hostname: string,
|
||||||
opts: LookupOneOptions,
|
opts: LookupOneOptions,
|
||||||
|
@ -37,6 +46,7 @@ export function lookupWithFallback(
|
||||||
fallbackErr: NodeJS.ErrnoException | null,
|
fallbackErr: NodeJS.ErrnoException | null,
|
||||||
records: Array<string>
|
records: Array<string>
|
||||||
): void => {
|
): void => {
|
||||||
|
setServers(ORIGINAL_SERVERS);
|
||||||
if (fallbackErr) {
|
if (fallbackErr) {
|
||||||
return callback(fallbackErr, '', 0);
|
return callback(fallbackErr, '', 0);
|
||||||
}
|
}
|
||||||
|
@ -53,6 +63,7 @@ export function lookupWithFallback(
|
||||||
callback(null, records[index], family);
|
callback(null, records[index], family);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
setServers(FALLBACK_SERVERS);
|
||||||
if (family === 4) {
|
if (family === 4) {
|
||||||
resolve4(hostname, onRecords);
|
resolve4(hostname, onRecords);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue