-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathdnsbl.go
More file actions
37 lines (32 loc) · 899 Bytes
/
dnsbl.go
File metadata and controls
37 lines (32 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package smtpserver
import (
"context"
"errors"
"sync"
"time"
"github.com/mjl-/mox/dns"
"github.com/mjl-/mox/dnsbl"
"github.com/mjl-/mox/mlog"
)
var dnsblHealth = struct {
sync.Mutex
zones map[dns.Domain]dnsblStatus
}{
zones: map[dns.Domain]dnsblStatus{},
}
type dnsblStatus struct {
last time.Time
err error // nil, dnsbl.ErrDNS or other
}
// checkDNSBLHealth checks healthiness of DNSBL "zone", keeping the result cached for 4 hours.
func checkDNSBLHealth(ctx context.Context, log mlog.Log, resolver dns.Resolver, zone dns.Domain) (rok bool) {
dnsblHealth.Lock()
defer dnsblHealth.Unlock()
status, ok := dnsblHealth.zones[zone]
if !ok || time.Since(status.last) > 4*time.Hour {
status.err = dnsbl.CheckHealth(ctx, log.Logger, resolver, zone)
status.last = time.Now()
dnsblHealth.zones[zone] = status
}
return status.err == nil || errors.Is(status.err, dnsbl.ErrDNS)
}