*Update dist
This commit is contained in:
parent
2e71082a59
commit
ec291909c4
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAkB5C,MAAM,CAAC,OAAO,OAAO,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,aAAa,CAA0C;IAC/D,OAAO,CAAC,eAAe,CAAM;IAC7B,OAAO,CAAC,OAAO,CAAS;gBAEZ,IAAI,KAAK;IAMrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAEY,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAiChD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAgBpC,WAAW,IAAI,IAAI;YAIZ,iBAAiB;IAazB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC;YAU/C,eAAe;CAoBhC;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAEvD"}
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAkB5C,MAAM,CAAC,OAAO,OAAO,GAAG;IACtB,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,aAAa,CAA0C;IAC/D,OAAO,CAAC,eAAe,CAAM;IAC7B,OAAO,CAAC,OAAO,CAAS;gBAEZ,IAAI,KAAK;IAMrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAEY,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAiChD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAepC,WAAW,IAAI,IAAI;YAIZ,iBAAiB;IAazB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC;YAc/C,eAAe;CAkC9B;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAEvD"}
|
|
@ -24,6 +24,9 @@ export default class DHT {
|
|||
this._options = opts;
|
||||
}
|
||||
ready() {
|
||||
if (this._inited) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
this._inited = true;
|
||||
return this.fillConnections();
|
||||
}
|
||||
|
@ -46,7 +49,7 @@ export default class DHT {
|
|||
if (isNaN(parseInt(port))) {
|
||||
return false;
|
||||
}
|
||||
this._relays[pubkey] = `wss://${domain}:${port}/`;
|
||||
this._relays.set(pubkey, `wss://${domain}:${port}/`);
|
||||
if (this._inited) {
|
||||
await this.fillConnections();
|
||||
}
|
||||
|
@ -86,9 +89,13 @@ export default class DHT {
|
|||
return node.connect(pubkey, options);
|
||||
}
|
||||
async fillConnections() {
|
||||
let available = [...this._relays.keys()].filter(x => [...this._activeRelays.keys()].includes(x));
|
||||
let available = [...this._relays.keys()].filter((x) => [...this._activeRelays.keys()].includes(x));
|
||||
let relayPromises = [];
|
||||
while (this._activeRelays.size <= Math.min(this._maxConnections, available.length + this._activeRelays.size)) {
|
||||
if (0 > available.length) {
|
||||
return;
|
||||
}
|
||||
while (this._activeRelays.size <=
|
||||
Math.min(this._maxConnections, available.length + this._activeRelays.size)) {
|
||||
const relayIndex = await randomNumber(0, available.length - 1);
|
||||
const connection = available[relayIndex];
|
||||
if (!this.isServerAvailable(connection)) {
|
||||
|
|
Loading…
Reference in New Issue