forked from folbricht/routedns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocklistdb-multi.go
44 lines (36 loc) · 885 Bytes
/
blocklistdb-multi.go
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
38
39
40
41
42
43
44
package rdns
import (
"net"
"github.com/miekg/dns"
)
// MultiDB wraps multiple blocklist DBs and performs queries over all of them.
type MultiDB struct {
dbs []BlocklistDB
}
var _ BlocklistDB = MultiDB{}
// NewMultiDB returns a new instance of a wrapper for blocklists
func NewMultiDB(dbs ...BlocklistDB) (MultiDB, error) {
return MultiDB{dbs}, nil
}
func (m MultiDB) Reload() (BlocklistDB, error) {
var newDBs []BlocklistDB
for _, db := range m.dbs {
n, err := db.Reload()
if err != nil {
return nil, err
}
newDBs = append(newDBs, n)
}
return NewMultiDB(newDBs...)
}
func (m MultiDB) Match(q dns.Question) ([]net.IP, []string, *BlocklistMatch, bool) {
for _, db := range m.dbs {
if ip, name, match, ok := db.Match(q); ok {
return ip, name, match, ok
}
}
return nil, nil, nil, false
}
func (m MultiDB) String() string {
return "Multi-Blocklist"
}