*Try to update the available list every loop and only compare max _activeRelays against the min of _maxConnections and available

This commit is contained in:
Derrick Hammer 2022-07-26 23:20:34 -04:00
parent cb16b87b73
commit 5f37b74baf
1 changed files with 10 additions and 4 deletions

View File

@ -123,16 +123,22 @@ export default class DHT {
}
private async fillConnections(): Promise<any> {
let available = [...this._relays.keys()].filter(
let available: string[] = [];
const updateAvailable = () => {
available = [...this._relays.keys()].filter(
(x) => ![...this._activeRelays.keys()].includes(x)
);
};
updateAvailable();
let relayPromises = [];
if (0 === available.length) {
return;
}
while (
this._activeRelays.size <=
Math.min(this._maxConnections, available.length + this._activeRelays.size)
Math.min(this._maxConnections, available.length)
) {
const relayIndex = await randomNumber(0, available.length - 1);