*add get_peers and get_direct_peers api methods to the core rpc plugin
ci/woodpecker/push/woodpecker Pipeline failed
Details
ci/woodpecker/push/woodpecker Pipeline failed
Details
This commit is contained in:
parent
e35b602133
commit
cd7b12e8b3
|
@ -9,7 +9,7 @@ import {
|
|||
RPCResponse,
|
||||
} from "@lumeweb/relay-types";
|
||||
import { getRpcByPeer } from "../rpc";
|
||||
import { get as getSwarm } from "../swarm";
|
||||
import { get as getSwarm, LUMEWEB_TOPIC_HASH } from "../swarm";
|
||||
import b4a from "b4a";
|
||||
|
||||
async function broadcastRequest(
|
||||
|
@ -124,6 +124,21 @@ const plugin: Plugin = {
|
|||
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"));
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue