MCPcopy Create free account
hub / github.com/DNAProject/DNA / getNextNode

Method getNextNode

p2pserver/block_sync.go:856–888  ·  view source on GitHub ↗
(nextBlockHeight uint32)

Source from the content-addressed store, hash-verified

854}
855
856func (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
890func (this *BlockSyncMgr) getNodeWithMinFailedTimes(flightInfo *SyncFlightInfo, curBlockHeight uint32) *peer.Peer {
891 var minFailedTimes = math.MaxInt64

Callers 4

syncHeaderMethod · 0.95
syncBlockMethod · 0.95
saveBlockMethod · 0.95

Calls 5

getAllNodeWeightsMethod · 0.95
getNextNodeIdFunction · 0.85
getNodeMethod · 0.80
GetHeightMethod · 0.65
GetStateMethod · 0.45

Tested by

no test coverage detected