*Instead of disconnecting dead peers, just use an "online" property on the node graph, and filter out dead peers in _recalculate
This commit is contained in:
parent
52a0e41ca2
commit
29478e9a5a
17
src/index.ts
17
src/index.ts
|
@ -422,6 +422,13 @@ export default class DHTCache extends EventEmitter {
|
||||||
this.graph.removeNode(id);
|
this.graph.removeNode(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const id of online) {
|
||||||
|
const item = this.graph.node.get(id);
|
||||||
|
if (!item?.online) {
|
||||||
|
online.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this._online = online;
|
this._online = online;
|
||||||
|
|
||||||
this.emit("online", online);
|
this.emit("online", online);
|
||||||
|
@ -467,14 +474,10 @@ export default class DHTCache extends EventEmitter {
|
||||||
const heartbeat = this.graph.node.get(peer)?.heartbeat;
|
const heartbeat = this.graph.node.get(peer)?.heartbeat;
|
||||||
|
|
||||||
const conn = this.swarm._allConnections.get(pubkey);
|
const conn = this.swarm._allConnections.get(pubkey);
|
||||||
if (!conn) {
|
const online =
|
||||||
this.onRemovePeer({ remotePublicKey: pubkey });
|
conn && heartbeat > 0 && Date.now() - heartbeat > 60 * 1000;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (heartbeat > 0 && Date.now() - heartbeat > 60 * 1000) {
|
this._setEntity(peer, { online });
|
||||||
conn.end();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue