Skip to content

Commit

Permalink
feat: increase delay time for certificates refresh
Browse files Browse the repository at this point in the history
This increases the delay in refreshing certificates if the first start
was successful. This is necessary to save battery power when the network
connection is unavailable.
  • Loading branch information
Gedsh committed Feb 11, 2024
1 parent 58a16ed commit c5035a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dnscrypt-proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
}
proxy.certRefreshConcurrency = Max(1, config.CertRefreshConcurrency)
proxy.certRefreshDelay = time.Duration(Max(60, config.CertRefreshDelay)) * time.Minute
proxy.certRefreshDelayAfterFailure = time.Duration(10 * time.Second)
proxy.certRefreshDelayStartFailure = time.Duration(10 * time.Second)
proxy.certRefreshDelayAfterFailure = time.Duration(30 * time.Minute)
proxy.certIgnoreTimestamp = config.CertIgnoreTimestamp
proxy.ephemeralKeys = config.EphemeralKeys
if len(config.ListenAddresses) == 0 && len(config.LocalDoH.ListenAddresses) == 0 {
Expand Down
9 changes: 8 additions & 1 deletion dnscrypt-proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Proxy struct {
ServerNames []string
DisabledServerNames []string
requiredProps stamps.ServerInformalProperties
certRefreshDelayStartFailure time.Duration
certRefreshDelayAfterFailure time.Duration
timeout time.Duration
certRefreshDelay time.Duration
Expand Down Expand Up @@ -252,9 +253,12 @@ func (proxy *Proxy) StartProxy() {
if proxy.showCerts {
os.Exit(0)
}
startSuccesfull := false
if liveServers > 0 {
startSuccesfull = true
dlog.Noticef("dnscrypt-proxy is ready - live servers: %d", liveServers)
} else if err != nil {
startSuccesfull = false
dlog.Error(err)
dlog.Notice("dnscrypt-proxy is waiting for at least one server to be reachable")
}
Expand All @@ -269,12 +273,15 @@ func (proxy *Proxy) StartProxy() {
go func() {
for {
delay := proxy.certRefreshDelay
if liveServers == 0 {
if liveServers == 0 && startSuccesfull {
delay = proxy.certRefreshDelayAfterFailure
} else if liveServers == 0 {
delay = proxy.certRefreshDelayStartFailure
}
clocksmith.Sleep(delay)
liveServers, _ = proxy.serversInfo.refresh(proxy)
if liveServers > 0 {
startSuccesfull = true
proxy.certIgnoreTimestamp = false
}
runtime.GC()
Expand Down

0 comments on commit c5035a4

Please sign in to comment.