From b3b5f17e039004f92ca970f8387227c0a635bdbe Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Tue, 13 Dec 2022 11:23:34 +0800 Subject: [PATCH] chore: cleanup doh/doq's code --- dns/doh.go | 20 ++++++-------------- dns/doq.go | 22 ++++++---------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/dns/doh.go b/dns/doh.go index ac5d7486..d2bfeb82 100644 --- a/dns/doh.go +++ b/dns/doh.go @@ -15,7 +15,6 @@ import ( "sync" "time" - "github.com/Dreamacro/clash/component/dialer" tlsC "github.com/Dreamacro/clash/component/tls" C "github.com/Dreamacro/clash/constant" "github.com/Dreamacro/clash/log" @@ -530,21 +529,14 @@ func (doh *dnsOverHTTPS) dialQuic(ctx context.Context, addr string, tlsCfg *tls. Port: portInt, } var conn net.PacketConn - if doh.proxyAdapter == "" { - conn, err = dialer.ListenPacket(ctx, "udp", "") - if err != nil { - return nil, err + if wrapConn, err := dialContextExtra(ctx, doh.proxyAdapter, "udp", addr, doh.r); err == nil { + if pc, ok := wrapConn.(*wrapPacketConn); ok { + conn = pc + } else { + return nil, fmt.Errorf("conn isn't wrapPacketConn") } } else { - if wrapConn, err := dialContextExtra(ctx, doh.proxyAdapter, "udp", addr, doh.r); err == nil { - if pc, ok := wrapConn.(*wrapPacketConn); ok { - conn = pc - } else { - return nil, fmt.Errorf("conn isn't wrapPacketConn") - } - } else { - return nil, err - } + return nil, err } return quic.DialEarlyContext(ctx, conn, &udpAddr, doh.url.Host, tlsCfg, cfg) } diff --git a/dns/doq.go b/dns/doq.go index 16a32a3a..3f2b7d07 100644 --- a/dns/doq.go +++ b/dns/doq.go @@ -12,7 +12,6 @@ import ( "sync" "time" - "github.com/Dreamacro/clash/component/dialer" tlsC "github.com/Dreamacro/clash/component/tls" "github.com/metacubex/quic-go" @@ -336,23 +335,14 @@ func (doq *dnsOverQUIC) openConnection(ctx context.Context) (conn quic.Connectio p, err := strconv.Atoi(port) udpAddr := net.UDPAddr{IP: net.ParseIP(ip), Port: p} var udp net.PacketConn - if doq.proxyAdapter == "" { - udp, err = dialer.ListenPacket(ctx, "udp", "") - if err != nil { - return nil, err - } - } else { - conn, err := dialContextExtra(ctx, doq.proxyAdapter, "udp", addr, doq.r) - if err != nil { - return nil, err - } - - wrapConn, ok := conn.(*wrapPacketConn) - if !ok { + if wrapConn, err := dialContextExtra(ctx, doq.proxyAdapter, "udp", addr, doq.r); err == nil { + if pc, ok := wrapConn.(*wrapPacketConn); ok { + udp = pc + } else { return nil, fmt.Errorf("quic create packet failed") } - - udp = wrapConn + } else { + return nil, err } host, _, err := net.SplitHostPort(doq.addr)