feat: add register method for network registry

This commit is contained in:
Derrick Hammer 2023-07-19 12:58:08 -04:00
parent 81f4fc2a0f
commit 663a67c7ba
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 11 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import { Helia } from "@helia/interface";
// @ts-ignore // @ts-ignore
import type { Components } from "libp2p/src/components.js"; import type { Components } from "libp2p/src/components.js";
import { libp2pConfig } from "./config.js"; import { libp2pConfig } from "./config.js";
import { createClient as createNetworkRegistryClient } from "@lumeweb/kernel-network-registry-client";
const basesByPrefix: { [prefix: string]: MultibaseDecoder<any> } = Object.keys( const basesByPrefix: { [prefix: string]: MultibaseDecoder<any> } = Object.keys(
bases, bases,
@ -35,11 +36,14 @@ const basesByPrefix: { [prefix: string]: MultibaseDecoder<any> } = Object.keys(
return acc; return acc;
}, {}); }, {});
const TYPES = ["content"];
onmessage = handleMessage; onmessage = handleMessage;
const moduleDefer = defer(); const moduleDefer = defer();
let activeIpfsPeersDefer = defer(); let activeIpfsPeersDefer = defer();
let networkPeersAvailable = defer(); let networkPeersAvailable = defer();
const networkRegistry = createNetworkRegistryClient();
let swarm; let swarm;
let proxy: MultiSocketProxy; let proxy: MultiSocketProxy;
@ -53,6 +57,7 @@ BigInt.prototype.toJSON = function () {
}; };
addHandler("presentKey", handlePresentKey); addHandler("presentKey", handlePresentKey);
addHandler("register", handleRegister);
addHandler("ready", handleReady); addHandler("ready", handleReady);
addHandler("stat", handleStat); addHandler("stat", handleStat);
addHandler("ls", handleLs, { receiveUpdates: true }); addHandler("ls", handleLs, { receiveUpdates: true });
@ -284,3 +289,9 @@ async function ready() {
await moduleDefer.promise; await moduleDefer.promise;
await networkPeersAvailable.promise; await networkPeersAvailable.promise;
} }
async function handleRegister(aq: ActiveQuery) {
await networkRegistry.registerNetwork(TYPES);
aq.respond();
}