Skip to content

Commit

Permalink
added check for peer pairs on order invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
rsercano committed Sep 10, 2020
1 parent 7b7e7fc commit 8bd9f06
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions lib/p2p/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,8 @@ class Pool extends EventEmitter {
* peers to notify them of the change.
*/
public updatePairs = (pairIds: string[]) => {
const differentPairs = this.nodeState.pairs.concat(pairIds).filter((val, _index, arr) => {
return arr.indexOf(val) === arr.lastIndexOf(val);
});

this.nodeState.pairs = pairIds;
this.sendNodeStateUpdate((peer: Peer) => {
return differentPairs.some(pair => peer.isPairActive(pair));
});
this.sendNodeStateUpdate();
}

/**
Expand Down Expand Up @@ -267,12 +261,10 @@ class Pool extends EventEmitter {
this.sendNodeStateUpdate();
}

private sendNodeStateUpdate = (condition?: Function) => {
private sendNodeStateUpdate = () => {
const packet = new packets.NodeStateUpdatePacket(this.nodeState);
this.peers.forEach(async (peer) => {
if (!condition || condition(peer)) {
await peer.sendPacket(packet);
}
await peer.sendPacket(packet);
});
}

Expand Down

0 comments on commit 8bd9f06

Please sign in to comment.