*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);
|
||||
}
|
||||
|
||||
for (const id of online) {
|
||||
const item = this.graph.node.get(id);
|
||||
if (!item?.online) {
|
||||
online.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
this._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 conn = this.swarm._allConnections.get(pubkey);
|
||||
if (!conn) {
|
||||
this.onRemovePeer({ remotePublicKey: pubkey });
|
||||
continue;
|
||||
}
|
||||
const online =
|
||||
conn && heartbeat > 0 && Date.now() - heartbeat > 60 * 1000;
|
||||
|
||||
if (heartbeat > 0 && Date.now() - heartbeat > 60 * 1000) {
|
||||
conn.end();
|
||||
}
|
||||
this._setEntity(peer, { online });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue