*Only choose a random index if we have more than 1 relay
This commit is contained in:
parent
7633e000e6
commit
21bcebb689
12
src/index.ts
12
src/index.ts
|
@ -113,11 +113,13 @@ export default class DHT {
|
||||||
throw new Error("Failed to find an available relay");
|
throw new Error("Failed to find an available relay");
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = this._activeRelays.get(
|
let index = 0;
|
||||||
[...this._activeRelays.keys()][
|
|
||||||
await randomNumber(0, this._activeRelays.size - 1)
|
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);
|
return node.connect(pubkey, options);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue