mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-02 18:14:01 +00: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)
51 lines
839 B
Go
51 lines
839 B
Go
package logic
|
|
|
|
import (
|
|
"fmt"
|
|
C "github.com/Dreamacro/clash/constant"
|
|
)
|
|
|
|
type NOT struct {
|
|
rule C.Rule
|
|
payload string
|
|
adapter string
|
|
}
|
|
|
|
func NewNOT(payload string, adapter string) (*NOT, error) {
|
|
not := &NOT{payload: payload, adapter: adapter}
|
|
rule, err := parseRule(payload)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(rule) < 1 {
|
|
return nil, fmt.Errorf("the parsed rule is empty")
|
|
}
|
|
|
|
not.rule = rule[0]
|
|
return not, nil
|
|
}
|
|
|
|
func (not *NOT) RuleType() C.RuleType {
|
|
return C.NOT
|
|
}
|
|
|
|
func (not *NOT) Match(metadata *C.Metadata) bool {
|
|
return !not.rule.Match(metadata)
|
|
}
|
|
|
|
func (not *NOT) Adapter() string {
|
|
return not.adapter
|
|
}
|
|
|
|
func (not *NOT) Payload() string {
|
|
return not.payload
|
|
}
|
|
|
|
func (not *NOT) ShouldResolveIP() bool {
|
|
return not.rule.ShouldResolveIP()
|
|
}
|
|
|
|
func (not *NOT) RuleExtra() *C.RuleExtra {
|
|
return nil
|
|
}
|