From 94f812b026df6197191e0ce6a8c3cdd7355fdff3 Mon Sep 17 00:00:00 2001 From: tiancheng91 Date: Mon, 16 Jan 2023 16:05:08 +0800 Subject: [PATCH] fix: ping result ttl random --- selector.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/selector.go b/selector.go index a5f68b91..67d83c15 100644 --- a/selector.go +++ b/selector.go @@ -240,7 +240,6 @@ 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 { @@ -251,7 +250,8 @@ func (f *FastestFilter) Filter(nodes []Node) []Node { // get latency go func(node Node) { latency := f.doTcpPing(node.Addr) - ttl := 300 - int64(60*r.Float64()) + r := rand.New(rand.NewSource(time.Now().UnixNano())) + ttl := 300 - int64(120*r.Float64()) f.mu.Lock() f.pingResult[node.ID] = latency