Skip to content

Commit

Permalink
propagate context
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokangwang committed Jun 18, 2020
1 parent 73616ab commit 85bd352
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/proxyman/inbound/always.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions app/proxyman/inbound/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion app/proxyman/inbound/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type tcpWorker struct {
downlinkCounter stats.Counter

hub internet.Listener

ctx context.Context
}

func getTProxyType(s *internet.MemoryStreamConfig) internet.SocketConfig_TProxyMode {
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 85bd352

Please sign in to comment.