chore: proxyDialer first using old function to let mux work
This commit is contained in:
parent
e5158977b1
commit
3defc3fc77
2 changed files with 20 additions and 40 deletions
|
@ -45,23 +45,13 @@ func (p proxyDialer) DialContext(ctx context.Context, network, address string) (
|
|||
return N.NewBindPacketConn(pc, currentMeta.UDPAddr()), nil
|
||||
}
|
||||
var conn C.Conn
|
||||
switch p.proxy.SupportWithDialer() {
|
||||
case C.ALLNet:
|
||||
fallthrough
|
||||
case C.TCP:
|
||||
if d, ok := p.dialer.(dialer.Dialer); ok { // first using old function to let mux work
|
||||
conn, err = p.proxy.DialContext(ctx, currentMeta, dialer.WithOption(d.Opt))
|
||||
} else {
|
||||
conn, err = p.proxy.DialContextWithDialer(ctx, p.dialer, currentMeta)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default: // fallback to old function
|
||||
if d, ok := p.dialer.(dialer.Dialer); ok { // fallback to old function
|
||||
conn, err = p.proxy.DialContext(ctx, currentMeta, dialer.WithOption(d.Opt))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, C.ErrNotSupport
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if p.statistic {
|
||||
conn = statistic.NewTCPTracker(conn, statistic.DefaultManager, currentMeta, nil, 0, 0, false)
|
||||
|
@ -81,23 +71,13 @@ func (p proxyDialer) listenPacket(ctx context.Context, currentMeta *C.Metadata)
|
|||
var pc C.PacketConn
|
||||
var err error
|
||||
currentMeta.NetWork = C.UDP
|
||||
switch p.proxy.SupportWithDialer() {
|
||||
case C.ALLNet:
|
||||
fallthrough
|
||||
case C.UDP:
|
||||
if d, ok := p.dialer.(dialer.Dialer); ok { // first using old function to let mux work
|
||||
pc, err = p.proxy.ListenPacketContext(ctx, currentMeta, dialer.WithOption(d.Opt))
|
||||
} else {
|
||||
pc, err = p.proxy.ListenPacketWithDialer(ctx, p.dialer, currentMeta)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default: // fallback to old function
|
||||
if d, ok := p.dialer.(dialer.Dialer); ok { // fallback to old function
|
||||
pc, err = p.proxy.ListenPacketContext(ctx, currentMeta, dialer.WithOption(d.Opt))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, C.ErrNotSupport
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if p.statistic {
|
||||
pc = statistic.NewUDPTracker(pc, statistic.DefaultManager, currentMeta, nil, 0, 0, false)
|
||||
|
|
16
dns/util.go
16
dns/util.go
|
@ -170,15 +170,15 @@ func getDialHandler(r *Resolver, proxyAdapter C.ProxyAdapter, proxyName string,
|
|||
Host: host,
|
||||
DstPort: port,
|
||||
}
|
||||
if proxyAdapter.IsL3Protocol(metadata) {
|
||||
dstIP, err := resolver.ResolveIPWithResolver(ctx, host, r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
metadata.Host = ""
|
||||
metadata.DstIP = dstIP
|
||||
}
|
||||
if proxyAdapter != nil {
|
||||
if proxyAdapter.IsL3Protocol(metadata) { // L3 proxy should resolve domain before to avoid loopback
|
||||
dstIP, err := resolver.ResolveIPWithResolver(ctx, host, r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
metadata.Host = ""
|
||||
metadata.DstIP = dstIP
|
||||
}
|
||||
return proxyAdapter.DialContext(ctx, metadata, opts...)
|
||||
}
|
||||
opts = append(opts, dialer.WithResolver(r))
|
||||
|
|
Loading…
Reference in a new issue