*Update dist
This commit is contained in:
parent
35c6a0e314
commit
90aeec6802
|
@ -8,8 +8,9 @@ export default class DHTCache extends EventEmitter {
|
||||||
private bootstrapped;
|
private bootstrapped;
|
||||||
private graph;
|
private graph;
|
||||||
private connectedTo;
|
private connectedTo;
|
||||||
|
private heartBeatInterval;
|
||||||
protected flood: DHTFlood;
|
protected flood: DHTFlood;
|
||||||
constructor(swarm: any, { id, ...opts }?: {
|
constructor(swarm: any, { id, heartBeatInterval, ...opts }?: {
|
||||||
id?: Buffer;
|
id?: Buffer;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAYlC,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAa1C,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,YAAY;IAChD,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;IACrB,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,WAAW,CAAW;IAE9B,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC;gBAGxB,KAAK,EAAE,GAAG,EACV,EACE,EAA4B,EAC5B,GAAG,IAAI,EACR,GAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAO;IAoC7C,OAAO,CAAC,MAAM,CAAc;IAE5B,IAAW,KAAK,IAAI,MAAM,EAAE,CAE3B;IAED,IAAW,QAAQ,IAAI,MAAM,EAAE,CAU9B;IAEM,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IAOlE,OAAO,CAAC,IAAI,EAAE,MAAM,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OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,uBAAuB;IAa/B,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,cAAc;IAwBtB,OAAO,CAAC,iBAAiB;IAoBzB,OAAO,CAAC,YAAY;IA0CpB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,WAAW;IA0BnB,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,cAAc;CA2BvB"}
|
|
@ -22,8 +22,9 @@ class DHTCache extends events_1.default {
|
||||||
bootstrapped;
|
bootstrapped;
|
||||||
graph;
|
graph;
|
||||||
connectedTo;
|
connectedTo;
|
||||||
|
heartBeatInterval;
|
||||||
flood;
|
flood;
|
||||||
constructor(swarm, { id = swarm.keyPair.publicKey, ...opts } = {}) {
|
constructor(swarm, { id = swarm.keyPair.publicKey, heartBeatInterval = 15, ...opts } = {}) {
|
||||||
super();
|
super();
|
||||||
if (!id)
|
if (!id)
|
||||||
throw new TypeError("Must provide id for self");
|
throw new TypeError("Must provide id for self");
|
||||||
|
@ -31,6 +32,7 @@ class DHTCache extends events_1.default {
|
||||||
this.bootstrapped = false;
|
this.bootstrapped = false;
|
||||||
this.graph = new jsnetworkx_1.DiGraph();
|
this.graph = new jsnetworkx_1.DiGraph();
|
||||||
this.connectedTo = new Set();
|
this.connectedTo = new Set();
|
||||||
|
this.heartBeatInterval = heartBeatInterval;
|
||||||
this._cache = new Set();
|
this._cache = new Set();
|
||||||
this._online = new Set([this._maybeHexify(this.id)]);
|
this._online = new Set([this._maybeHexify(this.id)]);
|
||||||
this.swarm = swarm;
|
this.swarm = swarm;
|
||||||
|
@ -49,7 +51,7 @@ class DHTCache extends events_1.default {
|
||||||
});
|
});
|
||||||
this._ensurePeer(this.id);
|
this._ensurePeer(this.id);
|
||||||
setInterval(() => this._heartbeatCheck(), 5 * 1000);
|
setInterval(() => this._heartbeatCheck(), 5 * 1000);
|
||||||
setInterval(() => this._emitHeartbeat(), 60 * 1000);
|
setInterval(() => this._emitHeartbeat(), this.heartBeatInterval * 1000);
|
||||||
}
|
}
|
||||||
_cache;
|
_cache;
|
||||||
get cache() {
|
get cache() {
|
||||||
|
@ -330,6 +332,9 @@ class DHTCache extends events_1.default {
|
||||||
this.graph.removeNode(id);
|
this.graph.removeNode(id);
|
||||||
}
|
}
|
||||||
for (const id of online) {
|
for (const id of online) {
|
||||||
|
if (b4a_1.default.equals(b4a_1.default.from(id, "hex"), this.id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const item = this.graph.node.get(id);
|
const item = this.graph.node.get(id);
|
||||||
if (!item?.online) {
|
if (!item?.online) {
|
||||||
online.delete(id);
|
online.delete(id);
|
||||||
|
@ -376,7 +381,9 @@ class DHTCache extends events_1.default {
|
||||||
const node = this.graph.node.get(peer);
|
const node = this.graph.node.get(peer);
|
||||||
const heartbeat = node?.heartbeat;
|
const heartbeat = node?.heartbeat;
|
||||||
const conn = this.swarm._allConnections.get(pubkey);
|
const conn = this.swarm._allConnections.get(pubkey);
|
||||||
const online = conn && heartbeat > 0 && Date.now() - heartbeat <= 60 * 1000;
|
const online = conn &&
|
||||||
|
heartbeat > 0 &&
|
||||||
|
Date.now() - heartbeat <= this.heartBeatInterval * 1000;
|
||||||
if (node?.online !== online) {
|
if (node?.online !== online) {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue