*Fix usage of connection
This commit is contained in:
parent
b4962e994b
commit
007b9a09d7
11
src/index.ts
11
src/index.ts
|
@ -123,8 +123,8 @@ export default class DHT {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async fillConnections(): Promise<any> {
|
private async fillConnections(): Promise<any> {
|
||||||
let available = [...this._relays.keys()].filter((x) =>
|
let available = [...this._relays.keys()].filter(
|
||||||
![...this._activeRelays.keys()].includes(x)
|
(x) => ![...this._activeRelays.keys()].includes(x)
|
||||||
);
|
);
|
||||||
let relayPromises = [];
|
let relayPromises = [];
|
||||||
if (0 === available.length) {
|
if (0 === available.length) {
|
||||||
|
@ -136,17 +136,14 @@ export default class DHT {
|
||||||
) {
|
) {
|
||||||
const relayIndex = await randomNumber(0, available.length - 1);
|
const relayIndex = await randomNumber(0, available.length - 1);
|
||||||
|
|
||||||
const connection = available[relayIndex];
|
const connection = this._relays.get(available[relayIndex]);
|
||||||
|
|
||||||
if (!this.isServerAvailable(connection)) {
|
if (!this.isServerAvailable(connection)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = new DhtNode(
|
const node = new DhtNode(
|
||||||
new Stream(
|
new Stream(true, new WebSocket(connection)),
|
||||||
true,
|
|
||||||
new WebSocket(this._relays.get(connection) as string)
|
|
||||||
),
|
|
||||||
this._options
|
this._options
|
||||||
);
|
);
|
||||||
this._activeRelays.set(available[relayIndex], node);
|
this._activeRelays.set(available[relayIndex], node);
|
||||||
|
|
Loading…
Reference in New Issue