1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

feat(node/dns): Tts for A and AAAA record queries

This commit is contained in:
siaeyy 2025-01-15 05:26:21 +03:00
parent f5d1f3f038
commit e9a1b8e83a

View file

@ -186,20 +186,22 @@ export class ChannelWrap extends AsyncWrap implements ChannelWrapQuery {
this.#tries = tries; this.#tries = tries;
} }
async #query(query: string, recordType: Deno.RecordType) { async #query(query: string, recordType: Deno.RecordType, ttl?: boolean) {
// TODO(@bartlomieju): TTL logic.
let code: number; let code: number;
let ret: Awaited<ReturnType<typeof Deno.resolveDns>>; let ret: Awaited<ReturnType<typeof Deno.resolveDns>>;
const resolveOptions: Deno.ResolveDnsOptions = {
...ttl !== undefined ? { ttl } : {},
};
if (this.#servers.length) { if (this.#servers.length) {
for (const [ipAddr, port] of this.#servers) { for (const [ipAddr, port] of this.#servers) {
const resolveOptions = { Object.assign(resolveOptions, {
nameServer: { nameServer: {
ipAddr, ipAddr,
port, port,
}, },
}; });
({ code, ret } = await this.#resolve( ({ code, ret } = await this.#resolve(
query, query,
@ -212,7 +214,7 @@ export class ChannelWrap extends AsyncWrap implements ChannelWrapQuery {
} }
} }
} else { } else {
({ code, ret } = await this.#resolve(query, recordType)); ({ code, ret } = await this.#resolve(query, recordType, resolveOptions));
} }
return { code: code!, ret: ret! }; return { code: code!, ret: ret! };
@ -351,18 +353,34 @@ export class ChannelWrap extends AsyncWrap implements ChannelWrapQuery {
} }
queryA(req: QueryReqWrap, name: string): number { queryA(req: QueryReqWrap, name: string): number {
this.#query(name, "A").then(({ code, ret }) => { this.#query(name, "A", req.ttl).then(({ code, ret }) => {
req.oncomplete(code, ret); let recordsWithTtl;
if (req.ttl) {
recordsWithTtl = (ret as Deno.RecordWithTtl[]).map((val) => ({
address: val?.data,
ttl: val?.ttl,
}));
}
req.oncomplete(code, recordsWithTtl ?? ret);
}); });
return 0; return 0;
} }
queryAaaa(req: QueryReqWrap, name: string): number { queryAaaa(req: QueryReqWrap, name: string): number {
this.#query(name, "AAAA").then(({ code, ret }) => { this.#query(name, "AAAA", req.ttl).then(({ code, ret }) => {
const records = (ret as string[]).map((record) => compressIPv6(record)); let recordsWithTtl;
if (req.ttl) {
recordsWithTtl = (ret as Deno.RecordWithTtl[]).map((val) => ({
address: compressIPv6(val?.data as string),
ttl: val?.ttl,
}));
} else {
ret = (ret as string[]).map((record) => compressIPv6(record));
}
req.oncomplete(code, records); req.oncomplete(code, recordsWithTtl ?? ret);
}); });
return 0; return 0;