(nextBlockHeight uint32)
| 854 | } |
| 855 | |
| 856 | func (this *BlockSyncMgr) getNextNode(nextBlockHeight uint32) *peer.Peer { |
| 857 | weights := this.getAllNodeWeights() |
| 858 | sort.Sort(sort.Reverse(weights)) |
| 859 | nodelist := make([]uint64, 0) |
| 860 | for _, n := range weights { |
| 861 | nodelist = append(nodelist, n.id) |
| 862 | } |
| 863 | nextNodeIndex := 0 |
| 864 | triedNode := make(map[uint64]bool, 0) |
| 865 | for { |
| 866 | var nextNodeId uint64 |
| 867 | nextNodeIndex, nextNodeId = getNextNodeId(nextNodeIndex, nodelist) |
| 868 | if nextNodeId == 0 { |
| 869 | return nil |
| 870 | } |
| 871 | _, ok := triedNode[nextNodeId] |
| 872 | if ok { |
| 873 | return nil |
| 874 | } |
| 875 | triedNode[nextNodeId] = true |
| 876 | n := this.server.getNode(nextNodeId) |
| 877 | if n == nil { |
| 878 | continue |
| 879 | } |
| 880 | if n.GetState() != p2pComm.ESTABLISH { |
| 881 | continue |
| 882 | } |
| 883 | nodeBlockHeight := n.GetHeight() |
| 884 | if nextBlockHeight <= uint32(nodeBlockHeight) { |
| 885 | return n |
| 886 | } |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | func (this *BlockSyncMgr) getNodeWithMinFailedTimes(flightInfo *SyncFlightInfo, curBlockHeight uint32) *peer.Peer { |
| 891 | var minFailedTimes = math.MaxInt64 |
no test coverage detected