DialerProxy: Fix SplitHTTP H3 dialerProxy (#3570)

* wip

* wip

* formatting

* cnc connection no longer needs to be a Packetconn

* dialerProxy: do not cancel connection when Dial context is cancelled
This commit is contained in:
mmmray 2024-08-11 18:58:52 +02:00 committed by GitHub
parent 0c7303960a
commit 498d8eb3cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 7 deletions

View file

@ -111,7 +111,7 @@ func canLookupIP(ctx context.Context, dst net.Destination, sockopt *SocketConfig
}
func redirect(ctx context.Context, dst net.Destination, obt string) net.Conn {
errors.LogInfo(ctx, "redirecting request " + dst.String() + " to " + obt)
errors.LogInfo(ctx, "redirecting request "+dst.String()+" to "+obt)
h := obm.GetHandler(obt)
outbounds := session.OutboundsFromContext(ctx)
ctx = session.ContextWithOutbounds(ctx, append(outbounds, &session.Outbound{
@ -123,10 +123,16 @@ func redirect(ctx context.Context, dst net.Destination, obt string) net.Conn {
ur, uw := pipe.New(pipe.OptionsFromContext(ctx)...)
dr, dw := pipe.New(pipe.OptionsFromContext(ctx)...)
go h.Dispatch(ctx, &transport.Link{Reader: ur, Writer: dw})
go h.Dispatch(context.WithoutCancel(ctx), &transport.Link{Reader: ur, Writer: dw})
var readerOpt cnc.ConnectionOption
if dst.Network == net.Network_TCP {
readerOpt = cnc.ConnectionOutputMulti(dr)
} else {
readerOpt = cnc.ConnectionOutputMultiUDP(dr)
}
nc := cnc.NewConnection(
cnc.ConnectionInputMulti(uw),
cnc.ConnectionOutputMulti(dr),
readerOpt,
cnc.ConnectionOnClose(common.ChainedClosable{uw, dw}),
)
return nc
@ -150,7 +156,7 @@ func DialSystem(ctx context.Context, dest net.Destination, sockopt *SocketConfig
ips, err := lookupIP(dest.Address.String(), sockopt.DomainStrategy, src)
if err == nil && len(ips) > 0 {
dest.Address = net.IPAddress(ips[dice.Roll(len(ips))])
errors.LogInfo(ctx, "replace destination with " + dest.String())
errors.LogInfo(ctx, "replace destination with "+dest.String())
} else if err != nil {
errors.LogWarningInner(ctx, err, "failed to resolve ip")
}