diff --git a/dnscrypt-proxy/proxy.go b/dnscrypt-proxy/proxy.go index 87106a7b..2be3e4a6 100644 --- a/dnscrypt-proxy/proxy.go +++ b/dnscrypt-proxy/proxy.go @@ -10,6 +10,7 @@ import ( "time" "github.com/jedisct1/dlog" + clocksmith "github.com/jedisct1/go-clocksmith" "github.com/pquerna/cachecontrol/cacheobject" "golang.org/x/crypto/curve25519" ) @@ -100,7 +101,7 @@ func (proxy *Proxy) StartProxy() { if proxy.serversInfo.liveServers() == 0 { delay = proxy.certRefreshDelayAfterFailure } - time.Sleep(delay) + clocksmith.Sleep(delay) proxy.serversInfo.refresh(proxy) } }() @@ -121,7 +122,7 @@ func (proxy *Proxy) prefetcher(urlsToPrefetch *[]URLToPrefetch) { } } } - time.Sleep(60 * time.Second) + clocksmith.Sleep(60 * time.Second) } }() } diff --git a/vendor/github.com/jedisct1/go-clocksmith/.gitignore b/vendor/github.com/jedisct1/go-clocksmith/.gitignore new file mode 100644 index 00000000..a1338d68 --- /dev/null +++ b/vendor/github.com/jedisct1/go-clocksmith/.gitignore @@ -0,0 +1,14 @@ +# Binaries for programs and plugins +*.exe +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 +.glide/ diff --git a/vendor/github.com/jedisct1/go-clocksmith/LICENSE b/vendor/github.com/jedisct1/go-clocksmith/LICENSE new file mode 100644 index 00000000..74a9a9b2 --- /dev/null +++ b/vendor/github.com/jedisct1/go-clocksmith/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Frank Denis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/jedisct1/go-clocksmith/README.md b/vendor/github.com/jedisct1/go-clocksmith/README.md new file mode 100644 index 00000000..194829a3 --- /dev/null +++ b/vendor/github.com/jedisct1/go-clocksmith/README.md @@ -0,0 +1,4 @@ +# clocksmith + +A sleep-aware sleep() function, that doesn't pause (for too long) if +the system goes to hibernation. diff --git a/vendor/github.com/jedisct1/go-clocksmith/clocksmith.go b/vendor/github.com/jedisct1/go-clocksmith/clocksmith.go new file mode 100644 index 00000000..cf60122f --- /dev/null +++ b/vendor/github.com/jedisct1/go-clocksmith/clocksmith.go @@ -0,0 +1,31 @@ +package clocksmith + +import "time" + +const ( + // DefaultGranularity - Maximum duration of actual time.Sleep() calls + DefaultGranularity = 10 * time.Second +) + +// SleepWithGranularity - sleeps for the given amount of time, with the given granularity; +// doesn't pause if the system goes to hibernation +func SleepWithGranularity(duration time.Duration, granularity time.Duration) { + if duration <= granularity { + time.Sleep(duration) + return + } + now := time.Now() + for { + time.Sleep(granularity) + if elapsed := time.Since(now); elapsed > duration-granularity { + time.Sleep(duration - elapsed) + break + } + } +} + +// Sleep - sleeps for the given amount of time, with the default granularity; +// doesn't pause if the system goes to hibernation +func Sleep(duration time.Duration) { + SleepWithGranularity(duration, DefaultGranularity) +}