*Only choose a random index if we have more than 1 relay

This commit is contained in:
Derrick Hammer 2022-07-27 00:37:30 -04:00
parent 7633e000e6
commit 21bcebb689
1 changed files with 7 additions and 5 deletions

View File

@ -113,11 +113,13 @@ export default class DHT {
throw new Error("Failed to find an available relay");
}
const node = this._activeRelays.get(
[...this._activeRelays.keys()][
await randomNumber(0, this._activeRelays.size - 1)
]
);
let index = 0;
if (this._activeRelays.size > 1) {
index = await randomNumber(0, this._activeRelays.size - 1);
}
const node = this._activeRelays.get([...this._activeRelays.keys()][index]);
return node.connect(pubkey, options);
}