From bbc9020f66fb90bbe624d6f9dc0210c2c2bacf54 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 5 Dec 2022 15:22:18 -0500 Subject: [PATCH] *Update get_direct_peers to filter against dhtCache online list --- src/modules/plugins/rpc.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/modules/plugins/rpc.ts b/src/modules/plugins/rpc.ts index 90fcc06..a818e18 100644 --- a/src/modules/plugins/rpc.ts +++ b/src/modules/plugins/rpc.ts @@ -133,10 +133,20 @@ const plugin: Plugin = { api.registerMethod("get_direct_peers", { cacheable: false, async handler(): Promise { + const online = getRpcServer().cache.dhtCache.online; + const pubkey = b4a + .from(getRpcServer().cache.swarm.keyPair.publicKey) + .toString("hex"); + + if (online.has(pubkey)) { + online.delete(pubkey); + } + const topic = LUMEWEB_TOPIC_HASH.toString("hex"); return [...getRpcServer().cache.swarm.peers.values()] .filter((item: any) => [...item._seenTopics.keys()].includes(topic)) - .map((item: any) => item.publicKey.toString("hex")); + .map((item: any) => item.publicKey.toString("hex")) + .filter((item: any) => online.has(item)); }, }); },