*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:
parent
dd21b0fa30
commit
225537fc39
29
src/index.ts
29
src/index.ts
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue