9 "github.com/mjl-/mox/dns"
10 "github.com/mjl-/mox/dnsbl"
11 "github.com/mjl-/mox/mlog"
14var dnsblHealth = struct {
16 zones map[dns.Domain]dnsblStatus
18 zones: map[dns.Domain]dnsblStatus{},
21type dnsblStatus struct {
23 err error // nil, dnsbl.ErrDNS or other
26// checkDNSBLHealth checks healthiness of DNSBL "zone", keeping the result cached for 4 hours.
27func checkDNSBLHealth(ctx context.Context, log mlog.Log, resolver dns.Resolver, zone dns.Domain) (rok bool) {
29 defer dnsblHealth.Unlock()
30 status, ok := dnsblHealth.zones[zone]
31 if !ok || time.Since(status.last) > 4*time.Hour {
32 status.err = dnsbl.CheckHealth(ctx, log.Logger, resolver, zone)
33 status.last = time.Now()
34 dnsblHealth.zones[zone] = status
36 return status.err == nil || errors.Is(status.err, dnsbl.ErrDNS)