From 0736469296951c7ffb29c7f684553da896ba2974 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 19 Apr 2023 04:47:48 -0400 Subject: [PATCH] refactor: removing rpc methods that require caching --- src/plugins/rpc.ts | 85 ---------------------------------------------- 1 file changed, 85 deletions(-) diff --git a/src/plugins/rpc.ts b/src/plugins/rpc.ts index ed506a6..dc79854 100644 --- a/src/plugins/rpc.ts +++ b/src/plugins/rpc.ts @@ -50,91 +50,6 @@ const plugin: Plugin = { name: "rpc", async plugin(_api: PluginAPI): Promise { api = _api; - if (api.config.bool("cache")) { - api.registerMethod("get_cached_item", { - cacheable: false, - async handler(req: string): Promise { - if (typeof req !== "string") { - throw new Error("item must be a string"); - } - - const cache = api.rpcServer.cache?.data; - - if (!cache?.has(req)) { - throw new Error("item does not exist"); - } - - return { - data: true, - ...cache.get(req)?.value, - signature: cache.get(req)?.signature, - }; - }, - }); - api.registerMethod("clear_cached_item", { - cacheable: false, - async handler(req: string): Promise { - if (typeof req !== "string") { - throw new Error("item must be a string"); - } - try { - api.rpcServer.cache.deleteItem(req); - } catch (e: any) { - throw e; - } - }, - }); - api.registerMethod("get_peers", { - cacheable: false, - async handler(): Promise { - const pubkey = b4a.from(api.identity.publicKeyRaw).toString("hex"); - - const online = api.rpcServer.cache?.dhtCache.online || new Set(); - if (online.has(pubkey)) { - online.delete(pubkey); - } - - return [...online]; - }, - }); - if (api.logger.level === "debug") { - api.registerMethod("get_direct_peers", { - cacheable: false, - async handler(): Promise { - const online = api.rpcServer.cache.dhtCache.online; - const pubkey = b4a - .from(api.swarm.keyPair.publicKeyRaw()) - .toString("hex"); - - if (online.has(pubkey)) { - online.delete(pubkey); - } - - const topic = LUMEWEB_TOPIC_HASH.toString("hex"); - return [...api.swarm.peers.values()] - .filter((item: any) => - [...item._seenTopics.keys()].includes(topic) - ) - .map((item: any) => item.publicKey.toString("hex")) - .filter((item: any) => online.has(item)); - }, - }); - api.registerMethod("get_bootstrap_info", { - cacheable: false, - async handler(): Promise { - // @ts-ignore - return api.rpcServer.cache.dhtCache._getBootstrapInfo(); - }, - }); - api.registerMethod("get_connected_peers", { - cacheable: false, - async handler(): Promise { - // @ts-ignore - return [...api.rpcServer.cache.dhtCache.connectedTo]; - }, - }); - } - } api.registerMethod("broadcast_request", { cacheable: false, async handler(req: RPCBroadcastRequest): Promise {