*If max relays is greater than 0, and we have more relays than max relays, pick a random selection

This commit is contained in:
Derrick Hammer 2022-09-22 09:35:15 -04:00
parent fa8910a4fd
commit 47356ed6e0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 17 additions and 1 deletions

View File

@ -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;
}
}