From da06f787dc766010b7d2e01365e55ebdef1d76f2 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 19 Jul 2022 14:46:10 -0400 Subject: [PATCH] *DHT connect in queryRelay can be a promise --- src/rpcQuery.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/rpcQuery.ts b/src/rpcQuery.ts index 31e9f07..917684f 100644 --- a/src/rpcQuery.ts +++ b/src/rpcQuery.ts @@ -63,7 +63,16 @@ export default class RpcQuery { } private async queryRelay(relay: string): Promise { - const socket = this._network.dht.connect(Buffer.from(relay, "hex")); + let socket: any; + + try { + socket = this._network.dht.connect(Buffer.from(relay, "hex")); + if (isPromise(socket)) { + socket = await socket; + } + } catch (e) { + return; + } return new Promise((resolve, reject) => { socket.on("data", (res: Buffer) => { socket.end();