Retry more frequently if we don't have any useable certificates

This will ahve to be done at startup time as well.
This commit is contained in:
Frank Denis 2018-01-17 17:22:29 +01:00
parent 1a502d0c2f
commit 1140e067ad
3 changed files with 44 additions and 26 deletions

View File

@ -88,6 +88,7 @@ func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error {
proxy.mainProto = "tcp"
}
proxy.certRefreshDelay = time.Duration(config.CertRefreshDelay) * time.Minute
proxy.certRefreshDelayAfterFailure = time.Duration(10 * time.Second)
if len(config.ListenAddresses) == 0 {
return errors.New("No local IP/port configured")
}

View File

@ -16,29 +16,30 @@ import (
)
type Proxy struct {
proxyPublicKey [32]byte
proxySecretKey [32]byte
questionSizeEstimator QuestionSizeEstimator
serversInfo ServersInfo
timeout time.Duration
certRefreshDelay time.Duration
mainProto string
listenAddresses []string
daemonize bool
registeredServers []RegisteredServer
pluginBlockIPv6 bool
cache bool
cacheSize int
cacheNegTTL uint32
cacheMinTTL uint32
cacheMaxTTL uint32
queryLogFile string
queryLogFormat string
blockNameFile string
blockNameLogFile string
blockNameFormat string
forwardFile string
pluginsGlobals PluginsGlobals
proxyPublicKey [32]byte
proxySecretKey [32]byte
questionSizeEstimator QuestionSizeEstimator
serversInfo ServersInfo
timeout time.Duration
certRefreshDelay time.Duration
certRefreshDelayAfterFailure time.Duration
mainProto string
listenAddresses []string
daemonize bool
registeredServers []RegisteredServer
pluginBlockIPv6 bool
cache bool
cacheSize int
cacheNegTTL uint32
cacheMinTTL uint32
cacheMaxTTL uint32
queryLogFile string
queryLogFormat string
blockNameFile string
blockNameLogFile string
blockNameFormat string
forwardFile string
pluginsGlobals PluginsGlobals
}
type App struct {
@ -140,7 +141,11 @@ func (proxy *Proxy) StartProxy() {
dlog.Notice("dnscrypt-proxy is ready")
go func() {
for {
time.Sleep(proxy.certRefreshDelay)
delay := proxy.certRefreshDelay
if proxy.serversInfo.liveServers() == 0 {
delay = proxy.certRefreshDelayAfterFailure
}
time.Sleep(delay)
proxy.serversInfo.refresh(proxy)
}
}()

View File

@ -80,14 +80,26 @@ func (serversInfo *ServersInfo) registerServer(proxy *Proxy, name string, stamp
return nil
}
func (serversInfo *ServersInfo) refresh(proxy *Proxy) {
func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
dlog.Infof("Refreshing certificates")
serversInfo.RLock()
registeredServers := serversInfo.registeredServers
serversInfo.RUnlock()
liveServers := 0
var err error
for _, registeredServer := range registeredServers {
serversInfo.registerServer(proxy, registeredServer.name, registeredServer.stamp)
if err = serversInfo.registerServer(proxy, registeredServer.name, registeredServer.stamp); err == nil {
liveServers++
}
}
return liveServers, err
}
func (serversInfo *ServersInfo) liveServers() int {
serversInfo.RLock()
liveServers := len(serversInfo.registeredServers)
serversInfo.RUnlock()
return liveServers
}
func (serversInfo *ServersInfo) getOne() *ServerInfo {