*Property handle follow ns/glue records for A lookup

*Handle NS record lookup
*Dedupe array elements using serialization and set
*Ensure options.options is an object for simplicity
This commit is contained in:
Derrick Hammer 2022-08-20 12:09:09 -04:00
parent f3379652a6
commit cab30a8c13
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 27 additions and 12 deletions

View File

@ -8,7 +8,6 @@ import {
isPromise, isPromise,
normalizeDomain, normalizeDomain,
resolverEmptyResponse, resolverEmptyResponse,
ResolverModule,
ResolverOptions, ResolverOptions,
resolveSuccess, resolveSuccess,
} from "@lumeweb/resolver-common"; } from "@lumeweb/resolver-common";
@ -48,6 +47,7 @@ export default class Handshake extends AbstractResolverModule {
options: ResolverOptions, options: ResolverOptions,
bypassCache: boolean bypassCache: boolean
): Promise<DNSResult> { ): Promise<DNSResult> {
options.options = options.options || {};
const tld = getTld(domain); const tld = getTld(domain);
const blacklist = await this.buildBlacklist(); const blacklist = await this.buildBlacklist();
@ -74,7 +74,14 @@ export default class Handshake extends AbstractResolverModule {
for (const record of chainRecords as HnsRecord[]) { for (const record of chainRecords as HnsRecord[]) {
switch (record.type) { switch (record.type) {
case "NS": { case "NS": {
await this.processNs(domain, record, records, options, bypassCache); await this.processNs(
domain,
record,
records,
chainRecords as HnsRecord[],
options,
bypassCache
);
break; break;
} }
case "GLUE4": { case "GLUE4": {
@ -113,6 +120,10 @@ export default class Handshake extends AbstractResolverModule {
} }
} }
records = [
...new Set(records.map((item: DNSRecord) => JSON.stringify(item))),
].map((item) => JSON.parse(item));
if (0 < records.length) { if (0 < records.length) {
return resolveSuccess(records); return resolveSuccess(records);
} }
@ -125,6 +136,7 @@ export default class Handshake extends AbstractResolverModule {
domain: string, domain: string,
record: HnsRecord, record: HnsRecord,
records: DNSRecord[], records: DNSRecord[],
hnsRecords: HnsRecord[],
options: ResolverOptions, options: ResolverOptions,
bypassCache: boolean bypassCache: boolean
) { ) {
@ -136,26 +148,31 @@ export default class Handshake extends AbstractResolverModule {
return; return;
} }
// @ts-ignore // @ts-ignore
const glue = records.slice().find( const glue = hnsRecords.slice().find(
(item: object) => (item: object) =>
// @ts-ignore // @ts-ignore
["GLUE4", "GLUE6"].includes(item.type) && item.ns === record.ns ["GLUE4", "GLUE6"].includes(item.type) && item.ns === record.ns
); );
if (glue) { if (glue && options.type !== DNS_RECORD_TYPE.NS) {
return this.processGlue(domain, record, records, options, bypassCache); return this.processGlue(domain, glue, records, options, bypassCache);
}
if (options.type === DNS_RECORD_TYPE.NS) {
records.push({ type: options.type, value: record.ns });
return;
} }
const foundDomain = normalizeDomain(record.ns); const foundDomain = normalizeDomain(record.ns);
let isIcann = false;
let isIcann = false;
let isHip5 = false; let isHip5 = false;
let hip5Parts = foundDomain.split("."); let hip5Parts = foundDomain.split(".");
if ( if (
hip5Parts.length >= 2 && hip5Parts.length >= 2 &&
[...options.options?.hip5, ...HIP5_EXTENSIONS].includes( [...(options.options?.hip5 ?? []), ...HIP5_EXTENSIONS].includes(
hip5Parts[hip5Parts.length - 1] hip5Parts[hip5Parts.length - 1]
) )
) { ) {
@ -184,6 +201,8 @@ export default class Handshake extends AbstractResolverModule {
}, },
}); });
} }
return resolverEmptyResponse();
} }
return this.resolver.resolve(domain, { return this.resolver.resolve(domain, {
@ -209,11 +228,7 @@ export default class Handshake extends AbstractResolverModule {
options: ResolverOptions, options: ResolverOptions,
bypassCache: boolean bypassCache: boolean
) { ) {
if ( if (![DNS_RECORD_TYPE.A, DNS_RECORD_TYPE.CNAME].includes(options.type)) {
![DNS_RECORD_TYPE.A, DNS_RECORD_TYPE.CNAME, DNS_RECORD_TYPE.NS].includes(
options.type
)
) {
return; return;
} }
if (isDomain(record.ns) && isIp(record.address)) { if (isDomain(record.ns) && isIp(record.address)) {