From ff10bc05ecc9fb69af81e13b0c764d053925261f Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Thu, 31 Jul 2025 11:05:22 +0800 Subject: [PATCH] chore: --- .../src/modules/monitor/service/dns-custom.ts | 58 ++++++------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/packages/ui/certd-server/src/modules/monitor/service/dns-custom.ts b/packages/ui/certd-server/src/modules/monitor/service/dns-custom.ts index 29436b96..951dd1da 100644 --- a/packages/ui/certd-server/src/modules/monitor/service/dns-custom.ts +++ b/packages/ui/certd-server/src/modules/monitor/service/dns-custom.ts @@ -1,15 +1,15 @@ import {LocalCache, logger} from '@certd/basic'; import dnsSdk, {AnyRecord} from 'dns' -import { LRUCache } from 'lru-cache'; import {LookupAddress} from "node:dns"; + const dns = dnsSdk.promises export class DnsCustom{ private resolver: dnsSdk.promises.Resolver; - private cache = new LRUCache({ - max: 1000, - ttl: 1000 * 60 * 5, - }); + // private cache = new LRUCache({ + // max: 1000, + // ttl: 1000 * 60 * 5, + // }); constructor(dnsServers:string[]) { const resolver = new dns.Resolver(); @@ -17,45 +17,21 @@ export class DnsCustom{ this.resolver = resolver; } + // async lookup(hostname:string,options?:{ family: any, hints: number, all: boolean }):Promise{ + // const cacheKey = hostname + JSON.stringify(options) + // let res = this.cache.get(cacheKey) + // if (res){ + // return res + // } + // res = await this.doLookup(hostname,options) + // this.cache.set(cacheKey,res) + // return res + // } async lookup(hostname:string,options?:{ family: any, hints: number, all: boolean }):Promise{ - const cacheKey = hostname + JSON.stringify(options) - let res = this.cache.get(cacheKey) - if (res){ - return res - } - res = await this.doLookup(hostname,options) - this.cache.set(cacheKey,res) - return res - } - async doLookup(hostname:string,options?:{ family: any, hints: number, all: boolean }):Promise{ // { family: undefined, hints: 0, all: true } - let cnameIps:LookupAddress[] = [] let v4:LookupAddress[] = [] let v6:LookupAddress[] = [] let errors = [] - const resolveCname = async ()=>{ - let cnames = [] - try{ - cnames = await this.resolver.resolveCname(hostname) - }catch (e) { - errors.push(e) - logger.warn("query cname error",e) - } - // deep - if (cnames && cnames.length > 0) { - for (let cname of cnames) { - try{ - const cnameIp = await this.lookup(cname,options) - if (cnameIp && cnameIp.length > 0) { - cnameIps.push(...cnameIp) - } - }catch (e) { - errors.push(e) - logger.warn("lookup cname error",e) - } - } - } - } const queryV6 = async ()=>{ try{ const list = await this.resolver.resolve6(hostname) @@ -89,7 +65,7 @@ export class DnsCustom{ } } - const queries:Promise[] = [resolveCname()] + const queries:Promise[] = [] const {family, all} = options @@ -105,7 +81,7 @@ export class DnsCustom{ } } await Promise.all(queries) - const res = [...v4,...v6,...cnameIps] + const res = [...v4,...v6] if(res.length === 0){ if (errors.length > 0){ const e = new Error(errors[0])