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

@ -5,9 +5,11 @@ import (
"crypto/tls"
"fmt"
"net"
"net/netip"
"time"
"github.com/Dreamacro/clash/common/cache"
"github.com/Dreamacro/clash/common/nnip"
"github.com/Dreamacro/clash/component/dialer"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/log"
@ -96,15 +98,15 @@ func handleMsgWithEmptyAnswer(r *D.Msg) *D.Msg {
return msg
}
func msgToIP(msg *D.Msg) []net.IP {
ips := []net.IP{}
func msgToIP(msg *D.Msg) []netip.Addr {
ips := []netip.Addr{}
for _, answer := range msg.Answer {
switch ans := answer.(type) {
case *D.AAAA:
ips = append(ips, ans.AAAA)
ips = append(ips, nnip.IpToAddr(ans.AAAA))
case *D.A:
ips = append(ips, ans.A)
ips = append(ips, nnip.IpToAddr(ans.A))
}
}
@ -129,7 +131,7 @@ func (wpc *wrapPacketConn) RemoteAddr() net.Addr {
return wpc.rAddr
}
func dialContextWithProxyAdapter(ctx context.Context, adapterName string, network string, dstIP net.IP, port string, opts ...dialer.Option) (net.Conn, error) {
func dialContextWithProxyAdapter(ctx context.Context, adapterName string, network string, dstIP netip.Addr, port string, opts ...dialer.Option) (net.Conn, error) {
adapter, ok := tunnel.Proxies()[adapterName]
if !ok {
return nil, fmt.Errorf("proxy adapter [%s] not found", adapterName)
@ -144,7 +146,7 @@ func dialContextWithProxyAdapter(ctx context.Context, adapterName string, networ
}
addrType := C.AtypIPv4
if dstIP.To4() == nil {
if dstIP.Is6() {
addrType = C.AtypIPv6
}