36 lines
640 B
Go
36 lines
640 B
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
func (a *App) watchAddressOverrides(ctx context.Context) {
|
|
if a.zones == nil || a.blocks == nil {
|
|
return
|
|
}
|
|
t := time.NewTicker(2 * time.Second)
|
|
defer t.Stop()
|
|
var last string
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-t.C:
|
|
content, ok, err := a.zones.Data(ctx, "address-overrides.rpz")
|
|
if err != nil || !ok || content == last {
|
|
continue
|
|
}
|
|
a.overrideMu.Lock()
|
|
a.blocks.SetManagedRPZ(content)
|
|
if _, err := a.blocks.RefreshAll(ctx); err == nil {
|
|
if a.cache != nil {
|
|
a.cache.Flush()
|
|
}
|
|
last = content
|
|
}
|
|
a.overrideMu.Unlock()
|
|
}
|
|
}
|
|
}
|