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

Method Weight

p2pserver/block_sync.go:112–127  ·  view source on GitHub ↗

Weight calculate node's weight for sort. Highest weight node will be accessed first for next request.

()

Source from the content-addressed store, hash-verified

110
111//Weight calculate node's weight for sort. Highest weight node will be accessed first for next request.
112func (this *NodeWeight) Weight() float32 {
113 avgSpeed := float32(0.0)
114 for _, s := range this.speed {
115 avgSpeed += s
116 }
117 avgSpeed = avgSpeed / float32(len(this.speed))
118
119 avgInterval := float32(0.0)
120 now := time.Now().UnixNano() / int64(time.Millisecond)
121 for _, t := range this.reqTime {
122 avgInterval += float32(now - t)
123 }
124 avgInterval = avgInterval / float32(len(this.reqTime))
125 w := avgSpeed + avgInterval
126 return w
127}
128
129//NodeWeights implement sorting
130type NodeWeights []*NodeWeight

Callers 1

LessMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected