mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-01-18 02:54:30 +01:00
Don't pause the cert refresh timers if the host goes to hibernation
This commit is contained in:
parent
d8f502f130
commit
817f2ff560
@ -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)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
14
vendor/github.com/jedisct1/go-clocksmith/.gitignore
generated
vendored
Normal file
14
vendor/github.com/jedisct1/go-clocksmith/.gitignore
generated
vendored
Normal file
@ -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/
|
21
vendor/github.com/jedisct1/go-clocksmith/LICENSE
generated
vendored
Normal file
21
vendor/github.com/jedisct1/go-clocksmith/LICENSE
generated
vendored
Normal file
@ -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.
|
4
vendor/github.com/jedisct1/go-clocksmith/README.md
generated
vendored
Normal file
4
vendor/github.com/jedisct1/go-clocksmith/README.md
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# clocksmith
|
||||
|
||||
A sleep-aware sleep() function, that doesn't pause (for too long) if
|
||||
the system goes to hibernation.
|
31
vendor/github.com/jedisct1/go-clocksmith/clocksmith.go
generated
vendored
Normal file
31
vendor/github.com/jedisct1/go-clocksmith/clocksmith.go
generated
vendored
Normal file
@ -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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user