@@ -12,6 +12,7 @@ import (
1212 "time"
1313 "unsafe"
1414
15+ "github.com/xtls/xray-core/app/dispatcher"
1516 "github.com/xtls/xray-core/app/reverse"
1617 "github.com/xtls/xray-core/common"
1718 "github.com/xtls/xray-core/common/buf"
@@ -31,6 +32,7 @@ import (
3132 "github.com/xtls/xray-core/features/outbound"
3233 "github.com/xtls/xray-core/features/policy"
3334 "github.com/xtls/xray-core/features/routing"
35+ "github.com/xtls/xray-core/features/stats"
3436 "github.com/xtls/xray-core/proxy"
3537 "github.com/xtls/xray-core/proxy/vless"
3638 "github.com/xtls/xray-core/proxy/vless/encoding"
@@ -72,10 +74,11 @@ func init() {
7274type Handler struct {
7375 inboundHandlerManager feature_inbound.Manager
7476 policyManager policy.Manager
77+ stats stats.Manager
7578 validator vless.Validator
7679 decryption * encryption.ServerInstance
7780 outboundHandlerManager outbound.Manager
78- wrapLink func ( ctx context. Context , link * transport. Link ) * transport. Link
81+ defaultDispatcher routing. Dispatcher
7982 ctx context.Context
8083 fallbacks map [string ]map [string ]map [string ]* Fallback // or nil
8184 // regexps map[string]*regexp.Regexp // or nil
@@ -84,16 +87,13 @@ type Handler struct {
8487// New creates a new VLess inbound handler.
8588func New (ctx context.Context , config * Config , dc dns.Client , validator vless.Validator ) (* Handler , error ) {
8689 v := core .MustFromContext (ctx )
87- var wrapLinkFunc func (ctx context.Context , link * transport.Link ) * transport.Link
88- if dispatcher , ok := v .GetFeature (routing .DispatcherType ()).(routing.WrapLinkDispatcher ); ok {
89- wrapLinkFunc = dispatcher .WrapLink
90- }
9190 handler := & Handler {
9291 inboundHandlerManager : v .GetFeature (feature_inbound .ManagerType ()).(feature_inbound.Manager ),
9392 policyManager : v .GetFeature (policy .ManagerType ()).(policy.Manager ),
93+ stats : v .GetFeature (stats .ManagerType ()).(stats.Manager ),
9494 validator : validator ,
9595 outboundHandlerManager : v .GetFeature (outbound .ManagerType ()).(outbound.Manager ),
96- wrapLink : wrapLinkFunc ,
96+ defaultDispatcher : v . GetFeature ( routing . DispatcherType ()).(routing. Dispatcher ) ,
9797 ctx : ctx ,
9898 }
9999
@@ -264,7 +264,7 @@ func (*Handler) Network() []net.Network {
264264}
265265
266266// Process implements proxy.Inbound.Process().
267- func (h * Handler ) Process (ctx context.Context , network net.Network , connection stat.Connection , dispatcher routing.Dispatcher ) error {
267+ func (h * Handler ) Process (ctx context.Context , network net.Network , connection stat.Connection , dispatch routing.Dispatcher ) error {
268268 iConn := stat .TryUnwrapStatsConn (connection )
269269
270270 if h .decryption != nil {
@@ -623,13 +623,10 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
623623 if err != nil {
624624 return err
625625 }
626- if h .wrapLink == nil {
627- return errors .New ("VLESS reverse must have a dispatcher that implemented routing.WrapLinkDispatcher" )
628- }
629- return r .NewMux (ctx , h .wrapLink (ctx , & transport.Link {Reader : clientReader , Writer : clientWriter }))
626+ return r .NewMux (ctx , dispatcher .WrapLink (ctx , h .policyManager , h .stats , & transport.Link {Reader : clientReader , Writer : clientWriter }))
630627 }
631628
632- if err := dispatcher .DispatchLink (ctx , request .Destination (), & transport.Link {
629+ if err := dispatch .DispatchLink (ctx , request .Destination (), & transport.Link {
633630 Reader : clientReader ,
634631 Writer : clientWriter },
635632 ); err != nil {
0 commit comments