mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-27 01:07:10 +00:00
chore: cleanup netip code
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/metacubex/mihomo/common/lru"
|
||||
"github.com/metacubex/mihomo/common/nnip"
|
||||
"github.com/metacubex/mihomo/component/fakeip"
|
||||
R "github.com/metacubex/mihomo/component/resolver"
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
@@ -120,14 +119,21 @@ func withMapping(mapping *lru.LruCache[netip.Addr, string]) middleware {
|
||||
|
||||
switch a := ans.(type) {
|
||||
case *D.A:
|
||||
ip = nnip.IpToAddr(a.A)
|
||||
ip, _ = netip.AddrFromSlice(a.A)
|
||||
ttl = a.Hdr.Ttl
|
||||
case *D.AAAA:
|
||||
ip = nnip.IpToAddr(a.AAAA)
|
||||
ip, _ = netip.AddrFromSlice(a.AAAA)
|
||||
ttl = a.Hdr.Ttl
|
||||
default:
|
||||
continue
|
||||
}
|
||||
if !ip.IsValid() {
|
||||
continue
|
||||
}
|
||||
if !ip.IsGlobalUnicast() {
|
||||
continue
|
||||
}
|
||||
ip = ip.Unmap()
|
||||
|
||||
if ttl < 1 {
|
||||
ttl = 1
|
||||
|
||||
20
dns/util.go
20
dns/util.go
@@ -10,7 +10,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/metacubex/mihomo/common/nnip"
|
||||
"github.com/metacubex/mihomo/common/picker"
|
||||
"github.com/metacubex/mihomo/component/dialer"
|
||||
"github.com/metacubex/mihomo/component/resolver"
|
||||
@@ -150,19 +149,24 @@ func handleMsgWithEmptyAnswer(r *D.Msg) *D.Msg {
|
||||
return msg
|
||||
}
|
||||
|
||||
func msgToIP(msg *D.Msg) []netip.Addr {
|
||||
ips := []netip.Addr{}
|
||||
|
||||
func msgToIP(msg *D.Msg) (ips []netip.Addr) {
|
||||
for _, answer := range msg.Answer {
|
||||
var ip netip.Addr
|
||||
switch ans := answer.(type) {
|
||||
case *D.AAAA:
|
||||
ips = append(ips, nnip.IpToAddr(ans.AAAA))
|
||||
ip, _ = netip.AddrFromSlice(ans.AAAA)
|
||||
case *D.A:
|
||||
ips = append(ips, nnip.IpToAddr(ans.A))
|
||||
ip, _ = netip.AddrFromSlice(ans.A)
|
||||
default:
|
||||
continue
|
||||
}
|
||||
if !ip.IsValid() {
|
||||
continue
|
||||
}
|
||||
ip = ip.Unmap()
|
||||
ips = append(ips, ip)
|
||||
}
|
||||
|
||||
return ips
|
||||
return
|
||||
}
|
||||
|
||||
func msgToDomain(msg *D.Msg) string {
|
||||
|
||||
Reference in New Issue
Block a user