Compare commits
No commits in common. "1970763114b96c247a81153c270f622aef36e362" and "acbc5408c995194e32d01bea58e8eea3e91a003b" have entirely different histories.
1970763114
...
acbc5408c9
|
@ -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;AAKlD,qBAAa,WAAY,SAAQ,MAAM;IACrC,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,eAAe,CAAM;IAE7B,OAAO,CAAC,MAAM,CAAC,CAAgB;gBAEnB,aAAa,UAAO,EAAE,aAAa,UAAQ;IAUvD,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;IActB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAUd,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,OAAO,CAAC,IAAI,CAAC;CAGhD;AAQD,qBAAa,MAAO,SAAQ,MAAM;I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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"}
|
|
@ -1,7 +1,6 @@
|
||||||
import { Client, factory } from "@lumeweb/libkernel-universal";
|
import { Client, factory } from "@lumeweb/libkernel-universal";
|
||||||
import { hexToBuf } from "@siaweb/libweb";
|
import { hexToBuf } from "@siaweb/libweb";
|
||||||
// @ts-ignore
|
import backoff from "backoff";
|
||||||
import Backoff from "backoff.js";
|
|
||||||
export class SwarmClient extends Client {
|
export class SwarmClient extends Client {
|
||||||
useDefaultSwarm;
|
useDefaultSwarm;
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -12,9 +11,9 @@ export class SwarmClient extends Client {
|
||||||
super();
|
super();
|
||||||
this.useDefaultSwarm = useDefaultDht;
|
this.useDefaultSwarm = useDefaultDht;
|
||||||
this._autoReconnect = autoReconnect;
|
this._autoReconnect = autoReconnect;
|
||||||
this._connectBackoff = new Backoff({
|
this._connectBackoff = backoff.fibonacci();
|
||||||
strategy: "fibo",
|
this._connectBackoff.on("ready", () => {
|
||||||
maxAttempts: 0,
|
this.start();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
get swarm() {
|
get swarm() {
|
||||||
|
@ -42,12 +41,18 @@ export class SwarmClient extends Client {
|
||||||
this._ready = this.callModuleReturn("ready", { swarm: this.swarm });
|
this._ready = this.callModuleReturn("ready", { swarm: this.swarm });
|
||||||
await this._ready;
|
await this._ready;
|
||||||
this._ready = undefined;
|
this._ready = undefined;
|
||||||
|
this._connectBackoff.reset();
|
||||||
}
|
}
|
||||||
async start() {
|
async start() {
|
||||||
this._connectBackoff.run(() => this.init());
|
const backoff = () => setImmediate(() => this._connectBackoff.backoff());
|
||||||
this._connectBackoff.on("retry", (error) => {
|
try {
|
||||||
this.logErr(error);
|
await this.init();
|
||||||
});
|
}
|
||||||
|
catch (e) {
|
||||||
|
this.logErr(e);
|
||||||
|
backoff();
|
||||||
|
return;
|
||||||
|
}
|
||||||
await this.ready();
|
await this.ready();
|
||||||
}
|
}
|
||||||
async _listen() {
|
async _listen() {
|
||||||
|
@ -55,7 +60,7 @@ export class SwarmClient extends Client {
|
||||||
this.emit("connection", await createSocket(socketId));
|
this.emit("connection", await createSocket(socketId));
|
||||||
});
|
});
|
||||||
await connect[1];
|
await connect[1];
|
||||||
this.start();
|
this._connectBackoff.backoff();
|
||||||
}
|
}
|
||||||
async addRelay(pubkey) {
|
async addRelay(pubkey) {
|
||||||
return this.callModuleReturn("addRelay", { pubkey, swarm: this.swarm });
|
return this.callModuleReturn("addRelay", { pubkey, swarm: this.swarm });
|
||||||
|
|
|
@ -6,10 +6,11 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git",
|
"@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git",
|
||||||
"@siaweb/libweb": "git+https://git.lumeweb.com/LumeWeb/libsiaweb.git",
|
"@siaweb/libweb": "git+https://git.lumeweb.com/LumeWeb/libsiaweb.git",
|
||||||
"backoff.js": "^1.0.4",
|
"backoff": "^2.5.0",
|
||||||
"eventemitter3": "^5.0.0"
|
"eventemitter3": "^5.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/backoff": "^2.5.2",
|
||||||
"@types/node": "^18.13.0",
|
"@types/node": "^18.13.0",
|
||||||
"prettier": "^2.8.4",
|
"prettier": "^2.8.4",
|
||||||
"pretty": "^2.0.0",
|
"pretty": "^2.0.0",
|
||||||
|
|
27
src/index.ts
27
src/index.ts
|
@ -4,14 +4,13 @@ import { DataFn, ErrTuple, hexToBuf } from "@siaweb/libweb";
|
||||||
|
|
||||||
import type { EventEmitter } from "eventemitter3";
|
import type { EventEmitter } from "eventemitter3";
|
||||||
|
|
||||||
// @ts-ignore
|
import backoff, { Backoff } from "backoff";
|
||||||
import Backoff from "backoff.js";
|
|
||||||
|
|
||||||
export class SwarmClient extends Client {
|
export class SwarmClient extends Client {
|
||||||
private useDefaultSwarm: boolean;
|
private useDefaultSwarm: boolean;
|
||||||
private id: number = 0;
|
private id: number = 0;
|
||||||
private _autoReconnect: boolean;
|
private _autoReconnect: boolean;
|
||||||
private _connectBackoff: any;
|
private _connectBackoff: Backoff;
|
||||||
|
|
||||||
private _ready?: Promise<void>;
|
private _ready?: Promise<void>;
|
||||||
|
|
||||||
|
@ -19,9 +18,10 @@ export class SwarmClient extends Client {
|
||||||
super();
|
super();
|
||||||
this.useDefaultSwarm = useDefaultDht;
|
this.useDefaultSwarm = useDefaultDht;
|
||||||
this._autoReconnect = autoReconnect;
|
this._autoReconnect = autoReconnect;
|
||||||
this._connectBackoff = new Backoff({
|
this._connectBackoff = backoff.fibonacci();
|
||||||
strategy: "fibo",
|
|
||||||
maxAttempts: 0,
|
this._connectBackoff.on("ready", () => {
|
||||||
|
this.start();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,14 +57,19 @@ export class SwarmClient extends Client {
|
||||||
await this._ready;
|
await this._ready;
|
||||||
|
|
||||||
this._ready = undefined;
|
this._ready = undefined;
|
||||||
|
this._connectBackoff.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
async start(): Promise<void> {
|
async start(): Promise<void> {
|
||||||
this._connectBackoff.run(() => this.init());
|
const backoff = () => setImmediate(() => this._connectBackoff.backoff());
|
||||||
|
|
||||||
this._connectBackoff.on("retry", (error: any) => {
|
try {
|
||||||
this.logErr(error);
|
await this.init();
|
||||||
});
|
} catch (e) {
|
||||||
|
this.logErr(e);
|
||||||
|
backoff();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await this.ready();
|
await this.ready();
|
||||||
}
|
}
|
||||||
|
@ -79,7 +84,7 @@ export class SwarmClient extends Client {
|
||||||
);
|
);
|
||||||
|
|
||||||
await connect[1];
|
await connect[1];
|
||||||
this.start();
|
this._connectBackoff.backoff();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async addRelay(pubkey: string): Promise<void> {
|
public async addRelay(pubkey: string): Promise<void> {
|
||||||
|
|
Loading…
Reference in New Issue