summaryrefslogtreecommitdiff
path: root/internal/resolver/root.go
diff options
context:
space:
mode:
authorradhitya <alif@radhitya.org>2026-06-13 16:09:53 +0700
committerradhitya <alif@radhitya.org>2026-06-13 16:09:53 +0700
commit3e44adc94f32bfe500730fcbf1c02cedf65b0a30 (patch)
tree66932e0f386ba1277506e9d1fb18eaaad70bfef3 /internal/resolver/root.go
parentd802d4a685016be8b79c89b4f21099b9a1569532 (diff)
root hints, glue record, delegation loop, iterative, ns fallback, timeout, glue record
Diffstat (limited to 'internal/resolver/root.go')
-rw-r--r--internal/resolver/root.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/resolver/root.go b/internal/resolver/root.go
new file mode 100644
index 0000000..9dac31c
--- /dev/null
+++ b/internal/resolver/root.go
@@ -0,0 +1,55 @@
+package resolver
+
+import (
+ _ "embed"
+ "github.com/miekg/dns"
+ "strings"
+)
+
+//go:embed named.root
+var rootHintsData []byte
+
+func loadRootServers() []string {
+ var addrs []string
+ seen := make(map[string]bool)
+
+ zp := dns.NewZoneParser(strings.NewReader(string(rootHintsData)), "", "")
+ for {
+ rr, ok := zp.Next()
+ if !ok {
+ break
+ }
+ a, ok := rr.(*dns.A)
+ if !ok {
+ continue
+ }
+ ip := a.A.String()
+ if !seen[ip] {
+ seen[ip] = true
+ addrs = append(addrs, ip)
+ }
+ }
+
+ if err := zp.Err(); err != nil || len(addrs) == 0 {
+ return hardcodedRoots()
+ }
+ return addrs
+}
+
+func hardcodedRoots() []string {
+ return []string{
+ "198.41.0.4",
+ "170.247.170.2",
+ "192.33.4.12",
+ "199.7.91.13",
+ "192.203.230.10",
+ "192.5.5.241",
+ "192.112.36.4",
+ "198.97.190.53",
+ "192.36.148.17",
+ "192.58.128.30",
+ "193.0.14.129",
+ "199.7.83.42",
+ "202.12.27.33",
+ }
+}