chore: cleanup doh/doq's code
This commit is contained in:
parent
88acf8e098
commit
b3b5f17e03
2 changed files with 12 additions and 30 deletions
20
dns/doh.go
20
dns/doh.go
|
@ -15,7 +15,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/component/dialer"
|
|
||||||
tlsC "github.com/Dreamacro/clash/component/tls"
|
tlsC "github.com/Dreamacro/clash/component/tls"
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"github.com/Dreamacro/clash/log"
|
"github.com/Dreamacro/clash/log"
|
||||||
|
@ -530,21 +529,14 @@ func (doh *dnsOverHTTPS) dialQuic(ctx context.Context, addr string, tlsCfg *tls.
|
||||||
Port: portInt,
|
Port: portInt,
|
||||||
}
|
}
|
||||||
var conn net.PacketConn
|
var conn net.PacketConn
|
||||||
if doh.proxyAdapter == "" {
|
if wrapConn, err := dialContextExtra(ctx, doh.proxyAdapter, "udp", addr, doh.r); err == nil {
|
||||||
conn, err = dialer.ListenPacket(ctx, "udp", "")
|
if pc, ok := wrapConn.(*wrapPacketConn); ok {
|
||||||
if err != nil {
|
conn = pc
|
||||||
return nil, err
|
} else {
|
||||||
|
return nil, fmt.Errorf("conn isn't wrapPacketConn")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if wrapConn, err := dialContextExtra(ctx, doh.proxyAdapter, "udp", addr, doh.r); err == nil {
|
return nil, err
|
||||||
if pc, ok := wrapConn.(*wrapPacketConn); ok {
|
|
||||||
conn = pc
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("conn isn't wrapPacketConn")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return quic.DialEarlyContext(ctx, conn, &udpAddr, doh.url.Host, tlsCfg, cfg)
|
return quic.DialEarlyContext(ctx, conn, &udpAddr, doh.url.Host, tlsCfg, cfg)
|
||||||
}
|
}
|
||||||
|
|
22
dns/doq.go
22
dns/doq.go
|
@ -12,7 +12,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/component/dialer"
|
|
||||||
tlsC "github.com/Dreamacro/clash/component/tls"
|
tlsC "github.com/Dreamacro/clash/component/tls"
|
||||||
"github.com/metacubex/quic-go"
|
"github.com/metacubex/quic-go"
|
||||||
|
|
||||||
|
@ -336,23 +335,14 @@ func (doq *dnsOverQUIC) openConnection(ctx context.Context) (conn quic.Connectio
|
||||||
p, err := strconv.Atoi(port)
|
p, err := strconv.Atoi(port)
|
||||||
udpAddr := net.UDPAddr{IP: net.ParseIP(ip), Port: p}
|
udpAddr := net.UDPAddr{IP: net.ParseIP(ip), Port: p}
|
||||||
var udp net.PacketConn
|
var udp net.PacketConn
|
||||||
if doq.proxyAdapter == "" {
|
if wrapConn, err := dialContextExtra(ctx, doq.proxyAdapter, "udp", addr, doq.r); err == nil {
|
||||||
udp, err = dialer.ListenPacket(ctx, "udp", "")
|
if pc, ok := wrapConn.(*wrapPacketConn); ok {
|
||||||
if err != nil {
|
udp = pc
|
||||||
return nil, err
|
} else {
|
||||||
}
|
|
||||||
} else {
|
|
||||||
conn, err := dialContextExtra(ctx, doq.proxyAdapter, "udp", addr, doq.r)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
wrapConn, ok := conn.(*wrapPacketConn)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("quic create packet failed")
|
return nil, fmt.Errorf("quic create packet failed")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
udp = wrapConn
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
host, _, err := net.SplitHostPort(doq.addr)
|
host, _, err := net.SplitHostPort(doq.addr)
|
||||||
|
|
Loading…
Reference in a new issue