*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:
Derrick Hammer 2022-12-05 14:08:15 -05:00
parent 52a0e41ca2
commit 29478e9a5a
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 7 deletions

View File

@ -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 });
}
}