mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-16 12:22:21 +08:00
Fix match clash mode
This commit is contained in:
parent
e18b527eaa
commit
2be7482e32
|
@ -219,8 +219,7 @@ func NewDefaultRule(ctx context.Context, logger log.ContextLogger, options optio
|
|||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
if options.ClashMode != "" {
|
||||
clashServer := service.FromContext[adapter.ClashServer](ctx)
|
||||
item := NewClashModeItem(clashServer, options.ClashMode)
|
||||
item := NewClashModeItem(ctx, options.ClashMode)
|
||||
rule.items = append(rule.items, item)
|
||||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
|
|
|
@ -216,8 +216,7 @@ func NewDefaultDNSRule(ctx context.Context, logger log.ContextLogger, options op
|
|||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
if options.ClashMode != "" {
|
||||
clashServer := service.FromContext[adapter.ClashServer](ctx)
|
||||
item := NewClashModeItem(clashServer, options.ClashMode)
|
||||
item := NewClashModeItem(ctx, options.ClashMode)
|
||||
rule.items = append(rule.items, item)
|
||||
rule.allItems = append(rule.allItems, item)
|
||||
}
|
||||
|
|
|
@ -1,25 +1,33 @@
|
|||
package rule
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing/service"
|
||||
)
|
||||
|
||||
var _ RuleItem = (*ClashModeItem)(nil)
|
||||
|
||||
type ClashModeItem struct {
|
||||
ctx context.Context
|
||||
clashServer adapter.ClashServer
|
||||
mode string
|
||||
}
|
||||
|
||||
func NewClashModeItem(clashServer adapter.ClashServer, mode string) *ClashModeItem {
|
||||
func NewClashModeItem(ctx context.Context, mode string) *ClashModeItem {
|
||||
return &ClashModeItem{
|
||||
clashServer: clashServer,
|
||||
ctx: ctx,
|
||||
mode: mode,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ClashModeItem) Start() error {
|
||||
r.clashServer = service.FromContext[adapter.ClashServer](r.ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ClashModeItem) Match(metadata *adapter.InboundContext) bool {
|
||||
if r.clashServer == nil {
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue
Block a user