mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
propagate context
This commit is contained in:
parent
73616ab9e2
commit
85bd352bc1
@ -103,6 +103,7 @@ func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *
|
||||
sniffingConfig: receiverConfig.GetEffectiveSniffingSettings(),
|
||||
uplinkCounter: uplinkCounter,
|
||||
downlinkCounter: downlinkCounter,
|
||||
ctx: ctx,
|
||||
}
|
||||
h.workers = append(h.workers, worker)
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ type DynamicInboundHandler struct {
|
||||
lastRefresh time.Time
|
||||
mux *mux.Server
|
||||
task *task.Periodic
|
||||
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func NewDynamicInboundHandler(ctx context.Context, tag string, receiverConfig *proxyman.ReceiverConfig, proxyConfig interface{}) (*DynamicInboundHandler, error) {
|
||||
@ -39,6 +41,7 @@ func NewDynamicInboundHandler(ctx context.Context, tag string, receiverConfig *p
|
||||
portsInUse: make(map[net.Port]bool),
|
||||
mux: mux.NewServer(ctx),
|
||||
v: v,
|
||||
ctx: ctx,
|
||||
}
|
||||
|
||||
mss, err := internet.ToMemoryStreamConfig(receiverConfig.StreamSettings)
|
||||
@ -134,6 +137,7 @@ func (h *DynamicInboundHandler) refresh() error {
|
||||
sniffingConfig: h.receiverConfig.GetEffectiveSniffingSettings(),
|
||||
uplinkCounter: uplinkCounter,
|
||||
downlinkCounter: downlinkCounter,
|
||||
ctx: h.ctx,
|
||||
}
|
||||
if err := worker.Start(); err != nil {
|
||||
newError("failed to create TCP worker").Base(err).AtWarning().WriteToLog()
|
||||
|
@ -43,6 +43,8 @@ type tcpWorker struct {
|
||||
downlinkCounter stats.Counter
|
||||
|
||||
hub internet.Listener
|
||||
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func getTProxyType(s *internet.MemoryStreamConfig) internet.SocketConfig_TProxyMode {
|
||||
@ -53,7 +55,7 @@ func getTProxyType(s *internet.MemoryStreamConfig) internet.SocketConfig_TProxyM
|
||||
}
|
||||
|
||||
func (w *tcpWorker) callback(conn internet.Connection) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(w.ctx)
|
||||
sid := session.NewID()
|
||||
ctx = session.ContextWithID(ctx, sid)
|
||||
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
|
||||
// CreateObject creates a new object based on the given V2Ray instance and config. The V2Ray instance may be nil.
|
||||
func CreateObject(v *Instance, config interface{}) (interface{}, error) {
|
||||
ctx := context.Background()
|
||||
ctx := v.ctx
|
||||
if v != nil {
|
||||
ctx = context.WithValue(ctx, v2rayKey, v)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user