Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Sort peers & fix bug with filtered peer status #354

Merged
merged 5 commits into from
Oct 30, 2017
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions client/app/src/services/network.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,13 @@
if (!network.forcepeer) {
getFromPeer("/api/peers").then(function(response) {
if (response.success) {
storageService.set("peers", response.peers.filter(function(peer) {
return peer.status == "OK";
}));
findGoodPeer(response.peers, 0);
getFromPeer('/api/peers/version').then(function(versionResponse) {
let peers = response.peers.filter(function(peer) {

Choose a reason for hiding this comment

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

Does there need to be validation for response.success like the above api call here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not a bad shout. It shouldn't be necessary but will add it anyway and will let it fallback on the stored peers if it fails 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Pushed the change for you to take a look 👀

return peer.status == "OK" && peer.version === versionResponse.version;
});
storageService.set("peers", peers);
findGoodPeer(peers, 0);
});
} else {
findGoodPeer(storageService.get("peers"), 0);
}
Expand All @@ -286,6 +289,11 @@
//peer.ip=network.peerseed;
return;
}
if (index === 0) {
peers = peers.sort(function(a, b) {
return b.height - a.height || a.delay - b.delay;
});
}
peer.ip = "http://" + peers[index].ip + ":" + peers[index].port;
getFromPeer("/api/blocks/getheight").then(function(response) {
if (response.success && response.height < peer.height) {
Expand Down