*Refactor so every call to addPeerHandler, we only add if it's not there, vs aborting completely if in connectedTo. This will ensure we stay alive via heartbeats even in edge cases

This commit is contained in:
Derrick Hammer 2022-12-17 09:05:48 -05:00
parent dd21b0fa30
commit 225537fc39
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 15 additions and 14 deletions

View File

@ -178,25 +178,26 @@ export default class DHTCache extends EventEmitter {
protected addPeerHandler(peer: any) { protected addPeerHandler(peer: any) {
const id = peer.remotePublicKey; const id = peer.remotePublicKey;
const stringId = id.toString("hex"); const stringId = id.toString("hex");
if (this.connectedTo.has(stringId)) { if (!this.connectedTo.has(stringId)) {
return; this.connectedTo.add(stringId);
} // Already know we're connected here }
this.connectedTo.add(stringId); if (!this._hasSeenEntity(id)) {
this._ensurePeer(id); this._ensurePeer(id);
this._addEntityConnection(this.id, id); this._addEntityConnection(this.id, id);
this.emit("peer-add", id); this.emit("peer-add", id);
this._recalculate(); this._recalculate();
this._broadcastMessage({ this._broadcastMessage({
type: Type.CONNECTED, type: Type.CONNECTED,
id, id,
}); });
this._emitHeartbeat(peer); this._emitHeartbeat(peer);
this.log.debug(`Relay peer connected: ${stringId}`); this.log.debug(`Relay peer connected: ${stringId}`);
}
if (this.bootstrapped) { if (this.bootstrapped) {
return; return;