From 47356ed6e082f9d14ddb8ac6895c2052d372d405 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 22 Sep 2022 09:35:15 -0400 Subject: [PATCH] *If max relays is greater than 0, and we have more relays than max relays, pick a random selection --- src/query/wisdom.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/query/wisdom.ts b/src/query/wisdom.ts index fd0572a..8ee9ba4 100644 --- a/src/query/wisdom.ts +++ b/src/query/wisdom.ts @@ -86,6 +86,22 @@ export default class WisdomRpcQuery extends RpcQueryBase { } protected getRelays(): string[] | [] { - return this._network.relays; + if ( + this._network.maxRelays === 0 || + this._network.relays.length <= this._network.maxRelays + ) { + return this._network.relays; + } + + const list: string[] = []; + let available = this._network.relays; + + while (list.length < this._network.maxRelays) { + const item = Math.floor(Math.random() * available.length); + list.push(available[item]); + available.splice(item, 1); + } + + return list; } }