*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) {
const id = peer.remotePublicKey;
const stringId = id.toString("hex");
if (this.connectedTo.has(stringId)) {
return;
} // Already know we're connected here
if (!this.connectedTo.has(stringId)) {
this.connectedTo.add(stringId);
}
this.connectedTo.add(stringId);
this._ensurePeer(id);
this._addEntityConnection(this.id, id);
this.emit("peer-add", id);
if (!this._hasSeenEntity(id)) {
this._ensurePeer(id);
this._addEntityConnection(this.id, id);
this.emit("peer-add", id);
this._recalculate();
this._recalculate();
this._broadcastMessage({
type: Type.CONNECTED,
id,
});
this._broadcastMessage({
type: Type.CONNECTED,
id,
});
this._emitHeartbeat(peer);
this._emitHeartbeat(peer);
this.log.debug(`Relay peer connected: ${stringId}`);
this.log.debug(`Relay peer connected: ${stringId}`);
}
if (this.bootstrapped) {
return;