mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
Fix: resolver dial context options
This commit is contained in:
parent
a412745314
commit
3686446919
|
@ -48,15 +48,16 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
|
||||||
network = "tcp"
|
network = "tcp"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options := []dialer.Option{}
|
||||||
|
if c.iface != "" {
|
||||||
|
options = append(options, dialer.WithInterface(c.iface))
|
||||||
|
}
|
||||||
|
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
if c.proxyAdapter == "" {
|
if c.proxyAdapter == "" {
|
||||||
options := []dialer.Option{}
|
|
||||||
if c.iface != "" {
|
|
||||||
options = append(options, dialer.WithInterface(c.iface))
|
|
||||||
}
|
|
||||||
conn, err = dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port), options...)
|
conn, err = dialer.DialContext(ctx, network, net.JoinHostPort(ip.String(), c.port), options...)
|
||||||
} else {
|
} else {
|
||||||
conn, err = dialContextWithProxyAdapter(ctx, c.proxyAdapter, network, ip, c.port)
|
conn, err = dialContextWithProxyAdapter(ctx, c.proxyAdapter, network, ip, c.port, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/common/cache"
|
"github.com/Dreamacro/clash/common/cache"
|
||||||
|
"github.com/Dreamacro/clash/component/dialer"
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"github.com/Dreamacro/clash/log"
|
"github.com/Dreamacro/clash/log"
|
||||||
"github.com/Dreamacro/clash/tunnel"
|
"github.com/Dreamacro/clash/tunnel"
|
||||||
|
@ -128,7 +129,7 @@ func (wpc *wrapPacketConn) RemoteAddr() net.Addr {
|
||||||
return wpc.rAddr
|
return wpc.rAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
func dialContextWithProxyAdapter(ctx context.Context, adapterName string, network string, dstIP net.IP, port string) (net.Conn, error) {
|
func dialContextWithProxyAdapter(ctx context.Context, adapterName string, network string, dstIP net.IP, port string, opts ...dialer.Option) (net.Conn, error) {
|
||||||
adapter, ok := tunnel.Proxies()[adapterName]
|
adapter, ok := tunnel.Proxies()[adapterName]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("proxy adapter [%s] not found", adapterName)
|
return nil, fmt.Errorf("proxy adapter [%s] not found", adapterName)
|
||||||
|
@ -156,7 +157,7 @@ func dialContextWithProxyAdapter(ctx context.Context, adapterName string, networ
|
||||||
}
|
}
|
||||||
|
|
||||||
if networkType == C.UDP {
|
if networkType == C.UDP {
|
||||||
packetConn, err := adapter.ListenPacketContext(ctx, metadata)
|
packetConn, err := adapter.ListenPacketContext(ctx, metadata, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -167,5 +168,5 @@ func dialContextWithProxyAdapter(ctx context.Context, adapterName string, networ
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return adapter.DialContext(ctx, metadata)
|
return adapter.DialContext(ctx, metadata, opts...)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user