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

Commit

Permalink
Merge pull request #354 from alexbarnsley/bug/network-connectivity
Browse files Browse the repository at this point in the history
Sort peers & fix bug with filtered peer status
  • Loading branch information
luciorubeens committed Oct 30, 2017
2 parents 45a01f3 + f168b79 commit 84559d0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 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,17 @@
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) {
if (versionResponse.success) {
let peers = response.peers.filter(function(peer) {
return peer.status == "OK" && peer.version === versionResponse.version;
});
storageService.set("peers", peers);
findGoodPeer(peers, 0);
} else {
findGoodPeer(storageService.get("peers"), 0);
}
});
} else {
findGoodPeer(storageService.get("peers"), 0);
}
Expand All @@ -286,6 +293,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

0 comments on commit 84559d0

Please sign in to comment.