mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2024-12-29 00:30:30 +01:00
cleanup: serversInfo : Simplify liveServers handling
This commit is contained in:
parent
a941cbd893
commit
9b019574a0
@ -157,6 +157,7 @@ func (proxy *Proxy) StartProxy() {
|
||||
dlog.Fatal(err)
|
||||
}
|
||||
liveServers, err := proxy.serversInfo.refresh(proxy)
|
||||
proxy.certIgnoreTimestamp = !(liveServers > 0)
|
||||
if proxy.showCerts {
|
||||
os.Exit(0)
|
||||
}
|
||||
@ -174,11 +175,12 @@ func (proxy *Proxy) StartProxy() {
|
||||
go func() {
|
||||
for {
|
||||
delay := proxy.certRefreshDelay
|
||||
if proxy.serversInfo.liveServers() == 0 {
|
||||
if liveServers == 0 {
|
||||
delay = proxy.certRefreshDelayAfterFailure
|
||||
}
|
||||
clocksmith.Sleep(delay)
|
||||
proxy.serversInfo.refresh(proxy)
|
||||
liveServers, _ = proxy.serversInfo.refresh(proxy)
|
||||
proxy.certIgnoreTimestamp = !(liveServers > 0)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -158,19 +158,11 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
|
||||
}
|
||||
if innerLen > 0 {
|
||||
dlog.Noticef("Server with the lowest initial latency: %s (rtt: %dms)", inner[0].Name, inner[0].initialRtt)
|
||||
proxy.certIgnoreTimestamp = false
|
||||
}
|
||||
serversInfo.Unlock()
|
||||
return liveServers, err
|
||||
}
|
||||
|
||||
func (serversInfo *ServersInfo) liveServers() int {
|
||||
serversInfo.RLock()
|
||||
liveServers := len(serversInfo.inner)
|
||||
serversInfo.RUnlock()
|
||||
return liveServers
|
||||
}
|
||||
|
||||
func (serversInfo *ServersInfo) estimatorUpdate(candidate int) {
|
||||
candidateRtt, currentBestRtt := serversInfo.inner[candidate].rtt.Value(), serversInfo.inner[0].rtt.Value()
|
||||
if currentBestRtt < 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user