1
0
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:
Markus Linnala 2019-10-09 18:25:15 +03:00 committed by Frank Denis
parent a941cbd893
commit 9b019574a0
2 changed files with 4 additions and 10 deletions

View File

@ -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)
}
}()
}

View File

@ -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 {