mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 21:51:23 +08:00
8595d6c2e9
1.Add Network rule, match network type(TCP/UDP) 2.Add logic rules(NOT,OR,AND) -AND,((DOMAIN,baidu.com),(NETWORK,UDP)),REJECT (cherry picked from commit d7092e2e37f2c48282c878edea1b2ebc2912b09a)
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package provider
|
|
|
|
import (
|
|
"fmt"
|
|
C "github.com/Dreamacro/clash/constant"
|
|
P "github.com/Dreamacro/clash/constant/provider"
|
|
)
|
|
|
|
type RuleSet struct {
|
|
ruleProviderName string
|
|
adapter string
|
|
ruleProvider P.RuleProvider
|
|
ruleExtra *C.RuleExtra
|
|
}
|
|
|
|
func (rs *RuleSet) RuleType() C.RuleType {
|
|
return C.RuleSet
|
|
}
|
|
|
|
func (rs *RuleSet) Match(metadata *C.Metadata) bool {
|
|
return rs.getProviders().Match(metadata)
|
|
}
|
|
|
|
func (rs *RuleSet) Adapter() string {
|
|
return rs.adapter
|
|
}
|
|
|
|
func (rs *RuleSet) Payload() string {
|
|
return rs.getProviders().Name()
|
|
}
|
|
|
|
func (rs *RuleSet) ShouldResolveIP() bool {
|
|
return rs.getProviders().ShouldResolveIP()
|
|
}
|
|
func (rs *RuleSet) getProviders() P.RuleProvider {
|
|
if rs.ruleProvider == nil {
|
|
rp := RuleProviders()[rs.ruleProviderName]
|
|
rs.ruleProvider = rp
|
|
}
|
|
|
|
return rs.ruleProvider
|
|
}
|
|
|
|
func (rs *RuleSet) RuleExtra() *C.RuleExtra {
|
|
return nil
|
|
}
|
|
|
|
func NewRuleSet(ruleProviderName string, adapter string, ruleExtra *C.RuleExtra) (*RuleSet, error) {
|
|
rp, ok := RuleProviders()[ruleProviderName]
|
|
if !ok {
|
|
return nil, fmt.Errorf("rule set %s not found", ruleProviderName)
|
|
}
|
|
return &RuleSet{
|
|
ruleProviderName: ruleProviderName,
|
|
adapter: adapter,
|
|
ruleProvider: rp,
|
|
ruleExtra: ruleExtra,
|
|
}, nil
|
|
}
|