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.mainProto = "tcp"
} }
proxy.certRefreshDelay = time.Duration(config.CertRefreshDelay) * time.Minute proxy.certRefreshDelay = time.Duration(config.CertRefreshDelay) * time.Minute
proxy.certRefreshDelayAfterFailure = time.Duration(10 * time.Second)
if len(config.ListenAddresses) == 0 { if len(config.ListenAddresses) == 0 {
return errors.New("No local IP/port configured") return errors.New("No local IP/port configured")
} }

View File

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

View File

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