Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check status and version to find peers #30

Merged
merged 6 commits into from Jan 29, 2019
Merged

Conversation

luciorubeens
Copy link
Contributor

@luciorubeens luciorubeens commented Jan 28, 2019

This PR includes a way to deal wtih ArkEcosystem/core#2026

@codecov-io
Copy link

codecov-io commented Jan 28, 2019

Codecov Report

Merging #30 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #30      +/-   ##
==========================================
+ Coverage   99.54%   99.55%   +<.01%     
==========================================
  Files          23       23              
  Lines         221      224       +3     
  Branches       19       20       +1     
==========================================
+ Hits          220      223       +3     
  Misses          1        1
Impacted Files Coverage Δ
lib/index.js 98.68% <100%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3dc0386...e4ff81a. Read the comment docs.

@luciorubeens luciorubeens changed the title [WIP] fix: check status and version to find peers fix: check status and version to find peers Jan 28, 2019
@alexbarnsley alexbarnsley requested review from j-a-m-l and removed request for alexbarnsley January 28, 2019 20:21
Copy link
Contributor

@j-a-m-l j-a-m-l left a comment

Choose a reason for hiding this comment

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

I've done some simple tests and I didn't have any problem.

@@ -19,6 +20,10 @@ const mergePeerArrays = (oldArray, newArray) => {
return peers
}

const getPeerVersion = (peer) => {
return !peer.version || /^1\./.test(peer.version) ? 1 : 2
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd use something like:

return (peer.version && peer.version.startsWith('1.')) ? 1 : 2

@@ -69,7 +71,7 @@ module.exports = class ApiClient {
if (responsePeers.length) {
// Ignore local and unavailable peers
Copy link
Contributor

Choose a reason for hiding this comment

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

// Ignore local and unavailable peers, and those with wrong version

@@ -69,7 +71,7 @@ module.exports = class ApiClient {
if (responsePeers.length) {
// Ignore local and unavailable peers
responsePeers = responsePeers.filter(peer => {
return selfIps.indexOf(peer.ip) === -1 && peer.status === versionStatus[version]
return selfIps.indexOf(peer.ip) === -1 && versionStatus.includes(peer.status) && getPeerVersion(peer) === version
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd use includes on both checks:

return !selfIps.includes(peer.ip) && versionStatus.includes(peer.status) && getPeerVersion(peer) === version

Copy link
Contributor

@j-a-m-l j-a-m-l left a comment

Choose a reason for hiding this comment

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

@alexbarnsley Approved in case you want to release it today without my suggestions

@alexbarnsley
Copy link
Member

Can do the refactoring at a later time, thanks 👌

@alexbarnsley alexbarnsley merged commit 0f008f8 into master Jan 29, 2019
@alexbarnsley alexbarnsley deleted the fix/peer-status branch January 29, 2019 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants