mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
Improve Domain Alive Check
This commit is contained in:
parent
1a1513c040
commit
73f0321f02
@ -36,7 +36,7 @@ const dohServers: Array<[string, DNS2.DnsResolver]> = ([
|
|||||||
'wikimedia-dns.org',
|
'wikimedia-dns.org',
|
||||||
// 'ordns.he.net',
|
// 'ordns.he.net',
|
||||||
'dns.mullvad.net',
|
'dns.mullvad.net',
|
||||||
'zero.dns0.eu',
|
// 'zero.dns0.eu',
|
||||||
'basic.rethinkdns.com'
|
'basic.rethinkdns.com'
|
||||||
// 'ada.openbld.net',
|
// 'ada.openbld.net',
|
||||||
// 'dns.rabbitdns.org'
|
// 'dns.rabbitdns.org'
|
||||||
@ -48,7 +48,7 @@ const dohServers: Array<[string, DNS2.DnsResolver]> = ([
|
|||||||
})
|
})
|
||||||
] as const);
|
] as const);
|
||||||
|
|
||||||
const queue = newQueue(24);
|
const queue = newQueue(18);
|
||||||
const mutex = new Map<string, Promise<unknown>>();
|
const mutex = new Map<string, Promise<unknown>>();
|
||||||
function keyedAsyncMutexWithQueue<T>(key: string, fn: () => Promise<T>) {
|
function keyedAsyncMutexWithQueue<T>(key: string, fn: () => Promise<T>) {
|
||||||
if (mutex.has(key)) {
|
if (mutex.has(key)) {
|
||||||
@ -91,6 +91,10 @@ const resolve: DNS2.DnsResolver<DnsResponse> = async (...args) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function getWhois(domain: string) {
|
||||||
|
return asyncRetry(() => whoiser.domain(domain), { retries: 5 });
|
||||||
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const domainSets = await new Fdir()
|
const domainSets = await new Fdir()
|
||||||
.withFullPaths()
|
.withFullPaths()
|
||||||
@ -130,7 +134,7 @@ async function isApexDomainAlive(apexDomain: string): Promise<[string, boolean]>
|
|||||||
let whois;
|
let whois;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
whois = await whoiser.domain(apexDomain);
|
whois = await getWhois(apexDomain);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('[whois fail]', 'whois error', { domain: apexDomain }, e);
|
console.log('[whois fail]', 'whois error', { domain: apexDomain }, e);
|
||||||
return [apexDomain, true];
|
return [apexDomain, true];
|
||||||
@ -238,7 +242,7 @@ export async function runAgainstDomainset(filepath: string) {
|
|||||||
for await (const l of readFileByLine(filepath)) {
|
for await (const l of readFileByLine(filepath)) {
|
||||||
const line = processLine(l);
|
const line = processLine(l);
|
||||||
if (!line) continue;
|
if (!line) continue;
|
||||||
promises.push(isDomainAlive(line, line[0] === '.'));
|
promises.push(keyedAsyncMutexWithQueue(line, () => isDomainAlive(line, line[0] === '.')));
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user