*Update get_direct_peers to filter against dhtCache online list
This commit is contained in:
parent
cd7b12e8b3
commit
bbc9020f66
|
@ -133,10 +133,20 @@ const plugin: Plugin = {
|
|||
api.registerMethod("get_direct_peers", {
|
||||
cacheable: false,
|
||||
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");
|
||||
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));
|
||||
},
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue