mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-16 12:52:22 +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)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
if options.ClashMode != "" {
|
if options.ClashMode != "" {
|
||||||
clashServer := service.FromContext[adapter.ClashServer](ctx)
|
item := NewClashModeItem(ctx, options.ClashMode)
|
||||||
item := NewClashModeItem(clashServer, options.ClashMode)
|
|
||||||
rule.items = append(rule.items, item)
|
rule.items = append(rule.items, item)
|
||||||
rule.allItems = append(rule.allItems, 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)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
if options.ClashMode != "" {
|
if options.ClashMode != "" {
|
||||||
clashServer := service.FromContext[adapter.ClashServer](ctx)
|
item := NewClashModeItem(ctx, options.ClashMode)
|
||||||
item := NewClashModeItem(clashServer, options.ClashMode)
|
|
||||||
rule.items = append(rule.items, item)
|
rule.items = append(rule.items, item)
|
||||||
rule.allItems = append(rule.allItems, item)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,33 @@
|
||||||
package rule
|
package rule
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/adapter"
|
"github.com/sagernet/sing-box/adapter"
|
||||||
|
"github.com/sagernet/sing/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ RuleItem = (*ClashModeItem)(nil)
|
var _ RuleItem = (*ClashModeItem)(nil)
|
||||||
|
|
||||||
type ClashModeItem struct {
|
type ClashModeItem struct {
|
||||||
|
ctx context.Context
|
||||||
clashServer adapter.ClashServer
|
clashServer adapter.ClashServer
|
||||||
mode string
|
mode string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClashModeItem(clashServer adapter.ClashServer, mode string) *ClashModeItem {
|
func NewClashModeItem(ctx context.Context, mode string) *ClashModeItem {
|
||||||
return &ClashModeItem{
|
return &ClashModeItem{
|
||||||
clashServer: clashServer,
|
ctx: ctx,
|
||||||
mode: mode,
|
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 {
|
func (r *ClashModeItem) Match(metadata *adapter.InboundContext) bool {
|
||||||
if r.clashServer == nil {
|
if r.clashServer == nil {
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue
Block a user