*add get_peers and get_direct_peers api methods to the core rpc plugin
ci/woodpecker/push/woodpecker Pipeline failed Details

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

View File

@ -9,7 +9,7 @@ import {
RPCResponse, RPCResponse,
} from "@lumeweb/relay-types"; } from "@lumeweb/relay-types";
import { getRpcByPeer } from "../rpc"; import { getRpcByPeer } from "../rpc";
import { get as getSwarm } from "../swarm"; import { get as getSwarm, LUMEWEB_TOPIC_HASH } from "../swarm";
import b4a from "b4a"; import b4a from "b4a";
async function broadcastRequest( async function broadcastRequest(
@ -124,6 +124,21 @@ const plugin: Plugin = {
return result; return result;
}, },
}); });
api.registerMethod("get_peers", {
cacheable: false,
async handler(): Promise<string[]> {
return [...getRpcServer().cache.dhtCache.online];
},
});
api.registerMethod("get_direct_peers", {
cacheable: false,
async handler(): Promise<string[]> {
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"));
},
});
}, },
}; };