fix: ping result ttl random

This commit is contained in:
tiancheng91 2023-01-16 16:05:08 +08:00
parent 80ec307308
commit a9e7fee369

View File

@ -240,7 +240,6 @@ func (f *FastestFilter) Filter(nodes []Node) []Node {
// get latency with ttl cache // get latency with ttl cache
now := time.Now().Unix() now := time.Now().Unix()
r := rand.New(rand.NewSource(time.Now().UnixNano()))
var getNodeLatency = func(node Node) int { var getNodeLatency = func(node Node) int {
if f.pingResultTTL[node.ID] < now { if f.pingResultTTL[node.ID] < now {
@ -251,7 +250,8 @@ func (f *FastestFilter) Filter(nodes []Node) []Node {
// get latency // get latency
go func(node Node) { go func(node Node) {
latency := f.doTcpPing(node.Addr) 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.mu.Lock()
f.pingResult[node.ID] = latency f.pingResult[node.ID] = latency