Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions app/mydispatcher/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ type DefaultDispatcher struct {
fdns dns.FakeDNSEngine
Limiter *limiter.Limiter
RuleManager *rule.Manager
SpliceCopyEnable bool
}

// 新增一个存储config 的简单配置结构体
type ControllerConfig struct {
SpliceCopyEnable bool
}

func init() {
Expand Down Expand Up @@ -146,6 +152,14 @@ func (d *DefaultDispatcher) Init(config *Config, om outbound.Manager, router rou
return nil
}

// ApplyControllerConfig 由 controller 在运行时调用,把需要的字段传给 dispatcher
func (d *DefaultDispatcher) ApplyControllerConfig(cc *ControllerConfig) {
if d == nil || cc == nil {
return
}
d.SpliceCopyEnable = cc.SpliceCopyEnable
}

// Type implements common.HasType for registering as a separate feature, not overriding core dispatcher.
func (*DefaultDispatcher) Type() interface{} {
return Type()
Expand Down Expand Up @@ -179,10 +193,11 @@ func (d *DefaultDispatcher) getLink(ctx context.Context) (*transport.Link, *tran
sessionInbound := session.InboundFromContext(ctx)
var user *protocol.MemoryUser
if sessionInbound != nil {
// Disable splice to avoid Vision/REALITY bypassing stats path
sessionInbound.CanSpliceCopy = 3
user = sessionInbound.User
sessionInbound.CanSpliceCopy = 3
if !d.SpliceCopyEnable {
// Disable splice to avoid Vision/REALITY bypassing stats path
sessionInbound.CanSpliceCopy = 3
}
}

if user != nil && len(user.Email) > 0 {
Expand Down
1 change: 1 addition & 0 deletions release/config/config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Nodes:
ProxyProtocolVer: 0 # Send PROXY protocol version, 0 for disable
DisableLocalREALITYConfig: false # disable local reality config
EnableREALITY: false # Enable REALITY
SpliceCopyEnable: false # enable时开启Splice 特性,但会流量统计滞后
REALITYConfigs:
Show: true # Show REALITY debug
Dest: www.amazon.com:443 # Required, Same as fallback
Expand Down
1 change: 1 addition & 0 deletions service/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {
DisableLocalREALITYConfig bool `mapstructure:"DisableLocalREALITYConfig"`
EnableREALITY bool `mapstructure:"EnableREALITY"`
REALITYConfigs *REALITYConfig `mapstructure:"REALITYConfigs"`
SpliceCopyEnable bool `mapstructure:"SpliceCopyEnable"`
}

type AutoSpeedLimitConfig struct {
Expand Down
17 changes: 13 additions & 4 deletions service/controller/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ type statsOutboundWrapper struct {
outbound.Handler
pm policy.Manager
sm stats.Manager
spliceCopyEnable bool // 是否允许在 Dispatch 中设置 sess.CanSpliceCopy
}

func (w *statsOutboundWrapper) Dispatch(ctx context.Context, link *transport.Link) {
// Disable kernel splice to avoid Vision/REALITY bypassing userland stats path
if sess := session.InboundFromContext(ctx); sess != nil {
sess.CanSpliceCopy = 3
if !w.spliceCopyEnable {
// Disable kernel splice to avoid Vision/REALITY bypassing userland stats path
if sess := session.InboundFromContext(ctx); sess != nil {
sess.CanSpliceCopy = 3
}
}
w.Handler.Dispatch(ctx, link)
}
Expand Down Expand Up @@ -68,7 +71,13 @@ func (c *Controller) addOutbound(config *core.OutboundHandlerConfig) error {
return fmt.Errorf("not an InboundHandler: %s", err)
}
// Wrap outbound handler to ensure downlink stats are always counted (e.g., REALITY/VLESS cases)
handler = &statsOutboundWrapper{Handler: handler, pm: c.pm, sm: c.stm}
// 将 controller 配置传入 wrapper,用于在 Dispatch 时决定是否设置 sess.CanSpliceCopy
handler = &statsOutboundWrapper{
Handler: handler,
pm: c.pm,
sm: c.stm,
spliceCopyEnable: c.config != nil && c.config.SpliceCopyEnable,
}
if err := c.obm.AddHandler(context.Background(), handler); err != nil {
return err
}
Expand Down
7 changes: 7 additions & 0 deletions service/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ func New(server *core.Instance, api api.API, config *Config, panelType string) *
logger: logger,
}

// 立即把 controller 配置的 SpliceCopyEnable 推给 dispatcher(运行时传值)
if controller.dispatcher != nil {
controller.dispatcher.ApplyControllerConfig(&mydispatcher.ControllerConfig{
SpliceCopyEnable: config.SpliceCopyEnable,
})
}

return controller
}

Expand Down
Loading