mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2024-12-29 00:30:30 +01:00
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.Set(float64(newServer.initialRtt))
|
||||
isNew := true
|
||||
serversInfo.Lock()
|
||||
defer serversInfo.Unlock()
|
||||
previousIndex = -1
|
||||
for i, oldServer := range serversInfo.inner {
|
||||
if oldServer.Name == name {
|
||||
previousIndex = i
|
||||
serversInfo.inner[i] = &newServer
|
||||
isNew = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if previousIndex >= 0 {
|
||||
serversInfo.inner[previousIndex] = &newServer
|
||||
return nil
|
||||
if isNew {
|
||||
serversInfo.inner = append(serversInfo.inner, &newServer)
|
||||
serversInfo.registeredServers = append(serversInfo.registeredServers, RegisteredServer{name: name, stamp: stamp})
|
||||
}
|
||||
serversInfo.inner = append(serversInfo.inner, &newServer)
|
||||
serversInfo.registeredServers = append(serversInfo.registeredServers, RegisteredServer{name: name, stamp: stamp})
|
||||
serversInfo.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user