From 9b019574a0875fc5f3d82303bced4a76739fee86 Mon Sep 17 00:00:00 2001 From: Markus Linnala Date: Wed, 9 Oct 2019 18:25:15 +0300 Subject: [PATCH] cleanup: serversInfo : Simplify liveServers handling --- dnscrypt-proxy/proxy.go | 6 ++++-- dnscrypt-proxy/serversInfo.go | 8 -------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/dnscrypt-proxy/proxy.go b/dnscrypt-proxy/proxy.go index 559bfa06..b1e3318a 100644 --- a/dnscrypt-proxy/proxy.go +++ b/dnscrypt-proxy/proxy.go @@ -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) } }() } diff --git a/dnscrypt-proxy/serversInfo.go b/dnscrypt-proxy/serversInfo.go index be4cff5a..6f71f9a5 100644 --- a/dnscrypt-proxy/serversInfo.go +++ b/dnscrypt-proxy/serversInfo.go @@ -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 {