From 2f9a0c7356057c441f31857fc5f61bc7c960c287 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 28 Nov 2022 00:14:11 -0500 Subject: [PATCH] *Refactor getRpcByPeer to operate in Buffers --- src/modules/rpc.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/rpc.ts b/src/modules/rpc.ts index d527d07..ac0fec1 100644 --- a/src/modules/rpc.ts +++ b/src/modules/rpc.ts @@ -7,6 +7,7 @@ import { errorExit } from "../lib/error.js"; import stringify from "json-stable-stringify"; import { getRpcServer, RPC_PROTOCOL_SYMBOL } from "./rpc/server.js"; import { get as getSwarm, SecretStream } from "./swarm.js"; +import b4a from "b4a"; export async function start() { if (!config.str("pocket-app-id") || !config.str("pocket-app-key")) { @@ -18,8 +19,9 @@ export async function start() { ); } -export async function getRpcByPeer(peer: string) { +export async function getRpcByPeer(peer: Buffer | string) { const swarm = getSwarm(); + peer = b4a.from(peer) as Buffer; if (swarm._allConnections.has(peer)) { return swarm._allConnections.get(peer)[RPC_PROTOCOL_SYMBOL]; @@ -28,7 +30,7 @@ export async function getRpcByPeer(peer: string) { return new Promise((resolve) => { const listener = () => {}; swarm.on("connection", (peer: any, info: any) => { - if (info.publicKey.toString("hex") !== peer) { + if (info.publicKey.toString("hex") !== peer.toString("hex")) { return; } swarm.removeListener("connection", listener);