*Consolidate all dns setup into 1 function and store the promise

*await on the dns setup promise on the cached resolve function
This commit is contained in:
Derrick Hammer 2022-08-22 01:52:10 -04:00
parent 1ef168cd9e
commit 3f8e7075a1
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 13 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import {
ResolverOptions,
} from "@lumeweb/libresolver";
import { blake2b, bufToHex, Err } from "libskynet/dist";
import { getDnsSetupPromise } from "./main/vars.js";
const cache = new NodeCache({ stdTTL: 60 });
@ -27,7 +28,7 @@ export async function resolve(
return cache.get(cacheId) as DNSResult;
}
await dnsReady();
await getDnsSetupPromise();
let res;
try {

View File

@ -216,11 +216,10 @@ async function boot() {
document.body.appendChild(getKernelIframe());
setupContextMenus(engine);
await registerResolvers();
await dnsReady();
setDnsSetupPromise(dnsSetup());
}
async function registerResolvers() {
async function dnsSetup() {
const resolvers = [
"AQBXtVkPDbZ5Qmjl8dzJ0siSYaFcS3XbDZHapxmZCLfwfg", // icann
"AQAI3TbarrXRxWtrb_5XO-gMYg-UsjVAChue5JEoqywbAw", // eip137
@ -234,6 +233,8 @@ async function registerResolvers() {
for (const resolver of resolvers) {
await callModule(resolver, "register");
}
await dnsReady();
}
boot();

View File

@ -17,6 +17,7 @@ let blockForBridge = new Promise((resolve) => {
bridgeLoadedResolve = resolve;
});
let kernelFrame: HTMLIFrameElement;
let blockForDnsSetup: Promise<void>;
export function getAuthStatusKnown() {
return authStatusKnown;
@ -94,6 +95,12 @@ export function setKernelIframe(iframe: HTMLIFrameElement) {
kernelFrame = iframe;
}
export function setDnsSetupPromise(p: Promise<void>) {
blockForDnsSetup = p;
}
export function getDnsSetupPromise(): Promise<void> {
return blockForDnsSetup;
}
export function getAuthStatusResolve(): DataFn {
return authStatusResolve;
}