* Add DNS setup functionality and import necessary clients, add peer and relay registration, and refactor DNS setup to use promises instead of callbacks.

This commit is contained in:
Derrick Hammer 2023-04-09 19:42:18 -04:00
parent 91cd5504c7
commit 61f7821c0b
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 25 additions and 11 deletions

View File

@ -30,12 +30,19 @@ import {
setKernelIframe, setKernelIframe,
setOpenPort, setOpenPort,
setTimer, setTimer,
getDnsSetupPromise,
getDnsSetupDefer,
} from "./vars.js"; } from "./vars.js";
// @ts-ignore // @ts-ignore
import browser from "@lumeweb/webextension-polyfill"; import browser from "@lumeweb/webextension-polyfill";
import setupContextMenus from "../contextMenu.js"; import setupContextMenus from "../contextMenu.js";
import { callModule } from "libkernel"; import { callModule } from "libkernel";
import { ipfsClient } from "../clients.js"; import {
dnsClient,
ipfsClient,
peerDiscoveryClient,
swarmClient,
} from "../clients.js";
function logLargeObjects() { function logLargeObjects() {
let queriesLen = Object.keys(getQueries()).length; let queriesLen = Object.keys(getQueries()).length;
@ -80,8 +87,6 @@ export function queryKernel(query: any): Promise<any> {
function handleKernelMessage(event: MessageEvent) { function handleKernelMessage(event: MessageEvent) {
let data = event.data.data; let data = event.data.data;
console.log("handleKernelMessage debug", event.data);
if (event.data.method === "kernelBridgeVersion") { if (event.data.method === "kernelBridgeVersion") {
getBlockForBridge().then(() => { getBlockForBridge().then(() => {
for (let [, port] of Object.entries(getOpenPorts())) { for (let [, port] of Object.entries(getOpenPorts())) {
@ -156,8 +161,6 @@ function handleBridgeMessage(
data: any, data: any,
domain: string domain: string
) { ) {
console.log("handleBridgeMessage debug", data.data);
if (data.method === "bridgeLoaded") { if (data.method === "bridgeLoaded") {
getBridgeLoadedResolve()(); getBridgeLoadedResolve()();
return; return;
@ -231,21 +234,32 @@ async function boot() {
// @ts-ignore // @ts-ignore
window.callModule = callModule; window.callModule = callModule;
await kernelLoaded(); await kernelLoaded();
await swarmClient.addRelay(
"fd35779a2dcae738308098e8f6702e25c282a52cce972ff2f96bcc50d5043c99"
);
await peerDiscoveryClient.register(
"_AEPtjxDCq3H4nmLLV7-P0L3D_d_Aude4i9O9S498dXcFw"
);
await ipfsClient.ready(); await ipfsClient.ready();
setupContextMenus(engine); setupContextMenus(engine);
setDnsSetupPromise(dnsSetup());
dnsSetup();
await getDnsSetupDefer().promise;
console.log("ready");
} }
async function dnsSetup() { async function dnsSetup() {
const resolvers = [ const resolvers = [
"AQBXtVkPDbZ5Qmjl8dzJ0siSYaFcS3XbDZHapxmZCLfwfg", // icann "_B0tpRWWzAf77qfhiRMx1EGTDURht_2V9VsUmMqIzcpW4Q", // ens
"_B1zdE-P7e1csLVoT9w3DvgxWGdDdUj9tnkRGzXyYV-rkg", // ens // "vAMl33T1TusZqZmJl9mlWJCbYm_Lu1TPjE3aSl2ZFHE_yg", // hns
"vAN0mq5cLYOK2e2Wk1Is980LYSW3reHKrd-w2-vqWfwNUw", // hns
]; ];
for (const resolver of resolvers) { for (const resolver of resolvers) {
await callModule(resolver, "register"); await dnsClient.registerResolver(resolver);
} }
getDnsSetupDefer().resolve();
} }
boot(); boot();