mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
all: add flush cache domains config
This commit is contained in:
committed by
Cuong Manh Le
parent
34ebe9b054
commit
b50cccac85
@@ -1831,6 +1831,11 @@ func fieldErrorMsg(fe validator.FieldError) string {
|
||||
return fmt.Sprintf("must define at least %s element", fe.Param())
|
||||
}
|
||||
return fmt.Sprintf("minimum value: %q", fe.Param())
|
||||
case "max":
|
||||
if fe.Kind() == reflect.Map || fe.Kind() == reflect.Slice {
|
||||
return fmt.Sprintf("exceeded maximum number of elements: %s", fe.Param())
|
||||
}
|
||||
return fmt.Sprintf("maximum value: %q", fe.Param())
|
||||
case "len":
|
||||
if fe.Kind() == reflect.Slice {
|
||||
return fmt.Sprintf("must have at least %s element", fe.Param())
|
||||
|
||||
@@ -101,6 +101,10 @@ func (p *prog) serveDNS(listenerNum string) error {
|
||||
go p.detectLoop(m)
|
||||
q := m.Question[0]
|
||||
domain := canonicalName(q.Name)
|
||||
if _, ok := p.cacheFlushDomainsMap[domain]; ok && p.cache != nil {
|
||||
p.cache.Purge()
|
||||
ctrld.Log(ctx, mainLog.Load().Debug(), "received query %q, local cache is purged", domain)
|
||||
}
|
||||
remoteIP, _, _ := net.SplitHostPort(w.RemoteAddr().String())
|
||||
ci := p.getClientInfo(remoteIP, m)
|
||||
ci.ClientIDPref = p.cfg.Service.ClientIDPref
|
||||
|
||||
@@ -70,17 +70,18 @@ type prog struct {
|
||||
logConn net.Conn
|
||||
cs *controlServer
|
||||
|
||||
cfg *ctrld.Config
|
||||
localUpstreams []string
|
||||
ptrNameservers []string
|
||||
appCallback *AppCallback
|
||||
cache dnscache.Cacher
|
||||
sema semaphore
|
||||
ciTable *clientinfo.Table
|
||||
um *upstreamMonitor
|
||||
router router.Router
|
||||
ptrLoopGuard *loopGuard
|
||||
lanLoopGuard *loopGuard
|
||||
cfg *ctrld.Config
|
||||
localUpstreams []string
|
||||
ptrNameservers []string
|
||||
appCallback *AppCallback
|
||||
cache dnscache.Cacher
|
||||
cacheFlushDomainsMap map[string]struct{}
|
||||
sema semaphore
|
||||
ciTable *clientinfo.Table
|
||||
um *upstreamMonitor
|
||||
router router.Router
|
||||
ptrLoopGuard *loopGuard
|
||||
lanLoopGuard *loopGuard
|
||||
|
||||
loopMu sync.Mutex
|
||||
loop map[string]bool
|
||||
@@ -253,12 +254,17 @@ func (p *prog) run(reload bool, reloadCh chan struct{}) {
|
||||
p.loop = make(map[string]bool)
|
||||
p.lanLoopGuard = newLoopGuard()
|
||||
p.ptrLoopGuard = newLoopGuard()
|
||||
p.cacheFlushDomainsMap = nil
|
||||
if p.cfg.Service.CacheEnable {
|
||||
cacher, err := dnscache.NewLRUCache(p.cfg.Service.CacheSize)
|
||||
if err != nil {
|
||||
mainLog.Load().Error().Err(err).Msg("failed to create cacher, caching is disabled")
|
||||
} else {
|
||||
p.cache = cacher
|
||||
p.cacheFlushDomainsMap = make(map[string]struct{}, 256)
|
||||
for _, domain := range p.cfg.Service.CacheFlushDomains {
|
||||
p.cacheFlushDomainsMap[canonicalName(domain)] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user