@@ -57,16 +57,23 @@ func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *
5757 if err != nil {
5858 return nil , err
5959 }
60-
61- // Set tag and sniffing config in context before creating proxy
62- // This allows proxies like TUN to access these settings
63- ctx = session .ContextWithInbound (ctx , & session.Inbound {Tag : tag })
64- if receiverConfig .SniffingSettings != nil {
65- ctx = session .ContextWithContent (ctx , & session.Content {
66- SniffingRequest : sniffingRequest ,
67- })
60+ src := net .TCPDestination (net .AnyIP , 0 )
61+ if receiverConfig .Listen != nil {
62+ src .Address = receiverConfig .Listen .AsAddress ()
63+ }
64+ if receiverConfig .PortList != nil && len (receiverConfig .PortList .Range ) > 0 {
65+ src .Port = net .Port (receiverConfig .PortList .Range [0 ].From )
6866 }
69- rawProxy , err := common .CreateObject (ctx , proxyConfig )
67+ mss , err := internet .ToMemoryStreamConfig (receiverConfig .StreamSettings )
68+ if err != nil {
69+ return nil , errors .New ("failed to parse stream config" ).Base (err ).AtWarning ()
70+ }
71+
72+ newCtx := session .ContextWithInbound (ctx , & session.Inbound {Tag : tag , Source : src })
73+ newCtx = session .ContextWithContent (newCtx , & session.Content {SniffingRequest : sniffingRequest })
74+ newCtx = session .ContextWithStreamSettings (newCtx , mss )
75+
76+ rawProxy , err := common .CreateObject (newCtx , proxyConfig )
7077 if err != nil {
7178 return nil , err
7279 }
@@ -92,11 +99,6 @@ func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *
9299 address = net .AnyIP
93100 }
94101
95- mss , err := internet .ToMemoryStreamConfig (receiverConfig .StreamSettings )
96- if err != nil {
97- return nil , errors .New ("failed to parse stream config" ).Base (err ).AtWarning ()
98- }
99-
100102 if receiverConfig .ReceiveOriginalDestination {
101103 if mss .SocketSettings == nil {
102104 mss .SocketSettings = & internet.SocketConfig {}
0 commit comments