-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.go
55 lines (46 loc) · 988 Bytes
/
core.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
47
48
49
50
51
52
53
54
55
package core
import (
"strings"
"github.com/zalgonoise/x/dns/dns"
)
const (
fallbackOneDot = "1.1.1.1:53"
fallbackGoogle = "8.8.8.8:53"
portSep = ":"
portDNS = ":53"
)
var (
defaultFallback = []string{
fallbackOneDot,
fallbackGoogle,
}
)
// DNSCore adds a basic Answer / Fallback interaction for miekg's DNS
// implementation (used on the transport layer)
//
// It holds a list of strings which will be the fallback domain-name servers
// to contact if a domain's IP is requested but there no records for it
type DNSCore struct {
fallbackDNS []string
}
// New returns a new DNSCore as a dns.Repository
func New(fallbackDNS ...string) dns.Repository {
var fbDNS []string
for _, fb := range fallbackDNS {
fb := fb
if fb == "" {
continue
}
if !strings.Contains(fb, portSep) {
fb += portDNS
}
fbDNS = append(fbDNS, fb)
}
if len(fbDNS) == 0 {
// add defaults
fbDNS = defaultFallback
}
return &DNSCore{
fallbackDNS: fbDNS,
}
}