Add clash mode support

This commit is contained in:
世界
2022-09-10 14:09:47 +08:00
parent 80cfc9a25b
commit 5297273937
12 changed files with 98 additions and 23 deletions

33
route/rule_clash_mode.go Normal file
View File

@@ -0,0 +1,33 @@
package route
import (
"strings"
"github.com/sagernet/sing-box/adapter"
)
var _ RuleItem = (*ClashModeItem)(nil)
type ClashModeItem struct {
router adapter.Router
mode string
}
func NewClashModeItem(router adapter.Router, mode string) *ClashModeItem {
return &ClashModeItem{
router: router,
mode: strings.ToLower(mode),
}
}
func (r *ClashModeItem) Match(metadata *adapter.InboundContext) bool {
clashServer := r.router.ClashServer()
if clashServer == nil {
return false
}
return clashServer.Mode() == r.mode
}
func (r *ClashModeItem) String() string {
return "clash_mode=" + r.mode
}