pingOutsyncNodes send ping msg to lower height nodes for syncing
(curHeight uint32)
| 969 | |
| 970 | //pingOutsyncNodes send ping msg to lower height nodes for syncing |
| 971 | func (this *BlockSyncMgr) pingOutsyncNodes(curHeight uint32) { |
| 972 | peers := make([]*peer.Peer, 0) |
| 973 | this.lock.RLock() |
| 974 | maxHeight := curHeight |
| 975 | for id := range this.nodeWeights { |
| 976 | peer := this.server.getNode(id) |
| 977 | if peer == nil { |
| 978 | continue |
| 979 | } |
| 980 | peerHeight := uint32(peer.GetHeight()) |
| 981 | if peerHeight >= maxHeight { |
| 982 | maxHeight = peerHeight |
| 983 | } |
| 984 | if peerHeight < curHeight { |
| 985 | peers = append(peers, peer) |
| 986 | } |
| 987 | } |
| 988 | this.lock.RUnlock() |
| 989 | if curHeight > maxHeight-SYNC_MAX_HEIGHT_OFFSET && len(peers) > 0 { |
| 990 | this.server.pingTo(peers) |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | //Using polling for load balance |
| 995 | func getNextNodeId(nextNodeIndex int, nodeList []uint64) (int, uint64) { |