Skip to content

Commit

Permalink
fix: 修正随机ttl生成
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancheng91 committed Jan 16, 2023
1 parent 80ec307 commit 10112b1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,18 @@ func (f *FastestFilter) Filter(nodes []Node) []Node {

// get latency with ttl cache
now := time.Now().Unix()
r := rand.New(rand.NewSource(time.Now().UnixNano()))

var getNodeLatency = func(node Node) int {
if f.pingResultTTL[node.ID] < now {
f.mu.Lock()
f.pingResultTTL[node.ID] = now + 5 // tmp
defer f.mu.Unlock()
f.mu.Unlock()

// get latency
go func(node Node) {
latency := f.doTcpPing(node.Addr)
ttl := 300 - int64(60*r.Float64())
rand.Seed(time.Now().UnixNano() + int64(latency))
ttl := 300 - int64(60*rand.Float64())

f.mu.Lock()
f.pingResult[node.ID] = latency
Expand Down

0 comments on commit 10112b1

Please sign in to comment.