From f00682e58ec52786b1efdf2029e50684adddf5a5 Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Fri, 12 Aug 2022 18:44:56 +0800 Subject: [PATCH] fix bug --- core/core.go | 12 ++++++++---- core/inbound.go | 14 ++++---------- core/outbound.go | 6 ++---- core/rule.go | 7 +++---- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/core/core.go b/core/core.go index ad3fac6..591fb11 100644 --- a/core/core.go +++ b/core/core.go @@ -6,11 +6,12 @@ import ( "github.com/Yuzuki616/V2bX/core/app/dispatcher" _ "github.com/Yuzuki616/V2bX/core/distro/all" "github.com/xtls/xray-core/app/proxyman" - "github.com/xtls/xray-core/app/proxyman/inbound" - "github.com/xtls/xray-core/app/proxyman/outbound" "github.com/xtls/xray-core/app/stats" "github.com/xtls/xray-core/common/serial" "github.com/xtls/xray-core/core" + "github.com/xtls/xray-core/features/inbound" + "github.com/xtls/xray-core/features/outbound" + "github.com/xtls/xray-core/features/routing" coreConf "github.com/xtls/xray-core/infra/conf" io "io/ioutil" "log" @@ -21,8 +22,8 @@ import ( type Core struct { access sync.Mutex Server *core.Instance - ihm *inbound.Manager - ohm *outbound.Manager + ihm inbound.Manager + ohm outbound.Manager dispatcher *dispatcher.DefaultDispatcher } @@ -154,6 +155,9 @@ func (p *Core) Start() { if err := p.Server.Start(); err != nil { log.Panicf("Failed to start instance: %s", err) } + p.ihm = p.Server.GetFeature(inbound.ManagerType()).(inbound.Manager) + p.ohm = p.Server.GetFeature(outbound.ManagerType()).(outbound.Manager) + p.dispatcher = p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) return } diff --git a/core/inbound.go b/core/inbound.go index cbd8add..f4306a2 100644 --- a/core/inbound.go +++ b/core/inbound.go @@ -5,10 +5,8 @@ import ( "fmt" "github.com/Yuzuki616/V2bX/api" "github.com/Yuzuki616/V2bX/app/limiter" - "github.com/Yuzuki616/V2bX/core/app/dispatcher" "github.com/xtls/xray-core/core" "github.com/xtls/xray-core/features/inbound" - "github.com/xtls/xray-core/features/routing" ) func (p *Core) RemoveInbound(tag string) error { @@ -32,14 +30,12 @@ func (p *Core) AddInbound(config *core.InboundHandlerConfig) error { } func (p *Core) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList []api.UserInfo) error { - dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) - err := dispather.Limiter.AddInboundLimiter(tag, nodeInfo, userList) + err := p.dispatcher.Limiter.AddInboundLimiter(tag, nodeInfo, userList) return err } func (p *Core) GetInboundLimiter(tag string) (*limiter.InboundInfo, error) { - dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) - limit, ok := dispather.Limiter.InboundInfo.Load(tag) + limit, ok := p.dispatcher.Limiter.InboundInfo.Load(tag) if ok { return limit.(*limiter.InboundInfo), nil } @@ -47,13 +43,11 @@ func (p *Core) GetInboundLimiter(tag string) (*limiter.InboundInfo, error) { } func (p *Core) UpdateInboundLimiter(tag string, nodeInfo *api.NodeInfo, updatedUserList []api.UserInfo) error { - dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) - err := dispather.Limiter.UpdateInboundLimiter(tag, nodeInfo, updatedUserList) + err := p.dispatcher.Limiter.UpdateInboundLimiter(tag, nodeInfo, updatedUserList) return err } func (p *Core) DeleteInboundLimiter(tag string) error { - dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) - err := dispather.Limiter.DeleteInboundLimiter(tag) + err := p.dispatcher.Limiter.DeleteInboundLimiter(tag) return err } diff --git a/core/outbound.go b/core/outbound.go index 2cdb81c..8ec8137 100644 --- a/core/outbound.go +++ b/core/outbound.go @@ -8,13 +8,11 @@ import ( ) func (p *Core) RemoveOutbound(tag string) error { - outboundManager := p.Server.GetFeature(outbound.ManagerType()).(outbound.Manager) - err := outboundManager.RemoveHandler(context.Background(), tag) + err := p.ohm.RemoveHandler(context.Background(), tag) return err } func (p *Core) AddOutbound(config *core.OutboundHandlerConfig) error { - outboundManager := p.Server.GetFeature(outbound.ManagerType()).(outbound.Manager) rawHandler, err := core.CreateObject(p.Server, config) if err != nil { return err @@ -23,7 +21,7 @@ func (p *Core) AddOutbound(config *core.OutboundHandlerConfig) error { if !ok { return fmt.Errorf("not an InboundHandler: %s", err) } - if err := outboundManager.AddHandler(context.Background(), handler); err != nil { + if err := p.ohm.AddHandler(context.Background(), handler); err != nil { return err } return nil diff --git a/core/rule.go b/core/rule.go index d78cc60..8cda5bb 100644 --- a/core/rule.go +++ b/core/rule.go @@ -5,13 +5,12 @@ import ( ) func (p *Core) UpdateRule(tag string, newRuleList []api.DetectRule) error { - err := p.dispatcher.RuleManager.UpdateRule(tag, newRuleList) - return err + return p.dispatcher.RuleManager.UpdateRule(tag, newRuleList) } func (p *Core) UpdateProtocolRule(tag string, newRuleList []string) error { - err := p.dispatcher.RuleManager.UpdateProtocolRule(tag, newRuleList) - return err + + return p.dispatcher.RuleManager.UpdateProtocolRule(tag, newRuleList) } func (p *Core) GetDetectResult(tag string) ([]api.DetectResult, error) {