forked from d3mondev/puredns
/
clientdns.go
46 lines (36 loc) · 1.32 KB
/
clientdns.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
45
46
package wildcarder
import "github.com/d3mondev/resolvermt"
// DNSAnswer represents a DNS answer without the question.
type DNSAnswer struct {
Type resolvermt.RRtype
Answer string
}
// ClientDNS is a DNS client that implements the Resolver interface.
type ClientDNS struct {
client resolver
}
type resolver interface {
Resolve(domains []string, rrtype resolvermt.RRtype) []resolvermt.Record
QueryCount() int
}
// NewClientDNS creates a new ResolverDNS object to use with a Wildcarder object.
func NewClientDNS(resolvers []string, retryCount int, qps int, concurrency int) *ClientDNS {
return &ClientDNS{
client: resolvermt.New(resolvers, retryCount, qps, concurrency),
}
}
// Resolve resolves A records from a list of domain names and returns the answers.
func (r *ClientDNS) Resolve(domains []string) []DNSAnswer {
records := r.client.Resolve(domains, resolvermt.TypeA)
// Removed AAAA records as those are not being handled by massdns right now
// records = append(records, r.client.Resolve(domains, resolvermt.TypeAAAA)...)
answers := []DNSAnswer{}
for _, record := range records {
answers = append(answers, DNSAnswer{Type: record.Type, Answer: record.Answer})
}
return answers
}
// QueryCount returns the number of DNS queries really performed.
func (r *ClientDNS) QueryCount() int {
return r.client.QueryCount()
}