Browse Source

propagate context

pull/2582/head
Shelikhoo 4 years ago
parent
commit
85bd352bc1
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
  1. 1
      app/proxyman/inbound/always.go
  2. 4
      app/proxyman/inbound/dynamic.go
  3. 4
      app/proxyman/inbound/worker.go
  4. 2
      functions.go

1
app/proxyman/inbound/always.go

@ -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)
}

4
app/proxyman/inbound/dynamic.go

@ -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()

4
app/proxyman/inbound/worker.go

@ -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)

2
functions.go

@ -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…
Cancel
Save