Compare commits

...

2 Commits

Author SHA1 Message Date
Derrick Hammer 1970763114
*Update dist 2023-02-17 09:26:10 -05:00
Derrick Hammer ff7266f05e
*Switch to backoff.js 2023-02-17 09:25:58 -05:00
4 changed files with 23 additions and 34 deletions

2
dist/index.d.ts.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,MAAM,EAAW,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAU,QAAQ,EAAY,MAAM,gBAAgB,CAAC;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD,qBAAa,WAAY,SAAQ,MAAM;IACrC,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,eAAe,CAAU;IAEjC,OAAO,CAAC,MAAM,CAAC,CAAgB;gBAEnB,aAAa,UAAO,EAAE,aAAa,UAAQ;IAWvD,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAEY,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAa5D,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC;IAGzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAetB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAcd,OAAO;IAaR,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAG5B,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAI9B,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG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a,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,EAClD,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI;IAiBP,GAAG,CAAC,CAAC,SAAS,YAAY,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,EACpD,KAAK,EAAE,CAAC,EACR,EAAE,CAAC,EAAE,YAAY,CAAC,aAAa,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,EACnD,OAAO,CAAC,EAAE,GAAG,EACb,IAAI,CAAC,EAAE,OAAO,GACb,IAAI;IASP,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrC,GAAG,IAAI,IAAI;IAUX,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,UAAU;CAInB;AAID,eAAO,MAAM,YAAY,+BAA4C,CAAC"}

25
dist/index.js vendored
View File

@ -1,6 +1,7 @@
import { Client, factory } from "@lumeweb/libkernel-universal";
import { hexToBuf } from "@siaweb/libweb";
import backoff from "backoff";
// @ts-ignore
import Backoff from "backoff.js";
export class SwarmClient extends Client {
useDefaultSwarm;
id = 0;
@ -11,9 +12,9 @@ export class SwarmClient extends Client {
super();
this.useDefaultSwarm = useDefaultDht;
this._autoReconnect = autoReconnect;
this._connectBackoff = backoff.fibonacci();
this._connectBackoff.on("ready", () => {
this.start();
this._connectBackoff = new Backoff({
strategy: "fibo",
maxAttempts: 0,
});
}
get swarm() {
@ -41,18 +42,12 @@ export class SwarmClient extends Client {
this._ready = this.callModuleReturn("ready", { swarm: this.swarm });
await this._ready;
this._ready = undefined;
this._connectBackoff.reset();
}
async start() {
const backoff = () => setImmediate(() => this._connectBackoff.backoff());
try {
await this.init();
}
catch (e) {
this.logErr(e);
backoff();
return;
}
this._connectBackoff.run(() => this.init());
this._connectBackoff.on("retry", (error) => {
this.logErr(error);
});
await this.ready();
}
async _listen() {
@ -60,7 +55,7 @@ export class SwarmClient extends Client {
this.emit("connection", await createSocket(socketId));
});
await connect[1];
this._connectBackoff.backoff();
this.start();
}
async addRelay(pubkey) {
return this.callModuleReturn("addRelay", { pubkey, swarm: this.swarm });

View File

@ -6,11 +6,10 @@
"dependencies": {
"@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git",
"@siaweb/libweb": "git+https://git.lumeweb.com/LumeWeb/libsiaweb.git",
"backoff": "^2.5.0",
"backoff.js": "^1.0.4",
"eventemitter3": "^5.0.0"
},
"devDependencies": {
"@types/backoff": "^2.5.2",
"@types/node": "^18.13.0",
"prettier": "^2.8.4",
"pretty": "^2.0.0",

View File

@ -4,13 +4,14 @@ import { DataFn, ErrTuple, hexToBuf } from "@siaweb/libweb";
import type { EventEmitter } from "eventemitter3";
import backoff, { Backoff } from "backoff";
// @ts-ignore
import Backoff from "backoff.js";
export class SwarmClient extends Client {
private useDefaultSwarm: boolean;
private id: number = 0;
private _autoReconnect: boolean;
private _connectBackoff: Backoff;
private _connectBackoff: any;
private _ready?: Promise<void>;
@ -18,10 +19,9 @@ export class SwarmClient extends Client {
super();
this.useDefaultSwarm = useDefaultDht;
this._autoReconnect = autoReconnect;
this._connectBackoff = backoff.fibonacci();
this._connectBackoff.on("ready", () => {
this.start();
this._connectBackoff = new Backoff({
strategy: "fibo",
maxAttempts: 0,
});
}
@ -57,19 +57,14 @@ export class SwarmClient extends Client {
await this._ready;
this._ready = undefined;
this._connectBackoff.reset();
}
async start(): Promise<void> {
const backoff = () => setImmediate(() => this._connectBackoff.backoff());
this._connectBackoff.run(() => this.init());
try {
await this.init();
} catch (e) {
this.logErr(e);
backoff();
return;
}
this._connectBackoff.on("retry", (error: any) => {
this.logErr(error);
});
await this.ready();
}
@ -84,7 +79,7 @@ export class SwarmClient extends Client {
);
await connect[1];
this._connectBackoff.backoff();
this.start();
}
public async addRelay(pubkey: string): Promise<void> {