mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00:00
Add session context outbounds as slice (#3356)
* Add session context outbounds as slice slice is needed for dialer proxy where two outbounds work on top of each other There are two sets of target addr for example It also enable Xtls to correctly do splice copy by checking both outbounds are ready to do direct copy * Fill outbound tag info * Splice now checks capalibility from all outbounds * Fix unit tests
This commit is contained in:
parent
0735053348
commit
017f53b5fc
42 changed files with 303 additions and 236 deletions
|
@ -112,7 +112,12 @@ func canLookupIP(ctx context.Context, dst net.Destination, sockopt *SocketConfig
|
|||
func redirect(ctx context.Context, dst net.Destination, obt string) net.Conn {
|
||||
newError("redirecting request " + dst.String() + " to " + obt).WriteToLog(session.ExportIDToError(ctx))
|
||||
h := obm.GetHandler(obt)
|
||||
ctx = session.ContextWithOutbound(ctx, &session.Outbound{Target: dst, Gateway: nil})
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ctx = session.ContextWithOutbounds(ctx, append(outbounds, &session.Outbound{
|
||||
Target: dst,
|
||||
Gateway: nil,
|
||||
Tag: obt,
|
||||
})) // add another outbound in session ctx
|
||||
if h != nil {
|
||||
ur, uw := pipe.New(pipe.OptionsFromContext(ctx)...)
|
||||
dr, dw := pipe.New(pipe.OptionsFromContext(ctx)...)
|
||||
|
@ -131,8 +136,10 @@ func redirect(ctx context.Context, dst net.Destination, obt string) net.Conn {
|
|||
// DialSystem calls system dialer to create a network connection.
|
||||
func DialSystem(ctx context.Context, dest net.Destination, sockopt *SocketConfig) (net.Conn, error) {
|
||||
var src net.Address
|
||||
if outbound := session.OutboundFromContext(ctx); outbound != nil {
|
||||
src = outbound.Gateway
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
if len(outbounds) > 0 {
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
src = ob.Gateway
|
||||
}
|
||||
if sockopt == nil {
|
||||
return effectiveSystemDialer.Dial(ctx, src, dest, sockopt)
|
||||
|
|
|
@ -118,7 +118,7 @@ func getGrpcClient(ctx context.Context, dest net.Destination, streamSettings *in
|
|||
address := net.ParseAddress(rawHost)
|
||||
|
||||
gctx = session.ContextWithID(gctx, session.IDFromContext(ctx))
|
||||
gctx = session.ContextWithOutbound(gctx, session.OutboundFromContext(ctx))
|
||||
gctx = session.ContextWithOutbounds(gctx, session.OutboundsFromContext(ctx))
|
||||
gctx = session.ContextWithTimeoutOnly(gctx, true)
|
||||
|
||||
c, err := internet.DialSystem(gctx, net.TCPDestination(address, port), sockopt)
|
||||
|
|
|
@ -68,7 +68,7 @@ func getHTTPClient(ctx context.Context, dest net.Destination, streamSettings *in
|
|||
address := net.ParseAddress(rawHost)
|
||||
|
||||
hctx = session.ContextWithID(hctx, session.IDFromContext(ctx))
|
||||
hctx = session.ContextWithOutbound(hctx, session.OutboundFromContext(ctx))
|
||||
hctx = session.ContextWithOutbounds(hctx, session.OutboundsFromContext(ctx))
|
||||
hctx = session.ContextWithTimeoutOnly(hctx, true)
|
||||
|
||||
pconn, err := internet.DialSystem(hctx, net.TCPDestination(address, port), sockopt)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue