parent
cf4df9dc91
commit
0204e4d5e3
|
@ -4,8 +4,9 @@ import {
|
||||||
DNS_RECORD_TYPE,
|
DNS_RECORD_TYPE,
|
||||||
resolverError,
|
resolverError,
|
||||||
} from "@lumeweb/resolver-common";
|
} from "@lumeweb/resolver-common";
|
||||||
import { resolve } from "@lumeweb/kernel-dns-client";
|
import { getResolvers, resolve } from "@lumeweb/kernel-dns-client";
|
||||||
import { RpcNetwork } from "@lumeweb/kernel-rpc-client";
|
import { RpcNetwork } from "@lumeweb/kernel-rpc-client";
|
||||||
|
import { callModule } from "libkmodule";
|
||||||
|
|
||||||
export class ResolverRegistry {
|
export class ResolverRegistry {
|
||||||
private _rpcNetwork: RpcNetwork;
|
private _rpcNetwork: RpcNetwork;
|
||||||
|
@ -18,6 +19,18 @@ export class ResolverRegistry {
|
||||||
return this._rpcNetwork;
|
return this._rpcNetwork;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get resolvers(): Promise<Set<ResolverModule>> {
|
||||||
|
return getResolvers()
|
||||||
|
.catch(() => {
|
||||||
|
return new Set();
|
||||||
|
})
|
||||||
|
.then((resolvers: string[]) => {
|
||||||
|
return new Set(
|
||||||
|
resolvers.map((resolver) => new ResolverModule(this, resolver))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async resolve(
|
public async resolve(
|
||||||
domain: string,
|
domain: string,
|
||||||
options: ResolverOptions = { type: DNS_RECORD_TYPE.DEFAULT },
|
options: ResolverOptions = { type: DNS_RECORD_TYPE.DEFAULT },
|
||||||
|
@ -35,4 +48,31 @@ export class ResolverRegistry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ResolverModule {
|
||||||
|
private resolver: ResolverRegistry;
|
||||||
|
private domain: string;
|
||||||
|
|
||||||
|
constructor(resolver: ResolverRegistry, domain: string) {
|
||||||
|
this.resolver = resolver;
|
||||||
|
this.domain = domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
async resolve(
|
||||||
|
domain: string,
|
||||||
|
options: ResolverOptions,
|
||||||
|
bypassCache: boolean
|
||||||
|
): Promise<DNSResult> {
|
||||||
|
const [ret, err] = await callModule(this.domain, "resolve", {
|
||||||
|
domain,
|
||||||
|
options,
|
||||||
|
bypassCache,
|
||||||
|
});
|
||||||
|
if (err) {
|
||||||
|
return resolverError(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export { RpcNetwork };
|
export { RpcNetwork };
|
||||||
|
|
Loading…
Reference in New Issue