Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.

Change selectPeers function to only handle detailed PeerInfo objects; not live Peer objects Closes#1059 #1067

Merged
merged 4 commits into from
Feb 5, 2019

Conversation

ishantiw
Copy link
Contributor

Description

Currently, the selectPeers function accepts and returns a list of Peer objects (ReadonlyArray<Peer>). We should make the selectPeers function in peer_selection.ts work with detailed peer info objects instead of live Peer objects.

Review checklist

@ishantiw ishantiw self-assigned this Jan 31, 2019
@ishantiw ishantiw added this to Open PRs in Version 2.1.0 via automation Jan 31, 2019
@@ -365,6 +365,10 @@ export class Peer extends EventEmitter {
inboundSocket.off(REMOTE_EVENT_MESSAGE, this._handleRawMessage);
}

public static constructPeerIdFromPeerInfo(peerInfo: P2PPeerInfo): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just export as a function?

Copy link

@jondubois jondubois Feb 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we export as a function then we should do the same for the Peer.constructPeerId(address, port) which is now a static method.

Or we can do this in a separate PR because I also rely on the same static method right now for my next PR.

@ishantiw ishantiw force-pushed the 1059-change_selectpeers_to_handle_peerinfo branch from eded4d5 to ff555a0 Compare February 1, 2019 09:33
);
}
const response: P2PResponsePacket = await selectedPeer[0].request(packet);
const response = await this._peerPool.requestPeer(packet, this._nodeInfo);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't pass this._nodeInfo as second argument. We should only support a single way of updating the nodeInfo; using applyNodeInfo.

Because the PeerPool now holds a reference to the latest _nodeInfo state internally, you can just use this. _nodeInfo from inside the PeerPool instead.

selectedPeers.forEach((peer: Peer) => {
peer.send(message);
});
this._peerPool.sendToPeers(message, this._nodeInfo);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar as previous comment.

@@ -365,6 +365,10 @@ export class Peer extends EventEmitter {
inboundSocket.off(REMOTE_EVENT_MESSAGE, this._handleRawMessage);
}

public static constructPeerIdFromPeerInfo(peerInfo: P2PPeerInfo): string {
Copy link

@jondubois jondubois Feb 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we export as a function then we should do the same for the Peer.constructPeerId(address, port) which is now a static method.

Or we can do this in a separate PR because I also rely on the same static method right now for my next PR.

nodeInfo: P2PNodeInfo,
): Promise<P2PResponsePacket> {
const peerSelectionParams: PeerOptions = {
lastBlockHeight: nodeInfo.height,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in previous comment, you can just use this._nodeInfo instead of getting the nodeInfo as a second argument to this function.

return response;
}

public sendToPeers(message: P2PMessagePacket, nodeInfo: P2PNodeInfo): void {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment about nodeInfo.

@ishantiw
Copy link
Contributor Author

ishantiw commented Feb 1, 2019

comments are addressed

shuse2
shuse2 previously approved these changes Feb 2, 2019
@shuse2 shuse2 merged commit ca4c189 into development Feb 5, 2019
Version 2.1.0 automation moved this from Open PRs to Closed PRs Feb 5, 2019
@shuse2 shuse2 deleted the 1059-change_selectpeers_to_handle_peerinfo branch February 5, 2019 15:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Version 2.1.0
  
Closed PRs
Development

Successfully merging this pull request may close these issues.

None yet

3 participants