mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Housekeeping
This commit is contained in:
@@ -36,14 +36,8 @@ export const getTelegramCIDRPromise = once(async () => {
|
||||
|
||||
// Backup IP Source 1 (DoH)
|
||||
await Promise.all([
|
||||
DNS2.DOHClient({
|
||||
dns: '8.8.8.8',
|
||||
http: false
|
||||
}),
|
||||
DNS2.DOHClient({
|
||||
dns: '1.0.0.1',
|
||||
http: false
|
||||
})
|
||||
DNS2.DOHClient({ dns: '8.8.8.8' }),
|
||||
DNS2.DOHClient({ dns: '1.0.0.1' })
|
||||
].flatMap(
|
||||
(client) => [
|
||||
'apv3.stel.com', // prod
|
||||
|
||||
@@ -18,10 +18,6 @@ class DnsError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
interface DnsResponse extends DNS2.$DnsResponse {
|
||||
dns: string
|
||||
}
|
||||
|
||||
const dohServers: Array<[string, DNS2.DnsResolver]> = ([
|
||||
'8.8.8.8',
|
||||
'8.8.4.4',
|
||||
@@ -59,10 +55,7 @@ const dohServers: Array<[string, DNS2.DnsResolver]> = ([
|
||||
// 'dns.rabbitdns.org'
|
||||
] as const).map(dns => [
|
||||
dns,
|
||||
DNS2.DOHClient({
|
||||
dns,
|
||||
http: false
|
||||
})
|
||||
DNS2.DOHClient({ dns })
|
||||
] as const);
|
||||
|
||||
const domesticDohServers: Array<[string, DNS2.DnsResolver]> = ([
|
||||
@@ -72,10 +65,7 @@ const domesticDohServers: Array<[string, DNS2.DnsResolver]> = ([
|
||||
'1.12.12.12'
|
||||
] as const).map(dns => [
|
||||
dns,
|
||||
DNS2.DOHClient({
|
||||
dns,
|
||||
http: false
|
||||
})
|
||||
DNS2.DOHClient({ dns })
|
||||
] as const);
|
||||
|
||||
const domainAliveMutex = createKeyedAsyncMutex('isDomainAlive');
|
||||
@@ -121,7 +111,7 @@ export async function isDomainAlive(
|
||||
return true;
|
||||
}
|
||||
|
||||
aDns.push(aRecords.dns);
|
||||
aDns.push(servers[i][0]);
|
||||
} catch {}
|
||||
|
||||
if (aDns.length >= 2) {
|
||||
@@ -138,7 +128,7 @@ export async function isDomainAlive(
|
||||
return true;
|
||||
}
|
||||
|
||||
aaaaDns.push(aaaaRecords.dns);
|
||||
aaaaDns.push(servers[i][0]);
|
||||
} catch {}
|
||||
|
||||
if (aaaaDns.length >= 2) {
|
||||
@@ -156,7 +146,7 @@ export async function isDomainAlive(
|
||||
domainAliveMap.set(domain, true);
|
||||
return true;
|
||||
}
|
||||
aDns.push(aRecords.dns);
|
||||
aDns.push(domesticServers[i][0]);
|
||||
} catch {}
|
||||
if (aDns.length >= 2) {
|
||||
break; // we only need to test 2 times
|
||||
@@ -171,7 +161,7 @@ export async function isDomainAlive(
|
||||
domainAliveMap.set(domain, true);
|
||||
return true;
|
||||
}
|
||||
aaaaDns.push(aaaaRecords.dns);
|
||||
aaaaDns.push(domesticServers[i][0]);
|
||||
} catch {}
|
||||
|
||||
if (aaaaDns.length >= 2) {
|
||||
@@ -246,10 +236,7 @@ async function $resolve(name: string, type: DNS2.PacketQuestion, server: [string
|
||||
const [dohServer, dohClient] = server;
|
||||
|
||||
try {
|
||||
return {
|
||||
...await dohClient(name, type),
|
||||
dns: dohServer
|
||||
} satisfies DnsResponse;
|
||||
return await dohClient(name, type);
|
||||
} catch (e) {
|
||||
// console.error(e);
|
||||
throw new DnsError((e as Error).message, dohServer);
|
||||
|
||||
23
Build/mod.d.ts
vendored
23
Build/mod.d.ts
vendored
@@ -1,23 +0,0 @@
|
||||
import 'dns2';
|
||||
|
||||
declare module 'dns2' {
|
||||
import DNS2 from 'dns2';
|
||||
|
||||
declare namespace DNS2 {
|
||||
interface DoHClientOption {
|
||||
/** @example dns.google.com */
|
||||
dns: string,
|
||||
/** @description whether to use HTTP or HTTPS */
|
||||
http: boolean
|
||||
}
|
||||
|
||||
export type PacketQuestion = keyof typeof Packet.TYPE;
|
||||
export type DnsResolver<T = DnsResponse> = (name: string, type: PacketQuestion) => Promise<T>;
|
||||
|
||||
declare function DOHClient(opt: DoHClientOption): DnsResolver;
|
||||
|
||||
export type $DnsResponse = DnsResponse;
|
||||
}
|
||||
|
||||
export = DNS2;
|
||||
}
|
||||
Reference in New Issue
Block a user