diff --git a/src/index.ts b/src/index.ts index 08436b7..6c290e9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,6 +29,7 @@ export default class DHTCache extends EventEmitter { private bootstrapped: boolean; private graph: any; private connectedTo: Set; + private heartBeatInterval: number; protected flood: DHTFlood; @@ -36,6 +37,7 @@ export default class DHTCache extends EventEmitter { swarm: any, { id = swarm.keyPair.publicKey, + heartBeatInterval = 15, ...opts }: { id?: Buffer; [key: string]: any } = {} ) { @@ -46,6 +48,7 @@ export default class DHTCache extends EventEmitter { this.bootstrapped = false; this.graph = new DiGraph(); this.connectedTo = new Set(); + this.heartBeatInterval = heartBeatInterval; this._cache = new Set(); this._online = new Set([this._maybeHexify(this.id)]); this.swarm = swarm; @@ -70,7 +73,7 @@ export default class DHTCache extends EventEmitter { this._ensurePeer(this.id); setInterval(() => this._heartbeatCheck(), 5 * 1000); - setInterval(() => this._emitHeartbeat(), 60 * 1000); + setInterval(() => this._emitHeartbeat(), this.heartBeatInterval * 1000); } private _cache: Set; @@ -482,7 +485,9 @@ export default class DHTCache extends EventEmitter { const conn = this.swarm._allConnections.get(pubkey); const online = - conn && heartbeat > 0 && Date.now() - heartbeat <= 60 * 1000; + conn && + heartbeat > 0 && + Date.now() - heartbeat <= this.heartBeatInterval * 1000; if (node?.online !== online) { changed = true;