From 663a67c7ba9450c6a499f6ce3dcb06d0245476d3 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 19 Jul 2023 12:58:08 -0400 Subject: [PATCH] feat: add register method for network registry --- src/index.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/index.ts b/src/index.ts index bcd75bd..2cbd274 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,6 +26,7 @@ import { Helia } from "@helia/interface"; // @ts-ignore import type { Components } from "libp2p/src/components.js"; import { libp2pConfig } from "./config.js"; +import { createClient as createNetworkRegistryClient } from "@lumeweb/kernel-network-registry-client"; const basesByPrefix: { [prefix: string]: MultibaseDecoder } = Object.keys( bases, @@ -35,11 +36,14 @@ const basesByPrefix: { [prefix: string]: MultibaseDecoder } = Object.keys( return acc; }, {}); +const TYPES = ["content"]; + onmessage = handleMessage; const moduleDefer = defer(); let activeIpfsPeersDefer = defer(); let networkPeersAvailable = defer(); +const networkRegistry = createNetworkRegistryClient(); let swarm; let proxy: MultiSocketProxy; @@ -53,6 +57,7 @@ BigInt.prototype.toJSON = function () { }; addHandler("presentKey", handlePresentKey); +addHandler("register", handleRegister); addHandler("ready", handleReady); addHandler("stat", handleStat); addHandler("ls", handleLs, { receiveUpdates: true }); @@ -284,3 +289,9 @@ async function ready() { await moduleDefer.promise; await networkPeersAvailable.promise; } + +async function handleRegister(aq: ActiveQuery) { + await networkRegistry.registerNetwork(TYPES); + + aq.respond(); +}