*Update get_direct_peers to filter against dhtCache online list

This commit is contained in:
Derrick Hammer 2022-12-05 15:22:18 -05:00
parent cd7b12e8b3
commit bbc9020f66
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 11 additions and 1 deletions

View File

@ -133,10 +133,20 @@ const plugin: Plugin = {
api.registerMethod("get_direct_peers", { api.registerMethod("get_direct_peers", {
cacheable: false, cacheable: false,
async handler(): Promise<string[]> { async handler(): Promise<string[]> {
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"); const topic = LUMEWEB_TOPIC_HASH.toString("hex");
return [...getRpcServer().cache.swarm.peers.values()] return [...getRpcServer().cache.swarm.peers.values()]
.filter((item: any) => [...item._seenTopics.keys()].includes(topic)) .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));
}, },
}); });
}, },