cleanup: serversInfo: simplify handling onld/new servers
This commit is contained in:
parent
63520e494d
commit
683b111bf9
|
@ -109,21 +109,20 @@ func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp s
|
||||||
}
|
}
|
||||||
newServer.rtt = ewma.NewMovingAverage(RTTEwmaDecay)
|
newServer.rtt = ewma.NewMovingAverage(RTTEwmaDecay)
|
||||||
newServer.rtt.Set(float64(newServer.initialRtt))
|
newServer.rtt.Set(float64(newServer.initialRtt))
|
||||||
|
isNew := true
|
||||||
serversInfo.Lock()
|
serversInfo.Lock()
|
||||||
defer serversInfo.Unlock()
|
|
||||||
previousIndex = -1
|
|
||||||
for i, oldServer := range serversInfo.inner {
|
for i, oldServer := range serversInfo.inner {
|
||||||
if oldServer.Name == name {
|
if oldServer.Name == name {
|
||||||
previousIndex = i
|
serversInfo.inner[i] = &newServer
|
||||||
|
isNew = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if previousIndex >= 0 {
|
if isNew {
|
||||||
serversInfo.inner[previousIndex] = &newServer
|
serversInfo.inner = append(serversInfo.inner, &newServer)
|
||||||
return nil
|
serversInfo.registeredServers = append(serversInfo.registeredServers, RegisteredServer{name: name, stamp: stamp})
|
||||||
}
|
}
|
||||||
serversInfo.inner = append(serversInfo.inner, &newServer)
|
serversInfo.Unlock()
|
||||||
serversInfo.registeredServers = append(serversInfo.registeredServers, RegisteredServer{name: name, stamp: stamp})
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue