1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-07-26 11:44:22 -04:00

fixing misbehaving code in mux that do not propagate context

This commit is contained in:
Shelikhoo 2021-03-06 14:31:46 +00:00
parent 8cf51a847e
commit b585f2283a
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
2 changed files with 18 additions and 7 deletions

View File

@ -108,14 +108,15 @@ func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (outbou
h.mux = &mux.ClientManager{ h.mux = &mux.ClientManager{
Enabled: h.senderSettings.MultiplexSettings.Enabled, Enabled: h.senderSettings.MultiplexSettings.Enabled,
Picker: &mux.IncrementalWorkerPicker{ Picker: &mux.IncrementalWorkerPicker{
Factory: &mux.DialingWorkerFactory{ Factory: mux.NewDialingWorkerFactory(
Proxy: proxyHandler, ctx,
Dialer: h, proxyHandler,
Strategy: mux.ClientStrategy{ h,
mux.ClientStrategy{
MaxConcurrency: config.Concurrency, MaxConcurrency: config.Concurrency,
MaxConnection: 128, MaxConnection: 128,
}, },
}, ),
}, },
} }
} }
@ -199,7 +200,7 @@ func (h *Handler) Dial(ctx context.Context, dest net.Destination) (internet.Conn
if h.senderSettings != nil && h.senderSettings.ProxySettings != nil && h.senderSettings.ProxySettings.HasTag() && h.senderSettings.ProxySettings.TransportLayerProxy { if h.senderSettings != nil && h.senderSettings.ProxySettings != nil && h.senderSettings.ProxySettings.HasTag() && h.senderSettings.ProxySettings.TransportLayerProxy {
tag := h.senderSettings.ProxySettings.Tag tag := h.senderSettings.ProxySettings.Tag
newError("transport layer proxying to ", tag, " for dest ", dest).AtDebug().WriteToLog(session.ExportIDToError(ctx)) newError("transport layer proxying to ", tag, " for dest ", dest).AtDebug().WriteToLog(session.ExportIDToError(ctx))
session.SetTransportLayerProxyTagToContext(ctx, tag) ctx = session.SetTransportLayerProxyTagToContext(ctx, tag)
} }
conn, err := internet.Dial(ctx, dest, h.streamSettings) conn, err := internet.Dial(ctx, dest, h.streamSettings)

View File

@ -131,8 +131,18 @@ type DialingWorkerFactory struct {
Proxy proxy.Outbound Proxy proxy.Outbound
Dialer internet.Dialer Dialer internet.Dialer
Strategy ClientStrategy Strategy ClientStrategy
ctx context.Context
} }
func NewDialingWorkerFactory(ctx context.Context, Proxy proxy.Outbound, Dialer internet.Dialer, Strategy ClientStrategy) *DialingWorkerFactory {
return &DialingWorkerFactory{
Proxy: Proxy,
Dialer: Dialer,
Strategy: Strategy,
ctx: ctx,
}
}
func (f *DialingWorkerFactory) Create() (*ClientWorker, error) { func (f *DialingWorkerFactory) Create() (*ClientWorker, error) {
opts := []pipe.Option{pipe.WithSizeLimit(64 * 1024)} opts := []pipe.Option{pipe.WithSizeLimit(64 * 1024)}
uplinkReader, upLinkWriter := pipe.New(opts...) uplinkReader, upLinkWriter := pipe.New(opts...)
@ -148,7 +158,7 @@ func (f *DialingWorkerFactory) Create() (*ClientWorker, error) {
} }
go func(p proxy.Outbound, d internet.Dialer, c common.Closable) { go func(p proxy.Outbound, d internet.Dialer, c common.Closable) {
ctx := session.ContextWithOutbound(context.Background(), &session.Outbound{ ctx := session.ContextWithOutbound(f.ctx, &session.Outbound{
Target: net.TCPDestination(muxCoolAddress, muxCoolPort), Target: net.TCPDestination(muxCoolAddress, muxCoolPort),
}) })
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)