Refactor: metadata use netip.Addr

This commit is contained in:
yaling888
2022-04-20 01:52:51 +08:00
parent 29c775331a
commit cd62daccb0
45 changed files with 369 additions and 360 deletions

View File

@@ -1,7 +1,6 @@
package dns
import (
"net"
"net/netip"
"strings"
"time"
@@ -88,21 +87,21 @@ func withMapping(mapping *cache.LruCache[netip.Addr, string]) middleware {
host := strings.TrimRight(q.Name, ".")
for _, ans := range msg.Answer {
var ip net.IP
var ip netip.Addr
var ttl uint32
switch a := ans.(type) {
case *D.A:
ip = a.A
ip = nnip.IpToAddr(a.A)
ttl = a.Hdr.Ttl
case *D.AAAA:
ip = a.AAAA
ip = nnip.IpToAddr(a.AAAA)
ttl = a.Hdr.Ttl
default:
continue
}
mapping.SetWithExpire(nnip.IpToAddr(ip), host, time.Now().Add(time.Second*time.Duration(ttl)))
mapping.SetWithExpire(ip, host, time.Now().Add(time.Second*time.Duration(ttl)))
}
return msg, nil